Browse Source

feature: 数据整理分包

332777428@qq.com 6 months atrás
parent
commit
149a2900eb

+ 0 - 137
pages/download/download.js

@@ -1,137 +0,0 @@
-// pages/download/download.ts
-Page({
-
-  /**
-   * 页面的初始数据
-   */
-  data: {
-    codeUrl: "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20221107134141195228914.png",
-    nvabarData: {
-      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
-      title: '下载', //导航栏 中间的标题
-    },
-  },
-
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad() {
-    init().then((res)=> {
-      this.setData({
-        codeUrl: res.appDownQrCode,
-      })
-    })
-  },
-
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload() {
-
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
-
-  },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-
-  },
-
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
-
-  },
-   // 保存海报
-   saveImageToPhotosAlbum() {
-     const _this = this;
-    wx.showLoading({
-      title: '保存中...'
-    })
-    wx.downloadFile({
-      url: _this.data.codeUrl,
-      success: function (res) {
-        //图片保存到本地
-        wx.saveImageToPhotosAlbum({
-          filePath: res.tempFilePath,
-          success: function (data) {
-            wx.hideLoading()
-            wx.showToast({
-              title: '保存成功',
-              icon: 'success',
-              duration: 2000
-            })
-          },
-          fail: function (err) {
-            if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
-              // 这边微信做过调整,必须要在按钮中触发,因此需要在弹框回调中进行调用
-              wx.showModal({
-                title: '提示',
-                content: '需要您授权保存相册',
-                showCancel: false,
-                success(){
-                  wx.openSetting({
-                    success(settingdata) {
-                      console.log("settingdata", settingdata)
-                      if (settingdata.authSetting['scope.writePhotosAlbum']) {
-                        wx.showModal({
-                          title: '提示',
-                          content: '获取权限成功,再次点击图片即可保存',
-                          showCancel: false,
-                        })
-                      } else {
-                        wx.showModal({
-                          title: '提示',
-                          content: '获取权限失败,将无法保存到相册哦~',
-                          showCancel: false,
-                        })
-                      }
-                    },
-                    fail(failData) {
-                      console.log("failData",failData)
-                    },
-                    complete(finishData) {
-                      console.log("finishData", finishData)
-                    }
-                  })
-                }
-              })
-            }
-          },
-          complete(res) {
-            wx.hideLoading()
-          }
-        })
-      }
-    })
-  },
-})

+ 0 - 5
pages/download/download.json

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

+ 0 - 26
pages/download/download.wxml

@@ -1,26 +0,0 @@
-<!--pages/download/download.wxml-->
-<view class="download">
-  <nav-bar bind:goBack="_goBack" nav-bgc-class="ex-nav-bgc-class" nav-title-class="ex-nav-title-class" ex-back-pre="ex-back-pre" navbar-data='{{nvabarData}}'>
-  </nav-bar>
-  <image style="width: 100vw;" class="logo" mode="widthFix" src="./../../img/s.png"></image>
-  <view class="li">
-    <view class="h3">
-      方式一
-    </view>
-    <view class="textList">前往App Store或安卓市场搜索“<text>OhPlay猫王妙播</text>”并下载</view>
-  </view>
-  <view class="li">
-    <view class="h3">
-      方式二
-    </view>
-    <view class="textList">1.保存二维码</view>
-    <view class="textList">2.进入微信扫一扫功能,点击“相册”,选取二维码</view>
-    <view class="textList">3.下载OhPlay猫王妙播</view>
-  </view>
-  <view class="code">
-    <image mode="widthFix" 	show-menu-by-longpress src="{{codeUrl}}"></image>
-  </view>
-  <view class="button">
-    <text bindtap="saveImageToPhotosAlbum">保存到相册</text>
-  </view>
-</view>

+ 0 - 74
pages/download/download.wxss

@@ -1,74 +0,0 @@
-/* pages/download/download.wxss */
-.download .li {
-  padding: 50rpx 66rpx 0;
-}
-
-.download .li .h3 {
-  width: 160rpx;
-  height: 40rpx;
-  line-height: 40rpx;
-  text-align: center;
-  font-size: 28rpx;
-  color: #353535;
-  font-weight: bold;
-  margin-bottom: 20rpx;
-  position: relative;
-}
-
-.download .li .h3::after {
-  content: " ";
-  width: 160rpx;
-  height: 20rpx;
-  border-radius: 30rpx;
-  background-color: rgba(111, 56, 180, 0.1);
-  display: block;
-  position: absolute;
-  bottom: 0;
-}
-
-.download .li .textList {
-  font-size: 28rpx;
-  color: #353535;
-  line-height: 40rpx;
-}
-
-.download .li .textList text {
-  color: #6f38b4;
-  font-weight: bold;
-}
-
-.download .code {
-  margin-top: 30rpx;
-  width: 100vw;
-  display: flex;
-  align-items: center;
-  justify-content: center;
-}
-
-.download .code image {
-  width: 280rpx;
-}
-
-.download .button {
-  margin-top: 84rpx;
-  width: 100vw;
-  display: flex;
-  justify-content: center;
-}
-
-.download .button text {
-  width: 520rpx;
-  height: 80rpx;
-  background: #6547A3;
-  border-radius: 45rpx;
-  display: flex;
-  justify-content: center;
-  align-items: center;
-  font-size: 36rpx;
-  color: #fff;
-}
-
-.ex-nav-bgc-class {
-  background: rgba(237, 237, 237, 0.9);
-  backdrop-filter: blur(10px);
-}

