소스 검색

reactor:电话控件调整:

zhangchong 1 년 전
부모
커밋
6987ef6d26
2개의 변경된 파일33개의 추가작업 그리고 33개의 파일을 삭제
  1. 31 9
      src/layout/navBars/breadcrumb/telControl.vue
  2. 2 24
      src/utils/ola_api.ts

+ 31 - 9
src/layout/navBars/breadcrumb/telControl.vue

@@ -509,6 +509,7 @@ import { useRouter } from 'vue-router';
 import { useSocket } from '@/utils/websocket';
 import mittBus from '@/utils/mitt';
 import { voiceAssistant } from '@/api/todo/voiceAssistant';
+import {submitLog} from "@/api/public/log";
 // 引入组件
 const CommonAdvice = defineAsyncComponent(() => import('@/components/CommonAdvice/index.vue')); // 常用意见
 const AnnexList = defineAsyncComponent(() => import('@/components/AnnexList/index.vue'));
@@ -582,7 +583,7 @@ const talkTimer = ref<any>(null); // 通话时长定时器
 // 开始通话计时
 const startTime = () => {
 	let localTalkTime = Local.get('talkTime');
-	if (talkTime) {
+	if (talkTime.value) {
 		talkTime.value = Number(localTalkTime);
 		talkTimer.value = setInterval(() => {
 			talkTime.value++;
@@ -850,7 +851,7 @@ const websocket_connect = () => {
 		ola.close();
 	}
 	ola.onConnect = onConnect;
-	ola.onclose = onclose;
+	ola.onClose = onClose;
 	ola.onMessage = onMessage;
 	ola.connect(import.meta.env.VITE_CALLCENTER_SOCKET_URL, currentTel.value.telNo, currentTel.value.password);
 };
@@ -874,7 +875,6 @@ const onConnect = () => {
 		ola.login(array_ola_queue, currentTel.value.telNo, { type: 'onhook' });
 		connectVoiceAssistant(currentTel.value.telNo); // 坐席助手开启
 	}
-
   Local.set('telNo', currentTel.value.telNo);
 };
 // 业务系统发送消息
@@ -1155,23 +1155,42 @@ const onMessage = async (event: any) => {
 		// console.log('command/reply', data);
 	}
 };
+// 记录日志
+const submitLogFn = async (event: any) => {
+  const telsNo = Local.get('telNo');
+  const name: string = `分机号:${telsNo}的websocket断开链接`;
+  const remark: string = `websocket 断开: 错误code:${event.code}, 错误原因:${event.reason}, 是否正常断开:${event.wasClean}`;
+  console.log(name, remark, event);
+  const request = {
+    creationTime: new Date(),
+    name,
+    remark,
+    executeUrl: import.meta.env.VITE_CALLCENTER_SOCKET_URL,
+  };
+  try {
+    await submitLog(request);
+    Local.remove('telNo');
+  } catch (error) {
+    console.log(error);
+  }
+};
 // 呼叫中心链接关闭
 const isReconnect = ref(true); // 呼叫中心是否需要重连
-const onclose = (e: any) => {
-	console.log(e, 'ws断开');
-	console.log('呼叫中心断开链接', isReconnect.value ? '需要重连' : '不需要重连');
+const onClose =  async(event: any) => {
 	removeTimerOnDuty(); // 移除签入时长定时器
 	removeTimer(); // 移除通话计时器
 	clearTimeout(talkDealTimer.value); // 清除话后整理定时器
 	clearInterval(pingTimer.value); // 清除心跳定时器
 	clearInterval(onDutyTimer.value); // 清除签入时长定时器
 	clearInterval(talkTimer.value); // 清除通话时长定时器
+  console.log('呼叫中心断开链接', isReconnect.value ? '需要重连' : '不需要重连');
 	if (isReconnect.value) {
-		reConnect(); // 重新链接呼叫中心
+		await reConnect(); // 重新链接呼叫中心
 		Local.set('currentTelNo', currentTel.value.telNo);
 	}
 	// 重置所有状态
 	useTelStatusStore.resetState();
+  await submitLogFn(event);
 };
 // 重新链接呼叫中心
 let reconnectAttempts = 0; // 重连次数
@@ -1273,6 +1292,10 @@ const offDutyFn = () => {
 			state.loading = true;
 			dutyOff()
 				.then(() => {
+          console.log('业务系统:签出成功')
+
+          isReconnect.value = false; // 不需要重连
+          Local.set('isReconnect1',false)
 					sendMsg('logout');
 					ola.logout(currentTel.value.telNo); //签出
 					setTimeout(() => {
@@ -1286,8 +1309,7 @@ const offDutyFn = () => {
 					clearInterval(pingTimer.value); // 清除心跳定时器
 					clearInterval(onDutyTimer.value); // 清除签入时长定时器
 					clearInterval(talkTimer.value); // 清除通话时长定时器
-					isReconnect.value = false; // 不需要重连
-					state.loading = false;
+
 					state.dutyOnSrc = getImageUrl('phoneControls/dutyOn_blue.png'); //签入图片
 					state.loading = false;
 				})

+ 2 - 24
src/utils/ola_api.ts

@@ -3,9 +3,6 @@ import { dutyOff } from '@/api/public/wex';
  * @description 呼叫中心对接接口
  */
 import { ElMessage } from 'element-plus';
-import { submitLog } from '@/api/public/log';
-import dayjs from 'dayjs';
-import { Local } from '@/utils/storage';
 
 export const ola: any = {
 	version: '2.0.1',
@@ -28,7 +25,7 @@ export const ola: any = {
 			// browser supports websockets
 			this.ws = new WebSocket(url);
 			if (this.ws) {
-				this.ws.onclose = ola._onClose;
+				this.ws.onclose = ola.onClose;
 				this.ws.onopen = ola._onOpen;
 				this.ws.onmessage = ola._onMessage;
 				this._connectSuccess = success;
@@ -48,31 +45,12 @@ export const ola: any = {
 	},
 
 	close: function () {
-		ola.ws.close();
+		ola.ws?.close();
 	},
 
 	_onOpen: function () {
 		ola.auth(ola._username, ola._password);
 	},
-	_onClose: async function (e: any) {
-		const telsNo = Local.get('telNo');
-		ola.ws.onclose = ola.onclose;
-		console.log(`websocket 断开: 分机号:${telsNo} ,错误code:${e.code}, 错误原因:${e.reason}, 是否正常断开:${e.wasClean}`, e);
-		const name: string = `分机号:${telsNo}的websocket断开链接`;
-		const remark: string = `websocket 断开: 错误code:${e.code}, 错误原因:${e.reason}, 是否正常断开:${e.wasClean}`;
-		const request = {
-			creationTime: new Date(),
-			name,
-			remark,
-			executeUrl: import.meta.env.VITE_CALLCENTER_SOCKET_URL,
-		};
-		try {
-			await submitLog(request);
-			Local.remove('telNo');
-		} catch (error) {
-			console.log(error);
-		}
-	},
 
 	_onMessage: function (evt: any) {
 		//获取消息