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.

43 lines
1.2 KiB

/**
* 封装的异步请求处理函数
* 使用方法为:
* request('接口名称',{key:value},'请求方式(默认为GET)')
* .then(res=>{console.log(res)})
*/
import { getToken, removeToken } from "./auth";
const baseUrl = 'http://47.100.1.234:8080/jeecg-boot';
async function request(mehtod, params, type = 'GET') {
//创建一个名为request请求的方法函数
let header = {
//设置请求头信息
'X-Access-Token': getToken(),
'X-Requested-With': 'XMLHttpRequest',
"Accept": "application/json",
"Content-Type": "application/json; charset=UTF-8"
};
let http = {
url: baseUrl + mehtod,
data: params,
method: type.toUpperCase(),
header: header
};
let promise = new Promise((resolve, reject) => {
uni.request(http).then(res => {
console.log(res)
let newdata = res[1].data; // if (newdata.code == 403) {
if (newdata == -1) {
//如果错误码为 -1 提示
uni.showToast({
title: res[1].data.msg,
icon: 'none'
});
}
resolve(res[1].data);
}).catch(err => {
reject(err);
console.log(err);
});
});
return promise;
}
export default request