Files
2025-11-28 13:55:54 +08:00

52 lines
1.3 KiB
JavaScript

import { baseUrl} from './config.js'
const request = {}
const headers = {}
request.globalRequest = (url, method, data, power, type) => {
// 权限判断 因为有的接口请求头可能需要添加的参数不一样,所以这里做了区分
// 1 == 不通过access_token校验的接口
// 2 == 文件下载接口列表
const userInfo = uni.getStorageSync('CAuserInfo')
console.log("ca用户",userInfo);
if(userInfo != ""){
headers['Token'] = userInfo.token
}
return uni.request({
timeout: 60000,
url: baseUrl + url,
method,
data: data,
dataType: 'json',
header: headers
}).then(res => {
if (res.data.Result) {
return res.data
} else {
throw res.data
}
}).catch(parmas => {
switch (parmas.status) {
case 401:
uni.showToast({
title: parmas.msg,
icon: 'none',
duration: 3500
})
uni.removeStorageSync("CAuserInfo");
setTimeout(() => {
uni.reLaunch({
url: "/pages/index/index"
})
}, 2800)
break
default:
console.error(parmas);
return Promise.reject()
break
}
})
}
export default request