fix : 修复socket接收数据功能
This commit is contained in:
@@ -1,28 +1,33 @@
|
||||
<template>
|
||||
<!--测试 张三 : 17260625724565 李四: 17260625724123-->
|
||||
<!--测试 张三 : 17260625724565 李四: 17260625724123-->
|
||||
<div class="live-call-block">
|
||||
<live-call-item ref="recordLeftRef" :recordObj="recordLeftObj" :headData="leftHeadData" />
|
||||
<live-call-item ref="recordRightRef" :recordObj="recordRightObj" :headData="rightHeadData" />
|
||||
<live-call-item ref="recordLeftRef" :recordObj="recordLeftObj" :headData="leftHeadData"/>
|
||||
<live-call-item ref="recordRightRef" :recordObj="recordRightObj" :headData="rightHeadData"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {useAuthStore} from '@/stores/userstore.js'
|
||||
import {getToken} from '@/utils/auth'
|
||||
import {usePermisstionStroe} from '@/stores/permisstion'
|
||||
|
||||
const permisstionStore = usePermisstionStroe()
|
||||
const authStore = useAuthStore()
|
||||
//聊天消息滚动面板dom
|
||||
const recordLeftRef = ref(null);
|
||||
const recordRightRef = ref(null);
|
||||
const leftHeadData=ref({
|
||||
username:'张三',
|
||||
phone:'13546812315',
|
||||
orderName:'张三工单',
|
||||
const leftHeadData = ref({
|
||||
username: '张三',
|
||||
phone: '13546812315',
|
||||
orderName: '张三工单',
|
||||
})
|
||||
const rightHeadData=ref({
|
||||
username:'李四',
|
||||
phone:'18246812546',
|
||||
orderName:'李四工单',
|
||||
const rightHeadData = ref({
|
||||
username: '李四',
|
||||
phone: '18246812546',
|
||||
orderName: '李四工单',
|
||||
})
|
||||
const recordLeftObj = ref({
|
||||
content:[]
|
||||
content: []
|
||||
}
|
||||
// {
|
||||
// "callIdNumber": "17260625724565",
|
||||
@@ -50,7 +55,7 @@ const recordLeftObj = ref({
|
||||
// }
|
||||
)
|
||||
const recordRightObj = ref({
|
||||
content:[]
|
||||
content: []
|
||||
}
|
||||
// {
|
||||
// "callIdNumber": "17260625724123",
|
||||
@@ -95,10 +100,16 @@ const scrollToBottom = (scrollbarRef) => {
|
||||
const setWsUrl = (url) => {
|
||||
return (window.location.protocol === 'http:' ? "ws://" : "wss://") + window.location.host + import.meta.env.VITE_BASE_WSURL + url;
|
||||
}
|
||||
const handleLogout = () => {
|
||||
authStore.userLogout()
|
||||
permisstionStore.removeMenu()
|
||||
router.push('/login')
|
||||
}
|
||||
const initWebSocket = () => {
|
||||
try {
|
||||
// const wsUrl=setWsUrl(`/ws/text/${token}`)
|
||||
const wsUrl = `ws://frp.feashow.cn:31800/ws/text/${token}`
|
||||
// const wsUrl = `ws://112.19.165.99:20002/ws/text/${token}`
|
||||
socket = new WebSocket(wsUrl)
|
||||
// 2. ws.send()给服务器发送信息
|
||||
//连接发生错误的回调方法
|
||||
@@ -119,21 +130,27 @@ const initWebSocket = () => {
|
||||
socket.onmessage = function (event) {
|
||||
let data = JSON.parse(event.data)
|
||||
if (data.type !== 'pong') {
|
||||
if (data.type === 'error') {
|
||||
handleLogout()
|
||||
return;
|
||||
} else if (data.type === 'failed') {
|
||||
initWebSocket()
|
||||
return;
|
||||
}
|
||||
console.log("服务器返回的信息: ", data);
|
||||
if(data.type=='1'){
|
||||
recordLeftObj.value.content.push(data.content)
|
||||
if (data.type == '1') {
|
||||
recordLeftObj.value.content.push(data.content)
|
||||
// console.info("🚀 ~method:onmessage -----", recordLeftObj.value)
|
||||
nextTick(() => {
|
||||
scrollToBottom(recordLeftRef.value)
|
||||
})
|
||||
}else {
|
||||
recordRightObj.value.content.push(data.content)
|
||||
} else {
|
||||
recordRightObj.value.content.push(data.content)
|
||||
// console.info("🚀 ~method:onmessage -----", recordRightObj.value)
|
||||
nextTick(() => {
|
||||
scrollToBottom(recordRightRef.value);
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//连接关闭的回调方法
|
||||
@@ -143,7 +160,7 @@ const initWebSocket = () => {
|
||||
}
|
||||
setInterval(() => {
|
||||
socket.send(JSON.stringify(send))
|
||||
}, 10000)
|
||||
}, 5000)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
console.log("ws连接失败");
|
||||
|
||||
Reference in New Issue
Block a user