mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-17 16:36:03 +08:00
195 lines
3.7 KiB
JavaScript
195 lines
3.7 KiB
JavaScript
// miniprogram/pages/index/index.js
|
|
const amap = require('../../libs/amap-wx.js');
|
|
const { requestApi } = require('../../API/request.js');
|
|
const app = getApp();
|
|
const project_id = 'wHJB7a';
|
|
var timer;
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
weather:{}, //天气信息
|
|
products:[],
|
|
DeviceList:[],
|
|
onlineList:[],
|
|
unlineList:[],
|
|
fourGDeviceList:[],
|
|
show: false,
|
|
actions: [
|
|
{ name: '绑定设备' },
|
|
],
|
|
|
|
},
|
|
// },
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
// timer = setInterval(() => {
|
|
this.getDevices();
|
|
// }, 2000);
|
|
},
|
|
|
|
//获取设备列表
|
|
async getDevices(){
|
|
wx.showLoading({
|
|
title: '获取设备',
|
|
mask: true
|
|
})
|
|
const res = await requestApi('/system/device/list',{ method:'GET' });
|
|
wx.hideLoading();
|
|
const result = JSON.parse(res.result);
|
|
if (result.code !== 200) {
|
|
wx.showToast({
|
|
title: '请求失败',
|
|
icon:'error'
|
|
});
|
|
return;
|
|
}
|
|
wx.showToast({
|
|
title: '请求成功',
|
|
});
|
|
let onlineList = [];
|
|
let unlineList = [];
|
|
result.rows.forEach(v=>{
|
|
if (v.isOnline == 1) {
|
|
onlineList.push(v)
|
|
} else if (v.isOnline == 0) {
|
|
unlineList.push(v);
|
|
}
|
|
})
|
|
this.setData({
|
|
onlineList,
|
|
unlineList,
|
|
DeviceList:result.rows
|
|
})
|
|
},
|
|
|
|
|
|
//获取天气
|
|
getWeather:async function(){
|
|
let that = this;
|
|
var myAmapFun = new amap.AMapWX({key:'5cafa1133f593cfe005081749a46e717'});
|
|
myAmapFun.getWeather({
|
|
success: function(data){
|
|
console.log(data);
|
|
that.setData({
|
|
weather:data
|
|
})
|
|
},
|
|
fail: function(info){
|
|
//失败回调
|
|
console.log(info)
|
|
}
|
|
})
|
|
},
|
|
|
|
goToDeviceControl(e){
|
|
|
|
switch (e.currentTarget.dataset.info.categoryId) {
|
|
case 1:
|
|
wx.navigateTo({
|
|
url: '/pages/4Gswitch/index',
|
|
success:(res)=>{
|
|
res.eventChannel.emit('getDeviceInfo',e.currentTarget.dataset.info)
|
|
}
|
|
})
|
|
break;
|
|
case 4:
|
|
wx.navigateTo({
|
|
url: '/pages/someData/index',
|
|
success:(res)=>{
|
|
res.eventChannel.emit('getDeviceInfo',e.currentTarget.dataset.info)
|
|
}
|
|
})
|
|
break;
|
|
|
|
case 5:
|
|
wx.navigateTo({
|
|
url: '/pages/roomSystem/index',
|
|
success:(res)=>{
|
|
res.eventChannel.emit('getDeviceInfo',e.currentTarget.dataset.info)
|
|
}
|
|
})
|
|
break;
|
|
}
|
|
},
|
|
|
|
deviceFail(){
|
|
wx.showToast({
|
|
title: '设备离线!',
|
|
icon:'error'
|
|
})
|
|
},
|
|
deviceNone(){
|
|
wx.showToast({
|
|
title: '设备未激活!',
|
|
icon:'error'
|
|
})
|
|
},
|
|
|
|
//底部弹起的模态面板
|
|
isShow:function(){
|
|
this.setData({
|
|
show:!this.data.show
|
|
})
|
|
},
|
|
onClose:function() {
|
|
this.setData({ show: false });
|
|
},
|
|
onCancel:function(){
|
|
this.setData({ show: false });
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
this.getWeather();
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
clearInterval(timer);
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
this.onLoad();
|
|
wx.stopPullDownRefresh();
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |