添加控制功能和页面逻辑

This commit is contained in:
qianlile
2021-07-29 11:11:14 +08:00
parent 2096a6e755
commit 7c061bbb9b
14 changed files with 265 additions and 49 deletions

View File

@@ -1,8 +1,9 @@
{ {
"pages": [ "pages": [
"pages/index/index",
"pages/login/index", "pages/login/index",
"pages/roomSystem/index" "pages/index/index",
"pages/roomSystem/index",
"pages/my/index"
], ],
"window": { "window": {
"backgroundColor": "#F6F6F6", "backgroundColor": "#F6F6F6",
@@ -11,6 +12,20 @@
"navigationBarTitleText": "智慧宿舍", "navigationBarTitleText": "智慧宿舍",
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black"
}, },
"tabBar": {
"list": [{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "icons/home.png",
"selectedIconPath": "icons/home_selected.png"
},
{
"pagePath": "pages/my/index",
"text": "我的",
"iconPath": "icons/user.png",
"selectedIconPath": "icons/user_selected.png"
}]
},
"sitemapLocation": "sitemap.json", "sitemapLocation": "sitemap.json",
"permission": { "permission": {
"scope.userLocation": { "scope.userLocation": {

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@@ -42,7 +42,16 @@ Page({
username: this.data.username username: this.data.username
}, },
}) })
if (res.data.code !== 200) {
wx.showToast({
title: '登录失败',
});
return;
}
wx.setStorageSync('token', res.data.token); wx.setStorageSync('token', res.data.token);
wx.switchTab({
url: '/pages/index/index',
})
}, },

View File

@@ -1,5 +1,6 @@
{ {
"usingComponents": { "usingComponents": {
"van-field": "@vant/weapp/field/index" "van-field": "@vant/weapp/field/index",
"van-button": "@vant/weapp/button/index"
} }
} }

View File

@@ -1,4 +1,5 @@
<!--miniprogram/pages/index/index.wxml--> <!--miniprogram/pages/index/index.wxml-->
<view class="title">欢迎登录智慧宿舍系统</view>
<view class="form"> <view class="form">
<view class="input"> <view class="input">
<van-field <van-field
@@ -14,6 +15,7 @@
value="{{ password }}" value="{{ password }}"
placeholder="请输入密码" placeholder="请输入密码"
bind:change="inputPassword" bind:change="inputPassword"
type='password'
label='密码' label='密码'
title-width='100rpx' title-width='100rpx'
right-icon='' right-icon=''
@@ -34,8 +36,9 @@
<image src='data:image/gif;base64,{{ img }}' /> <image src='data:image/gif;base64,{{ img }}' />
</view> </view>
</view> </view>
<view class="btn">
<van-button block bind:click="submit" round type="info">登录</van-button>
</view>
</view> </view>
<button bindtap="submit">提交</button>
<button bindtap="query">查询</button>

View File

@@ -1,6 +1,13 @@
/* miniprogram/pages/index/index.wxss */ /* miniprogram/pages/index/index.wxss */
.title{
display: block;
width: 80vw;
margin: 60rpx auto;
font-size: 40rpx;
margin-top: 35%;
}
.form{ .form{
width: 90vw; width: 80vw;
margin: 0 auto; margin: 0 auto;
} }
.input{ .input{
@@ -31,3 +38,7 @@
display: inline-block; display: inline-block;
height: 77rpx; height: 77rpx;
} }
.btn{
margin: 45rpx auto;
width: 40vw;
}

View File

@@ -0,0 +1,19 @@
var app = getApp();
Page({
data: {
userInfo: {},
mode: ['信息反馈', '联系客服', '关于我们']
},
onLoad: function () {
},
getOut(){
wx.clearStorage({
success: (res) => {
wx.reLaunch({
url: '/pages/login/index',
})
},
})
}
})

View File

@@ -0,0 +1,3 @@
{
"usingComponents": {}
}

