Explorar o código

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

Damon hai 1 ano
pai
achega
8b156551bd

+ 68 - 0
custom-tab-bar/tabbar.js

@@ -0,0 +1,68 @@
+const eventBus = {
+  // 存储所有事件和对应的订阅者
+  eventList: new Map(),
+  // 订阅事件
+  on(event, callback) {
+    if (!this.eventList.has(event)) {
+      this.eventList.set(event, new Set())
+    }
+    this.eventList.get(event).add(callback)
+  },
+  // 取消订阅事件
+  off(event, callback) {
+    if (this.eventList.has(event)) {
+      const callbacks = this.eventList.get(event)
+      callbacks.delete(callback)
+      if (callbacks.size === 0) {
+        this.eventList.delete(event)
+      }
+    }
+  },
+  // 发布事件
+  emit(event, ...args) {
+    if (this.eventList.has(event)) {
+      const callbacks = this.eventList.get(event)
+      callbacks.forEach((callback) => {
+        callback.call(null, ...args)
+      })
+    }
+  }
+}
+
+function selectIndex(index) {
+  var pages = getCurrentPages();
+  var curPage = pages[pages.length - 1]
+  if (typeof curPage.getTabBar === 'function' &&
+    curPage.getTabBar()) {
+    curPage.getTabBar().setData({
+      selected: index
+    })
+  }
+}
+
+function eventOn(curPage) {
+  getApp().eventBus.on('rightChange', data => {
+    // var pages = getCurrentPages();
+    // var curPage = pages[pages.length - 1]
+    if (data !== curPage.data.rightId) {
+      curPage.setData({
+        rightId: data
+      })
+      if (curPage.data.rightId === 2) {
+        let num = curPage.data.rightId === 1 ? 2 : 1
+        if (typeof curPage.getTabBar === 'function' &&
+          curPage.getTabBar()) {
+          curPage.getTabBar().setData({
+            selected: num
+          })
+        }
+      }
+    }
+  });
+}
+
+module.exports = {
+  eventBus,
+  selectIndex,
+  eventOn
+}

+ 141 - 85
pages/bluConnect/bleconnect.js

@@ -1,107 +1,163 @@
 // pages/bluConnect/bleconnect.js
 Page(
   {
-  /**
-   * 页面的初始数据
-   */
-  data: {
-    scopeBluetooth: false,
-    isScaning: false,
-    connectStatus: 0,
-    connectText: "连接中",
-    connectTips: "确保蓝牙已经打开",
-
-    
-    userFuzzyLocation: true,
-    nvabarData: {
-      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
-      title: '设备连接', //导航栏 中间的标题
-      callback() {
-        wx.navigateBack({
-          delta: 1,
-        })
+    /**
+     * 页面的初始数据
+     */
+    data: {
+      scopeBluetooth: false,
+      isScaning: false,
+      connectStatus: 0,
+      connectText: "连接中",
+      connectPic: "",
+      connectTips: "正在搜索设备,请保持开机状态...",
+      buttonTips: "正在搜索设备",
+
+      userFuzzyLocation: true,
+      nvabarData: {
+        showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
+        title: '设备连接', //导航栏 中间的标题
+        callback: () => {
+          wx.switchTab({
+            url: '../home/home',
+          })
+        }
+      },
+      isNotruter: false,
+      deviceItem: {
+        "pic": "../../img/g.png",
+        "address": "",
+        "name": "猫王钢琴音箱",
+        "devName": "名称1", "state": "online", "power": 40
       }
+    }, getBluetoothStatusCallck(v) {
+      this.setData({
+        scopeBluetooth: v
+      })
     },
-  },  getBluetoothStatusCallck(v) {
-    this.setData({
-      scopeBluetooth: v
-    })
-  },
-  setBluetooth(){
-    wx.openSetting({
-      complete () {
-        // app.getBluetoothStatus();
+    setBluetooth() {
+      wx.openSetting({
+        complete() {
+          // app.getBluetoothStatus();
+        }
+      })
+    }, connectDeviceTap() {
+var _this = this;
+      // var curPage = getCurrentPages();
+      // var homePage = curPage[curPage.length - 1];
+      var key = 'home_device_list'+wx.getUserInfo().userId;
+      var saveStr = wx.getStorageSync(key) ?? "[]";
+      console.log("返回数据: "+saveStr);
+
+      var oldList = JSON.parse(saveStr);
+
+      oldList.push(_this.deviceItem);
+      console.log("返回数据:2\n"+JSON.stringify(oldList));
+
+wx.setStorageSync(key, JSON.stringify(oldList));
+      // homePage.setData({deviceList:[_this.deviceItem]});
+wx.navigateBack();
+      if (!_this.isScaning) {
+        return;
       }
-    })
-  },
 
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad(options) {
+    }, scanDevice() {
+      this.isScaning = true;
+    },
 
-    if(options.isLognlink) {
-      this.setData({
-        isNotruter: true,
-        nvabarData: {
-          showCapsule: 1,
-          title: '设备连接',
-          callback: ()=> {
-            wx.switchTab({
-              url: '../home/home',
-            })
-          }
-        },
-      })
-    }
-  },
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad(options) {
+
+      if (options.isLognlink) {
+
+      }
+    
+      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;
+      }
+    },
 
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady() {
+    /**
+     * 生命周期函数--监听页面初次渲染完成
+     */
+    onReady() {
 
-  },
+    },
 
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow() {
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    onShow() {
 
-  },
+    },
 
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide() {
+    /**
+     * 生命周期函数--监听页面隐藏
+     */
+    onHide() {
 
-  },
+    },
 
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload() {
+    /**
+     * 生命周期函数--监听页面卸载
+     */
+    onUnload() {
 
-  },
+    },
 
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
+    /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh() {
 
-  },
+    },
 
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
+    /**
+     * 页面上拉触底事件的处理函数
+     */
+    onReachBottom() {
 
-  },
+    },
 
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
+    /**
+     * 用户点击右上角分享
+     */
+    onShareAppMessage() {
 
-  }
-})
+    }
+  })

