Преглед изворни кода

feature:增加裁剪壁纸的保存

zeng.chen пре 6 месеци
родитељ
комит
b087fb8a53
3 измењених фајлова са 59 додато и 23 уклоњено
  1. 3 1
      pages/ota/ota.js
  2. 34 4
      pages/piano/cropper/cropper.js
  3. 22 18
      pages/piano/wallpaper/wallpaper.js

+ 3 - 1
pages/ota/ota.js

@@ -457,7 +457,9 @@ Page({
           break;
         case EnumCmdEvent.onoffline:
           let state = event.commonValue
-          _this.data.device.state = state
+          if (event.deviceId === _this.data.device.deviceId) {
+            _this.data.device.state = state
+          }
           wx.hideLoading()
           break;
         case EnumCmdEvent.version:

+ 34 - 4
pages/piano/cropper/cropper.js

@@ -4,6 +4,7 @@ const { BtCmd } = require('../../../devices/bluetooth/bt_cmd');
 import EventManager from '../../../utils/event_bus'
 import { EnumCmdEvent, CmdEvent } from '../../../devices/cmd_key_event';
 import js_md5 from '../../../utils/js_md5';
+import store from '../../../utils/store';
 const { BtHelper } = require('../../../devices/bt_helper');
 
 Page({
@@ -132,7 +133,7 @@ Page({
 
       },
       fail: (err) => {
-        console.error('读取 .bin 文件失败:', err);
+        console.error('读取 .bin 文件失败2:', err);
       },
     });
     // 651kb的
@@ -171,7 +172,8 @@ Page({
       })
       // app.globalData.imgSrc = obj.url;
       console.log("裁剪壁纸:", res);
-      _this.data._imgUrl = _this.data._imgTopPic ?? res.url
+      _this.data._imgUrl = res.url
+      _this.data._imgTopPic = res.url
       fs.readFile({
         filePath: _this.data._imgUrl,
         encoding: '', // 不指定编码以获取原始二进制数据
@@ -213,6 +215,11 @@ Page({
 
         },
         fail: (err) => {
+          s
+          wx.hideLoading()
+          wx.showToast({
+            title: '读取该图片失败',
+          })
           console.error('读取 .bin 文件失败:', err);
         },
       });
@@ -418,7 +425,7 @@ Page({
   successSend() {
     let _this = this
     wx.showModal({
-      title: '上传壁纸成功',
+      title: '保存壁纸成功',
       showCancel: false,
       success(res) {
         if (res.confirm) {
@@ -426,7 +433,7 @@ Page({
           // 获取上一级页面实例
           const prevPage = pages[pages.length - 2];
           // 传递参数
-          prevPage.updateTopImg(_this.data._imgUrl)
+          prevPage.updateTopImg(_this.data._imgTopPic)
           wx.navigateBack({
             delta: 1,
           })
@@ -468,6 +475,26 @@ Page({
     });
     that.data._imgTopPic = image.pic
   },
+  disconnect(event) {
+    let _this = this;
+    console.log("断开连接", event.commonValue, event.deviceId);
+    if (event.commonValue === "offline") {
+      wx.showModal({
+        title: '提示',
+        content: '设备断开连接,请重新连接设备',
+        showCancel: false,
+        success: function (res) {
+          if (res.confirm) {
+            wx.navigateBack({
+              delta: 1
+            })
+          }
+        }
+      })
+    }
+    // 设备断开连接,请重新连接设备
+  },
+
   /**
    * 生命周期函数--监听页面加载
    */
@@ -496,6 +523,9 @@ Page({
       console.log("裁剪页:", name, value, kind)
 
       switch (name) {
+        case EnumCmdEvent.onoffline:
+          _this.disconnect(event)
+          break;
         case EnumCmdEvent.wallpaper:
           //0x78
           // 小程序:0x78,  1。 开启壁纸

+ 22 - 18
pages/piano/wallpaper/wallpaper.js

@@ -4,6 +4,7 @@ const { deviceWallPaper } = require('../../../request/deviceListRequest')
 // const fs = require('fs');
 
 import route_util from '../../../utils/route_util';
+import store from '../../../utils/store';
 
 // import EventManager from '../../utils/event_bus'
 
@@ -71,12 +72,14 @@ Page({
     deviceWallPaper().then(res => {
       console.log("壁纸列表", res);
       let data = res ?? []
-      if (data.length == 0) {
-        // _this.setData({
-        //   imageList: [],
-        //   topImg: {},
-        // })
-        return;
+
+      let localImg = store.getStore("_imgTopPic");
+      if (localImg) {
+        data.unshift({
+          id: 0,
+          name: "本地壁纸",
+          pic: localImg
+        })
       }
 
       _this.setData({
@@ -88,19 +91,20 @@ Page({
   }, 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"
-      }
-      _this.data.imageList.push(newImg)
-      _this.setData({
-        imageList: _this.data.imageList,
-        topImg: newImg
-      })
+    // let hasImg = _this.data.imageList.find(function (vForItem) {
+    //   return vForItem.pic == topUrl;
+    // })
+    // if (!hasImg) {
+    let newImg = {
+      "pic": topUrl, "id": "0"
     }
+    _this.data.imageList.push(newImg)
+    _this.setData({
+      imageList: _this.data.imageList,
+      topImg: newImg
+    })
+    store.setStore('_imgTopPic', topUrl)
+    // }
   },
   hideCut(e) {
     const img = arguments[0].detail