init
This commit is contained in:
2
src/script/net/config/index.ts
Normal file
2
src/script/net/config/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
export { ParamsReq, ParamsRes } from './params'
|
||||
33
src/script/net/config/params.ts
Normal file
33
src/script/net/config/params.ts
Normal file
@ -0,0 +1,33 @@
|
||||
//发送请求 地址和参数
|
||||
class ParamsReq {
|
||||
private _url: string = ''
|
||||
private _parms: any
|
||||
//进行封装
|
||||
constructor(url: string, parms: any) {
|
||||
this._url = url
|
||||
this._parms = parms
|
||||
}
|
||||
public get url(): string {
|
||||
return this._url
|
||||
}
|
||||
public get parms(): any {
|
||||
return this._parms
|
||||
}
|
||||
}
|
||||
|
||||
class resParams {
|
||||
data: any = {}
|
||||
message: string = ''
|
||||
}
|
||||
|
||||
//接受请求 请求码 和请求回来的参数
|
||||
class ParamsRes {
|
||||
public resCode: number
|
||||
public resParams: resParams
|
||||
constructor(resCode: number, resParams: resParams) {
|
||||
this.resCode = resCode
|
||||
this.resParams = resParams
|
||||
}
|
||||
}
|
||||
|
||||
export { ParamsReq, ParamsRes, resParams }
|
||||
4
src/script/net/config/ss.json
Normal file
4
src/script/net/config/ss.json
Normal file
@ -0,0 +1,4 @@
|
||||
{"children":
|
||||
[{"id": "1000", "type": "category", "label": "1671172471589", "children":
|
||||
[{"id": "1002", "type": "item", "label": "右肺上叶前段", "modelname": "isPickable_右肺上叶前段", "paramsdata": {"color": "#cc5921", "opacity": "1"}}],
|
||||
"modelname": ""}, {"id": "1001", "type": "category", "label": "1671172471973", "modelname": ""}], "modelurl": "http://192.168.3.151:8084/model/1671171942281-feimoxing.glb"}
|
||||
27
src/script/net/netrouter/EditorRequest.ts
Normal file
27
src/script/net/netrouter/EditorRequest.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { Request } from '../request'
|
||||
import { ParamsReq, ParamsRes } from 'script/net/config'
|
||||
|
||||
//资源请求
|
||||
export class EditorRequest {
|
||||
public request: Request = new Request()
|
||||
|
||||
public Post(url: string, parms: any, resFunc: Function, errFunc?: Function) {
|
||||
const paramsReq = new ParamsReq(url, parms)
|
||||
|
||||
this.request
|
||||
.post(paramsReq)
|
||||
.then((res) => {
|
||||
resFunc(res.data)
|
||||
})
|
||||
.catch((err) => {
|
||||
errFunc ? err : ''
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
public production(parms: any, resFunc: Function, errFunc?: Function) {
|
||||
this.Post('cpq/3d/create/order', parms, resFunc, errFunc)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
13
src/script/net/netrouter/index.ts
Normal file
13
src/script/net/netrouter/index.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { EditorRequest } from './EditorRequest'
|
||||
|
||||
let _editorRequest: EditorRequest
|
||||
|
||||
//编辑器的所有请求
|
||||
export function editorRequest() {
|
||||
if (_editorRequest) {
|
||||
return _editorRequest
|
||||
} else {
|
||||
_editorRequest = new EditorRequest()
|
||||
return _editorRequest
|
||||
}
|
||||
}
|
||||
40
src/script/net/request.ts
Normal file
40
src/script/net/request.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import axios from 'axios'
|
||||
import { ParamsReq } from 'script/net/config'
|
||||
import { AxiosInstance } from 'axios'
|
||||
//https://script.jiaweijia.cn/script
|
||||
|
||||
export class Request {
|
||||
|
||||
service: AxiosInstance
|
||||
// import.meta.env.VITE_BASE_URL
|
||||
//'https://script.jiaweijia.cn/script'
|
||||
|
||||
|
||||
constructor() {
|
||||
console.log(import.meta.env.VITE_BASE_URL);
|
||||
this.service = axios.create({
|
||||
baseURL: import.meta.env.VITE_BASE_URL,
|
||||
timeout: 15000,
|
||||
headers: {
|
||||
// 这里可设置所有的请求头
|
||||
//'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' //该项建议设置 如果未 POST请求时 数据未做处理时会出现错误,最理想的解决方法就是 直接设置该项
|
||||
//"Content-Type": "multipart/form-data"
|
||||
"Content-Type": "application/json"
|
||||
//'Cache-Control': 'no-cache'
|
||||
}
|
||||
})
|
||||
}
|
||||
get(url: string) {
|
||||
return this.service.get(url)
|
||||
}
|
||||
post(data: ParamsReq) {
|
||||
console.log(data.url);
|
||||
return this.service.post(data.url, data.parms)
|
||||
}
|
||||
del(url: string) {
|
||||
return this.service.delete(url)
|
||||
}
|
||||
put(data: ParamsReq) {
|
||||
return this.service.put(data.url, data.parms)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user