+ 5 - 7
pages/bluConnect/bleconnect.wxml

@@ -2,17 +2,15 @@
 <view class="container">
   <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>
   <!-- <scroll-view class="scrollClass" scroll-y="true"> -->
-  <image class="device_pic_class" src="../../img/a.png" mode="scaleToFill" />
-  <view class="text_class">
-    <text class="scanDeviceClass">搜索钢琴音箱</text>
-    <view wx:if="{{isScaning}}">{{connectTips}}</view>
+  <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">
-      <image class="scan_device_status_img_class" src="../../img/a.png" mode="scaleToFill" />
+      <image class="scan_device_status_img_class" src="{{connectPic}}" mode="scaleToFill" />
       <text class="scan_device_status_text_class">{{connectText}}</text>
     </span>
-  </view>
   <view style="flex: 1;  "></view>
-<view style="justify-content: center;  display: flex;">  <button class="connect_btn_class">连接</button>
+<view bind:tap="connectDeviceTap" >  <button class="connect_btn_class">{{buttonTips}}</button>
 </view>
   <!-- </scroll-view> -->
 </view>

+ 20 - 13
pages/bluConnect/bleconnect.wxss

@@ -11,10 +11,9 @@
 
 .container .device_pic_class {
   height: 300rpx;
-  /* width: 300rpx; */
-  margin-top: 56rpx;
-  margin-left: 60rpx;
-  margin-right: 60rpx;
+  margin-top: 160rpx;
+  padding-left: 60rpx;
+  padding-right: 60rpx;
 
 }
 
@@ -26,10 +25,17 @@
 }
 
 .container .scanDeviceClass {
-  margin-top: 16rpx;
+  margin-top: 60rpx;
   margin-left: 16rpx;
   margin-right: 16rpx;
+text-align: center;
+}
 
+.container .connect_tips {
+  margin-top: 16rpx;
+  margin-left: 16rpx;
+  margin-right: 16rpx;
+text-align: center;
 }
 
 
@@ -39,26 +45,27 @@
   margin-left: 16rpx;
   margin-right: 16rpx;
   flex-direction: row;
+  text-align: center;
+
 }
 
 
