|
|
@ -4,11 +4,12 @@
|
|
|
|
* request('接口名称',{key:value},'请求方式(默认为GET)')
|
|
|
|
* request('接口名称',{key:value},'请求方式(默认为GET)')
|
|
|
|
* .then(res=>{console.log(res)})
|
|
|
|
* .then(res=>{console.log(res)})
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
import { getToken, removeToken } from "./auth";
|
|
|
|
import {getToken} from "./auth";
|
|
|
|
import CONFIG from '@/config'
|
|
|
|
import CONFIG from '@/config'
|
|
|
|
|
|
|
|
|
|
|
|
export const baseUrl = CONFIG.apiUrl
|
|
|
|
export const baseUrl = CONFIG.apiUrl
|
|
|
|
const whitePath = ['/pages/login/index1']
|
|
|
|
const whitePath = ['/pages/login/index1']
|
|
|
|
async function request(mehtod, params, type = 'GET') {
|
|
|
|
async function request(method, params, type = 'GET') {
|
|
|
|
//创建一个名为request请求的方法函数
|
|
|
|
//创建一个名为request请求的方法函数
|
|
|
|
const token = getToken()
|
|
|
|
const token = getToken()
|
|
|
|
// if (!token) {
|
|
|
|
// if (!token) {
|
|
|
@ -25,15 +26,15 @@ async function request(mehtod, params, type = 'GET') {
|
|
|
|
"Content-Type": "application/json; charset=UTF-8"
|
|
|
|
"Content-Type": "application/json; charset=UTF-8"
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let http = {
|
|
|
|
let http = {
|
|
|
|
url: baseUrl + mehtod,
|
|
|
|
url: baseUrl + method,
|
|
|
|
data: params,
|
|
|
|
data: params,
|
|
|
|
method: type.toUpperCase(),
|
|
|
|
method: type.toUpperCase(),
|
|
|
|
header: header
|
|
|
|
header: header
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let promise = new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
uni.request(http).then(res => {
|
|
|
|
uni.request(http).then(res => {
|
|
|
|
let newdata = res[1].data; // if (newdata.code == 403) {
|
|
|
|
let newData = res[1].data; // if (newdata.code == 403) {
|
|
|
|
if (newdata == -1) {
|
|
|
|
if (newData == -1) {
|
|
|
|
//如果错误码为 -1 提示
|
|
|
|
//如果错误码为 -1 提示
|
|
|
|
uni.showToast({
|
|
|
|
uni.showToast({
|
|
|
|
title: res[1].data.msg,
|
|
|
|
title: res[1].data.msg,
|
|
|
@ -42,15 +43,14 @@ async function request(mehtod, params, type = 'GET') {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resolve(res[1].data);
|
|
|
|
resolve(res[1].data);
|
|
|
|
}).catch(err => {
|
|
|
|
}).catch(err => {
|
|
|
|
if (err.statusCode === 401) {
|
|
|
|
if (err.statusCode === 401) {
|
|
|
|
uni.redirectTo({
|
|
|
|
uni.redirectTo({
|
|
|
|
url: '/pages/login/index1?status=' + 1
|
|
|
|
url: '/pages/login/index1?status=' + 1
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reject(err);
|
|
|
|
reject(err);
|
|
|
|
console.log(err);
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return promise;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export default request
|
|
|
|
export default request
|
|
|
|