Parcourir la source

reactor:坐席辅助调整;

zhangchong il y a 1 an
Parent
commit
b9748c3029

+ 32 - 34
src/layout/navBars/breadcrumb/telControl.vue

@@ -868,6 +868,7 @@ const clickOnDuty = (formEl: FormInstance | undefined) => {
 
 // 链接呼叫中心
 const websocket_connect = () => {
+	console.log('链接呼叫中心');
 	if (ola.ws) {
 		// 如果已经连接 则先关闭
 		ola.close();
@@ -882,7 +883,7 @@ const onConnect = () => {
 	ola.subscribe('ola.agent.' + currentTel.value.telNo);
 	ola.subscribe('ola.caller.' + currentTel.value.telNo);
 	ola.get_agent_state(currentTel.value.telNo);
-
+	seatAssistOn(); // 坐席助手开启
 	// ola.logout(currentTel.value.telNo); //连接之后,先登出一次,防止其他地方已经登陆
 	let array_ola_queue: EmptyArrayType = []; // 队列
 	if (currentTel.value.queue) {
@@ -940,7 +941,6 @@ const onMessage = (event: any) => {
 			state.loading = false;
 			// ElMessage.success('示闲中');
 			console.log('呼叫中心:示闲中');
-			seatAssistOn();
 		} else if (data.state == 'unready') {
 			// 示忙中
 			useTelStatusStore.setPhoneControlState(TelStates.rest);
@@ -1477,40 +1477,38 @@ const clickOnOutbound = (formEl: FormInstance | undefined) => {
 const socket = ref<any>(null);
 // 打开websocket链接
 const seatAssistOn = () => {
-	if (telStatusInfo.value.telsNo) {
-		if (socket.value?.socket?.ws) {
-			// 如果已经有连接了 先关闭
-			socket.value.close();
-			socket.value = null;
-		}
-		axios
-			.get(`${import.meta.env.VITE_VOICE_ASSISTANT_API_URL}/users/getUserByAgentId/${telStatusInfo.value.telsNo}`)
-			.then((res) => {
-				const { data } = res;
-				const { result } = data;
-				const uid = `8#User-${result.uid}`;
-				const subscribe = `/trans/${result.orgCode}/${result.groupUid}/${uid}`;
-				socket.value = useSocket(import.meta.env.VITE_VOICE_ASSISTANT_SOCKET_URL, { uid, subscribe });
-				socket.value.on('open', () => {
-					console.log('坐席辅助:已开启');
-					socket.value.send({
-						// 调用登录
-						id: '',
-						type: 1,
-						from: uid,
-						to: 'sys',
-						timestamps: new Date().getTime(),
-						body: result.userName,
-					});
+	if (socket.value?.socket?.ws) {
+		// 如果已经有连接了 先关闭
+		socket.value.close();
+		socket.value = null;
+	}
+	axios
+		.get(`${import.meta.env.VITE_VOICE_ASSISTANT_API_URL}/users/getUserByAgentId/${currentTel.value.telNo}`)
+		.then((res) => {
+			const { data } = res;
+			const { result } = data;
+			const uid = `8#User-${result.uid}`;
+			const subscribe = `/trans/${result.orgCode}/${result.groupUid}/${uid}`;
+			socket.value = useSocket(import.meta.env.VITE_VOICE_ASSISTANT_SOCKET_URL, { uid, subscribe });
+			socket.value.on('open', () => {
+				console.log('坐席辅助:已开启');
+				socket.value.send({
+					// 调用登录
+					id: '',
+					type: 1,
+					from: uid,
+					to: 'sys',
+					timestamps: new Date().getTime(),
+					body: result.userName,
 				});
-				socket.value.on('message', wsReceive); // 接收消息
-				/* socket.value.on('error', onError); // 错误
-          socket.value.on('close', onClose); // 关闭*/
-			})
-			.catch((err) => {
-				console.log(err, '坐席辅助:获取到的坐席辅助用户信息失败');
 			});
-	}
+			socket.value.on('message', wsReceive); // 接收消息
+			/* socket.value.on('error', onError); // 错误
+          socket.value.on('close', onClose); // 关闭*/
+		})
+		.catch((err) => {
+			console.log(err, '坐席辅助:获取到的坐席辅助用户信息失败');
+		});
 };
 // 坐席辅助关闭
 const seatAssistOff = () => {

+ 5 - 8
src/views/todo/seats/accept/Voice-assistant.vue

@@ -165,14 +165,11 @@ const wsReceive = (message: any) => {
 				if (data.body.content.action === 1) {
 					// 通话中
 					if (messageList.value.length) {
-						for (let i of messageList.value) {
-							if (i.body.content.callSentenceInfo.index === data.body.content.callSentenceInfo.index) {
-								// 如果index相同就替换内容
-								i.body.content.callSentenceInfo.text = data.body.content.callSentenceInfo.text;
-							} else {
-								//index不同就添加
-								messageList.value.push(data);
-							}
+						const item = messageList.value.find((item: any) => item.body.content.callSentenceInfo.index === data.body.content.callSentenceInfo.index);
+						if (item) {
+							item.body.content.callSentenceInfo.text = data.body.content.callSentenceInfo.text;
+						} else {
+							messageList.value.push(data);
 						}
 					} else {
 						messageList.value.push(data);