Parcourir la source

feature: 处理蓝牙和wifi设备点击item处理

Damon il y a 8 mois
Parent
commit
d83fb9fb47

+ 1 - 1
app.js

@@ -27,7 +27,7 @@ App({
     isHuaWei: false,
     btHelper: null,
     // 当前设备
-    device: {},
+    // device: {},
     // 设备列表,跟app同步字段
     classifyProducts: [],
     //MQTT连接的配置

+ 8 - 63
pages/channelDetails/channelDetails.js

@@ -1,11 +1,10 @@
 // pages/channelDetails/channelDetails.js
-const { pageByDevice }=require('./../../utils/api.js');
+const {
+  pageByDevice
+} = require('./../../utils/api.js');
 const app = getApp();
 Page({
 
-  /**
-   * 页面的初始数据
-   */
   data: {
     nvabarData: {
       showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
@@ -15,28 +14,23 @@ Page({
     MenuButtonTop: app.globalData.MenuButtonTop,
     thisChannel: {},
     pageIndex: 1,
-    channelList:[],
+    channelList: [],
   },
 
-  /**
-   * 生命周期函数--监听页面加载
-   */
   onLoad() {
-
-    const _this = this;
-
+    var that = this;
     wx.getStorage({
       key: "channelDeta",
       success(res) {
-        _this.setData({
+        that.setData({
           thisChannel: res.data
         });
         pageByDevice({
           channelId: res.data.channelId,
           pageNum: 1,
           pageSize: 300
-        }).then((res)=> {
-          _this.setData({
+        }).then((res) => {
+          that.setData({
             channelList: res.records
           })
           wx.removeStorage({
@@ -45,55 +39,6 @@ Page({
         })
       }
     })
-    
-  },
-
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide() {
-
   },
 
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload() {
-
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
-
-  },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-
-  },
-
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
-
-  }
 })

+ 3 - 3
pages/channelDetails/channelDetails.wxml

@@ -10,11 +10,11 @@
         </view>
         <view class="textInfo">
           <text>FM.{{thisChannel.channelNum !== null ? (thisChannel.channelNum < 10 ? "0" + (thisChannel.channelNum) : thisChannel.channelNum) : 00}}</text>
-          <text>{{thisChannel.channelName}}</text>
+              <text>{{thisChannel.channelName}}</text>
         </view>
       </view>
       <!-- <image class="bgPic_1" src="./../../img/pd1.png" mode="heightFix"></image> -->
-      <image class="bgPic_3"  src="./../../img/pd3.png" mode="widthFix"></image>
+      <image class="bgPic_3" src="./../../img/pd3.png" mode="widthFix"></image>
       <image class="bgPic_2" src="./../../img/pd2.png" mode="heightFix"></image>
     </view>
     <view class="list" style="height: calc(100vh - {{navBarHeight}}px - 260rpx);">
@@ -24,4 +24,4 @@
       </view>
     </view>
   </view>
-</view>
+</view>

Fichier diff supprimé car celui-ci est trop grand
+ 1 - 1
pages/connectBle/connectBle.js


+ 22 - 20
pages/deviceConnect2/deviceConnect2.js

@@ -25,7 +25,7 @@ Page({
     isOnBluetooth: false,
   },
   onShow() {
-    if(!this.data.isOne) {
+    if (!this.data.isOne) {
       this.Search();
     }
   },
@@ -34,48 +34,49 @@ Page({
    */
   onLoad() {
     const _this = this;
-    const isOne = setTimeout(()=> {
+    const isOne = setTimeout(() => {
       clearTimeout(isOne);
-      if(_this.data.isOne) {
+      if (_this.data.isOne) {
         _this.setData({
           isOne: false,
         });
       }
     }, 2000);
-    if(app.globalData.oneInitBluetooth) {
+    if (app.globalData.oneInitBluetooth) {
       app.globalData.oneInitBluetooth = false;
       xBlufi.initXBlufi(1);
     };
     xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
     this.Search();
   },
-  funListenDeviceMsgEvent: function(options) {
+  funListenDeviceMsgEvent: function (options) {
     const _this = this;
     switch (options.type) {
       case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
         // 搜索到蓝牙
+        // console.log("gadsfadsfadsfa==xxx===" + JSON.stringify(options));
         if (options.result) {
-          if(options.data.filter((v)=> v.name.indexOf("BLUFI_") !== -1 ).length > 0) {
+          if (options.data.filter((v) => v.name.indexOf("BLUFI_") !== -1).length > 0) {
             _this.setData({
               islanya: true,
-              devicesList: options.data.filter((v)=> v.name.indexOf("BLUFI_") !== -1 )
+              devicesList: options.data.filter((v) => v.name.indexOf("BLUFI_") !== -1)
             });
           }
         }
-          
+
         break;
 
       case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
         // console.log("连接回调:" + JSON.stringify(options))
         if (options.result) {
           wx.hideLoading();
-          if(_this.data.isOnBluetooth) {
+          if (_this.data.isOnBluetooth) {
             return;
           };
           _this.setData({
             isOnBluetooth: true,
           });
-          setTimeout(()=> {
+          setTimeout(() => {
             _this.setData({
               isSubmit: false,
               islanya: false,
@@ -127,17 +128,18 @@ Page({
 
     }
   },
-  Search: function() {
+  Search: function () {
     xBlufi.notifyStartDiscoverBle({
       'isStart': true,
     });
   },
-  Connect: function(e) {
-    if(!this.data.islanya) {
-      return;
-    };
+  Connect: function (e) {
+    // if(!this.data.islanya) {
+    //   return;
+    // };
+
     const deviceIdData = this.data.devicesList;
-    if(deviceIdData.length < 1) {
+    if (deviceIdData.length < 1) {
       wx.showToast({
         title: '请短按设备配对键',
         icon: 'none',
@@ -145,8 +147,8 @@ Page({
       });
       return;
     };
-    
-    if(this.data.isSubmit) {
+
+    if (this.data.isSubmit) {
       return;
     };
     this.setData({
@@ -168,13 +170,13 @@ Page({
       title: '请稍后',
     });
   },
-  onUnload: function() {
+  onUnload: function () {
     xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
   },
   getBluetoothStatus() {
     app.getBluetoothStatus();
   },
-  notRoter(){
+  notRoter() {
     wx.navigateBack({
       delta: 1
     });

+ 59 - 40
pages/deviceConnect3/deviceConnect3.js

@@ -10,13 +10,13 @@ Page({
    * 页面的初始数据
    */
   data: {
-    scopeBluetooth: app.globalData.scopeBluetooth,
-    ssid: app.globalData.ssid,
-    password: app.globalData.pwdData,
     nvabarData: {
       showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
       title: '连接配网', //导航栏 中间的标题
     },
+    scopeBluetooth: app.globalData.scopeBluetooth,
+    ssid: app.globalData.ssid,
+    password: app.globalData.pwdData,
     version: '2.0',
     name: '',
     connectedDeviceId: '',
@@ -27,10 +27,10 @@ Page({
     percent: 0,
     ruterStatus: 0, // 0 连接中 // 1 成功 // 2失败
   },
-  onShow: function(options) {
+  onShow: function (options) {
 
   },
-  onLoad: function(options) {
+  onLoad: function (options) {
     _this = this;
     _this.setData({
       name: options.name,
@@ -40,8 +40,8 @@ Page({
     xBlufi.notifyInitBleEsp32({
       deviceId: options.deviceId,
     });
-    percentIn = setInterval(()=> {
-      if(_this.data.percent === 100) {
+    percentIn = setInterval(() => {
+      if (_this.data.percent === 100) {
         clearInterval(percentIn);
         _this.setData({
           ruterStatus: 2
@@ -54,7 +54,7 @@ Page({
       });
     }, 600);
   },
-  onUnload: function() {
+  onUnload: function () {
     // 关闭蓝牙连接
     let _this = this
     xBlufi.notifyConnectBle({
@@ -66,10 +66,10 @@ Page({
     clearTimeout(errTi);
     clearInterval(percentIn);
   },
-  funListenDeviceMsgEvent: function(options) {
+  funListenDeviceMsgEvent: function (options) {
     let _this = this;
     switch (options.type) {
-      
+
       case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
         _this.setData({
           connected: options.result
@@ -79,7 +79,7 @@ Page({
             title: '很抱歉提醒你!',
             content: '小程序与设备异常断开',
             showCancel: false, //是否显示取消按钮
-            success: function(res) {
+            success: function (res) {
               wx.navigateBack({
                 delta: 1
               });
@@ -92,16 +92,16 @@ Page({
       case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_ROUTER_RESULT:
         wx.hideLoading();
         if (!options.result)
-          errTi = setTimeout(()=> {
+          errTi = setTimeout(() => {
             _this.setData({
               ruterStatus: 2
             });
             clearTimeout(errTi);
             clearInterval(percentIn);
           }, 5000);
-          
+
         else {
-          
+
           // 配网成功
           if (options.data.progress == 100) {
             clearTimeout(errTi);
@@ -109,34 +109,50 @@ Page({
             // 更新数据
             wx.getStorage({
               key: 'devicelist',
-              success (res) {
-                if(res.data) {
+              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);
-                  if(devicelist.length > 0) {
-                    arr = arr.filter((v)=> v.deviceId !== _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"}]
                   arr.unshift({
+                    /// Wifi mqtt-连接
+                    connectType: 3,
                     deviceId: _this.data.name,
                     name: _this.data.name,
                     state: "online"
                   });
-                  wx.setStorage({
-                    key:"devicelist",
-                    data: JSON.stringify(arr),
-                    success() {
-                      _this.setData({
-                        percent: 100,
-                        ruterStatus: 1
-                      });
-                    }
-                  })
+
+                  getCurrentPages()[0].addConnectWifiDevice(arr);
+                  _this.setData({
+                    percent: 100,
+                    ruterStatus: 1
+                  });
+                  // wx.setStorage({
+                  //   key: "devicelist",
+                  //   data: JSON.stringify(arr),
+                  //   success() {
+                  //     _this.setData({
+                  //       percent: 100,
+                  //       ruterStatus: 1
+                  //     });
+                  //   }
+                  // })
                 }
               },
               fail() {
                 wx.setStorage({
-                  key:"devicelist",
+                  key: "devicelist",
                   data: JSON.stringify([{
                     name: _this.data.name,
                     deviceId: _this.data.name,
@@ -153,8 +169,11 @@ Page({
             })
             // 记住密码
             wx.setStorage({
-              key:"wifiInfo",
-              data: JSON.stringify({"password": app.globalData.pwdData, "ssid": app.globalData.ssid})
+              key: "wifiInfo",
+              data: JSON.stringify({
+                "password": app.globalData.pwdData,
+                "ssid": app.globalData.ssid
+              })
             });
           }
         }
@@ -178,7 +197,7 @@ Page({
     }
   },
 
-  OnClickStart: function() {
+  OnClickStart: function () {
     if (!app.globalData.ssid) {
       wx.showToast({
         title: 'SSID不能为空',
@@ -199,26 +218,26 @@ Page({
       password: app.globalData.pwdData
     });
   },
-  bindPasswordInput: function(e) {
+  bindPasswordInput: function (e) {
     this.setData({
       password: e.detail.value
     })
   },
-  bindCustomDataInput: function(e) {
+  bindCustomDataInput: function (e) {
     this.setData({
       customData: e.detail.value
     })
   },
-  egen(){
+  egen() {
     wx.navigateBack({
       delta: 1
     })
   },
-  goIndex(){
+  goIndex() {
     //  BLUFI_7cdfa1fd3cfc
     app.globalData.newDeviceId = this.data.name;
-          wx.redirectTo({
-            url: '/pages/index/index'
-          });
+    wx.redirectTo({
+      url: '/pages/index/index'
+    });
   }
 })

+ 3 - 55
pages/deviceDetail/detail.js

@@ -7,74 +7,22 @@ Page({
   onLoad: function () {
     // 页面加载时的逻辑
   },
+
   goToAccountSecurity: function () {
     wx.navigateTo({
       url: '/pages/accountSecurity/accountSecurity'
     });
   },
+
   goToPrivacySettings: function () {
     wx.navigateTo({
       url: '/pages/privacySettings/privacySettings'
     });
   },
+
   goToNotificationSettings: function () {
     wx.navigateTo({
       url: '/pages/notificationSettings/notificationSettings'
     });
   },
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad(options) {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload() {
-
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
-
-  },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-
-  },
-
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
-
-  }
 })

Fichier diff supprimé car celui-ci est trop grand
+ 60 - 18
pages/index/index.js


+ 3 - 3
pages/index/index.wxml

@@ -34,10 +34,10 @@
               <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" ? "在线" : "离线"}}</view>
+                  <view style="color: #666666; font-size: 24rpx;">{{item.state && item.state === "online" ? (item.connectType==3?"Wifi在线":"蓝牙在线") : "离线"}}</view>
                 </view>
                 <view style="align-items: center; justify-content: center; vertical-align: middle;width: 280rpx;height: 64rpx;background-color: #F2F5F7;  border-radius: 52rpx; text-align: center; justify-content: center;  display: flex;" data-index="{{index}}" catchtap="deleteDevice">
                   <view style="color: #666666; font-size: 28rpx; ">删除</view>
@@ -166,7 +166,7 @@
         <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==='猫王小王子OTR-X'}}" class="bottom_view" data-index="1" bind:tap="onTapIndex">
+      <view wx:if="{{deviceListIndex!=null&&deviceList.length>deviceListIndex&&deviceList[deviceListIndex].devName==='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>