From 1038b701ee870288c7cbd4afb323a1d2f893932e Mon Sep 17 00:00:00 2001 From: hwj Date: Wed, 28 Jan 2026 18:12:45 +0800 Subject: [PATCH] =?UTF-8?q?style=EF=BC=9A=E9=87=87=E9=9B=86=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=A8=A1=E5=9E=8B/=E9=87=87=E9=9B=86=E8=AE=BE?= =?UTF-8?q?=E5=A4=87-=E6=B7=BB=E5=8A=A0=E7=82=B9=E4=BD=8D=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=90=8D=E7=A7=B0=E5=AD=97=E6=AE=B5=E5=85=A5=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/components/DeviceAttributeForm.vue | 27 ++++++++--- .../components/DeviceModelAttributeForm.vue | 47 ++++++++++++++----- .../dashboard1/components/EnergyMonitor.vue | 4 -- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/views/iot/device/components/DeviceAttributeForm.vue b/src/views/iot/device/components/DeviceAttributeForm.vue index a79719a6..8995dc5c 100644 --- a/src/views/iot/device/components/DeviceAttributeForm.vue +++ b/src/views/iot/device/components/DeviceAttributeForm.vue @@ -24,8 +24,9 @@ clearable filterable placeholder="请选择点位类型" + @change="handleAttributeTypeChange" > - + @@ -95,7 +96,8 @@ const formData = ref({ id: undefined as number | undefined, attributeCode: undefined as string | undefined, attributeName: undefined as string | undefined, - attributeType: undefined as string | undefined, + attributeType: undefined as number | undefined, + typeName: undefined as string | undefined, dataType: undefined as string | undefined, address: undefined as string | undefined, dataUnit: undefined as string | undefined, @@ -140,6 +142,13 @@ const handleSortInput = (val: string) => { formData.value.sort = val?.replace(/\D/g, '') } +const handleAttributeTypeChange = (val: number | string) => { + const matched = typeList.value.find( + (item) => item.id === val || String(item.id) === String(val) + ) + formData.value.typeName = matched?.name +} + const formRules = reactive({ attributeCode: [ { required: true, message: '点位编码不能为空', trigger: 'blur' }, @@ -196,6 +205,7 @@ const buildSubmitData = () => { attributeCode, attributeName, attributeType, + typeName, dataType, address, dataUnit, @@ -215,6 +225,7 @@ const buildSubmitData = () => { attributeCode, attributeName, attributeType, + typeName, dataType, address, dataUnit, @@ -255,13 +266,14 @@ const open = async (type: string, id?: number, deviceId: number) => { if (currentType !== undefined && currentType !== null && currentType !== '') { const matched = typeList.value.find( (item) => - item.name === currentType || item.id === currentType || - item.code === currentType || - String(item.id) === String(currentType) + String(item.id) === String(currentType) || + item.name === currentType || + item.code === currentType ) - if (matched?.name) { - ;(formData.value as any).attributeType = matched.name + if (matched) { + ;(formData.value as any).attributeType = matched.id + ;(formData.value as any).typeName = matched.name } } } finally { @@ -302,6 +314,7 @@ const resetForm = () => { attributeCode: undefined, attributeName: undefined, attributeType: undefined, + typeName: undefined, dataType: undefined, address: undefined, dataUnit: undefined, diff --git a/src/views/iot/devicemodel/components/DeviceModelAttributeForm.vue b/src/views/iot/devicemodel/components/DeviceModelAttributeForm.vue index 8507f20e..665d0079 100644 --- a/src/views/iot/devicemodel/components/DeviceModelAttributeForm.vue +++ b/src/views/iot/devicemodel/components/DeviceModelAttributeForm.vue @@ -20,6 +20,7 @@ filterable placeholder="请选择点位类型" class="!w-180px" + @change="handleAttributeTypeChange" > @@ -92,17 +93,18 @@ const dialogTitle = ref('') // 弹窗的标题 const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 const formType = ref('') // 表单的类型:create - 新增;update - 修改 const formData = ref({ - id: undefined, - attributeCode: undefined, - attributeName: undefined, - attributeType: undefined, - dataType: undefined, - address: undefined, - dataUnit: undefined, - ratio: undefined, - remark: undefined, - deviceModelId: undefined, -}) + id: undefined, + attributeCode: undefined, + attributeName: undefined, + attributeType: undefined, + typeName: undefined, + dataType: undefined, + address: undefined, + dataUnit: undefined, + ratio: undefined, + remark: undefined, + deviceModelId: undefined, + }) const formRules = reactive({ attributeCode: [{ required: true, message: '点位编码不能为空', trigger: 'blur' }], attributeName: [{ required: true, message: '点位名称不能为空', trigger: 'blur' }], @@ -122,6 +124,21 @@ const open = async (type: string, id: number, modelId: number) => { formLoading.value = true try { formData.value = await DeviceModelAttributeApi.getDeviceModelAttribute(id) + + const currentType = (formData.value as any)?.attributeType + if (currentType !== undefined && currentType !== null && currentType !== '') { + const matched = typeList.value.find( + (item) => + item.id === currentType || + String(item.id) === String(currentType) || + item.name === currentType || + item.code === currentType + ) + if (matched) { + ;(formData.value as any).attributeType = matched.id + ;(formData.value as any).typeName = matched.name + } + } } finally { formLoading.value = false } @@ -153,6 +170,13 @@ const submitForm = async () => { } } +const handleAttributeTypeChange = (val: number | string) => { + const matched = typeList.value.find( + (item) => item.id === val || String(item.id) === String(val) + ) + ;(formData.value as any).typeName = matched?.name +} + /** 重置表单 */ const resetForm = () => { formData.value = { @@ -160,6 +184,7 @@ const resetForm = () => { attributeCode: undefined, attributeName: undefined, attributeType: undefined, + typeName: undefined, dataType: undefined, address: undefined, dataUnit: undefined, diff --git a/src/views/report/dashboardPage/dashboard1/components/EnergyMonitor.vue b/src/views/report/dashboardPage/dashboard1/components/EnergyMonitor.vue index be2ee70a..ca8d9afa 100644 --- a/src/views/report/dashboardPage/dashboard1/components/EnergyMonitor.vue +++ b/src/views/report/dashboardPage/dashboard1/components/EnergyMonitor.vue @@ -93,10 +93,6 @@ const render = (data: any = []) => { x = [] y = [] } - - // 如果没有数据,使用模拟数据防止图表空白(可选,或者显示暂无数据) - // 为了演示效果,如果API没通,可以保留之前的mock作为fallback吗? - // 用户明确要求对接接口,所以尽量用接口数据。如果为空,就显示空。 chart.setOption({ backgroundColor: 'transparent',