Преглед на файлове

feature: 选择对应频道播放数据处理

Damon преди 7 месеца
родител
ревизия
cd06f56666
променени са 7 файла, в които са добавени 105 реда и са изтрити 63 реда
  1. 12 44
      pages/index/index.js
  2. 1 1
      pages/index/index.wxml
  3. 9 7
      utils/lexin/connect.js
  4. 67 0
      utils/lexin/jump.js
  5. 9 6
      utils/lexin/message.js
  6. 5 4
      utils/lexin/scan.js
  7. 2 1
      utils/lexin/subscribe.js

+ 12 - 44
pages/index/index.js

@@ -143,7 +143,6 @@ Page({
         });
         break;
 
-        // PlayState:  ///播放状态:0默认状态,1播放状态,2暂停状态, 3停止状态,4缓冲状态。
       case "message":
         if (payloads) {
           var payloadType = payloads.type;
@@ -227,52 +226,14 @@ Page({
     });
   },
 
-  onTapActionMusic(e) {
+  ///选择对应的频道
+  onTapChannelIndex(e) {
     var that = this;
-    var actionIndex = that.data.actionIndex;
-    if (strings.isEmpty(actionIndex)) {
-      return;
-    }
-
     var index = e.currentTarget.dataset.index;
-    if (index === actionIndex) {
-      return;
-    };
-
-    var deviceList = that.getDeviceList();
-    var deviceListSelect = that.getDeviceListSelect();
-    if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
-      wx.showToast({
-        title: '请选择设备',
-        icon: "none"
+    lexin_jump.toChannelIndex(index, function (i) {
+      that.setData({
+        actionIndex: i,
       });
-      return;
-    };
-
-    that.setData({
-      actionIndex: index,
-    });
-
-    var channelData = that.getChannelData();
-    var deviceId = deviceList[deviceListSelect].deviceId;
-    const other = {
-      "url": "",
-      "media_data": "",
-      "user_id": `${app.globalData.userInfo.deviceUid}`,
-      "timestamp": `${Math.round(new Date() / 1000)}`,
-      "channel_id": `${channelData[index].channelNum}`,
-      "order": "",
-      "resource_from": "",
-      "songAlbumID": "",
-      "version": 3,
-      "is_debug": app.globalData.is_debug
-    };
-
-    var deviceMacId = lexin_util.getDeviceMacId(deviceId);
-    app.PubMsg({
-      type: "play",
-      DstDeviceName: deviceMacId,
-      other
     });
   },
 
@@ -676,6 +637,13 @@ Page({
     return channelData;
   },
 
+  /// 当前播放频道
+  getActionIndex() {
+    var that = this;
+    var actionIndex = that.data.actionIndex;
+    return actionIndex;
+  },
+
   ///设置设备相关信息
   setDeviceInfor(other) {
     var that = this;

+ 1 - 1
pages/index/index.wxml

@@ -103,7 +103,7 @@
               <view wx:for="{{channelData}}" class="li {{index === actionIndex ? 'action' : ' '}}">
                 <image mode="scaleToFill" wx:if="{{index === actionIndex}}" class="zz" src="./../../img/zz.png"></image>
                 <text class="lm">{{luoma[index]}}</text>
-                <view class="musicInfo" data-index="{{index}}" bindtap="onTapActionMusic">
+                <view class="musicInfo" data-index="{{index}}" bindtap="onTapChannelIndex">
                   <image mode="scaleToFill" class="pic" src="{{item.channelPic ? item.channelPic : './../../img/head_pic.png'}}"></image>
                   <text>{{item.channelName}}</text>
                   <image mode="scaleToFill" wx:if="{{index === actionIndex}}" class="svg" src="./../../svg/audio.svg"></image>

+ 9 - 7
utils/lexin/connect.js

@@ -13,7 +13,8 @@ function searchOnlineDevice(payloads, changeCallback, resetCallback) {
   var isChanged = false;
   const strings = require('../strings');
   const lexin_util = require('../lexin/util');
-  var deviceList = getCurrentPages()[0].getDeviceList();
+  var pages = getCurrentPages();
+  var deviceList = pages[0].getDeviceList();
 
   /// 处理在线设备
   if (!strings.isEmpty(deviceList)) {
@@ -47,20 +48,21 @@ function searchOnlineDevice(payloads, changeCallback, resetCallback) {
 /// 连接设备
 function _connectToDevice(resetCallback) {
   ///是否已登录
-  var isLogin = getCurrentPages()[0].getIsLogin();
+  var pages = getCurrentPages();
+  var isLogin = pages[0].getIsLogin();
   if (!isLogin) {
     return;
   }
 
   ///当前没有连接设备,则去连接第一个wifi设备
-  var deviceList = getCurrentPages()[0].getDeviceList();
-  var deviceListSelect = getCurrentPages()[0].getDeviceListSelect();
+  var deviceList = pages[0].getDeviceList();
+  var deviceListSelect = pages[0].getDeviceListSelect();
   ///去连接第一个
   if (deviceListSelect === null) {
     const strings = require('../strings');
     if (!strings.isEmpty(deviceList)) {
-      var autoConnected = getCurrentPages()[0].getAutoConnected();
-      var connectDeviceIding = getCurrentPages()[0].getConnectDeviceIding();
+      var autoConnected = pages[0].getAutoConnected();
+      var connectDeviceIding = pages[0].getConnectDeviceIding();
       /// 还没有自动连接采用第一个
       if (!autoConnected) {
         for (var i = 0; i < deviceList.length; i++) {
@@ -78,7 +80,7 @@ function _connectToDevice(resetCallback) {
         var deviceId = device.deviceId;
         if (deviceId == connectDeviceIding) {
           if (device.connectType == 3 && device.state === "online") {
-            getCurrentPages()[0].actionDevice(device);
+            pages[0].actionDevice(device);
           }
           break;
         }

+ 67 - 0
utils/lexin/jump.js

@@ -1,7 +1,74 @@
 module.exports = {
+  toChannelIndex: toChannelIndex,
   toAboutUs: toAboutUs,
 }
 
+///选择指定频道
+function toChannelIndex(index, callback) {
+  var pages = getCurrentPages();
+  const route_util = require('../route_util');
+  const route_constant = require('../route_constant');
+  var isLogin = pages[0].getIsLogin();
+  if (!isLogin) {
+    route_util.jump(route_constant.login);
+    return;
+  }
+
+  const strings = require('../strings');
+  var actionIndex = pages[0].getActionIndex();
+  if (strings.isEmpty(actionIndex)) {
+    return;
+  }
+
+  if (index === actionIndex) {
+    return;
+  };
+
+  var deviceList = pages[0].getDeviceList();
+  var deviceListSelect = pages[0].getDeviceListSelect();
+  if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
+    wx.showToast({
+      title: '请选择设备',
+      icon: "none"
+    });
+    return;
+  };
+
+  callback(index);
+
+  const app = getApp();
+  const lexin_util = require('../lexin/util');
+  var channelData = pages[0].getChannelData();
+
+  // `${deviceUid}`
+  var deviceUid = app.globalData.userInfo.deviceUid;
+  var timestamp = Math.round(new Date() / 1000);
+  var channel_id = channelData[index].channelNum;
+  var is_debug = app.globalData.is_debug;
+
+  var deviceId = deviceList[deviceListSelect].deviceId;
+  const other = {
+    "url": "",
+    "media_data": "",
+    "user_id": deviceUid,
+    "timestamp": timestamp,
+    "channel_id": channel_id,
+    "order": "",
+    "resource_from": "",
+    "songAlbumID": "",
+    "version": 3,
+    "is_debug": is_debug,
+  };
+
+  var deviceMacId = lexin_util.getDeviceMacId(deviceId);
+  app.PubMsg({
+    type: "play",
+    DstDeviceName: deviceMacId,
+    other
+  });
+};
+
+///关于我们
 function toAboutUs() {
   const route_util = require('../route_util');
   const route_constant = require('../route_constant');

+ 9 - 6
utils/lexin/message.js

@@ -11,7 +11,8 @@ function getPosition(other, canllback) {
   try {
     var actionIndex = null;
     const strings = require('../strings');
-    var channelData = getCurrentPages()[0].getChannelData();
+    var pages = getCurrentPages();
+    var channelData = pages[0].getChannelData();
     if (!strings.isEmpty(channelData)) {
       channelData.map((v, index) => {
         if (v.channelNum === other.channel) {
@@ -32,7 +33,8 @@ function getDeviceInfo(payloads) {
   ///连上就调用2次 payloads.SrcDeviceName:AIrSMArT_7cdfa1fcbb24
   const strings = require('../strings');
   const lexin_util = require('../lexin/util');
-  var deviceList = getCurrentPages()[0].getDeviceList();
+  var pages = getCurrentPages();
+  var deviceList = pages[0].getDeviceList();
   if (!strings.isEmpty(deviceList)) {
     var currentDeviceId = "";
     /// 获取需要连接的那个设备,获取设备名称
@@ -62,7 +64,7 @@ function getDeviceInfo(payloads) {
         var device = deviceList[i];
         var deviceId = device.deviceId;
         if (deviceId == currentDeviceId) {
-          getCurrentPages()[0].refreshCurrentDevice(device);
+          pages[0].refreshCurrentDevice(device);
           break;
         }
       }
@@ -89,10 +91,11 @@ function getBattery(battery) {
   return b;
 };
 
-///播放和播放状态
+///播放和播放状态  PlayState:  ///播放状态:0默认状态,1播放状态,2暂停状态, 3停止状态,4缓冲状态。
 function getPlay() {
-  var deviceList = getCurrentPages()[0].getDeviceList();
-  var deviceListSelect = getCurrentPages()[0].getDeviceListSelect();
+  var pages = getCurrentPages();
+  var deviceList = pages[0].getDeviceList();
+  var deviceListSelect = pages[0].getDeviceListSelect();
   if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
     return;
   };

+ 5 - 4
utils/lexin/scan.js

@@ -3,7 +3,8 @@ module.exports = {
 }
 
 function compareList(changeCallback, addBlueCallback) {
-  var deviceList = getCurrentPages()[0].getDeviceList()
+  var pages = getCurrentPages();
+  var deviceList = pages[0].getDeviceList()
   if (deviceList.length > 0) {
     const {
       BtHelper
@@ -56,10 +57,10 @@ function compareList(changeCallback, addBlueCallback) {
         }
 
         ///没有连接则连接第一个在线的蓝牙
-        var autoConnected = getCurrentPages()[0].getAutoConnected();
-        var deviceListSelect = getCurrentPages()[0].getDeviceListSelect();
+        var autoConnected = pages[0].getAutoConnected();
+        var deviceListSelect = pages[0].getDeviceListSelect();
         if (!autoConnected && deviceListSelect == null) {
-          var list = getCurrentPages()[0].getDeviceList();
+          var list = pages[0].getDeviceList();
           for (var i = 0; i < list.length; i++) {
             var item = list[i];
             if (item.connectType == 1 && item.state == "online") {

+ 2 - 1
utils/lexin/subscribe.js

@@ -18,7 +18,8 @@ function subscribeSingleDevice(deviceId) {
 // 订阅在线设备
 function subscribeAllDevice() {
   const strings = require('../strings');
-  var deviceList = getCurrentPages()[0].getDeviceList();
+  var pages = getCurrentPages();
+  var deviceList = pages[0].getDeviceList();
   if (strings.isEmpty(deviceList)) {
     return;
   }