瀏覽代碼

feature: 唤醒以及环境正式环境和测试环境处理

Damon 7 月之前
父節點
當前提交
f003509347
共有 5 個文件被更改,包括 252 次插入262 次删除
  1. 9 2
      app.js
  2. 127 105
      pages/deviceWake/deviceWake.js
  3. 2 2
      pages/deviceWake/deviceWake.wxml
  4. 110 150
      pages/wakeList/wakeList.js
  5. 4 3
      utils/util.js

+ 9 - 2
app.js

@@ -2,6 +2,8 @@ import mqtt from './utils/mqtt';
 import update from './utils/update';
 import strings from './utils/strings';
 import store from './utils/store.js';
+import env from './utils/env.js';
+
 //连接的服务器域名
 // const host = 'wxs://mqtt.test.radio1964.com';
 // const host = 'wxs://mqtt.ssl.keepradioon.net:8884'
@@ -10,9 +12,12 @@ const iosHost = 'wxs://mqtt.test.radio1964.com:8884';
 const androidHost = 'wxs://mqtt.ssl.keepradioon.net:8884'
 App({
   globalData: {
+    isRelease: false,
+    is_debug: 2, // 1 测试环境 // 2正式环境
+    baseUrl: env.test.baseUrl,
+
     userInfo: null,
     classifyProducts: "",
-
     statusBarHeight: 0,
     navBarHeight: 0,
     MenuButtonheight: 0,
@@ -21,7 +26,6 @@ App({
     ssid: "",
     pwdData: "",
     userData: null,
-    is_debug: 2, // 1 测试环境 // 2正式环境
     client: null,
     oneInitBluetooth: true,
 
@@ -44,6 +48,9 @@ App({
   ///全局初始化
   onLaunch() {
     var that = this;
+    that.globalData.is_debug = that.globalData.isRelease ? 2 : 1;
+    that.globalData.baseUrl = that.globalData.isRelease ? env.prod.baseUrl : env.test.baseUrl;
+
     ///用户信息
     var userInfo = store.getStore("userInfo");
     if (!strings.isEmpty(userInfo)) {

+ 127 - 105
pages/deviceWake/deviceWake.js

@@ -1,4 +1,3 @@
-// pages/deviceWake/deviceWake.js
 const app = getApp();
 const {
   formatNumber
@@ -6,15 +5,11 @@ const {
 const {
   deviceWakedetail
 } = require('./../../utils/api.js');
-import lexin_devices from '../../utils/lexin/devices';
+
+import lexin_devices from '../../utils/lexin/devices.js';
 import lexin_util from '../../utils/lexin/util.js';
 
-let _this = null
 Page({
-
-  /**
-   * 页面的初始数据
-   */
   data: {
     nvabarData: {
       showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
@@ -69,16 +64,14 @@ Page({
     deviceOther: null,
     updataDeviceInfo: false,
     repeatIndex: 0,
+    deviceId: "",
   },
 
-  /**
-   * 生命周期函数--监听页面加载
-   */
   onLoad(options) {
-    _this = this;
-
+    var that = this;
     var clientType = options.clientType;
     var deviceId = options.deviceId;
+    that.data.deviceId = deviceId;
     var deviceMac = lexin_util.getDeviceMacId(deviceId);
     // var deviceMac = `AIrSMArT_${deviceId.split(lexin_devices.leXin)[1]}`;
     deviceWakedetail({
@@ -86,23 +79,23 @@ Page({
       deviceMac: deviceMac,
     }).then((res) => {
       if (res && res.length > 0) {
-        this.setData({
+        that.setData({
           wakeName: res[0].audioName || null
         });
       }
     })
-    this.data.clientType = options.clientType
-    this.data.deviceMac = lexin_util.getDeviceMacId(options.deviceId);
-    // this.data.deviceMac = `AIrSMArT_${options.deviceId.split(lexin_devices.leXin)[1]}`;
+    that.data.clientType = options.clientType
+    that.data.deviceMac = lexin_util.getDeviceMacId(options.deviceId);
+    // that.data.deviceMac = `AIrSMArT_${options.deviceId.split(lexin_devices.leXin)[1]}`;
     app.PubMsg({
       type: "get_dev_info",
-      DstDeviceName: this.data.deviceMac
+      DstDeviceName: that.data.deviceMac
     });
 
     // 赋值按钮回调
-    this.setData({
+    that.setData({
       twoButCallback: () => {
-        _this.setData({
+        that.setData({
           toast_visible: false
         })
       }
@@ -110,13 +103,16 @@ Page({
   },
 
   onShow(options) {
+    var that = this;
+    var deviceMac = that.data.deviceMac;
     app.PubMsg({
       type: "get_dev_info",
-      DstDeviceName: _this.data.deviceMac
+      DstDeviceName: deviceMac,
     });
   },
 
   mqttCallback(type, option) {
+    var that = this;
     let payloads = null;
     if (option) {
       payloads = JSON.parse(option.payload);
@@ -130,11 +126,11 @@ Page({
             icon: 'none',
             duration: 2000
           });
-          _this.setData({
+          that.setData({
             devicerStatus: false,
           })
         } else {
-          _this.setData({
+          that.setData({
             devicerStatus: true,
           })
         }
@@ -142,7 +138,7 @@ Page({
       case "message":
         // 设备信息
         if (payloads.type === "get_dev_info") {
-          _this.setData({
+          that.setData({
             deviceOther: payloads.other,
             updataDeviceInfo: true,
           });
@@ -151,61 +147,60 @@ Page({
               if (v.alarm_id === "0") {
                 v.action = "update";
                 // 休眠
-                _this.setData({
+                that.setData({
                   alarm_id_0: v
                 });
 
                 // 定时时间
                 if (v.on_off_timestamp !== "") {
-                  _this.setData({
+                  that.setData({
                     alarm_id_0_time: v.on_off_timestamp
                   })
                 }
 
-
                 // 是否启用
                 if (v.enable === "1") {
-                  _this.setData({
+                  that.setData({
                     switch1Checked: true
                   })
                 } else {
-                  _this.setData({
+                  that.setData({
                     switch1Checked: false
                   })
                 }
 
                 // 重复
                 if (v.week_actives) {
-                  _this.setData({
-                    repeat0: _this.repeatText(v.week_actives),
+                  that.setData({
+                    repeat0: that.repeatText(v.week_actives),
                   })
                 }
 
               } else if (v.alarm_id === "1") {
                 // 唤醒
-                _this.setData({
+                that.setData({
                   alarm_id_1: v
                 });
                 // 定时时间
                 if (v.on_off_timestamp !== "") {
-                  _this.setData({
+                  that.setData({
                     time: v.on_off_timestamp
                   })
                 }
                 // 是否启用
                 if (v.enable === "1") {
-                  _this.setData({
+                  that.setData({
                     switch2Checked: true
                   })
                 } else {
-                  _this.setData({
+                  that.setData({
                     switch2Checked: false
                   })
                 }
                 // 重复
                 if (v.week_actives) {
-                  _this.setData({
-                    repeat: _this.repeatText(v.week_actives),
+                  that.setData({
+                    repeat: that.repeatText(v.week_actives),
                   })
                 }
               }
@@ -215,7 +210,7 @@ Page({
           if (payloads.code === 200) {
             app.PubMsg({
               type: "get_dev_info",
-              DstDeviceName: _this.data.deviceMac
+              DstDeviceName: that.data.deviceMac
             });
           } else {
             wx.showModal({
@@ -237,14 +232,15 @@ Page({
 
   // 休眠-选择时间
   switch1Change(e) {
-    let other = this.data.alarm_id_0;
+    var that = this;
+    let other = that.data.alarm_id_0;
     if (e.detail.value) {
-      _this.setData({
+      that.setData({
         switch1Checked: e.detail.value
       });
       const thisTime = Math.round(new Date() / 1000);
-      other = this.setOther(other, 1);
-      other.on_off_timestamp = _this.data.alarm_id_0_time;
+      other = that.setOther(other, 1);
+      other.on_off_timestamp = that.data.alarm_id_0_time;
 
       // 有重复
       if (other.week_actives && other.week_actives.filter((v) => v === 1).length > 0) {
@@ -254,39 +250,41 @@ Page({
         other.weekly_repeat = "0";
       };
       // 如果跨天了
-      if (!this.compareDate(_this.data.alarm_id_0_time, this.formatTime(thisTime, "h:m:s"))) {
-        const date = new Date((_this.formatTime(thisTime, "Y-M-D") + " 00:00:00").replace(/-/g, '/'));
-        other.current_timestamp = this.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
+      if (!that.compareDate(that.data.alarm_id_0_time, that.formatTime(thisTime, "h:m:s"))) {
+        const date = new Date((that.formatTime(thisTime, "Y-M-D") + " 00:00:00").replace(/-/g, '/'));
+        other.current_timestamp = that.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
       };
       app.PubMsg({
         type: "alert_set",
-        DstDeviceName: _this.data.deviceMac,
+        DstDeviceName: that.data.deviceMac,
         other
       });
     } else {
-      _this.setData({
+      that.setData({
         switch1Checked: e.detail.value
       });
-      other = this.setOther(other, 0);
+      other = that.setOther(other, 0);
       app.PubMsg({
         type: "alert_set",
-        DstDeviceName: _this.data.deviceMac,
+        DstDeviceName: that.data.deviceMac,
         other
       });
     }
   },
+
   switch2Change(e) {
-    _this.data.updataDeviceInfo = false;
-    let other = _this.data.alarm_id_1;
+    var that = this;
+    that.data.updataDeviceInfo = false;
+    let other = that.data.alarm_id_1;
     if (e.detail.value) {
-      if (_this.data.deviceOther && _this.data.deviceOther.Power < 20) {
-        _this.setData({
+      if (that.data.deviceOther && that.data.deviceOther.Power < 20) {
+        that.setData({
           toast_visible: true,
         });
       };
       // app.PubMsg({
       //   type: "get_dev_info",
-      //   DstDeviceName: _this.data.deviceMac
+      //   DstDeviceName: that.data.deviceMac
       // });
       if (!other) {
         wx.showToast({
@@ -295,8 +293,8 @@ Page({
         })
         return
       }
-      other.on_off_timestamp = _this.data.time;
-      other = this.setOther(other, 1);
+      other.on_off_timestamp = that.data.time;
+      other = that.setOther(other, 1);
       let week_actives = other.week_actives ?? []
       if (week_actives.filter((v) => v === 1).length > 0) {
         // other.week_actives = [0,1,1,1,1,1,0],
@@ -306,17 +304,17 @@ Page({
       };
       app.PubMsg({
         type: "alert_set",
-        DstDeviceName: _this.data.deviceMac,
+        DstDeviceName: that.data.deviceMac,
         other
       });
 
       // 不要循环发送,也不要改alarm_id_0.enable
       // 循环查询
       // const Interval = setInterval(() => {
-      //   if (_this.data.updataDeviceInfo) {
+      //   if (that.data.updataDeviceInfo) {
       //     clearInterval(Interval);
-      // other.on_off_timestamp = _this.data.time;
-      // other = this.setOther(other, 1);
+      // other.on_off_timestamp = that.data.time;
+      // other = that.setOther(other, 1);
       // if (other.week_actives.filter((v) => v === 1).length > 0) {
       //   // other.week_actives = [0,1,1,1,1,1,0],
       //   other.weekly_repeat = "1";
@@ -325,15 +323,15 @@ Page({
       // };
       // app.PubMsg({
       //   type: "alert_set",
-      //   DstDeviceName: _this.data.deviceMac,
+      //   DstDeviceName: that.data.deviceMac,
       //   other
       // });
       // 需打开休眠
-      // if (_this.data.alarm_id_0.enable === "0") {
+      // if (that.data.alarm_id_0.enable === "0") {
 
       //   const thisTime = Math.round(new Date() / 1000);
-      //   const alarm_id_0 = this.setOther(_this.data.alarm_id_0, 1);
-      //   alarm_id_0.on_off_timestamp = _this.data.alarm_id_0_time;
+      //   const alarm_id_0 = that.setOther(that.data.alarm_id_0, 1);
+      //   alarm_id_0.on_off_timestamp = that.data.alarm_id_0_time;
 
       //   // 有重复
       //   if (alarm_id_0.week_actives.filter((v) => v === 1).length > 0) {
@@ -342,13 +340,13 @@ Page({
       //     alarm_id_0.weekly_repeat = "0";
       //   };;
       //   // 如果跨天了
-      //   if (!this.compareDate(_this.data.alarm_id_0_time, this.formatTime(thisTime, "h:m:s"))) {
-      //     const date = new Date((_this.formatTime(thisTime, "Y-M-D") + " 00:00:00").replace(/-/g, '/'));
-      //     alarm_id_0.current_timestamp = this.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
+      //   if (!that.compareDate(that.data.alarm_id_0_time, that.formatTime(thisTime, "h:m:s"))) {
+      //     const date = new Date((that.formatTime(thisTime, "Y-M-D") + " 00:00:00").replace(/-/g, '/'));
+      //     alarm_id_0.current_timestamp = that.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
       //   };
       //   app.PubMsg({
       //     type: "alert_set",
-      //     DstDeviceName: _this.data.deviceMac,
+      //     DstDeviceName: that.data.deviceMac,
       //     other: alarm_id_0
       //   });
       // }
@@ -356,33 +354,37 @@ Page({
       //   }
       // }, 500);
     } else {
-      other = this.setOther(other, 0);
+      other = that.setOther(other, 0);
       app.PubMsg({
         type: "alert_set",
-        DstDeviceName: _this.data.deviceMac,
+        DstDeviceName: that.data.deviceMac,
         other
       });
     }
   },
+
   // bindPickerChange(e) {
-  //   let other = this.data.alarm_id_0;
+  // var that = this;
+  //   let other = that.data.alarm_id_0;
   //   const thisTime = Math.round(new Date() / 1000);
-  //   other = this.setOther(other, 1);
-  //   other.on_off_timestamp = this.formatTime(thisTime + this.data.timeArray[e.detail.value].id, "h:m:s");
+  //   other = that.setOther(other, 1);
+  //   other.on_off_timestamp = that.formatTime(thisTime + that.data.timeArray[e.detail.value].id, "h:m:s");
   //   // 如果跨天了
-  //   if(parseInt(this.formatTime(thisTime + this.data.timeArray[e.detail.value].id, "D")) > parseInt(this.formatTime(thisTime, "D"))) {
-  //     const date = new Date(_this.formatTime(thisTime, "Y-M-D") + " 00:00:00");
-  //     other.current_timestamp = this.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
+  //   if(parseInt(that.formatTime(thisTime + that.data.timeArray[e.detail.value].id, "D")) > parseInt(that.formatTime(thisTime, "D"))) {
+  //     const date = new Date(that.formatTime(thisTime, "Y-M-D") + " 00:00:00");
+  //     other.current_timestamp = that.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
   //   };
-  //   app.PubMsg({type: "alert_set", DstDeviceName: _this.data.deviceMac, other});
+  //   app.PubMsg({type: "alert_set", DstDeviceName: that.data.deviceMac, other});
   // },
+
   bindTimeChange0: function (e) {
-    this.setData({
+    var that = this;
+    that.setData({
       alarm_id_0_time: e.detail.value + ":00"
     });
-    let other = this.data.alarm_id_0;
+    let other = that.data.alarm_id_0;
     other.on_off_timestamp = e.detail.value + ":00";
-    other = this.setOther(other, 1);
+    other = that.setOther(other, 1);
     // 有重复
     if (other.week_actives.filter((v) => v === 1).length > 0) {
       // other.week_actives = [0,1,1,1,1,1,0],
@@ -392,71 +394,88 @@ Page({
     };
     // 如果跨天了
     const thisTime = Math.round(new Date() / 1000);
-    if (!this.compareDate(_this.data.alarm_id_0_time, this.formatTime(thisTime, "h:m:s"))) {
-      const date = new Date((_this.formatTime(thisTime, "Y-M-D") + " 00:00:00").replace(/-/g, '/'));
-      other.current_timestamp = this.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
+    if (!that.compareDate(that.data.alarm_id_0_time, that.formatTime(thisTime, "h:m:s"))) {
+      const date = new Date((that.formatTime(thisTime, "Y-M-D") + " 00:00:00").replace(/-/g, '/'));
+      other.current_timestamp = that.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
     };
     app.PubMsg({
       type: "alert_set",
-      DstDeviceName: _this.data.deviceMac,
+      DstDeviceName: that.data.deviceMac,
       other
     });
   },
+
   bindTimeChange: function (e) {
-    this.setData({
+    var that = this;
+    that.setData({
       time: e.detail.value + ":00"
     });
-    let other = this.data.alarm_id_1;
+    let other = that.data.alarm_id_1;
     other.on_off_timestamp = e.detail.value + ":00";
-    other = this.setOther(other, 1);
+    other = that.setOther(other, 1);
     app.PubMsg({
       type: "alert_set",
-      DstDeviceName: _this.data.deviceMac,
+      DstDeviceName: that.data.deviceMac,
       other
     });
   },
+
   setRepeat(arr) {
-    let other = this.data.repeatIndex === "0" ? _this.data.alarm_id_0 : _this.data.alarm_id_1;
-    other = this.setOther(other, 1);
+    var that = this;
+    let other = that.data.repeatIndex === "0" ? that.data.alarm_id_0 : that.data.alarm_id_1;
+    other = that.setOther(other, 1);
     other.week_actives = arr;
     other.weekly_repeat = arr.filter((v) => v === 1).length > 0 ? "1" : "0";
     // 倒计时
-    if (this.data.repeatIndex === "0") {
+    if (that.data.repeatIndex === "0") {
       // 如果跨天了
       const thisTime = Math.round(new Date() / 1000);
-      if (!this.compareDate(_this.data.alarm_id_0_time, this.formatTime(thisTime, "h:m:s"))) {
-        const date = new Date((_this.formatTime(thisTime, "Y-M-D") + " 00:00:00").replace(/-/g, '/'));
-        other.current_timestamp = this.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
+      if (!that.compareDate(that.data.alarm_id_0_time, that.formatTime(thisTime, "h:m:s"))) {
+        const date = new Date((that.formatTime(thisTime, "Y-M-D") + " 00:00:00").replace(/-/g, '/'));
+        other.current_timestamp = that.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
       };
     }
     app.PubMsg({
       type: "alert_set",
-      DstDeviceName: _this.data.deviceMac,
+      DstDeviceName: that.data.deviceMac,
       other
     });
   },
+
   goWakeList() {
+    var that = this;
+    var deviceId = that.data.deviceId;
+    var clientType = that.data.clientType;
+    // var deviceMac = that.data.deviceMac;
+    ///唤醒的设置特殊,智能这样用
+    var deviceMac = `AIrSMArT_${deviceId.split(lexin_devices.leXin)[1]}`;
     wx.navigateTo({
-      url: './../wakeList/wakeList?clientType=' + this.data.clientType + "&deviceMac=" + this.data.deviceMac,
+      url: './../wakeList/wakeList?clientType=' + clientType + "&deviceMac=" + deviceMac,
     })
   },
+
   gorepeat(e) {
-    this.data.repeatIndex = e.currentTarget.dataset.index;
-    this.data.week_actives = e.currentTarget.dataset.index === "0" ? _this.data.alarm_id_0.week_actives : _this.data.alarm_id_1.week_actives;
+    var that = this;
+    that.data.repeatIndex = e.currentTarget.dataset.index;
+    that.data.week_actives = e.currentTarget.dataset.index === "0" ? that.data.alarm_id_0.week_actives : that.data.alarm_id_1.week_actives;
     wx.navigateTo({
-      url: './../repeat/repeat?week_actives=' + this.data.week_actives
+      url: './../repeat/repeat?week_actives=' + that.data.week_actives
     })
   },
+
+
   setdeviceWakedetail() {
+    var that = this;
     deviceWakedetail({
-      clientType: this.data.clientType,
-      deviceMac: this.data.deviceMac,
+      clientType: that.data.clientType,
+      deviceMac: that.data.deviceMac,
     }).then((res) => {
-      this.setData({
+      that.setData({
         wakeName: res[0].audioName
       })
     })
   },
+
   /** 
    * 时间戳转化为年 月 日 时 分 秒 
    * number: 传入时间戳 
@@ -481,8 +500,10 @@ Page({
     }
     return format;
   },
+
   // type: 0 关闭  1 开启
   setOther(other, type) {
+    var that = this;
     if (type === 0) {
       other.enable = "0";
       other.alarm_name = "close";
@@ -493,7 +514,7 @@ Page({
       other.operation = "on";
     }
     const thisTime = Math.round(new Date() / 1000);
-    other.current_timestamp = this.formatTime(thisTime, "Y-M-D h:m:s");
+    other.current_timestamp = that.formatTime(thisTime, "Y-M-D h:m:s");
     other.action = "update",
       other.song_uri = "-1";
     other.version = 3;
@@ -507,8 +528,9 @@ Page({
     var b = t2.split(":");
     return date.setHours(a[0], a[1]) > date.setHours(b[0], b[1]);
   },
-  repeatText(arr) {
 
+  repeatText(arr) {
+    var that = this;
     let text = "";
     if (arr.toString() === [0, 1, 1, 1, 1, 1, 0].toString()) {
       text = "工作日";
@@ -518,9 +540,9 @@ Page({
       arr.map((v, index) => {
         if (v === 1) {
           if (text === "") {
-            text = text + _this.data.week[index]
+            text = text + that.data.week[index]
           } else {
-            text = text + "、" + _this.data.week[index];
+            text = text + "、" + that.data.week[index];
           }
         }
       });

+ 2 - 2
pages/deviceWake/deviceWake.wxml

@@ -65,14 +65,14 @@
           <image src="./../../img/b.png" mode="heightFix"></image>
         </view>
       </view>
-      <!-- <view class="page__bd" style="opacity: {{switch2Checked ? 1 : 0.4}};">
+      <view class="page__bd" style="opacity: {{switch2Checked ? 1 : 0.4}};">
         <text>唤醒音</text>
         <view class="choice">
           <view class="mode" wx:if="{{!switch2Checked}}"></view>
           <text bindtap="goWakeList">{{wakeName}}</text>
           <image src="./../../img/b.png" mode="heightFix"></image>
         </view>
-      </view> -->
+      </view>
     </view>
   </view>
   <Toast visible="{{toast_visible}}" toast-data='{{toastData}}' twoButCallback="{{twoButCallback}}"></Toast>

+ 110 - 150
pages/wakeList/wakeList.js

@@ -1,13 +1,15 @@
-// pages/wakeList/wakeList.js
-const { deviceWakeList, deviceWakeadd, deviceWakedetail, listByDevice, pageByDevice, radioList }=require('./../../utils/api.js');
-let PreselectionIndex = null; // 记录选中的频道
-let _this = null;
 const app = getApp();
-Page({
+let PreselectionIndex = null; // 记录选中的频道
+const {
+  deviceWakeList,
+  deviceWakeadd,
+  deviceWakedetail,
+  listByDevice,
+  pageByDevice,
+  radioList
+} = require('./../../utils/api.js');
 
-  /**
-   * 页面的初始数据
-   */
+Page({
   data: {
     navBarHeight: app.globalData.navBarHeight,
     MenuButtonTop: app.globalData.MenuButtonTop,
@@ -24,22 +26,62 @@ Page({
     actionWakeIndex: null,
     deviceWake: [],
   },
-  actionWakeDetail(e){
-    this.setData({
+
+  onLoad(options) {
+    var that = this;
+    that.data.clientType = options.clientType;
+    that.data.deviceMac = options.deviceMac;
+    that.init();
+  },
+
+  init() {
+    var that = this;
+    deviceWakeList({
+      clientType: that.data.clientType,
+      deviceMac: that.data.deviceMac,
+    }).then((res) => {
+
+      listByDevice({
+        clientType: that.data.clientType
+      }).then((item) => {
+
+        const listData = [...res, ...item];
+        that.setData({
+          list: listData
+        })
+        deviceWakedetail({
+          clientType: that.data.clientType,
+          deviceMac: that.data.deviceMac,
+        }).then((data) => {
+          if (data && data.length === 0) {
+            return;
+          };
+          that.setData({
+            deviceWake: data,
+          });
+          listData.map((v, index) => {
+            if (v.wakeId === data[0].wakeId || v.channelId === data[0].channelId) {
+              that.setData({
+                actionIndex: index
+              })
+            }
+          })
+        })
+      })
+    })
+  },
+
+  actionWakeDetail(e) {
+    var that = this;
+    that.setData({
       actionWakeIndex: e.currentTarget.dataset.index,
     })
   },
+
   setWake() {
-    const index = this.data.actionWakeIndex;
-    if(_this.data.deviceWake.length > 0 && (_this.data.deviceWake[0].audioId === this.data.detailList[index].audioId)) {
-      wx.showToast({
-        title: '请不要重复设置哦!',
-        icon: "none",
-        duration: 1500
-      })
-      return;
-    }
-    if(index === null) {
+    var that = this;
+    var index = that.data.actionWakeIndex;
+    if (index === null) {
       wx.showToast({
         title: '请选择唤醒音',
         icon: "none",
@@ -47,66 +89,80 @@ Page({
       })
       return
     };
+
+    if (that.data.deviceWake.length > 0 && (that.data.deviceWake[0].audioId === that.data.detailList[index].audioId)) {
+      wx.showToast({
+        title: '请不要重复设置哦!',
+        icon: "none",
+        duration: 1500
+      });
+      return;
+    }
+
     let repData = {}
-    if(this.data.detailList[index].channelId) {
-      repData={
-        clientType: this.data.clientType,
-        deviceMac: this.data.deviceMac,
+    if (that.data.detailList[index].channelId) {
+      repData = {
+        clientType: that.data.clientType,
+        deviceMac: that.data.deviceMac,
         type: 1,
-        audioId: this.data.detailList[index].audioId,
-        audioType: this.data.detailList[index].audioType,
-        channelId: this.data.detailList[index].channelId,
+        audioId: that.data.detailList[index].audioId,
+        audioType: that.data.detailList[index].audioType,
+        channelId: that.data.detailList[index].channelId,
       }
     } else {
       repData = {
-        wakeAudioId: this.data.detailList[index].wakeAudioId,
-        clientType: this.data.clientType,
-        deviceMac: this.data.deviceMac,
+        wakeAudioId: that.data.detailList[index].wakeAudioId,
+        clientType: that.data.clientType,
+        deviceMac: that.data.deviceMac,
         type: 0,
       }
     }
-    deviceWakeadd(repData).then(()=> {
-      _this.setData({
+
+    deviceWakeadd(repData).then(() => {
+      that.setData({
         actionWakeIndex: null,
         isShowWakeDetail: false,
         actionWakeDetail: null,
         actionWakeIndex: PreselectionIndex
       });
       // 刷新页面
-      _this.init();
-      getCurrentPages().map((v)=> {
-        if(v.route === "pages/deviceWake/deviceWake") {
+      that.init();
+      getCurrentPages().map((v) => {
+        if (v.route === "pages/deviceWake/deviceWake") {
           v.setdeviceWakedetail();
         };
       })
-    })
+    });
   },
+
   clone() {
-    this.setData({
+    var that = this;
+    that.setData({
       isShowWakeDetail: false,
       actionWakeIndex: null
     })
   },
+
   actionWake(e) {
-    
-    const index = e.currentTarget.dataset.index;
-    if(this.data.list[index].channelId) {
+    var that = this;
+    var index = e.currentTarget.dataset.index;
+    if (that.data.list[index].channelId) {
       // 选择1-12频道
       pageByDevice({
-        channelId: this.data.list[index].channelId,
+        channelId: that.data.list[index].channelId,
         pageNum: 1,
         pageSize: 300
-      }).then((res)=> {
-        if(_this.data.deviceWake.length > 0) {
-          res.records.map((v, index)=> {
-            if(v.audioId === _this.data.deviceWake[0].audioId) {
-              _this.setData({
+      }).then((res) => {
+        if (that.data.deviceWake.length > 0) {
+          res.records.map((v, index) => {
+            if (v.audioId === that.data.deviceWake[0].audioId) {
+              that.setData({
                 actionWakeIndex: index
               })
             }
           });
         };
-        _this.setData({
+        that.setData({
           isShowWakeDetail: true,
           detailList: res.records
         })
@@ -114,122 +170,26 @@ Page({
     } else {
       // 官方频道
       radioList({
-        wakeId: this.data.list[index].wakeId,
+        wakeId: that.data.list[index].wakeId,
         pageNum: 1,
         pageSize: 300
-      }).then((res)=> {
-        if(_this.data.deviceWake.length > 0) {
-          res.records.map((v, index)=> {
-            if(v.audioId === _this.data.deviceWake[0].audioId) {
-              _this.setData({
+      }).then((res) => {
+        if (that.data.deviceWake.length > 0) {
+          res.records.map((v, index) => {
+            if (v.audioId === that.data.deviceWake[0].audioId) {
+              that.setData({
                 actionWakeIndex: index
               })
             }
           });
         };
-        _this.setData({
+        that.setData({
           isShowWakeDetail: true,
           detailList: res.records
         })
       })
     };
     PreselectionIndex = e.currentTarget.dataset.index;
-    
-  },
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad(options) {
-
-    _this = this;
-
-    this.data.clientType = options.clientType;
-    this.data.deviceMac = options.deviceMac;
-    
-    this.init();
-  },
-
-  init() {
-    deviceWakeList({
-      clientType: this.data.clientType,
-      deviceMac: this.data.deviceMac,
-    }).then((res)=> {
-
-      listByDevice({clientType: this.data.clientType}).then((item)=> {
-
-        const listData = [...res, ...item];
-        _this.setData({
-          list: listData
-        })
-        deviceWakedetail({
-          clientType: this.data.clientType,
-          deviceMac: this.data.deviceMac,
-        }).then((data)=> {
-          if(data && data.length === 0) {
-            return;
-          };
-          _this.setData({
-            deviceWake: data,
-          });
-          listData.map((v, index)=> {
-            if(v.wakeId === data[0].wakeId || v.channelId === data[0].channelId) {
-              this.setData({
-                actionIndex: index
-              })
-            }
-          })
-        })
-      })
-    })
-
-  },
-
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload() {
-
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
-
-  },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-
   },
 
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
-
-  }
 })

+ 4 - 3
utils/util.js

@@ -1,7 +1,7 @@
 // const { baseUrl } = require('./env.js').prod; // 正式
-const {
-  baseUrl
-} = require('./env.js').test; // 测试
+// const {
+//   baseUrl
+// } = require('./env.js').test; // 测试
 
 // token
 let Authorization = "";
@@ -68,6 +68,7 @@ function request(url, data = {}, method = "GET", header = urlencodeType, isToken
     }
   }
   // 拼接地址
+  var baseUrl = getApp().globalData.baseUrl;
   let fullurl = `${baseUrl}${url}`;
 
   //返回异步操作成功的结果和返回异步操作失败的结果