feat:完善功能

This commit is contained in:
zjc
2025-01-26 01:27:56 +08:00
parent fd726ead46
commit 21fb9a9c59
11 changed files with 165 additions and 23 deletions

View File

@@ -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>