+ 0 - 444
pages/ota/ota.js

@@ -1,444 +0,0 @@
-const { BtHelper } = require("../../devices/bt_helper");
-import { EnumCmdEvent, CmdEvent } from '../../devices/cmd_key_event';
-import EventManager from '../../utils/event_bus'
-import route_util from '../../utils/route_util';
-import route_constant from '../../utils/route_constant.js';
-import { BtCmd } from '../../devices/bluetooth/bt_cmd.js';
-
-// pages/OTA/ota.js
-Page({
-
-  /**
-   * 页面的初始数据
-   */
-  data: {
-    navbarData: {
-      showCapsule: 1, //
-      title: '固件信息',
-    },
-    device: {},
-    otaData: {},
-    btHelper: null,
-    progress: 0, // 进度条初始值
-    otaStatus: 0,
-    buttonTips: "固件更新",
-    _chunks: [],
-    progressPercent: 0,
-    progress: 0,
-    progressTextLeft: "0%",
-    _timer: null,
-  },
-  setOtaStatus(status) {
-    switch (status) {
-      case 0:
-        this.setData({
-          otaStatus: 0,
-          buttonTips: "固件更新"
-        });
-        break;
-      case 1:
-        this.setData({
-          otaStatus: 1,
-          buttonTips: "下载升级包"
-        });
-        break;
-      case 2:
-        this.setData({
-          otaStatus: 2,
-          buttonTips: "开始更新"
-        });
-        break;
-      case 3:
-        this.setData({
-          otaStatus: 3,
-          buttonTips: "更新中..."
-        });
-        break;
-
-      case 4:
-        this.setData({
-          otaStatus: 4,
-          buttonTips: "更新失败,再试一次"
-        });
-        break;
-      case 5:
-        this.setData({
-          otaStatus: 4,
-          buttonTips: "更新完成"
-        });
-        break;
-      default:
-        break;
-    }
-
-  },
-  startOtaTap() {
-    let online = this.data.device.state === "online"
-    if (!online) {
-      wx.showToast({
-        title: '设备已经掉线了',
-      })
-      return;
-    }
-
-    let hasNewVersion = this.data.otaData.hasNewVersion ?? false
-    if (!hasNewVersion) {
-      wx.showToast({
-        title: '没有可升级的固件',
-      })
-      return;
-    }
-    if (this.data.otaStatus != 0) {
-      console.log("没有可升级的固件2")
-      return;
-    }
-
-    let _this = this
-    wx.showModal({
-      title: '有新固件可升级',
-      content: _this.data.otaData.content ?? '提升体验,操作更流畅',
-      cancelText: '以后再说',
-      confirmText: '升级',
-      complete: (res) => {
-        if (res.cancel) {
-
-        }
-
-        if (res.confirm) {
-          wx.showLoading({
-            title: '升级设备中,请稍后',
-          })
-          _this.sendOtaCmd(1)
-
-          // _this.startDownloadFile()
-          // _this.downloadOtaFile(_this.data.otaData.url ?? "")
-        }
-      }
-    })
-    // const btHelper = BtHelper.getInstance();
-    // btHelper.ota(this.data.otaData.file_url)
-
-  },
-  goToWifi() {
-    route_util.jump(route_constant.setWifi)
-  },
-  sendUrlData() {
-    let url = this.data.otaData.url ?? ""
-    let codeUrl = BtCmd.stringToUint8Array(url)
-    BtHelper.getInstance().otaUrl(codeUrl);
-  },
-
-  // 读取文件废弃代码
-  startDownloadFile() {
-
-    var urlPath = this.data.otaData.url ?? "";
-
-    var list = urlPath.split("/");
-    // let cachePath = await PathUtil.getDownloadPath(fileName: list.last ?? 'OTAUpgrade.OTA');
-    const fs = wx.getFileSystemManager();
-
-    // 构建本地文件路径
-    var localFilePath = list[list.length - 1];
-    console.log(list, localFilePath)
-
-    let _this = this;
-    _this.setOtaStatus(2);
-
-    let localPath = `${wx.env.USER_DATA_PATH}/` + localFilePath
-    // 判断文件是否存在
-    fs.access({
-      path: localPath,
-      success(res) {
-        console.log('文件已存在:', res);
-
-        if (res) {
-          // 有文件
-          _this.readFile(localPath);
-
-        } else {
-          _this.downloadOtaFile(urlPath, localPath)
-        }
-      }, fail(err) {
-        // 文件不存在或其他错误
-        console.log(err)
-        // 文件不存在,开始下载
-        _this.downloadOtaFile(urlPath, localPath)
-      }
-    }
-    );
-  },
-  downloadOtaFile(urlPath, localPath) {
-    let _this = this;
-    // const fs = wx.getFileSystemManager();
-
-    wx.downloadFile({
-      url: urlPath, // 下载资源的URL
-      success: (res) => {
-        console.log('文件下载成功2', res);
-
-        if (res.statusCode === 200) {
-          // 下载成功,保存文件路径
-          const filePath = res.tempFilePath;
-          // _this.readFile(filePath);
-
-          // 将下载的文件移动到本地路径
-          fs.rename({
-            oldPath: filePath,
-            newPath: localPath,
-            success: () => {
-              wx.showToast({
-                title: '文件下载成功',
-              });
-              _this.readFile(localPath);
-            },
-            fail: (err) => {
-              _this.setOtaStatus(4);
-
-              wx.showToast({
-                title: '下载文件失败,检查下手机内存吧',
-              });
-              console.error('文件移动失败:', err);
-            }
-          });
-        } else {
-          _this.setOtaStatus(4);
-          wx.showToast({
-            title: '文件下载失败',
-          });
-        }
-      },
-      fail: (err) => {
-        _this.setOtaStatus(4);
-        wx.showToast({
-          title: '文件下载失败',
-        });
-        console.error('下载文件失败:', err);
-      }
-    });
-  },
-  readFile(localFilePath) {
-
-    if (!localFilePath) {
-      wx.showToast({
-        title: '下载文件为空',
-      });
-      return;
-    }
-    wx.showLoading({
-      title: '开始传输文件',
-    })
-    const fs = wx.getFileSystemManager();
-
-    let _this = this;
-    fs.readFile({
-      filePath: localFilePath,
-      encoding: 'base64', // 可以选择 'utf8' 或 'base64'
-      success: (res) => {
-
-        // const btHelper = BtHelper.getInstance();
-        //   btHelper.ota(localFilePath);
-
-        console.log('文件内容:', res.data.length);
-
-        _this.startSend(res.data);
-      },
-      fail: (err) => {
-        wx.showToast({
-          title: 'OTA文件下载失败',
-        });
-        console.error('文件读取失败:', err);
-        _this.setOtaStatus(4);
-      }
-
-    });
-  },
-  startSend(data) {
-    // const chunkSize = 20; // 每次发送的数据块大小
-    // const chunks = [];
-    // for (let i = 0; i < data.length; i += chunkSize) {
-    //   chunks.push(data.slice(i, i + chunkSize));
-    // }
-
-    // this.data._chunks = chunks;
-    this.sendOtaCmd(1)
-    // this.startSendOtaData()
-  },
-
-  startSendOtaData() {
-    let _this = this
-    let length = this.data._chunks.length
-
-    if (length === 0) {
-      wx.showToast({
-        title: '下载文件失败',
-        icon: 'none'
-      })
-      _this.sendOtaCmd(2)
-      return;
-    }
-    _this.sendOtaData(this.data._chunks, 0)
-    // }
-  }, sendOtaData(imageBuffer, index) {
-    let _this = this
-
-    if (index >= imageBuffer.length) {
-      _this.sendOtaCmd(0)
-      return;
-    }
-    let chunkSize = 20;
-
-
-    let total = imageBuffer.length
-    let next = index + chunkSize;
-    const chunk = imageBuffer.slice(index, next);
-    // todo 改成设备wifi下载
-    // BtHelper.getInstance().wallPaperData(chunk, function (res) {
-    //   console.log("发送OTA数据:", next)
-    //   if (res) {
-    //     _this.updateProgress(next, total);
-
-    //     _this.sendOtaData(imageBuffer)
-    //   } else {
-    //     wx.showModal({
-    //       title: 'OTA升级失败了',
-    //       showCancel: false
-    //     })
-    //   }
-    // })
-
-  },
-  sendOtaCmd(value) {
-    BtHelper.getInstance().otaCmd(value)
-    if (value == 0) {
-      this.setOtaStatus(0);
-    } else {
-      // this.setOtaStatus(4);
-    }
-  },
-
-  startProgress() {
-    this.setData({
-      progress: 0,
-      showProgress: true
-    })
-  },
-  updateProgress(chunk, total) {
-    let progress = chunk / total * 100;
-    let _this = this
-    if (progress >= 100) {
-      _this.setData({
-        progress: 0,
-        showProgress: false,
-        // showCropImg: false
-      });
-      wx.showToast({
-        title: '图片上传成功',
-      })
-    } else {
-      _this.setData({
-        progress: progress,
-      });
-    }
-  },
-  otaSuccess() {
-    wx.hideLoading();
-    // 流程成功
-    wx.showModal({
-      title: '设备开始升级中',
-      showCancel: false,
-      success: function (res) {
-        if (res.confirm) {
-          route_util.goBackHomePage();
-        }
-      }
-    })
-  },
-  otaFailure() {
-    wx.hideLoading();
-    // 流程失败
-    wx.showModal({
-      title: '设备升级失败了',
-      showCancel: false,
-      success: function (res) {
-        if (res.confirm) {
-          // 
-        }
-      }
-    })
-  },
-  addNotification() {
-    let _this = this;
-    EventManager.addNotification(CmdEvent.eventName, function (event) {
-      let name = event.cmdEvent;
-      let kind = event.heiJiaoKind;
-      // 74,1,1是wifi连接成功,74,0 2连接wifi失败/没有wifi。   
-      // 发送url给你后,你回:74 0 1是流程成功,74 0 3是流程失败。
-      let otaCmd = event.otaCmd;
-      console.log("OTA页:", otaCmd, kind, name)
-
-      switch (name) {
-        case EnumCmdEvent.otaCmd:
-
-          if (otaCmd === 1 && kind == 1) {
-            wx.hideLoading();
-            // 设备收到开启OTA的回复,发送url
-            _this.sendUrlData()
-          } else if (otaCmd === 0 && kind == 2) {
-            wx.hideLoading();
-            // 去设置wifi界面
-            _this.goToWifi()
-          } else if (otaCmd === 0 && kind == 3) {
-            _this.otaFailure()
-          } else if (otaCmd === 0 && kind == 1) {
-            _this.otaSuccess()
-          }
-          else if (kind == 0) {
-
-          }
-          break;
-        case EnumCmdEvent.otaUrl:
-          // 小程序发:0x75,  0
-          if (otaCmd === 1 && kind == 1) {
-            // _this.sendOtaCmd(0)
-            _this.otaSuccess()
-            // BtHelper.getInstance().otaUrl(BtCmd.stringToUint8Array(_this.data.otaData.url))
-          } else {
-            _this.otaFailure()
-
-          }
-          break;
-        case EnumCmdEvent.otaWifi:
-          //0x76 
-          wx.hideLoading()
-          // 0x76, 发送wifi成功
-          if (otaCmd === 1 && kind == 1) {
-            _this.sendUrlData()
-          } else {
-            // wifi失败
-            _this.otaFailure()
-
-          }
-          break;
-      }
-    }, _this)
-  },
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad(options) {
-    let param = JSON.parse(options.param)
-    console.log("OTA界面:", param)
-    let otaData = param.otaData
-    let device = param.device
-    this.setData({
-      otaData: otaData,
-      device: device,
-      isShowOta: device.clientType === 'MW-S2(BLE)' || device.clientType === 'MW-S2'
-    })
-    this.addNotification()
-  },
-  onUnload() {
-    EventManager.removeNotification(CmdEvent.eventName, this)
-  },
-
-})