View File

@@ -0,0 +1,16 @@
<!--miniprogram/pages/my/index.wxml-->
<view class="personal_info">
<view class="photo_wrap">
<open-data type="userAvatarUrl"></open-data>
</view>
<view class="nickname">
<open-data type="userNickName"></open-data>
</view>
</view>
<view class="wode_item_wrap">
<view class="wode_item" wx:for="{{mode}}">
{{item}}
<span class="arrow_wrap"></span>
</view>
</view>
<view class="wode_out" bindtap="getOut">退出</view>

View File

@@ -0,0 +1,54 @@
.personal_info {
padding: 20px 0;
background-color: #FFF;
}
.photo_wrap {
overflow:hidden;
display: block;
width: 160rpx;
height: 160rpx;
margin: auto;
margin-top: 50rpx;
border-radius: 50%;
border: 2px solid #fff;
box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.2);
}
.photo {
width: 90px;
height: 90px;
border-radius: 90px;
}
.nickname {
margin-top: 15px;
text-align: center;
color: #696969;
}
.wode_item_wrap {
background-color: #FFF;
font-size: 14px;
margin-top: 10px;
border-top: 1px solid #E5E5E5;
}
.wode_item {
height: 45px;
border-bottom: 1px solid #E5E5E5;
padding: 0 10px;
line-height: 45px;
position: relative;
}
.arrow_wrap {
position: absolute;
width: 50px;
height: 45px;
right: 0;
top: 0;
}
.wode_out {
height: 45px;
line-height: 45px;
text-align: center;
background-color: #FFF;
margin-top: 10px;
border-bottom: 1px solid #E5E5E5;
border-top: 1px solid #E5E5E5;
}

View File

