Sfoglia il codice sorgente

fix: 优化 ota 升级中删除时机的判断,增加设备详情中设备属性图形每隔 10 秒的更新操作

yanglzh 7 mesi fa
parent
commit
4c32ac804a

+ 0 - 3
src/views/iot/alarm/dashboard/index.vue

@@ -218,9 +218,6 @@ const getAlarmStatusData = () => {
 						top: 'center',
 						left: '55%',
 					},
-					// 					'未处理': '#ed5565', // 红色
-					// '已处理': '#23c6c8', // 蓝绿色
-					// '已忽略': '#ffce37'  // 黄色
 					color: ['#23c6c8', '#ed5565', '#ffce37'],
 					centerText: '总计',
 					data: resData.map((item: any) => {

+ 81 - 30
src/views/iot/device/instance/component/chart.vue

@@ -74,7 +74,7 @@
 </template>
 
 <script lang="ts" setup>
-import { ref, reactive, watch, nextTick } from 'vue'
+import { ref, reactive, watch, nextTick, onBeforeUnmount, onMounted } from 'vue'
 import api from '/@/api/device'
 import * as echarts from 'echarts'
 import dayjs from 'dayjs'
@@ -85,10 +85,13 @@ const data = ref({ name: '', key: '', unit: '' })
 const historyDateRangeType = ref('1')
 const loading = ref(false)
 const isShowDialog = ref(false)
-const chartRef = ref<HTMLElement | null>(null)
+const chartRef = ref()
 let chartInstance: echarts.ECharts | null = null
 const lineData = ref([])
 
+// 定时器引用
+let updateTimer: number | null = null
+
 const disabledDate = (time: Date) => {
 	return time.getTime() > Date.now()
 }
@@ -133,11 +136,11 @@ const initChart = () => {
 		// 创建图表实例
 		chartInstance = echarts.init(chartRef.value)
 		// 设置加载状态
-		if (loading.value) {
-			chartInstance.showLoading()
-		} else {
-			chartInstance.hideLoading()
-		}
+		// if (loading.value) {
+		// 	chartInstance.showLoading()
+		// } else {
+		// 	chartInstance.hideLoading()
+		// }
 		// 更新图表
 		updateChart()
 	}
@@ -226,6 +229,23 @@ const updateChart = () => {
 	chartInstance.setOption(option)
 }
 
+// 获取图表数据
+const fetchChartData = () => {
+	if (!params.deviceKey || !params.properties) return
+	
+	loading.value = true
+	api.instance
+		.getLogDetail({
+			deviceKey: params.deviceKey,
+			propertyKey: params.properties,
+			pageSize: 100,
+		})
+		.then((res: any) => {
+			lineData.value = res.List
+		})
+		.finally(() => (loading.value = false))
+}
+
 // 获取历史数据
 const fetchHistoryData = () => {
 	if (!params.deviceKey || !params.properties) return
@@ -282,18 +302,18 @@ watch(
 )
 
 // 监听 loading 状态变化
-watch(
-	() => loading.value,
-	(newVal) => {
-		if (chartInstance) {
-			if (newVal) {
-				chartInstance.showLoading()
-			} else {
-				chartInstance.hideLoading()
-			}
-		}
-	}
-)
+// watch(
+// 	() => loading.value,
+// 	(newVal) => {
+// 		if (chartInstance) {
+// 			if (newVal) {
+// 				chartInstance.showLoading()
+// 			} else {
+// 				chartInstance.hideLoading()
+// 			}
+// 		}
+// 	}
+// )
 
 // 监听弹窗显示状态
 watch(
@@ -307,8 +327,14 @@ watch(
 				// 如果是历史日志标签页,加载历史数据
 				if (activeTab.value === 'history') {
 					fetchHistoryData()
+				} else if (activeTab.value === 'trend') {
+					// 如果是趋势图标签页,启动自动更新
+					startAutoUpdate()
 				}
 			})
+		} else {
+			// 关闭弹窗时停止自动更新
+			stopAutoUpdate()
 		}
 	}
 )
@@ -318,10 +344,14 @@ watch(
 	() => activeTab.value,
 	(val) => {
 		if (val === 'history' && isShowDialog.value) {
+			// 切换到历史数据标签页时停止自动更新
+			stopAutoUpdate()
 			fetchHistoryData()
 		} else if (val === 'trend' && isShowDialog.value) {
 			nextTick(() => {
 				initChart()
+				// 切换到趋势图标签页时启动自动更新
+				startAutoUpdate()
 			})
 		}
 	}
@@ -339,6 +369,30 @@ const toggleFullscreen = () => {
 	})
 }
 
