111
chenyong
2026-03-06 9051d96029c8e860c6e6657b7df2106bfbfdc010
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
 
/*
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-08-02 14:58:23
 */
import axios from 'axios';
import UtilVar from "@/config/UtilVar";
import router from '@/router'
 
let baseUrl = UtilVar.baseUrl
// let wcsBaseUrl = 'http://10.6.100.16:9291'
// let wmsBaseUrl = 'http://10.6.100.116:9290'
let wmsBaseUrl = 'http://127.0.0.1:9290'
let wcsBaseUrl= 'http://127.0.0.1:9291'
const CancelToken = axios.CancelToken;
export { baseUrl };
// axios.defaults.withCredentials = true;
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么 传token
    let token = localStorage.getItem("token");
    config.headers.common['Content-Type'] = "application/json;charset=utf-8";
    config.headers.common['token'] = token;  //Authorization
    return config;
}, function (error) {
    // 对请求错误做些什么
    console.log(error)
    return Promise.reject(error);
});
/**
 * @响应拦截
 */
axios.interceptors.response.use(response => {
  
    if (response.status !== 200) {
        return Promise.reject(response)
    }
      /**
     * @code 登录过期 token验证失败 根据后端调 
     */
    if (response.data.code == UtilVar.code) {
        // router.push("/login")
    }
    return response.data
}, error => {
    console.error(error);
    let err = {
        success: false,
        msg: "未知异常,请联系管理员!"
    }
    return Promise.reject(err)
})
 
let configs_ENC = {
    headers: { 'enc': UtilVar.ENC }
}
//处理是否加密数据
let isEncryptionParam = (params) => {
    return params
 
}
export const GET = async (url, params) => {
    try {
        params = isEncryptionParam(params)
        const data = await axios.get(`${baseUrl}${url}`, {
            params: params,
            headers: configs_ENC.headers
        }, configs_ENC);
        return data;
    } catch (error) {
        return error;
    }
}
//没有基地址 访问根目录下文件
 
export const GETNOBASE = async (url, params) => {
    try {
        const data = await axios.get(url, {
            params: params,
        });
        return data;
    } catch (error) {
        return error;
    }
}
export const POST = async (url, params) => {
    try {
        params = isEncryptionParam(params)
        const data = await axios.post(`${baseUrl}${url}`, params, configs_ENC);
        return data;
    } catch (error) {
        return error;
    }
}
export const PUT = async (url, params) => {
    try {
        params = isEncryptionParam(params)
        const data = await axios.put(`${baseUrl}${url}`, params, configs_ENC);
        return data;
    } catch (error) {
        return error;
    }
}
export const DELETE = async (url, params) => {
    // console.log(params)
    try {
        params = isEncryptionParam(params)
        const data = await axios.delete(`${baseUrl}${url}`, { data: params, headers: configs_ENC.headers }, configs_ENC);
        return data;
    } catch (error) {
        return error;
    }
}
 
// WCS服务API请求
export const WCS_GET = async (url, params) => {
    try {
        params = isEncryptionParam(params)
        const data = await axios.get(`${wcsBaseUrl}${url}`, {
            params: params,
            headers: configs_ENC.headers
        }, configs_ENC);
        return data;
    } catch (error) {
        return error;
    }
}
 
export const WCS_POST = async (url, params) => {
    try {
        params = isEncryptionParam(params)
        const data = await axios.post(`${wcsBaseUrl}${url}`, params, configs_ENC);
        return data;
    } catch (error) {
        return error;
    }
}
 
// WMS服务API请求
export const WMS_GET = async (url, params) => {
    try {
        params = isEncryptionParam(params)
        const data = await axios.get(`${wmsBaseUrl}${url}`, {
            params: params,
            headers: configs_ENC.headers
        }, configs_ENC);
        return data;
    } catch (error) {
        return error;
    }
}
 
export const WMS_POST = async (url, params) => {
    try {
        params = isEncryptionParam(params)
        const data = await axios.post(`${wmsBaseUrl}${url}`, params, configs_ENC);
        return data;
    } catch (error) {
        return error;
    }
}
 
 
/**
 * @文件类型提交方法
 */
let configs = {
    headers: { 'Content-Type': 'multipart/form-data' },
 
}
export const FILESubmit = async (url, params, config) => {
    try {
        const data = await axios.post(`${baseUrl}${url}`, params, {
            ...configs,
            cancelToken: new CancelToken(function executor(c) {
                config.setCancel && config.setCancel(c)
            }),
            onUploadProgress: (e) => {
                if (e.total > 0) {
                    e.percent = e.loaded / e.total * 100;
                }
                // console.log(config)
                config.onProgress && config.onProgress(e)
            },
 
        });
        return data;
    } catch (err) {
        return err;
    }
}
 
/**
 * 下载文档流
 * @param {config.responseType} 下载文件流根据后端 配置   arraybuffer || blod
 */
export const FILE = async (config = {}, body, params) => {
    try {
        const data = await axios({
            method: config.method || 'get',
            url: `${baseUrl}${config.url}`,
            data: body,
            params: params,
            responseType: config.responseType || 'blob',
            onDownloadProgress: (e) => {
                // console.log(e,e.currentTarget)
                // if (e.currentTarget.response.size > 0) {
                //     e.percent = e.loaded / e.currentTarget.response.size * 100;
                // }
                // event.srcElement.getResponseHeader('content-length')
                config.onProgress && config.onProgress(e)
            },
        });
        return data;
    } catch (err) {
        return err;
    }
}