Browse Source

feature:修改壁纸的替换,排序问题

zeng.chen 6 months ago
parent
commit
65afd23d24
3 changed files with 98 additions and 39 deletions
  1. 10 9
      pages/piano/cropper/cropper.js
  2. 38 28
      pages/piano/wallpaper/wallpaper.js
  3. 50 2
      pages/setWifi/setWifi.js

+ 10 - 9
pages/piano/cropper/cropper.js

@@ -379,9 +379,9 @@ Page({
     let lowByte = value & 0xFF;
     return { highByte, lowByte };
   },
-  async sendImage(index) {
+  async sendImage() {
     let _this = this
-
+    let index = _this.data._imgIndex
     wx.hideLoading()
     let chunks = _this.data._chunks
 
@@ -406,7 +406,7 @@ Page({
     _this.data._imgNext += (chunk.byteLength ?? chunk.length);
 
     console.log("发送壁纸数据1:", index, ":", _this.data._imgNext, ":", chunk.length, ":", chunk.byteLength, ":", total, chunks.length)
-
+    _this.data._imgIndex += 1;
     let res = await btHelper.wallPaperSyncData(chunk);
     // let res = true;
     // btHelper.wallPaperData(chunk);
@@ -417,9 +417,8 @@ Page({
         showCancel: false
       })
       _this.endImage(2)
+      return
     }
-
-    _this.data._imgIndex += 1;
     _this.updateProgress(_this.data._imgNext, total);
     // }, 30);
   },
@@ -484,6 +483,7 @@ Page({
 
   },
   failSend(showToast) {
+    console.log('failSend')
     let _this = this
     _this.data._chunks = []
     _this.data._imgMD5 = null
@@ -497,7 +497,7 @@ Page({
       //   showCancel: false
       // })
       wx.showToast({
-        title: '发送图片败',
+        title: '发送图片败',
         icon: 'error'
       })
     }
@@ -603,9 +603,10 @@ Page({
         case EnumCmdEvent.wallPaperMD5:
           // 0x80
           console.log("开始发送MD5回复", kind, value)
-          // 收到回复md5,开始发送图片
+          // 收到回复md5,开始发送图片的第一片
           if (kind == 1 && value === 1) {
-            _this.sendImage(0)
+            _this.data._imgIndex = 0
+            _this.sendImage(_this.data._imgIndex)
           } else if (kind == 0 && value === 3) {
             _this.failSend(false)
             wx.showModal({
@@ -623,7 +624,7 @@ Page({
           break;
         case EnumCmdEvent.wallPaperData:
           // 0x79
-          // 收到回复md5,开始发送图片
+          // 收到回复md5,开始发送图片后面N片
           if (kind == 1 && value === 1) {
             _this.sendImage(_this.data._imgIndex)
           } else {

+ 38 - 28
pages/piano/wallpaper/wallpaper.js

@@ -33,7 +33,8 @@ Page({
     },
     imageList: [],
     image4List: [],
-    _locImageList: [],
+    _allImageList: [],
+    _netImageList: [],
     selectIndex: 0,
     _localImgPicKey: "_localImgPicListKey",
     navbarData: {
@@ -82,18 +83,20 @@ Page({
     let _this = this;
     deviceWallPaper().then(res => {
       let data = res ?? []
+      // 网络的
+      _this.data._netImageList = data;
 
       let localImgList = store.getStore(_this.data._localImgPicKey);
-      console.log("壁纸列表", data.length, localImgList, "空");
-
+      console.log("壁纸列表", data.length, "空", localImgList);
+      let allImgs = []
       if (localImgList) {
-        console.log("壁纸列表2", res.length, localImgList, "空");
-        data = localImgList.concat(data)
+        console.log("壁纸列表2", res.length, "空", localImgList, "空");
+        allImgs = localImgList.concat(data)
       }
-      _this.data._locImageList = data;
+      _this.data._allImageList = allImgs;
       _this.setData({
-        imageList: _this.data._locImageList,
-        image4List: _this.data._locImageList.slice(0, 4),
+        imageList: _this.data._allImageList,
+        image4List: _this.data._allImageList.slice(0, 4),
         // topImg: data[0] ?? {}
       })
 
@@ -102,40 +105,47 @@ Page({
   async updateTopImg(topUrl) {
     let _this = this;
 
-    // let hasImg = _this.data.imageList.find(function (vForItem) {
-    //   return vForItem.pic == topUrl;
-    // })
-    // if (!hasImg) {
     let newImg = {
       "pic": topUrl, "id": "0"
     }
     let myImgList = store.getStore(_this.data._localImgPicKey)
     myImgList = myImgList ?? []
-    let myIndex = myImgList.findIndex(img => img.pic === findImg.pic);
-    if (myIndex < 0) {
-      myImgList.unshift(newImg)
-    }
+    console.log("updateTopImg1", imgList, myImgList)
+
+    // 移除保存的重复图片
+    let myIndex = myImgList.findIndex(img => img.pic === topUrl);
 
-    let imgList = _this.data._locImageList
-    console.log("updateTopImg1", imgList)
+
+    let imgList = _this.data._netImageList
+    // 移除网络的重复图片
     let findImg = imgList.find(function (img) { return img.pic === topUrl })
     console.log("updateTopImg3", findImg)
     if (findImg) {
-      let index = imgList.findIndex(img => img.pic === findImg.pic);
-      imgList.splice(index, 1);
-      imgList.unshift(findImg);
+      // 官方不动位置
+      // let index = imgList.findIndex(img => img.pic === findImg.pic);
+      // imgList.splice(index, 1);
+      // imgList.unshift(findImg);
     } else {
-      imgList.unshift(newImg)
+      if (myIndex < 0) {
+        // 不是官方的壁纸,才添加进缓存
+        myImgList.unshift(newImg)
+        console.log("updateTopImg5", myImgList.length)
+
+      }
     }
-    console.log("updateTopImg2", imgList, findImg)
 
-    if (imgList.length > 10) {
-      imgList.pop()
+    if (myImgList.length > 1) {
+      console.log("updateTopImg4", myImgList.length)
+      // 本地图片缓存最多保存1张, 10张
+      myImgList.pop()
     }
-    _this.data._locImageList = imgList
+
+    console.log("updateTopImg2", imgList, findImg)
+    _this.data._allImageList = myImgList.concat(imgList);
+
     _this.setData({
-      imageList: _this.data._locImageList,
-      image4List: _this.data._locImageList.slice(0, 4),
+      imageList: _this.data._allImageList,
+      image4List: _this.data._allImageList.slice(0, 4),
       topImg: newImg
     })
     store.setStore(_this.data._localImgPicKey, myImgList)

+ 50 - 2
pages/setWifi/setWifi.js

@@ -39,6 +39,27 @@ Page({
       });
       return;
     }
+
+    const res = wx.getSystemInfoSync(); // 获取系统信息
+    /// android ios
+    const platform = res.platform; // 获取平台类型
+    console.log("平台类型", platform, getApp().globalData.scopeBluetooth, platform === 'ios' && !getApp().globalData.scopeBluetooth);
+    if (platform === 'ios') {
+      getApp().getBluetoothStatus()
+      return
+    }
+
+    that.getWifiName()
+  },
+  getBluetoothStatusCallck(v) {
+    if (v) {
+      console.log("获取蓝牙权限成功");
+      this.getWifiName()
+    }
+  },
+
+  getWifiName() {
+    var that = this;
     wx.startWifi({
       success(res) {
         console.log(res.errMsg)
@@ -60,10 +81,37 @@ Page({
           }
         });
 
-      }
-    })
+        // wx.getWifiList({
+        //   success: function (res) {
+        //     let wifiList = res.wifiList ?? [];
+        //     console.log('已连接的 Wi-Fi 列表:', res);
 
+        //     // 检查是否有已连接的 Wi-Fi
+        //     const connectedWifi = wifiList.find(wifi => wifi.SSID && wifi.connected);
+        //     if (connectedWifi) {
+        //       const wifiName = connectedWifi.SSID;
+        //       that.setData({
+        //         wifiName: wifiName
+        //       });
+        //     } else {
+        //       console.error('当前没有连接到 Wi-Fi');
+        //       wx.showToast({
+        //         title: '当前没有连接到 Wi-Fi',
+        //         icon: 'none'
+        //       });
+        //     }
+        //   },
+        //   fail: function (err) {
+        //     console.error('获取 Wi-Fi 列表失败', err);
+        //     wx.showToast({
+        //       title: '获取 Wi-Fi 列表失败',
+        //       icon: 'none'
+        //     });
+        //   }
+        // });
 
+      }
+    })
   },
 
   onWifiNameInput: function (e) {