|
@@ -1,10 +1,14 @@
|
|
|
// 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');
|
|
|
let _this = null;
|
|
|
const interval = null;
|
|
|
+// import routeUtil from '../../utils/route_util.js'
|
|
|
+import routeUtil from '../../utils/route_util'
|
|
|
+import route_constant from '../../utils/route_constant.js'
|
|
|
+
|
|
|
Page({
|
|
|
data: {
|
|
|
navBarHeight: app.globalData.navBarHeight,
|
|
@@ -12,7 +16,7 @@ Page({
|
|
|
MenuButtonTop: app.globalData.MenuButtonTop,
|
|
|
actionIndex: null,
|
|
|
isShowDevicelist: false,
|
|
|
- luoma: ["Ⅰ","Ⅱ","Ⅲ","Ⅳ","Ⅴ","Ⅵ"," Ⅶ","Ⅷ","Ⅸ","Ⅹ","Ⅺ","Ⅻ"],
|
|
|
+ luoma: ["Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", " Ⅶ", "Ⅷ", "Ⅸ", "Ⅹ", "Ⅺ", "Ⅻ"],
|
|
|
channelData: [],
|
|
|
deviceList: [],
|
|
|
deviceListIndex: null,
|
|
@@ -26,12 +30,12 @@ Page({
|
|
|
newVersion: false,
|
|
|
},
|
|
|
onShow() {
|
|
|
- if((!this.data.isOneLoading)) {
|
|
|
+ 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({
|
|
@@ -39,10 +43,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);
|
|
|
}
|
|
@@ -71,10 +75,10 @@ Page({
|
|
|
wx.showLoading({
|
|
|
title: '加载中',
|
|
|
});
|
|
|
-
|
|
|
- const str = setTimeout(()=> {
|
|
|
+
|
|
|
+ const str = setTimeout(() => {
|
|
|
clearTimeout(str);
|
|
|
- if(_this.data.isOneLoading) {
|
|
|
+ if (_this.data.isOneLoading) {
|
|
|
_this.setData({
|
|
|
isOneLoading: false,
|
|
|
});
|
|
@@ -84,7 +88,7 @@ Page({
|
|
|
// 获取缓存的频道数据
|
|
|
wx.getStorage({
|
|
|
key: "channelData",
|
|
|
- success(res){
|
|
|
+ success(res) {
|
|
|
_this.setData({
|
|
|
channelData: res.data
|
|
|
})
|
|
@@ -108,7 +112,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({
|
|
@@ -116,7 +120,7 @@ Page({
|
|
|
data: res
|
|
|
});
|
|
|
// 需要用授权登录
|
|
|
- if((res.isNewUser && res.isNewUser === true) || !phone) {
|
|
|
+ if ((res.isNewUser && res.isNewUser === true) || !phone) {
|
|
|
_this.setData({
|
|
|
showLogin: true,
|
|
|
});
|
|
@@ -129,7 +133,7 @@ Page({
|
|
|
showLogin: false,
|
|
|
});
|
|
|
wx.setStorage({
|
|
|
- key:"token",
|
|
|
+ key: "token",
|
|
|
data: JSON.stringify({
|
|
|
id: res.userId,
|
|
|
token: res.accessToken,
|
|
@@ -143,17 +147,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,
|
|
@@ -162,7 +166,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);
|
|
@@ -179,7 +183,7 @@ Page({
|
|
|
// }
|
|
|
}
|
|
|
},
|
|
|
- fail(e){
|
|
|
+ fail(e) {
|
|
|
wx.hideLoading();
|
|
|
}
|
|
|
});
|
|
@@ -187,10 +191,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;
|
|
@@ -199,28 +203,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);
|
|
|
// 电量
|
|
@@ -231,31 +235,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),
|
|
|
})
|
|
@@ -268,17 +272,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
|
|
@@ -289,8 +293,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;
|
|
|
}
|
|
|
});
|
|
@@ -299,15 +303,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);
|
|
|
}
|
|
@@ -316,11 +320,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,
|
|
@@ -328,24 +332,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`;
|
|
@@ -353,19 +357,20 @@ 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"
|
|
@@ -375,7 +380,7 @@ Page({
|
|
|
this.setData({
|
|
|
actionIndex: e.currentTarget.dataset.index
|
|
|
});
|
|
|
- const other= {
|
|
|
+ const other = {
|
|
|
"url": "",
|
|
|
"media_data": "",
|
|
|
"user_id": `${app.globalData.userInfo.deviceUid}`,
|
|
@@ -383,8 +388,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({
|
|
@@ -393,8 +398,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)
|
|
@@ -402,11 +407,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`);
|
|
|
};
|
|
|
|
|
@@ -430,6 +435,9 @@ Page({
|
|
|
});
|
|
|
},
|
|
|
goDeviceConnect() {
|
|
|
+ // routeUtil.jump(route_constant.deviceList)
|
|
|
+
|
|
|
+ // return;
|
|
|
wx.navigateTo({
|
|
|
url: './../deviceConnect0/deviceConnect0',
|
|
|
});
|
|
@@ -438,11 +446,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
|
|
|
});
|
|
@@ -450,14 +458,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;
|
|
|
// 去掉此功能,先留着吧
|
|
@@ -494,24 +502,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,
|
|
@@ -520,17 +528,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({
|
|
@@ -539,8 +547,8 @@ Page({
|
|
|
});
|
|
|
};
|
|
|
} else {
|
|
|
- deviceList.map((v, index)=> {
|
|
|
- if(v.name === name) {
|
|
|
+ deviceList.map((v, index) => {
|
|
|
+ if (v.name === name) {
|
|
|
_this.setData({
|
|
|
deviceListIndex: index,
|
|
|
});
|
|
@@ -549,30 +557,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()
|
|
|
},
|
|
@@ -582,7 +590,7 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
onUnload() {
|
|
|
- if(app.globalData.client === null) {
|
|
|
+ if (app.globalData.client === null) {
|
|
|
return;
|
|
|
};
|
|
|
app.globalData.client.end(true);
|