+ 0 - 5
pages/ota/ota.json

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

+ 0 - 32
pages/ota/ota.wxml

@@ -1,32 +0,0 @@
-<!-- pages/OTA/ota.wxml -->
-<view class="section">
-    <nav-bar bind:goBack="_goBack" nav-bgc-class="ex-nav-bgc-class" nav-title-class="ex-nav-title-class" ex-back-pre="ex-back-pre" navbar-data='{{navbarData}}'></nav-bar>
-    <view style="height: 32rpx;"></view>
-    <view class="item">
-        <text class="label">制造商</text>
-        <text class="arrow">AirSmart</text>
-    </view>
-    <view class="item">
-        <text class="label">产品型号</text>
-        <text class="arrow">{{device.clientType}}</text>
-    </view>
-    <view class="item">
-        <text class="label">MAC地址</text>
-        <text class="arrow">{{device.mac}}</text>
-    </view>
-    <view wx:if="{{isShowOta}}" class="button main_color" bind:tap="startOtaTap">
-        {{buttonTips}}
-    </view>
-</view>
-<view wx:if="{{otaStatus === 3}}" class="background">
-    <view class="content">
-        <view class="pro_title">正在升级</view>
-        <view class="progress-container">
-            <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}};">
-                {{progressPercent}}%
-            </view>
-        </view>
-        <view class="pro_tips">升级过程中请勿离开当前页面</view>
-    </view>
-</view>

