6ef461ce
wangming
项目上传
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
|
import service from './service.js'
import BASE_URL from '../common/config.js'
const get = function(url, data, noApiBase) {
return request(url, 'GET', data, noApiBase);
}
const post = function(url, data, noApiBase) {
return request(url, 'POST', data, noApiBase);
}
const del = function(url, data, noApiBase) {
return request(url, 'DELETE', data, noApiBase);
}
const request = function(url, method, data, noApiBase) {
url = BASE_URL + '/api' + url;
let token = service.getToken()
// if(!token ){
// uni.reLaunch({
// url:'/pages/login/login.vue'
// })
// return
// }
return new Promise((resolve, reject) => {
uni.request({
url,
data,
method,
header: {
'Authorization': token
},
success: (res) => {
if (res.data.code === 200) {
if (res.data.code < 0 && res.data.code) {
uni.showToast({
icon: 'none',
title: res.data.message,
duration: 2000
});
} else {
resolve(res.data);
}
} else if (res.code === 403 || res.code === 500 || res.statusCode === 500) {
service.addToken('');
service.saveUser('');
} else {
uni.showToast({
icon: 'none',
title: res.data.message,
duration: 2000
});
}
},
fail(err) {
console.log('err', err);
}
});
});
}
export default {
get,
post,
del,
request,
}
|