cloudcc-ccdk 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/lib/ccdk.js +293 -274
- package/lib/ccdk.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
#### 发布版本:0.2.0
|
|
2
|
+
#### 更新日期:2022/11/2
|
|
3
|
+
#### 更新内容:
|
|
4
|
+
* 修复
|
|
5
|
+
* 迭代
|
|
6
|
+
* 优化
|
|
7
|
+
* 调整ccdk名称顺序
|
|
8
|
+
|
|
9
|
+
#### 发布版本:0.1.9
|
|
10
|
+
#### 更新日期:2022/11/2
|
|
11
|
+
#### 更新内容:
|
|
12
|
+
* 修复
|
|
13
|
+
* 迭代
|
|
14
|
+
* 优化
|
|
15
|
+
* object使用local存储
|
|
16
|
+
|
|
17
|
+
#### 发布版本:0.1.8
|
|
18
|
+
#### 更新日期:2022/10/31
|
|
19
|
+
#### 更新内容:
|
|
20
|
+
* 修复
|
|
21
|
+
* 迭代
|
|
22
|
+
* 晚上ccobject
|
|
23
|
+
* 优化
|
|
24
|
+
|
|
1
25
|
#### 发布版本:0.1.7
|
|
2
26
|
#### 更新日期:2022/10/31
|
|
3
27
|
#### 更新内容:
|
package/lib/ccdk.js
CHANGED
|
@@ -1,9 +1,129 @@
|
|
|
1
|
-
import Cookies from 'js-cookie';
|
|
2
1
|
import CryptoJS from 'crypto-js/aes';
|
|
3
2
|
import UTF8 from 'crypto-js/enc-utf8';
|
|
4
3
|
import PAD from 'crypto-js/pad-pkcs7';
|
|
5
|
-
import { Message, MessageBox, Notification } from 'element-ui';
|
|
6
4
|
import axios from 'axios';
|
|
5
|
+
import { Message, MessageBox, Notification } from 'element-ui';
|
|
6
|
+
import Cookies from 'js-cookie';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 发布信息
|
|
10
|
+
* @param {string} event 事件名称
|
|
11
|
+
* @param {...any} args 参数列表
|
|
12
|
+
*/
|
|
13
|
+
function $emit(event, ...args) {
|
|
14
|
+
window.ccBus.$emit(event, ...args);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 订阅消息
|
|
18
|
+
* @param {string} event 事件名称
|
|
19
|
+
* @param {function} callback 回调方法
|
|
20
|
+
*/
|
|
21
|
+
function $on(event, callback) {
|
|
22
|
+
window.ccBus.$on(event, callback);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 取消订阅
|
|
26
|
+
* @param {string} event 事件名称
|
|
27
|
+
*/
|
|
28
|
+
function $off(event) {
|
|
29
|
+
window.ccBus.$off(event);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var CCBus = /*#__PURE__*/Object.freeze({
|
|
33
|
+
__proto__: null,
|
|
34
|
+
$emit: $emit,
|
|
35
|
+
$on: $on,
|
|
36
|
+
$off: $off
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// 电话对象
|
|
40
|
+
let ccCall = new Map();
|
|
41
|
+
// 电话服务商当前对象
|
|
42
|
+
let currentCall;
|
|
43
|
+
/**
|
|
44
|
+
* 初始化电话条
|
|
45
|
+
* @param {string} id 电话服务商唯一标识
|
|
46
|
+
* @param {object} callClient 电话对象
|
|
47
|
+
*/
|
|
48
|
+
function init(id, callClient) {
|
|
49
|
+
if (id && callClient) {
|
|
50
|
+
ccCall.set(id, callClient);
|
|
51
|
+
currentCall = callClient;
|
|
52
|
+
return currentCall
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 拨打电话
|
|
59
|
+
* @param {string} id 电话服务商唯一标识
|
|
60
|
+
* @param {object} options 配置信息
|
|
61
|
+
*/
|
|
62
|
+
function call(id, options) {
|
|
63
|
+
let call;
|
|
64
|
+
if (id) {
|
|
65
|
+
call = ccCall.get(id);
|
|
66
|
+
} else {
|
|
67
|
+
call = currentCall;
|
|
68
|
+
}
|
|
69
|
+
if (call) {
|
|
70
|
+
call.call(options);
|
|
71
|
+
}
|
|
72
|
+
return call
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 打开通话面板
|
|
76
|
+
* @param {string} id 电话服务商唯一标识
|
|
77
|
+
* @param {object} options 配置信息
|
|
78
|
+
*/
|
|
79
|
+
function openCallPanel(id, options) {
|
|
80
|
+
let call;
|
|
81
|
+
if (id) {
|
|
82
|
+
call = ccCall.get(id);
|
|
83
|
+
} else {
|
|
84
|
+
call = currentCall;
|
|
85
|
+
}
|
|
86
|
+
if (call) {
|
|
87
|
+
call.openCallPanel(options);
|
|
88
|
+
}
|
|
89
|
+
return call
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var CCCall = /*#__PURE__*/Object.freeze({
|
|
93
|
+
__proto__: null,
|
|
94
|
+
init: init,
|
|
95
|
+
call: call,
|
|
96
|
+
openCallPanel: openCallPanel
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 获取基础url
|
|
101
|
+
* @returns 基础地址
|
|
102
|
+
*/
|
|
103
|
+
function getBaseUrl() {
|
|
104
|
+
return window.gw.BASE_URL
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 获取网关对象
|
|
108
|
+
* @returns 网关对象
|
|
109
|
+
*/
|
|
110
|
+
function getGw() {
|
|
111
|
+
return window.gw;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 获取服务对象
|
|
115
|
+
* @returns 服务对象
|
|
116
|
+
*/
|
|
117
|
+
function getSvc() {
|
|
118
|
+
return window.Glod;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
var CCConfig = /*#__PURE__*/Object.freeze({
|
|
122
|
+
__proto__: null,
|
|
123
|
+
getBaseUrl: getBaseUrl,
|
|
124
|
+
getGw: getGw,
|
|
125
|
+
getSvc: getSvc
|
|
126
|
+
});
|
|
7
127
|
|
|
8
128
|
/**
|
|
9
129
|
* 加密
|
|
@@ -71,189 +191,9 @@ function decrypt(data, key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", iv = 1) {
|
|
|
71
191
|
}
|
|
72
192
|
|
|
73
193
|
var Crypto = /*#__PURE__*/Object.freeze({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 获得一级域名
|
|
81
|
-
* 比如:xx.com、xx.cn、xx.com.cn、xx.net.cn、xx.org.cn
|
|
82
|
-
*/
|
|
83
|
-
function getDomain() {
|
|
84
|
-
// 倒数第二位域名
|
|
85
|
-
let lastTow = document.domain.split('.').slice(-2, -1)[0];
|
|
86
|
-
// 如果倒数第二位是这些关键字,那么需要取倒数三位域名
|
|
87
|
-
if (lastTow == 'com' || lastTow == 'org' || lastTow == 'net') {
|
|
88
|
-
return "." + document.domain.split('.').slice(-3).join('.')
|
|
89
|
-
} else {
|
|
90
|
-
return "." + document.domain.split('.').slice(-2).join('.')
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
var CCUtils = /*#__PURE__*/Object.freeze({
|
|
95
|
-
__proto__: null,
|
|
96
|
-
getDomain: getDomain
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// cookie存储标识
|
|
100
|
-
const USER_INFO = "cc_user_info";
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* 存储用户信息
|
|
104
|
-
* @param {String} userInfo 用户信息
|
|
105
|
-
* @param {String} domain 域名
|
|
106
|
-
*/
|
|
107
|
-
function setUserInfo(userInfo, domain = getDomain()) {
|
|
108
|
-
Cookies.set(Crypto.encrypt(USER_INFO), Crypto.encrypt(userInfo), { domain: domain, expires: 1 / 12 });
|
|
109
|
-
Cookies.set(Crypto.encrypt(USER_INFO), Crypto.encrypt(userInfo), { expires: 1 / 12 });
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 获取用户信息
|
|
114
|
-
* @returns {String} 用户信息
|
|
115
|
-
*/
|
|
116
|
-
function getUserInfo() {
|
|
117
|
-
// 加密的用户信息
|
|
118
|
-
let encryptUserInfo = Cookies.get(Crypto.encrypt(USER_INFO));
|
|
119
|
-
if (encryptUserInfo) {
|
|
120
|
-
return Crypto.decrypt(encryptUserInfo)
|
|
121
|
-
} else {
|
|
122
|
-
return ""
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
var CCUser = /*#__PURE__*/Object.freeze({
|
|
127
|
-
__proto__: null,
|
|
128
|
-
setUserInfo: setUserInfo,
|
|
129
|
-
getUserInfo: getUserInfo
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// cookie存储标识
|
|
133
|
-
const TOKEN = "cc_token";
|
|
134
|
-
/**
|
|
135
|
-
* 获取URL中参数的数据
|
|
136
|
-
* @param {name} 参数名
|
|
137
|
-
*/
|
|
138
|
-
function getUrlQuery(name) {
|
|
139
|
-
var reg = new RegExp(name + "=([^&]*)(&|$)");
|
|
140
|
-
var r = window.location.href.match(reg);
|
|
141
|
-
let res = null;
|
|
142
|
-
if (r != null) res = r[1].trim();
|
|
143
|
-
return res;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* 获取token:优先级-url最高,cc_token-cookies第二,binding-cookies第三
|
|
147
|
-
* @param {String} urlName 获取token的url名称
|
|
148
|
-
* @returns
|
|
149
|
-
*/
|
|
150
|
-
function getToken(urlName = "binding") {
|
|
151
|
-
let token = getUrlQuery(urlName) || Cookies.get(Crypto.encrypt(TOKEN)) || Cookies.get(urlName);
|
|
152
|
-
// 如果存在token,那么存储到cookies中,刷新有效期
|
|
153
|
-
if (token) {
|
|
154
|
-
setToken(token);
|
|
155
|
-
}
|
|
156
|
-
return token
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* 存储token
|
|
160
|
-
* @param {String} token token
|
|
161
|
-
* @param {String} domain 域名
|
|
162
|
-
*/
|
|
163
|
-
function setToken(token, domain = getDomain()) {
|
|
164
|
-
Cookies.set(Crypto.encrypt(TOKEN), token, { domain: domain, expires: 1 / 12 });
|
|
165
|
-
Cookies.set(Crypto.encrypt(TOKEN), token, { expires: 1 / 12 });
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* 清除Token数据
|
|
170
|
-
* @param {String} domain 域名
|
|
171
|
-
*/
|
|
172
|
-
function clearToken(domain = getDomain()) {
|
|
173
|
-
Cookies.remove(Crypto.encrypt(TOKEN), { domain: domain });
|
|
174
|
-
Cookies.remove(Crypto.encrypt(TOKEN));
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
var CCToken = /*#__PURE__*/Object.freeze({
|
|
178
|
-
__proto__: null,
|
|
179
|
-
setToken: setToken,
|
|
180
|
-
getToken: getToken,
|
|
181
|
-
clearToken: clearToken
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* 获取基础url
|
|
186
|
-
* @returns 基础地址
|
|
187
|
-
*/
|
|
188
|
-
function getBaseUrl() {
|
|
189
|
-
return window.gw.BASE_URL
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* 获取网关对象
|
|
193
|
-
* @returns 网关对象
|
|
194
|
-
*/
|
|
195
|
-
function getGw() {
|
|
196
|
-
return window.gw;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* 获取服务对象
|
|
200
|
-
* @returns 服务对象
|
|
201
|
-
*/
|
|
202
|
-
function getSvc() {
|
|
203
|
-
return window.Glod;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
var CCConfig = /*#__PURE__*/Object.freeze({
|
|
207
|
-
__proto__: null,
|
|
208
|
-
getBaseUrl: getBaseUrl,
|
|
209
|
-
getGw: getGw,
|
|
210
|
-
getSvc: getSvc
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* 消息提示框
|
|
215
|
-
* @param {string} text 提示文字,支持vhtml渲染
|
|
216
|
-
* @param {string} type 消息类别
|
|
217
|
-
* @param {number} duration 持续时间
|
|
218
|
-
* @param {boolean} showClose 是否显示消息关闭按钮
|
|
219
|
-
* @param {boolean} center 文字是否剧中
|
|
220
|
-
*/
|
|
221
|
-
function showMessage(text, type = 'info', duration = 3000, showClose = false, center = false) {
|
|
222
|
-
Message({
|
|
223
|
-
message: text,
|
|
224
|
-
type,
|
|
225
|
-
duration,
|
|
226
|
-
showClose,
|
|
227
|
-
center
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* 提示确认框
|
|
232
|
-
* @param {string} text 提示信息
|
|
233
|
-
* @param {string} title 标题
|
|
234
|
-
* @param {object} options 配置信息
|
|
235
|
-
*/
|
|
236
|
-
function showConfirm(text, title, options = {}, confirm = () => { }, reject = () => { }) {
|
|
237
|
-
MessageBox.confirm(text, title, options).then(() => {
|
|
238
|
-
confirm();
|
|
239
|
-
}).catch(() => {
|
|
240
|
-
reject();
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* 提示消息框
|
|
246
|
-
* @param {object} options 配置信息
|
|
247
|
-
*/
|
|
248
|
-
function showNotification(options = {}) {
|
|
249
|
-
Notification(options);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
var CCMessage = /*#__PURE__*/Object.freeze({
|
|
253
|
-
__proto__: null,
|
|
254
|
-
showMessage: showMessage,
|
|
255
|
-
showConfirm: showConfirm,
|
|
256
|
-
showNotification: showNotification
|
|
194
|
+
__proto__: null,
|
|
195
|
+
encrypt: encrypt,
|
|
196
|
+
decrypt: decrypt
|
|
257
197
|
});
|
|
258
198
|
|
|
259
199
|
const service = axios.create({
|
|
@@ -329,27 +269,91 @@ function patch(url, data = {}) {
|
|
|
329
269
|
}
|
|
330
270
|
|
|
331
271
|
var CCHttp = /*#__PURE__*/Object.freeze({
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
272
|
+
__proto__: null,
|
|
273
|
+
get: get,
|
|
274
|
+
post: post,
|
|
275
|
+
put: put,
|
|
276
|
+
patch: patch,
|
|
277
|
+
postParams: postParams
|
|
338
278
|
});
|
|
339
279
|
|
|
280
|
+
/**
|
|
281
|
+
* 消息提示框
|
|
282
|
+
* @param {string} text 提示文字,支持vhtml渲染
|
|
283
|
+
* @param {string} type 消息类别
|
|
284
|
+
* @param {number} duration 持续时间
|
|
285
|
+
* @param {boolean} showClose 是否显示消息关闭按钮
|
|
286
|
+
* @param {boolean} center 文字是否剧中
|
|
287
|
+
*/
|
|
288
|
+
function showMessage(text, type = 'info', duration = 3000, showClose = false, center = false) {
|
|
289
|
+
Message({
|
|
290
|
+
message: text,
|
|
291
|
+
type,
|
|
292
|
+
duration,
|
|
293
|
+
showClose,
|
|
294
|
+
center
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* 提示确认框
|
|
299
|
+
* @param {string} text 提示信息
|
|
300
|
+
* @param {string} title 标题
|
|
301
|
+
* @param {object} options 配置信息
|
|
302
|
+
*/
|
|
303
|
+
function showConfirm(text, title, options = {}, confirm = () => { }, reject = () => { }) {
|
|
304
|
+
MessageBox.confirm(text, title, options).then(() => {
|
|
305
|
+
confirm();
|
|
306
|
+
}).catch(() => {
|
|
307
|
+
reject();
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* 提示消息框
|
|
313
|
+
* @param {object} options 配置信息
|
|
314
|
+
*/
|
|
315
|
+
function showNotification(options = {}) {
|
|
316
|
+
Notification(options);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
var CCMessage = /*#__PURE__*/Object.freeze({
|
|
320
|
+
__proto__: null,
|
|
321
|
+
showMessage: showMessage,
|
|
322
|
+
showConfirm: showConfirm,
|
|
323
|
+
showNotification: showNotification
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// 对象详情存储标识
|
|
340
327
|
const OBJECT_DETAIL = 'cc_object_detail';
|
|
328
|
+
// 对象存储标识
|
|
329
|
+
const OBJECT = 'cc_object';
|
|
330
|
+
|
|
341
331
|
/**
|
|
342
|
-
*
|
|
332
|
+
* 获得当前标准对象信息
|
|
343
333
|
*/
|
|
344
334
|
function getObject() {
|
|
335
|
+
let detail = localStorage.getItem(Crypto.encrypt(OBJECT));
|
|
336
|
+
if (detail) {
|
|
337
|
+
return JSON.parse(detail)
|
|
338
|
+
}
|
|
339
|
+
return ''
|
|
340
|
+
}
|
|
345
341
|
|
|
342
|
+
/**
|
|
343
|
+
* 设置当前标准对象信息
|
|
344
|
+
* @param {object} detail 对象数据
|
|
345
|
+
*/
|
|
346
|
+
function setObject(detail = '') {
|
|
347
|
+
if (detail) {
|
|
348
|
+
localStorage.setItem(Crypto.encrypt(OBJECT), JSON.stringify(detail));
|
|
349
|
+
}
|
|
346
350
|
}
|
|
347
351
|
|
|
348
352
|
/**
|
|
349
353
|
* 获得当前标准对象的详细信息
|
|
350
354
|
*/
|
|
351
355
|
function getObjectDetail() {
|
|
352
|
-
let detail =
|
|
356
|
+
let detail = localStorage.getItem(Crypto.encrypt(OBJECT_DETAIL));
|
|
353
357
|
if (detail) {
|
|
354
358
|
return JSON.parse(detail)
|
|
355
359
|
}
|
|
@@ -360,17 +364,18 @@ function getObjectDetail() {
|
|
|
360
364
|
* 设置当前标准对象的详细信息,默认两个小时有效期
|
|
361
365
|
* @param {object} detail 对象详细数据
|
|
362
366
|
*/
|
|
363
|
-
function setObjectDetail(detail = ''
|
|
367
|
+
function setObjectDetail(detail = '') {
|
|
364
368
|
if (detail) {
|
|
365
|
-
|
|
369
|
+
localStorage.setItem(Crypto.encrypt(OBJECT_DETAIL), JSON.stringify(detail));
|
|
366
370
|
}
|
|
367
371
|
}
|
|
368
372
|
|
|
369
373
|
var CCObject = /*#__PURE__*/Object.freeze({
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
+
__proto__: null,
|
|
375
|
+
getObject: getObject,
|
|
376
|
+
setObject: setObject,
|
|
377
|
+
getObjectDetail: getObjectDetail,
|
|
378
|
+
setObjectDetail: setObjectDetail
|
|
374
379
|
});
|
|
375
380
|
|
|
376
381
|
/**
|
|
@@ -427,104 +432,118 @@ function close() {
|
|
|
427
432
|
}
|
|
428
433
|
|
|
429
434
|
var CCPage = /*#__PURE__*/Object.freeze({
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
435
|
+
__proto__: null,
|
|
436
|
+
openListPage: openListPage,
|
|
437
|
+
openDetailPage: openDetailPage,
|
|
438
|
+
openCreatePage: openCreatePage,
|
|
439
|
+
openEditPage: openEditPage,
|
|
440
|
+
openCustomPage: openCustomPage,
|
|
441
|
+
close: close
|
|
437
442
|
});
|
|
438
443
|
|
|
439
444
|
/**
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
* @param {...any} args 参数列表
|
|
445
|
+
* 获得一级域名
|
|
446
|
+
* 比如:xx.com、xx.cn、xx.com.cn、xx.net.cn、xx.org.cn
|
|
443
447
|
*/
|
|
444
|
-
function
|
|
445
|
-
|
|
448
|
+
function getDomain() {
|
|
449
|
+
// 倒数第二位域名
|
|
450
|
+
let lastTow = document.domain.split('.').slice(-2, -1)[0];
|
|
451
|
+
// 如果倒数第二位是这些关键字,那么需要取倒数三位域名
|
|
452
|
+
if (lastTow == 'com' || lastTow == 'org' || lastTow == 'net') {
|
|
453
|
+
return "." + document.domain.split('.').slice(-3).join('.')
|
|
454
|
+
} else {
|
|
455
|
+
return "." + document.domain.split('.').slice(-2).join('.')
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
var CCUtils = /*#__PURE__*/Object.freeze({
|
|
460
|
+
__proto__: null,
|
|
461
|
+
getDomain: getDomain
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// cookie存储标识
|
|
465
|
+
const TOKEN = "cc_token";
|
|
466
|
+
/**
|
|
467
|
+
* 获取URL中参数的数据
|
|
468
|
+
* @param {name} 参数名
|
|
469
|
+
*/
|
|
470
|
+
function getUrlQuery(name) {
|
|
471
|
+
var reg = new RegExp(name + "=([^&]*)(&|$)");
|
|
472
|
+
var r = window.location.href.match(reg);
|
|
473
|
+
let res = null;
|
|
474
|
+
if (r != null) res = r[1].trim();
|
|
475
|
+
return res;
|
|
446
476
|
}
|
|
447
477
|
/**
|
|
448
|
-
*
|
|
449
|
-
* @param {
|
|
450
|
-
* @
|
|
478
|
+
* 获取token:优先级-url最高,cc_token-cookies第二,binding-cookies第三
|
|
479
|
+
* @param {String} urlName 获取token的url名称
|
|
480
|
+
* @returns
|
|
451
481
|
*/
|
|
452
|
-
function
|
|
453
|
-
|
|
482
|
+
function getToken(urlName = "binding") {
|
|
483
|
+
let token = getUrlQuery(urlName) || Cookies.get(Crypto.encrypt(TOKEN)) || Cookies.get(urlName);
|
|
484
|
+
// 如果存在token,那么存储到cookies中,刷新有效期
|
|
485
|
+
if (token) {
|
|
486
|
+
setToken(token);
|
|
487
|
+
}
|
|
488
|
+
return token
|
|
454
489
|
}
|
|
455
490
|
/**
|
|
456
|
-
*
|
|
457
|
-
* @param {
|
|
491
|
+
* 存储token
|
|
492
|
+
* @param {String} token token
|
|
493
|
+
* @param {String} domain 域名
|
|
458
494
|
*/
|
|
459
|
-
function
|
|
460
|
-
|
|
495
|
+
function setToken(token, domain = getDomain()) {
|
|
496
|
+
Cookies.set(Crypto.encrypt(TOKEN), token, { domain: domain, expires: 1 / 12 });
|
|
497
|
+
Cookies.set(Crypto.encrypt(TOKEN), token, { expires: 1 / 12 });
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* 清除Token数据
|
|
502
|
+
* @param {String} domain 域名
|
|
503
|
+
*/
|
|
504
|
+
function clearToken(domain = getDomain()) {
|
|
505
|
+
Cookies.remove(Crypto.encrypt(TOKEN), { domain: domain });
|
|
506
|
+
Cookies.remove(Crypto.encrypt(TOKEN));
|
|
461
507
|
}
|
|
462
508
|
|
|
463
|
-
var
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
509
|
+
var CCToken = /*#__PURE__*/Object.freeze({
|
|
510
|
+
__proto__: null,
|
|
511
|
+
setToken: setToken,
|
|
512
|
+
getToken: getToken,
|
|
513
|
+
clearToken: clearToken
|
|
468
514
|
});
|
|
469
515
|
|
|
470
|
-
//
|
|
471
|
-
|
|
472
|
-
// 电话服务商当前对象
|
|
473
|
-
let currentCall;
|
|
474
|
-
/**
|
|
475
|
-
* 初始化电话条
|
|
476
|
-
* @param {string} id 电话服务商唯一标识
|
|
477
|
-
* @param {object} callClient 电话对象
|
|
478
|
-
*/
|
|
479
|
-
function init(id, callClient) {
|
|
480
|
-
if (id && callClient) {
|
|
481
|
-
ccCall.set(id, callClient);
|
|
482
|
-
currentCall = callClient;
|
|
483
|
-
return currentCall
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
516
|
+
// cookie存储标识
|
|
517
|
+
const USER_INFO = "cc_user_info";
|
|
487
518
|
|
|
488
519
|
/**
|
|
489
|
-
*
|
|
490
|
-
* @param {
|
|
491
|
-
* @param {
|
|
520
|
+
* 存储用户信息
|
|
521
|
+
* @param {String} userInfo 用户信息
|
|
522
|
+
* @param {String} domain 域名
|
|
492
523
|
*/
|
|
493
|
-
function
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
call = ccCall.get(id);
|
|
497
|
-
} else {
|
|
498
|
-
call = currentCall;
|
|
499
|
-
}
|
|
500
|
-
if (call) {
|
|
501
|
-
call.call(options);
|
|
502
|
-
}
|
|
503
|
-
return call
|
|
524
|
+
function setUserInfo(userInfo, domain = getDomain()) {
|
|
525
|
+
Cookies.set(Crypto.encrypt(USER_INFO), Crypto.encrypt(userInfo), { domain: domain, expires: 1 / 12 });
|
|
526
|
+
Cookies.set(Crypto.encrypt(USER_INFO), Crypto.encrypt(userInfo), { expires: 1 / 12 });
|
|
504
527
|
}
|
|
528
|
+
|
|
505
529
|
/**
|
|
506
|
-
*
|
|
507
|
-
* @
|
|
508
|
-
* @param {object} options 配置信息
|
|
530
|
+
* 获取用户信息
|
|
531
|
+
* @returns {String} 用户信息
|
|
509
532
|
*/
|
|
510
|
-
function
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
533
|
+
function getUserInfo() {
|
|
534
|
+
// 加密的用户信息
|
|
535
|
+
let encryptUserInfo = Cookies.get(Crypto.encrypt(USER_INFO));
|
|
536
|
+
if (encryptUserInfo) {
|
|
537
|
+
return Crypto.decrypt(encryptUserInfo)
|
|
514
538
|
} else {
|
|
515
|
-
|
|
516
|
-
}
|
|
517
|
-
if (call) {
|
|
518
|
-
call.openCallPanel(options);
|
|
539
|
+
return ""
|
|
519
540
|
}
|
|
520
|
-
return call
|
|
521
541
|
}
|
|
522
542
|
|
|
523
|
-
var
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
openCallPanel: openCallPanel
|
|
543
|
+
var CCUser = /*#__PURE__*/Object.freeze({
|
|
544
|
+
__proto__: null,
|
|
545
|
+
setUserInfo: setUserInfo,
|
|
546
|
+
getUserInfo: getUserInfo
|
|
528
547
|
});
|
|
529
548
|
|
|
530
|
-
export { CCBus, CCCall,
|
|
549
|
+
export { CCBus, CCCall, CCConfig, Crypto as CCCrypto, CCHttp, CCMessage, CCObject, CCPage, CCToken, CCUser, CCUtils };
|
package/lib/ccdk.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CryptoJS from"crypto-js/aes";import UTF8 from"crypto-js/enc-utf8";import PAD from"crypto-js/pad-pkcs7";import axios from"axios";import{Message,MessageBox,Notification}from"element-ui";import Cookies from"js-cookie";function $emit(event,...args){window.ccBus.$emit(event,...args)}function $on(event,callback){window.ccBus.$on(event,callback)}function $off(event){window.ccBus.$off(event)}var CCBus=Object.freeze({__proto__:null,$emit:$emit,$on:$on,$off:$off});let ccCall=new Map;let currentCall;function init(id,callClient){if(id&&callClient){ccCall.set(id,callClient);currentCall=callClient;return currentCall}}function call(id,options){let call;if(id){call=ccCall.get(id)}else{call=currentCall}if(call){call.call(options)}return call}function openCallPanel(id,options){let call;if(id){call=ccCall.get(id)}else{call=currentCall}if(call){call.openCallPanel(options)}return call}var CCCall=Object.freeze({__proto__:null,init:init,call:call,openCallPanel:openCallPanel});function getBaseUrl(){return window.gw.BASE_URL}function getGw(){return window.gw}function getSvc(){return window.Glod}var CCConfig=Object.freeze({__proto__:null,getBaseUrl:getBaseUrl,getGw:getGw,getSvc:getSvc});function getAesString(data,key,iv){key=UTF8.parse(key);iv=UTF8.parse(iv);let encrypted=CryptoJS.encrypt(data,key,{iv:iv,padding:PAD});return encrypted.toString()}function getDAesString(encrypted,key,iv){key=UTF8.parse(key);iv=UTF8.parse(iv);let decrypted=CryptoJS.decrypt(encrypted,key,{iv:iv,padding:PAD});return decrypted.toString(UTF8)}function encrypt(data,key="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",iv=1){data=JSON.stringify(data);var encrypted=getAesString(data,key,iv);return encrypted}function decrypt(data,key="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",iv=1){try{var decryptedStr=getDAesString(data,key,iv);if(!decryptedStr)return null;return JSON.parse(decryptedStr)}catch(error){console.trace("解密密码错误",error);return null}}var Crypto=Object.freeze({__proto__:null,encrypt:encrypt,decrypt:decrypt});const service=axios.create({timeout:6e4,headers:{"Content-Type":"application/json; charset=utf-8"}});service.interceptors.request.use(config=>{config.headers["accessToken"]=$CCDK.CCToken.getToken();return config},error=>{Promise.reject(error)});service.interceptors.response.use(response=>{const code=response.data.code||200;if(code!==200){return Promise.reject(null==response.data.msg?"未知异常":response.data.msg)}else{return response.data}},error=>{return Promise.reject(error)});function get(url,data={},responseType=""){return service({url:url,method:"get",params:data,responseType:responseType})}function post(url,data={},responseType=""){return service({url:url,method:"post",data:data,responseType:responseType})}function put(url,data={}){return service({url:url,method:"put",data:data})}function postParams(url,data={}){return service({url:url,method:"post",params:data})}function patch(url,data={}){return service({url:url,method:"patch",data:data})}var CCHttp=Object.freeze({__proto__:null,get:get,post:post,put:put,patch:patch,postParams:postParams});function showMessage(text,type="info",duration=3e3,showClose=false,center=false){Message({message:text,type:type,duration:duration,showClose:showClose,center:center})}function showConfirm(text,title,options={},confirm=()=>{},reject=()=>{}){MessageBox.confirm(text,title,options).then(()=>{confirm()}).catch(()=>{reject()})}function showNotification(options={}){Notification(options)}var CCMessage=Object.freeze({__proto__:null,showMessage:showMessage,showConfirm:showConfirm,showNotification:showNotification});const OBJECT_DETAIL="cc_object_detail";const OBJECT="cc_object";function getObject(){let detail=localStorage.getItem(Crypto.encrypt(OBJECT));if(detail){return JSON.parse(detail)}return""}function setObject(detail=""){if(detail){localStorage.setItem(Crypto.encrypt(OBJECT),JSON.stringify(detail))}}function getObjectDetail(){let detail=localStorage.getItem(Crypto.encrypt(OBJECT_DETAIL));if(detail){return JSON.parse(detail)}return""}function setObjectDetail(detail=""){if(detail){localStorage.setItem(Crypto.encrypt(OBJECT_DETAIL),JSON.stringify(detail))}}var CCObject=Object.freeze({__proto__:null,getObject:getObject,setObject:setObject,getObjectDetail:getObjectDetail,setObjectDetail:setObjectDetail});function openListPage(objectType,options={}){$CCDK.CCBus.$emit("openListPage",objectType,id,options)}function openDetailPage(objectType,id,options={}){$CCDK.CCBus.$emit("openCreatePage",objectType,id,options)}function openCreatePage(objectType,options={}){$CCDK.CCBus.$emit("openCreatePage",objectType,options)}function openEditPage(objectType,id,options={}){$CCDK.CCBus.$emit("openEditPage",objectType,id,options)}function openCustomPage(pageId,options={}){$CCDK.CCBus.$emit("openCustomPage",pageId,options)}function close(){}var CCPage=Object.freeze({__proto__:null,openListPage:openListPage,openDetailPage:openDetailPage,openCreatePage:openCreatePage,openEditPage:openEditPage,openCustomPage:openCustomPage,close:close});function getDomain(){let lastTow=document.domain.split(".").slice(-2,-1)[0];if(lastTow=="com"||lastTow=="org"||lastTow=="net"){return"."+document.domain.split(".").slice(-3).join(".")}else{return"."+document.domain.split(".").slice(-2).join(".")}}var CCUtils=Object.freeze({__proto__:null,getDomain:getDomain});const TOKEN="cc_token";function getUrlQuery(name){var reg=new RegExp(name+"=([^&]*)(&|$)");var r=window.location.href.match(reg);let res=null;if(r!=null)res=r[1].trim();return res}function getToken(urlName="binding"){let token=getUrlQuery(urlName)||Cookies.get(Crypto.encrypt(TOKEN))||Cookies.get(urlName);if(token){setToken(token)}return token}function setToken(token,domain=getDomain()){Cookies.set(Crypto.encrypt(TOKEN),token,{domain:domain,expires:1/12});Cookies.set(Crypto.encrypt(TOKEN),token,{expires:1/12})}function clearToken(domain=getDomain()){Cookies.remove(Crypto.encrypt(TOKEN),{domain:domain});Cookies.remove(Crypto.encrypt(TOKEN))}var CCToken=Object.freeze({__proto__:null,setToken:setToken,getToken:getToken,clearToken:clearToken});const USER_INFO="cc_user_info";function setUserInfo(userInfo,domain=getDomain()){Cookies.set(Crypto.encrypt(USER_INFO),Crypto.encrypt(userInfo),{domain:domain,expires:1/12});Cookies.set(Crypto.encrypt(USER_INFO),Crypto.encrypt(userInfo),{expires:1/12})}function getUserInfo(){let encryptUserInfo=Cookies.get(Crypto.encrypt(USER_INFO));if(encryptUserInfo){return Crypto.decrypt(encryptUserInfo)}else{return""}}var CCUser=Object.freeze({__proto__:null,setUserInfo:setUserInfo,getUserInfo:getUserInfo});export{CCBus,CCCall,CCConfig,Crypto as CCCrypto,CCHttp,CCMessage,CCObject,CCPage,CCToken,CCUser,CCUtils};
|