const constant = require('../../../utils/constant.js'); Page({ data: { nvabarData: { showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示 title: '设置网络', //导航栏 中间的标题 }, scopeBluetooth: constant.app.globalData.scopeBluetooth, isShowPwd: false, is5GWifi: false, isIOS: false, ssid: "", pwdData: "", connectDevice: "", is5gDevice: false, }, onLoad(options) { var that = this; var param = options.param; that.data.connectDevice = param; var device = JSON.parse(param); var typeList = device.typeList; if (!constant.strings.isEmpty(typeList)) { var targetList = typeList.filter((v) => v.connectType == 3); if (!constant.strings.isEmpty(targetList)) { /// 字段,含义为是否支持5G:1-是 0-否; var is5g = targetList[0].is5g; if (is5g == 1) { that.setData({ is5gDevice: true, }); } } } const res = wx.getSystemInfoSync(); // 获取系统信息 /// android ios const platform = res.platform; // 获取平台类型 this.setData({ isIOS: platform === 'ios', isShowPwd: true, }); }, onShow() { var that = this; that.getWifiStatus(); }, getBluetoothStatus() { constant.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); } }, ///Wifi名称 setPwd: function (e) { console.log("设置密码:", e.detail.value) var that = this; 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, }); }; constant.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; }; constant.app.globalData.ssid = that.data.ssid; constant.app.globalData.pwdData = that.data.pwdData; var param = "?param=" + that.data.connectDevice; constant.routeUtil.jumpParam(constant.routePath.deviceConnect2, param); }, notRoter() { wx.navigateBack({ delta: 1 }); }, showPwd() { var that = this; that.setData({ isShowPwd: !that.data.isShowPwd }) }, onUnload: function () { var that = this; }, })