大棚关联用户

master
lld 2026-02-03 16:19:09 +08:00
parent 30d7a21b60
commit 62a4b70bff
4 changed files with 77 additions and 57 deletions

58
App.vue
View File

@ -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() {

View File

@ -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. sensorCardkey/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,

View File

@ -64,8 +64,8 @@
register: true,
globalConfig: getApp().globalData.config,
loginForm: {
username: "admin",
password: "admin123",
username: "",
password: "",
code: "",
uuid: ""
}

View File

@ -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
}
}
// }
}
/**