智能照明系统APP-本地串口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LightingSystemApp-serial/.svn/pristine/51/51f2bc41fb097c4bf7bf3ee3f5b...

1110 lines
26 KiB

3 years ago
<template>
<view class="page">
<u-navbar back-text="设备管控" />
<view class="card-group">
<view class="card" @tap="open(99)">
<view class="title">全网范围</view>
<view>暖色比:----</view>
<view>调&#12288;光:----</view>
<view>状&#12288;态:----</view>
</view>
<view
v-for="(item, index) in groupinfo"
:key="item.value"
class="card"
:class="statusClass[status['zone_status'+item.value]]"
@tap="open(item)"
>
<view class="title">{{item.text}}</view>
<view>暖色比:{{ WCR["warm_color_ratio"+item.value] !== -1 ? WCR["warm_color_ratio"+item.value] +"%" : "---" }}</view>
<view>调&#12288;光:{{ dimmer["zone_dimmer"+item.value] !== -1 ? dimmer["zone_dimmer"+item.value] +"%" : "---"}}</view>
<view>
状&#12288;态:
<text class="status">{{ statusName[status["zone_status"+item.value]] }}</text>
</view>
</view>
</view>
<u-popup v-model="showPopup" mode="top" @close="popupClose">
<view>
<u-picker v-model="show" :params="params" mode="time" @confirm = 'pickerconfirm'></u-picker>
</view>
<view class="title">{{ index !== 99 ? `${index}区域` : "全网范围" }}参数设置</view>
<view class="subsection">
<u-subsection
:list="this.control_list"
mode="subsection"
height="64"
active-color="#4E73DF"
@change="subsectionChange"
/>
</view>
<view v-if="operationIndex===0">
<view class="slider">
<text>调光</text>
<view class="slider-item">
<u-slider
v-model="region.set_zone_light"
height="20"
block-width="40"
active-color="transparent"
/>
</view>
<my-input
class="slider-input"
v-model="region.set_zone_light"
type="number"
maxlength="3"
/>
</view>
<view class="slider">
<text>调色</text>
<view class="slider-item">
<u-slider
v-model="region.set_zone_color"
height="20"
block-width="40"
active-color="transparent"
/>
</view>
<my-input
class="slider-input"
v-model="region.set_zone_color"
type="number"
maxlength="3"
/>
</view>
<u-button type="primary" shape="circle" @click="setDimmer">设置</u-button>
</view>
<view v-if="operationIndex===1">
<view class="table">
<view class="tr th">
<view class="th" style="width: 80rpx" />
<view class="th" style="width: 60rpx">小时</view>
<view class="th" style="width: 60rpx">分钟</view>
<view class="th" style="width: 120rpx">调光比例</view>
<view class="th" style="width: 120rpx">色温比例</view>
</view>
<view v-for="item in 6" :key="item" class="tr-item">
<view class="tr">
<view class="td" style="width: 80rpx">第{{item}}段</view>
<view class="border" />
<view class="td" style="width: 60rpx">
<my-input
class="input"
v-model="timetable[item - 1].hour"
type="number"
maxlength="3"
@click="timesolt(item)"
/>
</view>
<view class="border" />
<view class="td" style="width: 60rpx">
<my-input
class="input"
v-model="timetable[item - 1].minute"
type="number"
maxlength="3"
@click="timesolt(item)"
/>
</view>
<view class="border" />
<view class="td" style="width: 120rpx">
<my-input
class="input"
v-model="timetable[item-1].dimmer"
type="number"
maxlength="3"
@input="checknumber"
/>
</view>
<view class="border" />
<view class="td" style="width: 120rpx">
<my-input
class="input"
v-model="timetable[item-1].color"
type="number"
maxlength="3"
@input="checknumber"
/>
</view>
</view>
<view class="border" />
</view>
</view>
<view class="timetable-btn">
<u-button type="primary" shape="circle" @click="setTimetable">设置</u-button>
</view>
</view>
</u-popup>
<u-toast ref="uToast" />
<u-mask :show="commandmaskshow" z-index = 100000>
<view class="warp">
<view class="rect">
<view class="position">
<u-circle-progress active-color="#2979ff" :percent= progress>
<view class="u-progress-content">
<view class="u-progress-dot"></view>
<text class='u-progress-info'>执行中...</text>
</view>
</u-circle-progress>
</view>
<view class="readbtn">
<u-button type="warning" @click="stopcommand">终止执行</u-button>
</view>
</view>
</view>
</u-mask>
</view>
</template>
<script>
import myInput from "@/components/myInput";
import {
sendLampzonedimmer,
sendLampAlldimmer,
receiveLampzonedimmer,
setGroupTimetable,
receivesetGroupTimetable,
} from "@/common/network/equipment/protocol.js";
import {
getGroupinfo,
getAllGroupInfo,
} from "@/common/network/equipment/property.js";
export default {
components: { myInput },
data() {
return {
groupinfo:[],
control_list:['区域操作', '时间表设置'],
show: false,
params: {
hour: true,
minute: true,
},
progress: 0,
commandmaskshow: false,
device: {},
subdeviceid: "",
test_dimmer1: "",
test_dimmer2: "",
intervalID: {
groupstatus: undefined,
commandReceive: undefined,
commandOvertime: undefined,
dimmercommandReceive: undefined,
dimmercommandOvertime: undefined,
},
timetablenum: 1,
timetable: [
{
time:'00:00',
hour:'',
minute:'',
dimmer: "",
color: "",
},
{
time:'00:00',
hour:'',
minute:'',
dimmer: "",
color: "",
},
{
time:'00:00',
hour:'',
minute:'',
dimmer: "",
color: "",
},
{
time:'00:00',
hour:'',
minute:'',
dimmer: "",
color: "",
},
{
time:'00:00',
hour:'',
minute:'',
dimmer: "",
color: "",
},
{
time:'00:00',
hour:'',
minute:'',
dimmer: "",
color: "",
}
],
timetable_list: [
{
time:'00:00',
dimmer: "0",
color: "0",
},
{
time:'00:00',
dimmer: "0",
color: "0",
},
{
time:'00:00',
dimmer: "0",
color: "0",
},
{
time:'00:00',
dimmer: "0",
color: "0",
},
{
time:'00:00',
dimmer: "0",
color: "0",
},
{
time:'00:00',
dimmer: "0",
color: "0",
}
],
showPopup: false,
statusName: ["正常", "异常", "未用", "---"],
statusClass: ["", "abnormal", "unused", ""],
index: 0,
groupindex:1,
operationIndex: 0,
device: {},
WCR: {},
dimmer: {},
status: {},
region: {
select_zone_dimmer: 0,
set_zone_light: 0,
set_zone_color: 0,
},
LL: {
zone_longitude: "",
zone_latitude: "",
},
};
},
created() {},
mounted() {
},
methods: {
checknumber(e){
},
pickerconfirm(e){
if(this.timetablenum > 0 && this.timetablenum <= 6)
{
this.timetable[this.timetablenum - 1].hour = e.hour;
this.timetable[this.timetablenum - 1].minute = e.minute;
this.timetable[this.timetablenum - 1].time = e.hour+':'+e.minute;
}
},
timesolt(num){
this.timetablenum = num;
this.show = true;
},
setDimmer() {
if (
parseInt(this.region.set_zone_light) >= 0 &&
parseInt(this.region.set_zone_light) <= 100 &&
parseInt(this.region.set_zone_color) >= 0 &&
parseInt(this.region.set_zone_color) <= 100
)
{
var operastr;
var groupid;
if(this.region.select_zone_dimmer == 99)
{
operastr = 'changedimmingall';
groupid = 0;
}
else{
operastr = 'changedimmingbygroup';
groupid = this.region.select_zone_dimmer;
}
let data = {
operation: operastr,
id:this.terminalid,
dimming1: parseInt(this.region.set_zone_light),
dimming2: parseInt(this.region.set_zone_color),
groupid: groupid,
};
var that = this;
this.commandmaskshow = true;
this.intervalID.dimmercommandReceive = null;
this.intervalID.dimmercommandOvertime = null;
this.progress = 0;
if(groupid == 0)//全网调光
{
sendLampAlldimmer(data)
.then((res) => {
//命令下发成功
if(res.successed == true)
{
that.commandid = res.data.commandid;
data.commandid = that.commandid;
if(that.intervalID.dimmercommandOvertime == null) {
that.intervalID.dimmercommandOvertime = setTimeout(() => {
that.$refs.uToast.show({
title: "命令超时",
type: "error",
icon: false,
});
clearInterval(that.intervalID.dimmercommandReceive);
that.intervalID.dimmercommandReceive = null;
that.intervalID.dimmercommandOvertime == null
that.commandmaskshow = false;
that.progress = 0;
}, 20000);
}
if(that.intervalID.dimmercommandReceive == null) {
that.intervalID.dimmercommandReceive = setInterval(() => {
that.progress += 5;
receiveLampzonedimmer(data)
.then((res) => {
if(res.successed == true)
{
this.$refs.uToast.show({
title: "调光值设置成功",
type: "success",
});
clearInterval(that.intervalID.dimmercommandOvertime);
clearInterval(that.intervalID.dimmercommandReceive);
that.intervalID.dimmercommandOvertime = null;
that.intervalID.dimmercommandReceive = null;
that.commandmaskshow = false;
that.progress = 0;
}
else{
if(res.message.indexOf('无应答') == -1){
this.$refs.uToast.show({
title: res.message,
type: "error",
icon: false,
});
clearInterval(that.intervalID.dimmercommandOvertime);
clearInterval(that.intervalID.dimmercommandReceive);
that.intervalID.dimmercommandOvertime = null;
that.intervalID.dimmercommandReceive = null;
that.commandmaskshow = false;
that.progress = 0;
}
}
})
.catch((err) => {
console.log(err);
this.$refs.uToast.show({
title: res.message,
type: "error",
icon: false,
});
clearInterval(that.intervalID.dimmercommandOvertime);
clearInterval(that.intervalID.dimmercommandReceive);
that.intervalID.dimmercommandOvertime = null;
that.intervalID.dimmercommandReceive = null;
that.commandmaskshow = false;
that.progress = 0;
});
}, 1000);
}
}
else{
var indexstart = res.indexOf("info")
var indexend = res.indexOf("!")
var msg = res.substring(indexstart+6,indexend+1)
that.commandmaskshow = false;
that.progress = 0;
that.$refs.uToast.show({
title: msg,
type: "error",
icon: false,
});
}
})
.catch((err) => {
console.log(err);
});
}
else{
sendLampzonedimmer(data)
.then((res) => {
//命令下发成功
if(res.successed == true)
{
that.commandid = res.data.commandid;
data.commandid = that.commandid;
if(that.intervalID.dimmercommandOvertime == null) {
that.intervalID.dimmercommandOvertime = setTimeout(() => {
that.$refs.uToast.show({
title: "命令超时",
type: "error",
icon: false,
});
clearInterval(that.intervalID.dimmercommandReceive);
that.intervalID.dimmercommandReceive = null;
that.intervalID.dimmercommandOvertime == null
that.commandmaskshow = false;
that.progress = 0;
}, 20000);
}
if(that.intervalID.dimmercommandReceive == null) {
that.intervalID.dimmercommandReceive = setInterval(() => {
that.progress += 5;
receiveLampzonedimmer(data)
.then((res) => {
if(res.successed == true)
{
this.$refs.uToast.show({
title: "调光值设置成功",
type: "success",
});
clearInterval(that.intervalID.dimmercommandOvertime);
clearInterval(that.intervalID.dimmercommandReceive);
that.intervalID.dimmercommandOvertime = null;
that.intervalID.dimmercommandReceive = null;
that.commandmaskshow = false;
that.progress = 0;
}
else{
if(res.message.indexOf('无应答') == -1){
this.$refs.uToast.show({
title: res.message,
type: "error",
icon: false,
});
clearInterval(that.intervalID.dimmercommandOvertime);
clearInterval(that.intervalID.dimmercommandReceive);
that.intervalID.dimmercommandOvertime = null;
that.intervalID.dimmercommandReceive = null;
that.commandmaskshow = false;
that.progress = 0;
}
}
})
.catch((err) => {
console.log(err);
this.$refs.uToast.show({
title: res.message,
type: "error",
icon: false,
});
clearInterval(that.intervalID.dimmercommandOvertime);
clearInterval(that.intervalID.dimmercommandReceive);
that.intervalID.dimmercommandOvertime = null;
that.intervalID.dimmercommandReceive = null;
that.commandmaskshow = false;
that.progress = 0;
});
}, 1000);
}
}
else{
var indexstart = res.indexOf("info")
var indexend = res.indexOf("!")
var msg = res.substring(indexstart+6,indexend+1)
that.commandmaskshow = false;
that.progress = 0;
that.$refs.uToast.show({
title: msg,
type: "error",
icon: false,
});
}
})
.catch((err) => {
console.log(err);
});
}
}
else
{
this.$refs.uToast.show({
title: "请输入0-100范围内的数字",
type: "warning",
icon: false,
});
}
},
getGroupstatus(data) {
getGroupinfo(data)
.then((res) => {
if (res.data.totalCount > 0) {
for (let i = 1; i <= res.data.totalCount; i++) {
this.$set(this.WCR, "warm_color_ratio" + i, res.data.list[i-1].dimmer_wcr);
this.$set(this.dimmer, "zone_dimmer" + i, res.data.list[i-1].dimmer);
this.$set(this.status, "zone_status" + i, res.data.list[i-1].alarm);
}
} else {
console.log(res);
}
})
.catch((err) => {
console.log(err);
});
},
setTimetable() {
let isNumber = true;
for (var i=0; i<6; i++) {
if ((this.timetable[i].dimmer <= 100) &&(this.timetable[i].color <= 100)) {
if(this.timetable[i].dimmer == '')
{
this.timetable_list[i].dimmer = 0;
}
else
{
this.timetable_list[i].dimmer = this.timetable[i].dimmer;
}
if(this.timetable[i].color == '')
{
this.timetable_list[i].color = 0;
}
else
{
this.timetable_list[i].color = this.timetable[i].color;
}
;
this.timetable_list[i].time = this.timetable[i].time;
}
else{
isNumber = false;
}
}
if (isNumber) {
let data = {
id: this.terminalid,
groupid: this.groupindex,
timeList: [],
};
data.timeList = JSON.stringify(this.timetable_list);
var that = this;
this.commandmaskshow = true;
this.intervalID.commandReceive = null;
this.intervalID.commandOvertime = null;
this.progress = 0;
setGroupTimetable(data)
.then((res) => {
//命令下发成功
if(res.successed == true)
{
that.commandid = res.data.commandid;
data.commandid = that.commandid;
if(that.intervalID.commandOvertime == null) {
that.intervalID.commandOvertime = setTimeout(() => {
that.$refs.uToast.show({
title: "命令超时",
type: "error",
icon: false,
});
clearInterval(that.intervalID.commandReceive);
that.intervalID.commandReceive = null;
that.intervalID.commandOvertime == null
that.commandmaskshow = false;
that.progress = 0;
}, 20000);
}
if(that.intervalID.commandReceive == null) {
that.intervalID.commandReceive = setInterval(() => {
that.progress += 5;
receivesetGroupTimetable(data)
.then((res) => {
if(res.successed == true)
{
this.$refs.uToast.show({
title: "时间表设置成功",
type: "success",
});
clearInterval(that.intervalID.commandOvertime);
clearInterval(that.intervalID.commandReceive);
that.intervalID.commandOvertime = null;
that.intervalID.commandReceive = null;
that.commandmaskshow = false;
that.progress = 0;
}
else{
if(res.message.indexOf('无应答') == -1){
this.$refs.uToast.show({
title: res.message,
type: "error",
icon: false,
});
clearInterval(that.intervalID.dimmercommandOvertime);
clearInterval(that.intervalID.dimmercommandReceive);
that.intervalID.dimmercommandOvertime = null;
that.intervalID.dimmercommandReceive = null;
that.commandmaskshow = false;
that.progress = 0;
}
}
})
.catch((err) => {
console.log(err);
clearInterval(that.intervalID.commandOvertime);
clearInterval(that.intervalID.commandReceive);
that.intervalID.commandOvertime = null;
that.intervalID.commandReceive = null;
that.commandmaskshow = false;
that.progress = 0;
});
}, 1000);
}
}
else{
var msg = res.message
that.commandmaskshow = false;
that.progress = 0;
that.$refs.uToast.show({
title: msg,
type: "error",
icon: false,
});
}
})
.catch((err) => {
console.log(err);
});
} else {
this.$refs.uToast.show({
title: "调光和色温比例请输入0至100范围的整数!",
type: "warning",
});
}
},
open(index) {
this.show = false;
this.index = index.text;
this.groupindex = index.value;
if(index == '99'){
this.control_list = ['区域操作'];
}
else{
this.control_list = ['区域操作', '时间表设置'];
}
this.showPopup = true;
this.region.select_zone_dimmer = index;
this.region.set_zone_light =
this.dimmer["zone_dimmer" + index] * 100 || 0;
this.region.set_zone_color =
this.WCR["warm_color_ratio" + index] * 100 || 0;
},
popupClose() {
this.operationIndex = 0;
this.LL = {
zone_longitude: "",
zone_latitude: "",
};
this.timetable = [
{
time:'00:00',
hour:'',
minute:'',
dimmer: "",
color: "",
},
{
time:'00:00',
hour:'',
minute:'',
dimmer: "",
color: "",
},
{
time:'00:00',
hour:'',
minute:'',
dimmer: "",
color: "",
},
{
time:'00:00',
hour:'',
minute:'',
dimmer: "",
color: "",
},
{
time:'00:00',
hour:'',
minute:'',
dimmer: "",
color: "",
},
{
time:'00:00',
hour:'',
minute:'',
dimmer: "",
color: "",
}
];
},
subsectionChange(index) {
this.operationIndex = index;
},
stopcommand(){
clearInterval(this.intervalID.dimmercommandOvertime);
clearInterval(this.intervalID.dimmercommandReceive);
this.intervalID.dimmercommandOvertime = null;
this.intervalID.dimmercommandReceive = null;
this.commandmaskshow = false;
},
getProductAll() {
var that=this;
getProductAll()
.then((res) => {
if (res.totalCount > 0) {
that.productList = res.result;
let change = true;
for (let item of res.result) {
if (that.product.value === item.value) {
that.product = item;
change = false;
break;
}
}
if (change) {
that.product = res.result[0];
}
that.getDeviceAll(that.product);
} else {
that.showMask = true;
}
})
},
getAllGroupNum(data) {
var that=this;
getAllGroupInfo(data)
.then((res) => {
if (res.data.totalCount > 0) {
that.groupinfo = res.data.list;
}
})
},
},
onShow(){
},
onLoad(option) {
for (let i = 1; i <= 98; i++) {
this.$set(this.WCR, "warm_color_ratio" + i, "");
this.$set(this.dimmer, "zone_dimmer" + i, "");
this.$set(this.status, "zone_status" + i, 3);
}
this.device = option;
this.rtuid = this.device.deviceid;
this.terminalid = this.device.terminalId;
this.getAllGroupNum(this.rtuid);
this.getGroupstatus(this.terminalid);
this.intervalID.groupstatus = setInterval(() => {
this.getGroupstatus(this.terminalid);
}, 1000 * 60 * 5);
},
onUnload() {
clearInterval(this.intervalID.groupstatus);
},
};
</script>
<style scoped>
.page {
background: linear-gradient(
180deg,
rgba(235, 241, 255, 0.5) 0%,
#e4ebff 100%
);
}
.card-group {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
}
.card {
display: inline-block;
width: 220rpx;
margin: 24rpx 15rpx;
padding: 24rpx 30rpx;
font-size: 24rpx;
line-height: 50rpx;
background: #ffffff;
border-radius: 16rpx;
}
.card > .title {
font-size: 32rpx;
line-height: 60rpx;
font-weight: bold;
text-align: center;
}
.card.abnormal {
background: rgba(236, 106, 86, 0.3);
}
.card.abnormal .status {
color: #ec6a56;
}
.card.unused {
background: rgba(247, 194, 63, 0.31);
}
.card.unused .status {
color: #d7a81e;
}
.u-drawer,
.u-drawer >>> .u-mask {
margin-top: calc(var(--status-bar-height) + 44px);
}
.u-drawer .title {
margin: 32rpx 0 24rpx;
font-size: 36rpx;
font-weight: bolder;
text-align: center;
}
.subsection {
margin: 0 70rpx;
}
.slider {
display: flex;
justify-content: space-around;
height: 60rpx;
line-height: 60rpx;
font-size: 32rpx;
}
.slider > .slider-item {
display: flex;
flex-direction: column;
justify-content: center;
width: 440rpx;
}
.slider > .slider-input {
width: 120rpx;
height: 60rpx;
font-size: 28rpx;
text-align: center;
color: #4e73df;
border: 1px solid #4e73df;
border-radius: 2px;
}
.slider:first-child {
margin: 54rpx 0 36rpx;
}
.slider .u-slider {
background: linear-gradient(270deg, #fff7e5 0%, #f7c23f 100%);
box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.07);
}
.slider:first-child .u-slider {
background: linear-gradient(270deg, #f7f7f7 0%, #dddddd 100%);
}
.slider + .u-btn {
margin: 100rpx 52rpx 60rpx;
}
.u-radio-group {
justify-content: space-between;
margin: 34rpx 176rpx 26rpx;
font-size: 28rpx;
line-height: 1.8;
}
.u-radio-group >>> .u-radio__label {
font-size: 28rpx;
}
.table {
margin: 0 24rpx;
margin-top: 40rpx;
font-size: 28rpx;
border: 1px solid rgba(78, 115, 223, 0.4);
border-radius: 5px;
}
.table .input {
font-size: 28rpx;
}
.tr {
display: flex;
justify-content: space-around;
align-items: center;
height: 68rpx;
text-align: center;
}
.tr.th {
background: rgba(78, 115, 223, 0.4);
}
.tr > .border {
width: 1px;
height: 100%;
background: rgba(78, 115, 223, 0.4);
}
.tr + .border {
height: 1px;
background: rgba(78, 115, 223, 0.4);
}
.table .tr-item:last-child > .border {
height: 0;
}
.timetable-btn,
.LL-btn {
display: flex;
justify-content: space-around;
padding: 0 40rpx;
}
.timetable-btn > .u-btn,
.LL-btn > .u-btn {
width: 300rpx;
margin: 56rpx 0 70rpx;
}
.LL-item {
display: flex;
justify-content: space-around;
align-items: center;
padding: 0 60rpx;
height: 70rpx;
line-height: 70rpx;
font-size: 32rpx;
}
.LL-item:first-child {
margin: 50rpx 0 32rpx;
}
.LL-input {
width: 470rpx;
height: 70rpx;
padding: 0 20rpx;
border-radius: 5px;
border: 1px solid rgba(141, 146, 166, 0.49);
}
.LL-btn {
display: flex;
justify-content: space-around;
padding: 0 40rpx;
}
.LL-btn > .u-btn {
width: 300rpx;
margin: 56rpx 0 70rpx;
}
.warp {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.rect {
width: 145px;
height: 145px;
background-color: #fff;
}
.u-progress-content {
display: flex;
align-items: center;
justify-content: center;
}
.u-progress-dot {
width: 16rpx;
height: 16rpx;
border-radius: 50%;
background-color: #fb9126;
}
.u-progress-info {
font-size: 28rpx;
padding-left: 16rpx;
letter-spacing: 2rpx
}
.position{
margin: 5px 20px;
}
.readbtn{
margin: 2px 35px;
}
.readbtn>>>.u-btn {
width: 150rpx;
height: 56rpx;
margin: 0;
}
.readbtn>>>.u-btn--default {
color: #2979ff;
}
.readbtn>>>.u-btn--default::after {
border: 2px solid #2979ff;
}
.readbtn>>>.u-btn--default.u-default-hover {
color: #ffffff !important;
}
.readbtn>>>.u-btn--default.u-default-hover {
background-color: #2979ff !important;
}
</style>