Browse Source

Merge branch 'develop/3.2.4_黑胶' into develop/3.2.4

* develop/3.2.4_黑胶:
  feature:修改首页蓝牙的判断
  feature:修改图片裁剪的方法,删除不用的类
zeng.chen 7 months ago
parent
commit
0efce2b268

+ 0 - 1
app.json

@@ -19,7 +19,6 @@
     "pages/deviceDetail/detail",
     "pages/deviceDetail/detail",
     "pages/piano/wallpaper/wallpaper",
     "pages/piano/wallpaper/wallpaper",
     "pages/ota/ota",
     "pages/ota/ota",
-    "pages/blueDemos/blueDemos",
     "pages/piano/cropper/cropper"
     "pages/piano/cropper/cropper"
   ],
   ],
   "window": {
   "window": {

+ 6 - 105
devices/ble_manager.js

@@ -94,10 +94,14 @@ class bleManager {
             var temp = res.devices[i];
             var temp = res.devices[i];
             //            if (temp.name == "MW-SR1(4G_WIFI)") {
             //            if (temp.name == "MW-SR1(4G_WIFI)") {
             //            }
             //            }
+            // if (temp.name != null) {
+            //   console.log("2222", temp.name);
+            // }
             if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
             if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
               temp.mac = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
               temp.mac = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
+              temp.mac2 = that.ab2hex(temp.advertisData ?? "")
               // if (that.callBackConnect != null) {
               // if (that.callBackConnect != null) {
-              // console.log("2222", temp.mac);
+              // console.log("2222", temp.mac, temp.mac2);
               if (that.callBackConnect != null) {
               if (that.callBackConnect != null) {
                 that.callBackConnect(temp);
                 that.callBackConnect(temp);
               }
               }
@@ -245,28 +249,6 @@ class bleManager {
     });
     });
   }
   }
 
 
