feat:完善功能
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<script setup>
|
||||
import box1 from './components/box-1.vue'
|
||||
import box2 from './components/box-2.vue'
|
||||
|
||||
import { useWebSocket } from '@/hooks/socket'
|
||||
import { useScenicStore } from '@/stores/scenic'
|
||||
import { mode, socketBaseUrl, proSocketBaseUrl } from '@/utils/config'
|
||||
@@ -19,6 +20,8 @@
|
||||
)
|
||||
|
||||
let scenicSpotId = ref('')
|
||||
let scenicChange = null
|
||||
let timer = null
|
||||
|
||||
watch(
|
||||
() => [isConnected.value, scenicSpotId.value],
|
||||
@@ -34,6 +37,7 @@
|
||||
() => dataRes.value,
|
||||
(val) => {
|
||||
if (val) {
|
||||
console.log(val, '景区接受消息')
|
||||
switch (val.type) {
|
||||
case 'wordkOrderlist':
|
||||
scenicStore.setWordkOrderList(val.data)
|
||||
@@ -66,17 +70,33 @@
|
||||
scenicStore.setCarShipData(val.data)
|
||||
break
|
||||
}
|
||||
if (!timer) sendCarShip()
|
||||
}
|
||||
}
|
||||
)
|
||||
let scenicChange = null
|
||||
|
||||
const sendCarShip = (e) => {
|
||||
timer = setInterval(() => {
|
||||
if (isConnected.value) {
|
||||
console.log('定时发送车船消息22')
|
||||
sendMessage(
|
||||
JSON.stringify({
|
||||
action: 'start',
|
||||
type: 'carShipData',
|
||||
scenicSpotId: scenicSpotId.value
|
||||
})
|
||||
)
|
||||
}
|
||||
}, 5000)
|
||||
}
|
||||
onMounted(() => {
|
||||
scenicChange = PubSub.subscribe('scenicChange', (msg, data) => {
|
||||
scenicSpotId.value = data.scenicSpotId
|
||||
})
|
||||
})
|
||||
onUnmounted(() => {
|
||||
PubSub.unsubscribe(scenicChange)
|
||||
if (scenicChange) PubSub.unsubscribe(scenicChange)
|
||||
if (timer) clearInterval(timer)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user