瀏覽代碼

Merge branch 'develop/3.2.5' into develop/3.2.4_黑胶

332777428@qq.com 6 月之前
父節點
當前提交
cef6d37f2f

+ 1 - 1
app.js

@@ -14,7 +14,7 @@ App({
   globalData: {
     isRelease: true,
     is_debug: 2, // 1 测试环境 // 2正式环境
-    baseUrl: env.test.baseUrl,
+    baseUrl: env.prod.baseUrl,
 
     userInfo: null,
     classifyProducts: "",

+ 1 - 1
devices/ble_manager.js

@@ -164,7 +164,7 @@ class bleManager {
       }
     });
 
-    ///监听已连接或没有连接
+    ///监听已连接或没有连接 连接和断开的时候会回调
     // {"deviceId":"E4:9F:80:09:40:EC","connected":false}
     wx.onBLEConnectionStateChange((result) => {
       if (result.connected) {

文件差異過大導致無法顯示
+ 535 - 510
devices/bluetooth/bt_parse.js


+ 8 - 1
pages/index/index.js

@@ -216,6 +216,7 @@ Page({
     var deviceList = store.getStore("deviceList");
 
     if (!strings.isEmpty(deviceList)) {
+      // deviceList = deviceList.concat(deviceList);
       that.updateDeviceList(deviceList, true, false);
     }
 
@@ -238,7 +239,6 @@ Page({
         that.compareList();
       }, isFirst ? 6 * 1000 : 12 * 1000);
     }
-
   },
 
   /// 对比蓝牙数据
@@ -276,6 +276,13 @@ Page({
             deviceListSelect: null,
             indexPage: indexPage == 1 ? 0 : indexPage,
           });
+        }, function () {
+          var indexPage = that.data.indexPage;
+          that.setData({
+            actionIndex: null,
+            deviceListSelect: null,
+            indexPage: indexPage == 1 ? 0 : indexPage,
+          });
         });
         break;
 

+ 13 - 4
pages/index/index.wxml

@@ -9,7 +9,6 @@
 
       <!-- banner -->
       <view wx:if="{{bannerList.length>0}}" class="banner_container">
-
         <swiper class="swiper" indicator-dots="{{bannerList.length>1}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" circular="{{circular}}" indicator-active-color="#FFFFFF" indicator-color="#999999">
           <block wx:for="{{bannerList}}" wx:key="index">
             <swiper-item>
@@ -18,16 +17,26 @@
           </block>
         </swiper>
       </view>
+      <!-- banner -->
+      <!-- <view wx:if="{{bannerList.length>0}}" class="banner_container" style="width: calc(100vw - 64rpx);   border-radius: 16rpx;">
+        <swiper style="width: calc(100vw - 64rpx);   border-radius: 16rpx;" indicator-dots="{{bannerList.length>1}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" circular="{{circular}}" indicator-active-color="#FFFFFF" indicator-color="#999999">
+          <block wx:for="{{bannerList}}" wx:key="index">
+            <swiper-item style="width: calc(100vw - 64rpx); border-radius: 16rpx;">
+              <image class="banner_item" style="width: calc(100vw - 64rpx); border-radius: 16px;" src="{{item.pic}}" mode="aspectFill" bindtap="onTapBanner" data-item="{{item}}" lazy-load="true"></image>
+            </swiper-item>
+          </block>
+        </swiper>
+      </view> -->
 
       <view class="add_device_public" bind:tap="jumpToAddDevice">
         <image mode="heightFix" src="./../../img/add_device.png" style="width: 48rpx;height: 48rpx;"></image>
         <view style="color: white; margin-left: 8rpx; font-size: 32rpx;">添加设备</view>
       </view>
 
-      <scroll-view scroll-y="true" style="height: calc(100vh - 152rpx - 296rpx - 46rpx - 105rpx - {{safeBottomHeight}}rpx - 5rpx - {{navBarHeight}}px); padding-top: 10rpx; padding-bottom: 10rpx;">
+      <scroll-view scroll-y="true" style="height: calc(100vh - 152rpx - 296rpx - 46rpx - 105rpx - {{safeBottomHeight}}rpx - 5rpx - {{navBarHeight}}px);">
         <block wx:key="key" wx:for-item="item" wx:for-index="index" wx:for="{{deviceList}}">
 
-          <view class="item_public" style="border: {{item.state && item.state === 'online'&&deviceListSelect === index  ? '6rpx solid #6546A3' : item.state && item.state === 'online'?'2rpx solid #6546A3':'2rpx solid #F2F5F7'}};  flex-direction: row; display: flex;" data-item="{{item}}" data-index="{{index}}" bind:tap="onTapItem">
+          <view class="item_public" style="border: {{item.state && item.state === 'online'&&deviceListSelect === index  ? '6rpx solid #6546A3' : item.state && item.state === 'online'?'2rpx solid #6546A3':'2rpx solid #F2F5F7'}};  flex-direction: row; display: flex; margin-top: 10rpx; margin-bottom: {{index==0?deviceList.length-1:0}}rpx; " data-item="{{item}}" data-index="{{index}}" bind:tap="onTapItem">
 
             <view style="width: 264rpx; height: 200rpx;">
               <image class="item_public_image" src="{{item.imageUrl}}" style="opacity: {{item.state && item.state === 'online' ? '1' : '0.5'}};" mode="aspectFit" lazy-load="true" webp="true"></image>
@@ -73,7 +82,7 @@
         <view class="play-info">
           <view class="info">
             <image src="./../../img/blak.png" class="black" mode="scaleToFill"></image>
-            <image src="./../../img/mm.png" class="mode" mode="scaleToFill"></image>
+            <image src="./../../img/mm.png" class="mode" mode="widthFix"></image>
             <image class="logo" mode="heightFix" src="./../../img/logo.png"></image>
             <view wx:if="{{actionIndex !== null}}" style="opacity: 0.8; text-shadow:0px 0px 4px #6D00FF;" class="fm">
               FM.{{actionIndex !== null ? (actionIndex + 1 < 10 ? "0" + (actionIndex + 1) : actionIndex + 1) : 00}} </view>

+ 16 - 8
pages/index/index.wxss

@@ -107,7 +107,7 @@
   top: 0;
   left: 0;
   width: 96rpx;
-  height: 152rpx;
+  height: 148rpx;
   z-index: 999;
 }
 
@@ -169,6 +169,7 @@
 }
 
 .mair .play-info .info .fm .gochnnalList {
+  width: 50rpx;
   height: 50rpx;
   position: absolute;
   top: 8rpx;
@@ -506,6 +507,7 @@
 
 .wake {
   height: 48rpx;
+  width: 48rpx;
   z-index: 1000;
 }
 
@@ -683,11 +685,6 @@
   right: 0rpx;
 }
 
