123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- 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;
- },
- })
|