+ 0 - 100
pages/ota/ota.wxss

@@ -1,100 +0,0 @@
-/* pages/OTA/ota.wxss */
-
-
-
-
-.item {
-	display: flex;
-	align-items: center;
-	border-bottom: 1px solid #e0e0e0;
-	justify-content: space-between;
-	margin-inline: 32rpx;
-	height: 120rpx;
-}
-
-
-.label {
-	font-size: 16px;
-	color: #333333;
-	margin-left: 32rpx;
-}
-
-.arrow {
-	margin-right: 16rpx;
-}
-
-.button {
-	margin-top: 128rpx;
-	display: flex;
-	justify-content: center;
-	align-items: center;
-	margin-inline: 64rpx;
-	font-size: 32rpx;
-	font-weight: Medium;
-	color: white;
-	text-align: center;
-	border-radius: 44rpx;
-	height: 88rpx;
-}
-
-
-.background {
-	position: fixed;
-	top: 0;
-	left: 0;
-	right: 0;
-	bottom: 0;
-	background-color: rgba(0, 0, 0, 0.7);
-	display: flex;
-	justify-content: center;
-	align-items: center;
-	z-index: 1000;
-}
-
-.content {
-	background-color: white;
-	padding-inline: 20px;
-	border-radius: 10px;
-	box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
-	width: 558rpx;
-	height: 404rpx;
-}
-
-.pro_title {
-	font-weight: 500;
-	font-size: 32rpx;
-	color: #333333;
-	text-align: center;
-	font-style: normal;
-	margin-top: 64rpx;
-}
-
-.progress-container {
-	position: relative;
-	margin-inline: 32rpx;
-	margin-top: 46rpx;
-	/* 根据需要调整 */
-}
-
-.progress {
-	width: 100%;
-}
-
-.progress-text {
-	position: absolute;
-	top: 50%;
-	transform: translateY(-50%);
-	color: white;
-	font-size: 16px;
-	z-index: 1;
-	white-space: nowrap;
-}
-
-.pro_tips {
-	margin-top: 48rpx;
-	margin-inline: 34rpx;
-	font-size: 28rpx;
-	color: #666666;
-	text-align: center;
-	font-style: normal;
-}

+ 76 - 5
pages/pageD/download/download.js

