Pārlūkot izejas kodu

reactor:封装websocket:

zhangchong 1 gadu atpakaļ
vecāks
revīzija
f7e6d497e2

+ 4 - 0
.env.development

@@ -28,6 +28,10 @@ VITE_AMAP_KEY=83f51df235e4008e4eaf515cff63785c
 # # 呼叫中心socket地址
 VITE_CALLCENTER_SOCKET_URL=ws://222.213.23.229:29003/ola_socket
 
+# # 智能客服登录地址
+VITE_VOICE_ASSISTANT_API_URL=http://118.121.198.222:19080
 # # 智能客服socket地址
 VITE_VOICE_ASSISTANT_SOCKET_URL=ws://182.151.41.101:19005
 
+
+

+ 3 - 1
.env.production

@@ -29,4 +29,6 @@ VITE_AMAP_KEY=83f51df235e4008e4eaf515cff63785c
 VITE_CALLCENTER_SOCKET_URL=ws://222.213.23.229:29003/ola_socket
 
 # # 智能客服socket地址
-VITE_VOICE_ASSISTANT_SOCKET_URL=ws://182.151.41.101:19005
+VITE_VOICE_ASSISTANT_SOCKET_URL=ws://182.151.41.101:19005
+# # 智能客服登录地址
+VITE_VOICE_ASSISTANT_API_URL=http://118.121.198.222:19080

+ 2 - 1
src/utils/websocket.ts

@@ -18,7 +18,7 @@ class Socket {
 		this.url = url;
 		this.opts = {
 			heartbeatInterval: 10 * 1000, // 心跳间隔
-			reconnectInterval: 5 * 1000, // 重连间隔
+			reconnectInterval: 10 * 1000, // 重连间隔
 			maxReconnectAttempts: 5, // 最大重连次数
 			...opts,
 		};
@@ -36,6 +36,7 @@ class Socket {
 	}
 
 	onOpen(event: Event) {
+		// this.reconnectAttempts=0;
 		this.startHeartbeat();
 		this.emit('open', event);
 	}

+ 36 - 104
src/views/todo/seats/accept/Voice-assistant.vue

@@ -54,113 +54,45 @@ import { nextTick, onMounted, ref, watch } from 'vue';
 import { useSocket } from '/@/utils/websocket';
 import { ElMessageBox, ElNotification } from 'element-plus';
 import { getImageUrl } from '/@/utils/tools';
-
+import axios from 'axios';
+import { storeToRefs } from 'pinia';
+import { useTelStatus } from '/@/stores/telStatus';
 // 消息列表
-const messageList = ref([
-	{
-		type: 'agent',
-		content: '你好,我是小助手,我可以帮你完成一些事情,你可以通过我来完成,比如:我可以帮你查询天气,我可以帮你查询天气',
-		date: '2021-08-09 10:00:00',
-		name: '小助手',
-	},
-	{
-		type: 'user',
-		content: '你好,我是小助手,我可以帮你完成一些事情,你可以通过我来完成,比如:我可以帮你查询天气,我可以帮你查询天气',
-		date: '2021-08-09 10:00:00',
-		name: '小助手',
-	},
-	{
-		type: 'agent',
-		content: '你好,我是小助手,我可以帮你完成一些事情,你可以通过我来完成,比如:我可以帮你查询天气,我可以帮你查询天气',
-		date: '2021-08-09 10:00:00',
-		name: '小助手',
-	},
-	{
-		type: 'user',
-		content: '你好,我是小助手,我可以帮你完成一些事情,你可以通过我来完成,比如:我可以帮你查询天气,我可以帮你查询天气',
-		date: '2021-08-09 10:00:00',
-		name: '小助手',
-	},
-	{
-		type: 'agent',
-		content: '你好,我是小助手,我可以帮你完成一些事情,你可以通过我来完成,比如:我可以帮你查询天气,我可以帮你查询天气',
-		date: '2021-08-09 10:00:00',
-		name: '小助手',
-	},
-]);
-// setInterval(() => {
-//   messageList.value.push({
-//     type: 'agent',
-//     content: '你好,我是小助手,我可以帮你完成一些事情,你可以通过我来完成,比如:我可以帮你查询天气,我可以帮你查询天气',
-//     date: Date(),
-//     name:'小助手'
-//   })
-// }, 1000);
-// setInterval(() => {
-//   messageList.value.push({
-//     type: 'user',
-//     content: '你好,我是小助手,我可以帮你完成一些事情,你可以通过我来完成,比如:我可以帮你查询天气,我可以帮你查询天气',
-//     date: Date(),
-//     name:'用户123'
-//   })
-// }, 1000);
-// ws接收消息
-// 识别内容
-const recognizeList = ref([
-	{
-		title: '查询天气',
-		content: '我可以帮你查询天气',
-	},
-	{
-		title: '查询天气',
-		content: '我可以帮你查询天气',
-	},
-	{
-		title: '查询天气',
-		content: '我可以帮你查询天气',
-	},
-	{
-		title: '查询天气',
-		content: '我可以帮你查询天气',
-	},
-	{
-		title: '查询天气',
-		content: '我可以帮你查询天气',
-	},
-	{
-		title: '查询天气',
-		content: '我可以帮你查询天气',
-	},
-	{
-		title: '查询天气',
-		content: '我可以帮你查询天气',
-	},
-	{
-		title: '查询天气',
-		content: '我可以帮你查询天气',
-	},
-	{
-		title: '查询天气',
-		content: '我可以帮你查询天气',
-	},
-]);
+const messageList = ref([]); // 消息列表
+const recognizeList = ref([]); // 识别信息
+
+const useTelStatusStore = useTelStatus();
+const { telStatusInfo } = storeToRefs(useTelStatusStore); // 电话状态
+console.log(telStatusInfo.value);
+
+// 打开websocket链接
+const seatAssistOn = () => {
+	if (telStatusInfo.value.telsNo) {
+		axios.get(`${import.meta.env.VITE_VOICE_ASSISTANT_API_URL}/rtserver-api/users/getUserByAgentId/${telStatusInfo.value.telsNo}`).then((res) => {
+      console.log(res,'获取到的用户信息')
+			const { socket, send, on, off } = useSocket(import.meta.env.VITE_VOICE_ASSISTANT_SOCKET_URL);
+			on('open', () => {
+				console.log('坐席辅助链接已打开');
+				send({
+					id: '',
+					type: 1,
+					from: '',
+					to: 'sys',
+					timestamps: 1,
+					body: '',
+				});
+			});
+			on('message', wsReceive); // 接收消息
+			on('error', onError); // 错误
+			on('close', onClose); // 关闭
+		}).catch((err) => {
+      console.log(err,'获取用户信息失败');
+    });
+	}
+};
 // 设置初始化,防止刷新时恢复默认
 onMounted(() => {
-	const { socket, send, on, off } = useSocket(import.meta.env.VITE_VOICE_ASSISTANT_SOCKET_URL);
-	on('open', () => {
-		console.log('坐席辅助链接已打开');
-		send({
-			id: '',
-			type: 1,
-			from: '',
-			to: 'sys',
-			timestamps: 1,
-			body: '',
-		});
-	});
-	on('message', wsReceive); // 接收消息
-	on('error', onError); // 错误
-	on('close', onClose); // 关闭
+  seatAssistOn();
 });
 const wsReceive = (message: any) => {
 	try {