http.js
941 字节
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
var detaultHeaderOption = { 'Content-Type': 'application/json; charset=utf-8' };
import {default as app_config} from '../utils/app.js';
const http = {
async gql(parmas, loadding = false) {
console.debug("----http---", app_config.app_info)
return new Promise((resolve, reject) => {
let token = uni.getStorageSync('uni_cookie');
let header = {
'Cookie': token,
'AppVersion': encodeURI(JSON.stringify(app_config.app_info)),
...detaultHeaderOption
};
if(!token){
delete header.Cookie;
}
uni.request({
url: `${app_config.server_url.app_host}graphql`,
method:"POST",
data: parmas,
header: header,
success: (res) => {
let tokens = res.cookies;
if(res.header['connect.sid']){
uni.setStorageSync('uni_cookie',res.header['connect.sid'])
}
resolve(res.data)
},
fail: (error) => {
reject(error.data)
}
})
})
}
}
export default http;