You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
1 year ago
|
|
||
|
import storage from '@/common/utils/storage'
|
||
|
function service(options = {}) {
|
||
|
var token = storage.getStorage(storage.constant.token)
|
||
|
var tenantId = 1
|
||
|
if(getApp()!=undefined){
|
||
|
tenantId = getApp().globalData.tenantId
|
||
|
}
|
||
|
var requestUrl = ""
|
||
|
if(getApp()!=undefined){
|
||
|
requestUrl = getApp().globalData.request_url
|
||
|
}
|
||
|
options.header = {
|
||
|
"content-type": "application/json",
|
||
|
"Authorization": "Bearer "+token,
|
||
|
"dataType":"json",
|
||
|
"tenant-id":tenantId
|
||
|
};
|
||
|
options.timeout = 10000
|
||
|
|
||
|
options.url = requestUrl+options.url
|
||
|
|
||
|
return new Promise((resolve, reject) => {
|
||
|
options.success = (res) => {
|
||
|
if (res ) {
|
||
|
if(res.statusCode == 200){
|
||
|
if(res.data.code==0){
|
||
|
resolve(res.data);
|
||
|
}else {
|
||
|
reject( res.data.msg)
|
||
|
}
|
||
|
|
||
|
}else {
|
||
|
reject( res.data.msg)
|
||
|
}
|
||
|
|
||
|
} else {
|
||
|
reject(res.data.msg)
|
||
|
}
|
||
|
};
|
||
|
options.fail = (error) => {
|
||
|
var message = error.errMsg
|
||
|
if (message === 'Network Error') {
|
||
|
message = '后端接口连接异常'
|
||
|
} else if (message.includes('timeout')) {
|
||
|
message = '系统接口请求超时'
|
||
|
} else if (message.includes('Request failed with status code')) {
|
||
|
message = '系统接口' + message.substr(message.length - 3) + '异常'
|
||
|
}
|
||
|
reject(message);
|
||
|
};
|
||
|
uni.request(options);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export default service;
|