@@ -1,18 +1,26 @@
-// pages/pageD/download/download.js
+// pages/download/download.ts
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-
+    codeUrl: "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20221107134141195228914.png",
+    nvabarData: {
+      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
+      title: '下载', //导航栏 中间的标题
+    },
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
-  onLoad(options) {
-
+  onLoad() {
+    init().then((res) => {
+      this.setData({
+        codeUrl: res.appDownQrCode,
+      })
+    })
   },
 
   /**
@@ -62,5 +70,68 @@ Page({
    */
   onShareAppMessage() {
 
-  }
+  },
+  // 保存海报
+  saveImageToPhotosAlbum() {
+    const _this = this;
+    wx.showLoading({
+      title: '保存中...'
+    })
+    wx.downloadFile({
+      url: _this.data.codeUrl,
+      success: function (res) {
+        //图片保存到本地
+        wx.saveImageToPhotosAlbum({
+          filePath: res.tempFilePath,
+          success: function (data) {
+            wx.hideLoading()
+            wx.showToast({
+              title: '保存成功',
+              icon: 'success',
+              duration: 2000
+            })
+          },
+          fail: function (err) {
+            if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
+              // 这边微信做过调整,必须要在按钮中触发,因此需要在弹框回调中进行调用
+              wx.showModal({
+                title: '提示',
+                content: '需要您授权保存相册',
+                showCancel: false,
+                success() {
+                  wx.openSetting({
+                    success(settingdata) {
+                      console.log("settingdata", settingdata)
+                      if (settingdata.authSetting['scope.writePhotosAlbum']) {
+                        wx.showModal({
+                          title: '提示',
+                          content: '获取权限成功,再次点击图片即可保存',
+                          showCancel: false,
+                        })
+                      } else {
+                        wx.showModal({
+                          title: '提示',
+                          content: '获取权限失败,将无法保存到相册哦~',
+                          showCancel: false,
+                        })
+                      }
+                    },
+                    fail(failData) {
+                      console.log("failData", failData)
+                    },
+                    complete(finishData) {
+                      console.log("finishData", finishData)
+                    }
+                  })
+                }
+              })
+            }
+          },
+          complete(res) {
+            wx.hideLoading()
+          }
+        })
+      }
+    })
+  },
 })

+ 3 - 1
pages/pageD/download/download.json

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

+ 26 - 2
pages/pageD/download/download.wxml

@@ -1,2 +1,26 @@
-<!--pages/pageD/download/download.wxml-->
-<text>pages/pageD/download/download.wxml</text>
+<!--pages/download/download.wxml-->
+<view class="download">
+  <nav-bar bind:goBack="_goBack" nav-bgc-class="ex-nav-bgc-class" nav-title-class="ex-nav-title-class" ex-back-pre="ex-back-pre" navbar-data='{{nvabarData}}'>
+  </nav-bar>
+  <image style="width: 100vw;" class="logo" mode="widthFix" src="./../../img/s.png"></image>
+  <view class="li">
+    <view class="h3">
+      方式一
+    </view>
+    <view class="textList">前往App Store或安卓市场搜索“<text>OhPlay猫王妙播</text>”并下载</view>
+  </view>
+  <view class="li">
+    <view class="h3">
+      方式二
+    </view>
+    <view class="textList">1.保存二维码</view>
+    <view class="textList">2.进入微信扫一扫功能,点击“相册”,选取二维码</view>
+    <view class="textList">3.下载OhPlay猫王妙播</view>
+  </view>
+  <view class="code">
+    <image mode="widthFix" 	show-menu-by-longpress src="{{codeUrl}}"></image>
+  </view>
+  <view class="button">
+    <text bindtap="saveImageToPhotosAlbum">保存到相册</text>
+  </view>
+</view>

+ 74 - 1
pages/pageD/download/download.wxss

@@ -1 +1,74 @@
-/* pages/pageD/download/download.wxss */
+/* pages/download/download.wxss */
+.download .li {
+  padding: 50rpx 66rpx 0;
+}
+
+.download .li .h3 {
+  width: 160rpx;
+  height: 40rpx;
+  line-height: 40rpx;
+  text-align: center;
+  font-size: 28rpx;
+  color: #353535;
+  font-weight: bold;
+  margin-bottom: 20rpx;
+  position: relative;
+}
+
+.download .li .h3::after {
+  content: " ";
+  width: 160rpx;
+  height: 20rpx;
+  border-radius: 30rpx;
+  background-color: rgba(111, 56, 180, 0.1);
+  display: block;
+  position: absolute;
+  bottom: 0;
+}
+
+.download .li .textList {
+  font-size: 28rpx;
+  color: #353535;
+  line-height: 40rpx;
+}
+
+.download .li .textList text {
+  color: #6f38b4;
+  font-weight: bold;
+}
+
+.download .code {
+  margin-top: 30rpx;
+  width: 100vw;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+}
+
+.download .code image {
+  width: 280rpx;
+}
+
+.download .button {
+  margin-top: 84rpx;
+  width: 100vw;
+  display: flex;
+  justify-content: center;
+}
+
+.download .button text {
+  width: 520rpx;
+  height: 80rpx;
+  background: #6547A3;
+  border-radius: 45rpx;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  font-size: 36rpx;
+  color: #fff;
+}
+
+.ex-nav-bgc-class {
+  background: rgba(237, 237, 237, 0.9);
+  backdrop-filter: blur(10px);
+}

+ 412 - 34
pages/pageD/ota/ota.js

