refactor: 简化设备树的自动定位逻辑

This commit is contained in:
yangsy
2025-12-24 00:19:36 +08:00
parent 7f07725935
commit 4eb2a2ab3d
2 changed files with 5 additions and 15 deletions

View File

@@ -46,7 +46,6 @@ const {
selectedStationCode, selectedStationCode,
selectedDeviceType, selectedDeviceType,
selectedDevice, selectedDevice,
hasFromPage,
selectDevice, selectDevice,
routeDevice, routeDevice,
// 设备管理 // 设备管理
@@ -461,16 +460,11 @@ const onLocateDeviceTree = async () => {
animated.value = true; animated.value = true;
}; };
// 渲染全线设备树时,若是首次经过路由跳转而来选择设备,则定位设备树 // 渲染全线设备树时,选择设备发生变化,则定位设备树
const unwatchLocate = watch(selectedDevice, async (newDevice, oldDevice) => { // 暂时不考虑多次执行的问题,因为当选择的设备在设备树视口内时,不会发生滚动
watch(selectedDevice, async () => {
if (!!station.value) return; if (!!station.value) return;
if (!hasFromPage.value) return; await onLocateDeviceTree();
if (!!newDevice && !oldDevice) {
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 { computed, onMounted, ref, watch } from 'vue'; import { onMounted, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
export const useDeviceSelection = () => { export const useDeviceSelection = () => {
@@ -17,8 +17,6 @@ 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) {
@@ -107,8 +105,6 @@ export const useDeviceSelection = () => {
selectedDeviceType, selectedDeviceType,
selectedDevice, selectedDevice,
hasFromPage,
initFromRoute, initFromRoute,
selectDevice, selectDevice,
routeDevice, routeDevice,