Browse Source

feature:增加空密码的输入

zeng.chen 6 months atrás
parent
commit
be9e7fcc9e
2 changed files with 21 additions and 13 deletions
  1. 17 9
      devices/bluetooth/bt_cmd.js
  2. 4 4
      pages/setWifi/setWifi.js

+ 17 - 9
devices/bluetooth/bt_cmd.js

@@ -254,10 +254,10 @@ class BtCmd {
     }
 
     // wifi ,md5都用这个
-    static sendWiFiInfo(wifiName, pwd, changePwd) {
+    static sendWiFiInfo(wifiName, pwd) {
         // [0x22, (wifiList.length + pwdList.length + 6), 0x33, (wifiList.length), (wifiList), 0x44, (pwdList)];
 
-        if (!wifiName || !pwd) {
+        if (!wifiName) {
             return;
         }
 
@@ -267,7 +267,10 @@ class BtCmd {
         let wifiList = BtCmd.stringToUint8Array(wifiName);
 
         // 数字*3 +
-        let pwdList = BtCmd.stringToUint8Array(pwd);
+        var pwdList = [];
+        if (pwd) {
+            pwdList = BtCmd.stringToUint8Array(pwd);
+        }
         console.log("wifiList", wifiList, "pwdList", pwdList)
 
         // 16进制
@@ -285,13 +288,18 @@ class BtCmd {
             result.splice(i, 0, wifiList[j++]);
         }
 
-        // 密码
         result.splice(p, 0, 0x44);
-        result.splice(++p, 0, BtCmd.intToHex(pwdList.length));
-        p++;
-        j = 0;
-        for (let i = p; i < p + pwdList.length; i++) {
-            result.splice(i, 0, pwdList[j++]);
+        // 有密码
+        if (pwdList.length > 0) {
+            result.splice(++p, 0, BtCmd.intToHex(pwdList.length));
+            p++;
+            j = 0;
+            for (let i = p; i < p + pwdList.length; i++) {
+                result.splice(i, 0, pwdList[j++]);
+            }
+        } else {
+            p++
+            result.splice(++p, 0, BtCmd.intToHex(pwdList.length));
         }
 
         console.log("发送转换拼接数据:", result.toString());

+ 4 - 4
pages/setWifi/setWifi.js

@@ -139,9 +139,9 @@ Page({
   sendWiFiInfo(wifiName, pwd) {
     // [0x22, (wifiList.length + pwdList.length + 6), 0x33, (wifiList.length), (wifiList), 0x44, (pwdList)];
 
-    if (!wifiName || !pwd) {
+    if (!wifiName) {
       wx.showToast({
-        title: '请输入正确的账号密码',
+        title: '请输入正确的账号',
       })
       wx.hideLoading()
       return;
@@ -157,7 +157,7 @@ Page({
 
   onConfirm: function () {
     const { wifiName, wifiPassword } = this.data;
-    if (!wifiName || !wifiPassword) {
+    if (!wifiName) {
       wx.showToast({
         title: '请输入完整的Wi-Fi信息',
         icon: 'none'
@@ -194,7 +194,7 @@ Page({
   // 获取保存的 Wi-Fi 账号和密码
   getSavedWiFiInfo() {
     const wifiName = wx.getStorageSync('wifiName') || '';
-    const wifiPassword = wx.getStorageSync('wifiPassword') || '';
+    const wifiPassword = wx.getStorageSync('wifiPassword');
     this.setData({
       wifiName: wifiName,
       wifiPassword: wifiPassword