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