-.me .list .li .button image.logo {
-  height: 34rpx;
-  margin-left: 12rpx;
-}
-
 .login {
   position: fixed;
   bottom: 184rpx;
@@ -730,6 +727,7 @@
 }
 
 /************************ banner ************************/
+
 .banner_container {
   width: 100%;
   height: 264rpx;
@@ -750,6 +748,17 @@
   display: block;
 }
 
+/* .banner_container {
+  margin-top: 24rpx;
+  height: 270rpx;
+  background-color: transparent;
+}
+
+.banner_item {
+  height: 270rpx;
+  background-color: transparent;
+} */
+
 /* 设置指示点的大小和颜色 */
 .swiper_dot {
   width: 10px;
@@ -776,12 +785,11 @@
   /* 当前选中指示点的高度(可以比未选中时稍大) */
 }
 
-
 .add_device_public {
   background-color: #6546A3;
   width: 80vw;
   height: 88rpx;
-  margin-top: 64rpx;
+  margin-top: 32rpx;
   margin-left: 5%;
   border-radius: 72rpx;
   display: flex;

+ 1 - 1
pages/login/login.wxml

@@ -6,7 +6,7 @@
     <image mode="widthFix" src="./../../img/k.png"></image>
     <view class="loginbut">
       <view class="mode" wx:if="{{!isAgree}}" catchtap="notlogin"></view>
-      <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">微信手机号快速登录</button>
+      <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">手机号快速登录</button>
     </view>
     <view class="ys">
       <image bindtap="egree" mode="aspectFill" src="./../../img/{{isAgree ? 'h' : 'j'}}.png"></image>

+ 0 - 86
pages/meCopy/meCopy.js

@@ -1,86 +0,0 @@
-// pages/me/me.ts
-const app = getApp();
-
-Page({
-
-  /**
-   * 页面的初始数据
-   */
-  data: {
-    loginStatus: true,
-    userName: "未登录",
-    userPic: './../../img/head_pic.png',
-    nvabarData: {
-      showCapsule: 0, //是否显示左上角图标   1表示显示    0表示不显示
-      title: '', //导航栏 中间的标题
-    },
-    islogin: false,
-  },
-
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad() {
-    // wx.getStorage("userInfo")
-    const _this = this;
-    wx.getStorage({
-      key: "userInfo",
-      success(res) {
-        if (!res.data.phone) {
-          return;
-        };
-        _this.setData({
-          userName: res.data.nickname || "",
-          userPic: res.data.headUrl || "",
-          islogin: true,
-        })
-      }
-    })
-  },
-  goabout() {
-    wx.navigateTo({
-      url: './../about/about',
-    })
-  },
-  gologin() {
-    // 
-    const _this = this;
-    if (this.data.islogin) {
-      // 退出登录
-      wx.removeStorage({
-        key: 'userInfo',
-        success(res) {
-          _this.setData({
-            islogin: false,
-            userName: "未登录",
-            userPic: "./../../img/head_pic.png",
-          });
-          wx.redirectTo({
-            url: '/pages/index/index'
-          });
-        }
-      });
-      wx.removeStorage({
-        key: 'token',
-      })
-    } else {
-      // 登录
-      wx.navigateTo({
-        url: './../login/login',
-      });
-    }
-  },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow() {
-    this.onLoad();
-  },
-
-  goDownload() {
-    wx.navigateTo({
-      url: './../download/download',
-    })
-  }
-})

+ 0 - 5
pages/meCopy/meCopy.json

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

+ 0 - 44
pages/meCopy/meCopy.wxml

@@ -1,44 +0,0 @@
-<!--pages/me/me.wxml-->
-<view class="me">
-  <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>
-  <view class="head-logo">
-    <image mode="scaleToFill" src="{{userPic}}"></image>
-    <text class="userName" wx:if="{{userName}}">{{userName}}</text>
-    <!-- <text class="goLogin" wx:else>未登录</text> -->
-  </view>
-  <view class="br"></view>
-  <view class="list">
-    <view class="li">
-      <view class="icon">
-        <image mode="widthFix" src="./../../img/o.png"></image>
-      </view>
-      <view class="button">
-        <button open-type="feedback">建议与反馈</button>
-        <image class="j" mode="heightFix" src="./../../img/b.png"></image>
-      </view>
-    </view>
-    <view class="li">
-      <view class="icon">
-        <image mode="widthFix" src="./../../img/q.png"></image>
-      </view>
-      <view class="button" bindtap="goabout">
-        <text>关于我们</text>
-        <image class="j" mode="heightFix" src="./../../img/b.png"></image>
-      </view>
-    </view>
-    <!-- <view class="li">
-      <view class="icon">
-        <image mode="widthFix" src="./../../img/p.png"></image>
-      </view>
-      <view class="button" bindtap="goDownload">
-        <text>下载</text>
-        <image class="logo" mode="heightFix" src="./../../img/r.png"></image>
-        <image class="j" mode="heightFix" src="./../../img/b.png"></image>
-      </view>
-    </view> -->
-  </view>
-  <view wx:if="{{islogin}}" class="login">
-    <view bindtap="gologin" class="{{!islogin ? 'action' : ''}}">{{islogin ? '退出登录' : "登录"}}</view>
-  </view>
-</view>

+ 0 - 108
pages/meCopy/meCopy.wxss

@@ -1,108 +0,0 @@
-/* pages/me/me.wxss */
-.me .head-logo {
-  padding: 38rpx 0 28rpx;
-  display: flex;
-  flex-direction: column;
-  justify-content: center;
-  align-items: center;
-}
-
-.me .head-logo image {
-  width: 240rpx;
-  height: 240rpx;
-  border-radius: 50%;
-  border: 10rpx solid rgba(101, 71, 163, 0.2);
-  margin-bottom: 28rpx;
-}
-
-.me .head-logo text {
-  font-size: 36rpx;
-  font-weight: bold;
-}
-
-.me .head-logo .goLogin {
-  color: #999;
-}
-
-.me .head-logo .userName {
-  color: #353535;
-}
-
-.me .br {
-  height: 20rpx;
-  background: #999999;
-  opacity: 0.05;
-}
-
-.me .list {
-  padding: 0 30rpx;
-}
-
-.me .list .li {
-  height: 102rpx;
-  display: flex;
-}
-
-.me .list .li .icon {
-  height: 102rpx;
-  display: flex;
-  align-items: center;
-  margin-right: 20rpx;
-}
-
-.me .list .li image {
-  width: 40rpx;
-}
-
-.me .list .li .button {
-  width: calc(100% - 60rpx);
-  border-bottom: 1rpx solid #E0DCD7;
-  position: relative;
-  display: flex;
-  align-items: center;
-}
-
-.me .list .li .button button, .me .list .li .button text {
-  margin: 0;
-  background: none;
-  text-align: left;
-  padding: 0;
-  line-height: 102rpx;
-  font-size: 30rpx;
-  color: #353535;
-  font-weight: 400;
-}
-
-.me .list .li .button image.j {
-  height: 22rpx;
-  position: absolute;
-  top: 40rpx;
-  right: 0rpx;
-}
-
-.me .list .li .button image.logo {
-  height: 34rpx;
-  margin-left: 12rpx;
-}
-.login{
-  position: fixed;
-  bottom: 54rpx;
-  width: 100vw;
-  display: flex;
-  justify-content: center;
-}
-.login>view{
-  display: flex;
-  justify-content: center;
-  align-items: center;
-  width: 520rpx;
-  height: 80rpx;
-  background: #999999;
-  border-radius: 45rpx;
-  font-size: 36rpx;
-  font-weight: 400;
-  color: #FFFFFF;
-}
-.login>view.action{
-  background: #6547A3;
-}

+ 501 - 0
utils/blue_ble/manager.js

@@ -0,0 +1,501 @@
+module.exports = Manager;
+
+class Manager {
+  constructor() {
+    var that = this;
+    ///正在连接中的设备
+    that.connectWillDevice = null;
+    ///正在连接的设备,成功后返回的数据
+    that.callBackConnect = null;
+    ///搜索过快会失败,给的一定的缓冲时间
+    that.requestBlueTime = 0;
+    ///蓝牙是否已打开,是否可用
+    that.isAvailable = false;
+    ///蓝牙正在搜索中,则不允许继续搜索
+    that.doStartScaning = false;
+    ///蓝牙设备搜索的所有在线设备,用来和现有设备比较
+    that.compareList = [];
+    ///离线的所有设备,也可以用来比较
+    that.dissmissDevice = [];
+
+    ///当前蓝牙ble连接设备的相关属性
+    that.writeCharaterId = "";
+    that.writeServiceId = "";
+    that.readCharaterId = "";
+    that.readServiceId = "";
+  }
+
+  ///获取比较的数据
+  getCompareList() {
+    var that = this;
+    return that.compareList;
+  }
+
+  setCompareList(compareList) {
+    var that = this;
+    that.compareList = compareList;
+  }
+
+  getDissmissDevice() {
+    var that = this;
+    return that.dissmissDevice;
+  }
+
+  setConnectWillDevice(connectWillDevice) {
+    var that = this;
+    that.connectWillDevice = connectWillDevice;
+  }
+
+  getCallBackConnect() {
+    var that = this;
+    return that.callBackConnect;
+  }
+
+  setCallBackConnect(callBackConnect) {
+    this.callBackConnect = callBackConnect;
+  }
+
+  /// 监控蓝牙打开状态
+  initBlueAdapter() {
+    var that = this;
+    wx.onBluetoothAdapterStateChange(function (res) {
+      that.isAvailable = res.available;
+      if (!that.isAvailable) {
+        that.compareList = [];
+        that.dissmissDevice = [];
+        getCurrentPages()[0].closeBlueResetOffline(false, true);
+      }
+    })
+  }
+
+  ///监听搜索设备列表
+  listenBlueDevices() {
+    var that = this;
+    const hex_util = require('./../../utils/hex_util');
+    wx.onBluetoothDeviceFound(function (res) {
+      ///第一种情况
+      if (res.deviceId) {
+        if (that.callBackConnect != null) {
+          if (that.connectWillDevice != null && res.name == that.connectWillDevice.clientType) {
+            res.mac = res.advertisData ? hex_util.buf2hex(res.advertisData) : '';
+            if (that.callBackConnect != null) {
+              that.callBackConnect(res);
+            }
+          }
+        } else {
+          if (res.name != "") {
+            if (that.compareList.length > 0) {
+              var has = false;
+              for (var i = 0; i < that.compareList.length; i++) {
+                if (res.deviceId == that.compareList[i].deviceId) {
+                  has = true;
+                  break;
+                }
+              }
+              if (!has) {
+                that.compareList.push(res);
+              }
+            } else {
+              that.compareList.push(res);
+            }
+          }
+        }
+      }
+      ///第二种情况
+      else if (res.devices) {
+        if (that.callBackConnect != null) {
+          for (var i = 0; i < res.devices.length; i++) {
+            var temp = res.devices[i];
+            if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
+              temp.mac = temp.advertisData ? hex_util.buf2hex(temp.advertisData) : '';
+              temp.mac2 = that.ab2hex(temp.advertisData ?? "")
+              if (that.callBackConnect != null) {
+                that.callBackConnect(temp);
+              }
+              break;
+            }
+          }
+        } else {
+          for (var i = 0; i < res.devices.length; i++) {
+            if (that.compareList.length > 0) {
+              var has = false;
+              for (var j = 0; j < that.compareList.length; j++) {
+                if (res.devices[i].name != "") {
+                  if (res.devices[i].deviceId == that.compareList[j].deviceId) {
+                    has = true;
+                    break;
+                  }
+                }
+              }
+              if (!has) {
+                that.compareList.push(res.devices[i]);
+              }
+            } else {
+              that.compareList.push(res.devices[i]);
+            }
+          }
+        }
+      }
+      ///第三种情况
+      else if (res[0]) {
+        if (that.callBackConnect != null) {
+          if (that.connectWillDevice != null && res[0].name == that.connectWillDevice.clientType) {
+            res[0].mac = res[0].advertisData ? hex_util.buf2hex(res[0].advertisData) : '';
+            if (that.callBackConnect != null) {
+              that.callBackConnect(res[0]);
+            }
+          }
+        } else {
+          if (res[0].name != "") {
+            if (that.compareList.length > 0) {
+              var has = false;
+              for (var i = 0; i < that.compareList.length; i++) {
+                if (res[0].deviceId == that.compareList[i].deviceId) {
+                  has = true;
+                  break;
+                }
+              }
+              if (!has) {
+                that.compareList.push(res[0]);
+              }
+            } else {
+              that.compareList.push(res[0]);
+            }
+          }
+        }
+      }
+    });
+
+    ///监听  离线和连接成功设备导入
+    // {"deviceId":"E4:9F:80:09:40:EC","connected":false}
+    wx.onBLEConnectionStateChange((result) => {
+      if (result.connected) {
+        for (var i = 0; i < that.dissmissDevice.length; i++) {
+          if (result.deviceId == that.dissmissDevice[i].deviceId) {
+            that.dissmissDevice.splice(i, 1);
+            break;
+          }
+        }
+      } else {
+        var has = false;
+        for (var i = 0; i < that.dissmissDevice.length; i++) {
+          if (result.deviceId == that.dissmissDevice[i].deviceId) {
+            has = true;
+            break;
+          }
+        }
+        if (!has) {
+          that.dissmissDevice.push(result);
+        }
+      }
+    });
+  }
+
+  // 开始搜索蓝牙设备
+  async startScan(connectWillDevice, boolean, callBackConnect) {
+    var that = this;
+    ///限制搜索没有打开蓝牙一直询问打开蓝牙
+    var isAvailable = that.isAvailable;
+    if (!isAvailable && callBackConnect == null) {
+      return;
+    }
+
+    const route_util = require('../utils/route_util');
+    const route_constant = require('../utils/route_constant');
+    const indexRoot = route_constant.indexRoot;
+    const connectBleRoot = route_constant.connectBleRoot;
+    var lastPageRoute = route_util.getLastPageRoute();
+    if (lastPageRoute != indexRoot && lastPageRoute != connectBleRoot) {
+      return;
+    }
+
+    ///蓝牙连接 做限制
+    if (lastPageRoute == indexRoot) {
+      if (that.doStartScaning == true) {
+        return;
+      }
+    }
+
+    const time_util = require('./../../utils/time_util');
+    that.doStartScaning = true;
+    var currentMill = time_util.getCurrentMills();
+    var waitMills = 0;
+    var reduce = currentMill - that.requestBlueTime;
+    const delayMills = 6 * 1000;
+    if (reduce > 0 && reduce < delayMills) {
+      waitMills = delayMills - reduce;
+    }
+
+    if (waitMills > 0) {
+      await time_util.delayMills(waitMills);
+    }
+
+    if (callBackConnect == null && lastPageRoute == connectBleRoot) {
+      that.doStartScaning = false;
+      return;
+    }
+
+    wx.openBluetoothAdapter({
+      success: function (res) {
+        wx.stopBluetoothDevicesDiscovery({
+          success: (res) => {
+            that.search(connectWillDevice, boolean, callBackConnect);
+          },
+          fail: (err) => {
+            that.doStartScaning = false;
+            that.requestBlueTime = time_util.getCurrentMills();
+            if (boolean != null) {
+              boolean(false);
+            }
+          }
+        });
+      },
+      fail: function (res) {
+        that.doStartScaning = false;
+        that.requestBlueTime = time_util.getCurrentMills();
+        if (boolean != null) {
+          boolean(false);
+        }
+      }
+    });
+  }
+
+  ///搜索设备
+  search(connectWillDevice, boolean, callBackConnect) {
+    var that = this;
+    const time_util = require('./../../utils/time_util');
+    wx.startBluetoothDevicesDiscovery({
+      allowDuplicatesKey: true,
+      success: function (res) {
+        // that.getConnectedDevices();
+        that.doStartScaning = false;
+        that.requestBlueTime = time_util.getCurrentMills();
+        if (boolean != null) {
+          boolean(true);
+        }
+        that.setConnectWillDevice(connectWillDevice);
+        that.setCallBackConnect(callBackConnect);
+        that.compareList = [];
+      },
+      fail(err) {
+        that.doStartScaning = false;
+        that.requestBlueTime = time_util.getCurrentMills();
+        if (boolean != null) {
+          boolean(false);
+        }
+      },
+    });
+  }
+
+  // 停止搜索
+  stopScan() {
+    var that = this;
+    that.setCallBackConnect(null);
+    that.setConnectWillDevice(null);
+    return new Promise((resolve, reject) => {
+      wx.stopBluetoothDevicesDiscovery({
+        success: (res) => {
+          resolve(res);
+        },
+        fail: (err) => {
+          reject('停止搜索失败');
+        }
+      });
+    });
+  }
+
+  ///开始连接设备
+  startConnect(device) {
+    return new Promise((resolve, reject) => {
+      var deviceId = device.deviceId;
+      wx.createBLEConnection({
+        deviceId: deviceId,
+        success: function (res) {
+          resolve(true);
+        },
+        fail: function (res) {
+          resolve(false);
+        }
+      });
+    });
+  }
+
+  ///初始化 接收数据 获取特征值
+  getNotifyServices(device) {
+    return new Promise((resolve, reject) => {
+      var deviceId = device.deviceId;
+      wx.getBLEDeviceServices({
+        deviceId: deviceId,
+        success: function (res) {
+          resolve(res.services);
+        },
+        fail: function (res) {
+          resolve(null);
+        }
+      });
+    });
+  }
+
+  ///获取设备真正的属性特征值
+  getCharacteristics(device, services, index, notify, write, read, succeed, fail) {
+    var that = this;
+    var deviceId = device.deviceId;
+    wx.getBLEDeviceCharacteristics({
+      deviceId: deviceId,
+      serviceId: services[index].uuid,
+      success: function (res) {
+        var notifyCharaterId = "";
+        var notifyServiceId = "";
+        for (var i = 0; i < res.characteristics.length; i++) {
+          var properties = res.characteristics[i].properties;
+          var charaterId = res.characteristics[i].uuid;
+
+          if (!notify) {
+            if (properties.notify) {
+              notifyCharaterId = charaterId;
+              notifyServiceId = services[index].uuid;
+              notify = true;
+            }
+          }
+          if (!write) {
+            if (properties.write) {
+              that.writeCharaterId = charaterId;
+              that.writeServiceId = services[index].uuid;
+              write = true;
+            }
+          }
+
+          if (!read) {
+            if (properties.read) {
+              that.readCharaterId = charaterId;
+              that.readServiceId = services[index].uuid;
+              read = true;
+            }
+          }
+        }
+
+        if (!notify) {
+          index++
+          if (index == services.length) {
+            fail();
+          } else {
+            that.getCharacteristics(device, services, index, notify, write, read, succeed, fail);
+          }
+        } else {
+          succeed(notifyServiceId, notifyCharaterId);
+        }
+      }
+    })
+  }
+
+  // 监听发送的数据
+  monitorCharacteristicValueChange(device, notifyServiceId, notifyCharaterId) {
+    return new Promise((resolve, reject) => {
+      var deviceId = device.deviceId;
+      wx.notifyBLECharacteristicValueChange({
+        state: true,
+        deviceId: deviceId,
+        serviceId: notifyServiceId,
+        characteristicId: notifyCharaterId,
+        success: function (res) {
+          resolve(true);
+        },
+        fail: function (res) {
+          resolve(false);
+        }
+      });
+    });
+  }
+
+  ///收取到的数据转换为文字
+  onBLECharacteristicValueChange(callback) {
+    wx.onBLECharacteristicValueChange(function (r) {
+      callback(r.value);
+    });
+  }
+
+  // 断开设备的连接
+  disconnect(device) {
+    return new Promise((resolve, reject) => {
+      var deviceId = device.deviceId;
+      wx.closeBLEConnection({
+        deviceId: deviceId,
+        success: (res) => {
+          resolve(true);
+        },
+        fail: (err) => {
+          resolve(false);
+        }
+      });
+    });
+  }
+
+  ///发送数据
+  sendData(device, text) {
+    return new Promise((resolve, reject) => {
+      var that = this;
+      var deviceId = device.deviceId;
+      var buffer = new ArrayBuffer(text.length)
+      var dataView = new Uint8Array(buffer)
+      for (var i = 0; i < text.length; i++) {
+        dataView[i] = text.charCodeAt(i)
+      }
+      wx.writeBLECharacteristicValue({
+        deviceId: deviceId,
+        serviceId: that.writeServiceId,
+        characteristicId: that.writeCharaterId,
+        value: buffer,
+        success: function (res) {
+          resolve(true);
+        },
+        fail(err) {
+          resolve(false);
+        }
+      });
+    });
+  }
+}
+
+///获取 所有搜索过的蓝牙设备
+// getConnectedDevices() {
+//   var that = this;
+//   const hex_util = require('./../../utils/hex_util');
+//   wx.getBluetoothDevices({
+//     success: (res) => {
+//       if (that.callBackConnect != null) {
+//         for (var i = 0; i < res.devices.length; i++) {
+//           var temp = res.devices[i];
+//           if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
+//             temp.mac = temp.advertisData ? hex_util.buf2hex(temp.advertisData) : '';
+//             if (that.callBackConnect != null) {
+//               that.callBackConnect(temp);
+//             }
+//             break;
+//           }
+//         }
+//       } else {
+//         for (var i = 0; i < res.devices.length; i++) {
+//           if (that.compareList.length > 0) {
+//             var has = false;
+//             for (var j = 0; j < that.compareList.length; j++) {
+//               if (res.devices[i].name != "") {
+//                 if (res.devices[i].deviceId == that.compareList[j].deviceId) {
+//                   has = true;
+//                   break;
+//                 }
+//               }
+//             }
+//             if (!has) {
+//               that.compareList.push(res.devices[i]);
+//             }
+//           } else {
+//             that.compareList.push(res.devices[i]);
+//           }
+//         }
+//       }
+//     },
+//     fail: (err) => {
+//       console.error('获取蓝牙设备列表失败', err);
+//     }
+//   });
+// }

