cloudcc-ccdk 0.9.10 → 0.9.12

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