const app = getApp(); import routeUtil from '../../../utils/routeUtil.js'; import routePath from '../../../utils/routePath.js' Page({ data: { nvabarData: { showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示 title: '设置网络', //导航栏 中间的标题 }, scopeBluetooth: app.globalData.scopeBluetooth, isShowPwd: false, is5GWifi: false, ssid: "", pwdData: "", connectDevice: "", }, onLoad(options) { var that = this; var param = options.param; that.data.connectDevice = param; }, onShow() { var that = this; that.getWifiStatus(); }, getBluetoothStatus() { app.getBluetoothStatus(); }, ///Wifi名称 setSsid: function (e) { var that = this; let str = false; if (e.detail.value.indexOf("5G") !== -1) { str = true; }; that.setData({ ssid: e.detail.value, is5GWifi: str }); }, onFocus(event) { console.log("onFocus:", event) if (event.detail.value !== this.data.pwdData) { this.setPwd(event); } }, onBlur(event) { console.log("onBlur", event) if (event.detail.value !== this.data.pwdData) { this.setPwd(event); } }, ///Wifi名称 setPwd: function (e) { console.log("设置密码:", e.detail.value) var that = this; app.globalData.pwdData = e.detail.value; that.setData({ pwdData: e.detail.value, }); }, ///获取网络状态 getWifiStatus() { var that = this; wx.getNetworkType({ success(res) { if (res.networkType === "wifi") { wx.startWifi({ success(res) { //获取当前已连接wifi名 wx.getConnectedWifi({ success: function (res) { var ssid = res.wifi.SSID; // 5Gwifi if (res.wifi.SSID.indexOf("5G") !== -1) { that.setData({ is5GWifi: true, ssid: ssid, }); } else { that.setData({ is5GWifi: false, ssid: ssid, }); }; app.globalData.ssid = ssid; wx.getStorage({ key: 'wifiInfo', success(wifiRes) { console.log("wifiInfo:", wifiRes) const resData = JSON.parse(wifiRes.data ?? "{}") ?? {}; console.log("wifiInfo2:", resData) if (resData.ssid === res.wifi.SSID) { that.setData({ pwdData: resData.password ?? "", }); } } }) }, }) } }) } } }) }, ///下一步 next() { var that = this; if (that.data.ssid === "") { wx.showToast({ title: '请输入WIFI名称', icon: 'none', duration: 2000 }) return; }; // if (that.data.pwdData === "") { // wx.showToast({ // title: '请输入WIFI密码', // icon: 'none', // duration: 2000 // }) // return; // }; app.globalData.ssid = that.data.ssid; app.globalData.pwdData = that.data.pwdData; var param = "?param=" + that.data.connectDevice; routeUtil.jumpParam(routePath.deviceConnect2, param); }, notRoter() { wx.navigateBack({ delta: 1 }); }, showPwd() { var that = this; that.setData({ isShowPwd: !that.data.isShowPwd }) }, })