|
1
|
|
-// const { encrypt, decrypt } = CryptoJS.AES
|
|
2
|
|
-// const parse = CryptoJS.enc.Utf8;
|
|
3
|
|
-// const pkcs7 = CryptoJS.pad.Pkcs7;
|
|
4
|
|
-// const ECB = CryptoJS.mode.ECB;
|
|
5
|
|
-// const UTF8 = CryptoJS.enc.Utf8;
|
|
6
|
|
-//
|
|
7
|
|
-// const cacheCipher = {
|
|
8
|
|
-// key: '_11111000001111@',
|
|
9
|
|
-// iv: '@11111000001111_',
|
|
10
|
|
-// }
|
|
11
|
|
-//
|
|
12
|
|
-// const DEFAULT_CACHE_TIME = 60 * 60 * 24 * 7;
|
|
13
|
|
-//
|
|
14
|
|
-// const isNullOrUnDef = (val) => typeof val === 'undefined' || val === null
|
|
15
|
|
-//
|
|
16
|
|
-// class AesEncryption {
|
|
17
|
|
-// key;
|
|
18
|
|
-// iv;
|
|
19
|
|
-//
|
|
20
|
|
-// constructor(opt = {}) {
|
|
21
|
|
-// const { key, iv } = opt;
|
|
22
|
|
-// if (key) {
|
|
23
|
|
-// this.key = parse(key);
|
|
24
|
|
-// }
|
|
25
|
|
-// if (iv) {
|
|
26
|
|
-// this.iv = parse(iv);
|
|
27
|
|
-// }
|
|
28
|
|
-// }
|
|
29
|
|
-//
|
|
30
|
|
-// get getOptions() {
|
|
31
|
|
-// return {
|
|
32
|
|
-// mode: ECB,
|
|
33
|
|
-// padding: pkcs7,
|
|
34
|
|
-// iv: this.iv,
|
|
35
|
|
-// };
|
|
36
|
|
-// }
|
|
37
|
|
-//
|
|
38
|
|
-// encryptByAES(cipherText) {
|
|
39
|
|
-// return encrypt(cipherText, this.key, this.getOptions).toString();
|
|
40
|
|
-// }
|
|
41
|
|
-//
|
|
42
|
|
-// decryptByAES(cipherText) {
|
|
43
|
|
-// return decrypt(cipherText, this.key, this.getOptions).toString(UTF8);
|
|
44
|
|
-// }
|
|
45
|
|
-// }
|
|
46
|
|
-//
|
|
47
|
|
-//
|
|
48
|
|
-// const createStorage = (
|
|
49
|
|
-// {
|
|
50
|
|
-// prefixKey = '',
|
|
51
|
|
-// storage = sessionStorage,
|
|
52
|
|
-// key = cacheCipher.key,
|
|
53
|
|
-// iv = cacheCipher.iv,
|
|
54
|
|
-// timeout = null,
|
|
55
|
|
-// hasEncrypt = true,
|
|
56
|
|
-// } = {}) => {
|
|
57
|
|
-// if (hasEncrypt && [ key.length, iv.length ].some((item) => item !== 16)) {
|
|
58
|
|
-// throw new Error('When hasEncrypt is true, the key or iv must be 16 bits!');
|
|
59
|
|
-// }
|
|
60
|
|
-//
|
|
61
|
|
-// const encryption = new AesEncryption({ key, iv });
|
|
62
|
|
-//
|
|
63
|
|
-// /**
|
|
64
|
|
-// *Cache class
|
|
65
|
|
-// *Construction parameters can be passed into sessionStorage, localStorage,
|
|
66
|
|
-// * @class Cache
|
|
67
|
|
-// * @example
|
|
68
|
|
-// */
|
|
69
|
|
-// const WebStorage = class WebStorage {
|
|
70
|
|
-// storage
|
|
71
|
|
-// prefixKey
|
|
72
|
|
-// encryption
|
|
73
|
|
-// hasEncrypt
|
|
74
|
|
-//
|
|
75
|
|
-// /**
|
|
76
|
|
-// *
|
|
77
|
|
-// * @param {*} storage
|
|
78
|
|
-// */
|
|
79
|
|
-// constructor() {
|
|
80
|
|
-// this.storage = storage;
|
|
81
|
|
-// this.prefixKey = prefixKey;
|
|
82
|
|
-// this.encryption = encryption;
|
|
83
|
|
-// this.hasEncrypt = hasEncrypt;
|
|
84
|
|
-// }
|
|
85
|
|
-//
|
|
86
|
|
-// getKey(key) {
|
|
87
|
|
-// return `${ this.prefixKey }${ key }`.toUpperCase();
|
|
88
|
|
-// }
|
|
89
|
|
-//
|
|
90
|
|
-// /**
|
|
91
|
|
-// *
|
|
92
|
|
-// * Set cache
|
|
93
|
|
-// * @param {string} key
|
|
94
|
|
-// * @param {*} value
|
|
95
|
|
-// * @param {*} expire
|
|
96
|
|
-// * @expire Expiration time in seconds
|
|
97
|
|
-// * @memberof Cache
|
|
98
|
|
-// */
|
|
99
|
|
-// set(key, value, expire = timeout) {
|
|
100
|
|
-// const stringData = JSON.stringify({
|
|
101
|
|
-// value,
|
|
102
|
|
-// time: Date.now(),
|
|
103
|
|
-// expire: !isNullOrUnDef(expire) ? new Date().getTime() + expire * 1000 : null,
|
|
104
|
|
-// });
|
|
105
|
|
-// const stringifyValue = this.hasEncrypt
|
|
106
|
|
-// ? this.encryption.encryptByAES(stringData)
|
|
107
|
|
-// : stringData;
|
|
108
|
|
-// this.storage.setItem(this.getKey(key), stringifyValue);
|
|
109
|
|
-// }
|
|
110
|
|
-//
|
|
111
|
|
-// /**
|
|
112
|
|
-// *Read cache
|
|
113
|
|
-// * @param {string} key
|
|
114
|
|
-// * @param {any} [def=null] def
|
|
115
|
|
-// * @memberof Cache
|
|
116
|
|
-// */
|
|
117
|
|
-// get(key, def = null) {
|
|
118
|
|
-// const val = this.storage.getItem(this.getKey(key));
|
|
119
|
|
-// if (!val) return def;
|
|
120
|
|
-//
|
|
121
|
|
-// try {
|
|
122
|
|
-// const decVal = this.hasEncrypt ? this.encryption.decryptByAES(val) : val;
|
|
123
|
|
-// const data = JSON.parse(decVal);
|
|
124
|
|
-// const { value, expire } = data;
|
|
125
|
|
-// if (isNullOrUnDef(expire) || expire >= new Date().getTime()) {
|
|
126
|
|
-// return value;
|
|
127
|
|
-// }
|
|
128
|
|
-// this.remove(key);
|
|
129
|
|
-// } catch (e) {
|
|
130
|
|
-// return def;
|
|
131
|
|
-// }
|
|
132
|
|
-// }
|
|
133
|
|
-//
|
|
134
|
|
-// /**
|
|
135
|
|
-// * Delete cache based on key
|
|
136
|
|
-// * @param {string} key
|
|
137
|
|
-// * @memberof Cache
|
|
138
|
|
-// */
|
|
139
|
|
-// remove(key) {
|
|
140
|
|
-// this.storage.removeItem(this.getKey(key));
|
|
141
|
|
-// }
|
|
142
|
|
-//
|
|
143
|
|
-// /**
|
|
144
|
|
-// * Delete all caches of this instance
|
|
145
|
|
-// */
|
|
146
|
|
-// clear() {
|
|
147
|
|
-// this.storage.clear();
|
|
148
|
|
-// }
|
|
149
|
|
-// };
|
|
150
|
|
-// return new WebStorage();
|
|
151
|
|
-// }
|
|
152
|
|
-
|
|
153
|
1
|
const GLOBAL_STORAGE_KEY = (() => {
|
|
154
|
|
- const isDev = location.href.includes('dev=1')
|
|
155
|
2
|
const DEVELOPMENT = 'DEVELOPMENT'
|
|
156
|
3
|
const PRODUCTION = 'PRODUCTION'
|
|
157
|
|
- return `UNDEFINED__${ isDev ? DEVELOPMENT : PRODUCTION }__2.7.1__COMMON__LOCAL__KEY__`
|
|
|
4
|
+ return `UNDEFINED__${ isDEV ? DEVELOPMENT : PRODUCTION }__2.7.1__COMMON__LOCAL__KEY__`
|
|
158
|
5
|
})()
|
|
159
|
6
|
|
|
160
|
7
|
const GLOBAL_TOKEN = (() => {
|
|
161
|
|
- return JSON.parse(localStorage.getItem(GLOBAL_STORAGE_KEY)).value.JWT_TOKEN.value
|
|
|
8
|
+ const ls = createStorage({ storage: localStorage })
|
|
|
9
|
+ /**
|
|
|
10
|
+ * @description user info
|
|
|
11
|
+ * @type {{JWT_TOKEN: {value: string}}}
|
|
|
12
|
+ */
|
|
|
13
|
+ const common = ls.get(GLOBAL_STORAGE_KEY)
|
|
|
14
|
+ return common.JWT_TOKEN.value
|
|
162
|
15
|
})()
|
|
163
|
16
|
|
|
164
|
17
|
const GLOBAL_WS_URL = (() => {
|
...
|
...
|
|