feat: 细化设备树自动定位的触发条件

- 添加 `hasFromPage` 属性,辅助区分选择设备的来源是用户操作还是路由参数
This commit is contained in:
yangsy
2025-12-18 22:01:15 +08:00
parent d0b065d6ba
commit eb0ee841cf
2 changed files with 14 additions and 6 deletions

View File

@@ -46,6 +46,7 @@ const {
selectedStationCode, selectedStationCode,
selectedDeviceType, selectedDeviceType,
selectedDevice, selectedDevice,
hasFromPage,
selectDevice, selectDevice,
routeDevice, routeDevice,
// 设备管理 // 设备管理
@@ -460,12 +461,15 @@ const onLocateDeviceTree = async () => {
animated.value = true; animated.value = true;
}; };
// 渲染全线设备树时,若是首次选择设备,则定位设备树 // 渲染全线设备树时,若是首次经过路由跳转而来选择设备,则定位设备树
const unwatch = watch(selectedDevice, async (newDevice, oldDevice) => { const unwatchLocate = watch(selectedDevice, async (newDevice, oldDevice) => {
if (!!station.value) return; if (!!station.value) return;
if (!!newDevice && !oldDevice && !!deviceTreeInst.value) { if (!hasFromPage.value) return;
await onLocateDeviceTree(); if (!!newDevice && !oldDevice) {
unwatch(); if (!!deviceTreeInst.value) {
await onLocateDeviceTree();
unwatchLocate();
}
} }
}); });
</script> </script>

View File

@@ -3,7 +3,7 @@ import { tryGetDeviceType, type DeviceType } from '@/enums';
import { useDeviceStore } from '@/stores'; import { useDeviceStore } from '@/stores';
import { watchDebounced } from '@vueuse/core'; import { watchDebounced } from '@vueuse/core';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { onMounted, ref, watch } from 'vue'; import { computed, onMounted, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
export const useDeviceSelection = () => { export const useDeviceSelection = () => {
@@ -17,6 +17,8 @@ export const useDeviceSelection = () => {
const selectedDeviceType = ref<DeviceType>(); const selectedDeviceType = ref<DeviceType>();
const selectedDevice = ref<NdmDeviceResultVO>(); const selectedDevice = ref<NdmDeviceResultVO>();
const hasFromPage = computed(() => !!route.query['fromPage']);
const initFromRoute = (lineDevices: LineDevices) => { const initFromRoute = (lineDevices: LineDevices) => {
const { stationCode, deviceType, deviceDbId } = route.query; const { stationCode, deviceType, deviceDbId } = route.query;
if (stationCode) { if (stationCode) {
@@ -105,6 +107,8 @@ export const useDeviceSelection = () => {
selectedDeviceType, selectedDeviceType,
selectedDevice, selectedDevice,
hasFromPage,
initFromRoute, initFromRoute,
selectDevice, selectDevice,
routeDevice, routeDevice,