feat: 扩展设备树功能
- 支持控制是否同步路由参数 - 支持配置允许的事件类型 (select/manage) - 支持自定义设备节点前缀按钮文字 - 支持向外暴露设备选择逻辑 - 不再封装跳转设备逻辑,由外部实现 - 在车站模式下也支持选择设备
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import type { Station } from '@/apis';
|
||||
import { DeviceTree } from '@/components';
|
||||
import { DeviceTree, type DeviceTreeProps } from '@/components';
|
||||
import { tryGetDeviceType } from '@/enums';
|
||||
import { NModal } from 'naive-ui';
|
||||
import { toRefs } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
|
||||
const props = defineProps<{
|
||||
station?: Station;
|
||||
@@ -10,13 +12,30 @@ const props = defineProps<{
|
||||
|
||||
const show = defineModel<boolean>('show', { default: false });
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const { station } = toRefs(props);
|
||||
|
||||
const onAfterSelectDevice: DeviceTreeProps['onAfterSelectDevice'] = (device, stationCode) => {
|
||||
const deviceDbId = device.id;
|
||||
const deviceType = tryGetDeviceType(device.deviceType);
|
||||
router.push({
|
||||
path: '/device',
|
||||
query: {
|
||||
stationCode,
|
||||
deviceType,
|
||||
deviceDbId,
|
||||
fromPage: route.path,
|
||||
},
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NModal v-model:show="show" preset="card" style="width: 600px; height: 600px" :title="`${station?.name} - 设备详情`" :content-style="{ height: '100%', overflow: 'hidden' }">
|
||||
<template #default>
|
||||
<DeviceTree :station="station" />
|
||||
<DeviceTree :station="station" :events="['select', 'manage']" :device-prefix-label="'查看'" @after-select-device="onAfterSelectDevice" />
|
||||
</template>
|
||||
</NModal>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user