feat:【IoT 物联网】物模型数据使用 NVARCHAR 存储,并兼容 struct、array 等数据结构

pull/789/MERGE
YunaiV 2025-06-29 17:09:27 +08:00
parent 4af1875001
commit 1281ff62ba
3 changed files with 39 additions and 10 deletions

View File

@ -89,7 +89,7 @@
<!-- 数据图标 - 可点击 --> <!-- 数据图标 - 可点击 -->
<div <div
class="cursor-pointer flex items-center justify-center w-8 h-8 rounded-full hover:bg-blue-50 transition-colors" class="cursor-pointer flex items-center justify-center w-8 h-8 rounded-full hover:bg-blue-50 transition-colors"
@click="openHistory(props.deviceId, item.identifier)" @click="openHistory(props.deviceId, item.identifier, item.dataType)"
> >
<Icon icon="ep:data-line" class="text-[18px] text-[#0070ff]" /> <Icon icon="ep:data-line" class="text-[18px] text-[#0070ff]" />
</div> </div>
@ -135,7 +135,11 @@
/> />
<el-table-column label="操作" align="center"> <el-table-column label="操作" align="center">
<template #default="scope"> <template #default="scope">
<el-button link type="primary" @click="openHistory(props.deviceId, scope.row.identifier)"> <el-button
link
type="primary"
@click="openHistory(props.deviceId, scope.row.identifier, scope.row.dataType)"
>
查看数据 查看数据
</el-button> </el-button>
</template> </template>
@ -202,8 +206,8 @@ const handleQuery = () => {
/** 历史操作 */ /** 历史操作 */
const historyRef = ref() const historyRef = ref()
const openHistory = (deviceId: number, identifier: string) => { const openHistory = (deviceId: number, identifier: string, dataType: string) => {
historyRef.value.open(deviceId, identifier) historyRef.value.open(deviceId, identifier, dataType)
} }
/** 格式化属性值和单位 */ /** 格式化属性值和单位 */

View File

@ -27,6 +27,7 @@
<el-button <el-button
:type="viewMode === 'chart' ? 'primary' : 'default'" :type="viewMode === 'chart' ? 'primary' : 'default'"
@click="viewMode = 'chart'" @click="viewMode = 'chart'"
:disabled="isComplexDataType"
> >
<Icon icon="ep:histogram" /> <Icon icon="ep:histogram" />
</el-button> </el-button>
@ -57,7 +58,11 @@
{{ formatDate(new Date(scope.row.updateTime)) }} {{ formatDate(new Date(scope.row.updateTime)) }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="属性值" align="center" prop="value" /> <el-table-column label="属性值" align="center" prop="value">
<template #default="scope">
{{ scope.row.value }}
</template>
</el-table-column>
</el-table> </el-table>
</div> </div>
</ContentWrap> </ContentWrap>
@ -67,6 +72,7 @@
import { DeviceApi, IotDevicePropertyRespVO } from '@/api/iot/device/device' import { DeviceApi, IotDevicePropertyRespVO } from '@/api/iot/device/device'
import { beginOfDay, defaultShortcuts, endOfDay, formatDate } from '@/utils/formatTime' import { beginOfDay, defaultShortcuts, endOfDay, formatDate } from '@/utils/formatTime'
import { Echart } from '@/components/Echart' import { Echart } from '@/components/Echart'
import { IoTDataSpecsDataTypeEnum } from '@/views/iot/utils/constants'
defineProps<{ deviceId: number }>() defineProps<{ deviceId: number }>()
@ -78,6 +84,7 @@ const loading = ref(false)
const viewMode = ref<'chart' | 'list'>('chart') // const viewMode = ref<'chart' | 'list'>('chart') //
const list = ref<IotDevicePropertyRespVO[]>([]) // const list = ref<IotDevicePropertyRespVO[]>([]) //
const chartKey = ref(0) // key const chartKey = ref(0) // key
const thingModelDataType = ref<string>('') //
const queryParams = reactive({ const queryParams = reactive({
deviceId: -1, deviceId: -1,
identifier: '', identifier: '',
@ -89,6 +96,14 @@ const queryParams = reactive({
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
// struct array
const isComplexDataType = computed(() => {
if (!thingModelDataType.value) return false
return [IoTDataSpecsDataTypeEnum.STRUCT, IoTDataSpecsDataTypeEnum.ARRAY].includes(
thingModelDataType.value as any
)
})
// Echarts // Echarts
const echartsData = computed(() => { const echartsData = computed(() => {
if (!list.value || list.value.length === 0) return [] if (!list.value || list.value.length === 0) return []
@ -165,15 +180,24 @@ const getList = async () => {
} }
/** 打开弹窗 */ /** 打开弹窗 */
const open = async (deviceId: number, identifier: string) => { const open = async (deviceId: number, identifier: string, dataType: string) => {
dialogVisible.value = true dialogVisible.value = true
queryParams.deviceId = deviceId queryParams.deviceId = deviceId
queryParams.identifier = identifier queryParams.identifier = identifier
// key thingModelDataType.value = dataType
// structarray使 list
if (isComplexDataType.value) {
viewMode.value = 'list'
} else {
viewMode.value = 'chart'
}
// key
chartKey.value = 0 chartKey.value = 0
// //
await nextTick() await nextTick()
getList() await getList()
} }
/** 时间变化处理 */ /** 时间变化处理 */

View File

@ -153,9 +153,10 @@ const submitForm = async () => {
await ThingModelApi.updateThingModel(data) await ThingModelApi.updateThingModel(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
} finally { //
dialogVisible.value = false // dialogVisible.value = false
emit('success') emit('success')
} finally {
formLoading.value = false formLoading.value = false
} }
} }