|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+<template>
|
|
|
2
|
+ <div class="device-detail">
|
|
|
3
|
+ <!-- 顶部信息栏 -->
|
|
|
4
|
+ <el-page-header @back="router.back()" style="margin-bottom: 20px">
|
|
|
5
|
+ <template #content>
|
|
|
6
|
+ <span class="page-title">{{ device.deviceName || '设备详情' }}</span>
|
|
|
7
|
+ <el-tag :type="statusTag(device.status)" size="large" style="margin-left: 12px">
|
|
|
8
|
+ {{ statusLabel(device.status) }}
|
|
|
9
|
+ </el-tag>
|
|
|
10
|
+ </template>
|
|
|
11
|
+ <template #extra>
|
|
|
12
|
+ <el-button type="warning" v-if="device.status !== 'disabled'" @click="handleDisable">禁用设备</el-button>
|
|
|
13
|
+ <el-button type="success" v-else @click="handleEnable">启用设备</el-button>
|
|
|
14
|
+ <el-button type="primary" @click="triggerOta">OTA 升级</el-button>
|
|
|
15
|
+ </template>
|
|
|
16
|
+ </el-page-header>
|
|
|
17
|
+
|
|
|
18
|
+ <!-- 基本信息卡片 -->
|
|
|
19
|
+ <el-row :gutter="16" style="margin-bottom: 20px">
|
|
|
20
|
+ <el-col :span="6">
|
|
|
21
|
+ <el-card shadow="hover" class="info-card">
|
|
|
22
|
+ <div class="info-item">
|
|
|
23
|
+ <span class="info-label">设备编号</span>
|
|
|
24
|
+ <span class="info-value">{{ device.deviceCode }}</span>
|
|
|
25
|
+ </div>
|
|
|
26
|
+ <div class="info-item">
|
|
|
27
|
+ <span class="info-label">设备类型</span>
|
|
|
28
|
+ <span class="info-value">{{ deviceTypeLabel(device.deviceType) }}</span>
|
|
|
29
|
+ </div>
|
|
|
30
|
+ </el-card>
|
|
|
31
|
+ </el-col>
|
|
|
32
|
+ <el-col :span="6">
|
|
|
33
|
+ <el-card shadow="hover" class="info-card">
|
|
|
34
|
+ <div class="info-item">
|
|
|
35
|
+ <span class="info-label">固件版本</span>
|
|
|
36
|
+ <span class="info-value">{{ device.firmwareVersion }}</span>
|
|
|
37
|
+ </div>
|
|
|
38
|
+ <div class="info-item">
|
|
|
39
|
+ <span class="info-label">最后在线</span>
|
|
|
40
|
+ <span class="info-value">{{ device.lastOnlineTime || '-' }}</span>
|
|
|
41
|
+ </div>
|
|
|
42
|
+ </el-card>
|
|
|
43
|
+ </el-col>
|
|
|
44
|
+ <el-col :span="6">
|
|
|
45
|
+ <el-card shadow="hover" class="info-card">
|
|
|
46
|
+ <div class="info-item">
|
|
|
47
|
+ <span class="info-label">安装位置</span>
|
|
|
48
|
+ <span class="info-value">{{ device.location || '-' }}</span>
|
|
|
49
|
+ </div>
|
|
|
50
|
+ <div class="info-item">
|
|
|
51
|
+ <span class="info-label">坐标</span>
|
|
|
52
|
+ <span class="info-value">{{ device.latitude?.toFixed(4) }}, {{ device.longitude?.toFixed(4) }}</span>
|
|
|
53
|
+ </div>
|
|
|
54
|
+ </el-card>
|
|
|
55
|
+ </el-col>
|
|
|
56
|
+ <el-col :span="6">
|
|
|
57
|
+ <el-card shadow="hover" class="info-card">
|
|
|
58
|
+ <div class="info-item">
|
|
|
59
|
+ <span class="info-label">创建时间</span>
|
|
|
60
|
+ <span class="info-value">{{ device.createdAt }}</span>
|
|
|
61
|
+ </div>
|
|
|
62
|
+ <div class="info-item">
|
|
|
63
|
+ <span class="info-label">更新时间</span>
|
|
|
64
|
+ <span class="info-value">{{ device.updatedAt }}</span>
|
|
|
65
|
+ </div>
|
|
|
66
|
+ </el-card>
|
|
|
67
|
+ </el-col>
|
|
|
68
|
+ </el-row>
|
|
|
69
|
+
|
|
|
70
|
+ <!-- Tab 区域 -->
|
|
|
71
|
+ <el-card shadow="never">
|
|
|
72
|
+ <el-tabs v-model="activeTab" type="border-card">
|
|
|
73
|
+ <!-- 基本信息 Tab -->
|
|
|
74
|
+ <el-tab-pane label="基本信息" name="basic">
|
|
|
75
|
+ <el-descriptions :column="2" border>
|
|
|
76
|
+ <el-descriptions-item label="设备编号">{{ device.deviceCode }}</el-descriptions-item>
|
|
|
77
|
+ <el-descriptions-item label="设备名称">{{ device.deviceName }}</el-descriptions-item>
|
|
|
78
|
+ <el-descriptions-item label="设备类型">{{ deviceTypeLabel(device.deviceType) }}</el-descriptions-item>
|
|
|
79
|
+ <el-descriptions-item label="在线状态">
|
|
|
80
|
+ <el-tag :type="statusTag(device.status)">{{ statusLabel(device.status) }}</el-tag>
|
|
|
81
|
+ </el-descriptions-item>
|
|
|
82
|
+ <el-descriptions-item label="固件版本">{{ device.firmwareVersion }}</el-descriptions-item>
|
|
|
83
|
+ <el-descriptions-item label="最后在线时间">{{ device.lastOnlineTime || '-' }}</el-descriptions-item>
|
|
|
84
|
+ <el-descriptions-item label="安装位置">{{ device.location || '-' }}</el-descriptions-item>
|
|
|
85
|
+ <el-descriptions-item label="地理坐标">{{ device.latitude?.toFixed(6) }}, {{ device.longitude?.toFixed(6) }}</el-descriptions-item>
|
|
|
86
|
+ <el-descriptions-item label="创建时间">{{ device.createdAt }}</el-descriptions-item>
|
|
|
87
|
+ <el-descriptions-item label="更新时间">{{ device.updatedAt }}</el-descriptions-item>
|
|
|
88
|
+ <el-descriptions-item label="备注" :span="2">
|
|
|
89
|
+ {{ device.remark || '暂无备注' }}
|
|
|
90
|
+ </el-descriptions-item>
|
|
|
91
|
+ </el-descriptions>
|
|
|
92
|
+ </el-tab-pane>
|
|
|
93
|
+
|
|
|
94
|
+ <!-- 实时影子数据 Tab -->
|
|
|
95
|
+ <el-tab-pane label="实时影子数据" name="shadow">
|
|
|
96
|
+ <div style="margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center">
|
|
|
97
|
+ <span class="section-title">设备影子(Device Shadow)</span>
|
|
|
98
|
+ <el-button type="primary" size="small" @click="refreshShadow">
|
|
|
99
|
+ <el-icon><Refresh /></el-icon> 刷新
|
|
|
100
|
+ </el-button>
|
|
|
101
|
+ </div>
|
|
|
102
|
+
|
|
|
103
|
+ <el-row :gutter="16">
|
|
|
104
|
+ <el-col :span="12">
|
|
|
105
|
+ <el-card shadow="never" class="shadow-card">
|
|
|
106
|
+ <template #header>
|
|
|
107
|
+ <div class="card-header">
|
|
|
108
|
+ <span>上报状态(Reported)</span>
|
|
|
109
|
+ <el-tag type="success" size="small">实时</el-tag>
|
|
|
110
|
+ </div>
|
|
|
111
|
+ </template>
|
|
|
112
|
+ <el-descriptions :column="1" border size="small">
|
|
|
113
|
+ <el-descriptions-item v-for="(val, key) in shadow.reported" :key="key" :label="key">
|
|
|
114
|
+ <template v-if="typeof val === 'object'">
|
|
|
115
|
+ <pre style="margin: 0; font-size: 12px">{{ JSON.stringify(val, null, 2) }}</pre>
|
|
|
116
|
+ </template>
|
|
|
117
|
+ <template v-else>{{ val }}</template>
|
|
|
118
|
+ </el-descriptions-item>
|
|
|
119
|
+ </el-descriptions>
|
|
|
120
|
+ </el-card>
|
|
|
121
|
+ </el-col>
|
|
|
122
|
+ <el-col :span="12">
|
|
|
123
|
+ <el-card shadow="never" class="shadow-card">
|
|
|
124
|
+ <template #header>
|
|
|
125
|
+ <div class="card-header">
|
|
|
126
|
+ <span>期望状态(Desired)</span>
|
|
|
127
|
+ <el-button type="primary" size="small" link @click="showEditDesired = true">编辑</el-button>
|
|
|
128
|
+ </div>
|
|
|
129
|
+ </template>
|
|
|
130
|
+ <el-descriptions :column="1" border size="small">
|
|
|
131
|
+ <el-descriptions-item v-for="(val, key) in shadow.desired" :key="key" :label="key">
|
|
|
132
|
+ <template v-if="typeof val === 'object'">
|
|
|
133
|
+ <pre style="margin: 0; font-size: 12px">{{ JSON.stringify(val, null, 2) }}</pre>
|
|
|
134
|
+ </template>
|
|
|
135
|
+ <template v-else>{{ val }}</template>
|
|
|
136
|
+ </el-descriptions-item>
|
|
|
137
|
+ </el-descriptions>
|
|
|
138
|
+ </el-card>
|
|
|
139
|
+ </el-col>
|
|
|
140
|
+ </el-row>
|
|
|
141
|
+
|
|
|
142
|
+ <el-alert type="info" :closable="false" style="margin-top: 16px">
|
|
|
143
|
+ <template #title>影子数据说明</template>
|
|
|
144
|
+ 设备影子是云端维护的设备状态缓存,包含设备上报的实际状态(Reported)和云端期望的状态(Desired)。
|
|
|
145
|
+ 当设备离线时,可通过修改 Desired 状态实现离线指令缓存,设备上线后自动同步。
|
|
|
146
|
+ </el-alert>
|
|
|
147
|
+ </el-tab-pane>
|
|
|
148
|
+
|
|
|
149
|
+ <!-- OTA 升级历史 Tab -->
|
|
|
150
|
+ <el-tab-pane label="OTA 升级历史" name="ota">
|
|
|
151
|
+ <el-table :data="otaHistory" border style="width: 100%" v-loading="otaLoading">
|
|
|
152
|
+ <el-table-column prop="id" label="ID" width="60" />
|
|
|
153
|
+ <el-table-column prop="fromVersion" label="原版本" width="100" />
|
|
|
154
|
+ <el-table-column prop="toVersion" label="目标版本" width="100" />
|
|
|
155
|
+ <el-table-column prop="status" label="状态" width="100">
|
|
|
156
|
+ <template #default="{ row }">
|
|
|
157
|
+ <el-tag :type="otaStatusTag(row.status)" size="small">{{ otaStatusLabel(row.status) }}</el-tag>
|
|
|
158
|
+ </template>
|
|
|
159
|
+ </el-table-column>
|
|
|
160
|
+ <el-table-column prop="progress" label="进度" width="120">
|
|
|
161
|
+ <template #default="{ row }">
|
|
|
162
|
+ <el-progress :percentage="row.progress || 0" :status="row.status === 'success' ? 'success' : row.status === 'failed' ? 'exception' : ''" />
|
|
|
163
|
+ </template>
|
|
|
164
|
+ </el-table-column>
|
|
|
165
|
+ <el-table-column prop="errorMessage" label="错误信息" min-width="200" show-overflow-tooltip>
|
|
|
166
|
+ <template #default="{ row }">
|
|
|
167
|
+ <span v-if="row.errorMessage" style="color: #f56c6c">{{ row.errorMessage }}</span>
|
|
|
168
|
+ <span v-else>-</span>
|
|
|
169
|
+ </template>
|
|
|
170
|
+ </el-table-column>
|
|
|
171
|
+ <el-table-column prop="startTime" label="开始时间" width="170" />
|
|
|
172
|
+ <el-table-column prop="endTime" label="结束时间" width="170" />
|
|
|
173
|
+ </el-table>
|
|
|
174
|
+ <el-pagination style="margin-top: 12px; justify-content: flex-end"
|
|
|
175
|
+ v-model:current-page="otaPagination.page" v-model:page-size="otaPagination.size"
|
|
|
176
|
+ :total="otaPagination.total" :page-sizes="[10, 20]"
|
|
|
177
|
+ layout="total, sizes, prev, pager, next" @change="fetchOtaHistory" />
|
|
|
178
|
+ </el-tab-pane>
|
|
|
179
|
+
|
|
|
180
|
+ <!-- 操作日志 Tab -->
|
|
|
181
|
+ <el-tab-pane label="操作日志" name="logs">
|
|
|
182
|
+ <el-table :data="operationLogs" border style="width: 100%" v-loading="logsLoading">
|
|
|
183
|
+ <el-table-column prop="id" label="ID" width="60" />
|
|
|
184
|
+ <el-table-column prop="action" label="操作类型" width="120">
|
|
|
185
|
+ <template #default="{ row }">
|
|
|
186
|
+ <el-tag size="small">{{ logActionLabel(row.action) }}</el-tag>
|
|
|
187
|
+ </template>
|
|
|
188
|
+ </el-table-column>
|
|
|
189
|
+ <el-table-column prop="operator" label="操作人" width="120" />
|
|
|
190
|
+ <el-table-column prop="detail" label="详情" min-width="300" show-overflow-tooltip />
|
|
|
191
|
+ <el-table-column prop="createdAt" label="操作时间" width="170" />
|
|
|
192
|
+ </el-table>
|
|
|
193
|
+ <el-pagination style="margin-top: 12px; justify-content: flex-end"
|
|
|
194
|
+ v-model:current-page="logsPagination.page" v-model:page-size="logsPagination.size"
|
|
|
195
|
+ :total="logsPagination.total" :page-sizes="[10, 20, 50]"
|
|
|
196
|
+ layout="total, sizes, prev, pager, next" @change="fetchLogs" />
|
|
|
197
|
+ </el-tab-pane>
|
|
|
198
|
+ </el-tabs>
|
|
|
199
|
+ </el-card>
|
|
|
200
|
+
|
|
|
201
|
+ <!-- 编辑期望状态对话框 -->
|
|
|
202
|
+ <el-dialog v-model="showEditDesired" title="编辑期望状态(Desired)" width="500px">
|
|
|
203
|
+ <el-input type="textarea" :rows="10" v-model="desiredJson" placeholder="JSON 格式" />
|
|
|
204
|
+ <template #footer>
|
|
|
205
|
+ <el-button @click="showEditDesired = false">取消</el-button>
|
|
|
206
|
+ <el-button type="primary" @click="saveDesired">保存</el-button>
|
|
|
207
|
+ </template>
|
|
|
208
|
+ </el-dialog>
|
|
|
209
|
+ </div>
|
|
|
210
|
+</template>
|
|
|
211
|
+
|
|
|
212
|
+<script setup lang="ts">
|
|
|
213
|
+import { ref, reactive, onMounted, computed } from 'vue'
|
|
|
214
|
+import { useRouter, useRoute } from 'vue-router'
|
|
|
215
|
+import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
216
|
+import { Refresh } from '@element-plus/icons-vue'
|
|
|
217
|
+import { getDeviceDetail, getDeviceShadow, updateDeviceShadow, getOtaHistory, triggerOta as triggerOtaApi, getOperationLogs, batchOperateDevices } from '@/api/deviceApi'
|
|
|
218
|
+import type { Device, ShadowData, OtaRecord, OperationLog } from '@/api/deviceApi'
|
|
|
219
|
+
|
|
|
220
|
+const router = useRouter()
|
|
|
221
|
+const route = useRoute()
|
|
|
222
|
+const deviceId = computed(() => Number(route.params.id))
|
|
|
223
|
+const activeTab = ref('basic')
|
|
|
224
|
+
|
|
|
225
|
+const device = ref<Device>({} as Device)
|
|
|
226
|
+const shadow = ref<ShadowData>({ reported: {}, desired: {} })
|
|
|
227
|
+const otaHistory = ref<OtaRecord[]>([])
|
|
|
228
|
+const operationLogs = ref<OperationLog[]>([])
|
|
|
229
|
+
|
|
|
230
|
+const otaLoading = ref(false)
|
|
|
231
|
+const logsLoading = ref(false)
|
|
|
232
|
+const showEditDesired = ref(false)
|
|
|
233
|
+const desiredJson = ref('')
|
|
|
234
|
+
|
|
|
235
|
+const otaPagination = reactive({ page: 1, size: 10, total: 0 })
|
|
|
236
|
+const logsPagination = reactive({ page: 1, size: 10, total: 0 })
|
|
|
237
|
+
|
|
|
238
|
+const deviceTypeMap: Record<string, string> = {
|
|
|
239
|
+ water_level: '水位计', flow_meter: '流量计', water_quality: '水质监测',
|
|
|
240
|
+ gate_controller: '闸门控制器', camera: '摄像头', weather_station: '气象站'
|
|
|
241
|
+}
|
|
|
242
|
+const statusMap: Record<string, { label: string; type: string }> = {
|
|
|
243
|
+ online: { label: '在线', type: 'success' }, offline: { label: '离线', type: 'info' },
|
|
|
244
|
+ warning: { label: '告警', type: 'danger' }, disabled: { label: '已禁用', type: 'warning' }
|
|
|
245
|
+}
|
|
|
246
|
+const otaStatusMap: Record<string, { label: string; type: string }> = {
|
|
|
247
|
+ pending: { label: '等待中', type: 'info' }, upgrading: { label: '升级中', type: 'warning' },
|
|
|
248
|
+ success: { label: '成功', type: 'success' }, failed: { label: '失败', type: 'danger' }
|
|
|
249
|
+}
|
|
|
250
|
+const logActionMap: Record<string, string> = {
|
|
|
251
|
+ create: '创建设备', update: '更新设备', enable: '启用', disable: '禁用',
|
|
|
252
|
+ delete: '删除', ota: 'OTA升级', shadow_update: '影子更新', config_push: '配置推送'
|
|
|
253
|
+}
|
|
|
254
|
+
|
|
|
255
|
+function deviceTypeLabel(t: string) { return deviceTypeMap[t] || t }
|
|
|
256
|
+function statusLabel(s: string) { return statusMap[s]?.label || s }
|
|
|
257
|
+function statusTag(s: string) { return (statusMap[s]?.type || 'info') as any }
|
|
|
258
|
+function otaStatusLabel(s: string) { return otaStatusMap[s]?.label || s }
|
|
|
259
|
+function otaStatusTag(s: string) { return (otaStatusMap[s]?.type || 'info') as any }
|
|
|
260
|
+function logActionLabel(a: string) { return logActionMap[a] || a }
|
|
|
261
|
+
|
|
|
262
|
+// 获取设备详情
|
|
|
263
|
+async function fetchDevice() {
|
|
|
264
|
+ try {
|
|
|
265
|
+ const res = await getDeviceDetail(deviceId.value)
|
|
|
266
|
+ device.value = res.data
|
|
|
267
|
+ } catch {
|
|
|
268
|
+ // Mock 数据
|
|
|
269
|
+ const types = ['water_level', 'flow_meter', 'water_quality', 'gate_controller', 'camera', 'weather_station']
|
|
|
270
|
+ const statuses = ['online', 'offline', 'warning', 'disabled']
|
|
|
271
|
+ const locations = ['长河坝站', '青衣江入口', '雨城电站', '周公河汇口', '龟都府电站', '水津关']
|
|
|
272
|
+ const id = deviceId.value
|
|
|
273
|
+ device.value = {
|
|
|
274
|
+ id,
|
|
|
275
|
+ deviceCode: `IOT-${String(id).padStart(4, '0')}`,
|
|
|
276
|
+ deviceName: `${deviceTypeMap[types[id % types.length]]} #${id}`,
|
|
|
277
|
+ deviceType: types[id % types.length],
|
|
|
278
|
+ status: statuses[id % statuses.length],
|
|
|
279
|
+ latitude: 29.5 + Math.random() * 0.5,
|
|
|
280
|
+ longitude: 103.0 + Math.random() * 0.8,
|
|
|
281
|
+ location: locations[id % locations.length],
|
|
|
282
|
+ firmwareVersion: `v2.${Math.floor(Math.random() * 10)}.${Math.floor(Math.random() * 10)}`,
|
|
|
283
|
+ lastOnlineTime: new Date().toISOString().replace('T', ' ').slice(0, 19),
|
|
|
284
|
+ createdAt: new Date(Date.now() - Math.random() * 86400000 * 365).toISOString().replace('T', ' ').slice(0, 19),
|
|
|
285
|
+ updatedAt: new Date().toISOString().replace('T', ' ').slice(0, 19),
|
|
|
286
|
+ remark: '这是一台测试设备,用于演示 IoT 设备管理功能。'
|
|
|
287
|
+ }
|
|
|
288
|
+ }
|
|
|
289
|
+}
|
|
|
290
|
+
|
|
|
291
|
+// 获取影子数据
|
|
|
292
|
+async function fetchShadow() {
|
|
|
293
|
+ try {
|
|
|
294
|
+ const res = await getDeviceShadow(deviceId.value)
|
|
|
295
|
+ shadow.value = res.data || { reported: {}, desired: {} }
|
|
|
296
|
+ } catch {
|
|
|
297
|
+ // Mock 数据
|
|
|
298
|
+ shadow.value = {
|
|
|
299
|
+ reported: {
|
|
|
300
|
+ temperature: 25.3,
|
|
|
301
|
+ humidity: 68,
|
|
|
302
|
+ water_level: 12.45,
|
|
|
303
|
+ battery: 85,
|
|
|
304
|
+ signal_strength: -72,
|
|
|
305
|
+ timestamp: new Date().toISOString(),
|
|
|
306
|
+ sensors: { ph: 7.2, dissolved_oxygen: 8.1, turbidity: 3.5 }
|
|
|
307
|
+ },
|
|
|
308
|
+ desired: {
|
|
|
309
|
+ sampling_interval: 300,
|
|
|
310
|
+ upload_interval: 600,
|
|
|
311
|
+ alarm_threshold: { water_level: 15.0, temperature: 40 },
|
|
|
312
|
+ firmware_target: 'v2.5.0'
|
|
|
313
|
+ },
|
|
|
314
|
+ timestamp: new Date().toISOString()
|
|
|
315
|
+ }
|
|
|
316
|
+ }
|
|
|
317
|
+ desiredJson.value = JSON.stringify(shadow.value.desired, null, 2)
|
|
|
318
|
+}
|
|
|
319
|
+
|
|
|
320
|
+async function refreshShadow() {
|
|
|
321
|
+ await fetchShadow()
|
|
|
322
|
+ ElMessage.success('影子数据已刷新')
|
|
|
323
|
+}
|
|
|
324
|
+
|
|
|
325
|
+async function saveDesired() {
|
|
|
326
|
+ try {
|
|
|
327
|
+ const parsed = JSON.parse(desiredJson.value)
|
|
|
328
|
+ try { await updateDeviceShadow(deviceId.value, parsed) } catch { /* mock ok */ }
|
|
|
329
|
+ shadow.value.desired = parsed
|
|
|
330
|
+ showEditDesired.value = false
|
|
|
331
|
+ ElMessage.success('期望状态已更新')
|
|
|
332
|
+ } catch {
|
|
|
333
|
+ ElMessage.error('JSON 格式错误,请检查')
|
|
|
334
|
+ }
|
|
|
335
|
+}
|
|
|
336
|
+
|
|
|
337
|
+// OTA 历史
|
|
|
338
|
+async function fetchOtaHistory() {
|
|
|
339
|
+ otaLoading.value = true
|
|
|
340
|
+ try {
|
|
|
341
|
+ const res = await getOtaHistory(deviceId.value, { page: otaPagination.page, size: otaPagination.size })
|
|
|
342
|
+ otaHistory.value = res.data?.records || []
|
|
|
343
|
+ otaPagination.total = res.data?.total || 0
|
|
|
344
|
+ } catch {
|
|
|
345
|
+ // Mock 数据
|
|
|
346
|
+ const records: OtaRecord[] = []
|
|
|
347
|
+ for (let i = 1; i <= 15; i++) {
|
|
|
348
|
+ const statuses = ['success', 'success', 'success', 'failed', 'pending']
|
|
|
349
|
+ const status = statuses[i % statuses.length]
|
|
|
350
|
+ records.push({
|
|
|
351
|
+ id: i, deviceId: deviceId.value, deviceCode: device.value.deviceCode,
|
|
|
352
|
+ fromVersion: `v${i}.0.0`, toVersion: `v${i + 1}.0.0`,
|
|
|
353
|
+ status, progress: status === 'success' ? 100 : status === 'failed' ? 45 : status === 'pending' ? 0 : 67,
|
|
|
354
|
+ errorMessage: status === 'failed' ? '网络连接超时,升级失败' : undefined,
|
|
|
355
|
+ startTime: new Date(Date.now() - i * 86400000 * 7).toISOString().replace('T', ' ').slice(0, 19),
|
|
|
356
|
+ endTime: status === 'success' ? new Date(Date.now() - i * 86400000 * 7 + 300000).toISOString().replace('T', ' ').slice(0, 19) : undefined
|
|
|
357
|
+ })
|
|
|
358
|
+ }
|
|
|
359
|
+ otaHistory.value = records.slice(0, otaPagination.size)
|
|
|
360
|
+ otaPagination.total = records.length
|
|
|
361
|
+ } finally { otaLoading.value = false }
|
|
|
362
|
+}
|
|
|
363
|
+
|
|
|
364
|
+async function triggerOta() {
|
|
|
365
|
+ try {
|
|
|
366
|
+ const { value } = await ElMessageBox.prompt('请输入目标版本号(如 v3.0.0)', 'OTA 升级', {
|
|
|
367
|
+ confirmButtonText: '开始升级', cancelButtonText: '取消', inputPattern: /^v\d+\.\d+\.\d+$/, inputErrorMessage: '版本号格式错误'
|
|
|
368
|
+ })
|
|
|
369
|
+ try { await triggerOtaApi(deviceId.value, value) } catch { /* mock ok */ }
|
|
|
370
|
+ ElMessage.success(`OTA 升级已触发,目标版本:${value}`)
|
|
|
371
|
+ fetchOtaHistory()
|
|
|
372
|
+ } catch { /* cancel */ }
|
|
|
373
|
+}
|
|
|
374
|
+
|
|
|
375
|
+// 操作日志
|
|
|
376
|
+async function fetchLogs() {
|
|
|
377
|
+ logsLoading.value = true
|
|
|
378
|
+ try {
|
|
|
379
|
+ const res = await getOperationLogs(deviceId.value, { page: logsPagination.page, size: logsPagination.size })
|
|
|
380
|
+ operationLogs.value = res.data?.records || []
|
|
|
381
|
+ logsPagination.total = res.data?.total || 0
|
|
|
382
|
+ } catch {
|
|
|
383
|
+ // Mock 数据
|
|
|
384
|
+ const actions = ['create', 'update', 'enable', 'disable', 'ota', 'shadow_update', 'config_push']
|
|
|
385
|
+ const operators = ['admin', 'operator_zhang', 'operator_li', 'system']
|
|
|
386
|
+ const records: OperationLog[] = []
|
|
|
387
|
+ for (let i = 1; i <= 25; i++) {
|
|
|
388
|
+ records.push({
|
|
|
389
|
+ id: i, deviceId: deviceId.value,
|
|
|
390
|
+ action: actions[i % actions.length],
|
|
|
391
|
+ operator: operators[i % operators.length],
|
|
|
392
|
+ detail: `${logActionMap[actions[i % actions.length]]} - 操作详情描述 #${i}`,
|
|
|
393
|
+ createdAt: new Date(Date.now() - i * 3600000 * 6).toISOString().replace('T', ' ').slice(0, 19)
|
|
|
394
|
+ })
|
|
|
395
|
+ }
|
|
|
396
|
+ operationLogs.value = records.slice(0, logsPagination.size)
|
|
|
397
|
+ logsPagination.total = records.length
|
|
|
398
|
+ } finally { logsLoading.value = false }
|
|
|
399
|
+}
|
|
|
400
|
+
|
|
|
401
|
+async function handleEnable() {
|
|
|
402
|
+ try {
|
|
|
403
|
+ await ElMessageBox.confirm('确认启用该设备?', '启用确认')
|
|
|
404
|
+ try { await batchOperateDevices([deviceId.value], 'enable') } catch { /* mock */ }
|
|
|
405
|
+ ElMessage.success('设备已启用')
|
|
|
406
|
+ fetchDevice()
|
|
|
407
|
+ } catch { /* cancel */ }
|
|
|
408
|
+}
|
|
|
409
|
+
|
|
|
410
|
+async function handleDisable() {
|
|
|
411
|
+ try {
|
|
|
412
|
+ await ElMessageBox.confirm('确认禁用该设备?', '禁用确认')
|
|
|
413
|
+ try { await batchOperateDevices([deviceId.value], 'disable') } catch { /* mock */ }
|
|
|
414
|
+ ElMessage.success('设备已禁用')
|
|
|
415
|
+ fetchDevice()
|
|
|
416
|
+ } catch { /* cancel */ }
|
|
|
417
|
+}
|
|
|
418
|
+
|
|
|
419
|
+onMounted(() => {
|
|
|
420
|
+ fetchDevice()
|
|
|
421
|
+ fetchShadow()
|
|
|
422
|
+ fetchOtaHistory()
|
|
|
423
|
+ fetchLogs()
|
|
|
424
|
+})
|
|
|
425
|
+</script>
|
|
|
426
|
+
|
|
|
427
|
+<style scoped>
|
|
|
428
|
+.page-title { font-size: 18px; font-weight: bold; }
|
|
|
429
|
+.info-card { height: 100%; }
|
|
|
430
|
+.info-item { display: flex; justify-content: space-between; margin-bottom: 8px; }
|
|
|
431
|
+.info-label { color: #909399; font-size: 13px; }
|
|
|
432
|
+.info-value { font-weight: 500; font-size: 14px; }
|
|
|
433
|
+.section-title { font-size: 15px; font-weight: bold; }
|
|
|
434
|
+.shadow-card { height: 100%; }
|
|
|
435
|
+.card-header { display: flex; justify-content: space-between; align-items: center; }
|
|
|
436
|
+</style>
|