Files
ClassContent/历届学生/吴欣阳/项目开发/美食app/http/index.js
2024-09-27 02:06:13 +08:00

65 lines
1.8 KiB
JavaScript

import config from "../config";
class http {
constructor() {
this.Interceptor()
}
get(params) {
return new Promise((resolve, reject) => {
uni.request({
url: params.url,
data: params.data,
header: Object.assign({
token: uni.getStorageSync('token')
}, params.header),
success: (res) => {
resolve(res.data)
}
});
})
}
post () {
}
Interceptor() {
uni.addInterceptor('request', {
invoke(args) {
uni.showLoading({ title: '加载中...' });
args.url = config.checkUrl() + args.url
},
success(args) {
uni.hideLoading();
switch (args.data.status) {
case 200:
console.log("args===",args)
args.data = args.data.result;
break;
case 500:
uni.showModal({
title: '温馨提示',
content: args.data.msg,
success: function (res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
throw new Error(args.data.msg);
break;
default:
break;
}
}
})
}
}
export default new http()