大棚关联用户

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

View File

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

View File

@ -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: ""
} }

View File

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