+// 启动定时更新
+const startAutoUpdate = () => {
+	// 先清除可能存在的定时器
+	stopAutoUpdate()
+	
+	// 创建新的定时器,每10秒更新一次数据
+	updateTimer = window.setInterval(() => {
+		fetchChartData()
+	}, 10000) // 10秒 = 10000毫秒
+}
+
+// 停止定时更新
+const stopAutoUpdate = () => {
+	if (updateTimer !== null) {
+		window.clearInterval(updateTimer)
+		updateTimer = null
+	}
+}
+
+// 组件卸载前清除定时器
+onBeforeUnmount(() => {
+	stopAutoUpdate()
+})
+
 // 打开弹窗
 const openDialog = (row: any, deviceKey: string) => {
 	params.deviceKey = deviceKey
@@ -349,17 +403,14 @@ const openDialog = (row: any, deviceKey: string) => {
 	params.dateRange = [dayjs().subtract(30, 'minute').format('YYYY-MM-DD HH:mm:ss'), dayjs().format('YYYY-MM-DD HH:mm:ss')]
 	data.value = row
 	isShowDialog.value = true
-	loading.value = true
-	api.instance
-		.getLogDetail({
-			deviceKey: deviceKey,
-			propertyKey: row.key,
-			pageSize: 100,
-		})
-		.then((res: any) => {
-			lineData.value = res.List
-		})
-		.finally(() => (loading.value = false))
+	
+	// 获取初始数据
+	fetchChartData()
+	
+	// 如果是趋势图标签页,启动自动更新
+	if (activeTab.value === 'trend') {
+		startAutoUpdate()
+	}
 }
 
 defineExpose({ openDialog })

+ 3 - 6
src/views/iot/ota-update/update/component/batch.vue

@@ -65,8 +65,8 @@
 			<el-table-column label="操作" width="120" align="center">
 				<template #default="scope">
 					<el-button size="small" text type="primary" @click="getDeviceList(scope.row)">查看</el-button>
-					<!-- <el-button size="small" text type="warning" @click="edit(scope.row)">编辑</el-button> -->
-					<el-button size="small" text type="danger" @click="onRowDel(scope.row)">删除</el-button>
+					<!-- <el-button size="small" text type="warning" :disabled="!scope.row.isOperation" @click="edit(scope.row)">编辑</el-button> -->
+					<el-button size="small" text type="danger" :disabled="!scope.row.isOperation" @click="onRowDel(scope.row)">删除</el-button>
 				</template>
 			</el-table-column>
 		</el-table>
@@ -226,11 +226,8 @@ export default defineComponent({
 			deviceRef.value.openDialog(row)
 		}
 		const edit = (row: any) => {
-			console.log(row)
 			state.tableData.param.id = props.detail.id
-			console.log(state.tableData.param)
-			console.log(props.detail)
-			checkRef.value.openDialog(state.tableData.param, props.detail)
+			checkRef.value.openDialog(state.tableData.param, props.detail, row)
 		}
 		return {
 			edit,

+ 18 - 8
src/views/iot/ota-update/update/component/check.vue

@@ -15,9 +15,9 @@
 
 				<el-form-item label="协议方式" prop="method">
 					<el-radio-group v-model="ruleForm.method" @change="getMethod">
-						<el-radio label="1">http</el-radio>
-						<el-radio label="2">https</el-radio>
-						<el-radio label="3">mqtt</el-radio>
+						<el-radio :label="1">http</el-radio>
+						<el-radio :label="2">https</el-radio>
+						<el-radio :label="3">mqtt</el-radio>
 					</el-radio-group>
 				</el-form-item>
 
@@ -32,15 +32,15 @@
 
 				<el-form-item label="升级方式" prop="stratege">
 					<el-radio-group v-model="ruleForm.stratege">
-						<el-radio label="1">静态升级</el-radio>
-						<el-radio label="2">动态升级</el-radio>
+						<el-radio :label="1">静态升级</el-radio>
+						<el-radio :label="2">动态升级</el-radio>
 					</el-radio-group>
 				</el-form-item>
 
 				<el-form-item label="主动推送" prop="push">
 					<el-radio-group v-model="ruleForm.push">
-						<el-radio label="1" :disabled="ruleForm.pushDisabled">是</el-radio>
-						<el-radio label="2">否</el-radio>
+						<el-radio :label="1" :disabled="ruleForm.pushDisabled">是</el-radio>
+						<el-radio :label="2">否</el-radio>
 					</el-radio-group>
 				</el-form-item>
 			</el-form>
@@ -158,7 +158,7 @@ export default defineComponent({
 			}
 		}
 		// 打开弹窗
-		const openDialog = (row: RuleFormState | null, detail: any) => {
+		const openDialog = (row: RuleFormState | null, detail: any, editData?: any) => {
 			resetForm()
 			state.deviceNameList = []
 			state.deviceNameShow = false
@@ -166,6 +166,16 @@ export default defineComponent({
 				state.ruleForm.devOtaFirmwareId = row.id
 				state.ruleForm.productKey = row.productKey
 			}
+			if (editData) {
+				state.ruleForm.name = editData.name
+				state.ruleForm.waitVersion = editData.waitVersion
+				state.ruleForm.method = editData.method
+				state.ruleForm.stratege = editData.stratege
+				state.ruleForm.devOtaFirmwareId = editData.devOtaFirmwareId
+				state.ruleForm.push = editData.push
+				state.ruleForm.types = editData.types
+				state.ruleForm.productKey = editData.productKey
+			}
 			// 升级包状态是已验证才能选择升级类型,否则不可以
 			// 如果升级包是不需要验证类型的,则可以选择升级类型
 			state.showUpdate = detail.checkres === 2 || detail.check === 2