export const baseUrl = 'http://47.97.159.191:8300'
function getToken() {
const storageData = uni.getStorageSync('pinia_persiste_key_user');
if (storageData) {
const {
token
} = JSON.parse(storageData);
return token; // 返回 token
}
return ''; // 如果没有找到数据,返回 null 或其他合适的值
}
export const request = (options, header) => {
return new Promise((resolve, reject) => {
// uni.showLoading({
// title: '加载中',
// mask: true,
// })
uni.request({
url: baseUrl + options.url, //接口地址:前缀+方法中传入的地址
method: options.method || 'POST', //请求方法:传入的方法或者默认是“GET”
data: options.data || {}, //传递参数:传入的参数或者默认传递空集合
header: header || {
'token': getToken(), //自定义请求头信息
'content-type': options.isJson ? 'application/json' : 'application/x-www-form-urlencoded',
},
success: (res) => {
uni.hideLoading();
if (res.data.retCode == '601') {
uni.reLaunch({
url: '/pages/login/login',
})
return uni.$u.toast('登录过期,请重新登录');
}
resolve(res, '成功')
},
// 这里的接口请求,如果出现问题就输出接口请求失败
fail: (err) => {
uni.hideLoading();
// console.log('err', err)
reject(err)
},
})
})
}
05-14
322
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-03
1786
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-01
553
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-19
246
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交