4dfe89e4
monkeyhouyi
初始化
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// #ifdef H5
// if (process.env.NODE_ENV === 'development') {
// //本地环境,即开发环境
// baseUrl = 'http://localhost:8000'
// } else {
// //线上环境
// baseUrl = 'https://*******.**'
// console.log = () => {}
// }
// baseUrl = 'http://8.130.38.56:8027/admin-server'
// #endif
//封装request请求
const sendRequest = (url, method = 'GET', data = {}, baseUrl,contentType) => {
//判断header提交数据类型
let types = '';
if (method == 'POST' && !contentType) {
types = 'application/x-www-form-urlencoded'
} else if (method == 'POST' && contentType) {
types = contentType
} else {
types = 'application/json';
}
|
4dfe89e4
monkeyhouyi
初始化
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
var token = uni.getStorageSync('token') || '';
var shopId = uni.getStorageSync('shopId') || '';
return new Promise(function(resolve, reject) {
uni.showLoading({
title: '加载中...'
});
uni.request({
url: bases,
data: data,
method: method,
header: {
'Content-Type': 'application/json; charset=UTF-8',
'shopId':shopId,
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Authorization-business':uni.getStorageSync('token'),
},
success(res) {
uni.hideLoading();
var code = res.data.code;
console.log("res",res)
switch (code) {
case 20001:
uni.showModal({
title: '登录提示',
content: '无权访问!请重新登录后再来操作',
showCancel:false,
success:ress => {
uni.reLaunch({
url:'/pages'
})
}
})
break;
case 20002:
uni.showModal({
title: '登录提示',
content: '身份已过期,请重新登录后再来操作!',
showCancel:false,
success:ress => {
uni.redirectTo({
url:'/pages'
})
}
})
break;
case 20003:
uni.showModal({
title: '登录提示',
content: 'Token生成失败,请重新登录!',
showCancel:false,
success:ress => {
uni.redirectTo({
url:'/pages'
})
}
})
break;
case 20005:
uni.showModal({
title: '登录提示',
content: '访问被禁止,请重新登录!',
showCancel:false,
success:ress => {
uni.redirectTo({
url:'/pages'
})
}
})
break;
case 500:
uni.showModal({
title: '登录提示',
content: '系统错误,请重新登录!',
success:ress => {
if (ress.confirm) {
uni.redirectTo({
url:'/pages'
})
}
}
})
break;
default:
resolve(res);
break;
}
},
fail(err) {
uni.hideLoading();
uni.showToast({title:"出错啦,请稍后再试",icon:"error"});
reject(err);
}
})
})
}
module.exports.sendRequest = sendRequest
|