大棚关联用户
parent
30d7a21b60
commit
62a4b70bff
58
App.vue
58
App.vue
|
|
@ -5,8 +5,10 @@ import mqttUtil from '@/utils/mqtt'
|
|||
import {startMqttOnlinePing, stopMqttOnlinePing} from "./utils/mqtt";
|
||||
import {batchSubscribe} from "./api/system/mqtt";
|
||||
import store from "store";
|
||||
import {listAgri} from "./api/system/assets/agri";
|
||||
|
||||
export default {
|
||||
subscribeList:[],
|
||||
globalData: {
|
||||
config: {},
|
||||
mqtt: {
|
||||
|
|
@ -123,32 +125,26 @@ export default {
|
|||
return
|
||||
}
|
||||
var clientId = mqttUtil.getMqttState().clientId;
|
||||
const subscribeList = [
|
||||
`frontend/${clientId}/dtu/864865085016294/+`,
|
||||
`frontend/${clientId}/dtu/864536071808560/+`,
|
||||
`frontend/${clientId}/dtu/864865085008135/+`,
|
||||
`frontend/${clientId}/dtu/862538065276939/+`
|
||||
];
|
||||
if (store.getters && store.getters.name === 'admin') {
|
||||
subscribeList.push(`frontend/${clientId}/dtu/862538065276061/+`);
|
||||
}
|
||||
this.globalData.mqtt.subscribeList = subscribeList || []
|
||||
this.getSubscribeImei(clientId).then(res=>{
|
||||
console.info("subscribeList",res)
|
||||
const subscribeList = res;
|
||||
this.globalData.mqtt.subscribeList = subscribeList || []
|
||||
batchSubscribe({clientId: clientId}).then((result) => {
|
||||
if (result.code === 200) {
|
||||
console.info(`设备列表订阅成功:${subscribeList}`)
|
||||
}
|
||||
})
|
||||
|
||||
batchSubscribe({clientId: clientId}).then((result) => {
|
||||
if (result.code === 200) {
|
||||
console.info(`设备列表订阅成功:${subscribeList}`)
|
||||
// ========== 新增:登录成功时同步到localStorage ==========
|
||||
uni.setStorageSync('mqtt_subscribe_list', subscribeList || [])
|
||||
|
||||
if (subscribeList.length > 0) {
|
||||
mqttUtil.updateSubscribeList(subscribeList)
|
||||
console.log('恢复MQTT订阅列表:', subscribeList)
|
||||
// ========== 新增:恢复订阅后同步到localStorage ==========
|
||||
uni.setStorageSync('mqtt_subscribe_list', subscribeList)
|
||||
}
|
||||
})
|
||||
|
||||
// ========== 新增:登录成功时同步到localStorage ==========
|
||||
uni.setStorageSync('mqtt_subscribe_list', subscribeList || [])
|
||||
|
||||
if (subscribeList.length > 0) {
|
||||
mqttUtil.updateSubscribeList(subscribeList)
|
||||
console.log('恢复MQTT订阅列表:', subscribeList)
|
||||
// ========== 新增:恢复订阅后同步到localStorage ==========
|
||||
uni.setStorageSync('mqtt_subscribe_list', subscribeList)
|
||||
}
|
||||
},
|
||||
loginSuccess(token) {
|
||||
this.globalData.mqtt.hasLogin = true
|
||||
|
|
@ -169,8 +165,20 @@ export default {
|
|||
console.log('登出成功,MQTT已断开')
|
||||
},
|
||||
|
||||
|
||||
|
||||
getSubscribeImei(clientId) {
|
||||
return listAgri().then(response => {
|
||||
const subscribeList = [];
|
||||
if (response.code === 200) {
|
||||
response.rows.forEach(item =>
|
||||
subscribeList.push(`frontend/${clientId}/dtu/${item.imei}/+`)
|
||||
);
|
||||
if (store.getters && store.getters.name === 'admin') {
|
||||
subscribeList.push(`frontend/${clientId}/dtu/862538065276061/+`)
|
||||
}
|
||||
}
|
||||
return subscribeList;
|
||||
})
|
||||
},
|
||||
// token过期处理逻辑(核心)
|
||||
handleTokenExpired() {
|
||||
|
||||
|
|
|
|||
|
|
@ -261,6 +261,7 @@ export default {
|
|||
jm3k: 0,
|
||||
jm3g: 0
|
||||
},
|
||||
testMsg:'由于线上为真实数据。任何操作均可影响线上功能,故仅作演示',
|
||||
fontStyle: '',
|
||||
// 新增:弹窗相关变量
|
||||
currentCard: {}, // 当前点击的卡片信息
|
||||
|
|
@ -403,25 +404,16 @@ export default {
|
|||
}
|
||||
})
|
||||
},
|
||||
testFunction() {
|
||||
uni.showModal({
|
||||
title: '操作提示:',
|
||||
content: '确定' + (status === 1 ? "运行" : "暂停") + '【' + this.selectedText + '】设备?',
|
||||
cancelText: '取消',
|
||||
confirmText: '确定',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
// 组装消息
|
||||
this.message = JSON.stringify({[type]: status})
|
||||
// 控制设备
|
||||
this.publishMessage();
|
||||
// 设备回执
|
||||
//todo
|
||||
// this.testAuto(type);
|
||||
|
||||
testFunction(content) {
|
||||
uni.showModal({
|
||||
title: '操作提示:',
|
||||
content: content,
|
||||
cancelText: '确定',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
makeSpecialData(msgData, tag) {
|
||||
const div10 = (v) => (v == null ? null : Math.round((Number(v)/10)*10)/10);
|
||||
|
|
@ -483,6 +475,12 @@ export default {
|
|||
},
|
||||
// 卡片点击事件(实际项目中调用接口修改状态) 功能标识
|
||||
handleCardClick(status, type) {
|
||||
const funcMsg = "该功能用来开启或暂停设备,按钮亮为开启,按钮暗为暂停设备"
|
||||
if ((store.getters && store.getters.name !== 'admin')
|
||||
&& this.$auth.hasRole("test")) {
|
||||
this.testFunction(`${this.testMsg}\n${funcMsg}`)
|
||||
return;
|
||||
}
|
||||
// 校验
|
||||
// 定义类型与提示文案的映射关系,减少重复代码
|
||||
const tipMap = {
|
||||
|
|
@ -687,6 +685,13 @@ export default {
|
|||
this.$refs.inputNamelog.open()
|
||||
},
|
||||
confirmModifyName() {
|
||||
const funcMsg = "该功能用来设置温湿度卡片别名,如若不填则展示默认备注"
|
||||
if ((store.getters && store.getters.name !== 'admin')
|
||||
&& this.$auth.hasRole("test")) {
|
||||
this.testFunction(`${this.testMsg}\n${funcMsg}`)
|
||||
this.$refs?.inputNamelog?.close();
|
||||
return;
|
||||
}
|
||||
// 1. 解构赋值优化:直接拆分sensorCard的key/label,减少冗余
|
||||
let {
|
||||
selectedText,
|
||||
|
|
@ -761,6 +766,13 @@ export default {
|
|||
// 新增:确认修改运行时间
|
||||
// 确认修改运行时间
|
||||
confirmModifyTime() {
|
||||
const funcMsg = "该功能用来设置设备运行时间及设备别名,设备运行时间即开启设备后到达运行时间自行暂停设备;设备别名不填则展示默认设备名称"
|
||||
if ((store.getters && store.getters.name !== 'admin')
|
||||
&& this.$auth.hasRole("test")) {
|
||||
this.testFunction(`${this.testMsg}\n${funcMsg}`)
|
||||
this.$refs?.inputDialog?.close();
|
||||
return;
|
||||
}
|
||||
// 1. 解构赋值:简化频繁的this.xxx调用,提升可读性
|
||||
let {
|
||||
newLimitTime, currentCardTime, selectedText, currentCard,
|
||||
|
|
|
|||
|
|
@ -64,8 +64,8 @@
|
|||
register: true,
|
||||
globalConfig: getApp().globalData.config,
|
||||
loginForm: {
|
||||
username: "admin",
|
||||
password: "admin123",
|
||||
username: "",
|
||||
password: "",
|
||||
code: "",
|
||||
uuid: ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ function subscribeAllTopics() {
|
|||
* @returns {Boolean} - 是否触发发布成功
|
||||
*/
|
||||
export function publishMqtt(topic, message) {
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
// if (process.env.NODE_ENV === "production") {
|
||||
const { isConnected, client } = mqttState
|
||||
if (!isConnected || !client) {
|
||||
uni.showToast({ title: '控制异常', icon: 'none' })
|
||||
|
|
@ -235,7 +235,7 @@ export function publishMqtt(topic, message) {
|
|||
console.error('MQTT发布异常:', err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue