feat:对接景区接口
This commit is contained in:
@@ -10,20 +10,26 @@
|
||||
import { useScenicStore } from '@/stores/scenic'
|
||||
import { mode, socketBaseUrl, proSocketBaseUrl } from '@/utils/config'
|
||||
|
||||
import PubSub from 'pubsub-js'
|
||||
|
||||
const scenicStore = useScenicStore()
|
||||
|
||||
const { isConnected, sendMessage, dataRes } = useWebSocket(
|
||||
`${mode == 'dev' ? socketBaseUrl : proSocketBaseUrl}/ws/scenic-spot`
|
||||
)
|
||||
|
||||
let id = ref('')
|
||||
|
||||
watch(
|
||||
() => isConnected.value,
|
||||
() => [isConnected.value, id.value],
|
||||
(val) => {
|
||||
if (val) {
|
||||
sendMessage(JSON.stringify({ action: 'start', type: '', scenicSpotId: '1' }))
|
||||
if (val[0] && val[1]) {
|
||||
sendMessage(JSON.stringify({ action: 'start', type: '', scenicSpotId: id.value }))
|
||||
}
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
watch(
|
||||
() => dataRes.value,
|
||||
(val) => {
|
||||
@@ -33,6 +39,9 @@
|
||||
case 'wordkOrderlist':
|
||||
scenicStore.setWordkOrderList(val.data)
|
||||
break
|
||||
case 'wordkOrderTotal':
|
||||
scenicStore.setWordkOrderData(val)
|
||||
break
|
||||
case 'scenicSpotData':
|
||||
scenicStore.setScenicSpotData(val.data)
|
||||
break
|
||||
@@ -54,10 +63,22 @@
|
||||
case 'userPortrait':
|
||||
scenicStore.setUserPortraitData(val)
|
||||
break
|
||||
case 'carShipData':
|
||||
scenicStore.setCarShipData(val.data)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
let scenicChange = null
|
||||
onMounted(() => {
|
||||
scenicChange = PubSub.subscribe('scenicChange', (msg, data) => {
|
||||
id.value = data.scenicSpotId
|
||||
})
|
||||
})
|
||||
onUnmounted(() => {
|
||||
PubSub.unsubscribe(scenicChange)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
|
||||
Reference in New Issue
Block a user