@@ -16,9 +16,12 @@ Page({
curtainAutoChecked:true, curtainAutoChecked:true,
curtainManvalChecked:false, curtainManvalChecked:false,
curtainPowerChecked:false, curtainPowerChecked:false,
fanAutoChecked:true,
fanManvalChecked:false,
fanPowerChecked:false,
fanShow:false, fanShow:false,
tempShow:false, tempShow:false,
realMaxTempValue:50, realMaxTempValue:'',
maxTempValue:0, maxTempValue:0,
currentValue:0, currentValue:0,
deviceInfo:{}, deviceInfo:{},
@@ -32,11 +35,6 @@ Page({
wx.setNavigationBarTitle({ wx.setNavigationBarTitle({
title: '智能宿舍系统', title: '智能宿舍系统',
}) })
this.setData({
currentValue:this.data.realMaxTempValue,
maxTempValue:this.data.realMaxTempValue
});
this.getLastPageData(); this.getLastPageData();
this.query(); this.query();
}, },
@@ -46,14 +44,24 @@ Page({
async query(){ async query(){
const res = await requestApi(`/system/status/newByNum/${this.data.deviceInfo.deviceNum}`,{ method:'GET' }); const res = await requestApi(`/system/status/newByNum/${this.data.deviceInfo.deviceNum}`,{ method:'GET' });
let light_power; let light_power;
let relayStatus;
if (res.data.data.lightStatus === 0) { if (res.data.data.lightStatus === 0) {
light_power = false; light_power = false;
}else if (res.data.data.lightStatus === 1) { }else if (res.data.data.lightStatus === 1) {
light_power =true; light_power =true;
} }
if (res.data.data.relayStatus === 0) {
relayStatus = false;
}else if (res.data.data.relayStatus === 1) {
relayStatus = true;
}
this.setData({ this.setData({
nowDeviceData:res.data.data, nowDeviceData:res.data.data,
light_power light_power,
curtainPowerChecked:relayStatus,
currentValue:res.data.data.airTemperature,
maxTempValue:res.data.data.airTemperature,
realMaxTempValue: res.data.data.airTemperature
}) })
}, },
@@ -69,29 +77,11 @@ Page({
initParams(){ 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; const params = this.data.nowDeviceData;
return params; return params;
}, },
//灯开关
async lightPower(){ async lightPower(){
let light_power = this.data.light_power; let light_power = this.data.light_power;
let lightStatus; let lightStatus;
@@ -137,10 +127,77 @@ Page({
curtainManvalChecked:curtainManvalChecked curtainManvalChecked:curtainManvalChecked
}) })
}, },
onChangeCurtainPower(){
let curtainPowerChecked = this.data.curtainPowerChecked; //窗帘开关
if (this.data.curtainManvalChecked) { async onChangeCurtainPower(){
this.setData({ curtainPowerChecked:!curtainPowerChecked }) // let curtainPowerChecked = this.data.curtainPowerChecked;
// let relayStatus;
// if (curtainPowerChecked === false) {
// relayStatus = 1;
// }else if (curtainPowerChecked === true) {
// relayStatus = 0;
// }
// if (this.data.curtainManvalChecked) {
// let params = this.initParams();
// params.relayStatus = relayStatus;
// const res = await requestApi(`/system/status`,{
// method:'PUT',
// data:params
// });
// console.log('窗帘:',res);
// if (res.data.code !== 200) {
// wx.showToast({
// title: '操作失败',
// icon:'error'
// })
// return;
// }
// this.setData({ curtainPowerChecked:!curtainPowerChecked })
// }
},
onAutoFanMode(){
let fanAutoChecked = !this.data.fanAutoChecked;
this.setData({
fanAutoChecked:fanAutoChecked,
fanManvalChecked:!fanAutoChecked
})
},
onManvalFanMode(){
let fanManvalChecked = !this.data.fanManvalChecked;
this.setData({
fanAutoChecked:!fanManvalChecked,
fanManvalChecked:fanManvalChecked
})
},
//风扇开关
async onChangeFanPower(){
let fanPowerChecked = this.data.fanPowerChecked;
let relayStatus;
if (fanPowerChecked === false) {
relayStatus = 1;
}else if (fanPowerChecked === true) {
relayStatus = 0;
}
if (this.data.fanManvalChecked) {
let params = this.initParams();
params.relayStatus = relayStatus;
const res = await requestApi(`/system/status`,{
method:'PUT',
data:params
});
console.log('窗帘:',res);
if (res.data.code !== 200) {
wx.showToast({
title: '操作失败',
icon:'error'
})
return;
}
this.setData({ fanPowerChecked:!fanPowerChecked })
} }
}, },
@@ -155,6 +212,7 @@ Page({
}) })
}, },
onChangeValue(e){ onChangeValue(e){
this.setData({ maxTempValue:e.detail,currentValue:e.detail }) this.setData({ maxTempValue:e.detail,currentValue:e.detail })
}, },
onDrag(e){ onDrag(e){
@@ -167,7 +225,20 @@ Page({
tempShow:false tempShow:false
}) })
}, },
onMakeSure(){ async onMakeSure(){
const params = this.initParams();
params.airTemperature = this.data.maxTempValue;
const res = await requestApi('/system/status',{
method:'PUT',
data:params
});
if (res.data.code !== 200) {
wx.showToast({
title: '操作失败',
icon:'error'
})
return;
}
this.setData({ this.setData({
realMaxTempValue:this.data.maxTempValue, realMaxTempValue:this.data.maxTempValue,
tempShow:false tempShow:false

View File

@@ -2,12 +2,12 @@
<view class='body'> <view class='body'>
<view class='top'> <view class='top'>
<view class='around center power'> <view class='around center power'>
<view class='power_light center' bindtap='lightPower' style='{{ light_power?"box-shadow:0 0 50rpx 20rpx #0023ff":"" }}'> <view class='power_light center' bindtap='lightPower' style='{{ light_power===true?"box-shadow:0 0 50rpx 20rpx #0023ff":"" }}'>
<image src='{{ light_power?"/images/power_on.png":"/images/power_off.png" }}' /> <image src='{{ light_power?"/images/power_on.png":"/images/power_off.png" }}' />
</view> </view>
</view> </view>
<view class='TH around center'> <view class='TH around center'>
<van-circle value="{{ nowDeviceData.airTemperature }}" color="{{ gradientColor }}" stroke-width="8" size="165" > <van-circle value="{{ nowDeviceData.deviceTemperature }}" color="{{ gradientColor }}" stroke-width="8" size="165" >
<slots> <slots>
<view class='temp_text'>温度:{{ nowDeviceData.deviceTemperature }} ℃</view> <view class='temp_text'>温度:{{ nowDeviceData.deviceTemperature }} ℃</view>
<view class='humi_text'>湿度:{{ nowDeviceData.airHumidity }}%</view> <view class='humi_text'>湿度:{{ nowDeviceData.airHumidity }}%</view>
@@ -16,6 +16,12 @@
</view> </view>
</view> </view>
<view class='group'> <view class='group'>
<view class='door item'>
<van-cell title="门的状态" size='large' value="{{ nowDeviceData.remark.doorStatus===1?'开':'关' }}" icon='/images/door.png' />
</view>
<view class=' item'>
<van-cell title="光照强度" size='large' value="{{ nowDeviceData.remark.light }}" icon='/images/light.png' />
</view>
<view class='curtain item'> <view class='curtain item'>
<van-cell title="窗帘" value="{{ curtainAutoChecked?'自动':'手动' }}" size='large' <van-cell title="窗帘" value="{{ curtainAutoChecked?'自动':'手动' }}" size='large'
icon='/images/curtain.png' is-link bindtap='showCurtain' icon='/images/curtain.png' is-link bindtap='showCurtain'
@@ -59,24 +65,26 @@
<view class='choose'> <view class='choose'>
<van-cell size='large' title="自动模式"> <van-cell size='large' title="自动模式">
<view slots='value'> <view slots='value'>
<van-switch checked="{{ checked }}" bind:change="onChange" /> <van-switch checked="{{ fanAutoChecked }}" bind:change="onAutoFanMode" />
</view> </view>
</van-cell> </van-cell>
</view> </view>
<view class='choose'> <view class='choose'>
<van-cell size='large' title="手动模式"> <van-cell size='large' title="手动模式">
<view slots='value'> <view slots='value'>
<van-switch checked="{{ checked }}" bind:change="onChange" /> <van-switch checked="{{ fanManvalChecked }}" bind:change="onManvalFanMode" />
</view>
</van-cell>
</view>
<view class='curtain_power'>
<van-cell title="风扇开关">
<view slots='value'>
<van-switch checked="{{ checked }}" bind:change="onChange" />
</view> </view>
</van-cell> </van-cell>
</view> </view>
<block wx:if='{{ fanManvalChecked }}'>
<view class='curtain_power'>
<van-cell title="风扇开关" title-style='color:blue;'>
<view slots='value'>
<van-switch checked="{{ fanManvalChecked && fanPowerChecked }}" bind:change="onChangeFanPower" />
</view>
</van-cell>
</view>
</block>
</van-popup> </van-popup>
<van-popup show="{{ tempShow }}" round position="bottom" bind:close="onClose"> <van-popup show="{{ tempShow }}" round position="bottom" bind:close="onClose">
<view class='tempZu'>设置温度最大值:{{ maxTempValue }}℃</view> <view class='tempZu'>设置温度最大值:{{ maxTempValue }}℃</view>

View File

@@ -29,6 +29,12 @@
"pathName": "pages/login/index", "pathName": "pages/login/index",
"query": "", "query": "",
"scene": null "scene": null
},
{
"name": "pages/my/index",
"pathName": "pages/my/index",
"query": "",
"scene": null
} }
] ]
} }