diff --git a/config/index.js b/config/index.js index 0214091..931f053 100644 --- a/config/index.js +++ b/config/index.js @@ -5,8 +5,8 @@ const config = { BASE_URL: 'http://192.168.2.34:8000', API_PREFIX: '', // MQTT 配置 - MQTT_HOST: '47.120.79.150', - MQTT_PORT: 8083, + MQTT_HOST: 'www.cnxhyc.com', + MQTT_PORT: 9083, MQTT_USERNAME: 'admin', MQTT_PASSWORD: '#YtvpSfCNG' }, @@ -15,8 +15,8 @@ const config = { BASE_URL: 'https://fuyuanshen.com/backend', API_PREFIX: '', // MQTT 配置 - MQTT_HOST: '47.120.79.150', - MQTT_PORT: 8083, + MQTT_HOST: 'www.cnxhyc.com', + MQTT_PORT: 9084, MQTT_USERNAME: 'admin', MQTT_PASSWORD: '#YtvpSfCNG' } diff --git a/pages.json b/pages.json index ef36294..ab44658 100644 --- a/pages.json +++ b/pages.json @@ -178,26 +178,26 @@ } }, { - "path": "pages/6170/allShare/index", + "path": "pages/common/allShare/index", "style": { "navigationBarTitleText": "所有分享" } }, { - "path": "pages/6170/share/index", + "path": "pages/common/share/index", "style": { "navigationBarTitleText": "分享" } }, { - "path": "pages/6170/shareDevices/index", + "path": "pages/common/shareDevices/index", "style": { "navigationBarTitleText": "分享设备" } }, { - "path": "pages/6170/shareManagement/index", + "path": "pages/common/shareManagement/index", "style": { "navigationBarTitleText": "分享管理" } diff --git a/pages/6170/deviceControl/index.vue b/pages/6170/deviceControl/index.vue index 6a5d9ea..31b2306 100644 --- a/pages/6170/deviceControl/index.vue +++ b/pages/6170/deviceControl/index.vue @@ -757,7 +757,7 @@ // 分享 shareUp() { uni.navigateTo({ - url: '/pages/6170/share/index', + url: '/pages/common/share/index', events: { ack: function(data) {} }, diff --git a/pages/6170/allShare/index.vue b/pages/common/allShare/index.vue similarity index 100% rename from pages/6170/allShare/index.vue rename to pages/common/allShare/index.vue diff --git a/pages/6170/share/index.vue b/pages/common/share/index.vue similarity index 94% rename from pages/6170/share/index.vue rename to pages/common/share/index.vue index f3ff6ca..98fdbe8 100644 --- a/pages/6170/share/index.vue +++ b/pages/common/share/index.vue @@ -25,7 +25,7 @@ // 分享设备 shareDevice(){ uni.navigateTo({ - url: '/pages/6170/shareDevices/index', + url: '/pages/common/shareDevices/index', events: { ack: function(data) {} }, @@ -39,7 +39,7 @@ // 分享管理 shareManagement(){ uni.navigateTo({ - url: '/pages/6170/shareManagement/index', + url: '/pages/common/shareManagement/index', events: { ack: function(data) {} }, diff --git a/pages/6170/shareDevices/index.vue b/pages/common/shareDevices/index.vue similarity index 99% rename from pages/6170/shareDevices/index.vue rename to pages/common/shareDevices/index.vue index fcc8ac6..98c087c 100644 --- a/pages/6170/shareDevices/index.vue +++ b/pages/common/shareDevices/index.vue @@ -227,7 +227,7 @@ handleBtn() { this.shareShow = false uni.navigateTo({ - url: '/pages/6170/allShare/index' + url: '/pages/common/allShare/index' }) }, }, diff --git a/pages/6170/shareManagement/index.vue b/pages/common/shareManagement/index.vue similarity index 99% rename from pages/6170/shareManagement/index.vue rename to pages/common/shareManagement/index.vue index 36c96a5..e12d150 100644 --- a/pages/6170/shareManagement/index.vue +++ b/pages/common/shareManagement/index.vue @@ -171,8 +171,10 @@ }, // 跳转分享详情 handleFile(item) { + let url = item.detailPageUrl; + console.log(item,'item'); uni.navigateTo({ - url: "/pages/6170/deviceControl/index", + url: url, success: (res) => { // 页面跳转成功后的回调函数 res.eventChannel.emit('detailData', { diff --git a/utils/mqtt.js b/utils/mqtt.js index c036f94..1fdfafb 100644 --- a/utils/mqtt.js +++ b/utils/mqtt.js @@ -117,19 +117,20 @@ */ import Paho from 'paho-mqtt'; import allConfigs from '../config/index.js'; - // 根据环境选择正确的配置 -const env = 'production'; //production //开发of线上 改这里就行 -const config = allConfigs[env]; +const env = 'production'; //production development +const envConfig = allConfigs[env]; +const mqttProtocol = env === 'production' ? 'wss' : 'ws'; +const useSSL = env === 'production'; class MqttClient { constructor() { this.client = null; this.options = { - host: config.MQTT_HOST, - port: config.MQTT_PORT, + host: envConfig.MQTT_HOST, + port: envConfig.MQTT_PORT, clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8), - username: config.MQTT_USERNAME, - password: config.MQTT_PASSWORD, + username: envConfig.MQTT_USERNAME, + password: envConfig.MQTT_PASSWORD, }; this.onConnectCallback = null; this.messageCallbacks = new Map(); @@ -170,7 +171,7 @@ class MqttClient { potentialJsons.forEach(jsonString => { if (jsonString.trim() === '') return; if (this.messageCallbacks.has(topic)) { - this.messageCallbacks.get(topic)(jsonString,message); + this.messageCallbacks.get(topic)(jsonString, message); } }); }; @@ -189,16 +190,18 @@ class MqttClient { this.manualDisconnect = false; this.onConnectCallback = onConnectCallback; - - console.log(`正在连接MQTT: ${this.options.host}:${this.options.port}/mqtt`); - + console.log(`环境识别,http https:${env}`, { + connectUrl: `${mqttProtocol}://${this.options.host}:${this.options.port}/mqtt`, + useSSL: useSSL, + clientId: this.options.clientId + }); try { const connectOptions = { timeout: 10, // 增加连接超时时间,应对网络波动 keepAliveInterval: 30, // 明确设置心跳间隔为30秒 userName: this.options.username, password: this.options.password, - useSSL: false, + useSSL: useSSL, //http ws https wss开启 cleanSession: true, onSuccess: () => { console.log('MQTT连接成功');