Преглед на файлове

feature:修改壁纸的流程

zeng.chen преди 7 месеца
родител
ревизия
366f470cb9
променени са 4 файла, в които са добавени 70 реда и са изтрити 29 реда
  1. 47 16
      pages/piano/cropper/cropper.js
  2. 1 1
      pages/piano/cropper/cropper.wxml
  3. 12 8
      request/deviceListRequest.js
  4. 10 4
      utils/util.js

+ 47 - 16
pages/piano/cropper/cropper.js

@@ -104,6 +104,9 @@ Page({
   },
   submit() {
     let _this = this
+    wx.showLoading({
+      title: '图片裁剪中',
+    })
     this.cropper.getImg((obj) => {
       // app.globalData.imgSrc = obj.url;
       console.log("裁剪图片:", obj);
@@ -122,6 +125,10 @@ Page({
         let rgbData = _this.RGBAtoRGB565(res.data)
         console.log("转换rgb:", rgbData.length)
         _this.data._imageBuffer = rgbData;
+        wx.hideLoading();
+        wx.showLoading({
+          title: '开始传输图片',
+        })
         _this.startImage();
       },
       fail: (err) => {
@@ -131,9 +138,9 @@ Page({
   },
 
   startImage() {
-    BtHelper.sendData(BtCmd.wallPaper(1));
+    BtHelper.getInstance().sendData(BtCmd.wallPaper(1));
   },
-  sendImage(imageBuffer) {
+  startSendImage(imageBuffer) {
     if (imageBuffer == null) {
       wx.showToast({
         title: '图片裁剪失败',
@@ -142,22 +149,37 @@ Page({
       _this.endImage(2)
       return;
     }
-    let chunkSize = 20;
+    _this.sendImage(imageBuffer, 0)
+    // }
+  }, sendImage(imageBuffer, index) {
     let _this = this
 
-    let total = imageBuffer.length
-    for (let i = 0; i < total; i += chunkSize) {
+    if (index >= chunkSize) {
+      _this.endImage(0)
+      return;
+    }
+
+    let chunkSize = 20;
 
-      const chunk = imageBuffer.slice(i, i + chunkSize);
-      BtHelper.wallPaperData(chunk)
-      updateProgress(i, total);
-      if (i >= chunkSize) {
-        _this.endImage(0)
+    let total = imageBuffer.length
+    let next = index + chunkSize;
+    const chunk = imageBuffer.slice(index, next);
+    BtHelper.getInstance().wallPaperData(chunk, function (res) {
+      console.log("发送图片数据:", sendImage)
+      _this.updateProgress(next, total);
+      if (res) {
+        _this.sendImage(imageBuffer)
+      } else {
+        wx.showModal({
+          title: '图片上传失败了',
+          showCancel: false
+        })
       }
-    }
+    })
+
   },
   endImage(value) {
-    BtHelper.sendData(BtCmd.wallPaper(value));
+    BtHelper.getInstance().wallPaper(value);
   },
   startProgress() {
     this.setData({
@@ -200,11 +222,14 @@ Page({
     let _this = this;
     EventManager.addNotification(CmdEvent.eventName, function (event) {
       let name = event.cmdEvent;
-      console.log("壁纸页:", event)
+      console.log("裁剪页:", EnumCmdEvent)
+
       switch (name) {
-        case EnumCmdEvent.wallPaper:
-          let otaCmd = event.wallPaper;
-          let kind = event.kind;
+        case EnumCmdEvent.wallpaper:
+          let otaCmd = event.wallpaper;
+          let kind = event.heiJiaoKind;
+          console.log("裁剪页:", otaCmd, kind)
+
           if (otaCmd === 1 && kind == 1) {
             // 开始发送
             _this.sendImage(_this.data._imageBuffer)
@@ -212,6 +237,12 @@ Page({
           } else if (otaCmd === 0 && kind == 1) {
             // 发送结束
             _this.endImage(0)
+          } else if (kind == 0) {
+            wx.hideLoading()
+            wx.showModal({
+              title: '图片上传失败了',
+              showCancel: false
+            })
           }
           break;
         default:

+ 1 - 1
pages/piano/cropper/cropper.wxml

@@ -1,6 +1,6 @@
 <!-- pages/piano/cropper/cropper.wxml -->
 <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}}"></image-cropper>
+    <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>
     <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" />
         <view class="progress-text">保存壁纸中…{{progress}}%</view>

+ 12 - 8
request/deviceListRequest.js

@@ -1,31 +1,35 @@
-const { request } = require('../utils/util.js')
-import util from "../utils/util.js";
+// const { request } = require('../utils/util.js')
+const util = require('../utils/util');
 
 module.exports = {
   // 设备列表
   deviceList: (data) => {
-    return request("/mini/wx/device/base/deviceList", data, "GET", util.jsonType, false)
+    return util.request("/mini/wx/device/base/deviceList", data, "GET", util.jsonType, false)
   },
 
   // 设备类型列表
   deviceTypeList: (data) => {
-    return request("/mini/wx/device/base/typeList", data, "GET", util.jsonType, false)
+    return util.request("/mini/wx/device/base/typeList", data, "GET", util.jsonType, false)
   },
   // 设备分类列表
   deviceCategoryList: (data) => {
-    return request("/mini/wx/device/base/categoryList", data, "GET",)
+    return util.request("/mini/wx/device/base/categoryList", data, "GET",)
   },
   // 设备版本 OTA
   deviceVersion: (clientType, type, version) => {
-    return request("/mini/wx/device/base/appDeviceVersionGet", {
+    console.log("OTA版本:", clientType, type, version)
+    return util.request("/mini/wx/device/base/appDeviceVersionGet", {
       clientType: clientType,
       type: type,
       version: version,
-    }, "GET",)
+    }, "GET",).catch((error) => {
+      console.error('Request error:', error);
+      // 处理错误
+    });
   },
   // 壁纸列表
   deviceWallPaper: () => {
-    return request("/mini/wx/config/wallpaperList", {}, "GET",)
+    return util.request("/mini/wx/config/wallpaperList", {}, "GET",)
   },
 
 }

+ 10 - 4
utils/util.js

@@ -76,7 +76,7 @@ function request(url, data = {}, method = "GET", header = urlencodeType, isToken
       title: '加载中',
     });
   }
-
+  console.log("请求参数:", fullurl, data)
   return new Promise((resolve, reject) => {
     wx.request({
       url: fullurl,
@@ -88,7 +88,7 @@ function request(url, data = {}, method = "GET", header = urlencodeType, isToken
         "Authorization": isToken ? Authorization : undefined
       }, header),
       success(res) {
-        // console.log("接口:",fullurl, res)
+        console.log("接口:", fullurl, res)
         if (res.statusCode !== 200) {
           wx.hideLoading();
           wx.showToast({
@@ -96,15 +96,19 @@ function request(url, data = {}, method = "GET", header = urlencodeType, isToken
             "icon": "error",
             "duration": 1500
           });
+          resolve(res.data);
           return;
         }
 
         if (!strings.isTrue(data.unShowLoad)) {
           wx.hideLoading();
         }
+
         if (res.data.code === 0) {
           resolve(res.data.data);
         } else if (res.data.code === 401) {
+          resolve(res.data);
+          wx.showToast({ title: '登录过期' })
           // token过期
           try {
             getCurrentPages()[0].logOut();
@@ -114,15 +118,17 @@ function request(url, data = {}, method = "GET", header = urlencodeType, isToken
           // getCurrentPages()[0].login();
           // request(url,data,method,header,isToken);
         } else {
+          resolve(res.data);
           _show_error(res.data.code)
         }
       },
       fail: (err) => {
-        console.log("gadfadsfqweerqwerqewrqr==666==" + JSON.stringify(err));
+        console.log("请求失败" + JSON.stringify(err));
         _show_error("1");
         wx.hideLoading();
+        reject({ code: -1, msg: JSON.stringify(err) })
       },
-      complete() {}
+      complete() { }
     })
   })
 }