|
|
@@ -24,6 +24,7 @@ const getProjectId = () => {
|
|
|
type DevicePointData = {
|
|
|
identifier?: string
|
|
|
value?: unknown
|
|
|
+ unit?: string
|
|
|
}
|
|
|
|
|
|
const setPreviewData = async (dataModel: unknown) => {
|
|
|
@@ -37,7 +38,11 @@ const setPreviewData = async (dataModel: unknown) => {
|
|
|
}
|
|
|
|
|
|
const getDeviceBindItems = () => {
|
|
|
- return (previewData.value?.json || []).flatMap((item) =>
|
|
|
+ const previewItems = previewData.value?.pages?.length
|
|
|
+ ? previewData.value.pages.flatMap((page) => page.json)
|
|
|
+ : previewData.value?.json || []
|
|
|
+
|
|
|
+ return previewItems.flatMap((item) =>
|
|
|
(item.deviceBinds || [])
|
|
|
.filter((bind) => bind.deviceId && bind.deviceProp && bind.nodeProp)
|
|
|
.map((bind) => ({
|
|
|
@@ -49,6 +54,13 @@ const getDeviceBindItems = () => {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+const formatDevicePointValue = (item: DevicePointData) => {
|
|
|
+ if (!item.unit) {
|
|
|
+ return item.value
|
|
|
+ }
|
|
|
+ return `${item.value ?? ''} ${item.unit}`
|
|
|
+}
|
|
|
+
|
|
|
const refreshDeviceBindValues = async () => {
|
|
|
if (polling.value) {
|
|
|
return
|
|
|
@@ -72,7 +84,7 @@ const refreshDeviceBindValues = async () => {
|
|
|
deviceDataList.forEach(({ deviceId, data }) => {
|
|
|
data.forEach((item) => {
|
|
|
if (item.identifier) {
|
|
|
- valueMap.set(`${deviceId}:${item.identifier}`, item.value)
|
|
|
+ valueMap.set(`${deviceId}:${item.identifier}`, formatDevicePointValue(item))
|
|
|
}
|
|
|
})
|
|
|
})
|