From eb0ee841cfabfa203072d55a8e8e1c1c5eeb1d6b Mon Sep 17 00:00:00 2001 From: yangsy Date: Thu, 18 Dec 2025 22:01:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=86=E5=8C=96=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E6=A0=91=E8=87=AA=E5=8A=A8=E5=AE=9A=E4=BD=8D=E7=9A=84=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 `hasFromPage` 属性,辅助区分选择设备的来源是用户操作还是路由参数 --- src/components/device/device-tree/device-tree.vue | 14 +++++++++----- src/composables/device/use-device-selection.ts | 6 +++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/components/device/device-tree/device-tree.vue b/src/components/device/device-tree/device-tree.vue index 966d818..6248738 100644 --- a/src/components/device/device-tree/device-tree.vue +++ b/src/components/device/device-tree/device-tree.vue @@ -46,6 +46,7 @@ const { selectedStationCode, selectedDeviceType, selectedDevice, + hasFromPage, selectDevice, routeDevice, // 设备管理 @@ -460,12 +461,15 @@ const onLocateDeviceTree = async () => { animated.value = true; }; -// 渲染全线设备树时,若是首次选择设备,则定位设备树 -const unwatch = watch(selectedDevice, async (newDevice, oldDevice) => { +// 渲染全线设备树时,若是首次经过路由跳转而来选择设备,则定位设备树 +const unwatchLocate = watch(selectedDevice, async (newDevice, oldDevice) => { if (!!station.value) return; - if (!!newDevice && !oldDevice && !!deviceTreeInst.value) { - await onLocateDeviceTree(); - unwatch(); + if (!hasFromPage.value) return; + if (!!newDevice && !oldDevice) { + if (!!deviceTreeInst.value) { + await onLocateDeviceTree(); + unwatchLocate(); + } } }); diff --git a/src/composables/device/use-device-selection.ts b/src/composables/device/use-device-selection.ts index dd1319b..d8e88bb 100644 --- a/src/composables/device/use-device-selection.ts +++ b/src/composables/device/use-device-selection.ts @@ -3,7 +3,7 @@ import { tryGetDeviceType, type DeviceType } from '@/enums'; import { useDeviceStore } from '@/stores'; import { watchDebounced } from '@vueuse/core'; import { storeToRefs } from 'pinia'; -import { onMounted, ref, watch } from 'vue'; +import { computed, onMounted, ref, watch } from 'vue'; import { useRoute, useRouter } from 'vue-router'; export const useDeviceSelection = () => { @@ -17,6 +17,8 @@ export const useDeviceSelection = () => { const selectedDeviceType = ref(); const selectedDevice = ref(); + const hasFromPage = computed(() => !!route.query['fromPage']); + const initFromRoute = (lineDevices: LineDevices) => { const { stationCode, deviceType, deviceDbId } = route.query; if (stationCode) { @@ -105,6 +107,8 @@ export const useDeviceSelection = () => { selectedDeviceType, selectedDevice, + hasFromPage, + initFromRoute, selectDevice, routeDevice,