Ver código fonte

Merge branch 'feature/3.2.0' of http://60.205.190.38:9000/wuhao/wxmini into feature/3.2.0

Damon 1 ano atrás
pai
commit
41346fd838

+ 115 - 48
pages/bluConnect/bleconnect.js

@@ -1,4 +1,6 @@
 // pages/bluConnect/bleconnect.js
+const app = getApp();
+
 Page(
   {
     /**
@@ -12,7 +14,6 @@ Page(
       connectPic: "",
       connectTips: "正在搜索设备,请保持开机状态...",
       buttonTips: "正在搜索设备",
-
       userFuzzyLocation: true,
       nvabarData: {
         showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
@@ -26,15 +27,69 @@ Page(
       isNotruter: false,
       deviceItem: {
         "pic": "../../img/g.png",
-        "address": "",
+        "address": "xxxxxx",
         "name": "猫王钢琴音箱",
         "devName": "名称1", "state": "online", "power": 40
       }
-    }, getBluetoothStatusCallck(v) {
+    },
+    updateBleStatus() {
+      var _this = this;
+      switch (_this.connectStatus) {
+        case 1:
+          // 搜索中
+          _this.connectTips = "正在搜索设备,请保持开机状态...";
+          break;
+        case 2:
+          // 连接中
+          _this.connectText = "连接中...";
+          _this.connectPic = "";
+          break;
+        case 3:
+          // 连接失败
+          _this.connectText = "连接失败";
+          _this.connectPic = "../../img/i.png";
+          break;
+        case 4:
+          // 连接成功
+          _this.connectText = "连接成功";
+          _this.connectPic = "../../img/h.png";
+
+          break;
+        case 5:
+          // 搜索成功
+          _this.deviceItem = {
+            "pic": "../../img/g.png",
+            "address": "xxxxxx",
+            "name": "猫王钢琴音箱",
+            "devName": "名称1", "state": "online", "power": 40
+          };
+          _this.connectTips = "搜索到" + _this.deviceItem.name;
+          _this.buttonTips = "连接设备";
+          _this.isScaning = false;
+          _this.connectText = "搜索成功";
+
+          break;
+      }
+      _this.setData({
+        buttonTips: _this.buttonTips,
+        connectTips: _this.connectTips,
+        isScaning: _this.isScaning,
+        connectPic: _this.connectPic,
+        connectText: _this.connectText,
+        deviceItem: _this.deviceItem,
+        connectStatus: _this.connectStatus
+      })
+    },
+    getBluetoothStatusCallck(v) {
+      this.connectStatus = 1;
+      this.updateBleStatus();
+
       this.setData({
         scopeBluetooth: v,
-        isScaning:v
       })
+      if (v) {
+        this.scanDevice();
+      }
     },
     setBluetooth() {
       wx.openSetting({
@@ -43,19 +98,66 @@ Page(
         }
       })
     }, connectDeviceTap() {
-      var _this = this;
-      const eventChannel = this.getOpenerEventChannel();
-      eventChannel.emit('getBackData', {  
-       backData:  _this.deviceItem});
+      const _this = this;
 
-      wx.navigateBack();
-
-      if (!_this.isScaning) {
+      if (_this.isScaning) {
+        console.log("连接中2");
         return;
       }
 
+      // todo 测试
+      console.log("连接中");
+      this.connectStatus = 4;
+      this.updateBleStatus();
+
+      setTimeout(() => {
+        const eventChannel = _this.getOpenerEventChannel();
+        eventChannel.emit('getBackData', {
+          backData: _this.deviceItem
+        });
+        wx.navigateBack();
+      }, 1000);
+
+      return;
+
+      wx.openBluetoothAdapter({
+        success(res) {
+
+          // var _this = this;
+          // const eventChannel = this.getOpenerEventChannel();
+          // eventChannel.emit('getBackData', {
+          //   backData: _this.deviceItem
+          // });
+
+          // wx.navigateBack();
+
+
+
+        },
+        fail(res) {
+          console.log("连接失败:" + res);
+
+          if (res.errCode === 10001) {
+            wx.showToast({
+              title: '蓝牙未打开',
+              icon: "none",
+              duration: 2000
+            })
+          }
+        }
+      });
+
     }, scanDevice() {
-      this.isScaning = true;
+      this.setData({
+        isScaning: true,
+      });
+
+      setTimeout(() => {
+        console.log("2324");
+        this.connectStatus = 5;
+        this.updateBleStatus();
+      }, 3000);
+
     },
 
     /**
@@ -66,43 +168,8 @@ Page(
       if (options.isLognlink) {
 
       }
+      app.getBluetoothStatus();
 
-      this.buttonTips = this.isScaning ? "正在搜索设备" : "连接";
-
-      this.connectStatus = 4;
-      switch (this.connectStatus) {
-        case 1:
-          // 搜索中
-          this.connectTips = "正在搜索设备,请保持开机状态...";
-          break;
-        case 2:
-          // 连接中
-          this.connectText = "连接中...";
-          this.connectPic = "";
-        case 3:
-          // 连接失败
-          this.connectText = "连接失败";
-          this.connectPic = "../../img/i.png";
-          break;
-        case 4:
-          // 连接成功
-          this.connectText = "连接成功";
-          this.connectPic = "../../img/h.png";
-          this.deviceItem = {
-            "pic": "../../img/g.png",
-            "address": "xxxxxx",
-            "name": "猫王钢琴音箱",
-            "devName": "名称1", "state": "online", "power": 40
-          };
-          break;
-        case 5:
-          // 搜索成功
-          this.connectTips = "搜索到" + this.deviceItem.name;
-          var curPage = getCurrentPages();
-          var homePage = curPage[curPage.length - 1];
-
-          break;
-      }
     },
 
     /**

+ 1 - 1
pages/bluConnect/bleconnect.wxml

@@ -5,7 +5,7 @@
   <image class="device_pic_class" src="{{deviceItem.pic}}" mode="scaleToFill" />
     <text class="scanDeviceClass">{{connectTips}}</text>
     <view class="connect_tips" wx:if="{{isScaning}}">确认手机蓝牙已经打开</view>
-    <span wx:if="{{connectStatus == 4}}" class="scan_device_status_class">
+    <span wx:if="{{connectStatus > 1}}" class="scan_device_status_class">
       <image class="scan_device_status_img_class" src="{{connectPic}}" mode="scaleToFill" />
       <text class="scan_device_status_text_class">{{connectText}}</text>
     </span>

+ 10 - 13
pages/bluConnect/bleconnect.wxss

@@ -42,29 +42,26 @@ text-align: center;
 .container .scan_device_status_class {
   /* align-items: center; */
   margin-top: 16rpx;
-  margin-left: 16rpx;
-  margin-right: 16rpx;
-  flex-direction: row;
-  text-align: center;
-
+  display: flex;
+  justify-content: center;
+  align-items: center; 
 }
 
 
-.container .scan_device_status_class > scan_device_status_img_class {
-  width: 16rpx;
-  height: 16rpx;
+.container .scan_device_status_class .scan_device_status_img_class {
+  width: 32rpx;
+  height: 32rpx;
 }
 
-.container .scan_device_status_class > scan_device_status_text_class {
-  margin-right: 16rpx;
-  width: 16rpx;
-  height: 16rpx;
+.container .scan_device_status_class .scan_device_status_text_class {
+  margin-left: 16rpx;
 }
 
 .container .connect_btn_class {
   padding-left: 56rpx;
   padding-right: 56rpx;
-  padding-bottom: 56rpx;
+  /* padding-bottom: 56rpx; */
+  margin-bottom: 56rpx;
   margin-top: 70rpx;
   justify-content: center; 
   display: flex;

+ 0 - 1
pages/home/home.js

@@ -156,7 +156,6 @@ Page({
       url: './../bluConnect/bleconnect',
       events: {
         getBackData: res => {
-          console.log(res);
           var key = 'home_device_list' + wx.getUserInfo().userId;
           var saveStr = wx.getStorageSync(key) ?? "[]";