@@ -1,66 +1,444 @@
-// pages/pageD/ota/ota.js
+const { BtHelper } = require("../../../devices/bt_helper");
+import { EnumCmdEvent, CmdEvent } from '../../../devices/cmd_key_event';
+import EventManager from '../../../utils/event_bus'
+import route_util from '../../../utils/route_util';
+import route_constant from '../../../utils/route_constant.js';
+import { BtCmd } from '../../../devices/bluetooth/bt_cmd.js';
+
+// pages/OTA/ota.js
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-
+    navbarData: {
+      showCapsule: 1, //
+      title: '固件信息',
+    },
+    device: {},
+    otaData: {},
+    btHelper: null,
+    progress: 0, // 进度条初始值
+    otaStatus: 0,
+    buttonTips: "固件更新",
+    _chunks: [],
+    progressPercent: 0,
+    progress: 0,
+    progressTextLeft: "0%",
+    _timer: null,
   },
+  setOtaStatus(status) {
+    switch (status) {
+      case 0:
+        this.setData({
+          otaStatus: 0,
+          buttonTips: "固件更新"
+        });
+        break;
+      case 1:
+        this.setData({
+          otaStatus: 1,
+          buttonTips: "下载升级包"
+        });
+        break;
+      case 2:
+        this.setData({
+          otaStatus: 2,
+          buttonTips: "开始更新"
+        });
+        break;
+      case 3:
+        this.setData({
+          otaStatus: 3,
+          buttonTips: "更新中..."
+        });
+        break;
 
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad(options) {
+      case 4:
+        this.setData({
+          otaStatus: 4,
+          buttonTips: "更新失败,再试一次"
+        });
+        break;
+      case 5:
+        this.setData({
+          otaStatus: 4,
+          buttonTips: "更新完成"
+        });
+        break;
+      default:
+        break;
+    }
 
   },
+  startOtaTap() {
+    let online = this.data.device.state === "online"
+    if (!online) {
+      wx.showToast({
+        title: '设备已经掉线了',
+      })
+      return;
+    }
 
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady() {
+    let hasNewVersion = this.data.otaData.hasNewVersion ?? false
+    if (!hasNewVersion) {
+      wx.showToast({
+        title: '没有可升级的固件',
+      })
+      return;
+    }
+    if (this.data.otaStatus != 0) {
+      console.log("没有可升级的固件2")
+      return;
+    }
 
-  },
+    let _this = this
+    wx.showModal({
+      title: '有新固件可升级',
+      content: _this.data.otaData.content ?? '提升体验,操作更流畅',
+      cancelText: '以后再说',
+      confirmText: '升级',
+      complete: (res) => {
+        if (res.cancel) {
 
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow() {
+        }
+
+        if (res.confirm) {
+          wx.showLoading({
+            title: '升级设备中,请稍后',
+          })
+          _this.sendOtaCmd(1)
 
+          // _this.startDownloadFile()
+          // _this.downloadOtaFile(_this.data.otaData.url ?? "")
+        }
+      }
+    })
+    // const btHelper = BtHelper.getInstance();
+    // btHelper.ota(this.data.otaData.file_url)
+
+  },
+  goToWifi() {
+    route_util.jump(route_constant.setWifi)
+  },
+  sendUrlData() {
+    let url = this.data.otaData.url ?? ""
+    let codeUrl = BtCmd.stringToUint8Array(url)
+    BtHelper.getInstance().otaUrl(codeUrl);
   },
 
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide() {
+  // 读取文件废弃代码
+  startDownloadFile() {
+
+    var urlPath = this.data.otaData.url ?? "";
+
+    var list = urlPath.split("/");
+    // let cachePath = await PathUtil.getDownloadPath(fileName: list.last ?? 'OTAUpgrade.OTA');
+    const fs = wx.getFileSystemManager();
+
+    // 构建本地文件路径
+    var localFilePath = list[list.length - 1];
+    console.log(list, localFilePath)
+
+    let _this = this;
+    _this.setOtaStatus(2);
+
+    let localPath = `${wx.env.USER_DATA_PATH}/` + localFilePath
+    // 判断文件是否存在
+    fs.access({
+      path: localPath,
+      success(res) {
+        console.log('文件已存在:', res);
+
+        if (res) {
+          // 有文件
+          _this.readFile(localPath);
 
+        } else {
+          _this.downloadOtaFile(urlPath, localPath)
+        }
+      }, fail(err) {
+        // 文件不存在或其他错误
+        console.log(err)
+        // 文件不存在,开始下载
+        _this.downloadOtaFile(urlPath, localPath)
+      }
+    }
+    );
   },
+  downloadOtaFile(urlPath, localPath) {
+    let _this = this;
+    // const fs = wx.getFileSystemManager();
 
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload() {
+    wx.downloadFile({
+      url: urlPath, // 下载资源的URL
+      success: (res) => {
+        console.log('文件下载成功2', res);
+
+        if (res.statusCode === 200) {
+          // 下载成功,保存文件路径
+          const filePath = res.tempFilePath;
+          // _this.readFile(filePath);
 
+          // 将下载的文件移动到本地路径
+          fs.rename({
+            oldPath: filePath,
+            newPath: localPath,
+            success: () => {
+              wx.showToast({
+                title: '文件下载成功',
+              });
+              _this.readFile(localPath);
+            },
+            fail: (err) => {
+              _this.setOtaStatus(4);
+
+              wx.showToast({
+                title: '下载文件失败,检查下手机内存吧',
+              });
+              console.error('文件移动失败:', err);
+            }
+          });
+        } else {
+          _this.setOtaStatus(4);
+          wx.showToast({
+            title: '文件下载失败',
+          });
+        }
+      },
+      fail: (err) => {
+        _this.setOtaStatus(4);
+        wx.showToast({
+          title: '文件下载失败',
+        });
+        console.error('下载文件失败:', err);
+      }
+    });
   },
+  readFile(localFilePath) {
 
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
+    if (!localFilePath) {
+      wx.showToast({
+        title: '下载文件为空',
+      });
+      return;
+    }
+    wx.showLoading({
+      title: '开始传输文件',
+    })
+    const fs = wx.getFileSystemManager();
 
+    let _this = this;
+    fs.readFile({
+      filePath: localFilePath,
+      encoding: 'base64', // 可以选择 'utf8' 或 'base64'
+      success: (res) => {
+
+        // const btHelper = BtHelper.getInstance();
+        //   btHelper.ota(localFilePath);
+
+        console.log('文件内容:', res.data.length);
+
+        _this.startSend(res.data);
+      },
+      fail: (err) => {
+        wx.showToast({
+          title: 'OTA文件下载失败',
+        });
+        console.error('文件读取失败:', err);
+        _this.setOtaStatus(4);
+      }
+
+    });
   },
+  startSend(data) {
+    // const chunkSize = 20; // 每次发送的数据块大小
+    // const chunks = [];
+    // for (let i = 0; i < data.length; i += chunkSize) {
+    //   chunks.push(data.slice(i, i + chunkSize));
+    // }
 
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
+    // this.data._chunks = chunks;
+    this.sendOtaCmd(1)
+    // this.startSendOtaData()
+  },
+
+  startSendOtaData() {
+    let _this = this
+    let length = this.data._chunks.length
 
+    if (length === 0) {
+      wx.showToast({
+        title: '下载文件失败',
+        icon: 'none'
+      })
+      _this.sendOtaCmd(2)
+      return;
+    }
+    _this.sendOtaData(this.data._chunks, 0)
+    // }
+  }, sendOtaData(imageBuffer, index) {
+    let _this = this
+
+    if (index >= imageBuffer.length) {
+      _this.sendOtaCmd(0)
+      return;
+    }
+    let chunkSize = 20;
+
+
+    let total = imageBuffer.length
+    let next = index + chunkSize;
+    const chunk = imageBuffer.slice(index, next);
+    // todo 改成设备wifi下载
+    // BtHelper.getInstance().wallPaperData(chunk, function (res) {
+    //   console.log("发送OTA数据:", next)
+    //   if (res) {
+    //     _this.updateProgress(next, total);
+
+    //     _this.sendOtaData(imageBuffer)
+    //   } else {
+    //     wx.showModal({
+    //       title: 'OTA升级失败了',
+    //       showCancel: false
+    //     })
+    //   }
+    // })
+
+  },
+  sendOtaCmd(value) {
+    BtHelper.getInstance().otaCmd(value)
+    if (value == 0) {
+      this.setOtaStatus(0);
+    } else {
+      // this.setOtaStatus(4);
+    }
   },
 
+  startProgress() {
+    this.setData({
+      progress: 0,
+      showProgress: true
+    })
+  },
+  updateProgress(chunk, total) {
+    let progress = chunk / total * 100;
+    let _this = this
+    if (progress >= 100) {
+      _this.setData({
+        progress: 0,
+        showProgress: false,
+        // showCropImg: false
+      });
+      wx.showToast({
+        title: '图片上传成功',
+      })
+    } else {
+      _this.setData({
+        progress: progress,
+      });
+    }
+  },
+  otaSuccess() {
+    wx.hideLoading();
+    // 流程成功
+    wx.showModal({
+      title: '设备开始升级中',
+      showCancel: false,
+      success: function (res) {
+        if (res.confirm) {
+          route_util.goBackHomePage();
+        }
+      }
+    })
+  },
+  otaFailure() {
+    wx.hideLoading();
+    // 流程失败
+    wx.showModal({
+      title: '设备升级失败了',
+      showCancel: false,
+      success: function (res) {
+        if (res.confirm) {
+          // 
+        }
+      }
+    })
+  },
+  addNotification() {
+    let _this = this;
+    EventManager.addNotification(CmdEvent.eventName, function (event) {
+      let name = event.cmdEvent;
+      let kind = event.heiJiaoKind;
+      // 74,1,1是wifi连接成功,74,0 2连接wifi失败/没有wifi。   
+      // 发送url给你后,你回:74 0 1是流程成功,74 0 3是流程失败。
+      let otaCmd = event.otaCmd;
+      console.log("OTA页:", otaCmd, kind, name)
+
+      switch (name) {
+        case EnumCmdEvent.otaCmd:
+
+          if (otaCmd === 1 && kind == 1) {
+            wx.hideLoading();
+            // 设备收到开启OTA的回复,发送url
+            _this.sendUrlData()
+          } else if (otaCmd === 0 && kind == 2) {
+            wx.hideLoading();
+            // 去设置wifi界面
+            _this.goToWifi()
+          } else if (otaCmd === 0 && kind == 3) {
+            _this.otaFailure()
+          } else if (otaCmd === 0 && kind == 1) {
+            _this.otaSuccess()
+          }
+          else if (kind == 0) {
+
+          }
+          break;
+        case EnumCmdEvent.otaUrl:
+          // 小程序发:0x75,  0
+          if (otaCmd === 1 && kind == 1) {
+            // _this.sendOtaCmd(0)
+            _this.otaSuccess()
+            // BtHelper.getInstance().otaUrl(BtCmd.stringToUint8Array(_this.data.otaData.url))
+          } else {
+            _this.otaFailure()
+
+          }
+          break;
+        case EnumCmdEvent.otaWifi:
+          //0x76 
+          wx.hideLoading()
+          // 0x76, 发送wifi成功
+          if (otaCmd === 1 && kind == 1) {
+            _this.sendUrlData()
+          } else {
+            // wifi失败
+            _this.otaFailure()
+
+          }
+          break;
+      }
+    }, _this)
+  },
   /**
-   * 用户点击右上角分享
+   * 生命周期函数--监听页面加载
    */
-  onShareAppMessage() {
+  onLoad(options) {
+    let param = JSON.parse(options.param)
+    console.log("OTA界面:", param)
+    let otaData = param.otaData
+    let device = param.device
+    this.setData({
+      otaData: otaData,
+      device: device,
+      isShowOta: device.clientType === 'MW-S2(BLE)' || device.clientType === 'MW-S2'
+    })
+    this.addNotification()
+  },
+  onUnload() {
+    EventManager.removeNotification(CmdEvent.eventName, this)
+  },
 
-  }
 })

+ 3 - 1
pages/pageD/ota/ota.json

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

+ 32 - 2
pages/pageD/ota/ota.wxml

@@ -1,2 +1,32 @@
-<!--pages/pageD/ota/ota.wxml-->
-<text>pages/pageD/ota/ota.wxml</text>
+<!-- pages/OTA/ota.wxml -->
+<view class="section">
+    <nav-bar bind:goBack="_goBack" nav-bgc-class="ex-nav-bgc-class" nav-title-class="ex-nav-title-class" ex-back-pre="ex-back-pre" navbar-data='{{navbarData}}'></nav-bar>
+    <view style="height: 32rpx;"></view>
+    <view class="item">
+        <text class="label">制造商</text>
+        <text class="arrow">AirSmart</text>
+    </view>
+    <view class="item">
+        <text class="label">产品型号</text>
+        <text class="arrow">{{device.clientType}}</text>
+    </view>
+    <view class="item">
+        <text class="label">MAC地址</text>
+        <text class="arrow">{{device.mac}}</text>
+    </view>
+    <view wx:if="{{isShowOta}}" class="button main_color" bind:tap="startOtaTap">
+        {{buttonTips}}
+    </view>
+</view>
+<view wx:if="{{otaStatus === 3}}" class="background">
+    <view class="content">
+        <view class="pro_title">正在升级</view>
+        <view class="progress-container">
+            <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}};">
+                {{progressPercent}}%
+            </view>
+        </view>
+        <view class="pro_tips">升级过程中请勿离开当前页面</view>
+    </view>
+</view>

