|
@@ -10,13 +10,13 @@ Page({
|
|
* 页面的初始数据
|
|
* 页面的初始数据
|
|
*/
|
|
*/
|
|
data: {
|
|
data: {
|
|
- scopeBluetooth: app.globalData.scopeBluetooth,
|
|
|
|
- ssid: app.globalData.ssid,
|
|
|
|
- password: app.globalData.pwdData,
|
|
|
|
nvabarData: {
|
|
nvabarData: {
|
|
showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
|
|
showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
|
|
title: '连接配网', //导航栏 中间的标题
|
|
title: '连接配网', //导航栏 中间的标题
|
|
},
|
|
},
|
|
|
|
+ scopeBluetooth: app.globalData.scopeBluetooth,
|
|
|
|
+ ssid: app.globalData.ssid,
|
|
|
|
+ password: app.globalData.pwdData,
|
|
version: '2.0',
|
|
version: '2.0',
|
|
name: '',
|
|
name: '',
|
|
connectedDeviceId: '',
|
|
connectedDeviceId: '',
|
|
@@ -27,10 +27,10 @@ Page({
|
|
percent: 0,
|
|
percent: 0,
|
|
ruterStatus: 0, // 0 连接中 // 1 成功 // 2失败
|
|
ruterStatus: 0, // 0 连接中 // 1 成功 // 2失败
|
|
},
|
|
},
|
|
- onShow: function(options) {
|
|
|
|
|
|
+ onShow: function (options) {
|
|
|
|
|
|
},
|
|
},
|
|
- onLoad: function(options) {
|
|
|
|
|
|
+ onLoad: function (options) {
|
|
_this = this;
|
|
_this = this;
|
|
_this.setData({
|
|
_this.setData({
|
|
name: options.name,
|
|
name: options.name,
|
|
@@ -40,8 +40,8 @@ Page({
|
|
xBlufi.notifyInitBleEsp32({
|
|
xBlufi.notifyInitBleEsp32({
|
|
deviceId: options.deviceId,
|
|
deviceId: options.deviceId,
|
|
});
|
|
});
|
|
- percentIn = setInterval(()=> {
|
|
|
|
- if(_this.data.percent === 100) {
|
|
|
|
|
|
+ percentIn = setInterval(() => {
|
|
|
|
+ if (_this.data.percent === 100) {
|
|
clearInterval(percentIn);
|
|
clearInterval(percentIn);
|
|
_this.setData({
|
|
_this.setData({
|
|
ruterStatus: 2
|
|
ruterStatus: 2
|
|
@@ -54,7 +54,7 @@ Page({
|
|
});
|
|
});
|
|
}, 600);
|
|
}, 600);
|
|
},
|
|
},
|
|
- onUnload: function() {
|
|
|
|
|
|
+ onUnload: function () {
|
|
// 关闭蓝牙连接
|
|
// 关闭蓝牙连接
|
|
let _this = this
|
|
let _this = this
|
|
xBlufi.notifyConnectBle({
|
|
xBlufi.notifyConnectBle({
|
|
@@ -66,10 +66,10 @@ Page({
|
|
clearTimeout(errTi);
|
|
clearTimeout(errTi);
|
|
clearInterval(percentIn);
|
|
clearInterval(percentIn);
|
|
},
|
|
},
|
|
- funListenDeviceMsgEvent: function(options) {
|
|
|
|
|
|
+ funListenDeviceMsgEvent: function (options) {
|
|
let _this = this;
|
|
let _this = this;
|
|
switch (options.type) {
|
|
switch (options.type) {
|
|
-
|
|
|
|
|
|
+
|
|
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
|
|
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
|
|
_this.setData({
|
|
_this.setData({
|
|
connected: options.result
|
|
connected: options.result
|
|
@@ -79,7 +79,7 @@ Page({
|
|
title: '很抱歉提醒你!',
|
|
title: '很抱歉提醒你!',
|
|
content: '小程序与设备异常断开',
|
|
content: '小程序与设备异常断开',
|
|
showCancel: false, //是否显示取消按钮
|
|
showCancel: false, //是否显示取消按钮
|
|
- success: function(res) {
|
|
|
|
|
|
+ success: function (res) {
|
|
wx.navigateBack({
|
|
wx.navigateBack({
|
|
delta: 1
|
|
delta: 1
|
|
});
|
|
});
|
|
@@ -92,16 +92,16 @@ Page({
|
|
case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_ROUTER_RESULT:
|
|
case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_ROUTER_RESULT:
|
|
wx.hideLoading();
|
|
wx.hideLoading();
|
|
if (!options.result)
|
|
if (!options.result)
|
|
- errTi = setTimeout(()=> {
|
|
|
|
|
|
+ errTi = setTimeout(() => {
|
|
_this.setData({
|
|
_this.setData({
|
|
ruterStatus: 2
|
|
ruterStatus: 2
|
|
});
|
|
});
|
|
clearTimeout(errTi);
|
|
clearTimeout(errTi);
|
|
clearInterval(percentIn);
|
|
clearInterval(percentIn);
|
|
}, 5000);
|
|
}, 5000);
|
|
-
|
|
|
|
|
|
+
|
|
else {
|
|
else {
|
|
-
|
|
|
|
|
|
+
|
|
// 配网成功
|
|
// 配网成功
|
|
if (options.data.progress == 100) {
|
|
if (options.data.progress == 100) {
|
|
clearTimeout(errTi);
|
|
clearTimeout(errTi);
|
|
@@ -109,34 +109,50 @@ Page({
|
|
// 更新数据
|
|
// 更新数据
|
|
wx.getStorage({
|
|
wx.getStorage({
|
|
key: 'devicelist',
|
|
key: 'devicelist',
|
|
- success (res) {
|
|
|
|
- if(res.data) {
|
|
|
|
|
|
+ success(res) {
|
|
|
|
+ if (res.data) {
|
|
let arr = JSON.parse(res.data);
|
|
let arr = JSON.parse(res.data);
|
|
|
|
+
|
|
|
|
+ console.log("gadsfadsfadsfa==00===" + JSON.stringify(arr));
|
|
|
|
+ console.log("gadsfadsfadsfa==aa===" + _this.data.name);
|
|
// 同一个设备
|
|
// 同一个设备
|
|
- const devicelist = arr.filter((v)=> v.deviceId === _this.data.name);
|
|
|
|
- if(devicelist.length > 0) {
|
|
|
|
- arr = arr.filter((v)=> v.deviceId !== _this.data.name);
|
|
|
|
|
|
+ const devicelist = arr.filter((v) => v.deviceId === _this.data.name);
|
|
|
|
+
|
|
|
|
+ console.log("gadsfadsfadsfa==11===" + JSON.stringify(arr));
|
|
|
|
+ if (devicelist.length > 0) {
|
|
|
|
+ arr = arr.filter((v) => v.deviceId !== _this.data.name);
|
|
|
|
+ console.log("gadsfadsfadsfa==222===" + JSON.stringify(arr));
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+ // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online"}]
|
|
arr.unshift({
|
|
arr.unshift({
|
|
|
|
+ /// Wifi mqtt-连接
|
|
|
|
+ connectType: 3,
|
|
deviceId: _this.data.name,
|
|
deviceId: _this.data.name,
|
|
name: _this.data.name,
|
|
name: _this.data.name,
|
|
state: "online"
|
|
state: "online"
|
|
});
|
|
});
|
|
- wx.setStorage({
|
|
|
|
- key:"devicelist",
|
|
|
|
- data: JSON.stringify(arr),
|
|
|
|
- success() {
|
|
|
|
- _this.setData({
|
|
|
|
- percent: 100,
|
|
|
|
- ruterStatus: 1
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+
|
|
|
|
+ getCurrentPages()[0].addConnectWifiDevice(arr);
|
|
|
|
+ _this.setData({
|
|
|
|
+ percent: 100,
|
|
|
|
+ ruterStatus: 1
|
|
|
|
+ });
|
|
|
|
+ // wx.setStorage({
|
|
|
|
+ // key: "devicelist",
|
|
|
|
+ // data: JSON.stringify(arr),
|
|
|
|
+ // success() {
|
|
|
|
+ // _this.setData({
|
|
|
|
+ // percent: 100,
|
|
|
|
+ // ruterStatus: 1
|
|
|
|
+ // });
|
|
|
|
+ // }
|
|
|
|
+ // })
|
|
}
|
|
}
|
|
},
|
|
},
|
|
fail() {
|
|
fail() {
|
|
wx.setStorage({
|
|
wx.setStorage({
|
|
- key:"devicelist",
|
|
|
|
|
|
+ key: "devicelist",
|
|
data: JSON.stringify([{
|
|
data: JSON.stringify([{
|
|
name: _this.data.name,
|
|
name: _this.data.name,
|
|
deviceId: _this.data.name,
|
|
deviceId: _this.data.name,
|
|
@@ -153,8 +169,11 @@ Page({
|
|
})
|
|
})
|
|
// 记住密码
|
|
// 记住密码
|
|
wx.setStorage({
|
|
wx.setStorage({
|
|
- key:"wifiInfo",
|
|
|
|
- data: JSON.stringify({"password": app.globalData.pwdData, "ssid": app.globalData.ssid})
|
|
|
|
|
|
+ key: "wifiInfo",
|
|
|
|
+ data: JSON.stringify({
|
|
|
|
+ "password": app.globalData.pwdData,
|
|
|
|
+ "ssid": app.globalData.ssid
|
|
|
|
+ })
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -178,7 +197,7 @@ Page({
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- OnClickStart: function() {
|
|
|
|
|
|
+ OnClickStart: function () {
|
|
if (!app.globalData.ssid) {
|
|
if (!app.globalData.ssid) {
|
|
wx.showToast({
|
|
wx.showToast({
|
|
title: 'SSID不能为空',
|
|
title: 'SSID不能为空',
|
|
@@ -199,26 +218,26 @@ Page({
|
|
password: app.globalData.pwdData
|
|
password: app.globalData.pwdData
|
|
});
|
|
});
|
|
},
|
|
},
|
|
- bindPasswordInput: function(e) {
|
|
|
|
|
|
+ bindPasswordInput: function (e) {
|
|
this.setData({
|
|
this.setData({
|
|
password: e.detail.value
|
|
password: e.detail.value
|
|
})
|
|
})
|
|
},
|
|
},
|
|
- bindCustomDataInput: function(e) {
|
|
|
|
|
|
+ bindCustomDataInput: function (e) {
|
|
this.setData({
|
|
this.setData({
|
|
customData: e.detail.value
|
|
customData: e.detail.value
|
|
})
|
|
})
|
|
},
|
|
},
|
|
- egen(){
|
|
|
|
|
|
+ egen() {
|
|
wx.navigateBack({
|
|
wx.navigateBack({
|
|
delta: 1
|
|
delta: 1
|
|
})
|
|
})
|
|
},
|
|
},
|
|
- goIndex(){
|
|
|
|
|
|
+ goIndex() {
|
|
// BLUFI_7cdfa1fd3cfc
|
|
// BLUFI_7cdfa1fd3cfc
|
|
app.globalData.newDeviceId = this.data.name;
|
|
app.globalData.newDeviceId = this.data.name;
|
|
- wx.redirectTo({
|
|
|
|
- url: '/pages/index/index'
|
|
|
|
- });
|
|
|
|
|
|
+ wx.redirectTo({
|
|
|
|
+ url: '/pages/index/index'
|
|
|
|
+ });
|
|
}
|
|
}
|
|
})
|
|
})
|