|
@@ -32,11 +32,12 @@ App({
|
|
clientId: "wx_" + parseInt(Math.random() * 100 + 800, 10),
|
|
clientId: "wx_" + parseInt(Math.random() * 100 + 800, 10),
|
|
reconnectPeriod: 1000, //1000毫秒,两次重新连接之间的间隔
|
|
reconnectPeriod: 1000, //1000毫秒,两次重新连接之间的间隔
|
|
connectTimeout: 30 * 1000, //1000毫秒,两次重新连接之间的间隔
|
|
connectTimeout: 30 * 1000, //1000毫秒,两次重新连接之间的间隔
|
|
- resubscribe: true, //如果连接断开并重新连接,则会再次自动订阅已订阅的主题(默认true
|
|
|
|
|
|
+ resubscribe: true, //如果连接断开并重新连接,则会再次自动订阅已订阅的主题(默认true)
|
|
keepalive: 3, //每3秒发送一次心跳
|
|
keepalive: 3, //每3秒发送一次心跳
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ ///全局初始化
|
|
onLaunch() {
|
|
onLaunch() {
|
|
var that = this;
|
|
var that = this;
|
|
var userInfo = wx.getStorageSync("userInfo") || "";
|
|
var userInfo = wx.getStorageSync("userInfo") || "";
|
|
@@ -44,32 +45,29 @@ App({
|
|
that.globalData.userInfo = userInfo;
|
|
that.globalData.userInfo = userInfo;
|
|
}
|
|
}
|
|
|
|
|
|
- wx.onAppHide(() => {
|
|
|
|
- if (that.globalData.client && that.globalData.client.connected) {
|
|
|
|
- that.globalData.client.end(true);
|
|
|
|
- that.globalData.client.end(true);
|
|
|
|
- console.log("断开");
|
|
|
|
- };
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
|
|
+ ///显示界面
|
|
wx.onAppShow(() => {
|
|
wx.onAppShow(() => {
|
|
- console.log("加载")
|
|
|
|
if (that.globalData.userInfo !== null) {
|
|
if (that.globalData.userInfo !== null) {
|
|
if (that.globalData.client) {
|
|
if (that.globalData.client) {
|
|
that.globalData.client.end(true);
|
|
that.globalData.client.end(true);
|
|
- that.globalData.client.end(true);
|
|
|
|
}
|
|
}
|
|
console.log("重连");
|
|
console.log("重连");
|
|
that.connect();
|
|
that.connect();
|
|
};
|
|
};
|
|
});
|
|
});
|
|
|
|
|
|
- that.getBluetoothStatus();
|
|
|
|
|
|
+ ///界面后台化
|
|
|
|
+ wx.onAppHide(() => {
|
|
|
|
+ if (that.globalData.client && that.globalData.client.connected) {
|
|
|
|
+ that.globalData.client.end(true);
|
|
|
|
+ };
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // that.getBluetoothStatus();
|
|
//自定义导航栏 获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度)
|
|
//自定义导航栏 获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度)
|
|
wx.getSystemInfo({
|
|
wx.getSystemInfo({
|
|
success: (res) => {
|
|
success: (res) => {
|
|
let custom = wx.getMenuButtonBoundingClientRect();
|
|
let custom = wx.getMenuButtonBoundingClientRect();
|
|
-
|
|
|
|
that.globalData.navBarHeight = res.statusBarHeight + custom.height + (custom.top - res.statusBarHeight) * 2;
|
|
that.globalData.navBarHeight = res.statusBarHeight + custom.height + (custom.top - res.statusBarHeight) * 2;
|
|
that.globalData.MenuButtonheight = custom.height;
|
|
that.globalData.MenuButtonheight = custom.height;
|
|
that.globalData.MenuButtonTop = custom.top;
|
|
that.globalData.MenuButtonTop = custom.top;
|
|
@@ -84,6 +82,8 @@ App({
|
|
update.update();
|
|
update.update();
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ onHide: function () {},
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 连接设备
|
|
* 连接设备
|
|
* mqttCallback:mqtt回调统一方法
|
|
* mqttCallback:mqtt回调统一方法
|