cnhis-design-vue 2.1.22 → 2.1.23
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/CHANGELOG.md +2280 -2270
- package/es/affix/index.js +8 -8
- package/es/age/index.js +10 -10
- package/es/alert/index.js +8 -8
- package/es/anchor/index.js +8 -8
- package/es/auto-complete/index.js +8 -8
- package/es/avatar/index.js +8 -8
- package/es/back-top/index.js +8 -8
- package/es/badge/index.js +8 -8
- package/es/base/index.js +8 -8
- package/es/big-table/index.js +164 -164
- package/es/breadcrumb/index.js +8 -8
- package/es/button/index.js +31 -31
- package/es/calendar/index.js +8 -8
- package/es/captcha/index.js +3 -3
- package/es/card/index.js +8 -8
- package/es/carousel/index.js +8 -8
- package/es/cascader/index.js +8 -8
- package/es/checkbox/index.js +9 -9
- package/es/col/index.js +8 -8
- package/es/collapse/index.js +8 -8
- package/es/color-picker/index.js +1 -1
- package/es/comment/index.js +8 -8
- package/es/config-provider/index.js +8 -8
- package/es/date-picker/index.js +8 -8
- package/es/descriptions/index.js +8 -8
- package/es/divider/index.js +8 -8
- package/es/drag-layout/index.js +3 -3
- package/es/drawer/index.js +8 -8
- package/es/dropdown/index.js +8 -8
- package/es/editor/index.js +1 -1
- package/es/empty/index.js +8 -8
- package/es/fabric-chart/index.js +39 -39
- package/es/form/index.js +8 -8
- package/es/form-model/index.js +8 -8
- package/es/form-table/index.js +62 -62
- package/es/index/index.js +708 -685
- package/es/index/style.css +1 -1
- package/es/input/index.js +9 -9
- package/es/input-number/index.js +8 -8
- package/es/layout/index.js +8 -8
- package/es/list/index.js +8 -8
- package/es/locale-provider/index.js +8 -8
- package/es/map/index.js +9 -9
- package/es/mentions/index.js +8 -8
- package/es/menu/index.js +8 -8
- package/es/message/index.js +8 -8
- package/es/multi-chat/index.js +92 -92
- package/es/multi-chat-client/index.js +86 -86
- package/es/multi-chat-history/index.js +4 -4
- package/es/multi-chat-record/index.js +14 -14
- package/es/multi-chat-setting/index.js +27 -27
- package/es/multi-chat-sip/index.js +1 -1
- package/es/notification/index.js +8 -8
- package/es/page-header/index.js +8 -8
- package/es/pagination/index.js +8 -8
- package/es/popconfirm/index.js +8 -8
- package/es/popover/index.js +8 -8
- package/es/progress/index.js +8 -8
- package/es/radio/index.js +9 -9
- package/es/rate/index.js +8 -8
- package/es/result/index.js +8 -8
- package/es/row/index.js +8 -8
- package/es/scale-view/index.js +33 -33
- package/es/select/index.js +11 -11
- package/es/select-label/index.js +11 -11
- package/es/select-person/index.js +81 -58
- package/es/select-person/style.css +1 -1
- package/es/skeleton/index.js +8 -8
- package/es/slider/index.js +8 -8
- package/es/space/index.js +8 -8
- package/es/spin/index.js +8 -8
- package/es/statistic/index.js +8 -8
- package/es/steps/index.js +8 -8
- package/es/switch/index.js +8 -8
- package/es/table-filter/index.js +142 -142
- package/es/tabs/index.js +8 -8
- package/es/tag/index.js +9 -9
- package/es/time-picker/index.js +8 -8
- package/es/timeline/index.js +8 -8
- package/es/tooltip/index.js +8 -8
- package/es/transfer/index.js +8 -8
- package/es/tree/index.js +8 -8
- package/es/tree-select/index.js +8 -8
- package/es/upload/index.js +8 -8
- package/es/verification-code/index.js +2 -2
- package/lib/cui.common.js +659 -636
- package/lib/cui.umd.js +659 -636
- package/lib/cui.umd.min.js +13 -13
- package/package.json +107 -107
- package/packages/big-table/src/BigTable.vue +3044 -3044
- package/packages/big-table/src/assets/style/table-base.less +370 -370
- package/packages/big-table/src/components/AutoLayoutButton.vue +270 -270
- package/packages/big-table/src/utils/batchEditing.js +610 -610
- package/packages/big-table/src/utils/bigTableProps.js +95 -95
- package/packages/button/src/ButtonPrint/components/IdentityVerification.vue +181 -181
- package/packages/button/src/ButtonPrint/index.vue +728 -728
- package/packages/fabric-chart/src/components/TimeScaleValue.vue +113 -113
- package/packages/fabric-chart/src/const/defaultVaule.js +59 -59
- package/packages/fabric-chart/src/fabric-chart/FabricPolylines.vue +1066 -1066
- package/packages/fabric-chart/src/fabric-chart/FabricScaleValue.vue +135 -135
- package/packages/fabric-chart/src/fabric-chart/FabricTextGroup.vue +558 -558
- package/packages/fabric-chart/src/fabric-chart2/FabricTop.vue +172 -172
- package/packages/multi-chat/chat/chatFooter.vue +1594 -1594
- package/packages/multi-chat/chat/chatMain.vue +1466 -1466
- package/packages/multi-chat/chat/quickReply.vue +439 -439
- package/packages/multi-chat/chat/scrollList.vue +1232 -1232
- package/packages/multi-chat/setting/baseInfo/index.vue +1316 -1316
- package/packages/multi-chat/store/actions.js +448 -448
- package/packages/multi-chat/store/state.js +112 -112
- package/packages/scale-view/formitem/r-choice.vue +714 -714
- package/packages/scale-view/scaleView.vue +2010 -2010
- package/packages/select-person/select-person.vue +1680 -1658
- package/packages/table-filter/src/base-search-com/BaseSearch.vue +2462 -2462
- package/packages/table-filter/src/components/c-tree-select/tree-select.vue +336 -336
- package/packages/table-filter/src/components/multi-select/multi-select.vue +219 -219
- package/packages/table-filter/src/components/out-quick-search/out-quick-search.vue +340 -340
- package/packages/table-filter/src/components/search-condition/SearchCondition.vue +1825 -1825
- package/packages/table-filter/src/const/dataOptions.js +43 -43
- package/packages/table-filter/src/mixins/mixins.js +695 -695
- package/packages/table-filter/src/quick-search/QuickSearch.vue +2109 -2109
- package/src/directive/preventReClick.js +12 -12
|
@@ -1,448 +1,448 @@
|
|
|
1
|
-
import fetch, { qs } from '@/utils/chatFetch';
|
|
2
|
-
import Vue from 'vue';
|
|
3
|
-
import vexutils from '@/utils/vexutils';
|
|
4
|
-
import { fmtRobotMessage } from '../utils';
|
|
5
|
-
import UniRTCObject from "@/utils/UniRTCv2";
|
|
6
|
-
|
|
7
|
-
const deepClone = source => {
|
|
8
|
-
let target;
|
|
9
|
-
if (typeof source === "object" && source) {
|
|
10
|
-
target = Array.isArray(source) ? [] : {};
|
|
11
|
-
for (let key in source) {
|
|
12
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
13
|
-
// if (source.hasOwnProperty(key)) {
|
|
14
|
-
if (typeof source[key] !== "object") {
|
|
15
|
-
target[key] = source[key];
|
|
16
|
-
} else {
|
|
17
|
-
target[key] = deepClone(source[key]);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
} else {
|
|
22
|
-
target = source;
|
|
23
|
-
}
|
|
24
|
-
return target;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export default {
|
|
28
|
-
/* 更新聊天记录 */
|
|
29
|
-
setMsgList({ commit, state, getters }, option) {
|
|
30
|
-
let { sessionId, historySessionId, msgList, sessionHistoryList, serviceId, isServer, assemblyId } = state;
|
|
31
|
-
let id = msgList[0] && msgList[0].id;
|
|
32
|
-
if (msgList.length === 0 && sessionHistoryList.length > 0) {
|
|
33
|
-
id = sessionHistoryList.find(item => item.fromId === serviceId)?.lastContentId;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let orgId;
|
|
37
|
-
let userId;
|
|
38
|
-
let userType;
|
|
39
|
-
if (!isServer) {
|
|
40
|
-
orgId = getters.accessParams.orgId || getters.queryParams.orgId;
|
|
41
|
-
userId = getters.accessParams.userId || getters.chatUserId || getters.queryParams.userId;
|
|
42
|
-
userType = getters.accessParams.userType || getters.queryParams.userType;
|
|
43
|
-
} else {
|
|
44
|
-
orgId = state.userInfo?.sysParams?.orgId;
|
|
45
|
-
userId = state.userInfo?.sysParams?.userId;
|
|
46
|
-
}
|
|
47
|
-
let params = {
|
|
48
|
-
sessionId: sessionId || historySessionId,
|
|
49
|
-
id,
|
|
50
|
-
assemblyId,
|
|
51
|
-
orgId,
|
|
52
|
-
userId,
|
|
53
|
-
userType,
|
|
54
|
-
relateId: getters.accessParams.relateId
|
|
55
|
-
};
|
|
56
|
-
if (!isServer) {
|
|
57
|
-
params.source = 1;
|
|
58
|
-
params.serviceId = getters.queryParams.serviceId;
|
|
59
|
-
}
|
|
60
|
-
return fetch
|
|
61
|
-
.get(`/chat/${isServer ? 'service' : 'access'}/getHistoryRecord`, {
|
|
62
|
-
params
|
|
63
|
-
})
|
|
64
|
-
.then(({ data }) => {
|
|
65
|
-
if (data.result === 'SUCCESS') {
|
|
66
|
-
if (id && data.list.length === 0) {
|
|
67
|
-
return '没有更多消息了';
|
|
68
|
-
}
|
|
69
|
-
const validate = option?.validate;
|
|
70
|
-
if (validate && !validate(data)) return;
|
|
71
|
-
if (id) {
|
|
72
|
-
commit('setMsgList', [...data.list, ...msgList]);
|
|
73
|
-
commit('appendList', data.list);
|
|
74
|
-
// commit("setScrollTo", "current");
|
|
75
|
-
} else {
|
|
76
|
-
commit('setMsgList', data.list);
|
|
77
|
-
commit('appendList', data.list);
|
|
78
|
-
// commit("setScrollTo", "bottom");
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
},
|
|
83
|
-
/* 发送消息 */
|
|
84
|
-
sendMessage({ commit, state, getters }, body) {
|
|
85
|
-
let { assemblyId, sessionId, serviceId, queueId, isServer, clientId } = state;
|
|
86
|
-
let orgId;
|
|
87
|
-
let userId;
|
|
88
|
-
let userType;
|
|
89
|
-
if (!isServer) {
|
|
90
|
-
orgId = getters.accessParams.orgId || getters.queryParams.orgId;
|
|
91
|
-
userId = getters.accessParams.userId || getters.chatUserId || getters.queryParams.userId;
|
|
92
|
-
userType = getters.accessParams.userType || getters.queryParams.userType;
|
|
93
|
-
} else {
|
|
94
|
-
orgId = state.userInfo?.sysParams?.orgId;
|
|
95
|
-
userId = state.userInfo?.sysParams?.userId;
|
|
96
|
-
}
|
|
97
|
-
let fromName = state.userInfo?.sysParams?.userName;
|
|
98
|
-
let portrait = state.userInfo?.userInfoMap?.headUrl;
|
|
99
|
-
let failItem = body.failItem;
|
|
100
|
-
delete body.failItem;
|
|
101
|
-
let message;
|
|
102
|
-
if (!failItem) {
|
|
103
|
-
message = {
|
|
104
|
-
content: body,
|
|
105
|
-
fromId: isServer ? serviceId : clientId,
|
|
106
|
-
fromName,
|
|
107
|
-
sessionId,
|
|
108
|
-
id: '',
|
|
109
|
-
createdTime: new Date().getTime(),
|
|
110
|
-
sending: true,
|
|
111
|
-
fail: false,
|
|
112
|
-
portrait
|
|
113
|
-
};
|
|
114
|
-
commit('setIsAppendMsg', true);
|
|
115
|
-
commit('setMessage', message);
|
|
116
|
-
commit('appendList', [message]);
|
|
117
|
-
} else {
|
|
118
|
-
body = failItem.content;
|
|
119
|
-
message = failItem;
|
|
120
|
-
}
|
|
121
|
-
let params = {
|
|
122
|
-
assemblyId,
|
|
123
|
-
sessionId,
|
|
124
|
-
queueId,
|
|
125
|
-
orgId,
|
|
126
|
-
userId,
|
|
127
|
-
userType,
|
|
128
|
-
relateId: getters.accessParams.relateId,
|
|
129
|
-
body: JSON.stringify(body),
|
|
130
|
-
source: isServer ? 2 : 1
|
|
131
|
-
};
|
|
132
|
-
return fetch
|
|
133
|
-
.post(`/chat/${isServer ? 'service' : 'access'}/sendMessage`, qs.stringify(params))
|
|
134
|
-
.then(({ data }) => {
|
|
135
|
-
if (data.result === 'SUCCESS') {
|
|
136
|
-
const map = data.map || {};
|
|
137
|
-
const id = map.messageId;
|
|
138
|
-
const status = message.readStatus || state.msgRecordCache[id] || map.readStatus;
|
|
139
|
-
Vue.prototype.$set(message, 'id', id);
|
|
140
|
-
Vue.prototype.$set(message, 'fail', false);
|
|
141
|
-
Vue.prototype.$set(message, 'readStatus', status);
|
|
142
|
-
// commit("setIsAppendMsg", true);
|
|
143
|
-
// commit("setMessage", {
|
|
144
|
-
// content: body,
|
|
145
|
-
// fromId: isServer ? serviceId : clientId,
|
|
146
|
-
// fromName,
|
|
147
|
-
// sessionId,
|
|
148
|
-
// id: data.map?.messageId,
|
|
149
|
-
// createdTime: new Date().getTime()
|
|
150
|
-
// });
|
|
151
|
-
// 客服自己发送的消息也在会话列表实时更新
|
|
152
|
-
commit('setIsScrollListChange', true);
|
|
153
|
-
commit('setListChangeItem', {
|
|
154
|
-
opt: 1,
|
|
155
|
-
from: clientId,
|
|
156
|
-
msgCount: 0,
|
|
157
|
-
lastContent: body,
|
|
158
|
-
sessionId,
|
|
159
|
-
sendTime: new Date().getTime()
|
|
160
|
-
});
|
|
161
|
-
// 图片加载特殊处理
|
|
162
|
-
// setTimeout(() => {
|
|
163
|
-
// commit("setScrollTo", "bottom");
|
|
164
|
-
// }, 1000);
|
|
165
|
-
} else {
|
|
166
|
-
Vue.prototype.$set(message, 'fail', true);
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
.catch(() => {
|
|
170
|
-
Vue.prototype.$set(message, 'fail', true);
|
|
171
|
-
})
|
|
172
|
-
.finally(() => {
|
|
173
|
-
Vue.prototype.$set(message, 'sending', false);
|
|
174
|
-
});
|
|
175
|
-
},
|
|
176
|
-
sendRobotMessage({ commit, state, getters, dispatch }, body) {
|
|
177
|
-
let message = body; // 消息内容
|
|
178
|
-
let postParams = null; // 请求附带的额外参数
|
|
179
|
-
// 判断 body 类型 可传递多参数
|
|
180
|
-
if (Object.prototype.toString.call(message) === '[object Object]') {
|
|
181
|
-
message = body.message || '';
|
|
182
|
-
postParams = body.postParams || postParams;
|
|
183
|
-
}
|
|
184
|
-
let { robotId, questionId, dictionaryKey, intentionId, orgId, dictionaryValue, isQuickReply, queryParams } = state;
|
|
185
|
-
let userType = getters.accessParams.userType || getters.queryParams.userType;
|
|
186
|
-
let userId = getters.chatUserId;
|
|
187
|
-
let params = {
|
|
188
|
-
robotId,
|
|
189
|
-
userType,
|
|
190
|
-
userId,
|
|
191
|
-
orgId
|
|
192
|
-
};
|
|
193
|
-
if (isQuickReply) {
|
|
194
|
-
params.dictionaryValue = dictionaryValue;
|
|
195
|
-
}
|
|
196
|
-
if (message) {
|
|
197
|
-
params.message = message;
|
|
198
|
-
}
|
|
199
|
-
if (intentionId) {
|
|
200
|
-
params.intentionId = intentionId;
|
|
201
|
-
}
|
|
202
|
-
if (dictionaryKey) {
|
|
203
|
-
params.dictionaryKey = dictionaryKey;
|
|
204
|
-
}
|
|
205
|
-
if (questionId) {
|
|
206
|
-
params.questionId = questionId;
|
|
207
|
-
}
|
|
208
|
-
if (queryParams.relateId) {
|
|
209
|
-
params.relateId = queryParams.relateId;
|
|
210
|
-
}
|
|
211
|
-
postParams && Object.assign(params, postParams);
|
|
212
|
-
message && commit('setIsAppendMsg', true);
|
|
213
|
-
if (message) {
|
|
214
|
-
commit('setMessage', {
|
|
215
|
-
content: {
|
|
216
|
-
content: message,
|
|
217
|
-
type: 0
|
|
218
|
-
},
|
|
219
|
-
fromId: '',
|
|
220
|
-
mode: 'robot',
|
|
221
|
-
sendTime: new Date().getTime()
|
|
222
|
-
});
|
|
223
|
-
commit('setScrollTo', 'bottom');
|
|
224
|
-
}
|
|
225
|
-
return fetch.post('/robot/access/sendMessage', qs.stringify(params)).then(({ data }) => {
|
|
226
|
-
if (data.result === 'SUCCESS') {
|
|
227
|
-
commit('setIsQuickReply', false);
|
|
228
|
-
let { map = null } = data;
|
|
229
|
-
setTimeout(() => {
|
|
230
|
-
dispatch('robotSendMessage', map);
|
|
231
|
-
}, 50);
|
|
232
|
-
commit('setQuestionId', '');
|
|
233
|
-
commit('setDictionaryKey', '');
|
|
234
|
-
commit('setDictionaryValue', '');
|
|
235
|
-
commit('setIntentionId', '');
|
|
236
|
-
// 图片加载特殊处理
|
|
237
|
-
setTimeout(() => {
|
|
238
|
-
commit('setScrollTo', 'bottom');
|
|
239
|
-
}, 1000);
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
},
|
|
243
|
-
robotSendMessage({ commit }, map) {
|
|
244
|
-
if (!map) return;
|
|
245
|
-
if (map.body) {
|
|
246
|
-
let dictionaryValues = map.dictionaryValues || [];
|
|
247
|
-
if (vexutils.isJSON(dictionaryValues)) {
|
|
248
|
-
dictionaryValues = JSON.parse(dictionaryValues);
|
|
249
|
-
}
|
|
250
|
-
let body = map.body;
|
|
251
|
-
let result = Array.isArray(body) ? body : [{ content: body }];
|
|
252
|
-
if (map.actionFlag) {
|
|
253
|
-
// 判断是否触发动作
|
|
254
|
-
const last = result.pop(); // 接口返回的最后一个消息是动作消息(不用上屏,拿出单独执行)
|
|
255
|
-
const url = last?.content?.content || '';
|
|
256
|
-
url && window.open(url);
|
|
257
|
-
}
|
|
258
|
-
if (result.length > 0) {
|
|
259
|
-
result = body.map(item => {
|
|
260
|
-
return Object.assign(fmtRobotMessage(item), {
|
|
261
|
-
fromId: 'SYSTEM',
|
|
262
|
-
mode: 'robot',
|
|
263
|
-
sendTime: new Date().getTime()
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
if (Object.prototype.hasOwnProperty.call(map, 'autoAccess') && map.chatFlag) {
|
|
267
|
-
result[result.length - 1].autoAccess = map.autoAccess + '';
|
|
268
|
-
}
|
|
269
|
-
commit('setIsAppendMsg', true);
|
|
270
|
-
commit('setMessage', result);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (map.chatFlag && map.autoAccess) {
|
|
274
|
-
commit('setChatFlag', true);
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
/**
|
|
278
|
-
* 聊天计时
|
|
279
|
-
* @param {*} param0
|
|
280
|
-
* @param {undefined| string |number | object} data 接收 countdown 或者 {countdown, countdownDesc}
|
|
281
|
-
* @returns
|
|
282
|
-
*/
|
|
283
|
-
setChatTimer({ commit, state }, data) {
|
|
284
|
-
const isObject = vexutils.isObject(data);
|
|
285
|
-
const count = isObject ? data.countdown : data;
|
|
286
|
-
let { sessionTimer, assemblySetting } = state;
|
|
287
|
-
let showMode = assemblySetting?.timingSetting?.showMode;
|
|
288
|
-
clearInterval(sessionTimer);
|
|
289
|
-
commit('setSessionTimer', null);
|
|
290
|
-
commit('setSessionTime', count);
|
|
291
|
-
if (count === undefined) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
const isASC = showMode === 'ASC';
|
|
295
|
-
const countdownDesc = (isObject && Number(data.countdownDesc)) || 0;
|
|
296
|
-
commit('setSessionTotalTime', isObject && showMode ? count + countdownDesc : 0); // 正序时记录总时长
|
|
297
|
-
sessionTimer = setInterval(() => {
|
|
298
|
-
commit('setSessionTime', isASC ? ++state.sessionTime : (!state.sessionTime ? 0 : --state.sessionTime));
|
|
299
|
-
}, 1000);
|
|
300
|
-
commit('setSessionTimer', sessionTimer);
|
|
301
|
-
},
|
|
302
|
-
/* 机器人模式下发送文字 */
|
|
303
|
-
handleBotChat({ dispatch, commit, state }, message) {
|
|
304
|
-
commit('setIsAppendMsg', true);
|
|
305
|
-
commit('setMessage', {
|
|
306
|
-
content: {
|
|
307
|
-
content: `<div>${message}</div>`,
|
|
308
|
-
type: 0
|
|
309
|
-
},
|
|
310
|
-
fromId: '',
|
|
311
|
-
mode: 'bot'
|
|
312
|
-
});
|
|
313
|
-
commit('setScrollTo', 'bottom');
|
|
314
|
-
return fetch
|
|
315
|
-
.post(
|
|
316
|
-
'/chat/access/sendBotMessage',
|
|
317
|
-
qs.stringify({
|
|
318
|
-
sessionId: state.botSessionId,
|
|
319
|
-
body: message.replace(/<[^>]+>/g, '')
|
|
320
|
-
})
|
|
321
|
-
)
|
|
322
|
-
.then(({ data }) => {
|
|
323
|
-
if (data.result === 'SUCCESS') {
|
|
324
|
-
return dispatch('handleBotResult', data.map);
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
},
|
|
328
|
-
/* 机器人返回的结果 */
|
|
329
|
-
handleBotResult({ commit }, data) {
|
|
330
|
-
let { chatType, resultType, groupList, username, queueId, assembly } = data;
|
|
331
|
-
let content;
|
|
332
|
-
let type = 0;
|
|
333
|
-
if (chatType === 'message') {
|
|
334
|
-
if (['0', '1', '2', '3', '4', '5'].includes(resultType)) {
|
|
335
|
-
content = `<div>${groupList[0].Content}</div>`;
|
|
336
|
-
} else {
|
|
337
|
-
content = groupList.map(item => item.Content);
|
|
338
|
-
type = 6;
|
|
339
|
-
}
|
|
340
|
-
commit('setIsAppendMsg', true);
|
|
341
|
-
commit('setMessage', {
|
|
342
|
-
content: {
|
|
343
|
-
content,
|
|
344
|
-
type
|
|
345
|
-
},
|
|
346
|
-
fromId: 'bot',
|
|
347
|
-
mode: 'bot'
|
|
348
|
-
});
|
|
349
|
-
commit('setScrollTo', 'bottom');
|
|
350
|
-
return false;
|
|
351
|
-
} else {
|
|
352
|
-
commit('setClientId', username);
|
|
353
|
-
commit('setChatType', chatType);
|
|
354
|
-
commit('setAssemblySetting', assembly.settingObj);
|
|
355
|
-
commit('setQueueId', queueId);
|
|
356
|
-
commit('setBotSessionId', '');
|
|
357
|
-
return true;
|
|
358
|
-
}
|
|
359
|
-
},
|
|
360
|
-
getVideoHistoryList({ commit, state }) {
|
|
361
|
-
let params = {
|
|
362
|
-
assemblyId: state.assemblyId
|
|
363
|
-
};
|
|
364
|
-
return fetch
|
|
365
|
-
.get('/chat/service/getVideoHistoryList', {
|
|
366
|
-
params
|
|
367
|
-
})
|
|
368
|
-
.then(({ data }) => {
|
|
369
|
-
if (data.result === 'SUCCESS') {
|
|
370
|
-
let { list = [] } = data;
|
|
371
|
-
commit('setVideoVoiceList', list);
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
},
|
|
375
|
-
async initUniRTC({ commit, state }, obj) {
|
|
376
|
-
const { uniAppId, uniSecretKey, params } = obj;
|
|
377
|
-
let uniRTC = null;
|
|
378
|
-
const getLoginToken = async () => {
|
|
379
|
-
let appSign;
|
|
380
|
-
const paramsData = {
|
|
381
|
-
clientType: '1',
|
|
382
|
-
deviceToken: uniRTC.deviceToken,
|
|
383
|
-
appId: uniAppId,
|
|
384
|
-
secretKey: uniSecretKey
|
|
385
|
-
};
|
|
386
|
-
try {
|
|
387
|
-
const { data } = await fetch.get('/chat/access/getMediaAuthSign', { params: paramsData });
|
|
388
|
-
if (data.result == 'SUCCESS') {
|
|
389
|
-
appSign = data.obj;
|
|
390
|
-
return appSign;
|
|
391
|
-
}
|
|
392
|
-
} catch (error) {
|
|
393
|
-
console.log('获取签名失败:', error);
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
};
|
|
397
|
-
uniRTC = new UniRTCObject(uniAppId, getLoginToken);
|
|
398
|
-
uniRTC.onCallComing = incoming => {
|
|
399
|
-
commit("setIncoming", incoming);
|
|
400
|
-
console.log('onCallComing->', incoming);
|
|
401
|
-
};
|
|
402
|
-
uniRTC.onHangup = () => {
|
|
403
|
-
commit("setIncoming", null);
|
|
404
|
-
commit("setOuting", []);
|
|
405
|
-
};
|
|
406
|
-
// uniRTC.onCallTimeout = () => {
|
|
407
|
-
// commit("setIncoming", null);
|
|
408
|
-
// commit("setOuting", []);
|
|
409
|
-
// };
|
|
410
|
-
uniRTC.onCallRefused = outing => {
|
|
411
|
-
const index = state.outing.findIndex(v => v.target === outing.target);
|
|
412
|
-
if (index > -1) {
|
|
413
|
-
let cloneOuting = deepClone(state.outing);
|
|
414
|
-
cloneOuting.splice(index, 1);
|
|
415
|
-
commit("setOuting", cloneOuting);
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
let timer = null;
|
|
420
|
-
let n = 0;
|
|
421
|
-
const registerDeviceToken = async () => {
|
|
422
|
-
const res = await fetch.post('/chat/service/registerDeviceToken', qs.stringify({
|
|
423
|
-
...params,
|
|
424
|
-
deviceToken: uniRTC.deviceToken,
|
|
425
|
-
}));
|
|
426
|
-
if (res.data?.result !== 'SUCCESS') {
|
|
427
|
-
console.log(res.data.resultMsg);
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
timer && clearInterval(timer);
|
|
432
|
-
timer = setInterval(() => {
|
|
433
|
-
console.log('轮询本机设备token->', uniRTC.deviceToken);
|
|
434
|
-
n++;
|
|
435
|
-
if (!uniRTC.deviceToken) {
|
|
436
|
-
if (n > 60) {
|
|
437
|
-
timer && clearInterval(timer);
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
uniRTC.reconnect();
|
|
441
|
-
} else {
|
|
442
|
-
timer && clearInterval(timer);
|
|
443
|
-
registerDeviceToken();
|
|
444
|
-
}
|
|
445
|
-
}, 1000);
|
|
446
|
-
commit("setUniRTC", uniRTC);
|
|
447
|
-
}
|
|
448
|
-
};
|
|
1
|
+
import fetch, { qs } from '@/utils/chatFetch';
|
|
2
|
+
import Vue from 'vue';
|
|
3
|
+
import vexutils from '@/utils/vexutils';
|
|
4
|
+
import { fmtRobotMessage } from '../utils';
|
|
5
|
+
import UniRTCObject from "@/utils/UniRTCv2";
|
|
6
|
+
|
|
7
|
+
const deepClone = source => {
|
|
8
|
+
let target;
|
|
9
|
+
if (typeof source === "object" && source) {
|
|
10
|
+
target = Array.isArray(source) ? [] : {};
|
|
11
|
+
for (let key in source) {
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
13
|
+
// if (source.hasOwnProperty(key)) {
|
|
14
|
+
if (typeof source[key] !== "object") {
|
|
15
|
+
target[key] = source[key];
|
|
16
|
+
} else {
|
|
17
|
+
target[key] = deepClone(source[key]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
target = source;
|
|
23
|
+
}
|
|
24
|
+
return target;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default {
|
|
28
|
+
/* 更新聊天记录 */
|
|
29
|
+
setMsgList({ commit, state, getters }, option) {
|
|
30
|
+
let { sessionId, historySessionId, msgList, sessionHistoryList, serviceId, isServer, assemblyId } = state;
|
|
31
|
+
let id = msgList[0] && msgList[0].id;
|
|
32
|
+
if (msgList.length === 0 && sessionHistoryList.length > 0) {
|
|
33
|
+
id = sessionHistoryList.find(item => item.fromId === serviceId)?.lastContentId;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let orgId;
|
|
37
|
+
let userId;
|
|
38
|
+
let userType;
|
|
39
|
+
if (!isServer) {
|
|
40
|
+
orgId = getters.accessParams.orgId || getters.queryParams.orgId;
|
|
41
|
+
userId = getters.accessParams.userId || getters.chatUserId || getters.queryParams.userId;
|
|
42
|
+
userType = getters.accessParams.userType || getters.queryParams.userType;
|
|
43
|
+
} else {
|
|
44
|
+
orgId = state.userInfo?.sysParams?.orgId;
|
|
45
|
+
userId = state.userInfo?.sysParams?.userId;
|
|
46
|
+
}
|
|
47
|
+
let params = {
|
|
48
|
+
sessionId: sessionId || historySessionId,
|
|
49
|
+
id,
|
|
50
|
+
assemblyId,
|
|
51
|
+
orgId,
|
|
52
|
+
userId,
|
|
53
|
+
userType,
|
|
54
|
+
relateId: getters.accessParams.relateId
|
|
55
|
+
};
|
|
56
|
+
if (!isServer) {
|
|
57
|
+
params.source = 1;
|
|
58
|
+
params.serviceId = getters.queryParams.serviceId;
|
|
59
|
+
}
|
|
60
|
+
return fetch
|
|
61
|
+
.get(`/chat/${isServer ? 'service' : 'access'}/getHistoryRecord`, {
|
|
62
|
+
params
|
|
63
|
+
})
|
|
64
|
+
.then(({ data }) => {
|
|
65
|
+
if (data.result === 'SUCCESS') {
|
|
66
|
+
if (id && data.list.length === 0) {
|
|
67
|
+
return '没有更多消息了';
|
|
68
|
+
}
|
|
69
|
+
const validate = option?.validate;
|
|
70
|
+
if (validate && !validate(data)) return;
|
|
71
|
+
if (id) {
|
|
72
|
+
commit('setMsgList', [...data.list, ...msgList]);
|
|
73
|
+
commit('appendList', data.list);
|
|
74
|
+
// commit("setScrollTo", "current");
|
|
75
|
+
} else {
|
|
76
|
+
commit('setMsgList', data.list);
|
|
77
|
+
commit('appendList', data.list);
|
|
78
|
+
// commit("setScrollTo", "bottom");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
/* 发送消息 */
|
|
84
|
+
sendMessage({ commit, state, getters }, body) {
|
|
85
|
+
let { assemblyId, sessionId, serviceId, queueId, isServer, clientId } = state;
|
|
86
|
+
let orgId;
|
|
87
|
+
let userId;
|
|
88
|
+
let userType;
|
|
89
|
+
if (!isServer) {
|
|
90
|
+
orgId = getters.accessParams.orgId || getters.queryParams.orgId;
|
|
91
|
+
userId = getters.accessParams.userId || getters.chatUserId || getters.queryParams.userId;
|
|
92
|
+
userType = getters.accessParams.userType || getters.queryParams.userType;
|
|
93
|
+
} else {
|
|
94
|
+
orgId = state.userInfo?.sysParams?.orgId;
|
|
95
|
+
userId = state.userInfo?.sysParams?.userId;
|
|
96
|
+
}
|
|
97
|
+
let fromName = state.userInfo?.sysParams?.userName;
|
|
98
|
+
let portrait = state.userInfo?.userInfoMap?.headUrl;
|
|
99
|
+
let failItem = body.failItem;
|
|
100
|
+
delete body.failItem;
|
|
101
|
+
let message;
|
|
102
|
+
if (!failItem) {
|
|
103
|
+
message = {
|
|
104
|
+
content: body,
|
|
105
|
+
fromId: isServer ? serviceId : clientId,
|
|
106
|
+
fromName,
|
|
107
|
+
sessionId,
|
|
108
|
+
id: '',
|
|
109
|
+
createdTime: new Date().getTime(),
|
|
110
|
+
sending: true,
|
|
111
|
+
fail: false,
|
|
112
|
+
portrait
|
|
113
|
+
};
|
|
114
|
+
commit('setIsAppendMsg', true);
|
|
115
|
+
commit('setMessage', message);
|
|
116
|
+
commit('appendList', [message]);
|
|
117
|
+
} else {
|
|
118
|
+
body = failItem.content;
|
|
119
|
+
message = failItem;
|
|
120
|
+
}
|
|
121
|
+
let params = {
|
|
122
|
+
assemblyId,
|
|
123
|
+
sessionId,
|
|
124
|
+
queueId,
|
|
125
|
+
orgId,
|
|
126
|
+
userId,
|
|
127
|
+
userType,
|
|
128
|
+
relateId: getters.accessParams.relateId,
|
|
129
|
+
body: JSON.stringify(body),
|
|
130
|
+
source: isServer ? 2 : 1
|
|
131
|
+
};
|
|
132
|
+
return fetch
|
|
133
|
+
.post(`/chat/${isServer ? 'service' : 'access'}/sendMessage`, qs.stringify(params))
|
|
134
|
+
.then(({ data }) => {
|
|
135
|
+
if (data.result === 'SUCCESS') {
|
|
136
|
+
const map = data.map || {};
|
|
137
|
+
const id = map.messageId;
|
|
138
|
+
const status = message.readStatus || state.msgRecordCache[id] || map.readStatus;
|
|
139
|
+
Vue.prototype.$set(message, 'id', id);
|
|
140
|
+
Vue.prototype.$set(message, 'fail', false);
|
|
141
|
+
Vue.prototype.$set(message, 'readStatus', status);
|
|
142
|
+
// commit("setIsAppendMsg", true);
|
|
143
|
+
// commit("setMessage", {
|
|
144
|
+
// content: body,
|
|
145
|
+
// fromId: isServer ? serviceId : clientId,
|
|
146
|
+
// fromName,
|
|
147
|
+
// sessionId,
|
|
148
|
+
// id: data.map?.messageId,
|
|
149
|
+
// createdTime: new Date().getTime()
|
|
150
|
+
// });
|
|
151
|
+
// 客服自己发送的消息也在会话列表实时更新
|
|
152
|
+
commit('setIsScrollListChange', true);
|
|
153
|
+
commit('setListChangeItem', {
|
|
154
|
+
opt: 1,
|
|
155
|
+
from: clientId,
|
|
156
|
+
msgCount: 0,
|
|
157
|
+
lastContent: body,
|
|
158
|
+
sessionId,
|
|
159
|
+
sendTime: new Date().getTime()
|
|
160
|
+
});
|
|
161
|
+
// 图片加载特殊处理
|
|
162
|
+
// setTimeout(() => {
|
|
163
|
+
// commit("setScrollTo", "bottom");
|
|
164
|
+
// }, 1000);
|
|
165
|
+
} else {
|
|
166
|
+
Vue.prototype.$set(message, 'fail', true);
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
.catch(() => {
|
|
170
|
+
Vue.prototype.$set(message, 'fail', true);
|
|
171
|
+
})
|
|
172
|
+
.finally(() => {
|
|
173
|
+
Vue.prototype.$set(message, 'sending', false);
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
sendRobotMessage({ commit, state, getters, dispatch }, body) {
|
|
177
|
+
let message = body; // 消息内容
|
|
178
|
+
let postParams = null; // 请求附带的额外参数
|
|
179
|
+
// 判断 body 类型 可传递多参数
|
|
180
|
+
if (Object.prototype.toString.call(message) === '[object Object]') {
|
|
181
|
+
message = body.message || '';
|
|
182
|
+
postParams = body.postParams || postParams;
|
|
183
|
+
}
|
|
184
|
+
let { robotId, questionId, dictionaryKey, intentionId, orgId, dictionaryValue, isQuickReply, queryParams } = state;
|
|
185
|
+
let userType = getters.accessParams.userType || getters.queryParams.userType;
|
|
186
|
+
let userId = getters.chatUserId;
|
|
187
|
+
let params = {
|
|
188
|
+
robotId,
|
|
189
|
+
userType,
|
|
190
|
+
userId,
|
|
191
|
+
orgId
|
|
192
|
+
};
|
|
193
|
+
if (isQuickReply) {
|
|
194
|
+
params.dictionaryValue = dictionaryValue;
|
|
195
|
+
}
|
|
196
|
+
if (message) {
|
|
197
|
+
params.message = message;
|
|
198
|
+
}
|
|
199
|
+
if (intentionId) {
|
|
200
|
+
params.intentionId = intentionId;
|
|
201
|
+
}
|
|
202
|
+
if (dictionaryKey) {
|
|
203
|
+
params.dictionaryKey = dictionaryKey;
|
|
204
|
+
}
|
|
205
|
+
if (questionId) {
|
|
206
|
+
params.questionId = questionId;
|
|
207
|
+
}
|
|
208
|
+
if (queryParams.relateId) {
|
|
209
|
+
params.relateId = queryParams.relateId;
|
|
210
|
+
}
|
|
211
|
+
postParams && Object.assign(params, postParams);
|
|
212
|
+
message && commit('setIsAppendMsg', true);
|
|
213
|
+
if (message) {
|
|
214
|
+
commit('setMessage', {
|
|
215
|
+
content: {
|
|
216
|
+
content: message,
|
|
217
|
+
type: 0
|
|
218
|
+
},
|
|
219
|
+
fromId: '',
|
|
220
|
+
mode: 'robot',
|
|
221
|
+
sendTime: new Date().getTime()
|
|
222
|
+
});
|
|
223
|
+
commit('setScrollTo', 'bottom');
|
|
224
|
+
}
|
|
225
|
+
return fetch.post('/robot/access/sendMessage', qs.stringify(params)).then(({ data }) => {
|
|
226
|
+
if (data.result === 'SUCCESS') {
|
|
227
|
+
commit('setIsQuickReply', false);
|
|
228
|
+
let { map = null } = data;
|
|
229
|
+
setTimeout(() => {
|
|
230
|
+
dispatch('robotSendMessage', map);
|
|
231
|
+
}, 50);
|
|
232
|
+
commit('setQuestionId', '');
|
|
233
|
+
commit('setDictionaryKey', '');
|
|
234
|
+
commit('setDictionaryValue', '');
|
|
235
|
+
commit('setIntentionId', '');
|
|
236
|
+
// 图片加载特殊处理
|
|
237
|
+
setTimeout(() => {
|
|
238
|
+
commit('setScrollTo', 'bottom');
|
|
239
|
+
}, 1000);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
robotSendMessage({ commit }, map) {
|
|
244
|
+
if (!map) return;
|
|
245
|
+
if (map.body) {
|
|
246
|
+
let dictionaryValues = map.dictionaryValues || [];
|
|
247
|
+
if (vexutils.isJSON(dictionaryValues)) {
|
|
248
|
+
dictionaryValues = JSON.parse(dictionaryValues);
|
|
249
|
+
}
|
|
250
|
+
let body = map.body;
|
|
251
|
+
let result = Array.isArray(body) ? body : [{ content: body }];
|
|
252
|
+
if (map.actionFlag) {
|
|
253
|
+
// 判断是否触发动作
|
|
254
|
+
const last = result.pop(); // 接口返回的最后一个消息是动作消息(不用上屏,拿出单独执行)
|
|
255
|
+
const url = last?.content?.content || '';
|
|
256
|
+
url && window.open(url);
|
|
257
|
+
}
|
|
258
|
+
if (result.length > 0) {
|
|
259
|
+
result = body.map(item => {
|
|
260
|
+
return Object.assign(fmtRobotMessage(item), {
|
|
261
|
+
fromId: 'SYSTEM',
|
|
262
|
+
mode: 'robot',
|
|
263
|
+
sendTime: new Date().getTime()
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
if (Object.prototype.hasOwnProperty.call(map, 'autoAccess') && map.chatFlag) {
|
|
267
|
+
result[result.length - 1].autoAccess = map.autoAccess + '';
|
|
268
|
+
}
|
|
269
|
+
commit('setIsAppendMsg', true);
|
|
270
|
+
commit('setMessage', result);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (map.chatFlag && map.autoAccess) {
|
|
274
|
+
commit('setChatFlag', true);
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
/**
|
|
278
|
+
* 聊天计时
|
|
279
|
+
* @param {*} param0
|
|
280
|
+
* @param {undefined| string |number | object} data 接收 countdown 或者 {countdown, countdownDesc}
|
|
281
|
+
* @returns
|
|
282
|
+
*/
|
|
283
|
+
setChatTimer({ commit, state }, data) {
|
|
284
|
+
const isObject = vexutils.isObject(data);
|
|
285
|
+
const count = isObject ? data.countdown : data;
|
|
286
|
+
let { sessionTimer, assemblySetting } = state;
|
|
287
|
+
let showMode = assemblySetting?.timingSetting?.showMode;
|
|
288
|
+
clearInterval(sessionTimer);
|
|
289
|
+
commit('setSessionTimer', null);
|
|
290
|
+
commit('setSessionTime', count);
|
|
291
|
+
if (count === undefined) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const isASC = showMode === 'ASC';
|
|
295
|
+
const countdownDesc = (isObject && Number(data.countdownDesc)) || 0;
|
|
296
|
+
commit('setSessionTotalTime', isObject && showMode ? count + countdownDesc : 0); // 正序时记录总时长
|
|
297
|
+
sessionTimer = setInterval(() => {
|
|
298
|
+
commit('setSessionTime', isASC ? ++state.sessionTime : (!state.sessionTime ? 0 : --state.sessionTime));
|
|
299
|
+
}, 1000);
|
|
300
|
+
commit('setSessionTimer', sessionTimer);
|
|
301
|
+
},
|
|
302
|
+
/* 机器人模式下发送文字 */
|
|
303
|
+
handleBotChat({ dispatch, commit, state }, message) {
|
|
304
|
+
commit('setIsAppendMsg', true);
|
|
305
|
+
commit('setMessage', {
|
|
306
|
+
content: {
|
|
307
|
+
content: `<div>${message}</div>`,
|
|
308
|
+
type: 0
|
|
309
|
+
},
|
|
310
|
+
fromId: '',
|
|
311
|
+
mode: 'bot'
|
|
312
|
+
});
|
|
313
|
+
commit('setScrollTo', 'bottom');
|
|
314
|
+
return fetch
|
|
315
|
+
.post(
|
|
316
|
+
'/chat/access/sendBotMessage',
|
|
317
|
+
qs.stringify({
|
|
318
|
+
sessionId: state.botSessionId,
|
|
319
|
+
body: message.replace(/<[^>]+>/g, '')
|
|
320
|
+
})
|
|
321
|
+
)
|
|
322
|
+
.then(({ data }) => {
|
|
323
|
+
if (data.result === 'SUCCESS') {
|
|
324
|
+
return dispatch('handleBotResult', data.map);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
},
|
|
328
|
+
/* 机器人返回的结果 */
|
|
329
|
+
handleBotResult({ commit }, data) {
|
|
330
|
+
let { chatType, resultType, groupList, username, queueId, assembly } = data;
|
|
331
|
+
let content;
|
|
332
|
+
let type = 0;
|
|
333
|
+
if (chatType === 'message') {
|
|
334
|
+
if (['0', '1', '2', '3', '4', '5'].includes(resultType)) {
|
|
335
|
+
content = `<div>${groupList[0].Content}</div>`;
|
|
336
|
+
} else {
|
|
337
|
+
content = groupList.map(item => item.Content);
|
|
338
|
+
type = 6;
|
|
339
|
+
}
|
|
340
|
+
commit('setIsAppendMsg', true);
|
|
341
|
+
commit('setMessage', {
|
|
342
|
+
content: {
|
|
343
|
+
content,
|
|
344
|
+
type
|
|
345
|
+
},
|
|
346
|
+
fromId: 'bot',
|
|
347
|
+
mode: 'bot'
|
|
348
|
+
});
|
|
349
|
+
commit('setScrollTo', 'bottom');
|
|
350
|
+
return false;
|
|
351
|
+
} else {
|
|
352
|
+
commit('setClientId', username);
|
|
353
|
+
commit('setChatType', chatType);
|
|
354
|
+
commit('setAssemblySetting', assembly.settingObj);
|
|
355
|
+
commit('setQueueId', queueId);
|
|
356
|
+
commit('setBotSessionId', '');
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
getVideoHistoryList({ commit, state }) {
|
|
361
|
+
let params = {
|
|
362
|
+
assemblyId: state.assemblyId
|
|
363
|
+
};
|
|
364
|
+
return fetch
|
|
365
|
+
.get('/chat/service/getVideoHistoryList', {
|
|
366
|
+
params
|
|
367
|
+
})
|
|
368
|
+
.then(({ data }) => {
|
|
369
|
+
if (data.result === 'SUCCESS') {
|
|
370
|
+
let { list = [] } = data;
|
|
371
|
+
commit('setVideoVoiceList', list);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
},
|
|
375
|
+
async initUniRTC({ commit, state }, obj) {
|
|
376
|
+
const { uniAppId, uniSecretKey, params } = obj;
|
|
377
|
+
let uniRTC = null;
|
|
378
|
+
const getLoginToken = async () => {
|
|
379
|
+
let appSign;
|
|
380
|
+
const paramsData = {
|
|
381
|
+
clientType: '1',
|
|
382
|
+
deviceToken: uniRTC.deviceToken,
|
|
383
|
+
appId: uniAppId,
|
|
384
|
+
secretKey: uniSecretKey
|
|
385
|
+
};
|
|
386
|
+
try {
|
|
387
|
+
const { data } = await fetch.get('/chat/access/getMediaAuthSign', { params: paramsData });
|
|
388
|
+
if (data.result == 'SUCCESS') {
|
|
389
|
+
appSign = data.obj;
|
|
390
|
+
return appSign;
|
|
391
|
+
}
|
|
392
|
+
} catch (error) {
|
|
393
|
+
console.log('获取签名失败:', error);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
uniRTC = new UniRTCObject(uniAppId, getLoginToken);
|
|
398
|
+
uniRTC.onCallComing = incoming => {
|
|
399
|
+
commit("setIncoming", incoming);
|
|
400
|
+
console.log('onCallComing->', incoming);
|
|
401
|
+
};
|
|
402
|
+
uniRTC.onHangup = () => {
|
|
403
|
+
commit("setIncoming", null);
|
|
404
|
+
commit("setOuting", []);
|
|
405
|
+
};
|
|
406
|
+
// uniRTC.onCallTimeout = () => {
|
|
407
|
+
// commit("setIncoming", null);
|
|
408
|
+
// commit("setOuting", []);
|
|
409
|
+
// };
|
|
410
|
+
uniRTC.onCallRefused = outing => {
|
|
411
|
+
const index = state.outing.findIndex(v => v.target === outing.target);
|
|
412
|
+
if (index > -1) {
|
|
413
|
+
let cloneOuting = deepClone(state.outing);
|
|
414
|
+
cloneOuting.splice(index, 1);
|
|
415
|
+
commit("setOuting", cloneOuting);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
let timer = null;
|
|
420
|
+
let n = 0;
|
|
421
|
+
const registerDeviceToken = async () => {
|
|
422
|
+
const res = await fetch.post('/chat/service/registerDeviceToken', qs.stringify({
|
|
423
|
+
...params,
|
|
424
|
+
deviceToken: uniRTC.deviceToken,
|
|
425
|
+
}));
|
|
426
|
+
if (res.data?.result !== 'SUCCESS') {
|
|
427
|
+
console.log(res.data.resultMsg);
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
timer && clearInterval(timer);
|
|
432
|
+
timer = setInterval(() => {
|
|
433
|
+
console.log('轮询本机设备token->', uniRTC.deviceToken);
|
|
434
|
+
n++;
|
|
435
|
+
if (!uniRTC.deviceToken) {
|
|
436
|
+
if (n > 60) {
|
|
437
|
+
timer && clearInterval(timer);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
uniRTC.reconnect();
|
|
441
|
+
} else {
|
|
442
|
+
timer && clearInterval(timer);
|
|
443
|
+
registerDeviceToken();
|
|
444
|
+
}
|
|
445
|
+
}, 1000);
|
|
446
|
+
commit("setUniRTC", uniRTC);
|
|
447
|
+
}
|
|
448
|
+
};
|