+ 100 - 1
pages/pageD/ota/ota.wxss

@@ -1 +1,100 @@
-/* pages/pageD/ota/ota.wxss */
+/* pages/OTA/ota.wxss */
+
+
+
+
+.item {
+	display: flex;
+	align-items: center;
+	border-bottom: 1px solid #e0e0e0;
+	justify-content: space-between;
+	margin-inline: 32rpx;
+	height: 120rpx;
+}
+
+
+.label {
+	font-size: 16px;
+	color: #333333;
+	margin-left: 32rpx;
+}
+
+.arrow {
+	margin-right: 16rpx;
+}
+
+.button {
+	margin-top: 128rpx;
+	display: flex;
+	justify-content: center;
+	align-items: center;
+	margin-inline: 64rpx;
+	font-size: 32rpx;
+	font-weight: Medium;
+	color: white;
+	text-align: center;
+	border-radius: 44rpx;
+	height: 88rpx;
+}
+
+
+.background {
+	position: fixed;
+	top: 0;
+	left: 0;
+	right: 0;
+	bottom: 0;
+	background-color: rgba(0, 0, 0, 0.7);
+	display: flex;
+	justify-content: center;
+	align-items: center;
+	z-index: 1000;
+}
+
+.content {
+	background-color: white;
+	padding-inline: 20px;
+	border-radius: 10px;
+	box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
+	width: 558rpx;
+	height: 404rpx;
+}
+
+.pro_title {
+	font-weight: 500;
+	font-size: 32rpx;
+	color: #333333;
+	text-align: center;
+	font-style: normal;
+	margin-top: 64rpx;
+}
+
+.progress-container {
+	position: relative;
+	margin-inline: 32rpx;
+	margin-top: 46rpx;
+	/* 根据需要调整 */
+}
+
+.progress {
+	width: 100%;
+}
+
+.progress-text {
+	position: absolute;
+	top: 50%;
+	transform: translateY(-50%);
+	color: white;
+	font-size: 16px;
+	z-index: 1;
+	white-space: nowrap;
+}
+
+.pro_tips {
+	margin-top: 48rpx;
+	margin-inline: 34rpx;
+	font-size: 28rpx;
+	color: #666666;
+	text-align: center;
+	font-style: normal;
+}