feat:完善功能
This commit is contained in:
@@ -13,22 +13,61 @@
|
||||
import { useMap } from '@/hooks/map'
|
||||
|
||||
let modelValue = defineModel()
|
||||
const { map, initMap, addMarker } = useMap()
|
||||
const { map, initMap, addMarker, clearOverlays } = useMap()
|
||||
|
||||
let props = defineProps({
|
||||
carList: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
shipList: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
}
|
||||
})
|
||||
|
||||
let lat = ref('')
|
||||
let lng = ref('')
|
||||
let scenicChange = null
|
||||
|
||||
watch(
|
||||
() => modelValue.value,
|
||||
(val) => {
|
||||
if (val && !map.value) {
|
||||
if (val) {
|
||||
setTimeout(() => {
|
||||
initMap('big-car-ship', 109.552461, 31.049607, 15)
|
||||
addMarker(carIcon, [109.551419, 31.050001], [36, 50])
|
||||
addMarker(shipIcon, [109.551671, 31.04847], [36, 50])
|
||||
initMap('big-car-ship', lng.value, lat.value, 15)
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
watch(
|
||||
() => [map.value, props.carList, props.shipList],
|
||||
(val) => {
|
||||
if (val[0]) {
|
||||
setTimeout(() => {
|
||||
clearOverlays()
|
||||
val[1].map((item) => {
|
||||
if (item.lng && item.lat) addMarker(carIcon, [item.lng, item.lat], [36, 50])
|
||||
})
|
||||
val[2].map((item) => {
|
||||
if (item.lng && item.lat) addMarker(shipIcon, [item.lng, item.lat], [36, 50])
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
onMounted(() => {})
|
||||
onMounted(() => {
|
||||
scenicChange = PubSub.subscribe('scenicChange', (msg, data) => {
|
||||
lat.value = data.lat
|
||||
lng.value = data.lng
|
||||
})
|
||||
})
|
||||
onUnmounted(() => {
|
||||
PubSub.unsubscribe(scenicChange)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -283,7 +283,7 @@
|
||||
<div class="label">运营船只</div>
|
||||
<div class="value flex">
|
||||
<countup :end-val="scenicStore.carShipData.ship.count?.drivingCount" />
|
||||
<span class="suffix">辆</span>
|
||||
<span class="suffix">只</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="car-item">
|
||||
@@ -303,7 +303,11 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<BigCarShipMap v-model="show" />
|
||||
<big-car-ship-map
|
||||
v-model="show"
|
||||
:carList="scenicStore.carShipData.car.list"
|
||||
:shipList="scenicStore.carShipData.ship.list"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -319,6 +323,8 @@
|
||||
import { useMap } from '@/hooks/map'
|
||||
import { useScenicStore } from '@/stores/scenic'
|
||||
|
||||
import PubSub from 'pubsub-js'
|
||||
|
||||
const scenicStore = useScenicStore()
|
||||
const { initMap, addMarker } = useMap()
|
||||
|
||||
@@ -372,17 +378,22 @@
|
||||
})
|
||||
|
||||
let show = ref(false)
|
||||
let scenicChange = null
|
||||
|
||||
watch(
|
||||
() => scenicStore.carShipData,
|
||||
(val) => {
|
||||
if (val.car.list.length > 0) {
|
||||
if (val.car.list.length) {
|
||||
setTimeout(() => {
|
||||
val.car.list.map((item) => {
|
||||
addMarker(carIcon, [109.551419, 31.050001], [36, 50])
|
||||
addMarker(carIcon, [item.lng, item.lat], [36, 50])
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
if (val.ship.list.length) {
|
||||
setTimeout(() => {
|
||||
val.ship.list.map((item) => {
|
||||
addMarker(shipIcon, [109.551671, 31.04847], [36, 50])
|
||||
addMarker(shipIcon, [item.lng, item.lat], [36, 50])
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
@@ -391,7 +402,12 @@
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
initMap('car-ship', 109.552461, 31.049607, 15)
|
||||
scenicChange = PubSub.subscribe('scenicChange', (msg, data) => {
|
||||
initMap('car-ship', data.lng, data.lat, 15)
|
||||
})
|
||||
})
|
||||
onUnmounted(() => {
|
||||
PubSub.unsubscribe(scenicChange)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -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