mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-18 00:45:55 +08:00
智慧宿舍系统小程序
This commit is contained in:
154
wechat/miniprogram/pages/index/index.js
Normal file
154
wechat/miniprogram/pages/index/index.js
Normal file
@@ -0,0 +1,154 @@
|
||||
// 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:[],
|
||||
fourGDeviceList:[],
|
||||
show: false,
|
||||
actions: [
|
||||
{ name: '绑定设备' },
|
||||
],
|
||||
|
||||
},
|
||||
// },
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
// this.getProducts();
|
||||
// this.query();
|
||||
// timer = setInterval(() => {
|
||||
this.getDevices();
|
||||
// }, 2000);
|
||||
},
|
||||
|
||||
|
||||
async getDevices(){
|
||||
const res = await requestApi('/system/device/list');
|
||||
console.log(res);
|
||||
this.setData({ DeviceList:res.data.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){
|
||||
if (e.currentTarget.dataset.info.categoryId !== 5) {
|
||||
return;
|
||||
}
|
||||
wx.navigateTo({
|
||||
url: '/pages/roomSystem/index',
|
||||
success:(res)=>{
|
||||
res.eventChannel.emit('getDeviceInfo',e.currentTarget.dataset.info)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
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();
|
||||
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
||||
this.getTabBar().setData({
|
||||
homeSelected:true,
|
||||
userSelected:false //这个数字是当前页面在tabBar中list数组的索引
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
clearInterval(timer);
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
this.onLoad();
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
}
|
||||
})
|
||||
7
wechat/miniprogram/pages/index/index.json
Normal file
7
wechat/miniprogram/pages/index/index.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"van-action-sheet": "@vant/weapp/action-sheet/index",
|
||||
"van-tab": "@vant/weapp/tab/index",
|
||||
"van-tabs": "@vant/weapp/tabs/index"
|
||||
}
|
||||
}
|
||||
145
wechat/miniprogram/pages/index/index.wxml
Normal file
145
wechat/miniprogram/pages/index/index.wxml
Normal file
@@ -0,0 +1,145 @@
|
||||
<!--miniprogram/pages/myDevice/index.wxml-->
|
||||
<view class='body'>
|
||||
<view class='top'>
|
||||
<view class='top_left'>
|
||||
<view class='top_big_info'>
|
||||
<text class='temperature'>{{ weather.temperature.data }}℃</text>
|
||||
<text class='city'>城市: {{ weather.city.data }}</text>
|
||||
</view>
|
||||
<view class='top_small_info'>
|
||||
<view>
|
||||
<text class='humidity'>湿度: {{ weather.humidity.data }}</text>
|
||||
<text class='weather'>天气: {{ weather.weather.data }}</text>
|
||||
</view>
|
||||
<text class='winddirection'>风向: {{ weather.winddirection.data }}</text>
|
||||
<text class='windpower'>风力: {{ weather.windpower.data }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class='top_right'>
|
||||
<view class='start'>
|
||||
<image src='/icons/start.png' />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class='devices'>
|
||||
<view class='devices_tab'>全部 ({{ DeviceList.length }})</view>
|
||||
<van-tabs swipeable animated>
|
||||
<van-tab title="WiFi设备({{ DeviceList.length }})">
|
||||
<scroll-view scroll-y>
|
||||
<view class="devices_list">
|
||||
<block wx:if="{{ DeviceList.length !== 0 }}">
|
||||
<view wx:for='{{ DeviceList }}' wx:key='index' class='border'>
|
||||
<block wx:if="{{ item.isOnline === 2 }}">
|
||||
<view class='devices_item' style="background-color:rgba(0,0,0,.05)" bindtap='deviceNone' data-info='{{item}}'>
|
||||
<view class="info">
|
||||
<view class='img'>
|
||||
<image src='/images/room.jpeg' />
|
||||
</view>
|
||||
<view class="_right">
|
||||
<view style="color:#bfbfbf" class="status">未激活</view>
|
||||
<view style="font-size:24rpx;color:#666">{{ item.categoryName }}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class='name'>{{ item.deviceName }}</view>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:if="{{ item.isOnline === 1 }}">
|
||||
<view class='devices_item' bindtap='goToDeviceControl' data-info='{{item}}'>
|
||||
<view class="info">
|
||||
<view class='img'>
|
||||
<image src='/images/room.jpeg' />
|
||||
</view>
|
||||
<view class="_right">
|
||||
<view style="color:green" class="status">在线</view>
|
||||
<view style="font-size:24rpx;color:#666">{{ item.categoryName }}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class='name'>{{ item.deviceName }}</view>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:if="{{ item.isOnline === 0 }}">
|
||||
<view style="background-color:rgba(0,0,0,.05)" class='devices_item' bindtap='deviceFail' data-info='{{item}}'>
|
||||
<view class="info">
|
||||
<view class='img'>
|
||||
<image src='/images/room.jpeg' />
|
||||
</view>
|
||||
<view class="_right">
|
||||
<view style="color:#ff0000" class="status">离线</view>
|
||||
<view style="font-size:24rpx;color:#666">{{ item.categoryName }}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class='name'>{{ item.deviceName }}</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:elif='{{ DeviceList.length === 0 }}'>
|
||||
<view class='noDevice'> 暂无设备,请添加。 </view>
|
||||
</block>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</van-tab>
|
||||
<van-tab title="4G设备({{ fourGDeviceList.length }})">
|
||||
<scroll-view scroll-y>
|
||||
<view class="devices_list">
|
||||
<block wx:if="{{ fourGDeviceList.length !== 0 }}">
|
||||
<view wx:for='{{ fourGDeviceList }}' wx:key='index' class='border'>
|
||||
<block wx:if="{{ item.status === 1 }}">
|
||||
<view class='devices_item' style="background-color:rgba(0,0,0,.05)" bindtap='deviceNone' data-info='{{item}}'>
|
||||
<view class="info">
|
||||
<view class='img'>
|
||||
<image src='/icons/device.jpg' />
|
||||
</view>
|
||||
<view class="_right">
|
||||
<view style="color:#bfbfbf" class="status">未激活</view>
|
||||
<view style="font-size:24rpx;color:#666">{{ item.device_name }}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class='name'>{{ item.product_name }}</view>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:if="{{ item.status === 2 }}">
|
||||
<view class='devices_item' bindtap='goToDeviceControl' data-info='{{item}}'>
|
||||
<view class="info">
|
||||
<view class='img'>
|
||||
<image src='/icons/device.jpg' />
|
||||
</view>
|
||||
<view class="_right">
|
||||
<view style="color:green" class="status">在线</view>
|
||||
<view style="font-size:24rpx;color:#666">{{ item.device_name }}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class='name'>{{ item.product_name }}</view>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:if="{{ item.status === 3 }}">
|
||||
<view style="background-color:rgba(0,0,0,.05)" class='devices_item' bindtap='deviceFail' data-info='{{item}}'>
|
||||
<view class="info">
|
||||
<view class='img'>
|
||||
<image src='/icons/device.jpg' />
|
||||
</view>
|
||||
<view class="_right">
|
||||
<view style="color:#ff0000" class="status">离线</view>
|
||||
<view style="font-size:24rpx;color:#666">{{ item.device_name }}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class='name'>{{ item.product_name }}</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:elif='{{ fourGDeviceList.length === 0 }}'>
|
||||
<view class='noDevice'> 暂无设备,请添加。 </view>
|
||||
</block>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</van-tab>
|
||||
</van-tabs>
|
||||
</view>
|
||||
<!-- <view class='addDevice' catchtap='isShow'>
|
||||
<image src="/images/add.png" />
|
||||
</view> -->
|
||||
<van-action-sheet class='aa' show="{{ show }}" actions="{{ actions }}"
|
||||
bind:close="onClose" bind:select="onSelect" cancel-text="取消" bind:cancel='onCancel'
|
||||
/>
|
||||
</view>
|
||||
153
wechat/miniprogram/pages/index/index.wxss
Normal file
153
wechat/miniprogram/pages/index/index.wxss
Normal file
@@ -0,0 +1,153 @@
|
||||
/* miniprogram/pages/myDevice/index.wxss */
|
||||
.top{
|
||||
display:flex;
|
||||
justify-content:space-around;
|
||||
background-color:skyblue;
|
||||
background-image: linear-gradient(to bottom right, skyblue, blue);
|
||||
padding:30rpx 0;
|
||||
border-radius:0 0 25rpx 25rpx;
|
||||
color:#ffffff;
|
||||
height:270rpx;
|
||||
}
|
||||
|
||||
.top .top_left{
|
||||
width:420rpx;
|
||||
display:flex;
|
||||
flex-direction:column;
|
||||
justify-content:center;
|
||||
}
|
||||
.top .top_left .top_big_info{
|
||||
padding:10rpx 0;
|
||||
}
|
||||
.top .top_left .top_small_info{
|
||||
padding:10rpx 20rpx;
|
||||
font-size:30rpx;
|
||||
}
|
||||
|
||||
.temperature{
|
||||
font-size:60rpx;
|
||||
display:inline-block;
|
||||
padding:0 20rpx;
|
||||
}
|
||||
.humidity::after{
|
||||
content:'|';
|
||||
width:55rpx;
|
||||
display:inline-block;
|
||||
text-align:center;
|
||||
color:rgba(255,255,255,.5);
|
||||
}
|
||||
.winddirection::after{
|
||||
content:'|';
|
||||
width:55rpx;
|
||||
display:inline-block;
|
||||
text-align:center;
|
||||
color:rgba(255,255,255,.5);
|
||||
}
|
||||
.top .top_right{
|
||||
width:250rpx;
|
||||
display:flex;
|
||||
justify-content:center;
|
||||
align-items:center;
|
||||
}
|
||||
.top .top_right .start{
|
||||
position:relative;
|
||||
width:220rpx;
|
||||
height:220rpx;
|
||||
animation:move 4s linear infinite;
|
||||
}
|
||||
@keyframes move{
|
||||
0%{ top:0rpx }
|
||||
25%{ top:-30rpx }
|
||||
50%{ top:0rpx }
|
||||
75%{ top:30rpx }
|
||||
100%{ top:0rpx }
|
||||
}
|
||||
.top .top_right .start image{
|
||||
width:100%;
|
||||
height:100%;
|
||||
}
|
||||
|
||||
.devices .devices_tab{
|
||||
font-size:36rpx;
|
||||
padding:20rpx;
|
||||
}
|
||||
.devices .devices_list{
|
||||
padding:10rpx 0;
|
||||
display:flex;
|
||||
flex-wrap:wrap;
|
||||
}
|
||||
.devices .devices_list .border{
|
||||
width:50%;
|
||||
display:flex;
|
||||
justify-content:center;
|
||||
}
|
||||
.devices .devices_list .devices_item{
|
||||
width:280rpx;
|
||||
height:200rpx;
|
||||
margin:30rpx 20rpx;
|
||||
border-radius:10rpx;
|
||||
display:flex;
|
||||
flex-direction:column;
|
||||
justify-content:center;
|
||||
box-shadow:0rpx 5rpx 10rpx #bfbfbf;
|
||||
}
|
||||
.info{
|
||||
flex: 3;
|
||||
display: flex;
|
||||
}
|
||||
.status{
|
||||
padding: 15rpx;
|
||||
text-align: right;
|
||||
flex: 1;
|
||||
}
|
||||
.devices .devices_list .devices_item:active{
|
||||
background-color:rgba(0,0,0,.1);
|
||||
}
|
||||
.devices .devices_list .devices_item .img{
|
||||
width:50%;
|
||||
display:flex;
|
||||
justify-content:center;
|
||||
align-items:center;
|
||||
}
|
||||
.devices .devices_list .devices_item image{
|
||||
width:100rpx;
|
||||
height:100rpx;
|
||||
}
|
||||
.devices .devices_list .devices_item .name{
|
||||
flex:2;
|
||||
padding:0 20rpx;
|
||||
/* background-color:rgba(0,0,0,.1); */
|
||||
border-top:1rpx solid #bfbfbf;
|
||||
display:flex;
|
||||
align-items:center;
|
||||
}
|
||||
.noDevice{
|
||||
display:block;
|
||||
width:100%;
|
||||
height:200rpx;
|
||||
text-align:center;
|
||||
line-height:200rpx;
|
||||
}
|
||||
.addDevice{
|
||||
background-color:blue;
|
||||
width:80rpx;
|
||||
height:80rpx;
|
||||
border-radius:50%;
|
||||
position:fixed;
|
||||
right:0;
|
||||
top:30%;
|
||||
display:flex;
|
||||
justify-content:center;
|
||||
align-items:center;
|
||||
}
|
||||
.addDevice:active{
|
||||
background-color:deepskyblue;
|
||||
}
|
||||
.addDevice image{
|
||||
width:40rpx;
|
||||
height:40rpx;
|
||||
}
|
||||
scroll-view{
|
||||
height: 60vh;
|
||||
width: 100vw;
|
||||
}
|
||||
107
wechat/miniprogram/pages/login/index.js
Normal file
107
wechat/miniprogram/pages/login/index.js
Normal file
@@ -0,0 +1,107 @@
|
||||
// miniprogram/pages/index/index.js
|
||||
const { loginApi } = require('../../API/request.js');
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
value:'',
|
||||
img:'',
|
||||
uuid:'',
|
||||
password:'admin123',
|
||||
username:'admin'
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
this.getCaptchaImage();
|
||||
},
|
||||
|
||||
//获取验证码图片和uuid
|
||||
async getCaptchaImage(){
|
||||
const res = await loginApi('/captchaImage',{ method:'GET' });
|
||||
this.setData({
|
||||
img:res.data.img,
|
||||
uuid:res.data.uuid
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
//登录
|
||||
async submit(){
|
||||
const res = await loginApi('/login',{
|
||||
method:'POST',
|
||||
data:{
|
||||
code:this.data.value,
|
||||
uuid:this.data.uuid,
|
||||
password: this.data.password,
|
||||
username: this.data.username
|
||||
},
|
||||
})
|
||||
wx.setStorageSync('token', res.data.token);
|
||||
},
|
||||
|
||||
|
||||
inputUsername(e){
|
||||
this.setData({ username:e.detail });
|
||||
},
|
||||
inputPassword(e){
|
||||
this.setData({ password:e.detail });
|
||||
},
|
||||
onChange(e){
|
||||
this.setData({ value:e.detail });
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
}
|
||||
})
|
||||
5
wechat/miniprogram/pages/login/index.json
Normal file
5
wechat/miniprogram/pages/login/index.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"van-field": "@vant/weapp/field/index"
|
||||
}
|
||||
}
|
||||
41
wechat/miniprogram/pages/login/index.wxml
Normal file
41
wechat/miniprogram/pages/login/index.wxml
Normal file
@@ -0,0 +1,41 @@
|
||||
<!--miniprogram/pages/index/index.wxml-->
|
||||
<view class="form">
|
||||
<view class="input">
|
||||
<van-field
|
||||
value="{{ username }}"
|
||||
placeholder="请输入用户名"
|
||||
bind:change="inputUsername"
|
||||
label='用户名'
|
||||
title-width='100rpx'
|
||||
/>
|
||||
</view>
|
||||
<view class="input">
|
||||
<van-field
|
||||
value="{{ password }}"
|
||||
placeholder="请输入密码"
|
||||
bind:change="inputPassword"
|
||||
label='密码'
|
||||
title-width='100rpx'
|
||||
right-icon=''
|
||||
/>
|
||||
</view>
|
||||
<view class="cap">
|
||||
<view class="captcha">
|
||||
<van-field
|
||||
value="{{ value }}"
|
||||
placeholder="请输入计算结果"
|
||||
border="{{ false }}"
|
||||
bind:change="onChange"
|
||||
label='验证码'
|
||||
title-width='100rpx'
|
||||
/>
|
||||
</view>
|
||||
<view class="img" bindtap="getCaptchaImage">
|
||||
<image src='data:image/gif;base64,{{ img }}' />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
<button bindtap="submit">提交</button>
|
||||
<button bindtap="query">查询</button>
|
||||
33
wechat/miniprogram/pages/login/index.wxss
Normal file
33
wechat/miniprogram/pages/login/index.wxss
Normal file
@@ -0,0 +1,33 @@
|
||||
/* miniprogram/pages/index/index.wxss */
|
||||
.form{
|
||||
width: 90vw;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.input{
|
||||
margin: 15rpx 0;
|
||||
/* box-shadow: 0 0 5rpx 5rpx #bfbfbf; */
|
||||
border-bottom: 1rpx solid #bfbfbf;
|
||||
}
|
||||
.cap{
|
||||
display: flex;
|
||||
width: 100%;
|
||||
}
|
||||
.captcha{
|
||||
flex: 1;
|
||||
margin-right: 30rpx;
|
||||
/* box-shadow: 0 0 5rpx 5rpx #bfbfbf; */
|
||||
border-bottom: 1rpx solid #bfbfbf;
|
||||
|
||||
}
|
||||
.img{
|
||||
/* box-shadow: 0 0 5rpx 5rpx #bfbfbf; */
|
||||
border-bottom: 1rpx solid #bfbfbf;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.img image{
|
||||
width: 200rpx;
|
||||
display: inline-block;
|
||||
height: 77rpx;
|
||||
}
|
||||
232
wechat/miniprogram/pages/roomSystem/index.js
Normal file
232
wechat/miniprogram/pages/roomSystem/index.js
Normal file
@@ -0,0 +1,232 @@
|
||||
// miniprogram/pages/roomSystem/index.js
|
||||
const { requestApi } = require('../../API/request.js');
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
light_power:false,
|
||||
gradientColor: {
|
||||
'0%': '#ffd01e',
|
||||
'100%': '#ee0a24',
|
||||
},
|
||||
curtainShow:false,
|
||||
curtainAutoChecked:true,
|
||||
curtainManvalChecked:false,
|
||||
curtainPowerChecked:false,
|
||||
fanShow:false,
|
||||
tempShow:false,
|
||||
realMaxTempValue:50,
|
||||
maxTempValue:0,
|
||||
currentValue:0,
|
||||
deviceInfo:{},
|
||||
nowDeviceData:{}
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
wx.setNavigationBarTitle({
|
||||
title: '智能宿舍系统',
|
||||
})
|
||||
this.setData({
|
||||
currentValue:this.data.realMaxTempValue,
|
||||
maxTempValue:this.data.realMaxTempValue
|
||||
});
|
||||
|
||||
this.getLastPageData();
|
||||
this.query();
|
||||
},
|
||||
|
||||
|
||||
//查询设备最新数据
|
||||
async query(){
|
||||
const res = await requestApi(`/system/status/newByNum/${this.data.deviceInfo.deviceNum}`,{ method:'GET' });
|
||||
let light_power;
|
||||
if (res.data.data.lightStatus === 0) {
|
||||
light_power = false;
|
||||
}else if (res.data.data.lightStatus === 1) {
|
||||
light_power =true;
|
||||
}
|
||||
this.setData({
|
||||
nowDeviceData:res.data.data,
|
||||
light_power
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
getLastPageData(){
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
eventChannel.on('getDeviceInfo',(data)=>{
|
||||
this.setData({ deviceInfo:data })
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
initParams(){
|
||||
// const params = {
|
||||
// deviceNum: this.data.deviceInfo.deviceNum,
|
||||
// relayStatus: this.data.nowDeviceData.relayStatus,
|
||||
// lightStatus: this.data.nowDeviceData.lightStatus,
|
||||
// isOnline: this.data.nowDeviceData.isOnline,
|
||||
// rssi: this.data.nowDeviceData.rssi,
|
||||
// deviceTemperature: this.data.nowDeviceData.deviceTemperature,
|
||||
// airTemperature: this.data.nowDeviceData.airTemperature,
|
||||
// airHumidity: this.data.nowDeviceData.airHumidity,
|
||||
// triggerSource: this.data.nowDeviceData.triggerSource,
|
||||
// brightness: this.data.nowDeviceData.brightness,
|
||||
// lightInterval: this.data.nowDeviceData.lightInterval,
|
||||
// lightMode: this.data.nowDeviceData.lightMode,
|
||||
// fadeTime: this.data.nowDeviceData.fadeTime,
|
||||
// red: this.data.nowDeviceData.red,
|
||||
// green: this.data.nowDeviceData.green,
|
||||
// blue: this.data.nowDeviceData.blue,
|
||||
// other:this.data.nowDeviceData.other
|
||||
// };
|
||||
const params = this.data.nowDeviceData;
|
||||
return params;
|
||||
},
|
||||
|
||||
async lightPower(){
|
||||
let light_power = this.data.light_power;
|
||||
let lightStatus;
|
||||
if (light_power === false) {
|
||||
lightStatus = 1;
|
||||
}else if (light_power === true) {
|
||||
lightStatus = 0;
|
||||
}
|
||||
let params = this.initParams();
|
||||
params.lightStatus = lightStatus;
|
||||
const res = await requestApi(`/system/status`,{
|
||||
method:'PUT',
|
||||
data:params
|
||||
});
|
||||
console.log('lightres:',res);
|
||||
if (res.data.code !== 200) {
|
||||
wx.showToast({
|
||||
title: '操作失败',
|
||||
icon:'error'
|
||||
})
|
||||
return;
|
||||
}
|
||||
this.setData({ light_power:!light_power });
|
||||
},
|
||||
|
||||
showCurtain(){
|
||||
this.setData({
|
||||
curtainShow:true
|
||||
})
|
||||
},
|
||||
|
||||
onAutoCurtainMode(){
|
||||
let curtainAutoChecked = !this.data.curtainAutoChecked;
|
||||
this.setData({
|
||||
curtainAutoChecked:curtainAutoChecked,
|
||||
curtainManvalChecked:!curtainAutoChecked
|
||||
})
|
||||
},
|
||||
onManvalCurtainMode(){
|
||||
let curtainManvalChecked = !this.data.curtainManvalChecked;
|
||||
this.setData({
|
||||
curtainAutoChecked:!curtainManvalChecked,
|
||||
curtainManvalChecked:curtainManvalChecked
|
||||
})
|
||||
},
|
||||
onChangeCurtainPower(){
|
||||
let curtainPowerChecked = this.data.curtainPowerChecked;
|
||||
if (this.data.curtainManvalChecked) {
|
||||
this.setData({ curtainPowerChecked:!curtainPowerChecked })
|
||||
}
|
||||
},
|
||||
|
||||
showFan(){
|
||||
this.setData({
|
||||
fanShow:true
|
||||
})
|
||||
},
|
||||
showTemp(){
|
||||
this.setData({
|
||||
tempShow:true
|
||||
})
|
||||
},
|
||||
onChangeValue(e){
|
||||
this.setData({ maxTempValue:e.detail,currentValue:e.detail })
|
||||
},
|
||||
onDrag(e){
|
||||
this.setData({ currentValue:e.detail.value })
|
||||
},
|
||||
onCancel(){
|
||||
this.setData({
|
||||
maxTempValue:this.data.realMaxTempValue,
|
||||
currentValue:this.data.realMaxTempValue,
|
||||
tempShow:false
|
||||
})
|
||||
},
|
||||
onMakeSure(){
|
||||
this.setData({
|
||||
realMaxTempValue:this.data.maxTempValue,
|
||||
tempShow:false
|
||||
})
|
||||
},
|
||||
onClose(){
|
||||
this.setData({
|
||||
curtainShow:false,
|
||||
fanShow:false
|
||||
})
|
||||
this.onCancel();
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
}
|
||||
})
|
||||
11
wechat/miniprogram/pages/roomSystem/index.json
Normal file
11
wechat/miniprogram/pages/roomSystem/index.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"van-circle": "@vant/weapp/circle/index",
|
||||
"van-popup": "@vant/weapp/popup/index",
|
||||
"van-cell": "@vant/weapp/cell/index",
|
||||
"van-cell-group": "@vant/weapp/cell-group/index",
|
||||
"van-switch": "@vant/weapp/switch/index",
|
||||
"van-slider": "@vant/weapp/slider/index",
|
||||
"van-button": "@vant/weapp/button/index"
|
||||
}
|
||||
}
|
||||
92
wechat/miniprogram/pages/roomSystem/index.wxml
Normal file
92
wechat/miniprogram/pages/roomSystem/index.wxml
Normal file
@@ -0,0 +1,92 @@
|
||||
<!--miniprogram/pages/roomSystem/index.wxml-->
|
||||
<view class='body'>
|
||||
<view class='top'>
|
||||
<view class='around center power'>
|
||||
<view class='power_light center' bindtap='lightPower' style='{{ light_power?"box-shadow:0 0 50rpx 20rpx #0023ff":"" }}'>
|
||||
<image src='{{ light_power?"/images/power_on.png":"/images/power_off.png" }}' />
|
||||
</view>
|
||||
</view>
|
||||
<view class='TH around center'>
|
||||
<van-circle value="{{ nowDeviceData.airTemperature }}" color="{{ gradientColor }}" stroke-width="8" size="165" >
|
||||
<slots>
|
||||
<view class='temp_text'>温度:{{ nowDeviceData.deviceTemperature }} ℃</view>
|
||||
<view class='humi_text'>湿度:{{ nowDeviceData.airHumidity }}%</view>
|
||||
</slots>
|
||||
</van-circle>
|
||||
</view>
|
||||
</view>
|
||||
<view class='group'>
|
||||
<view class='curtain item'>
|
||||
<van-cell title="窗帘" value="{{ curtainAutoChecked?'自动':'手动' }}" size='large'
|
||||
icon='/images/curtain.png' is-link bindtap='showCurtain'
|
||||
border="{{ true }}" />
|
||||
</view>
|
||||
<view class='fan item'>
|
||||
<van-cell title="风扇" size='large' value="自动"
|
||||
icon='/images/fan.png' is-link border="{{ true }}" bindtap='showFan' />
|
||||
</view>
|
||||
<view class='temp item'>
|
||||
<van-cell title="温度最大值" size='large' value="{{ realMaxTempValue }}℃"
|
||||
icon='/images/temp.png'is-link border="{{ true }}" bindtap='showTemp' />
|
||||
</view>
|
||||
</view>
|
||||
<van-popup show="{{ curtainShow }}" round position="bottom" bind:close="onClose">
|
||||
<view class='choose'>
|
||||
<van-cell size='large' title="自动模式">
|
||||
<view slots='value'>
|
||||
<van-switch checked="{{ curtainAutoChecked }}" bind:change="onAutoCurtainMode" />
|
||||
</view>
|
||||
</van-cell>
|
||||
</view>
|
||||
<view class='choose'>
|
||||
<van-cell size='large' title="手动模式">
|
||||
<view slots='value'>
|
||||
<van-switch checked="{{ curtainManvalChecked }}" bind:change="onManvalCurtainMode" />
|
||||
</view>
|
||||
</van-cell>
|
||||
</view>
|
||||
<block wx:if='{{ curtainManvalChecked }}'>
|
||||
<view class='curtain_power'>
|
||||
<van-cell title="窗帘开关" title-style='color:blue;'>
|
||||
<view slots='value'>
|
||||
<van-switch checked="{{ curtainManvalChecked && curtainPowerChecked }}" bind:change="onChangeCurtainPower" />
|
||||
</view>
|
||||
</van-cell>
|
||||
</view>
|
||||
</block>
|
||||
</van-popup>
|
||||
<van-popup show="{{ fanShow }}" round custom-style="height: 30%;" position="bottom" bind:close="onClose">
|
||||
<view class='choose'>
|
||||
<van-cell size='large' title="自动模式">
|
||||
<view slots='value'>
|
||||
<van-switch checked="{{ checked }}" bind:change="onChange" />
|
||||
</view>
|
||||
</van-cell>
|
||||
</view>
|
||||
<view class='choose'>
|
||||
<van-cell size='large' title="手动模式">
|
||||
<view slots='value'>
|
||||
<van-switch checked="{{ checked }}" bind:change="onChange" />
|
||||
</view>
|
||||
</van-cell>
|
||||
</view>
|
||||
<view class='curtain_power'>
|
||||
<van-cell title="风扇开关">
|
||||
<view slots='value'>
|
||||
<van-switch checked="{{ checked }}" bind:change="onChange" />
|
||||
</view>
|
||||
</van-cell>
|
||||
</view>
|
||||
</van-popup>
|
||||
<van-popup show="{{ tempShow }}" round position="bottom" bind:close="onClose">
|
||||
<view class='tempZu'>设置温度最大值:{{ maxTempValue }}℃</view>
|
||||
<view class='tempZu'>滑块当前值:{{ currentValue }}</view>
|
||||
<view class='slider tempZu'>
|
||||
<van-slider value="{{ maxTempValue }}" bind:change="onChangeValue" bind:drag='onDrag' />
|
||||
</view>
|
||||
<view class='tempZu btns'>
|
||||
<van-button round color='#bfbfbf' bindtap='onCancel' block>取 消</van-button>
|
||||
<van-button round type="info" bindtap='onMakeSure' block>确 定</van-button>
|
||||
</view>
|
||||
</van-popup>
|
||||
</view>
|
||||
63
wechat/miniprogram/pages/roomSystem/index.wxss
Normal file
63
wechat/miniprogram/pages/roomSystem/index.wxss
Normal file
@@ -0,0 +1,63 @@
|
||||
/* miniprogram/pages/roomSystem/index.wxss */
|
||||
.center{
|
||||
display:flex;
|
||||
justify-content:center;
|
||||
align-items:center;
|
||||
}
|
||||
.top{
|
||||
display:flex;
|
||||
justify-content:space-around;
|
||||
margin:100rpx 0;
|
||||
}
|
||||
.power{
|
||||
background-color:#bfbfbf;
|
||||
}
|
||||
.around{
|
||||
width:300rpx;
|
||||
height:300rpx;
|
||||
border-radius:50%;
|
||||
}
|
||||
.power_light:active{
|
||||
background-color:#eee;
|
||||
}
|
||||
.power_light{
|
||||
width:230rpx;
|
||||
height:230rpx;
|
||||
border-radius:50%;
|
||||
background-color:#fff;
|
||||
}
|
||||
.power_light>image{
|
||||
width:70rpx;
|
||||
height:70rpx;
|
||||
border-radius:50%;
|
||||
}
|
||||
.temp_text{
|
||||
font-size:46rpx;
|
||||
margin:15rpx 0;
|
||||
}
|
||||
|
||||
.group{
|
||||
width:90%;
|
||||
margin:30rpx auto;
|
||||
}
|
||||
.item{
|
||||
margin:25rpx 0;
|
||||
width:100%;
|
||||
}
|
||||
.choose{
|
||||
margin:15rpx 0;
|
||||
}
|
||||
.tempZu{
|
||||
width:80%;
|
||||
margin:35rpx auto;
|
||||
}
|
||||
.slider{
|
||||
margin:70rpx auto;
|
||||
}
|
||||
.btns{
|
||||
display:flex;
|
||||
justify-content:space-around;
|
||||
}
|
||||
van-button{
|
||||
width:200rpx;
|
||||
}
|
||||
Reference in New Issue
Block a user