-.container .scan_device_status_img_class {
-  margin-right: 16rpx;
+.container .scan_device_status_class > scan_device_status_img_class {
   width: 16rpx;
   height: 16rpx;
 }
 
-.container .scan_device_status_text_class {
+.container .scan_device_status_class > scan_device_status_text_class {
   margin-right: 16rpx;
   width: 16rpx;
   height: 16rpx;
 }
 
-
 .container .connect_btn_class {
-  margin-left: 56rpx;
-  margin-right: 56rpx;
-  margin-bottom: 56rpx;
+  padding-left: 56rpx;
+  padding-right: 56rpx;
+  padding-bottom: 56rpx;
   margin-top: 70rpx;
-
+  justify-content: center; 
+  display: flex;
 }

+ 107 - 29
pages/home/home.js

@@ -1,5 +1,7 @@
 // pages/home/home.js
 const app = getApp();
+const { login } = require('./../../utils/api.js');
+const { selectIndex, eventOn } = require('./../../custom-tab-bar/tabbar.js');
 
 Page({
 
@@ -10,7 +12,7 @@ Page({
     navBarHeight: app.globalData.navBarHeight,
     MenuButtonheight: app.globalData.MenuButtonheight,
     MenuButtonTop: app.globalData.MenuButtonTop,
-    rightId:wx.getStorageSync('rightId') || 0,
+    rightId: wx.getStorageSync('rightId') || 0,
     nvabarData: {
       nvabarData: {
         showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
@@ -22,11 +24,12 @@ Page({
         }
       },
       isNotruter: false,
-      deviceList: [],
-      bannerList: [],
-      isLoginWx: false,
-      selectIndex: -1,
-        }
+
+    },
+    deviceList: [],
+    bannerList: ["https://img1.baidu.com/it/u=2003442481,2528062378&fm=253&fmt=auto&app=138&f=JPG?w=499&h=182", "https://hbimg.huabanimg.com/0ff93215a6d8d1c5f80117fdbfa24936dbd9097026ad99-CNduY8_fw658", "https://img.zcool.cn/community/0177ed5f365bdaa801215aa0a0c1c3.jpg@1280w_1l_2o_100sh.jpg"],
+    selectIndex: 0,
+    isLoginWx: true,
   },
   changeRole() {
     app.changeUserRight()
@@ -47,11 +50,80 @@ Page({
   },
   changeDeviceTap: function () {
   },
+  login() {
+    var _this = this;
+    wx.login({
+      success: res => {
+        let phone = undefined;
+        try {
+          var value = wx.getStorageSync('userInfo')
+          if (value) {
+            phone = value.phone || undefined;
+          };
+        } catch (e) {
+          // Do something when catch error
+        };
+        // 请求登录
+        login({ code: res.code, phone }).then((res) => {
+
+          app.globalData.userInfo = res;
+          wx.setStorage({
+            key: "userInfo",
+            data: res
+          });
+          // 需要用授权登录
+          if ((res.isNewUser && res.isNewUser === true) || !phone) {
+            _this.setData({
+              isLoginWx: true,
+            });
+            return;
+          };
+          // 获取设备本地数据
+          this.getDeviceData();
+
+          _this.setData({
+            isLoginWx: false,
+          });
+          wx.setStorage({
+            key: "token",
+            data: JSON.stringify({
+              id: res.userId,
+              token: res.accessToken,
+            }),
+          });
+        });
+      },
+    })
+  },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
+    var _this = this;
+    eventOn(_this);
+    // 版本自动更新代码
+    const updateManager = wx.getUpdateManager();
+    updateManager.onUpdateReady(function () {
+      _this.setData({
+        newVersion: true
+      });
+    })
+    updateManager.onUpdateFailed(function () {
+      // 新的版本下载失败
+      wx.showModal({
+        title: '已有新版本咯',
+        content: '请您删除当前小程序,重新打开呦~',
+        showCancel: false
+      })
+    })
+
+    wx.showLoading({
+      title: '加载中',
+    });
+    // 登录
+    _this.login();
+
   },
 
   /**
@@ -64,33 +136,39 @@ Page({
   /**
    * 生命周期函数--监听页面显示
    */
-  onShow() {
-    if (typeof this.getTabBar === 'function' &&
-      this.getTabBar()) {
-      this.getTabBar().setData({
-        selected: 0
-      })
+  onShow(options) {
+    selectIndex( 0);
+
+    // if (typeof this.getTabBar === 'function' &&
+    //   this.getTabBar()) {
+    //   this.getTabBar().setData({
+    //     selected: 0
+    //   })
+    // }
+    // app.eventBus.on('rightChange', data => {
+    //   if (data !== this.data.rightId) {
+    //     this.setData({
+    //       rightId: data
+    //     })
+    //   }
+    // });
+
+    if (this.data.isLoginWx) {
+      var key = 'home_device_list' + wx.getUserInfo().userId;
+      var saveStr = wx.getStorageSync(key) ?? "[]";
+      var devList = JSON.parse(saveStr);
+
+      this.setData({
+        deviceList: devList
+      });
     }
-    app.eventBus.on('rightChange', data => {
-      if (data !== this.data.rightId) {
-        this.setData({
-          rightId: data
-        })
-      }
-    })
 
-    this.setData({
-      deviceList: [
-        { "devName": "名称1", "state": "online", "pic": "url", "power": 40, },
-        { "devName": "名称2", "state": "online", "pic": "url", "power": 50, },
-        { "devName": "名称3", "state": "online", "pic": "url", "power": 60, },
-      ],
-      selectIndex: 0,
-      isLoginWx: true,
-      bannerList: ["https://img1.baidu.com/it/u=2003442481,2528062378&fm=253&fmt=auto&app=138&f=JPG?w=499&h=182", "https://hbimg.huabanimg.com/0ff93215a6d8d1c5f80117fdbfa24936dbd9097026ad99-CNduY8_fw658", "https://img.zcool.cn/community/0177ed5f365bdaa801215aa0a0c1c3.jpg@1280w_1l_2o_100sh.jpg"],
+  },
+  addDeviceTap() {
+    wx.navigateTo({
+      url: './../bluConnect/bleconnect',
     });
   },
-
   /**
    * 生命周期函数--监听页面隐藏
    */

+ 14 - 13
pages/home/home.wxml

@@ -6,28 +6,29 @@
   <view class="helloC" style="margin-top: {{navBarHeight}};">下午好,昵称XXX</view>
   <swiper class="bannerC" indicator-dots="true" autoplay="3000">
     <swiper-item class="bannerItemC" wx:for="{{bannerList}}" wx:key="item">
-      <image src="{{item}}" mode="scaleToFill"/>
+      <image src="{{item}}" mode="widthFix" style="flex: 1;" />
     </swiper-item>
   </swiper>
+  <view class="device_empty_tips" bind:tap="addDeviceTap" >
+      + 添加设备
+    </view>
   <scroll-view class="deviceScrollClass" scroll-y="true">
     <view class="deviceClass" wx:for="{{deviceList}}" wx:key="item" >
-          <image class="deviceImg" src="../../img/g.png" mode="scaleToFill" />
+          <image class="device_img" src="{{item.pic}}" mode="scaleToFill" />
           <view class="detailClass" style="flex-direction: row;">
-            <view class="powerClass">
-              <image class="powerImg" src="../../img/dl1.png" mode="scaleToFill" />
-              <view class="powerText">{{item.power}}</view>
+            <view class="power">
+              <image class="power_img" src="../../img/dl1.png" mode="scaleToFill" />
+              <text class="power_text">{{item.power}}</text>
             </view>
-            <view class="deviceName">{{item.devName}}</view>
-            <view class="deviceDeleteClass" bind:tap="deleteDeviceTap">删除</view>
-
+            <view class="device_name">{{item.devName}}</view>
+            <!-- <view class="device_delete" bind:tap="deleteDeviceTap">删除</view> -->
+<button class="device_delete" bind:tap="deleteDeviceTap">删除</button>
           </view>
 
-          <image class="detailPageC" src="../../img/a6.png" mode="scaleToFill" bind:tap="devieDetailPageTap" />
+          <image class="detail_page" src="../../img/a6.png" mode="scaleToFill" bind:tap="devieDetailPageTap" />
         </view>
-    <view class="deviceEmptyClass" wx:if="{{deviceList && deviceList.deviceList.length == 0 || !isLoginWx}}">
-      + 添加设备
-    </view>
-    <button type="primary" bindtap="changeRole">example-改变权限</button>
+
+    <button style="margin-bottom: 160rpx;" type="primary" bindtap="changeRole">example-改变权限</button>
 
   </scroll-view>
 </view>

+ 30 - 18
pages/home/home.wxss

@@ -20,29 +20,31 @@
 
 .bannerItemC {
   width: 100%;
+  height: 160rpx;
+  display: flex;
+}
+
+.device_empty_tips {
+  display: flex;
+  flex: 1;
+  justify-content: center;
 }
 
 .deviceScrollClass {
   margin-top: 16rpx;
-  margin-bottom: 16rpx;
+  /* margin-bottom: 16rpx; */
+  padding-bottom: 16rpx;
 }
 
  .deviceClass {
   flex: 1;
   width: 100%;
   display: inline-flex;
+  margin-bottom: 16rpx;
+margin-top: 16rpx;
 } 
 
-.deviceItemC {
-  width: 100%;
-  height: 160rpx;
-  background-color: skyblue;
-/* margin-bottom: 16rpx;
-margin-top: 16rpx; */
-
-}
-
-.deviceImg {
+.device_img {
   width: 120rpx;
   height: 120rpx;
 margin-top: 16rpx;
@@ -57,25 +59,35 @@ margin-left: 16rpx;
   flex: 1;
 }
 
-.powerClass {
+.power {
   /* width: 100rpx; */
   display: flex;
 }
 
-.powerImg {
+.power_img {
+  width: 56rpx;
+  height: 56rpx;
+}
+
+.power_text {
   width: 56rpx;
   height: 56rpx;
 }
 
-.deviceName {
+
+.devicename {
   margin-top: 4rpx;
 }
 
-.deviceDeleteClass {
-  margin-bottom: 16rpx;
+.device_delete {
+  display: inline;
+  padding-left: 16rpx;
+  padding-right: 16rpx;
+padding-top: 8rpx;
+padding-bottom: 8rpx;
 }
 
-.detailPageC {
+.detail_page {
 margin-top: 16rpx;
 /* margin-left: 116rpx; */
   margin-right: 16rpx;
@@ -83,7 +95,7 @@ margin-top: 16rpx;
   height: 16rpx;
 }
 
-.deviceEmptyClass {
+.device-empty-tips {
   margin-top: 16rpx;
 
 }

+ 118 - 130
pages/index/index.js

@@ -1,8 +1,10 @@
 // index.ts
 // 获取应用实例
 const app = getApp();
-const { login, listByDevice }=require('./../../utils/api.js');
-const { isCN }=require('./../../utils/util.js');
+const { login, listByDevice } = require('./../../utils/api.js');
+const { isCN } = require('./../../utils/util.js');
+const { selectIndex,eventOn } = require('./../../custom-tab-bar/tabbar.js');
+
 let _this = null;
 const interval = null;
 Page({
@@ -12,7 +14,7 @@ Page({
     MenuButtonTop: app.globalData.MenuButtonTop,
     actionIndex: null,
     isShowDevicelist: false,
-    luoma: ["Ⅰ","Ⅱ","Ⅲ","Ⅳ","Ⅴ","Ⅵ"," Ⅶ","Ⅷ","Ⅸ","Ⅹ","Ⅺ","Ⅻ"],
+    luoma: ["Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", " Ⅶ", "Ⅷ", "Ⅸ", "Ⅹ", "Ⅺ", "Ⅻ"],
     channelData: [],
     deviceList: [],
     deviceListIndex: null,
@@ -24,29 +26,30 @@ Page({
     thisDeviceMac: null,
     battery: 4, // 0≤电量<20,0格
     newVersion: false,
-    rightId:wx.getStorageSync('rightId') || 0
+    rightId: wx.getStorageSync('rightId') || 0
   },
   onShow() {
-    if (typeof this.getTabBar === 'function' &&
-      this.getTabBar()) {
-      this.getTabBar().setData({
-        selected: 1
-      })
-    }
-    app.eventBus.on('rightChange', data =>{
-      if(data !== this.data.rightId){
-        this.setData({
-          rightId: data
-        })
-      }
-    })
-
-    if((!this.data.isOneLoading)) {
+    selectIndex(1);
+    // if (typeof this.getTabBar === 'function' &&
+    //   this.getTabBar()) {
+    //   this.getTabBar().setData({
+    //     selected: 1
+    //   })
+    // }
+    // app.eventBus.on('rightChange', data => {
+    //   if (data !== this.data.rightId) {
+    //     this.setData({
+    //       rightId: data
+    //     })
+    //   }
+    // })
+var _this = this;
+    if ((!this.data.isOneLoading)) {
       wx.getStorage({
         key: 'userInfo',
-        fail (res) {
+        fail(res) {
           // 取消订阅
-          if(_this.data.thisDeviceMac !== null) {
+          if (_this.data.thisDeviceMac !== null) {
             app.unsubscribe(`/${_this.data.thisDeviceMac}/user/pub_response`);
           };
           _this.setData({
@@ -54,10 +57,10 @@ Page({
           });
         },
         success() {
-          if(app.globalData.newDeviceId) {
+          if (app.globalData.newDeviceId) {
             // 获取设备本地数据
             _this.getDeviceData();
-          } else if(_this.data.deviceListIndex !== null){
+          } else if (_this.data.deviceListIndex !== null) {
             // 更新
             _this.actionDevice(_this.data.deviceListIndex);
           }
@@ -65,34 +68,19 @@ Page({
       });
     };
   },
-  changeRole(){
+  changeRole() {
     app.changeUserRight()
   },
   onLoad() {
-    _this = this;
-    // 版本自动更新代码
-    const updateManager = wx.getUpdateManager();
-    updateManager.onUpdateReady(function () {
-      _this.setData({
-        newVersion: true
-      });
-    })
-    updateManager.onUpdateFailed(function () {
-      // 新的版本下载失败
-      wx.showModal({
-        title: '已有新版本咯',
-        content: '请您删除当前小程序,重新打开呦~',
-        showCancel: false
-      })
-    })
-
+var _this = this;
+eventOn(_this);
     wx.showLoading({
       title: '加载中',
     });
-    
-    const str = setTimeout(()=> {
+
+    const str = setTimeout(() => {
       clearTimeout(str);
-      if(_this.data.isOneLoading) {
+      if (_this.data.isOneLoading) {
         _this.setData({
           isOneLoading: false,
         });
@@ -102,15 +90,15 @@ Page({
     // 获取缓存的频道数据
     wx.getStorage({
       key: "channelData",
-      success(res){
+      success(res) {
         _this.setData({
           channelData: res.data
         })
       }
     });
 
-    // 登录
-    this.login();
+    // 获取设备本地数据
+    _this.getDeviceData();
 
   },
   login() {
@@ -126,7 +114,7 @@ Page({
           // Do something when catch error
         };
         // 请求登录
-        login({code: res.code, phone}).then((res)=> {
+        login({ code: res.code, phone }).then((res) => {
 
           app.globalData.userInfo = res;
           wx.setStorage({
@@ -134,7 +122,7 @@ Page({
             data: res
           });
           // 需要用授权登录
-          if((res.isNewUser && res.isNewUser === true) || !phone) {
+          if ((res.isNewUser && res.isNewUser === true) || !phone) {
             _this.setData({
               showLogin: true,
             });
@@ -147,7 +135,7 @@ Page({
             showLogin: false,
           });
           wx.setStorage({
-            key:"token",
+            key: "token",
             data: JSON.stringify({
               id: res.userId,
               token: res.accessToken,
@@ -161,17 +149,17 @@ Page({
     // 获取设备数据
     wx.getStorage({
       key: 'devicelist',
-      success (res) {
+      success(res) {
         wx.hideLoading();
-        if(res.data) {
+        if (res.data) {
           const resData = JSON.parse(res.data);
           _this.setData({
             deviceList: resData
           });
           // 连接mqtt
-          if(app.globalData.client === null) {
+          if (app.globalData.client === null) {
             app.connect();
-          } else if(app.globalData.newDeviceId) {
+          } else if (app.globalData.newDeviceId) {
             _this.setData({
               actionIndex: null,
               deviceListIndex: null,
@@ -180,7 +168,7 @@ Page({
             // 监听
             let topic = `/AIrSMArT_${resData[0].name.split("BLUFI_")[1]}/status/onoffline`;
             app.subscribe(topic);
-            const Timeout = setTimeout(()=> {
+            const Timeout = setTimeout(() => {
               clearTimeout(Timeout);
               _this.actionDevice(0);
             }, 1000);
@@ -197,7 +185,7 @@ Page({
           // }
         }
       },
-      fail(e){
+      fail(e) {
         wx.hideLoading();
       }
     });
@@ -205,10 +193,10 @@ Page({
   // 回调
   mqttCallback(type, option) {
     let payloads = null;
-    if(option) {
+    if (option) {
       payloads = JSON.parse(option.payload);
     };
-    switch(type) {
+    switch (type) {
       case "connect":
         _this.connectSuccess();
         break;
@@ -217,28 +205,28 @@ Page({
         break;
       case "message":
         // 接收设备播放信息
-        if(payloads.type === "get_position" && payloads.other) {
+        if (payloads.type === "get_position" && payloads.other) {
           let actionIndex = null;
-          
-          _this.data.channelData.map((v, index)=> {
-            if(v.channelNum === payloads.other.channel) {
+
+          _this.data.channelData.map((v, index) => {
+            if (v.channelNum === payloads.other.channel) {
               actionIndex = index;
             }
           });
           _this.setData({
             actionIndex,
           });
-        } else if(payloads.type === "play" || payloads.type === "play_state") {
+        } else if (payloads.type === "play" || payloads.type === "play_state") {
 
-          if(_this.data.deviceListIndex === null) {
+          if (_this.data.deviceListIndex === null) {
             return;
           }
           // 接收设备当前播放状态
           const obj = {
             DstDeviceName: _this.getThisDeviceID()
           }
-          app.PubMsg({type: "get_position", ...obj});
-        } else if(payloads.type === "get_dev_info") {
+          app.PubMsg({ type: "get_position", ...obj });
+        } else if (payloads.type === "get_dev_info") {
           // 接收设备当前信息
           this.getchannelData(payloads.other.ProdModel);
           // 电量
@@ -249,31 +237,31 @@ Page({
           _this.setData({
             isSetWake: false,
           });
-          payloads.other.alarm.map((v)=> {
-            if(v.enable === "1"){
+          payloads.other.alarm.map((v) => {
+            if (v.enable === "1") {
               _this.setData({
                 isSetWake: true
               });
             }
           });
           // 更新信息
-          _this.data.deviceList.map((v, index)=> {
-            if(payloads.SrcDeviceName && payloads.SrcDeviceName.indexOf(v.name.split("BLUFI_")[1]) !== -1) {
+          _this.data.deviceList.map((v, index) => {
+            if (payloads.SrcDeviceName && payloads.SrcDeviceName.indexOf(v.name.split("BLUFI_")[1]) !== -1) {
               _this.data.deviceList[index].ProdModel = payloads.other.ProdModel;
               _this.data.deviceList[index].devName = payloads.other.devName;
             }
           });
           // 更新缓存
           wx.setStorage({
-            key:"devicelist",
+            key: "devicelist",
             data: JSON.stringify(_this.data.deviceList),
-            success(){
+            success() {
               _this.setData({
                 deviceList: _this.data.deviceList
               })
             }
           });
-        } else if(payloads.type === "battery" && payloads.other) {
+        } else if (payloads.type === "battery" && payloads.other) {
           _this.setData({
             battery: _this._battery(payloads.other.battery),
           })
@@ -286,17 +274,17 @@ Page({
   // 格式化电量
   _battery(battery) {
     let _battery = 0;
-    if(battery < 20) {
+    if (battery < 20) {
       _battery = 0
-    } else if(20 <= battery && battery < 40) {
+    } else if (20 <= battery && battery < 40) {
       _battery = 1
-    } else if(40 <= battery && battery < 60) {
+    } else if (40 <= battery && battery < 60) {
       _battery = 2
-    } else if(60 <= battery && battery < 80) {
+    } else if (60 <= battery && battery < 80) {
       _battery = 3
-    } else if(80 <= battery && battery <= 100) {
+    } else if (80 <= battery && battery <= 100) {
       _battery = 4
-    } else if(battery > 100) {
+    } else if (battery > 100) {
       _battery = 5
     };
     return _battery
@@ -307,8 +295,8 @@ Page({
   },
   online(payloads) {
     // 设置在线状态
-    _this.data.deviceList.map((v, index)=> {
-      if(payloads.uuid && payloads.uuid.indexOf(v.name.split("BLUFI_")[1]) !== -1) {
+    _this.data.deviceList.map((v, index) => {
+      if (payloads.uuid && payloads.uuid.indexOf(v.name.split("BLUFI_")[1]) !== -1) {
         _this.data.deviceList[index].state = payloads.state;
       }
     });
@@ -317,15 +305,15 @@ Page({
     });
     // 更新缓存
     wx.setStorage({
-      key:"devicelist",
+      key: "devicelist",
       data: JSON.stringify(_this.data.deviceList)
     });
     // 如没有选中,选中最新的
-    (()=> {
-      if(_this.data.deviceListIndex === null) {
+    (() => {
+      if (_this.data.deviceListIndex === null) {
         let itue = false;
-        _this.data.deviceList.map((v, index)=> {
-          if(v.state === "online" && !itue) {
+        _this.data.deviceList.map((v, index) => {
+          if (v.state === "online" && !itue) {
             itue = true;
             _this.actionDevice(index);
           }
@@ -334,11 +322,11 @@ Page({
       //  else {
       //   _this.actionDevice(_this.data.deviceListIndex);
       // };
-      
+
     })();
 
     // 当前播放设备离线
-    if( _this.data.deviceListIndex !== null && _this.data.deviceList[_this.data.deviceListIndex].state !== "online") {
+    if (_this.data.deviceListIndex !== null && _this.data.deviceList[_this.data.deviceListIndex].state !== "online") {
       _this.setData({
         actionIndex: null,
         deviceListIndex: null,
@@ -346,24 +334,24 @@ Page({
     };
   },
   // 订阅设备在线状态
-  subscribeDevicesStatus(){
-    this.data.deviceList.forEach((value) =>{
+  subscribeDevicesStatus() {
+    this.data.deviceList.forEach((value) => {
       let topic = `/AIrSMArT_${value.name.split("BLUFI_")[1]}/status/onoffline`;
-      app.subscribe(topic); 
+      app.subscribe(topic);
     })
   },
 
   // 订阅消息
-  subscribeCurrDevice(){
+  subscribeCurrDevice() {
     if (!(app.globalData.client && app.globalData.client.connected)) {
       console.log("未连接MQTT服务器");
-      const str = setInterval(()=> {
+      const str = setInterval(() => {
         clearInterval(str);
         _this.subscribeCurrDevice();
       }, 500);
       return;
     };
-    if(this.data.deviceList.length === 0 || this.data.deviceListIndex === null) {
+    if (this.data.deviceList.length === 0 || this.data.deviceListIndex === null) {
       return
     };
     let topic = `/AIrSMArT_${this.data.deviceList[this.data.deviceListIndex].name.split("BLUFI_")[1]}/user/pub_response`;
@@ -371,19 +359,19 @@ Page({
     const obj = {
       DstDeviceName: _this.getThisDeviceID()
     };
-    app.PubMsg({type: "get_dev_info", ...obj});
+    app.PubMsg({ type: "get_dev_info", ...obj });
   },
-  
-  isShowDevicelistFun(){
+
+  isShowDevicelistFun() {
     this.setData({
       isShowDevicelist: !_this.data.isShowDevicelist
     })
   },
   actionMusic(e) {
-    if(e.currentTarget.dataset.index === this.data.actionIndex) {
+    if (e.currentTarget.dataset.index === this.data.actionIndex) {
       return;
     };
-    if(this.data.deviceListIndex === null) {
+    if (this.data.deviceListIndex === null) {
       wx.showToast({
         title: '请选择设备',
         icon: "none"
@@ -393,7 +381,7 @@ Page({
     this.setData({
       actionIndex: e.currentTarget.dataset.index
     });
-    const other= {
+    const other = {
       "url": "",
       "media_data": "",
       "user_id": `${app.globalData.userInfo.deviceUid}`,
@@ -401,8 +389,8 @@ Page({
       "channel_id": `${this.data.channelData[e.currentTarget.dataset.index].channelNum}`,
       "order": "",
       "resource_from": "",
-      "songAlbumID":"",
-      "version":3,
+      "songAlbumID": "",
+      "version": 3,
       "is_debug": app.globalData.is_debug
     };
     app.PubMsg({
@@ -411,8 +399,8 @@ Page({
       other
     });
   },
-  actionDeviceIndex(e){
-    if(e.currentTarget.dataset.index === this.data.deviceListIndex) {
+  actionDeviceIndex(e) {
+    if (e.currentTarget.dataset.index === this.data.deviceListIndex) {
       return
     };
     this.actionDevice(e.currentTarget.dataset.index)
@@ -420,11 +408,11 @@ Page({
 
   actionDevice(index) {
     const device = this.data.deviceList[index];
-    if(device.state !== "online") {
+    if (device.state !== "online") {
       return;
     };
     // 取消订阅
-    if(this.data.thisDeviceMac !== null) {
+    if (this.data.thisDeviceMac !== null) {
       app.unsubscribe(`/${this.data.thisDeviceMac}/user/pub_response`);
     };
 
@@ -456,11 +444,11 @@ Page({
     })
   },
   getchannelData(clientType) {
-    let _this=this;
-    if(this.data.deviceListIndex === null) {
+    let _this = this;
+    if (this.data.deviceListIndex === null) {
       return;
     };
-    listByDevice({clientType}).then((res)=> {
+    listByDevice({ clientType }).then((res) => {
       _this.setData({
         channelData: res
       });
@@ -468,14 +456,14 @@ Page({
       const obj = {
         DstDeviceName: _this.getThisDeviceID()
       }
-      app.PubMsg({type: "get_position", ...obj});
+      app.PubMsg({ type: "get_position", ...obj });
       wx.setStorage({
         key: "channelData",
         data: res
       });
 
       // 有新设备
-      if(app.globalData.newDeviceId) {
+      if (app.globalData.newDeviceId) {
         app.globalData.newDeviceId = null;
         return;
         // 去掉此功能,先留着吧
@@ -512,24 +500,24 @@ Page({
 
     const id = this.data.deviceList[e.currentTarget.dataset.index].deviceId;
     let name = _this.data.deviceListIndex !== null ? this.data.deviceList[_this.data.deviceListIndex].name : null;
-    const deviceList = this.data.deviceList.filter((v,i)=> {
+    const deviceList = this.data.deviceList.filter((v, i) => {
       return id !== v.deviceId
     });
     // 取消订阅
     app.unsubscribe(`/AIrSMArT_${_this.data.deviceList[e.currentTarget.dataset.index].name.split("BLUFI_")[1]}/user/pub_response`);
 
     wx.setStorage({
-      key:"devicelist",
+      key: "devicelist",
       data: JSON.stringify(deviceList),
-      success(){
-        
+      success() {
+
         _this.setData({
           deviceList,
           thisDeviceMac: null
         });
 
         // 当前没有设备
-        if(deviceList.length === 0) {
+        if (deviceList.length === 0) {
           _this.setData({
             showDelete: false,
             actionIndex: null,
@@ -538,17 +526,17 @@ Page({
           });
         }
 
-        if(_this.data.deviceListIndex === null) {
+        if (_this.data.deviceListIndex === null) {
           return
         };
-        if(e.currentTarget.dataset.index === _this.data.deviceListIndex) {
+        if (e.currentTarget.dataset.index === _this.data.deviceListIndex) {
           let index_ = null;
-          deviceList.map((v, index)=> {
-            if(v.state === "online" && index_ === null) {
+          deviceList.map((v, index) => {
+            if (v.state === "online" && index_ === null) {
               index_ = index;
             }
           });
-          if(index_ !== null) {
+          if (index_ !== null) {
             _this.actionDevice(index_);
           } else {
             _this.setData({
@@ -557,8 +545,8 @@ Page({
             });
           };
         } else {
-          deviceList.map((v, index)=> {
-            if(v.name === name) {
+          deviceList.map((v, index) => {
+            if (v.name === name) {
               _this.setData({
                 deviceListIndex: index,
               });
@@ -567,30 +555,30 @@ Page({
         }
       }
     })
-    
+
   },
   goWake() {
-    if(this.data.deviceListIndex === null) {
+    if (this.data.deviceListIndex === null) {
       return;
     };
     wx.navigateTo({
       url: './../deviceWake/deviceWake?deviceId=' + this.data.deviceList[this.data.deviceListIndex].deviceId + "&clientType=" + this.data.deviceList[this.data.deviceListIndex].ProdModel,
     });
-    
+
   },
   goChnnel() {
     wx.setStorage({
       key: "channelDeta",
       data: this.data.channelData[this.data.actionIndex],
-      success(){
+      success() {
         wx.navigateTo({
           url: './../channelDetails/channelDetails'
         })
       }
     })
-    
+
   },
-  updata () {
+  updata() {
     // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
     wx.getUpdateManager().applyUpdate()
   },
@@ -600,7 +588,7 @@ Page({
     })
   },
   onUnload() {
-    if(app.globalData.client === null) {
+    if (app.globalData.client === null) {
       return;
     };
     app.globalData.client.end(true);

+ 1 - 1
pages/index/index.wxml

@@ -17,7 +17,7 @@
       <text bindtap="goLogin">点击登录</text>
      </view>
   </view>
-  <view class="mair" style="height: calc(100vh - 22rpx - {{navBarHeight}}px);">
+  <view class="mair" style="height: calc(100vh - 22rpx - 100rpx - {{navBarHeight}}px);">
     <view wx:if="{{isShowDevicelist}}" class="deviceList" catchtap="isShowDevicelistFun">
       <view class="mz">
         <view class="li-view"  wx:for="{{deviceList}}">

+ 24 - 21
pages/me/me.js

@@ -2,6 +2,7 @@
 
 // pages/me/me.ts
 const app = getApp();
+const { selectIndex,eventOn } = require('./../../custom-tab-bar/tabbar.js');
 
 Page({
 
@@ -28,9 +29,10 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad() {
-
     // wx.getStorage("userInfo")
     const _this = this;
+    eventOn(_this);
+
     wx.getStorage({
       key: "userInfo",
       success(res) {
@@ -91,26 +93,27 @@ Page({
    */
   onShow() {
     let num = this.data.rightId === 1 ? 2 : 1
-    if (typeof this.getTabBar === 'function' &&
-      this.getTabBar()) {
-      this.getTabBar().setData({
-        selected: num
-      })
-    }
-    app.eventBus.on('rightChange', data =>{
-      if(data !== this.data.rightId){
-        this.setData({
-          rightId: data
-        })
-        num = this.data.rightId === 1 ? 2 : 1
-        if (typeof this.getTabBar === 'function' &&
-          this.getTabBar()) {
-          this.getTabBar().setData({
-            selected: num
-          })
-        }
-      }
-    })
+    selectIndex(num);
+    // if (typeof this.getTabBar === 'function' &&
+    //   this.getTabBar()) {
+    //   this.getTabBar().setData({
+    //     selected: num
+    //   })
+    // }
+    // app.eventBus.on('rightChange', data =>{
+    //   if(data !== this.data.rightId){
+    //     this.setData({
+    //       rightId: data
+    //     })
+    //     num = this.data.rightId === 1 ? 2 : 1
+    //     if (typeof this.getTabBar === 'function' &&
+    //       this.getTabBar()) {
+    //       this.getTabBar().setData({
+    //         selected: num
+    //       })
+    //     }
+    //   }
+    // })
     this.onLoad();
   },
 

+ 1 - 1
pages/piano/rank/rank.wxml

@@ -14,7 +14,7 @@
   </view>
 
   <view class="tab_list">
-    <view wx:for="{{tabList}}" wx:key="{{item}}" wx:for-index="{{index}}">
+    <view wx:for="{{tabList}}" wx:key="item" wx:for-index="index">
       <text class="tabbar {{selectIndex == index ? select : unselect}}">{{item}}</text>
     </view>
   </view>

+ 1 - 2
pages/piano/rank/rank.wxss

@@ -71,8 +71,7 @@ align-items: center;
 .container .rank_scroll {
   margin-top: 16rpx;
   width: 100%;
-  flex: 1;
-  display: flex;
+  height: 100%;
 }
 
 .container .rank_scroll .scoll_item {