进度条加载
This commit is contained in:
@ -912,7 +912,18 @@
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
handleMqttLost() {
|
||||
this.Progress = {
|
||||
...this.Progress,
|
||||
show: false, // 隐藏进度条
|
||||
};
|
||||
uni.showToast({
|
||||
title: '网络异常',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
onLoad(options) {
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
@ -973,9 +984,10 @@
|
||||
this.selectedImage = ''; // 清空已选图片
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
})
|
||||
// 设置连接丢失回调
|
||||
uni.$on('mqttConnectionLost', this.handleMqttLost);
|
||||
if (this.apiType === 'listA') {
|
||||
this.fetchDeviceDetail(data.data.id)
|
||||
} else {
|
||||
@ -995,6 +1007,10 @@
|
||||
if (this.mqttClient) {
|
||||
this.mqttClient.disconnect();
|
||||
}
|
||||
uni.$off('mqttConnectionLost', this.handleMqttLost);
|
||||
if (this.mqttClient) {
|
||||
this.mqttClient.disconnect();
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
|
@ -26,8 +26,11 @@
|
||||
const errText = JSON.stringify(err) || "Empty error object";
|
||||
console.error(`uni.connectSocket 失败: ${errText}`);
|
||||
if (this.onerror) {
|
||||
const errorMessage = (err && err.errMsg) ? err.errMsg : "uni.connectSocket call failed";
|
||||
this.onerror({ message: errorMessage });
|
||||
const errorMessage = (err && err.errMsg) ? err.errMsg :
|
||||
"uni.connectSocket call failed";
|
||||
this.onerror({
|
||||
message: errorMessage
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -53,22 +56,29 @@
|
||||
console.error(`WebSocket polyfill 错误: ${errText}`);
|
||||
if (this.onerror) {
|
||||
// Paho expects an object that can be stringified, not a real Error object.
|
||||
const errorMessage = (err && err.errMsg) ? err.errMsg : "WebSocket connection failed in uni-app";
|
||||
this.onerror({ message: errorMessage });
|
||||
const errorMessage = (err && err.errMsg) ? err.errMsg :
|
||||
"WebSocket connection failed in uni-app";
|
||||
this.onerror({
|
||||
message: errorMessage
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
socketTask.onMessage((res) => {
|
||||
if (this.onmessage) {
|
||||
// Paho 期望事件对象有一个 'data' 属性
|
||||
this.onmessage({ data: res.data });
|
||||
this.onmessage({
|
||||
data: res.data
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
send(data) {
|
||||
if (this.readyState === WebSocket.OPEN) {
|
||||
this._socketTask.send({ data: data });
|
||||
this._socketTask.send({
|
||||
data: data
|
||||
});
|
||||
} else {
|
||||
console.error('WebSocket polyfill: send() 在非 OPEN 状态下被调用。');
|
||||
throw new Error('WebSocket is not open');
|
||||
@ -109,7 +119,7 @@ import Paho from 'paho-mqtt';
|
||||
import allConfigs from '../config/index.js';
|
||||
|
||||
// 根据环境选择正确的配置
|
||||
const env = 'development';//production //开发of线上 改这里就行
|
||||
const env = 'production'; //production //开发of线上 改这里就行
|
||||
const config = allConfigs[env];
|
||||
|
||||
class MqttClient {
|
||||
@ -145,7 +155,11 @@ class MqttClient {
|
||||
this.client.onConnectionLost = (responseObject) => {
|
||||
if (responseObject.errorCode !== 0) {
|
||||
console.log("MQTT连接丢失: " + responseObject.errorMessage);
|
||||
// 可以在此添加重连逻辑
|
||||
// 发送全局事件
|
||||
uni.$emit('mqttConnectionLost', {
|
||||
error: responseObject.errorMessage,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -192,7 +206,9 @@ class MqttClient {
|
||||
subscribe(topic, onMessageCallback) {
|
||||
if (this.client && this.client.isConnected()) {
|
||||
console.log(`尝试订阅主题: ${topic}`);
|
||||
this.client.subscribe(topic, { qos: 1 });
|
||||
this.client.subscribe(topic, {
|
||||
qos: 1
|
||||
});
|
||||
// 存储该主题的回调函数
|
||||
this.messageCallbacks.set(topic, onMessageCallback);
|
||||
} else {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import config from '../config/index.js';
|
||||
const env = 'development'; //production development //开发of线上 改这里就行
|
||||
const env = 'production'; //production development //开发of线上 改这里就行
|
||||
const BASE = config[env];
|
||||
const request = (options) => {
|
||||
console.log("options"+JSON.stringify(options),BASE.BASE_URL)
|
||||
|
Reference in New Issue
Block a user