xyg пре 3 година
родитељ
комит
a411c6567d
2 измењених фајлова са 83 додато и 8 уклоњено
  1. 79 8
      light-application-wx/pages/index/index.js
  2. 4 0
      light-application-wx/pages/login/login.js

+ 79 - 8
light-application-wx/pages/index/index.js

@@ -212,17 +212,88 @@ Page({
      * 内容投屏
      */
     contentScreen: function () {
-        wx.startWifi({
+        let wifi, pass;
+        // 打开微信扫一扫
+        wx.scanCode({
+            onlyFromCamera: true,
+            scanType: 'qrCode',
             success: (res) => {
-                //{errCode:0,errMsg:startWifi:ok}
-                util.toast(JSON.stringify(res));
-                if (res.errCode == 0) {
-
-                } else {
-                    util.toast(res.errMsg);
+                console.info(res);
+                if (res.result.indexOf('WIFI') < 0) {
+                    util.toast('请扫描WIFI二维码');
+                    return;
                 }
+                wx.showLoading({
+                    title: '加载中...',
+                    mask: true
+                });
+                try {
+                    let a = res.result.split(',');
+                    wifi = a[0].split(':')[1];
+                    pass = a[1].split(':')[1];
+                } catch (error) {
+                    util.toast('请扫描WIFI二维码');
+                    return;
+                }
+                // 获取设备系统类型
+                wx.getSystemInfo({
+                    success: (res) => {
+                        console.info(res);
+                        if (!res.wifiEnabled) {
+                            wx.hideLoading();
+                            util.toast('请打开WIFI功能');
+                            return;
+                        }
+                        // 1、初始化Wi-Fi模块
+                        wx.startWifi({
+                            success: (res) => {
+                                console.info(res)
+                                if (res.errMsg == 'startWifi:ok') {
+                                    // 4、连接Wi-Fi
+                                    wx.connectWifi({
+                                        SSID: wifi,
+                                        password: pass,
+                                        success: (res) => {
+                                            console.info(res);
+                                            // 5、连接上Wi-Fi的事件回调
+                                            wx.onWifiConnected((result) => {
+                                                console.info(result);
+                                                util.toast('WIFI连接成功', 'success');
+                                            });
+                                            // wx.getConnectedWifi({
+                                            //     success: (result) => {
+                                            //         wx.hideLoading();
+                                            //         console.info(result)
+                                            //         if (result.wifi.SSID === SSID) {
+                                            //             // 连接成功
+                                            //         } else {
+                                            //             // 连接失败
+                                            //         }
+                                            //     },
+                                            // });
+                                        },
+                                        fail: (e) => {
+                                            console.info(e);
+                                            util.toast('WIFI连接失败');
+                                        }
+                                    });
+                                } else {
+                                    util.toast(res.errMsg);
+                                }
+                            },
+                            fail: (e) => { }
+                        });
+                    },
+                    fail: (e) => {
+                        util.toast('获取设备系统类型失败');
+                        return;
+                    }
+                });
             },
-            fail: (e) => { }
+            fail: (e) => {
+                util.toast('扫码失败,请重试');
+                return;
+            }
         });
     },
 

+ 4 - 0
light-application-wx/pages/login/login.js

@@ -253,6 +253,10 @@ Page({
      */
     getPhoneNumber: function (res) {
         let that = this;
+        if (!res.detail.code) {
+            util.toast('请升级微信版本');
+            return;
+        }
         //用户按了允许授权按钮
         if (res.detail.encryptedData) {
             util.post({