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