feat(area-detail-card): 为门区域详情卡片添加设备名称显示,通过查询设备映射列表并监听区域变化实现,以提供更直观的设备信息

This commit is contained in:
xudan 2025-12-01 15:13:40 +08:00
parent 22cf89f7e9
commit 8fdd3c3a89

View File

@ -1,9 +1,10 @@
<script setup lang="ts">
import { type DeviceMappingDTO, queryDeviceMappingByType } from '@api/device';
import { type MapAreaInfo, MapAreaType, type MapPen, MapPointType } from '@api/map';
import { DOOR_AREA_TYPE } from '@api/map/door-area';
import type { EditorService } from '@core/editor.service';
import sTheme from '@core/theme.service';
import { computed, inject, type InjectionKey, type ShallowRef } from 'vue';
import { computed, inject, type InjectionKey, ref, type ShallowRef,watch } from 'vue';
type Props = {
token: InjectionKey<ShallowRef<EditorService>>;
@ -73,6 +74,38 @@ const ruleText = computed(() => {
return '';
});
//
const deviceMappings = ref<DeviceMappingDTO[]>([]);
// ID
const getDeviceName = computed(() => {
if (!area.value?.doorDeviceId || !deviceMappings.value.length) return '';
const device = deviceMappings.value.find(d => d.id === area.value?.doorDeviceId);
return device?.deviceUniqueName || '';
});
//
const fetchDeviceMappings = async () => {
if (!area.value || (area.value.type as any) !== DOOR_AREA_TYPE) return;
try {
//
const deviceType = '1'; // "1"
deviceMappings.value = await queryDeviceMappingByType(deviceType);
} catch (error) {
console.error('获取设备映射失败:', error);
deviceMappings.value = [];
}
};
//
watch(area, (newArea) => {
if (newArea && (newArea.type as any) === DOOR_AREA_TYPE && newArea.doorDeviceId) {
fetchDeviceMappings();
}
}, { immediate: true });
//
</script>
@ -119,6 +152,12 @@ const ruleText = computed(() => {
<a-typography-text>{{ area.doorDeviceId || $t('无') }}</a-typography-text>
</a-flex>
</a-list-item>
<a-list-item v-if="area && (area.type as any) === DOOR_AREA_TYPE && getDeviceName">
<a-flex :gap="8" vertical>
<a-typography-text type="secondary">{{ $t('设备名称') }}</a-typography-text>
<a-typography-text>{{ getDeviceName }}</a-typography-text>
</a-flex>
</a-list-item>
<a-list-item v-if="area && (area.type as any) === DOOR_AREA_TYPE">
<a-flex :gap="8" vertical>
<a-typography-text type="secondary">{{ $t('连接状态') }}</a-typography-text>