wx.js
1.11 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
import Promise from '../vendors/es6-promise';
const api = {};
const apiNames = [
'request',
'navigateTo',
'navigateBack',
'redirectTo',
'switchTab',
'showLoading',
'hideLoading',
'navigateToMiniProgram',
'getUserInfo',
'getSetting',
'openSetting',
'showModal',
'login',
'scanCode',
'checkSession',
'setStorage',
'showToast',
'getSystemInfo',
'setClipboardData'
];
apiNames.forEach(key => {
if (typeof wx[key] === 'function') {
api[key] = (params = {}) => {
return new Promise((resolve, reject) => {
console.debug(`call api ${key}: `, Object.assign({}, params));
params.success = res => {
console.debug(`call api ${key} result: `, res);
return resolve(res);
};
params.fail = err => {
console.debug(`call api ${key} error: `, err);
return reject(err);
};
return wx[key](params);
});
};
}
});
export default Object.assign({}, wx, api);