cloudcc-ccdk 0.8.7 → 0.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +589 -574
- package/lib/ccdk.js +1675 -1597
- package/lib/ccdk.min.js +1 -1
- package/package.json +33 -33
package/lib/ccdk.js
CHANGED
|
@@ -5,69 +5,69 @@ import { cloneDeep } from 'lodash';
|
|
|
5
5
|
import Cookies from 'js-cookie';
|
|
6
6
|
import { Message, MessageBox, Notification } from 'element-ui';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* 加密
|
|
10
|
-
* @param {String} data 数据
|
|
11
|
-
* @param {String} key 密钥
|
|
12
|
-
* @param {String} iv 偏移量
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
function getAesString(data, key, iv) {
|
|
16
|
-
key = CryptoJS.enc.Utf8.parse(key);
|
|
17
|
-
iv = CryptoJS.enc.Utf8.parse(iv);
|
|
18
|
-
let encrypted = CryptoJS.AES.encrypt(data, key, {
|
|
19
|
-
iv: iv,
|
|
20
|
-
padding: CryptoJS.pad.Pkcs7,
|
|
21
|
-
});
|
|
22
|
-
return encrypted.toString(); //返回的是base64格式的密文
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 解密
|
|
27
|
-
* @param {String} encrypted 密文
|
|
28
|
-
* @param {String} key 密钥
|
|
29
|
-
* @param {String} iv 偏移量
|
|
30
|
-
* @returns
|
|
31
|
-
*/
|
|
32
|
-
function getDAesString(encrypted, key, iv) {
|
|
33
|
-
key = CryptoJS.enc.Utf8.parse(key);
|
|
34
|
-
iv = CryptoJS.enc.Utf8.parse(iv);
|
|
35
|
-
let decrypted = CryptoJS.AES.decrypt(encrypted, key, {
|
|
36
|
-
iv: iv,
|
|
37
|
-
padding: CryptoJS.pad.Pkcs7,
|
|
38
|
-
});
|
|
39
|
-
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* CryptoJS加密
|
|
44
|
-
* @param {String} data 数据
|
|
45
|
-
* @param {String} key 密钥
|
|
46
|
-
* @param {String} iv 偏移量
|
|
47
|
-
* @returns 加密的数据
|
|
48
|
-
*/
|
|
49
|
-
function encrypt(data, key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", iv = 1) {
|
|
50
|
-
data = JSON.stringify(data);
|
|
51
|
-
var encrypted = getAesString(data, key, iv); //密文
|
|
52
|
-
return encrypted;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* CryptoJS解密
|
|
57
|
-
* @param {String} data 加密的数据
|
|
58
|
-
* @param {String} key 密钥
|
|
59
|
-
* @param {String} iv 偏移量
|
|
60
|
-
* @returns 解密的数据
|
|
61
|
-
*/
|
|
62
|
-
function decrypt(data, key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", iv = 1) {
|
|
63
|
-
try {
|
|
64
|
-
var decryptedStr = getDAesString(data, key, iv);
|
|
65
|
-
if (!decryptedStr) return null
|
|
66
|
-
return JSON.parse(decryptedStr);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.trace("解密密码错误", error);
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
8
|
+
/**
|
|
9
|
+
* 加密
|
|
10
|
+
* @param {String} data 数据
|
|
11
|
+
* @param {String} key 密钥
|
|
12
|
+
* @param {String} iv 偏移量
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
function getAesString(data, key, iv) {
|
|
16
|
+
key = CryptoJS.enc.Utf8.parse(key);
|
|
17
|
+
iv = CryptoJS.enc.Utf8.parse(iv);
|
|
18
|
+
let encrypted = CryptoJS.AES.encrypt(data, key, {
|
|
19
|
+
iv: iv,
|
|
20
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
21
|
+
});
|
|
22
|
+
return encrypted.toString(); //返回的是base64格式的密文
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 解密
|
|
27
|
+
* @param {String} encrypted 密文
|
|
28
|
+
* @param {String} key 密钥
|
|
29
|
+
* @param {String} iv 偏移量
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
function getDAesString(encrypted, key, iv) {
|
|
33
|
+
key = CryptoJS.enc.Utf8.parse(key);
|
|
34
|
+
iv = CryptoJS.enc.Utf8.parse(iv);
|
|
35
|
+
let decrypted = CryptoJS.AES.decrypt(encrypted, key, {
|
|
36
|
+
iv: iv,
|
|
37
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
38
|
+
});
|
|
39
|
+
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* CryptoJS加密
|
|
44
|
+
* @param {String} data 数据
|
|
45
|
+
* @param {String} key 密钥
|
|
46
|
+
* @param {String} iv 偏移量
|
|
47
|
+
* @returns 加密的数据
|
|
48
|
+
*/
|
|
49
|
+
function encrypt(data, key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", iv = 1) {
|
|
50
|
+
data = JSON.stringify(data);
|
|
51
|
+
var encrypted = getAesString(data, key, iv); //密文
|
|
52
|
+
return encrypted;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* CryptoJS解密
|
|
57
|
+
* @param {String} data 加密的数据
|
|
58
|
+
* @param {String} key 密钥
|
|
59
|
+
* @param {String} iv 偏移量
|
|
60
|
+
* @returns 解密的数据
|
|
61
|
+
*/
|
|
62
|
+
function decrypt(data, key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", iv = 1) {
|
|
63
|
+
try {
|
|
64
|
+
var decryptedStr = getDAesString(data, key, iv);
|
|
65
|
+
if (!decryptedStr) return null
|
|
66
|
+
return JSON.parse(decryptedStr);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.trace("解密密码错误", error);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
var Crypto = /*#__PURE__*/Object.freeze({
|
|
@@ -76,27 +76,27 @@ var Crypto = /*#__PURE__*/Object.freeze({
|
|
|
76
76
|
decrypt: decrypt
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
// 当前应用存储标识
|
|
80
|
-
const APPLICATION_DETAIL = 'applicaton_current';
|
|
81
|
-
/**
|
|
82
|
-
* 获得当前访问的应用对象
|
|
83
|
-
*/
|
|
84
|
-
function getApplicaton() {
|
|
85
|
-
let detail = localStorage.getItem(Crypto.encrypt(APPLICATION_DETAIL));
|
|
86
|
-
if (detail) {
|
|
87
|
-
return JSON.parse(detail)
|
|
88
|
-
}
|
|
89
|
-
return ''
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* 设置应用对象信息
|
|
94
|
-
* @param {object} detail 应用对象
|
|
95
|
-
*/
|
|
96
|
-
function setApplication(detail = '') {
|
|
97
|
-
if (detail) {
|
|
98
|
-
localStorage.setItem(Crypto.encrypt(APPLICATION_DETAIL), JSON.stringify(detail));
|
|
99
|
-
}
|
|
79
|
+
// 当前应用存储标识
|
|
80
|
+
const APPLICATION_DETAIL = 'applicaton_current';
|
|
81
|
+
/**
|
|
82
|
+
* 获得当前访问的应用对象
|
|
83
|
+
*/
|
|
84
|
+
function getApplicaton() {
|
|
85
|
+
let detail = localStorage.getItem(Crypto.encrypt(APPLICATION_DETAIL));
|
|
86
|
+
if (detail) {
|
|
87
|
+
return JSON.parse(detail)
|
|
88
|
+
}
|
|
89
|
+
return ''
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 设置应用对象信息
|
|
94
|
+
* @param {object} detail 应用对象
|
|
95
|
+
*/
|
|
96
|
+
function setApplication(detail = '') {
|
|
97
|
+
if (detail) {
|
|
98
|
+
localStorage.setItem(Crypto.encrypt(APPLICATION_DETAIL), JSON.stringify(detail));
|
|
99
|
+
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
var CCApplication = /*#__PURE__*/Object.freeze({
|
|
@@ -105,44 +105,44 @@ var CCApplication = /*#__PURE__*/Object.freeze({
|
|
|
105
105
|
setApplication: setApplication
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
-
/**
|
|
109
|
-
* 获得一级域名
|
|
110
|
-
* 比如:xx.com、xx.cn、xx.com.cn、xx.net.cn、xx.org.cn
|
|
111
|
-
*/
|
|
112
|
-
function getDomain() {
|
|
113
|
-
// 倒数第二位域名
|
|
114
|
-
let lastTow = document.domain.split('.').slice(-2, -1)[0];
|
|
115
|
-
// 如果倒数第二位是这些关键字,那么需要取倒数三位域名
|
|
116
|
-
if (lastTow == 'com' || lastTow == 'org' || lastTow == 'net') {
|
|
117
|
-
return "." + document.domain.split('.').slice(-3).join('.')
|
|
118
|
-
} else {
|
|
119
|
-
return "." + document.domain.split('.').slice(-2).join('.')
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 获得16位标识
|
|
125
|
-
* @returns 16位标识
|
|
126
|
-
*/
|
|
127
|
-
function getUuid() {
|
|
128
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
129
|
-
var r = (Math.random() * 16) | 0,
|
|
130
|
-
v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
131
|
-
return v.toString(16);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function getBinding() {
|
|
136
|
-
let binding = window.$CCDK.CCToken.getToken();
|
|
137
|
-
if (!binding) {
|
|
138
|
-
window.open(window.Glod.LOGIN_URL, '_self');
|
|
139
|
-
// this.reLogin();
|
|
140
|
-
} else {
|
|
141
|
-
// 刷新有效期,而且有的老功能,依赖这个binding了
|
|
142
|
-
Cookies.set('binding', binding, { expires: 1 / 12 });
|
|
143
|
-
Cookies.set('JSESSIONID', binding, { expires: 1 / 12 });
|
|
144
|
-
}
|
|
145
|
-
return binding
|
|
108
|
+
/**
|
|
109
|
+
* 获得一级域名
|
|
110
|
+
* 比如:xx.com、xx.cn、xx.com.cn、xx.net.cn、xx.org.cn
|
|
111
|
+
*/
|
|
112
|
+
function getDomain() {
|
|
113
|
+
// 倒数第二位域名
|
|
114
|
+
let lastTow = document.domain.split('.').slice(-2, -1)[0];
|
|
115
|
+
// 如果倒数第二位是这些关键字,那么需要取倒数三位域名
|
|
116
|
+
if (lastTow == 'com' || lastTow == 'org' || lastTow == 'net') {
|
|
117
|
+
return "." + document.domain.split('.').slice(-3).join('.')
|
|
118
|
+
} else {
|
|
119
|
+
return "." + document.domain.split('.').slice(-2).join('.')
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 获得16位标识
|
|
125
|
+
* @returns 16位标识
|
|
126
|
+
*/
|
|
127
|
+
function getUuid() {
|
|
128
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
129
|
+
var r = (Math.random() * 16) | 0,
|
|
130
|
+
v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
131
|
+
return v.toString(16);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function getBinding() {
|
|
136
|
+
let binding = window.$CCDK.CCToken.getToken();
|
|
137
|
+
if (!binding) {
|
|
138
|
+
window.open(window.Glod.LOGIN_URL, '_self');
|
|
139
|
+
// this.reLogin();
|
|
140
|
+
} else {
|
|
141
|
+
// 刷新有效期,而且有的老功能,依赖这个binding了
|
|
142
|
+
Cookies.set('binding', binding, { expires: 1 / 12 });
|
|
143
|
+
Cookies.set('JSESSIONID', binding, { expires: 1 / 12 });
|
|
144
|
+
}
|
|
145
|
+
return binding
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
var CCUtils = /*#__PURE__*/Object.freeze({
|
|
@@ -152,453 +152,453 @@ var CCUtils = /*#__PURE__*/Object.freeze({
|
|
|
152
152
|
getBinding: getBinding
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
-
const toStr = Object.prototype.toString;
|
|
156
|
-
|
|
157
|
-
const TypeEnum = {
|
|
158
|
-
'FUNCTION': '[object Function]',
|
|
159
|
-
'ARRAY': '[object Array]',
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// 是否是一个函数
|
|
163
|
-
const isFn = (value) => toStr.call(value) === TypeEnum.FUNCTION;
|
|
164
|
-
|
|
165
|
-
// 是否是生产环境
|
|
166
|
-
const isProduction = () => true ;
|
|
167
|
-
|
|
168
|
-
// 延时
|
|
169
|
-
const delay = (waitTime = 1000) => new Promise(resolve => setTimeout(resolve, waitTime));
|
|
170
|
-
|
|
171
|
-
// 是否是超时请求
|
|
172
|
-
const isTimeout = (error = {
|
|
173
|
-
code: '',
|
|
174
|
-
message: ''
|
|
175
|
-
}) => {
|
|
176
|
-
return error.code === AxiosError.ECONNABORTED && error.message.includes('timeout')
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// 格式换请求体
|
|
180
|
-
const formateData = data => {
|
|
181
|
-
return {
|
|
182
|
-
head: {
|
|
183
|
-
appType: "lightning-main",
|
|
184
|
-
appVersion: "1.1.1",
|
|
185
|
-
accessToken: getBinding(),
|
|
186
|
-
source: "lightning-main"
|
|
187
|
-
},
|
|
188
|
-
body: {
|
|
189
|
-
...data
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
* 深度合并
|
|
195
|
-
* @param {object} source 合并的基础对象
|
|
196
|
-
* @param {object} target 新的数据
|
|
197
|
-
*/
|
|
198
|
-
const deepMerge = (source, target) => {
|
|
199
|
-
const res = cloneDeep(source);
|
|
200
|
-
for (let key in target) {
|
|
201
|
-
if (target.hasOwnProperty(key)) {
|
|
202
|
-
res[key] = isObject(target[key])
|
|
203
|
-
? deepMerge(res[key], target[key])
|
|
204
|
-
: target[key];
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return res
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* LRU算法
|
|
212
|
-
* @param {number} capacity 最大缓存容量
|
|
213
|
-
*/
|
|
214
|
-
const LRUCache = function (capacity) {
|
|
215
|
-
this.capacity = capacity;
|
|
216
|
-
this.cache = new Map();
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* 获取指定key的缓存
|
|
221
|
-
* @param {string} key 缓存的key
|
|
222
|
-
*/
|
|
223
|
-
LRUCache.prototype.get = function (key) {
|
|
224
|
-
var cacheTemp = this.cache,
|
|
225
|
-
curTemp = cacheTemp.get(key);
|
|
226
|
-
if (curTemp || curTemp === 0) {
|
|
227
|
-
cacheTemp.delete(key);
|
|
228
|
-
cacheTemp.set(key, curTemp);
|
|
229
|
-
return curTemp
|
|
230
|
-
}
|
|
231
|
-
return null
|
|
155
|
+
const toStr = Object.prototype.toString;
|
|
156
|
+
|
|
157
|
+
const TypeEnum = {
|
|
158
|
+
'FUNCTION': '[object Function]',
|
|
159
|
+
'ARRAY': '[object Array]',
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// 是否是一个函数
|
|
163
|
+
const isFn = (value) => toStr.call(value) === TypeEnum.FUNCTION;
|
|
164
|
+
|
|
165
|
+
// 是否是生产环境
|
|
166
|
+
const isProduction = () => true ;
|
|
167
|
+
|
|
168
|
+
// 延时
|
|
169
|
+
const delay = (waitTime = 1000) => new Promise(resolve => setTimeout(resolve, waitTime));
|
|
170
|
+
|
|
171
|
+
// 是否是超时请求
|
|
172
|
+
const isTimeout = (error = {
|
|
173
|
+
code: '',
|
|
174
|
+
message: ''
|
|
175
|
+
}) => {
|
|
176
|
+
return error.code === AxiosError.ECONNABORTED && error.message.includes('timeout')
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// 格式换请求体
|
|
180
|
+
const formateData = data => {
|
|
181
|
+
return {
|
|
182
|
+
head: {
|
|
183
|
+
appType: "lightning-main",
|
|
184
|
+
appVersion: "1.1.1",
|
|
185
|
+
accessToken: getBinding(),
|
|
186
|
+
source: "lightning-main"
|
|
187
|
+
},
|
|
188
|
+
body: {
|
|
189
|
+
...data
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* 深度合并
|
|
195
|
+
* @param {object} source 合并的基础对象
|
|
196
|
+
* @param {object} target 新的数据
|
|
197
|
+
*/
|
|
198
|
+
const deepMerge = (source, target) => {
|
|
199
|
+
const res = cloneDeep(source);
|
|
200
|
+
for (let key in target) {
|
|
201
|
+
if (target.hasOwnProperty(key)) {
|
|
202
|
+
res[key] = isObject(target[key])
|
|
203
|
+
? deepMerge(res[key], target[key])
|
|
204
|
+
: target[key];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return res
|
|
232
208
|
};
|
|
233
209
|
|
|
234
|
-
/**
|
|
235
|
-
*
|
|
236
|
-
* @param {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
requestInterceptors,
|
|
272
|
-
requestInterceptorsCatch,
|
|
273
|
-
responseInterceptors,
|
|
274
|
-
responseInterceptorsCatch,
|
|
275
|
-
} = transform;
|
|
276
|
-
// 请求拦截器
|
|
277
|
-
this.axiosInstance.interceptors.request.use(requestInterceptors, undefined);
|
|
278
|
-
// 请求拦截器错误处理
|
|
279
|
-
requestInterceptorsCatch
|
|
280
|
-
&& isFn(requestInterceptorsCatch)
|
|
281
|
-
&& this.axiosInstance.interceptors.request.use(undefined, requestInterceptorsCatch);
|
|
282
|
-
|
|
283
|
-
// 响应拦截器
|
|
284
|
-
this.axiosInstance.interceptors.response.use(responseInterceptors, undefined);
|
|
285
|
-
// 响应拦截器错误处理
|
|
286
|
-
responseInterceptorsCatch
|
|
287
|
-
&& isFn(responseInterceptorsCatch)
|
|
288
|
-
&& this.axiosInstance.interceptors.response.use(undefined, (error) => {
|
|
289
|
-
return responseInterceptorsCatch(this.axiosInstance, error)
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
get(config, options = {}) {
|
|
293
|
-
return this.request({ ...config, method: 'GET', }, options)
|
|
294
|
-
}
|
|
295
|
-
post(config, options = {}) {
|
|
296
|
-
const { envType } = options;
|
|
297
|
-
// 公有云专用接口,在私有云不请求
|
|
298
|
-
if ("public" == envType && "private" == window.Glod["ENV_TYPE"]) {
|
|
299
|
-
return new Promise(() => { })
|
|
300
|
-
}
|
|
301
|
-
// 私有云专用接口,在公有云不请求
|
|
302
|
-
if ("private" == envType && "private" != window.Glod["ENV_TYPE"]) {
|
|
303
|
-
return new Promise(() => { })
|
|
304
|
-
}
|
|
305
|
-
return this.request({ ...config, method: 'POST', }, options)
|
|
306
|
-
}
|
|
307
|
-
postFormat(config, options = {}) {
|
|
308
|
-
return this.request({ ...config, method: 'POST', data: formateData(config.data) }, options)
|
|
309
|
-
}
|
|
310
|
-
postParams(config, options = {}) {
|
|
311
|
-
return this.request({ ...config, method: 'POST', params: config.data }, options)
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// FIXME:如果初始化时配置了重试那么所有get接口都重试了
|
|
315
|
-
// options是接口级定义的参数
|
|
316
|
-
request(config, options) {
|
|
317
|
-
const transform = this.getTransform();
|
|
318
|
-
const conf = config,
|
|
319
|
-
{ requestOptions } = this.options;
|
|
320
|
-
requestOptions.cache = false;
|
|
321
|
-
requestOptions.cacheKey = '';
|
|
322
|
-
requestOptions.retryRequest = {
|
|
323
|
-
isOpenRetry: false,
|
|
324
|
-
count: 5,
|
|
325
|
-
waitTime: 1000
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
const opt = Object.assign({}, requestOptions, options);
|
|
329
|
-
conf.requestOptions = opt;
|
|
330
|
-
|
|
331
|
-
const retPromise = new Promise((resolve, reject) => {
|
|
332
|
-
this.axiosInstance(conf)
|
|
333
|
-
.then(res => {
|
|
334
|
-
const { transformResponseHook } = transform;
|
|
335
|
-
if (transformResponseHook && isFn(transformResponseHook)) {
|
|
336
|
-
try {
|
|
337
|
-
const ret = transformResponseHook(res, opt, this.cachePool);
|
|
338
|
-
resolve(ret);
|
|
339
|
-
} catch (err) {
|
|
340
|
-
reject(err || new Error('request error!'));
|
|
341
|
-
}
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
resolve(res);
|
|
345
|
-
})
|
|
346
|
-
.catch(err => {
|
|
347
|
-
reject(err);
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
// 缓存
|
|
351
|
-
retPromise.cache = (callback) => {
|
|
352
|
-
const { cache, cacheKey } = opt;
|
|
353
|
-
const cacheData = (cache && this.cachePool.get([cacheKey]));
|
|
354
|
-
callback(cacheData ? cacheData : null);
|
|
355
|
-
return retPromise
|
|
356
|
-
};
|
|
357
|
-
return retPromise
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// 使用全局弹窗进行提示
|
|
362
|
-
const createErrorModal = (response, options) => {
|
|
363
|
-
const { message } = options;
|
|
364
|
-
let temp;
|
|
365
|
-
if (response.name === 'AxiosError') {
|
|
366
|
-
temp = response.response;
|
|
367
|
-
temp.data.returnInfo = response.returnInfo || message || temp.error || '';
|
|
368
|
-
temp.data.returnCode = response.code || temp.status;
|
|
369
|
-
temp.data.requestId = response.config.headers.requestId;
|
|
370
|
-
} else {
|
|
371
|
-
temp = response;
|
|
372
|
-
temp.data.requestId = response.config.headers.requestId;
|
|
373
|
-
}
|
|
374
|
-
// 存在全局错误弹窗时才调用
|
|
375
|
-
isFn(Vue.prototype.$ErrorDialog) && Vue.prototype.$ErrorDialog({
|
|
376
|
-
response: temp
|
|
377
|
-
});
|
|
210
|
+
/**
|
|
211
|
+
* LRU算法
|
|
212
|
+
* @param {number} capacity 最大缓存容量
|
|
213
|
+
*/
|
|
214
|
+
const LRUCache = function (capacity) {
|
|
215
|
+
this.capacity = capacity;
|
|
216
|
+
this.cache = new Map();
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* 获取指定key的缓存
|
|
221
|
+
* @param {string} key 缓存的key
|
|
222
|
+
*/
|
|
223
|
+
LRUCache.prototype.get = function (key) {
|
|
224
|
+
var cacheTemp = this.cache,
|
|
225
|
+
curTemp = cacheTemp.get(key);
|
|
226
|
+
if (curTemp || curTemp === 0) {
|
|
227
|
+
cacheTemp.delete(key);
|
|
228
|
+
cacheTemp.set(key, curTemp);
|
|
229
|
+
return curTemp
|
|
230
|
+
}
|
|
231
|
+
return null
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* 指定key添加缓存
|
|
236
|
+
* @param {string} key 缓存的key
|
|
237
|
+
* @param {object} value 缓存的值
|
|
238
|
+
*/
|
|
239
|
+
LRUCache.prototype.put = function (key, value) {
|
|
240
|
+
var cacheTemp = this.cache;
|
|
241
|
+
if (cacheTemp.get(key)) {
|
|
242
|
+
cacheTemp.delete(key);
|
|
243
|
+
} else if (cacheTemp.size >= this.capacity) {
|
|
244
|
+
cacheTemp.delete(cacheTemp.keys().next().value);
|
|
245
|
+
}
|
|
246
|
+
cacheTemp.set(key, value);
|
|
378
247
|
};
|
|
379
248
|
|
|
249
|
+
class CCAxios {
|
|
250
|
+
constructor(opt) {
|
|
251
|
+
this.options = opt;
|
|
252
|
+
this.axiosInstance = axios.create(opt);
|
|
253
|
+
this.setupInterceptors();
|
|
254
|
+
this.cachePool = new LRUCache(20);
|
|
255
|
+
// FIXME:区分构造函数参数和接口级别的参数
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
//获取拦截器
|
|
259
|
+
getTransform() {
|
|
260
|
+
const { transform } = this.options;
|
|
261
|
+
return transform;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
//准备拦截器
|
|
265
|
+
setupInterceptors() {
|
|
266
|
+
const transform = this.getTransform();
|
|
267
|
+
if (!transform) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const {
|
|
271
|
+
requestInterceptors,
|
|
272
|
+
requestInterceptorsCatch,
|
|
273
|
+
responseInterceptors,
|
|
274
|
+
responseInterceptorsCatch,
|
|
275
|
+
} = transform;
|
|
276
|
+
// 请求拦截器
|
|
277
|
+
this.axiosInstance.interceptors.request.use(requestInterceptors, undefined);
|
|
278
|
+
// 请求拦截器错误处理
|
|
279
|
+
requestInterceptorsCatch
|
|
280
|
+
&& isFn(requestInterceptorsCatch)
|
|
281
|
+
&& this.axiosInstance.interceptors.request.use(undefined, requestInterceptorsCatch);
|
|
282
|
+
|
|
283
|
+
// 响应拦截器
|
|
284
|
+
this.axiosInstance.interceptors.response.use(responseInterceptors, undefined);
|
|
285
|
+
// 响应拦截器错误处理
|
|
286
|
+
responseInterceptorsCatch
|
|
287
|
+
&& isFn(responseInterceptorsCatch)
|
|
288
|
+
&& this.axiosInstance.interceptors.response.use(undefined, (error) => {
|
|
289
|
+
return responseInterceptorsCatch(this.axiosInstance, error)
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
get(config, options = {}) {
|
|
293
|
+
return this.request({ ...config, method: 'GET', }, options)
|
|
294
|
+
}
|
|
295
|
+
post(config, options = {}) {
|
|
296
|
+
const { envType } = options;
|
|
297
|
+
// 公有云专用接口,在私有云不请求
|
|
298
|
+
if ("public" == envType && "private" == window.Glod["ENV_TYPE"]) {
|
|
299
|
+
return new Promise(() => { })
|
|
300
|
+
}
|
|
301
|
+
// 私有云专用接口,在公有云不请求
|
|
302
|
+
if ("private" == envType && "private" != window.Glod["ENV_TYPE"]) {
|
|
303
|
+
return new Promise(() => { })
|
|
304
|
+
}
|
|
305
|
+
return this.request({ ...config, method: 'POST', }, options)
|
|
306
|
+
}
|
|
307
|
+
postFormat(config, options = {}) {
|
|
308
|
+
return this.request({ ...config, method: 'POST', data: formateData(config.data) }, options)
|
|
309
|
+
}
|
|
310
|
+
postParams(config, options = {}) {
|
|
311
|
+
return this.request({ ...config, method: 'POST', params: config.data }, options)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// FIXME:如果初始化时配置了重试那么所有get接口都重试了
|
|
315
|
+
// options是接口级定义的参数
|
|
316
|
+
request(config, options) {
|
|
317
|
+
const transform = this.getTransform();
|
|
318
|
+
const conf = config,
|
|
319
|
+
{ requestOptions } = this.options;
|
|
320
|
+
requestOptions.cache = false;
|
|
321
|
+
requestOptions.cacheKey = '';
|
|
322
|
+
requestOptions.retryRequest = {
|
|
323
|
+
isOpenRetry: false,
|
|
324
|
+
count: 5,
|
|
325
|
+
waitTime: 1000
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const opt = Object.assign({}, requestOptions, options);
|
|
329
|
+
conf.requestOptions = opt;
|
|
330
|
+
|
|
331
|
+
const retPromise = new Promise((resolve, reject) => {
|
|
332
|
+
this.axiosInstance(conf)
|
|
333
|
+
.then(res => {
|
|
334
|
+
const { transformResponseHook } = transform;
|
|
335
|
+
if (transformResponseHook && isFn(transformResponseHook)) {
|
|
336
|
+
try {
|
|
337
|
+
const ret = transformResponseHook(res, opt, this.cachePool);
|
|
338
|
+
resolve(ret);
|
|
339
|
+
} catch (err) {
|
|
340
|
+
reject(err || new Error('request error!'));
|
|
341
|
+
}
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
resolve(res);
|
|
345
|
+
})
|
|
346
|
+
.catch(err => {
|
|
347
|
+
reject(err);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
// 缓存
|
|
351
|
+
retPromise.cache = (callback) => {
|
|
352
|
+
const { cache, cacheKey } = opt;
|
|
353
|
+
const cacheData = (cache && this.cachePool.get([cacheKey]));
|
|
354
|
+
callback(cacheData ? cacheData : null);
|
|
355
|
+
return retPromise
|
|
356
|
+
};
|
|
357
|
+
return retPromise
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// 使用全局弹窗进行提示
|
|
362
|
+
const createErrorModal = (response, options) => {
|
|
363
|
+
const { message } = options;
|
|
364
|
+
let temp;
|
|
365
|
+
if (response.name === 'AxiosError') {
|
|
366
|
+
temp = response.response;
|
|
367
|
+
temp.data.returnInfo = response.returnInfo || message || temp.error || '';
|
|
368
|
+
temp.data.returnCode = response.code || temp.status;
|
|
369
|
+
temp.data.requestId = response.config.headers.requestId;
|
|
370
|
+
} else {
|
|
371
|
+
temp = response;
|
|
372
|
+
temp.data.requestId = response.config.headers.requestId;
|
|
373
|
+
}
|
|
374
|
+
// 存在全局错误弹窗时才调用
|
|
375
|
+
isFn(Vue.prototype.$ErrorDialog) && Vue.prototype.$ErrorDialog({
|
|
376
|
+
response: temp
|
|
377
|
+
});
|
|
378
|
+
};
|
|
379
|
+
|
|
380
380
|
const createMessage = Message;
|
|
381
381
|
|
|
382
|
-
// 需要上报的errorType
|
|
382
|
+
// 需要上报的errorType
|
|
383
383
|
const needReportErrorType = ['901', '999'];
|
|
384
384
|
|
|
385
|
-
function checkStatus(error, status, msg, errorMessageMode = 'modal') {
|
|
386
|
-
// const errorMsg = errorMsgMap[status] || {
|
|
387
|
-
// label: "message.error.object.contactadministrators"
|
|
388
|
-
// }
|
|
389
|
-
// let errMessage = '',
|
|
390
|
-
// label = '';
|
|
391
|
-
|
|
392
|
-
// label = errorMsg.label;
|
|
393
|
-
// [400, 401].includes(status) && msg && (label = msg)
|
|
394
|
-
let errMessage = "message.error.object.contactadministrators"; //系统异常,请联系系统管理员获取帮助。
|
|
395
|
-
|
|
396
|
-
if (status === 401) {
|
|
397
|
-
//重新登录相关逻辑
|
|
398
|
-
window.open(window.Glod.LOGIN_URL, '_self');
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
{
|
|
402
|
-
if (errorMessageMode === 'modal') {
|
|
403
|
-
createErrorModal(error, { message: errMessage });
|
|
404
|
-
} else if (errorMessageMode === 'message') {
|
|
405
|
-
createMessage.error(errMessage);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* 接口请求重试
|
|
412
|
-
* @param {object} AxiosInstance实例
|
|
413
|
-
* @param {error} AxiosError对象
|
|
414
|
-
*/
|
|
415
|
-
const retry = async (instance, error) => {
|
|
416
|
-
const { config } = error,
|
|
417
|
-
{ waitTime, count = 5} = config.requestOptions || {};
|
|
418
|
-
config.__retryCount = config.__retryCount || 0;
|
|
419
|
-
if(count <= config.__retryCount ) {
|
|
420
|
-
return Promise.reject(error)
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
config.__retryCount++;
|
|
424
|
-
|
|
425
|
-
await delay(waitTime);
|
|
426
|
-
//请求返回后config的header不正确造成重试请求失败,删除返回headers采用默认headers
|
|
427
|
-
delete config.headers;
|
|
428
|
-
return instance(config)
|
|
385
|
+
function checkStatus(error, status, msg, errorMessageMode = 'modal') {
|
|
386
|
+
// const errorMsg = errorMsgMap[status] || {
|
|
387
|
+
// label: "message.error.object.contactadministrators"
|
|
388
|
+
// }
|
|
389
|
+
// let errMessage = '',
|
|
390
|
+
// label = '';
|
|
391
|
+
|
|
392
|
+
// label = errorMsg.label;
|
|
393
|
+
// [400, 401].includes(status) && msg && (label = msg)
|
|
394
|
+
let errMessage = "message.error.object.contactadministrators"; //系统异常,请联系系统管理员获取帮助。
|
|
395
|
+
|
|
396
|
+
if (status === 401) {
|
|
397
|
+
//重新登录相关逻辑
|
|
398
|
+
window.open(window.Glod.LOGIN_URL, '_self');
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
{
|
|
402
|
+
if (errorMessageMode === 'modal') {
|
|
403
|
+
createErrorModal(error, { message: errMessage });
|
|
404
|
+
} else if (errorMessageMode === 'message') {
|
|
405
|
+
createMessage.error(errMessage);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* 接口请求重试
|
|
412
|
+
* @param {object} AxiosInstance实例
|
|
413
|
+
* @param {error} AxiosError对象
|
|
414
|
+
*/
|
|
415
|
+
const retry = async (instance, error) => {
|
|
416
|
+
const { config } = error,
|
|
417
|
+
{ waitTime, count = 5} = config.requestOptions || {};
|
|
418
|
+
config.__retryCount = config.__retryCount || 0;
|
|
419
|
+
if(count <= config.__retryCount ) {
|
|
420
|
+
return Promise.reject(error)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
config.__retryCount++;
|
|
424
|
+
|
|
425
|
+
await delay(waitTime);
|
|
426
|
+
//请求返回后config的header不正确造成重试请求失败,删除返回headers采用默认headers
|
|
427
|
+
delete config.headers;
|
|
428
|
+
return instance(config)
|
|
429
429
|
};
|
|
430
430
|
|
|
431
|
-
const transform = {
|
|
432
|
-
// 请求拦截器
|
|
433
|
-
requestInterceptors(config) {
|
|
434
|
-
// 设置日志请求头信息
|
|
435
|
-
config.headers.requestId = window.$CCDK.CCUtils.getUuid();
|
|
436
|
-
config.headers.requestIdProducer = "browser";
|
|
437
|
-
config.headers.accessToken = window.$CCDK.CCToken.getToken();
|
|
438
|
-
return config
|
|
439
|
-
},
|
|
440
|
-
// 响应拦截器
|
|
441
|
-
responseInterceptors(response) {
|
|
442
|
-
const { data, config } = response,
|
|
443
|
-
{ errorType, result } = data;
|
|
444
|
-
//失败
|
|
445
|
-
if (!result) {
|
|
446
|
-
if (needReportErrorType.includes(errorType) && isProduction()) {
|
|
447
|
-
const { errorReporter } = config.requestOptions;
|
|
448
|
-
//如果存在错误上报对象,则上报错误
|
|
449
|
-
if (errorReporter && isFn(errorReporter)) {
|
|
450
|
-
errorReporter(response);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return response
|
|
454
|
-
}
|
|
455
|
-
// 成功
|
|
456
|
-
// 生产环境上报日志
|
|
457
|
-
const { infoReporter } = config.requestOptions;
|
|
458
|
-
//如果存在日志上报对象,则上报日志
|
|
459
|
-
if (infoReporter && isFn(infoReporter)) {
|
|
460
|
-
infoReporter(response);
|
|
461
|
-
}
|
|
462
|
-
// 返回数据 外面处理
|
|
463
|
-
return response
|
|
464
|
-
},
|
|
465
|
-
// 响应拦截器异常处理,处理的错误类型包括: 服务器直接跑出异常、超时、网络错误
|
|
466
|
-
async responseInterceptorsCatch(axiosInstance, error) {
|
|
467
|
-
const { response, config } = error || {};
|
|
468
|
-
|
|
469
|
-
let err = "",
|
|
470
|
-
msg = "",
|
|
471
|
-
mode = "modal";
|
|
472
|
-
try {
|
|
473
|
-
err = error.toString(),
|
|
474
|
-
msg = response.data.error,
|
|
475
|
-
mode = config.requestOptions.errorMessageMode;
|
|
476
|
-
} catch (e) { }
|
|
477
|
-
|
|
478
|
-
let errorMessageMode = ['message', 'modal'].includes(mode) && mode || 'modal',
|
|
479
|
-
errMessage = '';
|
|
480
|
-
|
|
481
|
-
// 是否是取消的请求
|
|
482
|
-
if (axios.isCancel(error)) {
|
|
483
|
-
return Promise.reject(error)
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
try {
|
|
487
|
-
//如果存在错误上报对象,则上报错误
|
|
488
|
-
if (isProduction()) {
|
|
489
|
-
// 接口级的错误上报方式会覆盖实例初始化时的错误上报
|
|
490
|
-
const { errorReporter } = config.requestOptions;
|
|
491
|
-
if (errorReporter && isFn(errorReporter)) {
|
|
492
|
-
errorReporter(error);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
// 处理超时
|
|
496
|
-
if (isTimeout(error)) {
|
|
497
|
-
errMessage = 'c2487';
|
|
498
|
-
}
|
|
499
|
-
// 处理网络错误
|
|
500
|
-
if (err && err.includes('Network Error')) {
|
|
501
|
-
errMessage = 'c929';
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
if (errMessage) {
|
|
505
|
-
if (errorMessageMode === 'modal') {
|
|
506
|
-
createErrorModal({
|
|
507
|
-
...error,
|
|
508
|
-
response: {
|
|
509
|
-
data: {
|
|
510
|
-
returnInfo: error.message,
|
|
511
|
-
returnCode: error.code,
|
|
512
|
-
requestId: error.config.headers.requestId
|
|
513
|
-
},
|
|
514
|
-
config: error.config
|
|
515
|
-
}
|
|
516
|
-
}, { message: errMessage });
|
|
517
|
-
} else if (errorMessageMode === 'message') {
|
|
518
|
-
createMessage.error(errMessage);
|
|
519
|
-
}
|
|
520
|
-
return Promise.reject(error)
|
|
521
|
-
}
|
|
522
|
-
} catch (error) {
|
|
523
|
-
throw new Error(error);
|
|
524
|
-
}
|
|
525
|
-
// 根据status处理其他类型错误
|
|
526
|
-
checkStatus(error, error && error.response.status, msg, errorMessageMode);
|
|
527
|
-
|
|
528
|
-
// 接口重试操作
|
|
529
|
-
const { isOpenRetry } = config;
|
|
530
|
-
isOpenRetry && config.method && config.method.toUpperCase() === "GET" && retry(axiosInstance, error);
|
|
531
|
-
|
|
532
|
-
return Promise.reject(error);
|
|
533
|
-
},
|
|
534
|
-
// 响应数据处理,包含解密和数据返回结构设置
|
|
535
|
-
transformResponseHook(response, options, cachePool) {
|
|
536
|
-
const { data } = response;
|
|
537
|
-
const { errorType, result } = data;
|
|
538
|
-
// 失败
|
|
539
|
-
// 501异常处理
|
|
540
|
-
const businessLogicError = (response) => {
|
|
541
|
-
const { errorMessageMode, silent } = response.config.requestOptions;
|
|
542
|
-
// 接口如果设置了出现异常不提醒,则不提醒
|
|
543
|
-
if (silent) return;
|
|
544
|
-
// 根据errorMessageMode来判断显示错误弹窗的ui
|
|
545
|
-
if (errorMessageMode === 'modal') {
|
|
546
|
-
createErrorModal(response, { message: '业务出错' });
|
|
547
|
-
} else if (errorMessageMode === 'message') {
|
|
548
|
-
createMessage.error(response && response.data && response.data.returnInfo || '业务出错');
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
if (!result) {
|
|
552
|
-
switch (errorType) {
|
|
553
|
-
case '901':
|
|
554
|
-
createErrorModal(response, { message: '系统错误' });
|
|
555
|
-
break;
|
|
556
|
-
case '999':
|
|
557
|
-
break;
|
|
558
|
-
case '501':
|
|
559
|
-
default:
|
|
560
|
-
businessLogicError(response);
|
|
561
|
-
break;
|
|
562
|
-
}
|
|
563
|
-
return Promise.reject(response)
|
|
564
|
-
}
|
|
565
|
-
// 成功
|
|
566
|
-
const { isReturnNativeResponse, cache, cacheKey } = options;
|
|
567
|
-
// 直接返回
|
|
568
|
-
if (isReturnNativeResponse) {
|
|
569
|
-
cache && cacheKey && (cachePool.put(cacheKey, response));
|
|
570
|
-
return response
|
|
571
|
-
}
|
|
572
|
-
cache && cacheKey && (cachePool.put(cacheKey, data));
|
|
573
|
-
return data
|
|
574
|
-
}
|
|
575
|
-
};
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
function createAxios(opt) {
|
|
579
|
-
return new CCAxios(deepMerge({
|
|
580
|
-
timeout: 60 * 1000,
|
|
581
|
-
headers: {
|
|
582
|
-
'Content-Type': 'application/json;charset=UTF-8',
|
|
583
|
-
},
|
|
584
|
-
transform: cloneDeep(transform),
|
|
585
|
-
requestOptions: {
|
|
586
|
-
envType: '',
|
|
587
|
-
errorMessageMode: 'modal',
|
|
588
|
-
//是否静默错误提示
|
|
589
|
-
silent: false,
|
|
590
|
-
// 接口是否需要缓存
|
|
591
|
-
cache: false,
|
|
592
|
-
// 接口重试相关
|
|
593
|
-
retryRequest: {
|
|
594
|
-
isOpenRetry: false,
|
|
595
|
-
count: 5,
|
|
596
|
-
waitTime: 100,
|
|
597
|
-
},
|
|
598
|
-
// 是否返回原生响应头 比如:需要获取响应头时使用该属性
|
|
599
|
-
isReturnNativeResponse: false,
|
|
600
|
-
}
|
|
601
|
-
}, opt || {}))
|
|
431
|
+
const transform = {
|
|
432
|
+
// 请求拦截器
|
|
433
|
+
requestInterceptors(config) {
|
|
434
|
+
// 设置日志请求头信息
|
|
435
|
+
config.headers.requestId = window.$CCDK.CCUtils.getUuid();
|
|
436
|
+
config.headers.requestIdProducer = "browser";
|
|
437
|
+
config.headers.accessToken = window.$CCDK.CCToken.getToken();
|
|
438
|
+
return config
|
|
439
|
+
},
|
|
440
|
+
// 响应拦截器
|
|
441
|
+
responseInterceptors(response) {
|
|
442
|
+
const { data, config } = response,
|
|
443
|
+
{ errorType, result } = data;
|
|
444
|
+
//失败
|
|
445
|
+
if (!result) {
|
|
446
|
+
if (needReportErrorType.includes(errorType) && isProduction()) {
|
|
447
|
+
const { errorReporter } = config.requestOptions;
|
|
448
|
+
//如果存在错误上报对象,则上报错误
|
|
449
|
+
if (errorReporter && isFn(errorReporter)) {
|
|
450
|
+
errorReporter(response);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return response
|
|
454
|
+
}
|
|
455
|
+
// 成功
|
|
456
|
+
// 生产环境上报日志
|
|
457
|
+
const { infoReporter } = config.requestOptions;
|
|
458
|
+
//如果存在日志上报对象,则上报日志
|
|
459
|
+
if (infoReporter && isFn(infoReporter)) {
|
|
460
|
+
infoReporter(response);
|
|
461
|
+
}
|
|
462
|
+
// 返回数据 外面处理
|
|
463
|
+
return response
|
|
464
|
+
},
|
|
465
|
+
// 响应拦截器异常处理,处理的错误类型包括: 服务器直接跑出异常、超时、网络错误
|
|
466
|
+
async responseInterceptorsCatch(axiosInstance, error) {
|
|
467
|
+
const { response, config } = error || {};
|
|
468
|
+
|
|
469
|
+
let err = "",
|
|
470
|
+
msg = "",
|
|
471
|
+
mode = "modal";
|
|
472
|
+
try {
|
|
473
|
+
err = error.toString(),
|
|
474
|
+
msg = response.data.error,
|
|
475
|
+
mode = config.requestOptions.errorMessageMode;
|
|
476
|
+
} catch (e) { }
|
|
477
|
+
|
|
478
|
+
let errorMessageMode = ['message', 'modal'].includes(mode) && mode || 'modal',
|
|
479
|
+
errMessage = '';
|
|
480
|
+
|
|
481
|
+
// 是否是取消的请求
|
|
482
|
+
if (axios.isCancel(error)) {
|
|
483
|
+
return Promise.reject(error)
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
try {
|
|
487
|
+
//如果存在错误上报对象,则上报错误
|
|
488
|
+
if (isProduction()) {
|
|
489
|
+
// 接口级的错误上报方式会覆盖实例初始化时的错误上报
|
|
490
|
+
const { errorReporter } = config.requestOptions;
|
|
491
|
+
if (errorReporter && isFn(errorReporter)) {
|
|
492
|
+
errorReporter(error);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
// 处理超时
|
|
496
|
+
if (isTimeout(error)) {
|
|
497
|
+
errMessage = 'c2487';
|
|
498
|
+
}
|
|
499
|
+
// 处理网络错误
|
|
500
|
+
if (err && err.includes('Network Error')) {
|
|
501
|
+
errMessage = 'c929';
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (errMessage) {
|
|
505
|
+
if (errorMessageMode === 'modal') {
|
|
506
|
+
createErrorModal({
|
|
507
|
+
...error,
|
|
508
|
+
response: {
|
|
509
|
+
data: {
|
|
510
|
+
returnInfo: error.message,
|
|
511
|
+
returnCode: error.code,
|
|
512
|
+
requestId: error.config.headers.requestId
|
|
513
|
+
},
|
|
514
|
+
config: error.config
|
|
515
|
+
}
|
|
516
|
+
}, { message: errMessage });
|
|
517
|
+
} else if (errorMessageMode === 'message') {
|
|
518
|
+
createMessage.error(errMessage);
|
|
519
|
+
}
|
|
520
|
+
return Promise.reject(error)
|
|
521
|
+
}
|
|
522
|
+
} catch (error) {
|
|
523
|
+
throw new Error(error);
|
|
524
|
+
}
|
|
525
|
+
// 根据status处理其他类型错误
|
|
526
|
+
checkStatus(error, error && error.response.status, msg, errorMessageMode);
|
|
527
|
+
|
|
528
|
+
// 接口重试操作
|
|
529
|
+
const { isOpenRetry } = config;
|
|
530
|
+
isOpenRetry && config.method && config.method.toUpperCase() === "GET" && retry(axiosInstance, error);
|
|
531
|
+
|
|
532
|
+
return Promise.reject(error);
|
|
533
|
+
},
|
|
534
|
+
// 响应数据处理,包含解密和数据返回结构设置
|
|
535
|
+
transformResponseHook(response, options, cachePool) {
|
|
536
|
+
const { data } = response;
|
|
537
|
+
const { errorType, result } = data;
|
|
538
|
+
// 失败
|
|
539
|
+
// 501异常处理
|
|
540
|
+
const businessLogicError = (response) => {
|
|
541
|
+
const { errorMessageMode, silent } = response.config.requestOptions;
|
|
542
|
+
// 接口如果设置了出现异常不提醒,则不提醒
|
|
543
|
+
if (silent) return;
|
|
544
|
+
// 根据errorMessageMode来判断显示错误弹窗的ui
|
|
545
|
+
if (errorMessageMode === 'modal') {
|
|
546
|
+
createErrorModal(response, { message: '业务出错' });
|
|
547
|
+
} else if (errorMessageMode === 'message') {
|
|
548
|
+
createMessage.error(response && response.data && response.data.returnInfo || '业务出错');
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
if (!result) {
|
|
552
|
+
switch (errorType) {
|
|
553
|
+
case '901':
|
|
554
|
+
createErrorModal(response, { message: '系统错误' });
|
|
555
|
+
break;
|
|
556
|
+
case '999':
|
|
557
|
+
break;
|
|
558
|
+
case '501':
|
|
559
|
+
default:
|
|
560
|
+
businessLogicError(response);
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
563
|
+
return Promise.reject(response)
|
|
564
|
+
}
|
|
565
|
+
// 成功
|
|
566
|
+
const { isReturnNativeResponse, cache, cacheKey } = options;
|
|
567
|
+
// 直接返回
|
|
568
|
+
if (isReturnNativeResponse) {
|
|
569
|
+
cache && cacheKey && (cachePool.put(cacheKey, response));
|
|
570
|
+
return response
|
|
571
|
+
}
|
|
572
|
+
cache && cacheKey && (cachePool.put(cacheKey, data));
|
|
573
|
+
return data
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
function createAxios(opt) {
|
|
579
|
+
return new CCAxios(deepMerge({
|
|
580
|
+
timeout: 60 * 1000,
|
|
581
|
+
headers: {
|
|
582
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
583
|
+
},
|
|
584
|
+
transform: cloneDeep(transform),
|
|
585
|
+
requestOptions: {
|
|
586
|
+
envType: '',
|
|
587
|
+
errorMessageMode: 'modal',
|
|
588
|
+
//是否静默错误提示
|
|
589
|
+
silent: false,
|
|
590
|
+
// 接口是否需要缓存
|
|
591
|
+
cache: false,
|
|
592
|
+
// 接口重试相关
|
|
593
|
+
retryRequest: {
|
|
594
|
+
isOpenRetry: false,
|
|
595
|
+
count: 5,
|
|
596
|
+
waitTime: 100,
|
|
597
|
+
},
|
|
598
|
+
// 是否返回原生响应头 比如:需要获取响应头时使用该属性
|
|
599
|
+
isReturnNativeResponse: false,
|
|
600
|
+
}
|
|
601
|
+
}, opt || {}))
|
|
602
602
|
}
|
|
603
603
|
|
|
604
604
|
var CCHttp$1 = /*#__PURE__*/Object.freeze({
|
|
@@ -606,30 +606,30 @@ var CCHttp$1 = /*#__PURE__*/Object.freeze({
|
|
|
606
606
|
createAxios: createAxios
|
|
607
607
|
});
|
|
608
608
|
|
|
609
|
-
window.ccBus = new Vue;
|
|
610
|
-
/**
|
|
611
|
-
* 发布信息
|
|
612
|
-
* @param {string} event 事件名称
|
|
613
|
-
* @param {...any} args 参数列表
|
|
614
|
-
*/
|
|
615
|
-
function $emit( ...args) {
|
|
616
|
-
window.ccBus.$emit( ...args);
|
|
617
|
-
}
|
|
618
|
-
/**
|
|
619
|
-
* 订阅消息
|
|
620
|
-
* @param {string} event 事件名称
|
|
621
|
-
* @param {function} callback 回调方法
|
|
622
|
-
*/
|
|
623
|
-
function $on(...args) {
|
|
624
|
-
window.ccBus.$on(...args);
|
|
625
|
-
}
|
|
626
|
-
/**
|
|
627
|
-
* 取消订阅
|
|
628
|
-
* @param {string} event 事件名称
|
|
629
|
-
* @param { function | function[] | undefined } callbacks 需要解除监听的事件
|
|
630
|
-
*/
|
|
631
|
-
function $off(...args) {
|
|
632
|
-
window.ccBus.$off(...args);
|
|
609
|
+
window.ccBus = new Vue;
|
|
610
|
+
/**
|
|
611
|
+
* 发布信息
|
|
612
|
+
* @param {string} event 事件名称
|
|
613
|
+
* @param {...any} args 参数列表
|
|
614
|
+
*/
|
|
615
|
+
function $emit( ...args) {
|
|
616
|
+
window.ccBus.$emit( ...args);
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* 订阅消息
|
|
620
|
+
* @param {string} event 事件名称
|
|
621
|
+
* @param {function} callback 回调方法
|
|
622
|
+
*/
|
|
623
|
+
function $on(...args) {
|
|
624
|
+
window.ccBus.$on(...args);
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* 取消订阅
|
|
628
|
+
* @param {string} event 事件名称
|
|
629
|
+
* @param { function | function[] | undefined } callbacks 需要解除监听的事件
|
|
630
|
+
*/
|
|
631
|
+
function $off(...args) {
|
|
632
|
+
window.ccBus.$off(...args);
|
|
633
633
|
}
|
|
634
634
|
|
|
635
635
|
var CCBus = /*#__PURE__*/Object.freeze({
|
|
@@ -639,57 +639,57 @@ var CCBus = /*#__PURE__*/Object.freeze({
|
|
|
639
639
|
$off: $off
|
|
640
640
|
});
|
|
641
641
|
|
|
642
|
-
// 电话对象
|
|
643
|
-
let ccCall = new Map();
|
|
644
|
-
// 电话服务商当前对象
|
|
645
|
-
let currentCall;
|
|
646
|
-
/**
|
|
647
|
-
* 初始化电话条
|
|
648
|
-
* @param {string} id 电话服务商唯一标识
|
|
649
|
-
* @param {object} callClient 电话对象
|
|
650
|
-
*/
|
|
651
|
-
function init$1(id, callClient) {
|
|
652
|
-
if (id && callClient) {
|
|
653
|
-
ccCall.set(id, callClient);
|
|
654
|
-
currentCall = callClient;
|
|
655
|
-
return currentCall
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
/**
|
|
661
|
-
* 拨打电话
|
|
662
|
-
* @param {string} id 电话服务商唯一标识
|
|
663
|
-
* @param {object} options 配置信息
|
|
664
|
-
*/
|
|
665
|
-
function call(id, options) {
|
|
666
|
-
let call;
|
|
667
|
-
if (id) {
|
|
668
|
-
call = ccCall.get(id);
|
|
669
|
-
} else {
|
|
670
|
-
call = currentCall;
|
|
671
|
-
}
|
|
672
|
-
if (call) {
|
|
673
|
-
call.call(options);
|
|
674
|
-
}
|
|
675
|
-
return call
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* 打开通话面板
|
|
679
|
-
* @param {string} id 电话服务商唯一标识
|
|
680
|
-
* @param {object} options 配置信息
|
|
681
|
-
*/
|
|
682
|
-
function openCallPanel(id, options) {
|
|
683
|
-
let call;
|
|
684
|
-
if (id) {
|
|
685
|
-
call = ccCall.get(id);
|
|
686
|
-
} else {
|
|
687
|
-
call = currentCall;
|
|
688
|
-
}
|
|
689
|
-
if (call) {
|
|
690
|
-
call.openCallPanel(options);
|
|
691
|
-
}
|
|
692
|
-
return call
|
|
642
|
+
// 电话对象
|
|
643
|
+
let ccCall = new Map();
|
|
644
|
+
// 电话服务商当前对象
|
|
645
|
+
let currentCall;
|
|
646
|
+
/**
|
|
647
|
+
* 初始化电话条
|
|
648
|
+
* @param {string} id 电话服务商唯一标识
|
|
649
|
+
* @param {object} callClient 电话对象
|
|
650
|
+
*/
|
|
651
|
+
function init$1(id, callClient) {
|
|
652
|
+
if (id && callClient) {
|
|
653
|
+
ccCall.set(id, callClient);
|
|
654
|
+
currentCall = callClient;
|
|
655
|
+
return currentCall
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* 拨打电话
|
|
662
|
+
* @param {string} id 电话服务商唯一标识
|
|
663
|
+
* @param {object} options 配置信息
|
|
664
|
+
*/
|
|
665
|
+
function call(id, options) {
|
|
666
|
+
let call;
|
|
667
|
+
if (id) {
|
|
668
|
+
call = ccCall.get(id);
|
|
669
|
+
} else {
|
|
670
|
+
call = currentCall;
|
|
671
|
+
}
|
|
672
|
+
if (call) {
|
|
673
|
+
call.call(options);
|
|
674
|
+
}
|
|
675
|
+
return call
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* 打开通话面板
|
|
679
|
+
* @param {string} id 电话服务商唯一标识
|
|
680
|
+
* @param {object} options 配置信息
|
|
681
|
+
*/
|
|
682
|
+
function openCallPanel(id, options) {
|
|
683
|
+
let call;
|
|
684
|
+
if (id) {
|
|
685
|
+
call = ccCall.get(id);
|
|
686
|
+
} else {
|
|
687
|
+
call = currentCall;
|
|
688
|
+
}
|
|
689
|
+
if (call) {
|
|
690
|
+
call.openCallPanel(options);
|
|
691
|
+
}
|
|
692
|
+
return call
|
|
693
693
|
}
|
|
694
694
|
|
|
695
695
|
var CCCall = /*#__PURE__*/Object.freeze({
|
|
@@ -699,96 +699,96 @@ var CCCall = /*#__PURE__*/Object.freeze({
|
|
|
699
699
|
openCallPanel: openCallPanel
|
|
700
700
|
});
|
|
701
701
|
|
|
702
|
-
/**
|
|
703
|
-
* 错误日志上报
|
|
704
|
-
* @param {object} response 响应体
|
|
705
|
-
*/
|
|
706
|
-
function reportError(response) {
|
|
707
|
-
if ("1" === window.Glod['CC_LOG_LEVEL'] || "2" === window.Glod['CC_LOG_LEVEL']) {
|
|
708
|
-
window.$CCDK.CCLog.reportLog(window.Glod['ccex-log'] + "/ccerrorlog", response, "error", { serviceName: "lightning-custom-page" });
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* 常规日志上报
|
|
713
|
-
* @param {object} response 响应体
|
|
714
|
-
*/
|
|
715
|
-
function reportInfo(response) {
|
|
716
|
-
if ("2" === window.Glod['CC_LOG_LEVEL']) {
|
|
717
|
-
window.$CCDK.CCLog.reportLog(window.Glod['ccex-log'] + "/systeminfolog", response, "info", {
|
|
718
|
-
serviceName: "lightning-custom-page"
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
const service$1 = axios.create({
|
|
724
|
-
timeout: 60 * 1000,
|
|
725
|
-
headers: {
|
|
726
|
-
'Content-Type': 'application/json; charset=utf-8',
|
|
727
|
-
},
|
|
728
|
-
});
|
|
729
|
-
|
|
730
|
-
service$1.interceptors.request.use(
|
|
731
|
-
config => {
|
|
732
|
-
config.headers.accessToken = window.$CCDK.CCToken.getToken();
|
|
733
|
-
config.headers.requestId = window.$CCDK.CCUtils.getUuid();
|
|
734
|
-
config.headers.requestIdProducer = "browser";
|
|
735
|
-
return config
|
|
736
|
-
},
|
|
737
|
-
error => {
|
|
738
|
-
Promise.reject(error);
|
|
739
|
-
}
|
|
740
|
-
);
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
service$1.interceptors.response.use(
|
|
744
|
-
response => {
|
|
745
|
-
if (response.data.result) {
|
|
746
|
-
// 上报日志
|
|
747
|
-
reportInfo(response);
|
|
748
|
-
return response.data
|
|
749
|
-
} else {
|
|
750
|
-
reportError(response);
|
|
751
|
-
return Promise.reject(response)
|
|
752
|
-
}
|
|
753
|
-
},
|
|
754
|
-
error => {
|
|
755
|
-
// 上报错误日志
|
|
756
|
-
if (error) {
|
|
757
|
-
reportError(error.response);
|
|
758
|
-
}
|
|
759
|
-
return Promise.reject(error)
|
|
760
|
-
}
|
|
761
|
-
);
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
var http = {
|
|
765
|
-
get: (url, data = {}, responseType = '') => {
|
|
766
|
-
return service$1({
|
|
767
|
-
url: url,
|
|
768
|
-
method: 'get',
|
|
769
|
-
params: data,
|
|
770
|
-
responseType: responseType
|
|
771
|
-
})
|
|
772
|
-
},
|
|
773
|
-
post: (url, data = {}, responseType = '') => {
|
|
774
|
-
return service$1({
|
|
775
|
-
url: url,
|
|
776
|
-
method: 'post',
|
|
777
|
-
data: data,
|
|
778
|
-
responseType: responseType
|
|
779
|
-
})
|
|
780
|
-
},
|
|
702
|
+
/**
|
|
703
|
+
* 错误日志上报
|
|
704
|
+
* @param {object} response 响应体
|
|
705
|
+
*/
|
|
706
|
+
function reportError(response) {
|
|
707
|
+
if ("1" === window.Glod['CC_LOG_LEVEL'] || "2" === window.Glod['CC_LOG_LEVEL']) {
|
|
708
|
+
window.$CCDK.CCLog.reportLog(window.Glod['ccex-log'] + "/ccerrorlog", response, "error", { serviceName: "lightning-custom-page" });
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* 常规日志上报
|
|
713
|
+
* @param {object} response 响应体
|
|
714
|
+
*/
|
|
715
|
+
function reportInfo(response) {
|
|
716
|
+
if ("2" === window.Glod['CC_LOG_LEVEL']) {
|
|
717
|
+
window.$CCDK.CCLog.reportLog(window.Glod['ccex-log'] + "/systeminfolog", response, "info", {
|
|
718
|
+
serviceName: "lightning-custom-page"
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
const service$1 = axios.create({
|
|
724
|
+
timeout: 60 * 1000,
|
|
725
|
+
headers: {
|
|
726
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
727
|
+
},
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
service$1.interceptors.request.use(
|
|
731
|
+
config => {
|
|
732
|
+
config.headers.accessToken = window.$CCDK.CCToken.getToken();
|
|
733
|
+
config.headers.requestId = window.$CCDK.CCUtils.getUuid();
|
|
734
|
+
config.headers.requestIdProducer = "browser";
|
|
735
|
+
return config
|
|
736
|
+
},
|
|
737
|
+
error => {
|
|
738
|
+
Promise.reject(error);
|
|
739
|
+
}
|
|
740
|
+
);
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
service$1.interceptors.response.use(
|
|
744
|
+
response => {
|
|
745
|
+
if (response.data.result) {
|
|
746
|
+
// 上报日志
|
|
747
|
+
reportInfo(response);
|
|
748
|
+
return response.data
|
|
749
|
+
} else {
|
|
750
|
+
reportError(response);
|
|
751
|
+
return Promise.reject(response)
|
|
752
|
+
}
|
|
753
|
+
},
|
|
754
|
+
error => {
|
|
755
|
+
// 上报错误日志
|
|
756
|
+
if (error) {
|
|
757
|
+
reportError(error.response);
|
|
758
|
+
}
|
|
759
|
+
return Promise.reject(error)
|
|
760
|
+
}
|
|
761
|
+
);
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
var http = {
|
|
765
|
+
get: (url, data = {}, responseType = '') => {
|
|
766
|
+
return service$1({
|
|
767
|
+
url: url,
|
|
768
|
+
method: 'get',
|
|
769
|
+
params: data,
|
|
770
|
+
responseType: responseType
|
|
771
|
+
})
|
|
772
|
+
},
|
|
773
|
+
post: (url, data = {}, responseType = '') => {
|
|
774
|
+
return service$1({
|
|
775
|
+
url: url,
|
|
776
|
+
method: 'post',
|
|
777
|
+
data: data,
|
|
778
|
+
responseType: responseType
|
|
779
|
+
})
|
|
780
|
+
},
|
|
781
781
|
};
|
|
782
782
|
|
|
783
|
-
/**
|
|
784
|
-
* 请求common接口
|
|
785
|
-
* @param {string} className 类名
|
|
786
|
-
* @param {string} methodName 方法名
|
|
787
|
-
* @param {Array} params 参数集合
|
|
788
|
-
* @returns {Promise}
|
|
789
|
-
*/
|
|
790
|
-
function post$1(className, methodName, params) {
|
|
791
|
-
return http.post(window.$CCDK.CCConfig.getSvc()['ccex-apitsf'] + '/api/openCall/common', { className, methodName, params });
|
|
783
|
+
/**
|
|
784
|
+
* 请求common接口
|
|
785
|
+
* @param {string} className 类名
|
|
786
|
+
* @param {string} methodName 方法名
|
|
787
|
+
* @param {Array} params 参数集合
|
|
788
|
+
* @returns {Promise}
|
|
789
|
+
*/
|
|
790
|
+
function post$1(className, methodName, params) {
|
|
791
|
+
return http.post(window.$CCDK.CCConfig.getSvc()['ccex-apitsf'] + '/api/openCall/common', { className, methodName, params });
|
|
792
792
|
}
|
|
793
793
|
|
|
794
794
|
var CCCommon = /*#__PURE__*/Object.freeze({
|
|
@@ -796,33 +796,33 @@ var CCCommon = /*#__PURE__*/Object.freeze({
|
|
|
796
796
|
post: post$1
|
|
797
797
|
});
|
|
798
798
|
|
|
799
|
-
/**
|
|
800
|
-
* 获取基础url
|
|
801
|
-
* @returns 基础地址
|
|
802
|
-
*/
|
|
803
|
-
function getBaseUrl() {
|
|
804
|
-
return window.gw.BASE_URL
|
|
805
|
-
}
|
|
806
|
-
/**
|
|
807
|
-
* 获取网关对象
|
|
808
|
-
* @returns 网关对象
|
|
809
|
-
*/
|
|
810
|
-
function getGw() {
|
|
811
|
-
return window.gw;
|
|
812
|
-
}
|
|
813
|
-
/**
|
|
814
|
-
* 获取服务对象
|
|
815
|
-
* @returns 服务对象
|
|
816
|
-
*/
|
|
817
|
-
function getSvc() {
|
|
818
|
-
return window.Glod;
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* 获取静态资源的访问地址
|
|
822
|
-
* @returns 静态资源访问地址
|
|
823
|
-
*/
|
|
824
|
-
function getCDNUrl() {
|
|
825
|
-
return window.Glod.CDN_URL;
|
|
799
|
+
/**
|
|
800
|
+
* 获取基础url
|
|
801
|
+
* @returns 基础地址
|
|
802
|
+
*/
|
|
803
|
+
function getBaseUrl() {
|
|
804
|
+
return window.gw.BASE_URL
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* 获取网关对象
|
|
808
|
+
* @returns 网关对象
|
|
809
|
+
*/
|
|
810
|
+
function getGw() {
|
|
811
|
+
return window.gw;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* 获取服务对象
|
|
815
|
+
* @returns 服务对象
|
|
816
|
+
*/
|
|
817
|
+
function getSvc() {
|
|
818
|
+
return window.Glod;
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* 获取静态资源的访问地址
|
|
822
|
+
* @returns 静态资源访问地址
|
|
823
|
+
*/
|
|
824
|
+
function getCDNUrl() {
|
|
825
|
+
return window.Glod.CDN_URL;
|
|
826
826
|
}
|
|
827
827
|
|
|
828
828
|
var CCConfig = /*#__PURE__*/Object.freeze({
|
|
@@ -833,76 +833,76 @@ var CCConfig = /*#__PURE__*/Object.freeze({
|
|
|
833
833
|
getCDNUrl: getCDNUrl
|
|
834
834
|
});
|
|
835
835
|
|
|
836
|
-
const service = axios.create({
|
|
837
|
-
timeout: 60000,
|
|
838
|
-
headers: {
|
|
839
|
-
'Content-Type': 'application/json; charset=utf-8',
|
|
840
|
-
},
|
|
841
|
-
});
|
|
842
|
-
|
|
843
|
-
service.interceptors.request.use(
|
|
844
|
-
config => {
|
|
845
|
-
config.headers['accessToken'] = window.$CCDK.CCToken.getToken();
|
|
846
|
-
return config
|
|
847
|
-
},
|
|
848
|
-
error => {
|
|
849
|
-
Promise.reject(error);
|
|
850
|
-
}
|
|
851
|
-
);
|
|
852
|
-
|
|
853
|
-
service.interceptors.response.use(
|
|
854
|
-
response => {
|
|
855
|
-
const code = response.data.code || 200;
|
|
856
|
-
if (code !== 200) {
|
|
857
|
-
return Promise.reject(null == response.data.msg ? "未知异常" : response.data.msg)
|
|
858
|
-
} else {
|
|
859
|
-
return response.data
|
|
860
|
-
}
|
|
861
|
-
},
|
|
862
|
-
error => {
|
|
863
|
-
return Promise.reject(error)
|
|
864
|
-
}
|
|
865
|
-
);
|
|
866
|
-
function get(url, data = {}, responseType = '') {
|
|
867
|
-
return service({
|
|
868
|
-
url: url,
|
|
869
|
-
method: 'get',
|
|
870
|
-
params: data,
|
|
871
|
-
responseType: responseType
|
|
872
|
-
})
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
function post(url, data = {}, responseType = '') {
|
|
876
|
-
return service({
|
|
877
|
-
url: url,
|
|
878
|
-
method: 'post',
|
|
879
|
-
data: data,
|
|
880
|
-
responseType: responseType
|
|
881
|
-
})
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
function put(url, data = {}) {
|
|
885
|
-
return service({
|
|
886
|
-
url: url,
|
|
887
|
-
method: 'put',
|
|
888
|
-
data: data
|
|
889
|
-
})
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
function postParams(url, data = {}) {
|
|
893
|
-
return service({
|
|
894
|
-
url: url,
|
|
895
|
-
method: 'post',
|
|
896
|
-
params: data
|
|
897
|
-
})
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
function patch(url, data = {}) {
|
|
901
|
-
return service({
|
|
902
|
-
url: url,
|
|
903
|
-
method: 'patch',
|
|
904
|
-
data: data
|
|
905
|
-
})
|
|
836
|
+
const service = axios.create({
|
|
837
|
+
timeout: 60000,
|
|
838
|
+
headers: {
|
|
839
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
840
|
+
},
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
service.interceptors.request.use(
|
|
844
|
+
config => {
|
|
845
|
+
config.headers['accessToken'] = window.$CCDK.CCToken.getToken();
|
|
846
|
+
return config
|
|
847
|
+
},
|
|
848
|
+
error => {
|
|
849
|
+
Promise.reject(error);
|
|
850
|
+
}
|
|
851
|
+
);
|
|
852
|
+
|
|
853
|
+
service.interceptors.response.use(
|
|
854
|
+
response => {
|
|
855
|
+
const code = response.data.code || 200;
|
|
856
|
+
if (code !== 200) {
|
|
857
|
+
return Promise.reject(null == response.data.msg ? "未知异常" : response.data.msg)
|
|
858
|
+
} else {
|
|
859
|
+
return response.data
|
|
860
|
+
}
|
|
861
|
+
},
|
|
862
|
+
error => {
|
|
863
|
+
return Promise.reject(error)
|
|
864
|
+
}
|
|
865
|
+
);
|
|
866
|
+
function get(url, data = {}, responseType = '') {
|
|
867
|
+
return service({
|
|
868
|
+
url: url,
|
|
869
|
+
method: 'get',
|
|
870
|
+
params: data,
|
|
871
|
+
responseType: responseType
|
|
872
|
+
})
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
function post(url, data = {}, responseType = '') {
|
|
876
|
+
return service({
|
|
877
|
+
url: url,
|
|
878
|
+
method: 'post',
|
|
879
|
+
data: data,
|
|
880
|
+
responseType: responseType
|
|
881
|
+
})
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function put(url, data = {}) {
|
|
885
|
+
return service({
|
|
886
|
+
url: url,
|
|
887
|
+
method: 'put',
|
|
888
|
+
data: data
|
|
889
|
+
})
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
function postParams(url, data = {}) {
|
|
893
|
+
return service({
|
|
894
|
+
url: url,
|
|
895
|
+
method: 'post',
|
|
896
|
+
params: data
|
|
897
|
+
})
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
function patch(url, data = {}) {
|
|
901
|
+
return service({
|
|
902
|
+
url: url,
|
|
903
|
+
method: 'patch',
|
|
904
|
+
data: data
|
|
905
|
+
})
|
|
906
906
|
}
|
|
907
907
|
|
|
908
908
|
var CCHttp = /*#__PURE__*/Object.freeze({
|
|
@@ -914,64 +914,64 @@ var CCHttp = /*#__PURE__*/Object.freeze({
|
|
|
914
914
|
postParams: postParams
|
|
915
915
|
});
|
|
916
916
|
|
|
917
|
-
/**
|
|
918
|
-
* 下载js,并挂载到document上
|
|
919
|
-
* @param {string} src js下载路径
|
|
920
|
-
* @param {object} scriptOption script配置参数
|
|
921
|
-
* @returns
|
|
922
|
-
*/
|
|
923
|
-
function loadJs(src, scriptOption) {
|
|
924
|
-
return new Promise((resolve, reject) => {
|
|
925
|
-
let scriptTemp = document.createElement('script');
|
|
926
|
-
if (scriptOption) {
|
|
927
|
-
Object.assign(scriptTemp, scriptOption);
|
|
928
|
-
}
|
|
929
|
-
scriptTemp.type = "text/javascript";
|
|
930
|
-
scriptTemp.src = src;
|
|
931
|
-
document.body.appendChild(scriptTemp);
|
|
932
|
-
|
|
933
|
-
scriptTemp.onload = () => {
|
|
934
|
-
resolve();
|
|
935
|
-
};
|
|
936
|
-
scriptTemp.onerror = () => {
|
|
937
|
-
reject();
|
|
938
|
-
};
|
|
939
|
-
})
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* 创建加载js组件
|
|
943
|
-
*/
|
|
944
|
-
function createLoadJsComponent() {
|
|
945
|
-
Vue.component('cc-load-script', {
|
|
946
|
-
render: function (createElement) {
|
|
947
|
-
var self = this;
|
|
948
|
-
return createElement('script', {
|
|
949
|
-
attrs: {
|
|
950
|
-
type: 'text/javascript',
|
|
951
|
-
src: this.src
|
|
952
|
-
},
|
|
953
|
-
on: {
|
|
954
|
-
load: function (event) {
|
|
955
|
-
self.$emit('load', event);
|
|
956
|
-
},
|
|
957
|
-
error: function (event) {
|
|
958
|
-
self.$emit('error', event);
|
|
959
|
-
},
|
|
960
|
-
readystatechange: function (event) {
|
|
961
|
-
if (this.readyState == 'complete') {
|
|
962
|
-
self.$emit('load', event);
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
});
|
|
967
|
-
},
|
|
968
|
-
props: {
|
|
969
|
-
src: {
|
|
970
|
-
type: String,
|
|
971
|
-
required: true
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
});
|
|
917
|
+
/**
|
|
918
|
+
* 下载js,并挂载到document上
|
|
919
|
+
* @param {string} src js下载路径
|
|
920
|
+
* @param {object} scriptOption script配置参数
|
|
921
|
+
* @returns
|
|
922
|
+
*/
|
|
923
|
+
function loadJs(src, scriptOption) {
|
|
924
|
+
return new Promise((resolve, reject) => {
|
|
925
|
+
let scriptTemp = document.createElement('script');
|
|
926
|
+
if (scriptOption) {
|
|
927
|
+
Object.assign(scriptTemp, scriptOption);
|
|
928
|
+
}
|
|
929
|
+
scriptTemp.type = "text/javascript";
|
|
930
|
+
scriptTemp.src = src;
|
|
931
|
+
document.body.appendChild(scriptTemp);
|
|
932
|
+
|
|
933
|
+
scriptTemp.onload = () => {
|
|
934
|
+
resolve();
|
|
935
|
+
};
|
|
936
|
+
scriptTemp.onerror = () => {
|
|
937
|
+
reject();
|
|
938
|
+
};
|
|
939
|
+
})
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* 创建加载js组件
|
|
943
|
+
*/
|
|
944
|
+
function createLoadJsComponent() {
|
|
945
|
+
Vue.component('cc-load-script', {
|
|
946
|
+
render: function (createElement) {
|
|
947
|
+
var self = this;
|
|
948
|
+
return createElement('script', {
|
|
949
|
+
attrs: {
|
|
950
|
+
type: 'text/javascript',
|
|
951
|
+
src: this.src
|
|
952
|
+
},
|
|
953
|
+
on: {
|
|
954
|
+
load: function (event) {
|
|
955
|
+
self.$emit('load', event);
|
|
956
|
+
},
|
|
957
|
+
error: function (event) {
|
|
958
|
+
self.$emit('error', event);
|
|
959
|
+
},
|
|
960
|
+
readystatechange: function (event) {
|
|
961
|
+
if (this.readyState == 'complete') {
|
|
962
|
+
self.$emit('load', event);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
},
|
|
968
|
+
props: {
|
|
969
|
+
src: {
|
|
970
|
+
type: String,
|
|
971
|
+
required: true
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
975
|
}
|
|
976
976
|
|
|
977
977
|
var CCLoad = /*#__PURE__*/Object.freeze({
|
|
@@ -980,173 +980,198 @@ var CCLoad = /*#__PURE__*/Object.freeze({
|
|
|
980
980
|
createLoadJsComponent: createLoadJsComponent
|
|
981
981
|
});
|
|
982
982
|
|
|
983
|
-
/**
|
|
984
|
-
* 获取日志基础信息
|
|
985
|
-
* @returns 日志基础信息
|
|
986
|
-
*/
|
|
987
|
-
function getBaseInfo() {
|
|
988
|
-
let userInfo = window.$CCDK.CCUser.getUserInfo();
|
|
989
|
-
let old = {
|
|
990
|
-
// 用户名,使用登录账号
|
|
991
|
-
"userName": userInfo.loginName || "未知用户",
|
|
992
|
-
// 用户id
|
|
993
|
-
"userId": userInfo.userId,
|
|
994
|
-
// 组织id
|
|
995
|
-
"orgId": userInfo.orgId,
|
|
996
|
-
// 组织名称
|
|
997
|
-
"orgName": userInfo.orgName,
|
|
998
|
-
// 服务名称
|
|
999
|
-
"serviceName": "未知应用",
|
|
1000
|
-
// 记录类型:platform平台日志,dev开发者日志
|
|
1001
|
-
"recordType": "platform",
|
|
1002
|
-
// 日志类型
|
|
1003
|
-
"logType": "front",
|
|
1004
|
-
// 发生时间
|
|
1005
|
-
"operateTime": (new Date()).valueOf(),
|
|
1006
|
-
// 日志标识码,没有这个标识码,不能上传
|
|
1007
|
-
"cccode": "hidden",
|
|
1008
|
-
// 日志显示级别默认2
|
|
1009
|
-
"displayLevel": "2",
|
|
1010
|
-
};
|
|
1011
|
-
return old
|
|
1012
|
-
}
|
|
1013
|
-
/**
|
|
1014
|
-
* 获取网络异常信息
|
|
1015
|
-
* @param {object} response 网络请求响应体
|
|
1016
|
-
* @returns 请求体信息
|
|
1017
|
-
*/
|
|
1018
|
-
function getHttpErrorInfo(error = {}) {
|
|
1019
|
-
let { config = {}, data = {} } = error;
|
|
1020
|
-
if (config) {
|
|
1021
|
-
return {
|
|
1022
|
-
// 请求地址url
|
|
1023
|
-
"requestUrl": config.baseURL + config.url,
|
|
1024
|
-
// 请求id
|
|
1025
|
-
"requestId": config.headers ? config.headers.requestId : window.$CCDK.CCUtils.getUuid(),
|
|
1026
|
-
// 请求id类型
|
|
1027
|
-
"requestIdProducer": config.headers ? config.headers.requestIdProducer : "",
|
|
1028
|
-
// 请求体
|
|
1029
|
-
"requestParameter": config.data,
|
|
1030
|
-
// 错误描述
|
|
1031
|
-
"errorMessage": error.message || data.returnInfo || "未知错误",
|
|
1032
|
-
// 请求结果状态
|
|
1033
|
-
"requestResult": "失败",
|
|
1034
|
-
// 日志级别
|
|
1035
|
-
"errorLevel": "2",
|
|
1036
|
-
// 堆栈信息
|
|
1037
|
-
"printStackTraceInfo": (error.message || data.returnInfo || "未知错误") + "\n" + config.data,
|
|
1038
|
-
}
|
|
1039
|
-
} else {
|
|
1040
|
-
return {}
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
/**
|
|
1046
|
-
* 获取网络信息
|
|
1047
|
-
* @param {object} response 网络请求响应体
|
|
1048
|
-
* @returns 请求体信息
|
|
1049
|
-
*/
|
|
1050
|
-
function getHttpInfo(response) {
|
|
1051
|
-
if (response) {
|
|
1052
|
-
if (window.performance) {
|
|
1053
|
-
// 通过性能接口精确测量接口用时
|
|
1054
|
-
let per = performance.getEntriesByName(response.request.responseURL, "resource");
|
|
1055
|
-
if (per.length > 0) {
|
|
1056
|
-
response.spendTime = (per[0].fetchStart > 0) ? (per[0].responseEnd - per[0].fetchStart) : "0";
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
return {
|
|
1060
|
-
// 接口用时
|
|
1061
|
-
"spendTime": response.spendTime || "0",
|
|
1062
|
-
// 请求地址url
|
|
1063
|
-
"requestUrl": response.request ? response.request.responseURL : "",
|
|
1064
|
-
// 请求id
|
|
1065
|
-
"requestId": response.config.headers ? response.config.headers.requestId : window.$CCDK.CCUtils.getUuid(),
|
|
1066
|
-
// 请求id类型
|
|
1067
|
-
"requestIdProducer": response.config.headers ? response.config.headers.requestIdProducer : "",
|
|
1068
|
-
// 请求体
|
|
1069
|
-
"requestParameter": response.config.data,
|
|
1070
|
-
// 错误描述
|
|
1071
|
-
"infoMessage": response.request.responseURL + ". took:" + (response.spendTime || 0).toFixed(0) + "ms" + "\n" + (response.config.data || ''),
|
|
1072
|
-
// 请求结果状态
|
|
1073
|
-
"requestResult": response.data.result ? "成功" : "失败",
|
|
1074
|
-
// 日志类型:info,debug
|
|
1075
|
-
"infoType": "info",
|
|
1076
|
-
}
|
|
1077
|
-
} else {
|
|
1078
|
-
return {}
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
/**
|
|
1083
|
-
* 上报日志
|
|
1084
|
-
* @param {string} url 请求地址
|
|
1085
|
-
* @param {object} response 响应信息
|
|
1086
|
-
* @param {string} type 日志类型,info,debug,error
|
|
1087
|
-
* @param {object} logInfo 日志信息
|
|
1088
|
-
*/
|
|
1089
|
-
function reportLog(url, response, type = "info", logInfo = {}) {
|
|
1090
|
-
// 某些情况下获取不到用户信息,可能是刚登陆,获取用户信息接口还没返回
|
|
1091
|
-
let userInfo = getBaseInfo();
|
|
1092
|
-
if ("未知用户" != userInfo.userName && userInfo.userName) {
|
|
1093
|
-
axios.post(url,
|
|
1094
|
-
{
|
|
1095
|
-
...userInfo,
|
|
1096
|
-
...(type === "info" ? getHttpInfo(response) : getHttpErrorInfo(response)),
|
|
1097
|
-
...logInfo
|
|
1098
|
-
});
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
*
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
983
|
+
/**
|
|
984
|
+
* 获取日志基础信息
|
|
985
|
+
* @returns 日志基础信息
|
|
986
|
+
*/
|
|
987
|
+
function getBaseInfo() {
|
|
988
|
+
let userInfo = window.$CCDK.CCUser.getUserInfo();
|
|
989
|
+
let old = {
|
|
990
|
+
// 用户名,使用登录账号
|
|
991
|
+
"userName": userInfo.loginName || "未知用户",
|
|
992
|
+
// 用户id
|
|
993
|
+
"userId": userInfo.userId,
|
|
994
|
+
// 组织id
|
|
995
|
+
"orgId": userInfo.orgId,
|
|
996
|
+
// 组织名称
|
|
997
|
+
"orgName": userInfo.orgName,
|
|
998
|
+
// 服务名称
|
|
999
|
+
"serviceName": "未知应用",
|
|
1000
|
+
// 记录类型:platform平台日志,dev开发者日志
|
|
1001
|
+
"recordType": "platform",
|
|
1002
|
+
// 日志类型
|
|
1003
|
+
"logType": "front",
|
|
1004
|
+
// 发生时间
|
|
1005
|
+
"operateTime": (new Date()).valueOf(),
|
|
1006
|
+
// 日志标识码,没有这个标识码,不能上传
|
|
1007
|
+
"cccode": "hidden",
|
|
1008
|
+
// 日志显示级别默认2
|
|
1009
|
+
"displayLevel": "2",
|
|
1010
|
+
};
|
|
1011
|
+
return old
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* 获取网络异常信息
|
|
1015
|
+
* @param {object} response 网络请求响应体
|
|
1016
|
+
* @returns 请求体信息
|
|
1017
|
+
*/
|
|
1018
|
+
function getHttpErrorInfo(error = {}) {
|
|
1019
|
+
let { config = {}, data = {} } = error;
|
|
1020
|
+
if (config) {
|
|
1021
|
+
return {
|
|
1022
|
+
// 请求地址url
|
|
1023
|
+
"requestUrl": config.baseURL + config.url,
|
|
1024
|
+
// 请求id
|
|
1025
|
+
"requestId": config.headers ? config.headers.requestId : window.$CCDK.CCUtils.getUuid(),
|
|
1026
|
+
// 请求id类型
|
|
1027
|
+
"requestIdProducer": config.headers ? config.headers.requestIdProducer : "",
|
|
1028
|
+
// 请求体
|
|
1029
|
+
"requestParameter": config.data,
|
|
1030
|
+
// 错误描述
|
|
1031
|
+
"errorMessage": error.message || data.returnInfo || "未知错误",
|
|
1032
|
+
// 请求结果状态
|
|
1033
|
+
"requestResult": "失败",
|
|
1034
|
+
// 日志级别
|
|
1035
|
+
"errorLevel": "2",
|
|
1036
|
+
// 堆栈信息
|
|
1037
|
+
"printStackTraceInfo": (error.message || data.returnInfo || "未知错误") + "\n" + config.data,
|
|
1038
|
+
}
|
|
1039
|
+
} else {
|
|
1040
|
+
return {}
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
/**
|
|
1046
|
+
* 获取网络信息
|
|
1047
|
+
* @param {object} response 网络请求响应体
|
|
1048
|
+
* @returns 请求体信息
|
|
1049
|
+
*/
|
|
1050
|
+
function getHttpInfo(response) {
|
|
1051
|
+
if (response) {
|
|
1052
|
+
if (window.performance) {
|
|
1053
|
+
// 通过性能接口精确测量接口用时
|
|
1054
|
+
let per = performance.getEntriesByName(response.request.responseURL, "resource");
|
|
1055
|
+
if (per.length > 0) {
|
|
1056
|
+
response.spendTime = (per[0].fetchStart > 0) ? (per[0].responseEnd - per[0].fetchStart) : "0";
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
return {
|
|
1060
|
+
// 接口用时
|
|
1061
|
+
"spendTime": response.spendTime || "0",
|
|
1062
|
+
// 请求地址url
|
|
1063
|
+
"requestUrl": response.request ? response.request.responseURL : "",
|
|
1064
|
+
// 请求id
|
|
1065
|
+
"requestId": response.config.headers ? response.config.headers.requestId : window.$CCDK.CCUtils.getUuid(),
|
|
1066
|
+
// 请求id类型
|
|
1067
|
+
"requestIdProducer": response.config.headers ? response.config.headers.requestIdProducer : "",
|
|
1068
|
+
// 请求体
|
|
1069
|
+
"requestParameter": response.config.data,
|
|
1070
|
+
// 错误描述
|
|
1071
|
+
"infoMessage": response.request.responseURL + ". took:" + (response.spendTime || 0).toFixed(0) + "ms" + "\n" + (response.config.data || ''),
|
|
1072
|
+
// 请求结果状态
|
|
1073
|
+
"requestResult": response.data.result ? "成功" : "失败",
|
|
1074
|
+
// 日志类型:info,debug
|
|
1075
|
+
"infoType": "info",
|
|
1076
|
+
}
|
|
1077
|
+
} else {
|
|
1078
|
+
return {}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* 上报日志
|
|
1084
|
+
* @param {string} url 请求地址
|
|
1085
|
+
* @param {object} response 响应信息
|
|
1086
|
+
* @param {string} type 日志类型,info,debug,error
|
|
1087
|
+
* @param {object} logInfo 日志信息
|
|
1088
|
+
*/
|
|
1089
|
+
function reportLog(url, response, type = "info", logInfo = {}) {
|
|
1090
|
+
// 某些情况下获取不到用户信息,可能是刚登陆,获取用户信息接口还没返回
|
|
1091
|
+
let userInfo = getBaseInfo();
|
|
1092
|
+
if ("未知用户" != userInfo.userName && userInfo.userName) {
|
|
1093
|
+
axios.post(url,
|
|
1094
|
+
{
|
|
1095
|
+
...userInfo,
|
|
1096
|
+
...(type === "info" ? getHttpInfo(response) : getHttpErrorInfo(response)),
|
|
1097
|
+
...logInfo
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
/**
|
|
1105
|
+
* 批量上报日志
|
|
1106
|
+
* @param {string} url 请求地址
|
|
1107
|
+
* @param {object} response 响应信息
|
|
1108
|
+
* @param {string} type 日志类型,info,debug,error
|
|
1109
|
+
* @param {object} logInfo 日志信息
|
|
1110
|
+
*/
|
|
1111
|
+
function batchReportLog(url, response, type = "info", logInfo = []) {
|
|
1112
|
+
// 某些情况下获取不到用户信息,可能是刚登陆,获取用户信息接口还没返回
|
|
1113
|
+
let userInfo = getBaseInfo();
|
|
1114
|
+
if ("未知用户" != userInfo.userName && userInfo.userName && logInfo.length > 0) {
|
|
1115
|
+
let datas = logInfo.map(info => {
|
|
1116
|
+
return {
|
|
1117
|
+
...userInfo,
|
|
1118
|
+
...(type === "info" ? getHttpInfo(response) : getHttpErrorInfo(response)),
|
|
1119
|
+
...info
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
axios.post(url, datas);
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
/**
|
|
1128
|
+
* 上报info日志
|
|
1129
|
+
* @param {object} logInfo 日志信息
|
|
1130
|
+
* @param {object} response axios响应信息
|
|
1131
|
+
*/
|
|
1132
|
+
function reportInfoLog(logInfo, response) {
|
|
1133
|
+
logInfo.recordType = "dev";
|
|
1134
|
+
reportLog(window.Glod['ccex-log'] + "/systeminfolog", response, "info", logInfo);
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* 上报错误信息
|
|
1138
|
+
* @param {object} logInfo 日志信息
|
|
1139
|
+
* @param {object} response axios响应信息
|
|
1140
|
+
*/
|
|
1141
|
+
function reportErrorLog(logInfo, response) {
|
|
1142
|
+
logInfo.recordType = "dev";
|
|
1143
|
+
reportLog(window.Glod['ccex-log'] + "/ccerrorlog", response, "error", logInfo);
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* CC错误日志上报:这个api目前没有使用的场景
|
|
1149
|
+
* @param {object} error 响应体
|
|
1150
|
+
* @param {object} options 配置信息
|
|
1151
|
+
*/
|
|
1152
|
+
function reportCCError(error, options = { serviceName: "lightning-main" }) {
|
|
1153
|
+
if (process.env.NODE_ENV == 'production' && "1" === window.Glod['CC_LOG_LEVEL'] || "2" === window.Glod['CC_LOG_LEVEL']) {
|
|
1154
|
+
window.$CCDK.CCLog.reportLog(window.Glod['ccex-log'] + "/ccerrorlog", error, "error", options);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* CC常规日志上报:这个api目前没有使用的场景
|
|
1159
|
+
* @param {object} response 响应体
|
|
1160
|
+
* @param {object} options 配置信息
|
|
1161
|
+
*/
|
|
1162
|
+
function reportCCInfo(response, options = { serviceName: "lightning-main" }) {
|
|
1163
|
+
if (process.env.NODE_ENV == 'production' && "2" === window.Glod['CC_LOG_LEVEL']) {
|
|
1164
|
+
if (response.config.data) {
|
|
1165
|
+
try {
|
|
1166
|
+
let data = JSON.parse(response.config.data);
|
|
1167
|
+
if (data.head && data.head.accessToken) {
|
|
1168
|
+
data.head.accessToken = "******";
|
|
1169
|
+
response.config.data = JSON.stringify(data);
|
|
1170
|
+
}
|
|
1171
|
+
} catch (e) { }
|
|
1172
|
+
}
|
|
1173
|
+
window.$CCDK.CCLog.reportLog(window.Glod['ccex-log'] + "/systeminfolog", response, "info", options);
|
|
1174
|
+
}
|
|
1150
1175
|
}
|
|
1151
1176
|
|
|
1152
1177
|
var CCLog = /*#__PURE__*/Object.freeze({
|
|
@@ -1155,78 +1180,127 @@ var CCLog = /*#__PURE__*/Object.freeze({
|
|
|
1155
1180
|
reportInfoLog: reportInfoLog,
|
|
1156
1181
|
reportErrorLog: reportErrorLog,
|
|
1157
1182
|
reportCCError: reportCCError,
|
|
1158
|
-
reportCCInfo: reportCCInfo
|
|
1183
|
+
reportCCInfo: reportCCInfo,
|
|
1184
|
+
batchReportLog: batchReportLog
|
|
1159
1185
|
});
|
|
1160
1186
|
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
*
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
*
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
*
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
*
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1187
|
+
// 存储所有菜单标识
|
|
1188
|
+
const ALL_MENU_LIST = 'all_menu_list';
|
|
1189
|
+
// 存储当前选中的菜单
|
|
1190
|
+
const CURRENT_MENU = 'current_menu';
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* 获取全部菜单
|
|
1194
|
+
*/
|
|
1195
|
+
function getAllMenu() {
|
|
1196
|
+
let data = localStorage.getItem(Crypto.encrypt(ALL_MENU_LIST));
|
|
1197
|
+
if (data) {
|
|
1198
|
+
return JSON.parse(data)
|
|
1199
|
+
}
|
|
1200
|
+
return []
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
* 设置全部菜单
|
|
1205
|
+
* @param {object} data 菜单集合
|
|
1206
|
+
*/
|
|
1207
|
+
function setAllMenu(data = []) {
|
|
1208
|
+
if (data) {
|
|
1209
|
+
localStorage.setItem(Crypto.encrypt(ALL_MENU_LIST), JSON.stringify(data));
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
/**
|
|
1214
|
+
* 缓存当前选中菜单对象
|
|
1215
|
+
* @param {object} data 菜单对象
|
|
1216
|
+
*/
|
|
1217
|
+
function setCurrentMenu(data = {}) {
|
|
1218
|
+
if (data) {
|
|
1219
|
+
localStorage.setItem(Crypto.encrypt(CURRENT_MENU), JSON.stringify(data));
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
/**
|
|
1224
|
+
* 获取当前选中菜单对象
|
|
1225
|
+
* @param {object} data 菜单对象
|
|
1226
|
+
*/
|
|
1227
|
+
function getCurrentMenu() {
|
|
1228
|
+
let data = localStorage.getItem(Crypto.encrypt(CURRENT_MENU));
|
|
1229
|
+
if (data) {
|
|
1230
|
+
return JSON.parse(data)
|
|
1231
|
+
}
|
|
1232
|
+
return {}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
/**
|
|
1236
|
+
* 添加一个一级菜单
|
|
1237
|
+
* @param {object} options 菜单配置
|
|
1238
|
+
*/
|
|
1239
|
+
function addMenu1(options) {
|
|
1240
|
+
window.$CCDK.CCBus.$emit('addMenu1', options);
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* 添加一个二级菜单
|
|
1244
|
+
* @param {object} options 菜单配置
|
|
1245
|
+
*/
|
|
1246
|
+
function addMenu2(options) {
|
|
1247
|
+
window.$CCDK.CCBus.$emit('addMenu2', options);
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* 删除一个一级菜单
|
|
1251
|
+
* @param {object} options 菜单配置
|
|
1252
|
+
*/
|
|
1253
|
+
function deleteMenu1(options) {
|
|
1254
|
+
window.$CCDK.CCBus.$emit('deleteMenu1', options);
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* 删除一个二级菜单
|
|
1258
|
+
* @param {object} options 菜单配置
|
|
1259
|
+
*/
|
|
1260
|
+
function deleteMenu2(options) {
|
|
1261
|
+
window.$CCDK.CCBus.$emit('deleteMenu2', options);
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* 刷新一个一级菜单
|
|
1265
|
+
* @param {object} options 菜单配置
|
|
1266
|
+
*/
|
|
1267
|
+
function refreshMenu1(options) {
|
|
1268
|
+
window.$CCDK.CCBus.$emit('refreshMenu1', options);
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* 刷新一个二级菜单
|
|
1272
|
+
* @param {object} options 菜单配置
|
|
1273
|
+
*/
|
|
1274
|
+
function refreshMenu2(options) {
|
|
1275
|
+
window.$CCDK.CCBus.$emit('refreshMenu2', options);
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* 替换一个一级菜单
|
|
1279
|
+
* @param {object} options 菜单配置
|
|
1280
|
+
*/
|
|
1281
|
+
function replaceMenu1(options) {
|
|
1282
|
+
window.$CCDK.CCBus.$emit('replaceMenu1', options);
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* 替换一个二级菜单
|
|
1286
|
+
* @param {object} options 菜单配置
|
|
1287
|
+
*/
|
|
1288
|
+
function replaceMenu2(options) {
|
|
1289
|
+
window.$CCDK.CCBus.$emit('replaceMenu2', options);
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* 定位到已经打开的一级菜单
|
|
1293
|
+
* @param {object} options 菜单配置
|
|
1294
|
+
*/
|
|
1295
|
+
function reOpenMenu1(options) {
|
|
1296
|
+
window.$CCDK.CCBus.$emit('reOpenMenu1', options);
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* 定位到当前一级菜单下已经打开的二级菜单(前提是当前在二级菜单下)
|
|
1300
|
+
* @param {object} options 菜单配置
|
|
1301
|
+
*/
|
|
1302
|
+
function reOpenMenu2(options) {
|
|
1303
|
+
window.$CCDK.CCBus.$emit('reOpenMenu2', options);
|
|
1230
1304
|
}
|
|
1231
1305
|
|
|
1232
1306
|
var CCMenu = /*#__PURE__*/Object.freeze({
|
|
@@ -1240,46 +1314,50 @@ var CCMenu = /*#__PURE__*/Object.freeze({
|
|
|
1240
1314
|
replaceMenu1: replaceMenu1,
|
|
1241
1315
|
replaceMenu2: replaceMenu2,
|
|
1242
1316
|
reOpenMenu1: reOpenMenu1,
|
|
1243
|
-
reOpenMenu2: reOpenMenu2
|
|
1317
|
+
reOpenMenu2: reOpenMenu2,
|
|
1318
|
+
getAllMenu: getAllMenu,
|
|
1319
|
+
setAllMenu: setAllMenu,
|
|
1320
|
+
setCurrentMenu: setCurrentMenu,
|
|
1321
|
+
getCurrentMenu: getCurrentMenu
|
|
1244
1322
|
});
|
|
1245
1323
|
|
|
1246
|
-
/**
|
|
1247
|
-
* 消息提示框
|
|
1248
|
-
* @param {string} text 提示文字,支持vhtml渲染
|
|
1249
|
-
* @param {string} type 消息类别
|
|
1250
|
-
* @param {number} duration 持续时间
|
|
1251
|
-
* @param {boolean} showClose 是否显示消息关闭按钮
|
|
1252
|
-
* @param {boolean} center 文字是否剧中
|
|
1253
|
-
*/
|
|
1254
|
-
function showMessage(text, type = 'info', duration = 3000, showClose = false, center = false) {
|
|
1255
|
-
Message({
|
|
1256
|
-
message: text,
|
|
1257
|
-
type,
|
|
1258
|
-
duration,
|
|
1259
|
-
showClose,
|
|
1260
|
-
center
|
|
1261
|
-
});
|
|
1262
|
-
}
|
|
1263
|
-
/**
|
|
1264
|
-
* 提示确认框
|
|
1265
|
-
* @param {string} text 提示信息
|
|
1266
|
-
* @param {string} title 标题
|
|
1267
|
-
* @param {object} options 配置信息
|
|
1268
|
-
*/
|
|
1269
|
-
function showConfirm(text, title, options = {}, confirm = () => { }, reject = () => { }) {
|
|
1270
|
-
MessageBox.confirm(text, title, options).then(() => {
|
|
1271
|
-
confirm();
|
|
1272
|
-
}).catch(() => {
|
|
1273
|
-
reject();
|
|
1274
|
-
});
|
|
1275
|
-
}
|
|
1276
|
-
|
|
1277
|
-
/**
|
|
1278
|
-
* 提示消息框
|
|
1279
|
-
* @param {object} options 配置信息
|
|
1280
|
-
*/
|
|
1281
|
-
function showNotification(options = {}) {
|
|
1282
|
-
Notification(options);
|
|
1324
|
+
/**
|
|
1325
|
+
* 消息提示框
|
|
1326
|
+
* @param {string} text 提示文字,支持vhtml渲染
|
|
1327
|
+
* @param {string} type 消息类别
|
|
1328
|
+
* @param {number} duration 持续时间
|
|
1329
|
+
* @param {boolean} showClose 是否显示消息关闭按钮
|
|
1330
|
+
* @param {boolean} center 文字是否剧中
|
|
1331
|
+
*/
|
|
1332
|
+
function showMessage(text, type = 'info', duration = 3000, showClose = false, center = false) {
|
|
1333
|
+
Message({
|
|
1334
|
+
message: text,
|
|
1335
|
+
type,
|
|
1336
|
+
duration,
|
|
1337
|
+
showClose,
|
|
1338
|
+
center
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* 提示确认框
|
|
1343
|
+
* @param {string} text 提示信息
|
|
1344
|
+
* @param {string} title 标题
|
|
1345
|
+
* @param {object} options 配置信息
|
|
1346
|
+
*/
|
|
1347
|
+
function showConfirm(text, title, options = {}, confirm = () => { }, reject = () => { }) {
|
|
1348
|
+
MessageBox.confirm(text, title, options).then(() => {
|
|
1349
|
+
confirm();
|
|
1350
|
+
}).catch(() => {
|
|
1351
|
+
reject();
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* 提示消息框
|
|
1357
|
+
* @param {object} options 配置信息
|
|
1358
|
+
*/
|
|
1359
|
+
function showNotification(options = {}) {
|
|
1360
|
+
Notification(options);
|
|
1283
1361
|
}
|
|
1284
1362
|
|
|
1285
1363
|
var CCMessage = /*#__PURE__*/Object.freeze({
|
|
@@ -1289,133 +1367,133 @@ var CCMessage = /*#__PURE__*/Object.freeze({
|
|
|
1289
1367
|
showNotification: showNotification
|
|
1290
1368
|
});
|
|
1291
1369
|
|
|
1292
|
-
// 对象详情存储标识
|
|
1293
|
-
const OBJECT_DETAIL = 'cc_object_detail';
|
|
1294
|
-
// 对象详情id存储标识
|
|
1295
|
-
const OBJECT_DETAIL_ID = 'cc_object_detail_id';
|
|
1296
|
-
// 对象存储标识
|
|
1297
|
-
const OBJECT = 'cc_object';
|
|
1298
|
-
// 列表视图存储标识
|
|
1299
|
-
const OBJECT_LIST = 'cc_object_list';
|
|
1300
|
-
|
|
1301
|
-
/**
|
|
1302
|
-
* 获得当前标准对象信息
|
|
1303
|
-
*/
|
|
1304
|
-
function getObject() {
|
|
1305
|
-
let detail = localStorage.getItem(Crypto.encrypt(OBJECT));
|
|
1306
|
-
if (detail) {
|
|
1307
|
-
return JSON.parse(detail)
|
|
1308
|
-
}
|
|
1309
|
-
return ''
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
/**
|
|
1313
|
-
* 设置当前标准对象信息
|
|
1314
|
-
* @param {object} detail 对象数据
|
|
1315
|
-
*/
|
|
1316
|
-
function setObject(detail = '') {
|
|
1317
|
-
if (detail) {
|
|
1318
|
-
localStorage.setItem(Crypto.encrypt(OBJECT), JSON.stringify(detail));
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
/**
|
|
1323
|
-
* 获得当前标准对象的详细信息
|
|
1324
|
-
* @param {String} apiname: 查找字段的apiname
|
|
1325
|
-
* @param {String} detailId: 详情页数据id
|
|
1326
|
-
*/
|
|
1327
|
-
function getObjectDetail(apiname, detailId) {
|
|
1328
|
-
let detail = localStorage.getItem(Crypto.encrypt(OBJECT_DETAIL));
|
|
1329
|
-
if (detail) {
|
|
1330
|
-
// 转为对象
|
|
1331
|
-
detail = JSON.parse(detail);
|
|
1332
|
-
// 没有指定详情页id,获取最后一次的id
|
|
1333
|
-
if (!detailId) {
|
|
1334
|
-
detailId = detail.id;
|
|
1335
|
-
} else {
|
|
1336
|
-
detail.id = detailId;
|
|
1337
|
-
}
|
|
1338
|
-
// 通过详情页id获取对应的详情页数据
|
|
1339
|
-
let detailList = JSON.parse(sessionStorage.getItem(detailId));
|
|
1340
|
-
if (apiname) {
|
|
1341
|
-
let targetField = undefined;
|
|
1342
|
-
if (Array.isArray(detailList)) {
|
|
1343
|
-
targetField = detailList.find(item => item.apiname === apiname);
|
|
1344
|
-
}
|
|
1345
|
-
return targetField
|
|
1346
|
-
} else {
|
|
1347
|
-
detail.detail = detailList;
|
|
1348
|
-
return detail
|
|
1349
|
-
}
|
|
1350
|
-
} else {
|
|
1351
|
-
return ''
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
/**
|
|
1357
|
-
* 设置当前标准对象的详细信息,默认两个小时有效期
|
|
1358
|
-
* @param {object} detail 对象详细数据
|
|
1359
|
-
*/
|
|
1360
|
-
function setObjectDetail(detail = '') {
|
|
1361
|
-
if (detail && detail.id) {
|
|
1362
|
-
// 减少detail.detail层级
|
|
1363
|
-
if (Array.isArray(detail.detail) && detail.detail.length > 0) {
|
|
1364
|
-
let data = [];
|
|
1365
|
-
detail.detail.forEach(item => {
|
|
1366
|
-
if (item && Array.isArray(item.data)) {
|
|
1367
|
-
item.data.forEach(itemData => {
|
|
1368
|
-
if (itemData.left && !Array.isArray(itemData.left)) {
|
|
1369
|
-
data.push(itemData.left);
|
|
1370
|
-
}
|
|
1371
|
-
if (itemData.right && !Array.isArray(itemData.right)) {
|
|
1372
|
-
data.push(itemData.right);
|
|
1373
|
-
}
|
|
1374
|
-
});
|
|
1375
|
-
}
|
|
1376
|
-
});
|
|
1377
|
-
if (data.length > 0) {
|
|
1378
|
-
detail.detail = data;
|
|
1379
|
-
// 根据详情页id,记录详情页信息
|
|
1380
|
-
sessionStorage.setItem(detail.id, JSON.stringify(data));
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
localStorage.setItem(Crypto.encrypt(OBJECT_DETAIL), JSON.stringify(detail));
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
/**
|
|
1387
|
-
* 设置当前标准对象列表选中的信息
|
|
1388
|
-
* @param {object} detail 选中数据
|
|
1389
|
-
*/
|
|
1390
|
-
function setObjectList(detail = {}) {
|
|
1391
|
-
if (detail.ids) {
|
|
1392
|
-
localStorage.setItem(Crypto.encrypt(OBJECT_LIST), JSON.stringify(detail));
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
/**
|
|
1396
|
-
* 获得当前标准对象列表选中的信息
|
|
1397
|
-
*/
|
|
1398
|
-
function getObjectList() {
|
|
1399
|
-
let detail = localStorage.getItem(Crypto.encrypt(OBJECT_LIST));
|
|
1400
|
-
if (detail) {
|
|
1401
|
-
return JSON.parse(detail)
|
|
1402
|
-
}
|
|
1403
|
-
return { ids: [] }
|
|
1404
|
-
}
|
|
1405
|
-
/**
|
|
1406
|
-
* 设置当前标准对象的详情页id
|
|
1407
|
-
* @param {object} id 对象详情页id
|
|
1408
|
-
*/
|
|
1409
|
-
function setObjectDetailId(id = '') {
|
|
1410
|
-
if (id) {
|
|
1411
|
-
localStorage.setItem(Crypto.encrypt(OBJECT_DETAIL_ID),id);
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
/**
|
|
1415
|
-
* 获取最后访问标准对象的详情页id
|
|
1416
|
-
*/
|
|
1417
|
-
function getObjectDetailId() {
|
|
1418
|
-
return localStorage.getItem(Crypto.encrypt(OBJECT_DETAIL_ID))
|
|
1370
|
+
// 对象详情存储标识
|
|
1371
|
+
const OBJECT_DETAIL = 'cc_object_detail';
|
|
1372
|
+
// 对象详情id存储标识
|
|
1373
|
+
const OBJECT_DETAIL_ID = 'cc_object_detail_id';
|
|
1374
|
+
// 对象存储标识
|
|
1375
|
+
const OBJECT = 'cc_object';
|
|
1376
|
+
// 列表视图存储标识
|
|
1377
|
+
const OBJECT_LIST = 'cc_object_list';
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* 获得当前标准对象信息
|
|
1381
|
+
*/
|
|
1382
|
+
function getObject() {
|
|
1383
|
+
let detail = localStorage.getItem(Crypto.encrypt(OBJECT));
|
|
1384
|
+
if (detail) {
|
|
1385
|
+
return JSON.parse(detail)
|
|
1386
|
+
}
|
|
1387
|
+
return ''
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
/**
|
|
1391
|
+
* 设置当前标准对象信息
|
|
1392
|
+
* @param {object} detail 对象数据
|
|
1393
|
+
*/
|
|
1394
|
+
function setObject(detail = '') {
|
|
1395
|
+
if (detail) {
|
|
1396
|
+
localStorage.setItem(Crypto.encrypt(OBJECT), JSON.stringify(detail));
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
/**
|
|
1401
|
+
* 获得当前标准对象的详细信息
|
|
1402
|
+
* @param {String} apiname: 查找字段的apiname
|
|
1403
|
+
* @param {String} detailId: 详情页数据id
|
|
1404
|
+
*/
|
|
1405
|
+
function getObjectDetail(apiname, detailId) {
|
|
1406
|
+
let detail = localStorage.getItem(Crypto.encrypt(OBJECT_DETAIL));
|
|
1407
|
+
if (detail) {
|
|
1408
|
+
// 转为对象
|
|
1409
|
+
detail = JSON.parse(detail);
|
|
1410
|
+
// 没有指定详情页id,获取最后一次的id
|
|
1411
|
+
if (!detailId) {
|
|
1412
|
+
detailId = detail.id;
|
|
1413
|
+
} else {
|
|
1414
|
+
detail.id = detailId;
|
|
1415
|
+
}
|
|
1416
|
+
// 通过详情页id获取对应的详情页数据
|
|
1417
|
+
let detailList = JSON.parse(sessionStorage.getItem(detailId));
|
|
1418
|
+
if (apiname) {
|
|
1419
|
+
let targetField = undefined;
|
|
1420
|
+
if (Array.isArray(detailList)) {
|
|
1421
|
+
targetField = detailList.find(item => item.apiname === apiname);
|
|
1422
|
+
}
|
|
1423
|
+
return targetField
|
|
1424
|
+
} else {
|
|
1425
|
+
detail.detail = detailList;
|
|
1426
|
+
return detail
|
|
1427
|
+
}
|
|
1428
|
+
} else {
|
|
1429
|
+
return ''
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
/**
|
|
1435
|
+
* 设置当前标准对象的详细信息,默认两个小时有效期
|
|
1436
|
+
* @param {object} detail 对象详细数据
|
|
1437
|
+
*/
|
|
1438
|
+
function setObjectDetail(detail = '') {
|
|
1439
|
+
if (detail && detail.id) {
|
|
1440
|
+
// 减少detail.detail层级
|
|
1441
|
+
if (Array.isArray(detail.detail) && detail.detail.length > 0) {
|
|
1442
|
+
let data = [];
|
|
1443
|
+
detail.detail.forEach(item => {
|
|
1444
|
+
if (item && Array.isArray(item.data)) {
|
|
1445
|
+
item.data.forEach(itemData => {
|
|
1446
|
+
if (itemData.left && !Array.isArray(itemData.left)) {
|
|
1447
|
+
data.push(itemData.left);
|
|
1448
|
+
}
|
|
1449
|
+
if (itemData.right && !Array.isArray(itemData.right)) {
|
|
1450
|
+
data.push(itemData.right);
|
|
1451
|
+
}
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
if (data.length > 0) {
|
|
1456
|
+
detail.detail = data;
|
|
1457
|
+
// 根据详情页id,记录详情页信息
|
|
1458
|
+
sessionStorage.setItem(detail.id, JSON.stringify(data));
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
localStorage.setItem(Crypto.encrypt(OBJECT_DETAIL), JSON.stringify(detail));
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* 设置当前标准对象列表选中的信息
|
|
1466
|
+
* @param {object} detail 选中数据
|
|
1467
|
+
*/
|
|
1468
|
+
function setObjectList(detail = {}) {
|
|
1469
|
+
if (detail.ids) {
|
|
1470
|
+
localStorage.setItem(Crypto.encrypt(OBJECT_LIST), JSON.stringify(detail));
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* 获得当前标准对象列表选中的信息
|
|
1475
|
+
*/
|
|
1476
|
+
function getObjectList() {
|
|
1477
|
+
let detail = localStorage.getItem(Crypto.encrypt(OBJECT_LIST));
|
|
1478
|
+
if (detail) {
|
|
1479
|
+
return JSON.parse(detail)
|
|
1480
|
+
}
|
|
1481
|
+
return { ids: [] }
|
|
1482
|
+
}
|
|
1483
|
+
/**
|
|
1484
|
+
* 设置当前标准对象的详情页id
|
|
1485
|
+
* @param {object} id 对象详情页id
|
|
1486
|
+
*/
|
|
1487
|
+
function setObjectDetailId(id = '') {
|
|
1488
|
+
if (id) {
|
|
1489
|
+
localStorage.setItem(Crypto.encrypt(OBJECT_DETAIL_ID),id);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* 获取最后访问标准对象的详情页id
|
|
1494
|
+
*/
|
|
1495
|
+
function getObjectDetailId() {
|
|
1496
|
+
return localStorage.getItem(Crypto.encrypt(OBJECT_DETAIL_ID))
|
|
1419
1497
|
}
|
|
1420
1498
|
|
|
1421
1499
|
var CCObject = /*#__PURE__*/Object.freeze({
|
|
@@ -1430,177 +1508,177 @@ var CCObject = /*#__PURE__*/Object.freeze({
|
|
|
1430
1508
|
getObjectDetailId: getObjectDetailId
|
|
1431
1509
|
});
|
|
1432
1510
|
|
|
1433
|
-
/**
|
|
1434
|
-
* 用于保存打开的页面集合
|
|
1435
|
-
*/
|
|
1436
|
-
let pageList = new Map();
|
|
1437
|
-
/**
|
|
1438
|
-
* 打开对象视图页面
|
|
1439
|
-
* @param {object} obj 对象信息
|
|
1440
|
-
* @param {object} options 配置信息
|
|
1441
|
-
*/
|
|
1442
|
-
function openListPage(obj, options = {}) {
|
|
1443
|
-
let pageId = options.pageId||Math.random().toString(16).slice(2);
|
|
1444
|
-
window.$CCDK.CCBus.$emit('openListPage', pageId, obj, options);
|
|
1445
|
-
return pageId;
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
/**
|
|
1449
|
-
* 打开数据详情页
|
|
1450
|
-
* @param {object} obj 对象体
|
|
1451
|
-
* @param {string} id 数据id
|
|
1452
|
-
* @param {object} options 配置信息
|
|
1453
|
-
*/
|
|
1454
|
-
function openDetailPage(obj, id, options = {}) {
|
|
1455
|
-
let pageId = options.pageId||Math.random().toString(16).slice(2);
|
|
1456
|
-
window.$CCDK.CCBus.$emit('openDetailPage', pageId, obj, id, options);
|
|
1457
|
-
return pageId;
|
|
1458
|
-
}
|
|
1459
|
-
|
|
1460
|
-
/**
|
|
1461
|
-
* 打开创建页面
|
|
1462
|
-
* @param {object} obj 对象体
|
|
1463
|
-
* @param {object} options 配置信息
|
|
1464
|
-
*/
|
|
1465
|
-
function openCreatePage(obj, options = {}) {
|
|
1466
|
-
let pageId = options.pageId||Math.random().toString(16).slice(2);
|
|
1467
|
-
window.$CCDK.CCBus.$emit('openCreatePage', pageId, obj, options);
|
|
1468
|
-
return pageId;
|
|
1469
|
-
}
|
|
1470
|
-
|
|
1471
|
-
/**
|
|
1472
|
-
* 打开修改页面
|
|
1473
|
-
* @param {object} obj 对象体
|
|
1474
|
-
* @param {string} id 数据id
|
|
1475
|
-
* @param {object} options 配置信息
|
|
1476
|
-
*/
|
|
1477
|
-
function openEditPage(obj, id, options = {}) {
|
|
1478
|
-
let pageId = options.pageId||Math.random().toString(16).slice(2);
|
|
1479
|
-
window.$CCDK.CCBus.$emit('openEditPage', pageId, obj, id, options);
|
|
1480
|
-
return pageId;
|
|
1481
|
-
}
|
|
1482
|
-
/**
|
|
1483
|
-
* 打开自定义页面
|
|
1484
|
-
* @param {object} obj 自定义页面参数
|
|
1485
|
-
* @param {object} options 配置信息
|
|
1486
|
-
*/
|
|
1487
|
-
function openCustomPage(obj, options = {}) {
|
|
1488
|
-
let pageId = options.pageId||Math.random().toString(16).slice(2);
|
|
1489
|
-
window.$CCDK.CCBus.$emit('openCustomPage', pageId, obj, options);
|
|
1490
|
-
return pageId;
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
/**
|
|
1494
|
-
* 通过页面id,重新打开某个页面
|
|
1495
|
-
* @param {string} pageId 页面id
|
|
1496
|
-
* @param {object} options 配置信息
|
|
1497
|
-
*/
|
|
1498
|
-
function reOpenPage(pageId, options) {
|
|
1499
|
-
let page;
|
|
1500
|
-
if (pageId) {
|
|
1501
|
-
page = pageList.get(pageId);
|
|
1502
|
-
}
|
|
1503
|
-
if (page) {
|
|
1504
|
-
page.reOpenPage();
|
|
1505
|
-
if (options.refresh) {
|
|
1506
|
-
page.refresh();
|
|
1507
|
-
}
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
|
|
1511
|
-
/**
|
|
1512
|
-
* 将打开的页面添加到集合中
|
|
1513
|
-
* @param {string} id 唯一ID
|
|
1514
|
-
* @param {object} page 页面对象
|
|
1515
|
-
*/
|
|
1516
|
-
function addPage(id, page) {
|
|
1517
|
-
if (id && page) {
|
|
1518
|
-
pageList.set(id, page);
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
/**
|
|
1523
|
-
* 删除某个页面
|
|
1524
|
-
* @param {string} pageId 唯一ID
|
|
1525
|
-
*/
|
|
1526
|
-
function deletePage(pageId) {
|
|
1527
|
-
if (pageId) {
|
|
1528
|
-
pageList.delete(pageId);
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
/**
|
|
1532
|
-
* 更改页面数据
|
|
1533
|
-
* @param {string} id 唯一ID
|
|
1534
|
-
* @param {object} page 页面对象
|
|
1535
|
-
*/
|
|
1536
|
-
function updatePage(id, page) {
|
|
1537
|
-
if (id && page) {
|
|
1538
|
-
pageList.set(id, page);
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
/**
|
|
1543
|
-
* 通过页面id查询页面
|
|
1544
|
-
* @param {string} pageId 唯一ID
|
|
1545
|
-
*/
|
|
1546
|
-
function searchPage(pageId) {
|
|
1547
|
-
return pageList.get(pageId)
|
|
1548
|
-
}
|
|
1549
|
-
/**
|
|
1550
|
-
* 关闭页面,如果pageId为null,那么关闭当前页面
|
|
1551
|
-
* 如果pageId为all,关闭所有一级菜单
|
|
1552
|
-
* @param {string} pageId 页面id
|
|
1553
|
-
*/
|
|
1554
|
-
function close$1(pageId = '') {
|
|
1555
|
-
let page;
|
|
1556
|
-
if(pageId === 'all'){
|
|
1557
|
-
page = [...pageList.values()];
|
|
1558
|
-
page.forEach(item => {
|
|
1559
|
-
if(item){
|
|
1560
|
-
item.close();
|
|
1561
|
-
}
|
|
1562
|
-
});
|
|
1563
|
-
}else if (pageId) {
|
|
1564
|
-
page = pageList.get(pageId);
|
|
1565
|
-
} else {
|
|
1566
|
-
// 不传pageId 默认关闭当前选中的
|
|
1567
|
-
// 当前选中菜单的树形结构
|
|
1568
|
-
let currentMenuTree = JSON.parse(localStorage.getItem('current_page'));
|
|
1569
|
-
if (currentMenuTree) {
|
|
1570
|
-
// 说明当前选中的是二级菜单
|
|
1571
|
-
if (currentMenuTree.level2Id) {
|
|
1572
|
-
page = pageList.get(currentMenuTree.level2Id);
|
|
1573
|
-
} else {
|
|
1574
|
-
// 说明当前选中的是一级菜单
|
|
1575
|
-
page = pageList.get(currentMenuTree.id);
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
// if (pageList.size > 0) {
|
|
1579
|
-
// page = [...pageList.values()][pageList.size - 1]
|
|
1580
|
-
// }
|
|
1581
|
-
}
|
|
1582
|
-
if (page) {
|
|
1583
|
-
page.close();
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
/**
|
|
1587
|
-
* 刷新当前页面
|
|
1588
|
-
*/
|
|
1589
|
-
function refresh() {
|
|
1590
|
-
window.$CCDK.CCBus.$emit('refresh');
|
|
1591
|
-
}
|
|
1592
|
-
/**
|
|
1593
|
-
* 获取当前一二级选中菜单的树形结构
|
|
1594
|
-
* @param {object} obj 自定义页面参数
|
|
1595
|
-
* @param {object} options 配置信息
|
|
1596
|
-
*/
|
|
1597
|
-
function getCurrentPage() {
|
|
1598
|
-
// 当前选中菜单的树形结构
|
|
1599
|
-
let currentMenuTree = localStorage.getItem('current_page');
|
|
1600
|
-
if (currentMenuTree) {
|
|
1601
|
-
return JSON.parse(currentMenuTree)
|
|
1602
|
-
}
|
|
1603
|
-
return ''
|
|
1511
|
+
/**
|
|
1512
|
+
* 用于保存打开的页面集合
|
|
1513
|
+
*/
|
|
1514
|
+
let pageList = new Map();
|
|
1515
|
+
/**
|
|
1516
|
+
* 打开对象视图页面
|
|
1517
|
+
* @param {object} obj 对象信息
|
|
1518
|
+
* @param {object} options 配置信息
|
|
1519
|
+
*/
|
|
1520
|
+
function openListPage(obj, options = {}) {
|
|
1521
|
+
let pageId = options.pageId||Math.random().toString(16).slice(2);
|
|
1522
|
+
window.$CCDK.CCBus.$emit('openListPage', pageId, obj, options);
|
|
1523
|
+
return pageId;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
/**
|
|
1527
|
+
* 打开数据详情页
|
|
1528
|
+
* @param {object} obj 对象体
|
|
1529
|
+
* @param {string} id 数据id
|
|
1530
|
+
* @param {object} options 配置信息
|
|
1531
|
+
*/
|
|
1532
|
+
function openDetailPage(obj, id, options = {}) {
|
|
1533
|
+
let pageId = options.pageId||Math.random().toString(16).slice(2);
|
|
1534
|
+
window.$CCDK.CCBus.$emit('openDetailPage', pageId, obj, id, options);
|
|
1535
|
+
return pageId;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
/**
|
|
1539
|
+
* 打开创建页面
|
|
1540
|
+
* @param {object} obj 对象体
|
|
1541
|
+
* @param {object} options 配置信息
|
|
1542
|
+
*/
|
|
1543
|
+
function openCreatePage(obj, options = {}) {
|
|
1544
|
+
let pageId = options.pageId||Math.random().toString(16).slice(2);
|
|
1545
|
+
window.$CCDK.CCBus.$emit('openCreatePage', pageId, obj, options);
|
|
1546
|
+
return pageId;
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
/**
|
|
1550
|
+
* 打开修改页面
|
|
1551
|
+
* @param {object} obj 对象体
|
|
1552
|
+
* @param {string} id 数据id
|
|
1553
|
+
* @param {object} options 配置信息
|
|
1554
|
+
*/
|
|
1555
|
+
function openEditPage(obj, id, options = {}) {
|
|
1556
|
+
let pageId = options.pageId||Math.random().toString(16).slice(2);
|
|
1557
|
+
window.$CCDK.CCBus.$emit('openEditPage', pageId, obj, id, options);
|
|
1558
|
+
return pageId;
|
|
1559
|
+
}
|
|
1560
|
+
/**
|
|
1561
|
+
* 打开自定义页面
|
|
1562
|
+
* @param {object} obj 自定义页面参数
|
|
1563
|
+
* @param {object} options 配置信息
|
|
1564
|
+
*/
|
|
1565
|
+
function openCustomPage(obj, options = {}) {
|
|
1566
|
+
let pageId = options.pageId||Math.random().toString(16).slice(2);
|
|
1567
|
+
window.$CCDK.CCBus.$emit('openCustomPage', pageId, obj, options);
|
|
1568
|
+
return pageId;
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
/**
|
|
1572
|
+
* 通过页面id,重新打开某个页面
|
|
1573
|
+
* @param {string} pageId 页面id
|
|
1574
|
+
* @param {object} options 配置信息
|
|
1575
|
+
*/
|
|
1576
|
+
function reOpenPage(pageId, options) {
|
|
1577
|
+
let page;
|
|
1578
|
+
if (pageId) {
|
|
1579
|
+
page = pageList.get(pageId);
|
|
1580
|
+
}
|
|
1581
|
+
if (page) {
|
|
1582
|
+
page.reOpenPage();
|
|
1583
|
+
if (options.refresh) {
|
|
1584
|
+
page.refresh();
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
/**
|
|
1590
|
+
* 将打开的页面添加到集合中
|
|
1591
|
+
* @param {string} id 唯一ID
|
|
1592
|
+
* @param {object} page 页面对象
|
|
1593
|
+
*/
|
|
1594
|
+
function addPage(id, page) {
|
|
1595
|
+
if (id && page) {
|
|
1596
|
+
pageList.set(id, page);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
/**
|
|
1601
|
+
* 删除某个页面
|
|
1602
|
+
* @param {string} pageId 唯一ID
|
|
1603
|
+
*/
|
|
1604
|
+
function deletePage(pageId) {
|
|
1605
|
+
if (pageId) {
|
|
1606
|
+
pageList.delete(pageId);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
/**
|
|
1610
|
+
* 更改页面数据
|
|
1611
|
+
* @param {string} id 唯一ID
|
|
1612
|
+
* @param {object} page 页面对象
|
|
1613
|
+
*/
|
|
1614
|
+
function updatePage(id, page) {
|
|
1615
|
+
if (id && page) {
|
|
1616
|
+
pageList.set(id, page);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
/**
|
|
1621
|
+
* 通过页面id查询页面
|
|
1622
|
+
* @param {string} pageId 唯一ID
|
|
1623
|
+
*/
|
|
1624
|
+
function searchPage(pageId) {
|
|
1625
|
+
return pageList.get(pageId)
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* 关闭页面,如果pageId为null,那么关闭当前页面
|
|
1629
|
+
* 如果pageId为all,关闭所有一级菜单
|
|
1630
|
+
* @param {string} pageId 页面id
|
|
1631
|
+
*/
|
|
1632
|
+
function close$1(pageId = '') {
|
|
1633
|
+
let page;
|
|
1634
|
+
if(pageId === 'all'){
|
|
1635
|
+
page = [...pageList.values()];
|
|
1636
|
+
page.forEach(item => {
|
|
1637
|
+
if(item){
|
|
1638
|
+
item.close();
|
|
1639
|
+
}
|
|
1640
|
+
});
|
|
1641
|
+
}else if (pageId) {
|
|
1642
|
+
page = pageList.get(pageId);
|
|
1643
|
+
} else {
|
|
1644
|
+
// 不传pageId 默认关闭当前选中的
|
|
1645
|
+
// 当前选中菜单的树形结构
|
|
1646
|
+
let currentMenuTree = JSON.parse(localStorage.getItem('current_page'));
|
|
1647
|
+
if (currentMenuTree) {
|
|
1648
|
+
// 说明当前选中的是二级菜单
|
|
1649
|
+
if (currentMenuTree.level2Id) {
|
|
1650
|
+
page = pageList.get(currentMenuTree.level2Id);
|
|
1651
|
+
} else {
|
|
1652
|
+
// 说明当前选中的是一级菜单
|
|
1653
|
+
page = pageList.get(currentMenuTree.id);
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
// if (pageList.size > 0) {
|
|
1657
|
+
// page = [...pageList.values()][pageList.size - 1]
|
|
1658
|
+
// }
|
|
1659
|
+
}
|
|
1660
|
+
if (page) {
|
|
1661
|
+
page.close();
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
/**
|
|
1665
|
+
* 刷新当前页面
|
|
1666
|
+
*/
|
|
1667
|
+
function refresh() {
|
|
1668
|
+
window.$CCDK.CCBus.$emit('refresh');
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
* 获取当前一二级选中菜单的树形结构
|
|
1672
|
+
* @param {object} obj 自定义页面参数
|
|
1673
|
+
* @param {object} options 配置信息
|
|
1674
|
+
*/
|
|
1675
|
+
function getCurrentPage() {
|
|
1676
|
+
// 当前选中菜单的树形结构
|
|
1677
|
+
let currentMenuTree = localStorage.getItem('current_page');
|
|
1678
|
+
if (currentMenuTree) {
|
|
1679
|
+
return JSON.parse(currentMenuTree)
|
|
1680
|
+
}
|
|
1681
|
+
return ''
|
|
1604
1682
|
}
|
|
1605
1683
|
|
|
1606
1684
|
var CCPage = /*#__PURE__*/Object.freeze({
|
|
@@ -1620,62 +1698,62 @@ var CCPage = /*#__PURE__*/Object.freeze({
|
|
|
1620
1698
|
getCurrentPage: getCurrentPage
|
|
1621
1699
|
});
|
|
1622
1700
|
|
|
1623
|
-
/**
|
|
1624
|
-
* 设置用户信息
|
|
1625
|
-
* @param {object} sentry
|
|
1626
|
-
* @param {object} ccUser 用户信息
|
|
1627
|
-
*/
|
|
1628
|
-
function initUserInfo(sentry, ccUser = window.$CCDK.CCUser.getUserInfo()) {
|
|
1629
|
-
if (ccUser && ccUser != "") {
|
|
1630
|
-
// 添加日志监控标签:组织id
|
|
1631
|
-
sentry.setTag("orgId", ccUser.orgId);
|
|
1632
|
-
// 添加日志监控标签:组织名称
|
|
1633
|
-
sentry.setTag("orgName", ccUser.orgName);
|
|
1634
|
-
// 添加日志监控标签:用户id和用户名称
|
|
1635
|
-
sentry.setUser({
|
|
1636
|
-
username: ccUser.userName,
|
|
1637
|
-
id: ccUser.userId,
|
|
1638
|
-
});
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
/**
|
|
1642
|
-
* 内存上报
|
|
1643
|
-
* @param {object} sentry
|
|
1644
|
-
*/
|
|
1645
|
-
function reportMemory(sentry, ccUser) {
|
|
1646
|
-
if (performance.memory) {
|
|
1647
|
-
let memeryMsg =
|
|
1648
|
-
"内存监控:jsHeapSizeLimit=" +
|
|
1649
|
-
(performance.memory.jsHeapSizeLimit / 1024 / 1024).toFixed(2) +
|
|
1650
|
-
"mb、" +
|
|
1651
|
-
"totalJSHeapSize=" +
|
|
1652
|
-
(performance.memory.totalJSHeapSize / 1024 / 1024).toFixed(2) +
|
|
1653
|
-
"mb、" +
|
|
1654
|
-
"usedJSHeapSize=" +
|
|
1655
|
-
(performance.memory.usedJSHeapSize / 1024 / 1024).toFixed(2) +
|
|
1656
|
-
"mb";
|
|
1657
|
-
initUserInfo(sentry, ccUser);
|
|
1658
|
-
sentry.withScope(function (scope) {
|
|
1659
|
-
// 使用内存
|
|
1660
|
-
sentry.setTag("usedJSHeapSize", (performance.memory.usedJSHeapSize / 1024 / 1024).toFixed(2));
|
|
1661
|
-
// 添加日志监控标签:组织id
|
|
1662
|
-
scope.setFingerprint(["内存监控"]);
|
|
1663
|
-
sentry.captureMessage(memeryMsg);
|
|
1664
|
-
});
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
/**
|
|
1669
|
-
* 网络异常上报
|
|
1670
|
-
* @param {object} sentry
|
|
1671
|
-
* @param {error} error
|
|
1672
|
-
*/
|
|
1673
|
-
function reportHttpException(sentry, error, ccUser) {
|
|
1674
|
-
initUserInfo(sentry, ccUser);
|
|
1675
|
-
sentry.withScope(function (scope) {
|
|
1676
|
-
scope.setFingerprint(["接口未捕获异常response"]);
|
|
1677
|
-
sentry.captureException(error);
|
|
1678
|
-
});
|
|
1701
|
+
/**
|
|
1702
|
+
* 设置用户信息
|
|
1703
|
+
* @param {object} sentry
|
|
1704
|
+
* @param {object} ccUser 用户信息
|
|
1705
|
+
*/
|
|
1706
|
+
function initUserInfo(sentry, ccUser = window.$CCDK.CCUser.getUserInfo()) {
|
|
1707
|
+
if (ccUser && ccUser != "") {
|
|
1708
|
+
// 添加日志监控标签:组织id
|
|
1709
|
+
sentry.setTag("orgId", ccUser.orgId);
|
|
1710
|
+
// 添加日志监控标签:组织名称
|
|
1711
|
+
sentry.setTag("orgName", ccUser.orgName);
|
|
1712
|
+
// 添加日志监控标签:用户id和用户名称
|
|
1713
|
+
sentry.setUser({
|
|
1714
|
+
username: ccUser.userName,
|
|
1715
|
+
id: ccUser.userId,
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
/**
|
|
1720
|
+
* 内存上报
|
|
1721
|
+
* @param {object} sentry
|
|
1722
|
+
*/
|
|
1723
|
+
function reportMemory(sentry, ccUser) {
|
|
1724
|
+
if (performance.memory) {
|
|
1725
|
+
let memeryMsg =
|
|
1726
|
+
"内存监控:jsHeapSizeLimit=" +
|
|
1727
|
+
(performance.memory.jsHeapSizeLimit / 1024 / 1024).toFixed(2) +
|
|
1728
|
+
"mb、" +
|
|
1729
|
+
"totalJSHeapSize=" +
|
|
1730
|
+
(performance.memory.totalJSHeapSize / 1024 / 1024).toFixed(2) +
|
|
1731
|
+
"mb、" +
|
|
1732
|
+
"usedJSHeapSize=" +
|
|
1733
|
+
(performance.memory.usedJSHeapSize / 1024 / 1024).toFixed(2) +
|
|
1734
|
+
"mb";
|
|
1735
|
+
initUserInfo(sentry, ccUser);
|
|
1736
|
+
sentry.withScope(function (scope) {
|
|
1737
|
+
// 使用内存
|
|
1738
|
+
sentry.setTag("usedJSHeapSize", (performance.memory.usedJSHeapSize / 1024 / 1024).toFixed(2));
|
|
1739
|
+
// 添加日志监控标签:组织id
|
|
1740
|
+
scope.setFingerprint(["内存监控"]);
|
|
1741
|
+
sentry.captureMessage(memeryMsg);
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
/**
|
|
1747
|
+
* 网络异常上报
|
|
1748
|
+
* @param {object} sentry
|
|
1749
|
+
* @param {error} error
|
|
1750
|
+
*/
|
|
1751
|
+
function reportHttpException(sentry, error, ccUser) {
|
|
1752
|
+
initUserInfo(sentry, ccUser);
|
|
1753
|
+
sentry.withScope(function (scope) {
|
|
1754
|
+
scope.setFingerprint(["接口未捕获异常response"]);
|
|
1755
|
+
sentry.captureException(error);
|
|
1756
|
+
});
|
|
1679
1757
|
}
|
|
1680
1758
|
|
|
1681
1759
|
var CCSentry = /*#__PURE__*/Object.freeze({
|
|
@@ -1685,24 +1763,24 @@ var CCSentry = /*#__PURE__*/Object.freeze({
|
|
|
1685
1763
|
reportHttpException: reportHttpException
|
|
1686
1764
|
});
|
|
1687
1765
|
|
|
1688
|
-
/**
|
|
1689
|
-
* 初始化侧边区域
|
|
1690
|
-
* @param {object} options 自定义页面配置
|
|
1691
|
-
*/
|
|
1692
|
-
function init(options) {
|
|
1693
|
-
window.$CCDK.CCBus.$emit('initSide', options);
|
|
1694
|
-
}
|
|
1695
|
-
/**
|
|
1696
|
-
* 打开侧边区域
|
|
1697
|
-
*/
|
|
1698
|
-
function open() {
|
|
1699
|
-
window.$CCDK.CCBus.$emit('openSide');
|
|
1700
|
-
}
|
|
1701
|
-
/**
|
|
1702
|
-
* 关闭侧边区域
|
|
1703
|
-
*/
|
|
1704
|
-
function close() {
|
|
1705
|
-
window.$CCDK.CCBus.$emit('closeSide');
|
|
1766
|
+
/**
|
|
1767
|
+
* 初始化侧边区域
|
|
1768
|
+
* @param {object} options 自定义页面配置
|
|
1769
|
+
*/
|
|
1770
|
+
function init(options) {
|
|
1771
|
+
window.$CCDK.CCBus.$emit('initSide', options);
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* 打开侧边区域
|
|
1775
|
+
*/
|
|
1776
|
+
function open() {
|
|
1777
|
+
window.$CCDK.CCBus.$emit('openSide');
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* 关闭侧边区域
|
|
1781
|
+
*/
|
|
1782
|
+
function close() {
|
|
1783
|
+
window.$CCDK.CCBus.$emit('closeSide');
|
|
1706
1784
|
}
|
|
1707
1785
|
|
|
1708
1786
|
var CCSide = /*#__PURE__*/Object.freeze({
|
|
@@ -1712,52 +1790,52 @@ var CCSide = /*#__PURE__*/Object.freeze({
|
|
|
1712
1790
|
close: close
|
|
1713
1791
|
});
|
|
1714
1792
|
|
|
1715
|
-
// cookie存储标识
|
|
1716
|
-
const TOKEN = "cc_token";
|
|
1717
|
-
/**
|
|
1718
|
-
* 获取URL中参数的数据
|
|
1719
|
-
* @param {name} 参数名
|
|
1720
|
-
*/
|
|
1721
|
-
function getUrlQuery(name) {
|
|
1722
|
-
var reg = new RegExp(name + "=([^&]*)(&|$)");
|
|
1723
|
-
var r = window.location.href.match(reg);
|
|
1724
|
-
let res = null;
|
|
1725
|
-
if (r != null) res = r[1].trim();
|
|
1726
|
-
return res;
|
|
1727
|
-
}
|
|
1728
|
-
/**
|
|
1729
|
-
* 获取token:优先级-url最高,cc_token-cookies第二,binding-cookies第三
|
|
1730
|
-
* @param {String} urlName 获取token的url名称
|
|
1731
|
-
* @param {String} cookieName 获取token的cookie名称
|
|
1732
|
-
* @returns
|
|
1733
|
-
*/
|
|
1734
|
-
function getToken(urlName = "binding", cookieName = TOKEN) {
|
|
1735
|
-
let token = getUrlQuery(urlName) || Cookies.get(Crypto.encrypt(cookieName)) || Cookies.get(urlName||TOKEN);
|
|
1736
|
-
// 如果存在token,那么存储到cookies中,刷新有效期
|
|
1737
|
-
if (token) {
|
|
1738
|
-
setToken(token, cookieName);
|
|
1739
|
-
}
|
|
1740
|
-
return token
|
|
1741
|
-
}
|
|
1742
|
-
/**
|
|
1743
|
-
* 存储token
|
|
1744
|
-
* @param {String} token token
|
|
1745
|
-
* @param {String} cookieName 获取token的cookie名称
|
|
1746
|
-
* @param {String} domain 域名
|
|
1747
|
-
*/
|
|
1748
|
-
function setToken(token, cookieName = TOKEN, domain = getDomain()) {
|
|
1749
|
-
Cookies.set(Crypto.encrypt(cookieName), token, { domain: domain, expires: 1 / 12 });
|
|
1750
|
-
Cookies.set(Crypto.encrypt(cookieName), token, { expires: 1 / 12 });
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
/**
|
|
1754
|
-
* 清除Token数据
|
|
1755
|
-
* @param {String} domain 域名
|
|
1756
|
-
* @param {String} cookieName 获取token的cookie名称
|
|
1757
|
-
*/
|
|
1758
|
-
function clearToken(cookieName = TOKEN, domain = getDomain()) {
|
|
1759
|
-
Cookies.remove(Crypto.encrypt(cookieName), { domain: domain });
|
|
1760
|
-
Cookies.remove(Crypto.encrypt(cookieName));
|
|
1793
|
+
// cookie存储标识
|
|
1794
|
+
const TOKEN = "cc_token";
|
|
1795
|
+
/**
|
|
1796
|
+
* 获取URL中参数的数据
|
|
1797
|
+
* @param {name} 参数名
|
|
1798
|
+
*/
|
|
1799
|
+
function getUrlQuery(name) {
|
|
1800
|
+
var reg = new RegExp(name + "=([^&]*)(&|$)");
|
|
1801
|
+
var r = window.location.href.match(reg);
|
|
1802
|
+
let res = null;
|
|
1803
|
+
if (r != null) res = r[1].trim();
|
|
1804
|
+
return res;
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* 获取token:优先级-url最高,cc_token-cookies第二,binding-cookies第三
|
|
1808
|
+
* @param {String} urlName 获取token的url名称
|
|
1809
|
+
* @param {String} cookieName 获取token的cookie名称
|
|
1810
|
+
* @returns
|
|
1811
|
+
*/
|
|
1812
|
+
function getToken(urlName = "binding", cookieName = TOKEN) {
|
|
1813
|
+
let token = getUrlQuery(urlName) || Cookies.get(Crypto.encrypt(cookieName)) || Cookies.get(urlName||TOKEN);
|
|
1814
|
+
// 如果存在token,那么存储到cookies中,刷新有效期
|
|
1815
|
+
if (token) {
|
|
1816
|
+
setToken(token, cookieName);
|
|
1817
|
+
}
|
|
1818
|
+
return token
|
|
1819
|
+
}
|
|
1820
|
+
/**
|
|
1821
|
+
* 存储token
|
|
1822
|
+
* @param {String} token token
|
|
1823
|
+
* @param {String} cookieName 获取token的cookie名称
|
|
1824
|
+
* @param {String} domain 域名
|
|
1825
|
+
*/
|
|
1826
|
+
function setToken(token, cookieName = TOKEN, domain = getDomain()) {
|
|
1827
|
+
Cookies.set(Crypto.encrypt(cookieName), token, { domain: domain, expires: 1 / 12 });
|
|
1828
|
+
Cookies.set(Crypto.encrypt(cookieName), token, { expires: 1 / 12 });
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
/**
|
|
1832
|
+
* 清除Token数据
|
|
1833
|
+
* @param {String} domain 域名
|
|
1834
|
+
* @param {String} cookieName 获取token的cookie名称
|
|
1835
|
+
*/
|
|
1836
|
+
function clearToken(cookieName = TOKEN, domain = getDomain()) {
|
|
1837
|
+
Cookies.remove(Crypto.encrypt(cookieName), { domain: domain });
|
|
1838
|
+
Cookies.remove(Crypto.encrypt(cookieName));
|
|
1761
1839
|
}
|
|
1762
1840
|
|
|
1763
1841
|
var CCToken = /*#__PURE__*/Object.freeze({
|
|
@@ -1768,31 +1846,31 @@ var CCToken = /*#__PURE__*/Object.freeze({
|
|
|
1768
1846
|
getUrlQuery: getUrlQuery
|
|
1769
1847
|
});
|
|
1770
1848
|
|
|
1771
|
-
// cookie存储标识
|
|
1772
|
-
const USER_INFO = "cc_user_info";
|
|
1773
|
-
|
|
1774
|
-
/**
|
|
1775
|
-
* 存储用户信息
|
|
1776
|
-
* @param {String} userInfo 用户信息
|
|
1777
|
-
* @param {String} domain 域名
|
|
1778
|
-
*/
|
|
1779
|
-
function setUserInfo(userInfo, domain = getDomain()) {
|
|
1780
|
-
Cookies.set(Crypto.encrypt(USER_INFO), Crypto.encrypt(userInfo), { domain: domain, expires: 1 / 12 });
|
|
1781
|
-
Cookies.set(Crypto.encrypt(USER_INFO), Crypto.encrypt(userInfo), { expires: 1 / 12 });
|
|
1782
|
-
}
|
|
1783
|
-
|
|
1784
|
-
/**
|
|
1785
|
-
* 获取用户信息
|
|
1786
|
-
* @returns {String} 用户信息
|
|
1787
|
-
*/
|
|
1788
|
-
function getUserInfo() {
|
|
1789
|
-
// 加密的用户信息
|
|
1790
|
-
let encryptUserInfo = Cookies.get(Crypto.encrypt(USER_INFO));
|
|
1791
|
-
if (encryptUserInfo) {
|
|
1792
|
-
return Crypto.decrypt(encryptUserInfo)
|
|
1793
|
-
} else {
|
|
1794
|
-
return ""
|
|
1795
|
-
}
|
|
1849
|
+
// cookie存储标识
|
|
1850
|
+
const USER_INFO = "cc_user_info";
|
|
1851
|
+
|
|
1852
|
+
/**
|
|
1853
|
+
* 存储用户信息
|
|
1854
|
+
* @param {String} userInfo 用户信息
|
|
1855
|
+
* @param {String} domain 域名
|
|
1856
|
+
*/
|
|
1857
|
+
function setUserInfo(userInfo, domain = getDomain()) {
|
|
1858
|
+
Cookies.set(Crypto.encrypt(USER_INFO), Crypto.encrypt(userInfo), { domain: domain, expires: 1 / 12 });
|
|
1859
|
+
Cookies.set(Crypto.encrypt(USER_INFO), Crypto.encrypt(userInfo), { expires: 1 / 12 });
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
/**
|
|
1863
|
+
* 获取用户信息
|
|
1864
|
+
* @returns {String} 用户信息
|
|
1865
|
+
*/
|
|
1866
|
+
function getUserInfo() {
|
|
1867
|
+
// 加密的用户信息
|
|
1868
|
+
let encryptUserInfo = Cookies.get(Crypto.encrypt(USER_INFO));
|
|
1869
|
+
if (encryptUserInfo) {
|
|
1870
|
+
return Crypto.decrypt(encryptUserInfo)
|
|
1871
|
+
} else {
|
|
1872
|
+
return ""
|
|
1873
|
+
}
|
|
1796
1874
|
}
|
|
1797
1875
|
|
|
1798
1876
|
var CCUser = /*#__PURE__*/Object.freeze({
|
|
@@ -1801,8 +1879,8 @@ var CCUser = /*#__PURE__*/Object.freeze({
|
|
|
1801
1879
|
getUserInfo: getUserInfo
|
|
1802
1880
|
});
|
|
1803
1881
|
|
|
1804
|
-
let CCDK = { CCApplication, CCAxios: CCHttp$1, CCUser, CCCrypto: Crypto, CCToken, CCConfig, CCLoad, CCLog, CCMenu, CCUtils, CCHttp, CCObject, CCPage, CCSentry, CCSide, CCBus, CCCall, CCCommon, CCMessage };
|
|
1805
|
-
Vue.prototype.$CCDK = CCDK;
|
|
1882
|
+
let CCDK = { CCApplication, CCAxios: CCHttp$1, CCUser, CCCrypto: Crypto, CCToken, CCConfig, CCLoad, CCLog, CCMenu, CCUtils, CCHttp, CCObject, CCPage, CCSentry, CCSide, CCBus, CCCall, CCCommon, CCMessage };
|
|
1883
|
+
Vue.prototype.$CCDK = CCDK;
|
|
1806
1884
|
window.$CCDK = CCDK;
|
|
1807
1885
|
|
|
1808
1886
|
export { CCDK as default };
|