// pages/deviceConnect0/deviceConnect0.ts const app = getApp(); Page({ /** * 页面的初始数据 */ data: { scopeBluetooth: app.globalData.scopeBluetooth, isShowPwd: false, is5GWifi: false, ssid: "", pwdData: "", pwdData1: "", nvabarData: { showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示 title: '设置网络', //导航栏 中间的标题 }, }, /** * 生命周期函数--监听页面加载 */ onLoad() { }, getBluetoothStatus() { app.getBluetoothStatus(); }, setPwd: function (e) { app.globalData.pwdData = e.detail.value; this.setData({ pwdData: e.detail.value, }); }, setSsid: function (e) { let str = false; if(e.detail.value.indexOf("5G") !== -1) { str = true; }; this.setData({ ssid: e.detail.value, is5GWifi: str }); }, getWifiStatus(){ const _this = this; wx.getNetworkType({ success (res) { if(res.networkType === "wifi") { wx.startWifi({ success(res) { //获取当前已连接wifi名 wx.getConnectedWifi({ success: function (res) { // 5Gwifi if(res.wifi.SSID.indexOf("5G") !== -1) { _this.setData({ is5GWifi: true }); } else { _this.setData({ is5GWifi: false }); }; _this.setData({ ssid: res.wifi.SSID, }); app.globalData.ssid = res.wifi.SSID; wx.getStorage({ key: 'wifiInfo', success (wifiInfo) { const resData = JSON.parse(wifiInfo.data); if(resData.ssid === res.wifi.SSID) { _this.setData({ pwdData: resData.password, }); } } }) }, }) } }) } } }) }, next(){ if(this.data.ssid === ""){ wx.showToast({ title: '请输入WIFI名称', icon: 'none', duration: 2000 }) return; }; if(this.data.pwdData === ""){ wx.showToast({ title: '请输入WIFI密码', icon: 'none', duration: 2000 }) return; }; app.globalData.ssid = this.data.ssid; app.globalData.pwdData = this.data.pwdData; wx.navigateTo({ url: './../deviceConnect2/deviceConnect2', }) }, notRoter(){ wx.navigateBack({ delta: 1 }); }, showPwd() { this.setData({ isShowPwd: !this.data.isShowPwd }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { this.getWifiStatus(); }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })