request.js
1.8 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// export const baseUrl = 'http://192.168.1.136:9100'
export const baseUrl = 'http://longsi.t.brotop.cn'
function getHeaders() {
let header = {
"token": uni.getStorageSync('token') || '', // 'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json'
}
return header
}
function getHeader() {
let header = {
"token": uni.getStorageSync('token') || '', // 'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json',
}
return header
}
export default {
get(url, param) {
return new Promise((resolve, reject) => {
uni.request({
method: 'GET',
url: baseUrl + url,
data: param,
header: getHeaders()
}).then(res => {
if (res[1].data.code == 1) {
resolve(res[1].data)
} else if (res[1].data.msg.indexOf('过期') > -1 || res[1].data.msg.indexOf('请登录') > -1) {
uni.showToast({
icon: 'none',
title: "请登录",
duration: 3000
})
uni.navigateTo({
url:'/pages/index/index'
})
}else{
uni.showToast({
icon: 'none',
title: res[1].data.msg,
duration: 1300
})
}
}).catch(
(response) => {
reject(response)
}
)
})
},
post(url, param) {
return new Promise((resolve, reject) => {
uni.request({
method: 'POST',
url: baseUrl + url,
data: param,
header: getHeader()
}).then(res => {
if (res[1].data.code == 1) {
resolve(res[1].data)
} else if(res[1].data.code == 0){
resolve(res[1].data)
}
else if (res[1].data.msg.indexOf('过期') > -1 || res[1].data.msg.indexOf('请登录') > -1) {
uni.showToast({
icon: 'none',
title: "请登录",
duration: 3000
})
uni.navigateTo({
url:'/pages/index/index'
})
}
}).catch((response) => {
reject(response)
})
})
},
}