+ 137 - 0
utils/blue_ble/util.js

@@ -0,0 +1,137 @@
+const manager = require('./manager');
+module.exports = {
+  BleUtil
+}
+
+class BleUtil {
+  static _instance = new BleUtil();
+  static getInstance() {
+    return BleUtil._instance;
+  }
+
+  constructor() {
+    var that = this;
+    that.manager = new manager();
+  }
+
+  ///获取比较的数据
+  getCompareList() {
+    var that = this;
+    return that.manager.getCompareList();
+  }
+
+  getDissmissDevice() {
+    var that = this;
+    return that.manager.getDissmissDevice();
+  }
+
+  getCallBackConnect() {
+    var that = this;
+    return that.manager.getCallBackConnect();
+  }
+
+  ///初始化蓝牙适配器
+  initBluetoothAdapter() {
+    var that = this;
+    that.manager.initBlueAdapter();
+  }
+
+  ///获取蓝牙设备 connect:true,去连接,false,去对比
+  listenBlueDevices() {
+    var that = this;
+    that.manager.listenBlueDevices();
+  }
+
+  ///搜索蓝牙设备
+  startScan(connectWillDevice, boolean, callBackConnect) {
+    var that = this;
+    that.manager.startScan(
+      connectWillDevice,
+      boolean,
+      callBackConnect,
+    );
+  }
+
+  ///停止搜索蓝牙设备
+  async stopScan() {
+    var that = this;
+    await that.manager.stopScan();
+  }
+
+  ///开始连接设备
+  async startConnect(device, onChanged) {
+    var that = this;
+    await that.stopScan();
+    await that.disconnect(device);
+
+    var res = await that.manager.startConnect(device);
+    if (!res) {
+      onChanged(false, device);
+      return;
+    }
+
+    const strings = require('./../../utils/strings');
+    var services = await that.manager.getNotifyServices(device);
+    if (strings.isEmpty(services)) {
+      onChanged(false);
+      return;
+    }
+
+    that.manager.getCharacteristics(device, services, 0, false, false, false,
+      async function (notifyServiceId, notifyCharaterId) {
+          var isTrue = that.manager.monitorCharacteristicValueChange(device, notifyServiceId, notifyCharaterId);
+          if (!isTrue) {
+            onChanged(false);
+            return;
+          }
+
+          ///解决连接之后会有一段时间显示离线,先添加进去就不会了
+          var has = false;
+          var compareList = that.bleManager.getCompareList();
+          for (var j = 0; j < compareList.length; j++) {
+            if (compareList[j].deviceId == device.deviceId) {
+              has = true;
+              break;
+            }
+          }
+          if (!has) {
+            compareList.unshift(device);
+            that.manager.setCompareList(compareList);
+          }
+          onChanged(true);
+
+          const hex_util = require('./../../utils/hex_util');
+          const bt_parse = require('./../../devices/bluetooth/bt_parse');
+          that.manager.onBLECharacteristicValueChange(function (value) {
+            var receiveText = hex_util.buf2string(value);
+            console.log('接收到数据文字:' + receiveText);
+
+            var buffer = new DataView(value);
+            var result = []
+            for (let i = 0; i < buffer.byteLength; i++) {
+              result.push(buffer.getUint8(i))
+            }
+            bt_parse.parseTLV(result);
+          });
+        },
+        function () {
+          onChanged(false);
+          return;
+        });
+  }
+
+  ///发送数据
+  async sendData(device, text) {
+    var isTrue = await that.manager.sendData(device, text);
+    ///发送数据成功
+    if (isTrue) {
+
+    }
+  }
+
+  ///断开设备连接
+  async disconnect(device) {
+    var that = this;
+    await that.manager.disconnect(device);
+  }
+}

