Przeglądaj źródła

feature: 抽取版本更新

Damon 8 miesięcy temu
rodzic
commit
588c53bb36

+ 11 - 5
app.js

@@ -1,6 +1,7 @@
 // app.ts
 import btHelper from './devices/bt_helper';
 import mqtt from './utils/mqtt';
+import update from './utils/update';
 //连接的服务器域名
 // const host = 'wxs://mqtt.test.radio1964.com';
 const host = 'wxs://mqtt.ssl.keepradioon.net:8884'
@@ -39,6 +40,11 @@ App({
       keepalive: 3, //每3秒发送一次心跳
     },
   },
+
+  onShow: function () {
+    update.update();
+  },
+
   /**
    * 连接设备
    * mqttCallback:mqtt回调统一方法
@@ -51,11 +57,11 @@ App({
       if (pageinfo.mqttCallback) {
         pageinfo.mqttCallback("connect")
       };
-
     });
+
     // 接收消息
     this.globalData.client.on("message", function (topic, payload) {
-      wx.hideLoading();
+      // wx.hideLoading();
       const pageinfo = getCurrentPages()[getCurrentPages().length - 1];
       const thisPageIsIndex = getCurrentPages().length === 1;
       if (pageinfo.mqttCallback) {
@@ -156,9 +162,9 @@ App({
    */
   PubMsg(option, callback) {
     if (this.globalData.client && this.globalData.client.connected) {
-      wx.showLoading({
-        title: '请稍后',
-      });
+      // wx.showLoading({
+      //   title: '请稍后',
+      // });
       const data = {
         "DstDeviceName": option.DstDeviceName,
         "SrcDeviceName": `ALY_${this.globalData.userInfo.userId}`,

+ 0 - 6
pages/deviceConnect3/deviceConnect3.js

@@ -112,16 +112,10 @@ Page({
               success(res) {
                 if (res.data) {
                   let arr = JSON.parse(res.data);
-
-                  console.log("gadsfadsfadsfa==00===" + JSON.stringify(arr));
-                  console.log("gadsfadsfadsfa==aa===" + _this.data.name);
                   // 同一个设备
                   const devicelist = arr.filter((v) => v.deviceId === _this.data.name);
-
-                  console.log("gadsfadsfadsfa==11===" + JSON.stringify(arr));
                   if (devicelist.length > 0) {
                     arr = arr.filter((v) => v.deviceId !== _this.data.name);
-                    console.log("gadsfadsfadsfa==222===" + JSON.stringify(arr));
                   };
 
                   // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online"}]

+ 26 - 31
pages/index/index.js

@@ -45,7 +45,6 @@ Page({
     isSetWake: false,
     thisDeviceMac: null,
     battery: 4, // 0≤电量<20,0格
-    newVersion: false,
 
     ////我的界面
     loginStatus: true,
@@ -102,22 +101,6 @@ Page({
 
   onHomeLoad() {
     var that = this;
-    // 版本自动更新代码
-    const updateManager = wx.getUpdateManager();
-    updateManager.onUpdateReady(function () {
-      that.setData({
-        newVersion: true
-      });
-    })
-    updateManager.onUpdateFailed(function () {
-      // 新的版本下载失败
-      wx.showModal({
-        title: '已有新版本咯',
-        content: '请您删除当前小程序,重新打开呦~',
-        showCancel: false
-      })
-    })
-
     // wx.showLoading({
     //   title: '加载中',
     // });
@@ -145,7 +128,6 @@ Page({
   },
 
   onMeLoad() {
-    // wx.getStorage("userInfo")
     var that = this;
     wx.getStorage({
       key: "userInfo",
@@ -588,11 +570,10 @@ Page({
         //   other
         // });
       }
-
     })
   },
 
-  goChnnel() {
+  goChannel() {
     var that = this;
     wx.setStorage({
       key: "channelDeta",
@@ -610,13 +591,6 @@ Page({
     wx.getUpdateManager().applyUpdate()
   },
 
-  updataClone() {
-    var that = this;
-    that.setData({
-      newVersion: false
-    })
-  },
-
   onUnload() {
     if (app.globalData.client === null) {
       return;
@@ -699,19 +673,29 @@ Page({
 
   ///点击item
   // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
-  onTapIem(e) {
+  onTapItem(e) {
     var that = this;
     var item = e.currentTarget.dataset.item;
     var ProdModel = item.ProdModel;
     if (ProdModel == "MW-2AX(WIFI-N)") {
+      console.log("gadfadsfadsfaf===aa");
       if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
+        console.log("gadfadsfadsfaf===bbb");
         that.goWake();
       } else {
+        console.log("gadfadsfadsfaf===ccc");
         that.actionDevice(e.currentTarget.dataset.index)
       }
       return;
     }
     ///去蓝牙连接处理
+    that.addConnectBlueDevice({
+      deviceId: item.deviceId,
+      name: item.devName,
+      state: item.state,
+      clientType: item.ProdModel,
+      mac: item.mac,
+    });
   },
 
   actionDevice(index) {
@@ -720,6 +704,7 @@ Page({
     if (device.state !== "online") {
       return;
     };
+
     // 取消订阅
     if (that.data.thisDeviceMac !== null) {
       app.unsubscribe(`/${that.data.thisDeviceMac}/user/pub_response`);
@@ -856,10 +841,11 @@ Page({
     var that = this;
     // 同一个设备
     var deviceList = that.data.deviceList;
-    var tempList = deviceList.filter((v) => v.deviceId === newDevice.name);
+    var tempList = deviceList.filter((v) => v.deviceId === newDevice.deviceId);
     if (tempList && tempList.length > 0) {
-      deviceList = deviceList.filter((v) => v.deviceId !== newDevice.name);
+      deviceList = deviceList.filter((v) => v.deviceId !== newDevice.deviceId);
     };
+
     deviceList.unshift({
       /// 蓝牙ble连接
       connectType: 1,
@@ -868,6 +854,7 @@ Page({
       state: "online",
       ProdModel: newDevice.clientType,
       devName: newDevice.name,
+      mac: newDevice.mac,
     });
 
     var finalList = that.updateDeviceList(deviceList);
@@ -968,4 +955,12 @@ Page({
     return finalList;
   },
 
-})
+})
+
+
+// updataClone() {
+//   var that = this;
+//   that.setData({
+//     newVersion: false
+//   })
+// },

+ 7 - 6
pages/index/index.wxml

@@ -28,13 +28,13 @@
 
       <view wx:if="{{deviceList}}">
         <block wx:key="key" wx:for-item="item" wx:for-index="index" wx:for="{{deviceList}}">
-          <view class="item_public" style="width: calc(100vw - 72rpx);border: {{item.state && item.state === 'online'&&deviceListIndex === index  ? '4rpx solid #6546A3' : item.state && item.state === 'online'?'2rpx solid #6546A3':'2rpx solid #F2F5F7'}}; margin-left: {{item.state && item.state === 'online'&&deviceListIndex === index  ?0:4}}rpx;" data-item="{{item}}" data-index="{{index}}" bind:tap="{{item.state && item.state === 'online' ? 'onTapIem' : ''}}">
+          <view class="item_public" style="width: calc(100vw - 72rpx);border: {{item.state && item.state === 'online'&&deviceListIndex === index  ? '4rpx solid #6546A3' : item.state && item.state === 'online'?'2rpx solid #6546A3':'2rpx solid #F2F5F7'}}; margin-left: {{item.state && item.state === 'online'&&deviceListIndex === index  ?0:4}}rpx;" data-item="{{item}}" data-index="{{index}}" bind:tap="{{item.state && item.state === 'online' ? 'onTapItem' : ''}}">
             <image class="item_public_image" src="./../../img/min.png" style="opacity: {{item.state && item.state === 'online' ? '1' : '0.5'}};"></image>
             <view class="item_public_right" style="margin-right: 26rpx; opacity: {{item.state && item.state === 'online' ? '1' : '0.5'}};">
               <view style="height: 190rpx; margin-top: 37rpx; margin-left: 32rpx; flex-direction: column; display: flex;">
                 <view style="flex: 1;">
                   <view style="display: flex;">
-                    <view style="color: #333333; font-size: 28rpx; flex: 1;padding-right: 5rpx;">{{item.devName||" "}}</view>
+                    <view style="color: #333333; font-size: 28rpx; flex: 1;padding-right: 5rpx;">{{item.devName}}</view>
                     <image wx:if="{{item.state && item.state === 'online'&&deviceListIndex === index }}" mode="heightFix" src="./../../img/add_device_arrow.png" style="width: 48rxp;height: 48rpx;"></image>
                   </view>
                   <view style="color: #666666; font-size: 24rpx;">{{item.state && item.state === "online" ? (item.connectType==3?"Wifi在线":"蓝牙在线") : "离线"}}</view>
@@ -62,7 +62,7 @@
               <view wx:if="{{actionIndex !== null}}" style="opacity: 1;" class="fm">FM.{{actionIndex !== null ? (actionIndex + 1 < 10 ? "0" + (actionIndex + 1) : actionIndex + 1) : 00}} <image class="gochnnalList" mode="heightFix" src="./../../img/a6.png">
                   </image>
               </view>
-              <view class="fmMod" bindtap="goChnnel"></view>
+              <view class="fmMod" bindtap="goChannel"></view>
               <view wx:if="{{actionIndex !== null}}" class="thisMusic">
                 <text>当前播放:</text>
                 <view class="scroll-box">
@@ -166,7 +166,8 @@
         <image class="bottom_image" mode="widthFix" src="{{indexPage==0?'./../../img/index_action.png':'./../../img/index_unaction.png'}}"></image>
         <view style="font-size: 20rpx;color: {{indexPage==0?'#A4D099':'black'}}; padding-top: 0rpx;margin-top: 0rpx;"> 首页</view>
       </view>
-      <view wx:if="{{deviceListIndex!=null&&deviceList.length>deviceListIndex&&deviceList[deviceListIndex].devName==='MW-2AX(WIFI-N)'}}" class="bottom_view" data-index="1" bind:tap="onTapIndex">
+
+      <view wx:if="{{deviceListIndex!=null&&deviceList.length>deviceListIndex&&deviceList[deviceListIndex].ProdModel==='MW-2AX(WIFI-N)'}}" class="bottom_view" data-index="1" bind:tap="onTapIndex">
         <image class="bottom_image" mode="widthFix" src="{{indexPage==1?'./../../img/channel_action.png':'./../../img/channel_unaction.png'}}"></image>
         <view style="font-size: 20rpx;color: {{indexPage==1?'#A4D099':'black'}};"> 频道</view>
       </view>
@@ -177,7 +178,7 @@
     </view>
   </view>
 
-  <view wx:if="{{newVersion}}" class="updataminiwx">
+  <!-- <view wx:if="{{newVersion}}" class="updataminiwx">
     <view class="mode">
       <image class="bg" src="./../../img/BG@2x.png"></image>
       <view class="updata-view">
@@ -190,4 +191,4 @@
         </view>
       </view>
     </view>
-  </view>
+  </view> -->

+ 2 - 2
pages/index/index.wxss

@@ -507,7 +507,7 @@
    z-index: 1000;
  }
 
- .updataminiwx {
+ /* .updataminiwx {
    position: fixed;
    top: 0;
    left: 0;
@@ -592,7 +592,7 @@
  .updataminiwx .mode .updata-view>view .twoBut {
    background-color: rgba(101, 71, 163, 1);
    color: #fff;
- }
+ } */
 
 
  /************************ 我的 ************************/

+ 39 - 0
utils/update.js

@@ -0,0 +1,39 @@
+module.exports = {
+  update: update
+}
+
+var isShowed = false;
+
+//检测版本是否更新
+function update() {
+  if (isShowed) {
+    return;
+  }
+
+  //检测版本更新
+  const manager = wx.getUpdateManager();
+
+  //检测版本是否更新
+  manager.onCheckForUpdate(function (e) {
+
+  });
+
+  //版本更新
+  manager.onUpdateReady(function (e) {
+    isShowed = true;
+    wx.showModal({
+      title: '已有新版本咯',
+      content: '请您删除当前小程序,重新打开呦~',
+      success: function (res) {
+        if (res.confirm) {
+          manager.applyUpdate();
+        }
+      }
+    });
+  });
+
+  //版本更新失败
+  manager.onUpdateFailed(function (e) {
+
+  });
+};