Pārlūkot izejas kodu

feature:修改OTA界面的升级流程

zeng.chen 6 mēneši atpakaļ
vecāks
revīzija
99b9d7c097

+ 3 - 38
pages/deviceDetail/detail.js

@@ -1,9 +1,7 @@
 const {
   BtHelper
 } = require('../../devices/bt_helper');
-const {
-  deviceVersion
-} = require('../../request/deviceListRequest')
+
 import {
   EnumCmdEvent,
   CmdEvent
@@ -19,26 +17,11 @@ Page({
     },
     // 页面数据
     device: {},
-    btHelper: null,
     updateData: {},
     powerOpen: false,
     isShowWallpaper: false,
 
   },
-  checkOtaVersion(device) {
-    let _this = this;
-    device.clientType = "MW-S2"
-    deviceVersion(device.clientType, device.connectType, device.version ?? "1.0.0").then(res => {
-      console.log("OTA2:", res);
-      let updateData = res ?? {};
-
-      let hasNewVersion = updateData.isEnforcement === 1 || updateData.isEnforcement === 2;
-      updateData.hasNewVersion = hasNewVersion;
-      _this.setData({
-        updateData: updateData
-      });
-    })
-  },
 
 
   goToWallpaper: function () {
@@ -47,16 +30,8 @@ Page({
   },
 
   goToOta: function () {
-    if (this.data.updateData.hasNewVersion != 1) {
-      wx.showToast({
-        title: '当前已是最新版本',
-        icon: 'none'
-      })
-      return
-    }
     let param = {
       "device": this.data.device,
-      "otaData": this.data.updateData,
     }
     let newParam = JSON.stringify(param);
     // wx.navigateTo({
@@ -118,12 +93,7 @@ Page({
       isShowWallpaper: device.clientType === 'MW-S2'
     })
 
-    const btHelper = BtHelper.getInstance();
-    let isShowOta = device.clientType === 'MW-S2'
-    if (isShowOta) {
-      btHelper.getVersion()
-      // this.checkOtaVersion(device);
-    }
+
     // btHelper.getPauseSleep()
 
     let _this = this;
@@ -131,12 +101,7 @@ Page({
       let name = event.cmdEvent;
       // console.log("详情页:", name, event)
       switch (name) {
-        case EnumCmdEvent.version:
-          _this.data.device.version = event.version;
-          console.log("详情页1:", event.version)
 
-          _this.checkOtaVersion(_this.data.device);
-          break;
         case EnumCmdEvent.authSleepStatus:
           let value = event.pauseSleep;
           console.log("详情页2:", value)
@@ -147,7 +112,7 @@ Page({
         case EnumCmdEvent.onoffline:
           console.log("详情页3:")
           //目前只有下线
-          _this.data.device.state = "offline"
+          _this.data.device.state = event.commonValue
           break;
       }
     }, this)

+ 1 - 1
pages/deviceDetail/detail.wxml

@@ -21,7 +21,7 @@
         <view class="item" bindtap="goToOta">
             <view class="left-content">
                 <text class="label">固件信息</text>
-                <view wx:if="{{updateData.hasNewVersion}}" class="red"></view>
+                <!-- <view wx:if="{{updateData.hasNewVersion}}" class="red"></view> -->
             </view>
             <image class="arrow" src="../../images/common/icon_arrow.png"></image>
         </view>

+ 71 - 18
pages/ota/ota.js

@@ -4,6 +4,10 @@ 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';
+import strings from '../../utils/strings.js';
+const {
+  deviceVersion
+} = require('../../request/deviceListRequest')
 
 // pages/OTA/ota.js
 Page({
@@ -17,8 +21,8 @@ Page({
       title: '固件信息',
     },
     device: {},
-    otaData: {},
-    btHelper: null,
+    _otaData: {},
+    hasNewVersion: false,
     progress: 0, // 进度条初始值
     otaStatus: 0,
     buttonTips: "固件更新",
@@ -28,6 +32,22 @@ Page({
     progressTextLeft: "0%",
     _timer: null,
   },
+  checkOtaVersion(device) {
+    let _this = this;
+    device.clientType = "MW-S2"
+    deviceVersion(device.clientType, device.connectType, device.version ?? "1.0.0").then(res => {
+      console.log("OTA2:", res);
+      let updateData = res ?? {};
+
+      let hasNewVersion = updateData.isEnforcement === 1 || updateData.isEnforcement === 2;
+      updateData.hasNewVersion = hasNewVersion;
+      _this.data._otaData = updateData;
+      _this.setData({
+        hasNewVersion: hasNewVersion
+      });
+    })
+  },
+
   setOtaStatus(status) {
     switch (status) {
       case 0:
@@ -73,6 +93,9 @@ Page({
 
   },
   startOtaTap() {
+
+    // this.goToWifi()
+    // return;
     let online = this.data.device.state === "online"
     if (!online) {
       wx.showToast({
@@ -80,11 +103,10 @@ Page({
       })
       return;
     }
-
-    let hasNewVersion = this.data.otaData.hasNewVersion ?? false
+    let hasNewVersion = this.data._otaData.hasNewVersion ?? false
     if (!hasNewVersion) {
       wx.showToast({
-        title: '没有可升级的固件',
+        title: '当前已是最新版本',
       })
       return;
     }
@@ -96,7 +118,7 @@ Page({
     let _this = this
     wx.showModal({
       title: '有新固件可升级',
-      content: _this.data.otaData.content ?? '提升体验,操作更流畅',
+      content: _this.data._otaData.content ?? '提升体验,操作更流畅',
       cancelText: '以后再说',
       confirmText: '升级',
       complete: (res) => {
@@ -111,19 +133,19 @@ Page({
           _this.sendOtaCmd(1)
 
           // _this.startDownloadFile()
-          // _this.downloadOtaFile(_this.data.otaData.url ?? "")
+          // _this.downloadOtaFile(_this.data._otaData.url ?? "")
         }
       }
     })
     // const btHelper = BtHelper.getInstance();
-    // btHelper.ota(this.data.otaData.file_url)
+    // btHelper.ota(this.data._otaData.file_url)
 
   },
   goToWifi() {
     route_util.jump(route_constant.setWifi)
   },
   sendUrlData() {
-    let url = this.data.otaData.url ?? ""
+    let url = this.data._otaData.url ?? ""
     let codeUrl = BtCmd.stringToUint8Array(url)
     BtHelper.getInstance().otaUrl(codeUrl);
   },
@@ -131,7 +153,7 @@ Page({
   // 读取文件废弃代码
   startDownloadFile() {
 
-    var urlPath = this.data.otaData.url ?? "";
+    var urlPath = this.data._otaData.url ?? "";
 
     var list = urlPath.split("/");
     // let cachePath = await PathUtil.getDownloadPath(fileName: list.last ?? 'OTAUpgrade.OTA');
@@ -341,10 +363,19 @@ Page({
     }
   },
   otaSuccess() {
+
+    var pages = getCurrentPages();
+    var length = pages.length;
+    var currentPage = pages[length - 1];
+    console.log("currentPage==", currentPage.route)
+    if (currentPage.route == "pages/setWifi/setWifi") {
+      console.log("currentPage==222", currentPage.route)
+      currentPage.wifiPageSuccess()
+    }
     wx.hideLoading();
     // 流程成功
     wx.showModal({
-      title: '设备开始升级中',
+      title: '设备开始升级中,请等待',
       showCancel: false,
       success: function (res) {
         if (res.confirm) {
@@ -380,7 +411,10 @@ Page({
         case EnumCmdEvent.otaCmd:
 
           if (otaCmd === 1 && kind == 1) {
-            wx.hideLoading();
+            wx.showLoading({
+              title: '正在下载ota文件...',
+              mask: true
+            });
             // 设备收到开启OTA的回复,发送url
             _this.sendUrlData()
           } else if (otaCmd === 0 && kind == 2) {
@@ -401,10 +435,9 @@ Page({
           if (otaCmd === 1 && kind == 1) {
             // _this.sendOtaCmd(0)
             _this.otaSuccess()
-            // BtHelper.getInstance().otaUrl(BtCmd.stringToUint8Array(_this.data.otaData.url))
+            // BtHelper.getInstance().otaUrl(BtCmd.stringToUint8Array(_this.data._otaData.url))
           } else {
             _this.otaFailure()
-
           }
           break;
         case EnumCmdEvent.otaWifi:
@@ -412,13 +445,27 @@ Page({
           wx.hideLoading()
           // 0x76, 发送wifi成功
           if (otaCmd === 1 && kind == 1) {
+            wx.showLoading({
+              title: 'wifi连接成功,正在下载ota文件...',
+              mask: true
+            });
             _this.sendUrlData()
           } else {
             // wifi失败
             _this.otaFailure()
-
           }
           break;
+        case EnumCmdEvent.onoffline:
+          let state = event.commonValue
+          _this.data.device.state = state
+          wx.hideLoading()
+          break;
+        case EnumCmdEvent.version:
+          _this.data.device.version = event.version;
+          console.log("OTA1:", event.version)
+
+          _this.checkOtaVersion(_this.data.device);
+          break;
       }
     }, _this)
   },
@@ -428,13 +475,19 @@ Page({
   onLoad(options) {
     let param = JSON.parse(options.param)
     console.log("OTA界面:", param)
-    let otaData = param.otaData
+    // let otaData = param.otaData
     let device = param.device
+    device.mac = strings.isEmpty(device.mac) ? device.deviceId : device.mac
     this.setData({
-      otaData: otaData,
       device: device,
-      isShowOta: device.clientType === 'MW-S2(BLE)' || device.clientType === 'MW-S2'
+      isShowOta: device.clientType === 'MW-S2'
     })
+    const btHelper = BtHelper.getInstance();
+    let isShowOta = device.clientType === 'MW-S2'
+    if (isShowOta) {
+      btHelper.getVersion()
+    }
+
     this.addNotification()
   },
   onUnload() {

+ 4 - 1
pages/ota/ota.wxml

@@ -15,7 +15,10 @@
         <text class="arrow">{{device.mac}}</text>
     </view>
     <view wx:if="{{isShowOta}}" class="button main_color" bind:tap="startOtaTap">
-        {{buttonTips}}
+        <view class="left-content">
+            <text class="button_title">{{buttonTips}}</text>
+            <view wx:if="{{hasNewVersion}}" class="red"></view>
+        </view>
     </view>
 </view>
 <view wx:if="{{otaStatus === 3}}" class="background">

+ 20 - 4
pages/ota/ota.wxss

@@ -23,21 +23,37 @@
 	margin-right: 16rpx;
 }
 
+.left-content {
+	display: flex;
+	align-items: center;
+}
+
+.red {
+	width: 15rpx;
+	height: 15rpx;
+	margin-top: -14rpx;
+	background-color: red;
+	border-radius: 50%;
+	margin-left: 12rpx;
+}
+
+.button_title {
+	font-size: 32rpx;
+	font-weight: Medium;
+	color: white;
+}
+
 .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;