123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- 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;
- routeUtil.jumpParam(routePath.deviceConnect2, that.data.connectDevice);
- },
- notRoter() {
- wx.navigateBack({
- delta: 1
- });
- },
- showPwd() {
- var that = this;
- that.setData({
- isShowPwd: !that.data.isShowPwd
- })
- },
- })
|