+ 57 - 0
utils/hex_util.js

@@ -0,0 +1,57 @@
+module.exports = {
+  buf2hex: buf2hex,
+  buf2string: buf2string,
+  changeArrayByValue: changeArrayByValue,
+  removeWrongArray: removeWrongArray,
+}
+
+///获取数据
+function buf2hex(buffer) {
+  return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
+}
+
+///数据转文字
+function buf2string(buffer) {
+  var arr = Array.prototype.map.call(new Uint8Array(buffer), x => x)
+  var str = ''
+  for (var i = 0; i < arr.length; i++) {
+    str += String.fromCharCode(arr[i])
+  }
+  return str
+}
+
+/// value 数组转换的根据值  array 需要转换的数组 
+/// 根据数组中的一个值分隔数组, 分割后组成的新数组
+function changeArrayByValue(value, array) {
+  // var value = "IMU data";
+  var newArray = new Array();
+  var dataStr = '';
+  for (var i = 0; i < array.length; i++) {
+    if (array[i] == value) {
+      if (dataStr) {
+        //把分隔的数据添加新到数组中
+        newArray.push(dataStr.substring(0, dataStr.length - 2).split("  "));
+      }
+      dataStr = '';
+      continue;
+    } else {
+      dataStr += (array[i] + "  ");
+      //把最后分隔的数据添加新到数组中
+      if (i == array.length - 1) {
+        newArray.push(dataStr.substring(0, dataStr.length - 2).split("  "));
+      }
+    }
+  }
+  return newArray;
+}
+
+///数组 去除数组中长度不等于三的属性
+function removeWrongArray(array) {
+  for (var i = 0; i < array.length; i++) {
+    if (array[i].length != 9) {
+      array.splice(i, 1);
+      removeWrongArray(array);
+    }
+  }
+  return array;
+}

