fetch.js
2 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
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
import configApi from './configApi'
// 第一种写法
export function fetch(method = 'GET', url, params = null, headers = {}) {
method = method.toLocaleUpperCase();
return new Promise((resolve, reject) => {
uni.request({
url: url,
method: method,
data: params,
header: headers,
success: (res) => {
resolve(res)
},
fail: (err) => {
reject(err);
}
})
})
}
// 第二种写法
// 接口基类
const http = (options) => {
const { method = 'get', data, url, headers = {} } = options;
method = method.toLocaleUpperCase();
return new Promise((resolve, reject) => {
uni.request({
url: url,
method: method,
data: data,
header: headers,
success: (res) => {
resolve(res)
},
fail: (err) => {
reject(err);
}
})
})
}
export default {
// 接口应用层
// 集团列表
loadAccountList({ method, data, headers }) {
return http({
url: configApi.LOAD_ACCOUNT_LIST,
method: method,
data: data,
headers: headers
})
},
// 商场列表
loadMallList(method, data, headers) {
return http({
url: configApi.LOAD_MALL_LIST,
method: method,
data: data,
headers: headers
})
},
// 楼层列表
loadFloorList(method, data, headers) {
return http({
url: configApi.LOAD_FLOOR_LIST,
method: method,
data: data,
headers: headers
})
},
// 店铺列表
loadZoneList(method, data, headers) {
return http({
url: configApi.LOAD_ZONE_LIST,
method: method,
data: data,
headers: headers
})
},
// 监控点列表
loadGateList(method, data, headers) {
return http({
url: configApi.LOAD_GATE_LIST,
method: method,
data: data,
headers: headers
})
},
// 字典列表
loadDictList(method, data, headers) {
return http({
url: configApi.LOAD_DICT_LIST,
method: method,
data: data,
headers: headers
})
},
// 抓拍记录列表
loadFacerecognitionList(method, data, headers) {
return http({
url: configApi.LOAD_FACERECOGNITION_LIST,
method: method,
data: data,
headers: headers
})
}
}