diff --git a/src/views/iot/device/management/index.vue b/src/views/iot/device/management/index.vue
index fb2a701..fdb0f88 100644
--- a/src/views/iot/device/management/index.vue
+++ b/src/views/iot/device/management/index.vue
@@ -292,7 +292,7 @@
- {{ m.value || '-' }}
+ {{ m.addressValue || '-' }}
{{ m.dataUnit || '' }}
@@ -313,12 +313,12 @@
+ 查询
- 查询
-
+
曲线
列表
- 导出
+ 导出
@@ -843,14 +842,30 @@ const historyViewType = ref<'chart' | 'list'>('chart')
const historyList = ref([])
const historyLoading = ref(false)
+const parseHistoryTime = (timeText?: string) => {
+ if (!timeText) return { display: '-', timestamp: 0 }
+ const raw = String(timeText).trim()
+ const shortYearMatch = raw.match(/^(\d{2})-(\d{2})-(\d{2})\s+(\d{2}:\d{2}:\d{2})$/)
+ if (shortYearMatch) {
+ const [, yy, mm, dd, hms] = shortYearMatch
+ const isoText = `20${yy}-${mm}-${dd}T${hms}`
+ const timestamp = new Date(isoText).getTime()
+ return { display: raw, timestamp: Number.isNaN(timestamp) ? 0 : timestamp }
+ }
+ const timestamp = new Date(raw).getTime()
+ return { display: raw, timestamp: Number.isNaN(timestamp) ? 0 : timestamp }
+}
+
const loadHistoryMetrics = async () => {
if (!selectedDeviceDetail.value?.id) return
try {
const list = await DeviceApi.getDeviceAttributeList(selectedDeviceDetail.value.id)
historyMetricOptions.value = Array.isArray(list) ? list : []
- if (historyMetricOptions.value.length > 0 && !historyMetricKey.value) {
- historyMetricKey.value =
- historyMetricOptions.value[0].attributeCode || historyMetricOptions.value[0].attributeName
+ const hasCurrent = historyMetricOptions.value.some(
+ (item) => Number(item.id) === Number(historyMetricKey.value)
+ )
+ if (historyMetricOptions.value.length > 0 && !hasCurrent) {
+ historyMetricKey.value = historyMetricOptions.value[0].id
}
} catch (e) {
console.error(e)
@@ -859,11 +874,18 @@ const loadHistoryMetrics = async () => {
const loadHistoryData = async () => {
if (!selectedDeviceDetail.value?.id) return
+ if (!historyMetricOptions.value.length) {
+ await loadHistoryMetrics()
+ }
+ if (!historyMetricOptions.value.length) return
+ if (!historyMetricKey.value) {
+ historyMetricKey.value = historyMetricOptions.value[0].id
+ }
historyLoading.value = true
try {
const params: any = {
deviceId: selectedDeviceDetail.value.id,
- modelId: selectedDeviceDetail.value.deviceModelId
+ modelId: Number(historyMetricKey.value)
}
if (historyTimeRange.value && historyTimeRange.value.length === 2) {
params.collectionStartTime = historyTimeRange.value[0]
@@ -872,14 +894,18 @@ const loadHistoryData = async () => {
const res = await DeviceModelAttributeApi.operationAnalysisDetails(params)
let data = Array.isArray(res) ? res : res?.list || []
- // Convert property names if necessary, assuming common names like createTime/time, addressValue/value, etc.
- historyList.value = data.map((item: any) => ({
- ...item,
- time: item.time || item.createTime || item.collectionTime,
- value: item.value || item.addressValue || item.dataValue,
- attributeName: item.attributeName || item.parameter || item.name,
- unit: item.unit || item.dataUnit || ''
- }))
+ historyList.value = data.map((item: any) => {
+ const timeRaw = item.collectTime || item.time || item.createTime || item.collectionTime
+ const parsedTime = parseHistoryTime(timeRaw)
+ return {
+ ...item,
+ time: parsedTime.display,
+ timeValue: parsedTime.timestamp,
+ value: item.addressValue ?? item.value ?? item.dataValue ?? '-',
+ attributeName: item.attributeName || item.parameter || item.name,
+ unit: item.dataUnit || item.unit || ''
+ }
+ })
} catch (e) {
console.error(e)
} finally {
@@ -888,27 +914,16 @@ const loadHistoryData = async () => {
}
const historyChartOptions = computed(() => {
- let data = historyList.value
- if (historyMetricKey.value) {
- data = data.filter(
- (item) =>
- item.attributeCode === historyMetricKey.value ||
- item.attributeName === historyMetricKey.value
- )
- }
-
// Sort by time ascending for chart
- const sortedData = [...data].sort(
- (a, b) => new Date(a.time).getTime() - new Date(b.time).getTime()
+ const sortedData = [...historyList.value].sort(
+ (a, b) => Number(a.timeValue || 0) - Number(b.timeValue || 0)
)
- const labels = sortedData.map((item) => formatDate(item.time))
+ const labels = sortedData.map((item) => item.time || '-')
const values = sortedData.map((item) => Number(item.value) || 0)
const metricName =
- historyMetricOptions.value.find(
- (m) =>
- m.attributeCode === historyMetricKey.value || m.attributeName === historyMetricKey.value
- )?.attributeName || '数据'
+ historyMetricOptions.value.find((m) => Number(m.id) === Number(historyMetricKey.value))
+ ?.attributeName || '数据'
return {
grid: { left: 20, right: 20, bottom: 20, top: 40, containLabel: true },
@@ -933,10 +948,10 @@ const historyChartOptions = computed(() => {
}
})
-watch([() => activeTab.value, () => selectedDeviceDetail.value.id], ([tab, deviceId]) => {
+watch([() => activeTab.value, () => selectedDeviceDetail.value.id], async ([tab, deviceId]) => {
if (tab === 'history' && deviceId) {
- loadHistoryMetrics()
- loadHistoryData()
+ await loadHistoryMetrics()
+ await loadHistoryData()
}
})