+ 13 - 2
utils/lexin/connect.js

@@ -9,7 +9,7 @@ module.exports = {
 ///更新在线状态,连接第一个在线设备
 // deviceId: BLUFI_7cdfa1fd3af0
 // uuid: AIrSMArT_7cdfa1fd3af0
-function searchOnlineDevice(payloads, changeCallback, resetCallback) {
+function searchOnlineDevice(payloads, changeCallback, offlineConnectedCallback, resetCallback) {
   var isChanged = false;
   const strings = require('../strings');
   const lexin_util = require('../lexin/util');
@@ -17,6 +17,7 @@ function searchOnlineDevice(payloads, changeCallback, resetCallback) {
   var deviceList = pages[0].getDeviceList();
 
   /// 处理在线设备
+  var isOfflineCurrent = false;
   if (!strings.isEmpty(deviceList)) {
     for (var i = 0; i < deviceList.length; i++) {
       if (payloads && payloads.uuid) {
@@ -28,9 +29,16 @@ function searchOnlineDevice(payloads, changeCallback, resetCallback) {
           var index = payloads.uuid.indexOf(mac);
           if (index !== -1) {
             var connectDeviceIding = pages[0].getConnectDeviceIding();
-            if (connectDeviceIding != device.deviceId && device.state != payloads.state) {
+            if (connectDeviceIding != deviceId && device.state != payloads.state) {
               isChanged = true;
               device.state = payloads.state;
+              /// 离线的设备正好是当前设备
+              if (device.state == "offline") {
+                var currentConnnectDeviceId = pages[0].getCurrentDeviceId();
+                if (currentConnnectDeviceId == deviceId) {
+                  isOfflineCurrent = true;
+                }
+              }
             }
             break;
           }
@@ -42,6 +50,9 @@ function searchOnlineDevice(payloads, changeCallback, resetCallback) {
   if (isChanged) {
     changeCallback(deviceList);
   }
+  if (isOfflineCurrent) {
+    offlineConnectedCallback();
+  }
   _connectToDevice(resetCallback);
 };
 

+ 21 - 10
utils/lexin/message.js

@@ -107,17 +107,28 @@ function getDeviceInfo(payloads) {
 ///获取电量
 function getBattery(battery) {
   var b = 0;
+  ///0格 10
   if (battery < 20) {
-    _babttery = 0
-  } else if (20 <= battery && battery < 40) {
-    b = 1
-  } else if (40 <= battery && battery < 60) {
-    b = 2
-  } else if (60 <= battery && battery < 80) {
-    b = 3
-  } else if (80 <= battery && battery <= 100) {
-    b = 4
-  } else if (battery > 100) {
+    b = 0;
+  }
+  ///1格 20、30
+  else if (20 <= battery && battery < 40) {
+    b = 1;
+  }
+  ///2格 40、50
+  else if (40 <= battery && battery < 60) {
+    b = 2;
+  }
+  ///3格 60、70
+  else if (60 <= battery && battery < 80) {
+    b = 3;
+  }
+  ///满格 4格 80、90
+  else if (80 <= battery && battery <= 100) {
+    b = 4;
+  }
+  /// 充电中
+  else if (battery > 100) {
     b = 5
   };
   return b;

+ 17 - 1
utils/time_util.js

@@ -1,7 +1,23 @@
 module.exports = {
-  getGreet: getGreet
+  delayMills: delayMills,
+  getCurrentMills: getCurrentMills,
+  getGreet: getGreet,
 }
 
+// 等待毫秒数
+function delayMills(mills) {
+  return new Promise(resolve => setTimeout(resolve, mills));
+}
+
+///获取毫秒
+function getCurrentMills() {
+  var currentDate = new Date();
+  var currentTimeMillis = currentDate.getTime();
+  // return Math.floor(currentTimeMillis / 1000);
+  return currentTimeMillis;
+}
+
+///获取上午、下午、晚上
 function getGreet() {
   const now = new Date();
   const hour = now.getHours();

+ 1 - 1
utils/util.js

@@ -12,7 +12,7 @@ const urlencodeType = {
   "content-type": "application/x-www-form-urlencoded"
 }
 
-import strings from '../utils/strings.js';
+import strings from './strings.js';
 
 // 错误类型
 let statusCode = {