浏览代码

feature: 处理多个设备在线,关闭当前连接的设备,会假连接其他设备的问题

Damon 7 月之前
父节点
当前提交
9acb40412e
共有 7 个文件被更改,包括 15 次插入245 次删除
  1. 5 0
      pages/index/index.js
  2. 1 0
      pages/index/index.wxss
  3. 0 86
      pages/meCopy/meCopy.js
  4. 0 5
      pages/meCopy/meCopy.json
  5. 0 44
      pages/meCopy/meCopy.wxml
  6. 0 108
      pages/meCopy/meCopy.wxss
  7. 9 2
      utils/lexin/connect.js

+ 5 - 0
pages/index/index.js

@@ -269,6 +269,11 @@ Page({
       case "message_onoffline":
         lexin_connect.searchOnlineDevice(payloads, function (list) {
           that.updateDeviceList(list, false, false);
+        },function(){
+          that.setData({
+            deviceListSelect: null,
+            connectDeviceIding: "",
+          });
         }, function () {
           var indexPage = that.data.indexPage;
           that.setData({

+ 1 - 0
pages/index/index.wxss

@@ -506,6 +506,7 @@
 
 .wake {
   height: 48rpx;
+  width: 48rpx;
   z-index: 1000;
 }
 

+ 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;
-}

+ 9 - 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');
@@ -28,9 +28,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) {
+                  offlineConnectedCallback();
+                }
+              }
             }
             break;
           }