功能修复

master
lld 2026-01-01 12:05:55 +08:00
parent 1fef05d415
commit 0ea24e0329
2 changed files with 25 additions and 81 deletions

102
App.vue
View File

@ -1,89 +1,33 @@
<script>
import config from './config'
import { getToken } from '@/utils/auth'
import {
initMQTT,
disconnectMQTT,
getMQTTStatus,
manualReconnect
} from '@/utils/mqtt';
export default {
globalData: {
mqttClient: null, // MQTT
mqttConfig: { // MQTT
host: '1.94.254.176',
port: 9001, // wssEMQ X8084
isSSL: false, // true=wssfalse=ws
username: 'admin',
password: 'Admin#12345678',
keepalive: 60,
clean: true
},
mqttSubscribeList: [ //
{topic: 'dtu/#', qos: 0},
// {topic: 'system/status', qos: 1}
],
},
onLaunch() {
this.initApp()
console.log('应用启动初始化MQTT连接');
this.initGlobalMQTT();
},
onShow() {
console.log('应用切前台检查MQTT连接');
const { isConnected } = getMQTTStatus();
if (!isConnected) {
this.initGlobalMQTT();
}
console.info("mqtt",isConnected,getMQTTStatus);
},
import config from './config'
import { getToken } from '@/utils/auth'
onHide() {
console.log('应用切后台断开MQTT连接');
//
disconnectMQTT();
this.globalData.mqttClient = null;
export default {
onLaunch: function() {
this.initApp()
},
methods: {
//
initApp() {
//
this.initConfig()
//
//#ifdef H5
this.checkLogin()
//#endif
},
methods: {
//
initApp() {
//
this.initConfig()
//
//#ifdef H5
this.checkLogin()
//#endif
},
initConfig() {
this.globalData.config = config
},
checkLogin() {
if (!getToken()) {
this.$tab.reLaunch('/pages/login')
}
},
// MQTT
async initGlobalMQTT() {
try {
// +
const client = await initMQTT(
this.globalData.mqttConfig,
this.globalData.mqttSubscribeList
);
//
this.globalData.mqttClient = client;
//
uni.$emit('mqtt_client_ready', client);
console.log('全局MQTT初始化成功');
} catch (err) {
console.error('全局MQTT初始化失败', err);
uni.$emit('mqtt_init_fail', err);
}
initConfig() {
this.globalData.config = config
},
checkLogin() {
if (!getToken()) {
this.$tab.reLaunch('/pages/login')
}
}
}
}
</script>
<style lang="scss">
@import '@/static/scss/index.scss';
@import '@/static/scss/index.scss'
</style>

View File

@ -359,7 +359,7 @@ export default {
//todo
// this.status[type] = this.status[type] === 0 ? 1 : 0;
// this.show[type] = this.status[type] === 0 ? "" : "";
// this.show[type] = this.status[type] === 0 ? "" : "";
}
}
@ -475,7 +475,7 @@ export default {
if (isSuccess) {
this.status[type] = this.status[type] === 0 ? 1 : 0;
this.show[type] = this.status[type] === 0 ? "运行" : "暂停";
this.show[type] = this.status[type] === 0 ? "暂停" : "运行";
}
this.deviceType = '';
this.$modal.msgSuccess("设备操作成功!")