From 696bcbd4e5f81ac3f6ee2a0f66114f874f112a11 Mon Sep 17 00:00:00 2001 From: lld <15027638633@163.com> Date: Wed, 21 Jan 2026 23:59:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 9 ++++ api/system/assets/remark.js | 52 +++++++++++++++++++ pages/control/index.vue | 100 +++++++++++++++++++++++++++--------- utils/mqtt.js | 2 +- 4 files changed, 139 insertions(+), 24 deletions(-) create mode 100644 api/system/assets/remark.js diff --git a/App.vue b/App.vue index 34c821b..774f598 100644 --- a/App.vue +++ b/App.vue @@ -16,6 +16,15 @@ export default { } }, onLaunch: function() { + + // 仅开发环境生效 + if (process.env.NODE_ENV === 'development') { + // 监听热重载事件(HBuilderX特有) + document.addEventListener('uni-app:reload', () => { + console.log('开发环境代码热更新') ; + mqttUtil.disconnectMqtt(); // 断开旧MQTT连接 + }); + } // #ifdef H5 // 监听H5页面刷新/关闭事件 window.addEventListener('beforeunload', () => { diff --git a/api/system/assets/remark.js b/api/system/assets/remark.js new file mode 100644 index 0000000..3113c44 --- /dev/null +++ b/api/system/assets/remark.js @@ -0,0 +1,52 @@ +import request from '@/utils/request' + +// 查询dtu设备备注列表 +export function listRemark(query) { + return request({ + url: '/assets/remark/list', + method: 'get', + params: query + }) +} + +// 查询dtu设备备注详细 +export function getRemark(id) { + return request({ + url: '/assets/remark/' + id, + method: 'get' + }) +} +// 查询dtu设备备注详细 +export function getRemarkByImei(imei) { + return request({ + url: '/assets/remark/getDtuByImei', + method: 'get', + params: imei + }) +} + +// 新增dtu设备备注 +export function addRemark(data) { + return request({ + url: '/assets/remark', + method: 'post', + data: data + }) +} + +// 修改dtu设备备注 +export function updateRemark(data) { + return request({ + url: '/assets/remark', + method: 'put', + data: data + }) +} + +// 删除dtu设备备注 +export function delRemark(id) { + return request({ + url: '/assets/remark/' + id, + method: 'delete' + }) +} diff --git a/pages/control/index.vue b/pages/control/index.vue index e4e5904..ffdbfb1 100644 --- a/pages/control/index.vue +++ b/pages/control/index.vue @@ -25,7 +25,8 @@ {{ liveData[item.key] }} - {{ item.label }} + {{ dtu_remark[item.key] }} + {{ item.label }} @@ -40,7 +41,8 @@ {{ liveData[item.key] }} %RH - {{ item.label }} + {{ dtu_remark[item.key] }} + {{ item.label }} @@ -85,10 +87,10 @@ - {{ `【${selectedText} - ${currentCard.name}】运行时间` }} + {{ `【${selectedText} - ${currentCard.name}】设置` }} 当前时间: - {{ currentCardTime ? `${currentCardTime} 秒` : '未设置' }} + {{ currentCardTime>0 ? `${currentCardTime} 秒` : '未设置' }} 修改后时间: @@ -100,6 +102,11 @@ + + + 别名设置: + + @@ -128,6 +135,7 @@ import {addLimit, getAgriByImei, updateLimit} from "../../api/system/assets/limi import {listAgri} from "../../api/system/assets/agri"; import {getNewSpecialData} from "../../api/data/specialData"; import store from "../../store"; +import {getRemarkByImei, updateRemark} from "../../api/system/assets/remark"; export default { dicts: ['sys_data_map'], @@ -156,6 +164,8 @@ export default { message: {}, // 优化:声明响应式变量 connected connected: false, + remark:'', + dtu_remark:{}, liveData: { temp1: '数据加载中...', temp2: '数据加载中...', @@ -228,7 +238,7 @@ export default { fontStyle: '', // 新增:弹窗相关变量 currentCard: {}, // 当前点击的卡片信息 - currentCardTime: 0, // 当前卡片的运行时间 + currentCardTime: '', // 当前卡片的运行时间 newLimitTime: 0, // 新的运行时间 }; }, @@ -298,6 +308,7 @@ export default { this.fontStyle = 'font-size:16px;' }) this.getAgriByImei(); + this.getRemarkByImei(); } } else { this.selectedText = ''; // 无匹配项时清空 @@ -308,6 +319,13 @@ export default { this.reset(); this.style=""; }, + getRemarkByImei() { + getRemarkByImei({imei:this.imei}).then(response => { + if (response.code===200 && (response.data)) { + this.dtu_remark={...response.data} + } + }); + }, getAgriByImei() { getAgriByImei(this.imei).then(response => { if (response.code === 200) { @@ -593,6 +611,7 @@ export default { this.currentCard = card; // 记录当前卡片信息 this.currentCardTime = this.limitTimes[`${card.type}Limit`]; // 记录当前时间 this.newLimitTime = this.currentCardTime; // 默认填充当前时间 + this.remark = this.remark[card.type] || card.name; this.$refs.inputDialog.open() }, close() { @@ -608,31 +627,62 @@ export default { }); return; }*/ + var showText = `确定修改${this.selectedText}-${this.currentCard.name}:\n1. `; // 修改limitTimes(用$set确保响应式) - if (this.newLimitTime !== this.currentCardTime) { + var limitTimeUpdate = this.newLimitTime !== this.currentCardTime; + if (limitTimeUpdate) { + showText += `运行时间为:${this.newLimitTime} 秒?` + } + var remarkName = this.remark !== (this.remark[this.currentCard.type] || this.currentCard.name); + if (limitTimeUpdate && remarkName) { + showText += `\n2. ` + } + if (remarkName) { + showText += `别名设置为:${this.remark}?` + } + + if (limitTimeUpdate || remarkName) { + // 提示修改成功 // 提示修改成功 uni.showModal({ title: '温馨提示:', - content: `确定修改${this.selectedText}-${this.currentCard.name}运行时间为:${this.newLimitTime} 秒?`, + content: `${showText}`, cancelText: '取消', confirmText: '确定', success: (res) => { if (res.confirm) { - this.$set(this.limitTimes, `${this.currentCard.type}Limit`, this.newLimitTime); - if (this.limitTimes.imei) { - updateLimit(this.limitTimes).then(response => { - response.code === 200 ? this.$modal.msgSuccess("修改成功"):this.$modal.msgSuccess("修改失败") - }) - return; + var updateFlag = true; + if (limitTimeUpdate) { + this.$set(this.limitTimes, `${this.currentCard.type}Limit`, this.newLimitTime); + if (this.limitTimes.imei) { + updateLimit(this.limitTimes).then(response => { + if (response.code!==200) updateFlag=false; + }) + } else { + this.$set(this.limitTimes, 'imei', this.imei); + this.$set(this.limitTimes, 'agriName', this.selectedText); + this.$set(this.limitTimes, 'agriId', this.agriId); + addLimit(this.limitTimes).then(response => { + if (response.code!==200) updateFlag=false; + this.getAgriByImei(); + }) + } } - this.$set(this.limitTimes, 'imei', this.imei); - this.$set(this.limitTimes, 'agriName', this.selectedText); - this.$set(this.limitTimes, 'agriId', this.agriId); - addLimit(this.limitTimes).then(response => { - response.code === 200 ? this.$modal.msgSuccess("修改成功"):this.$modal.msgSuccess("修改失败") - this.getAgriByImei(); - }) - + if (remarkName) { + this.$set(this.dtu_remark, `${this.currentCard.type}`, this.remark); + if (this.dtu_remark.imei) { + updateRemark(this.dtu_remark).then(response => { + if (response.code!==200) updateFlag=false; + }) + } else { + this.$set(this.dtu_remark, 'imei', this.imei); + updateRemark(this.dtu_remark).then(response => { + if (response.code!==200) updateFlag=false; + this.getRemarkByImei(); + }) + } + } + updateFlag?this.$modal.msgError("修改成功"):this.$modal.msgSuccess("修改失败") } } }) @@ -801,14 +851,15 @@ export default { font-size: 30rpx; font-weight: 500; text-align: center; - margin-bottom: 30rpx; + margin-bottom: 40rpx; color: #333; } .modal-input-wrap { display: flex; align-items: center; - margin-bottom: 25rpx; + margin-bottom: 35rpx; font-size: 26rpx; + margin-left: 20rpx; } .modal-label { width: 160rpx; @@ -855,4 +906,7 @@ export default { .uni-stat-tooltip { width: 300rpx; } +/deep/ .is-input-border { + width: 340rpx; +} \ No newline at end of file diff --git a/utils/mqtt.js b/utils/mqtt.js index 03a74f2..1fb8785 100644 --- a/utils/mqtt.js +++ b/utils/mqtt.js @@ -302,7 +302,7 @@ export function startMqttOnlinePing(intervalMs = 20000) { const payload = JSON.stringify({ ts: Date.now() }); // qos=0 足够;retain 不要 mqttState.client.publish(topic, payload, { qos: 0, retain: false }); - console.info(`主题:${topic}:${payload}`) + // console.info(`主题:${topic}:${payload}`) } catch (e) {} };