-  ///获取 已连接的蓝牙设备
-  getConnectedBluetoothDevices() {
-    // [{"deviceId":"E4:9F:80:09:40:EC","name":"MW-SR1(4G_WIFI)"}]
-    // wx.getConnectedBluetoothDevices({
-    //   success: (res) => {
-    //     console.log("时代发生的法==33==" + JSON.stringify(res));
-    //     if (res.devices.length > 0) {
-    //       console.log("时代发生的法==22==" + JSON.stringify(res.devices));
-    //       for (var i = 0; i < res.devices.length; i++) {
-    //         console.log("时代发生的法==11==" + JSON.stringify(res.devices[i]));
-    //         if (res.devices[i].name == "MW-SR1(4G_WIFI)") {
-    //           console.log("gasdfqwerqwerqdfasdfr==11==" + JSON.stringify(res.devices[i]));
-    //         }
-    //       }
-    //     } else {
-
-    //     }
-    //   },
-    //   fail: (err) => {}
-    // });
-  }
-
   ///获取数据
   ///获取数据
   buf2hex(buffer) {
   buf2hex(buffer) {
     return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
     return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
@@ -366,7 +348,6 @@ class bleManager {
       allowDuplicatesKey: true,
       allowDuplicatesKey: true,
       success: function (res) {
       success: function (res) {
         that.getConnectedDevices();
         that.getConnectedDevices();
-        that.getConnectedBluetoothDevices();
 
 
         that.doStartScaning = false;
         that.doStartScaning = false;
         that.requestBlueTime = that.getCurrentMills();
         that.requestBlueTime = that.getCurrentMills();
@@ -473,7 +454,7 @@ class bleManager {
   }
   }
 
 
   // 发送数据到指定设备
   // 发送数据到指定设备
-  async sendData(data, callback, needChange) {
+  async sendData(data, callback) {
     var that = this
     var that = this
     return new Promise((resolve, reject) => {
     return new Promise((resolve, reject) => {
       var buffer = null;
       var buffer = null;
@@ -705,83 +686,3 @@ class bleManager {
 
 
 // 导出 bleManager 类
 // 导出 bleManager 类
 module.exports = bleManager;
 module.exports = bleManager;
-
-// wx.openBluetoothAdapter({
-//   success: (res) => {
-//     that.isAvailable = true;
-//   },
-//   fail: (err) => {
-//     that.isAvailable = false;
-//   }
-// });
-
-// wx.getSetting({
-//   success(res) {
-//     if (res.authSetting["scope.userFuzzyLocation"]) {
-//       // 成功
-//       // that.getBluetoothStatus();
-//       console.log("有定位权限")
-//       resolve(true);
-//     } else if (res.authSetting["scope.userFuzzyLocation"] === undefined) {
-//       wx.authorize({
-//         scope: "scope.userFuzzyLocation",
-//         success() {
-//           console.log("再次获取定位权限")
-//           resolve(that.getSetting());
-//         }
-//       });
-//     } else {
-//       wx.showModal({
-//         title: '请打开系统位置获取定位权限',
-//         success(res) {
-//           if (res.confirm) {
-//             console.log('用户点击确定')
-//             wx.openSetting({
-//               complete() {
-//                 // that.getSetting();
-//                 // resolve(that.getSetting());
-//               }
-//             })
-//           } else if (res.cancel) {
-//             console.log('用户点击取消');
-//           }
-//         }
-//       })
-//       console.log("没有有定位权限")
-//       reject(false);
-//     }
-//   }
-// })
-
-// // 获取已连接的蓝牙设备
-// getConnectedDevices() {
-//   var that = this;
-//   if (!that.isAvailable && !that.hasPermission) {
-//     return [];
-//   }
-
-//   return new Promise((resolve, reject) => {
-//     wx.getConnectedBluetoothDevices({
-//       // services: ["FFC0", "ffc0", "FFC1", "FFC2", "ffc1", "ffc2", "AB00", "ab00", "AB01", "AB02", "FFF1", "fff1", "FFE2", "FFE5",],
-//       // services: ["ab00", "ffe5", "1111", "FFC0", "FFC1", "FFF1", ],
-//       // services: [],
-//       // services: [
-//       //     "0000ab00-0000-1000-8000-00805f9b34fb",
-//       //     "0000ffc0-0000-1000-8000-00805f9b34fb",
-//       //     "0000FFF0-0000-1000-8000-00805F9B34FB",
-//       //     "0000FFF1-0000-1000-8000-00805F9B34FB",
-//       //     "0000FFE5-0000-1000-8000-00805F9B34FB",
-//       // ],
-//       success: (res) => {
-//         console.log('已连接的蓝牙设备==11==:', newDevices);
-//         let newDevices = that.fiterDevice(res)
-//         console.log('已连接的蓝牙设备==22==:', newDevices);
-//         resolve(newDevices);
-//       },
-//       fail: (err) => {
-//         console.error('获取已连接的蓝牙设备失败:', err);
-//         reject([]);
-//       }
-//     });
-//   });
-// }

+ 0 - 123
pages/blueDemos/blueDemos.js

@@ -1,123 +0,0 @@
-// pages/blueDemos/blueDemos.js
-Page({
-
-  /**
-   * 页面的初始数据
-   */
-  data: {
-
-  },
-
-  onLoad(options) {
-    console.log("gadsfadfqwerqr====00==");
-    wx.getSetting({
-      success(res) {
-        console.log("gadsfadfqwerqr====00==" + JSON.stringify(res));
-        if (res.authSetting['scope.userInfo']) {
-          // 已经授权,可以直接调用 getUserInfo 获取头像昵称
-          wx.getUserInfo({
-            success: function (res) {
-              console.log("获取用户信息成功", res.userInfo)
-            }
-          })
-        } else {
-          // 否则,先通过 wx.createUserInfoButton 接口发起授权
-          let button = wx.createUserInfoButton({
-            type: 'text',
-            text: '获取用户信息',
-            style: {
-              left: 10,
-              top: 160,
-              width: 200,
-              height: 40,
-              lineHeight: 40,
-              backgroundColor: '#ff0000',
-              color: '#ffffff',
-              textAlign: 'center',
-              fontSize: 16,
-              borderRadius: 4
-            }
-          })
-          button.onTap((res) => {
-            console.log(res)
-          })
-        }
-      },
-      fail(err) {
-        console.log("gadsfadfqwerqr====11==" + JSON.stringify(err));
-        console.log("获取用户信息失败", err)
-      }
-    });
-
-    ///获取定位权限  
-    wx.authorize({
-      scope: 'scope.userFuzzyLocation',
-      success(res) {
-        console.log("gadsfadfqwerqr====22==" + JSON.stringify(res));
-      },
-      fail(err) {
-        console.log("gadsfadfqwerqr====333==" + JSON.stringify(err));
-      }
-    });
-
-    ///获取蓝牙权限
-    wx.authorize({
-      scope: 'scope.bluetooth',
-      success(res) {
-        console.log("gadsfadfqwerqr====444==" + JSON.stringify(res));
-      },
-      fail(err) {
-        console.log("gadsfadfqwerqr====555==" + JSON.stringify(err));
-      }
-    });
-  },
-
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload() {
-
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
-
-  },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-
-  },
-
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
-
-  }
-})

+ 0 - 3
pages/blueDemos/blueDemos.json

@@ -1,3 +0,0 @@
-{
-  "usingComponents": {}
-}

+ 0 - 2
pages/blueDemos/blueDemos.wxml

@@ -1,2 +0,0 @@
-<!--pages/blueDemos/blueDemos.wxml-->
-<text>pages/blueDemos/blueDemos.wxml</text>

+ 0 - 1
pages/blueDemos/blueDemos.wxss

@@ -1 +0,0 @@
-/* pages/blueDemos/blueDemos.wxss */

+ 6 - 3
pages/components/navbar/navbar.js

@@ -9,7 +9,10 @@ Component({
     navbarData: { // 由父页面传递的数据
     navbarData: { // 由父页面传递的数据
       type: Object,
       type: Object,
       value: {},
       value: {},
-      callback: ()=> {},
+    },
+    callback: {
+      type: Boolean,
+      value: false
     },
     },
   },
   },
   externalClasses: ['nav-bgc-class', 'nav-title-class'],
   externalClasses: ['nav-bgc-class', 'nav-title-class'],
@@ -30,8 +33,8 @@ Component({
    */
    */
   methods: {
   methods: {
     _navback() {
     _navback() {
-      if(this.properties.navbarData.callback) {
-        this.properties.navbarData.callback();
+      if (this.properties.callback) {
+        this.triggerEvent('callback',); // 触发确定事件  
         return;
         return;
       };
       };
       wx.navigateBack({
       wx.navigateBack({

+ 15 - 16
pages/connectBle/connectBle.js

@@ -10,11 +10,6 @@ Page({
     nvabarData: {
     nvabarData: {
       showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
       showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
       title: '连接设备', //导航栏 中间的标题
       title: '连接设备', //导航栏 中间的标题
-      callback() {
-        wx.navigateBack({
-          delta: 1,
-        })
-      }
     },
     },
     connectStatus: 0,
     connectStatus: 0,
     searchTips: "正在搜索设备,请保持开机状态…",
     searchTips: "正在搜索设备,请保持开机状态…",
@@ -27,6 +22,10 @@ Page({
     var that = this;
     var that = this;
     var json = JSON.parse(options.param)
     var json = JSON.parse(options.param)
     console.log("要连接设备:", json)
     console.log("要连接设备:", json)
+
+    BtHelper.getInstance().initBluetoothAdapter();
+    BtHelper.getInstance().getBluetoothDevices();
+
     that.setData({
     that.setData({
       connectDevice: json
       connectDevice: json
     });
     });
@@ -40,17 +39,17 @@ Page({
     var connectDevice = that.data.connectDevice;
     var connectDevice = that.data.connectDevice;
     BtHelper.getInstance().startScan(connectDevice,
     BtHelper.getInstance().startScan(connectDevice,
       async function (b) {
       async function (b) {
-          if (!b) {
-            that.setStatus(1);
-          }
-        },
-        async function (res) {
-          await BtHelper.getInstance().stopSearch();
-          that.setStatus(2);
-          that.data.connectDevice.deviceId = res.deviceId;
-          that.data.connectDevice.connectable = res.connectable;
-          that.data.connectDevice.mac = res.mac;
+        if (!b) {
+          that.setStatus(1);
         }
         }
+      },
+      async function (res) {
+        await BtHelper.getInstance().stopSearch();
+        that.setStatus(2);
+        that.data.connectDevice.deviceId = res.deviceId;
+        that.data.connectDevice.connectable = res.connectable;
+        that.data.connectDevice.mac = res.mac;
+      }
     );
     );
   },
   },
 
 
@@ -111,7 +110,7 @@ Page({
     var buttonTips = ""
     var buttonTips = ""
     let name = that.data.connectDevice.name;
     let name = that.data.connectDevice.name;
     let typeList = that.data.connectDevice.typeList ?? []
     let typeList = that.data.connectDevice.typeList ?? []
-    let bleTypes = typeList.find(v => v.connectType == 1)
+    let bleTypes = typeList.find(v => v.connectType == 1) ?? {}
     let deviceLinkResp = bleTypes.deviceLinkResp ?? {}
     let deviceLinkResp = bleTypes.deviceLinkResp ?? {}
 
 
     console.log("搜索状态", bleType)
     console.log("搜索状态", bleType)

+ 42 - 12
pages/index/index.js

@@ -194,25 +194,49 @@ Page({
       },
       },
     });
     });
   },
   },
-
+  testData() {
+    return {
+      "deviceId": "xxxxx",
+      "deviceName": "xxxxxx",
+      "deviceType": "xxxx",
+      "type": 1,
+      "deviceIcon": "xxxx",
+      "deviceMacId": "xxxx",
+      "deviceBattery": 4,
+      "state": "online",
+      "connectType": 1,
+      "clientType": "猫王妙播黑胶音箱(BLE)",
+      "deviceConnectStatus": 1,
+      "deviceConnectStatusText": "xxxx",
+    }
+  },
   onDeviceLoad() {
   onDeviceLoad() {
     var that = this;
     var that = this;
     var deviceList = store.getStore("deviceList");
     var deviceList = store.getStore("deviceList");
+
     if (!strings.isEmpty(deviceList)) {
     if (!strings.isEmpty(deviceList)) {
       that.updateDeviceList(deviceList, true, false);
       that.updateDeviceList(deviceList, true, false);
     }
     }
 
 
-    ///监听蓝牙设备
-    BtHelper.getInstance().initBluetoothAdapter();
-    BtHelper.getInstance().getBluetoothDevices();
-    BtHelper.getInstance().startScan(null, null, null);
-    var isFirst = true;
-    ///再秒再对比一次
-    that.stopIntervalId1();
-    that.data.intervalId1 = setInterval(async function () {
-      isFirst = false;
-      that.compareList();
-    }, isFirst ? 6 * 1000 : 12 * 1000);
+    // that.addBlueDevice(that.testData())
+
+    let hasBle = that.data.deviceList.find(item => {
+      return item.connectType == 1;
+    })
+    if (hasBle) {
+      ///监听蓝牙设备
+      BtHelper.getInstance().initBluetoothAdapter();
+      BtHelper.getInstance().getBluetoothDevices();
+      BtHelper.getInstance().startScan(null, null, null);
+      var isFirst = true;
+      ///再秒再对比一次
+      that.stopIntervalId1();
+      that.data.intervalId1 = setInterval(async function () {
+        isFirst = false;
+        that.compareList();
+      }, isFirst ? 6 * 1000 : 12 * 1000);
+    }
+
   },
   },
 
 
   /// 对比蓝牙数据
   /// 对比蓝牙数据
@@ -695,6 +719,12 @@ Page({
     var finalList = lexin_add.updateDeviceList(deviceList, isInit, closeAllBlue);
     var finalList = lexin_add.updateDeviceList(deviceList, isInit, closeAllBlue);
     if (!strings.isEmpty(deviceList) || !strings.isEmpty(finalList)) {
     if (!strings.isEmpty(deviceList) || !strings.isEmpty(finalList)) {
       store.setStore("deviceList", finalList);
       store.setStore("deviceList", finalList);
+
+      // todo 测试代码
+      // finalList.forEach(element => {
+      //   element.state = "online";
+      // });
+
       that.setData({
       that.setData({
         deviceList: finalList,
         deviceList: finalList,
       });
       });

+ 1 - 1
pages/ota/ota.wxml

@@ -22,7 +22,7 @@
     <view class="content">
     <view class="content">
         <view class="pro_title">正在升级</view>
         <view class="pro_title">正在升级</view>
         <view class="progress-container">
         <view class="progress-container">
-            <progress class="progress" border-radius="16rpx" stroke-width="32rpx" percent="{{progress}}" activeColor="#6546A3" backgroundColor="rgba(101,70,163,0.16)" stroke-width="26" border-radius="13" />
+            <progress class="progress" border-radius="16rpx" stroke-width="32rpx" percent="{{progress}}" activeColor="rgba(101, 70, 163, 1)" backgroundColor="rgba(101,70,163,0.16)" stroke-width="26" border-radius="13" />
             <view class="progress-text" style="left: {{progressTextLeft}};">
             <view class="progress-text" style="left: {{progressTextLeft}};">
                 {{progressPercent}}%
                 {{progressPercent}}%
             </view>
             </view>

+ 94 - 38
pages/piano/cropper/cropper.js

@@ -12,21 +12,42 @@ Page({
    * 页面的初始数据
    * 页面的初始数据
    */
    */
   data: {
   data: {
+    navbarData: {
+      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
+      title: '壁纸设置', //导航栏 中间的标题
+
+    },
     src: "",
     src: "",
     width: 320,//宽度
     width: 320,//宽度
     height: 320,//高度
     height: 320,//高度
-
-    max_width: 320,
-    max_height: 320,
-    disable_rotate: true, //是否禁用旋转
-    disable_ratio: true, //锁定比例
-    limit_move: true, //是否限制移动
     showProgress: false,
     showProgress: false,
-    _imageBuffer: null,
+    _chunks: [],
     progress: 0,
     progress: 0,
+    _timer: null,
+    _imgUrl: null,
   },
   },
   cropper: null,
   cropper: null,
-
+  callback() {
+    let that = this
+    if (this.data._chunks.length > 0) {
+      wx.showModal({
+        title: '保存图片中,确定要中断退出吗?',
+        content: '',
+        complete: (res) => {
+          if (res.confirm) {
+            that.endImage(2)
+            wx.navigateBack({
+              delta: 1,
+            })
+          }
+        }
+      })
+    } else {
+      wx.navigateBack({
+        delta: 1,
+      })
+    }
+  },
   // 图片转RGB565
   // 图片转RGB565
   convertToRGB565(imageData) {
   convertToRGB565(imageData) {
     const { data, width, height } = imageData;
     const { data, width, height } = imageData;
@@ -63,15 +84,15 @@ Page({
   },
   },
   upload() {
   upload() {
     let that = this;
     let that = this;
-    wx.chooseImage({
+    wx.chooseMedia({
       count: 1,
       count: 1,
-      sizeType: ['original', 'compressed'],
+      mediaType: ['image'],
       sourceType: ['album'],
       sourceType: ['album'],
       success(res) {
       success(res) {
         wx.showLoading({
         wx.showLoading({
           title: '加载中',
           title: '加载中',
         })
         })
-        const tempFilePaths = res.tempFilePaths[0];
+        const tempFilePaths = res.tempFiles[0].tempFilePath;
         //重置图片角度、缩放、位置
         //重置图片角度、缩放、位置
         that.cropper.imgReset();
         that.cropper.imgReset();
         that.setData({
         that.setData({
@@ -89,8 +110,8 @@ Page({
     console.log("clickcut:", e.detail);
     console.log("clickcut:", e.detail);
     //图片预览
     //图片预览
     wx.previewImage({
     wx.previewImage({
-      current: e.detail.url, // 当前显示图片的http链接
-      urls: [e.detail.url] // 需要预览的图片http链接列表
+      current: e.detail.url,
+      urls: [e.detail.url]
     })
     })
   },
   },
   cancel() {
   cancel() {
@@ -104,10 +125,10 @@ Page({
       title: '图片裁剪中',
       title: '图片裁剪中',
     })
     })
     const fs = wx.getFileSystemManager();
     const fs = wx.getFileSystemManager();
-
     this.cropper.getImg((obj) => {
     this.cropper.getImg((obj) => {
       // app.globalData.imgSrc = obj.url;
       // app.globalData.imgSrc = obj.url;
       console.log("裁剪图片:", obj);
       console.log("裁剪图片:", obj);
+      _this.data._imgUrl = obj.url
       fs.readFile({
       fs.readFile({
         filePath: obj.url,
         filePath: obj.url,
         encoding: '', // 不指定编码以获取原始二进制数据
         encoding: '', // 不指定编码以获取原始二进制数据
@@ -118,13 +139,16 @@ Page({
             height: obj.height,
             height: obj.height,
             data: res.data
             data: res.data
           })
           })
-          _this.data._imageBuffer = rgbData;
-          console.log("下载文件成功2:", _this.data._imageBuffer)
+          console.log("下载文件成功2:", rgbData.byteLength)
+          _this.data._imageBufferLength = rgbData.byteLength
           wx.hideLoading();
           wx.hideLoading();
           wx.showLoading({
           wx.showLoading({
             title: '开始传输图片',
             title: '开始传输图片',
           })
           })
-          _this.startImage();
+          _this.startImage(rgbData);
+          // 测试
+          // _this.sendImage()
+          // _this.startProgress()
         },
         },
         fail: (err) => {
         fail: (err) => {
           console.error('读取 .bin 文件失败:', err);
           console.error('读取 .bin 文件失败:', err);
@@ -135,11 +159,11 @@ Page({
     // _this.downloadAndSaveFile("https://music-play.oss-cn-shenzhen.aliyuncs.com/backOss/file/6a909799a6924e6f86a4683e6da4fad4.bin");
     // _this.downloadAndSaveFile("https://music-play.oss-cn-shenzhen.aliyuncs.com/backOss/file/6a909799a6924e6f86a4683e6da4fad4.bin");
     // 55kb的
     // 55kb的
     // _this.downloadAndSaveFile("https://music-play.oss-cn-shenzhen.aliyuncs.com/backOss/file/55d2dd22bd554eb19b71536bec4ba42c.bin");
     // _this.downloadAndSaveFile("https://music-play.oss-cn-shenzhen.aliyuncs.com/backOss/file/55d2dd22bd554eb19b71536bec4ba42c.bin");
+    // _this.downloadAndSaveFile("https://music-play.oss-cn-shenzhen.aliyuncs.com/backOss/file/7498f0c94c5646d0a4648f313a2fa05c.bin");
 
 
   },
   },
   // 下载网络文件并保存到本地
   // 下载网络文件并保存到本地
   downloadAndSaveFile(url) {
   downloadAndSaveFile(url) {
-    // https://music-play.oss-cn-shenzhen.aliyuncs.com/backOss/file/6a909799a6924e6f86a4683e6da4fad4.bin
     const fs = wx.getFileSystemManager();
     const fs = wx.getFileSystemManager();
     let _this = this;
     let _this = this;
     wx.downloadFile({
     wx.downloadFile({
@@ -155,14 +179,12 @@ Page({
             success: (res) => {
             success: (res) => {
               console.log("下载文件成功:", res.data)
               console.log("下载文件成功:", res.data)
               let rgbData = res.data
               let rgbData = res.data
-              _this.data._imageBuffer = rgbData;
-              // console.log("下载文件成功2:", _this.data._imageBuffer)
 
 
               wx.hideLoading();
               wx.hideLoading();
               wx.showLoading({
               wx.showLoading({
                 title: '开始传输图片',
                 title: '开始传输图片',
               })
               })
-              _this.startImage();
+              _this.startImage(rgbData);
             },
             },
             fail: (err) => {
             fail: (err) => {
               console.error('读取 .bin 文件失败:', err);
               console.error('读取 .bin 文件失败:', err);
@@ -197,7 +219,7 @@ Page({
               console.log('用户拒绝授权访问相册');
               console.log('用户拒绝授权访问相册');
               wx.showModal({
               wx.showModal({
                 title: '提示',
                 title: '提示',
-                content: '您拒绝了访问相册的权限,请在设置中手动开启',
+                content: '您拒绝了访问相册的权限,无法上传图片',
                 showCancel: false,
                 showCancel: false,
                 success(res) {
                 success(res) {
                   if (res.confirm) {
                   if (res.confirm) {
@@ -207,6 +229,7 @@ Page({
                         if (settingRes.authSetting['scope.writePhotosAlbum']) {
                         if (settingRes.authSetting['scope.writePhotosAlbum']) {
                           console.log('用户已在设置中开启访问相册的权限');
                           console.log('用户已在设置中开启访问相册的权限');
                           // 可以在这里执行访问相册的操作
                           // 可以在这里执行访问相册的操作
+                          _this.upload(); //上传图片
                         } else {
                         } else {
                           console.log('用户仍未授权访问相册');
                           console.log('用户仍未授权访问相册');
                         }
                         }
@@ -225,7 +248,9 @@ Page({
       }
       }
     });
     });
   },
   },
-  async startImage() {
+  async startImage(imageBuffer) {
+    this.sliceDataIntoChunks(imageBuffer, 16);
+
     BtHelper.sendCallBack(BtCmd.wallPaper(1), function (res) {
     BtHelper.sendCallBack(BtCmd.wallPaper(1), function (res) {
       if (!res) {
       if (!res) {
         wx.hideLoading()
         wx.hideLoading()
@@ -244,22 +269,21 @@ Page({
       const chunk = data.slice(i, i + chunkSize);
       const chunk = data.slice(i, i + chunkSize);
       chunks.push(chunk);
       chunks.push(chunk);
     }
     }
-    return chunks;
+    this.data._chunks = chunks;
   },
   },
-  async sendImage(imageBuffer, index) {
+
+  async sendImage() {
     let _this = this
     let _this = this
 
 
     wx.hideLoading()
     wx.hideLoading()
-    console.log("发送图片数据0:", index, imageBuffer.byteLength)
-    // console.log("发送图片数据0:", index, imageBuffer.length)
-    let chunks = this.sliceDataIntoChunks(imageBuffer, 16);
-
+    let chunks = this.data._chunks
     let next = 0;
     let next = 0;
-    let total = imageBuffer.byteLength;
-    // let total = imageBuffer.length;
+    let total = this.data._imageBufferLength;
     let btHelper = BtHelper.getInstance();
     let btHelper = BtHelper.getInstance();
-    for (let i = 0; i < chunks.length; i++) {
+    let i = 0;
+    this._timer = setInterval(async () => {
       const chunk = chunks[i];
       const chunk = chunks[i];
+      i++;
       next += chunk.byteLength;
       next += chunk.byteLength;
       // next += chunk.length;
       // next += chunk.length;
       let uint8Array = new Uint8Array(chunk);
       let uint8Array = new Uint8Array(chunk);
@@ -269,15 +293,31 @@ Page({
       console.log("发送图片数据1:", i, next, total, unit16)
       console.log("发送图片数据1:", i, next, total, unit16)
       _this.updateProgress(next, total);
       _this.updateProgress(next, total);
 
 
-      await _this.delay(20);
       let res = await btHelper.wallPaperSyncData(chunk);
       let res = await btHelper.wallPaperSyncData(chunk);
+      // let res = true;
       // btHelper.wallPaperData(chunk);
       // btHelper.wallPaperData(chunk);
 
 
       let nowDate = Date.now()
       let nowDate = Date.now()
       if (i === chunks.length - 1 && res) {
       if (i === chunks.length - 1 && res) {
         wx.showModal({
         wx.showModal({
           title: '图片上传成功' + i + " / " + nowDate,
           title: '图片上传成功' + i + " / " + nowDate,
-          showCancel: false
+          showCancel: false,
+          success(res) {
+            if (res.confirm) {
+              const pages = getCurrentPages();
+              // 获取上一级页面实例
+              const prevPage = pages[pages.length - 2];
+              // 传递参数
+              prevPage.setData({
+                topImg: {
+                  "pic": _this.data._imgUrl,
+                }
+              });
+              wx.navigateBack({
+                delta: 1,
+              })
+            }
+          }
         })
         })
         _this.endImage(0)
         _this.endImage(0)
 
 
@@ -286,15 +326,28 @@ Page({
           title: '图片上传失败',
           title: '图片上传失败',
           showCancel: false
           showCancel: false
         })
         })
+
         _this.endImage(2)
         _this.endImage(2)
       }
       }
-    }
+    }, 20);
   },
   },
   async delay(ms) {
   async delay(ms) {
     return new Promise(resolve => setTimeout(resolve, ms));
     return new Promise(resolve => setTimeout(resolve, ms));
   },
   },
   endImage(value) {
   endImage(value) {
+    let _this = this
+    console.log("结束图片上传:", value)
+    if (_this.data._timer) {
+      clearInterval(_this.data._timer)
+      _this.data._timer = null
+    }
+    _this.data._chunks = []
     BtHelper.getInstance().wallPaper(value);
     BtHelper.getInstance().wallPaper(value);
+    if (value === 0) {
+
+    } else {          // 获取页面栈
+
+    }
   },
   },
   startProgress() {
   startProgress() {
     this.setData({
     this.setData({
@@ -303,7 +356,7 @@ Page({
     })
     })
   },
   },
   updateProgress(chunk, total) {
   updateProgress(chunk, total) {
-    let progress = chunk / total;
+    let progress = parseFloat((chunk / total * 100).toFixed(2));
     let _this = this
     let _this = this
     if (chunk >= total) {
     if (chunk >= total) {
       _this.setData({
       _this.setData({
@@ -345,17 +398,20 @@ Page({
 
 
           if (otaCmd === 1 && kind == 1) {
           if (otaCmd === 1 && kind == 1) {
             // 开始发送
             // 开始发送
-            _this.sendImage(_this.data._imageBuffer, 0)
+            _this.sendImage()
             _this.startProgress()
             _this.startProgress()
           } else if (otaCmd === 0 && kind == 1) {
           } else if (otaCmd === 0 && kind == 1) {
             // 发送结束
             // 发送结束
-            // _this.endImage(0)
           } else if (kind == 0) {
           } else if (kind == 0) {
             wx.hideLoading()
             wx.hideLoading()
             wx.showModal({
             wx.showModal({
               title: '图片上传失败了',
               title: '图片上传失败了',
               showCancel: false
               showCancel: false
             })
             })
+            if (_this.data._timer) {
+              clearInterval(_this.data._timer)
+              _this.data._timer = null
+            }
           }
           }
           break;
           break;
         default:
         default:

+ 1 - 0
pages/piano/cropper/cropper.json

@@ -1,5 +1,6 @@
 {
 {
   "usingComponents": {
   "usingComponents": {
+    "nav-bar": "./../../components/navbar/navbar",
     "image-cropper": "./../../components/image-cropper/image-cropper"
     "image-cropper": "./../../components/image-cropper/image-cropper"
   }
   }
 }
 }

+ 3 - 2
pages/piano/cropper/cropper.wxml

@@ -1,8 +1,9 @@
 <!-- pages/piano/cropper/cropper.wxml -->
 <!-- pages/piano/cropper/cropper.wxml -->
+<nav-bar class="navi_bar" bind:goBack="_goBack" nav-bgc-class="ex-nav-bgc-class" navbar-data='{{navbarData}}' callback="true" bind:callback="callback"></nav-bar>
 <view class="container">
 <view class="container">
-    <image-cropper id="image-cropper" bindload="cropperload" bindimageload="loadimage" bindtapcut="clickcut" limit_move="{{limit_move}}" disable_rotate="{{disable_rotate}}" width="{{width}}" height="{{height}}" imgSrc="{{src}}" angle="{{angle}}" disable_width="{{disable_width}}" max_width="{{max_width}}" max_height="{{max_height}}" disable_height="{{disable_height}}" disable_ratio="{{disable_ratio}}" min_width="{{max_width}}" min_height="{{max_height}}"></image-cropper>
+    <image-cropper id="image-cropper" bindload="cropperload" bindimageload="loadimage" bindtapcut="clickcut" limit_move="true" disable_rotate="true" width="{{width}}" height="{{height}}" imgSrc="{{src}}" disable_width="true" max_width="{{width}}" max_height="{{height}}" disable_height="true" disable_ratio="true" min_width="{{width}}" min_height="{{height}}" export_scale="1.5"></image-cropper>
     <view wx:if="{{showProgress}}" class="progress-container">
     <view wx:if="{{showProgress}}" class="progress-container">
-        <progress class="progress" border-radius="26rpx" stroke-width="52rpx" percent="{{progress}}" activeColor="#6546A3" backgroundColor="rgba(0,0,0,0.4)" stroke-width="26" border-radius="13" />
+        <progress class="progress" border-radius="26rpx" percent="{{progress}}" activeColor="rgba(101, 70, 163, 1)" backgroundColor="rgba(0, 0, 0, 0.40)" stroke-width="26" border-radius="13" />
         <view class="progress-text">保存壁纸中…{{progress}}%</view>
         <view class="progress-text">保存壁纸中…{{progress}}%</view>
     </view>
     </view>
     <view wx:if="{{!showProgress}}" class='bottom'>
     <view wx:if="{{!showProgress}}" class='bottom'>

+ 23 - 6
pages/piano/cropper/cropper.wxss

@@ -1,10 +1,23 @@
 /* pages/piano/cropper/cropper.wxss */
 /* pages/piano/cropper/cropper.wxss */
 .container {
 .container {
 	position: relative;
 	position: relative;
-	height: 100vh;
-	/* 确保容器占满整个视口高度 */
+	overflow: hidden;
 }
 }
 
 
+.navi_bar {
+	position: fixed;
+	z-index: 15;
+	top: 0;
+	left: 0;
+	right: 0;
+}
+
+.ex-nav-bgc-class {
+	background: white;
+	backdrop-filter: blur(10px);
+}
+
+
 .bottom {
 .bottom {
 	display: flex;
 	display: flex;
 	flex-direction: row;
 	flex-direction: row;
@@ -15,7 +28,7 @@
 	height: 88rpx;
 	height: 88rpx;
 
 
 	background-color: rgba(0, 0, 0, 0.6);
 	background-color: rgba(0, 0, 0, 0.6);
-	z-index: 12;
+	z-index: 13;
 }
 }
 
 
 .right_btn {
 .right_btn {
@@ -53,11 +66,15 @@
 .progress-container {
 .progress-container {
 	position: relative;
 	position: relative;
 	margin-inline: 56rpx;
 	margin-inline: 56rpx;
-	margin-top: 615rpx;
+	margin-top: 1454rpx;
+	z-index: 10;
+
 }
 }
 
 
 .progress {
 .progress {
-	width: 100%;
+	z-index: 11;
+	height: 52rpx;
+
 }
 }
 
 
 .progress-text {
 .progress-text {
@@ -67,6 +84,6 @@
 	transform: translate(-50%, -50%);
 	transform: translate(-50%, -50%);
 	color: white;
 	color: white;
 	font-size: 24rpx;
 	font-size: 24rpx;
-	z-index: 1;
+	z-index: 12;
 	font-weight: 500;
 	font-weight: 500;
 }
 }

+ 0 - 23
pages/piano/wallpaper/wallpaper.js

@@ -27,31 +27,8 @@ Page({
     navbarData: {
     navbarData: {
       showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
       showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
       title: '壁纸设置', //导航栏 中间的标题
       title: '壁纸设置', //导航栏 中间的标题
-      callback() {
-        if (this._imageBuffer) {
-          wx.showModal({
-            title: '保存图片中,确定要中断退出吗?',
-            content: '',
-            complete: (res) => {
-              if (res.cancel) {
-
-              }
-
-              if (res.confirm) {
-                this.endImage(2)
-              }
-            }
-          })
-        } else {
-          wx.navigateBack({
-            delta: 1,
-          })
-        }
-      }
     },
     },
     showCropImg: false,
     showCropImg: false,
-
-
   },
   },
   closePage() {
   closePage() {