HttpUtils.ets
2.58 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
109
110
111
112
113
114
115
116
117
import { SpConstants } from 'wdConstant/Index';
import { DeviceUtil, SPHelper, StringUtils } from 'wdKit/Index';
import { HttpParams } from '../http/HttpCommonParams';
import { HttpRequest } from '../http/HttpRequest';
const TAG: string = '[HttpUtils]'
/**
* http相关工具类,对外暴露
*/
export class HttpUtils {
private static userId = ''
private static userType = ''
private static token = ''
/**
* 添加公共参数,如登录后,添加登录信息
*/
static addCommonHeader() {
HttpRequest.addGlobalHeaderProvider(() => {
let headers: Record<string, string> = {};
return headers;
})
}
/**
* 添加公共参数,如登出后,移除登录信息
*/
static removeCommonHeader() {
}
static getRefreshToken() {
let refreshToken = SPHelper.default.getSync(SpConstants.USER_REFRESH_TOKEN, "")
if (StringUtils.isNotEmpty(refreshToken)) {
return refreshToken as string;
}
return '';
}
/**
* 设备id,uuid
*/
public static getDeviceId(): string {
return DeviceUtil.clientId();
}
/**
* 定位,城市code
*/
public static getCityCode(): string {
// TODO
// 城市编码
return '340100';
}
/**
* 定位,省份code
*/
public static getProvinceCode(): string {
// TODO
return '340000';
}
/**
* 定位,地区code
*/
public static getDistrictCode(): string {
// TODO
return '340103';
}
public static getImei(): string {
return DeviceUtil.clientId();
}
public static getUserId(): string {
// TODO 对接登录
if (StringUtils.isNotEmpty(HttpUtils.userId)) {
return HttpUtils.userId
}
HttpUtils.userId = SPHelper.default.getSync(SpConstants.USER_ID, "") as string
return HttpUtils.userId;
}
public static getUserType(): string {
if (StringUtils.isNotEmpty(HttpUtils.userType)) {
return HttpUtils.userType
}
HttpUtils.userType = SPHelper.default.getSync(SpConstants.USER_Type, "") as string
return HttpUtils.userType;
}
static getXToken(): string {
if (StringUtils.isNotEmpty(HttpUtils.token)) {
return HttpUtils.token
}
HttpUtils.token = SPHelper.default.getSync(SpConstants.USER_JWT_TOKEN, "") as string
if (StringUtils.isNotEmpty(HttpUtils.token)) {
return HttpUtils.token
}
return ''
}
public static setUserId(userId: string) {
// TODO 优化赋值
HttpUtils.userId = userId;
}
public static setUserType(userType: string) {
HttpUtils.userType = userType;
}
public static setUserToken(token: string) {
HttpUtils.token = token;
}
}