550 lines
15 KiB
Plaintext
550 lines
15 KiB
Plaintext
<template>
|
|
<view class="index_wrap">
|
|
<text class="index_title" @click="closeApp">运行状态</text>
|
|
<view class="index_list">
|
|
<view
|
|
class="index_inline"
|
|
v-for="item in listData"
|
|
>
|
|
<view class="inline_item">
|
|
<text class="inline_item_text">{{item.circuitName}}路电流:</text>
|
|
<text class="inline_item_text_clu">{{item.current}}A</text>
|
|
</view>
|
|
<view class="inline_item_end">
|
|
<text class="inline_item_text_end">{{item.typeName}}:</text>
|
|
<text :class="item.isTypeOpen=== '1'?'inline_item_circle_open':'inline_item_circle_close'"></text>
|
|
<text class="inline_item_text_type">{{item.isTypeOpen === '1'?'开':'关'}}</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="index_footer">
|
|
<text class="footer_set" @click="handleToSet">设置</text>
|
|
<text class="footer_history" @click="handleToHistory">操作历史</text>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
<script>
|
|
import {dbUtils} from '../script/dbUtils.js'
|
|
import {serialPortUtil} from '../script/serialPortUtil.js'
|
|
import {CrcUt} from '../script/CRCUtils.js'
|
|
|
|
export default {
|
|
name: 'main',
|
|
data() {
|
|
return {
|
|
listData:[],
|
|
stopRead:true,
|
|
sendStatus:true,
|
|
dianliuInte:null,
|
|
jidianqiInte:null,
|
|
dianliu1:null,
|
|
dianliu2:null,
|
|
dianliu3:null,
|
|
dianliu4:null,
|
|
map:new Map(),
|
|
mapBefore:new Map(),
|
|
};
|
|
},
|
|
//初始化
|
|
apiready(){
|
|
const vm = this
|
|
api.addEventListener({
|
|
name: 'myEvent'
|
|
}, function(ret, err) {
|
|
if(ret.value){
|
|
vm.initAll()
|
|
}
|
|
});
|
|
vm.initAll()
|
|
},
|
|
methods: {
|
|
closeApp(){
|
|
api.closeWidget({
|
|
id: api.appId, //应用ID
|
|
retData: { name: 'closeWidget' },
|
|
silent: true
|
|
});
|
|
},
|
|
initAll(){
|
|
const vm = this
|
|
clearInterval(vm.data.jidianqiInte)
|
|
clearInterval(vm.data.dianliuInte)
|
|
clearInterval(vm.data.dianliu1)
|
|
clearInterval(vm.data.dianliu2)
|
|
clearInterval(vm.data.dianliu3)
|
|
clearInterval(vm.data.dianliu4)
|
|
var db = api.require('db');
|
|
db.openDatabase({
|
|
name: 'test',
|
|
path: 'fs://Database/cqjiouzai.db'
|
|
}, function(ret, err) {
|
|
if (ret.status) {
|
|
//初始化设备表
|
|
vm.initSb(db);
|
|
}
|
|
});
|
|
},
|
|
//跳转到设置页面
|
|
handleToSet(){
|
|
api.openWin({
|
|
name: 'set',
|
|
url:'./main/set.stml'
|
|
})
|
|
},
|
|
//跳转到历史记录页
|
|
handleToHistory(){
|
|
api.openWin({
|
|
name: 'history',
|
|
url:'./main/history.stml'
|
|
})
|
|
},
|
|
//创建设备表
|
|
initSb(db) {
|
|
const vm = this;
|
|
// const uniqueId = 'id-' + new Date().getTime().toString(36) + '-' + Math.random().toString(36).substr(2, 9);
|
|
// dbUtils.execute(db, "INSERT INTO Sb (id,circuitName,current,typeName,isTypeOpen) VALUES ('"+uniqueId+"','test1','lw','"+vm.currTimeFn(new Date())+"','test');", function(ret, err) {
|
|
// })
|
|
dbUtils.select(db, 'SELECT * FROM Sb', function(ret, err) {
|
|
var data = ret.data;
|
|
if(undefined != data && data.length > 0){
|
|
vm.data.listData = data;
|
|
var m = new Map()
|
|
vm.data.listData.forEach(l=>{
|
|
m.set(l.sbId,l.current)
|
|
})
|
|
vm.data.map = m;
|
|
}
|
|
if (ret.status == false || err.status == false) {
|
|
dbUtils.execute(db, 'CREATE TABLE Sb(id varchar(50), sbId varchar(10), circuitName varchar(50), current varchar(20), typeName varchar(30),isTypeOpen int(10))', function(ret, err) {
|
|
if (ret.status == true) {
|
|
dbUtils.execute(db, "INSERT INTO Sb (Id,sbId,circuitName,current,typeName,isTypeOpen) VALUES ('1','0B','1','3.21','高压风冷',1);", function(ret, err) {})
|
|
dbUtils.execute(db, "INSERT INTO Sb (Id,sbId,circuitName,current,typeName,isTypeOpen) VALUES ('2','0C','2','3.21','中压风冷',1);", function(ret, err) {})
|
|
dbUtils.execute(db, "INSERT INTO Sb (Id,sbId,circuitName,current,typeName,isTypeOpen) VALUES ('3','0D','3','3.21','低压风冷',1);", function(ret, err) {})
|
|
dbUtils.execute(db, "INSERT INTO Sb (Id,sbId,circuitName,current,typeName,isTypeOpen) VALUES ('4','0E','4','3.21','闭锁调压',1);", function(ret, err) {})
|
|
console.log('创建设备表成功');
|
|
vm.initAll()
|
|
}
|
|
});
|
|
} else {
|
|
// console.log('设备表已存在');
|
|
vm.activeStatus()
|
|
// dbUtils.execute(db, "DROP TABLE Sb", function(ret, err) {
|
|
// console.log(JSON.stringify(ret))
|
|
// })
|
|
}
|
|
});
|
|
dbUtils.select(db, 'SELECT * FROM Log', function(ret, err) {
|
|
if (ret.status == false || err.status == false) {
|
|
dbUtils.execute(db, 'CREATE TABLE Log(action varchar(20), param varchar(100), time varchar(30), remark varchar(50))', function(ret, err) {
|
|
if (ret.status == true) {
|
|
console.log('创建日志表成功');
|
|
}
|
|
});
|
|
} else {
|
|
// console.log('日志表已存在');
|
|
// dbUtils.execute(db, "DROP TABLE Log", function(ret, err) {
|
|
// if(ret.status){
|
|
// console.log("删除日志表成功");
|
|
// }
|
|
// })
|
|
}
|
|
})
|
|
},
|
|
activeStatus(){
|
|
const vm = this;
|
|
//初始化串口
|
|
serialPortUtil.initSerial();
|
|
serialPortUtil.closeSerial({ index: 0 });
|
|
serialPortUtil.openSerial({ index: 0, port: '/dev/ttyS0', baudRate: '9600'}, function (ret, err) {})
|
|
serialPortUtil.addEventListener({ index: 0, revType: 'hex', stopBits:1, flowCon:2 }, function (ret, err) {
|
|
// console.log(JSON.stringify(ret));
|
|
var data = vm.data.listData;
|
|
var leng = data.length;
|
|
if (ret.dataHex.startsWith("FE0101") && ret.dataHex.length > 8) {
|
|
// console.log("读取设备状态");
|
|
var jidianqi = ret.dataHex.substr(6, 2);
|
|
jidianqi = parseInt(jidianqi, 16).toString(2);
|
|
vm.data.jidianqi = vm.forJidianqi(jidianqi);
|
|
jidianqi = vm.data.jidianqi;
|
|
|
|
// console.log("************main:"+jidianqi+"************");
|
|
vm.data.mapBefore.set("0B",jidianqi[3] === '1');
|
|
vm.data.mapBefore.set("0C",jidianqi[2] === '1');
|
|
vm.data.mapBefore.set("0D",jidianqi[1] === '1');
|
|
vm.data.mapBefore.set("0E",jidianqi[0] === '1');
|
|
for(var j=0;j<jidianqi.length;j++){
|
|
data[3-j].isTypeOpen = jidianqi[j]
|
|
}
|
|
vm.data.listData = data;
|
|
}else{
|
|
// console.log("读取设备电流");
|
|
if(ret.evenType === 'onDataReceived'){
|
|
vm.data.sendStatus=true
|
|
for(var i=0;i<leng; i++){
|
|
if(data[i] && data[i].sbId.toUpperCase() === ret.dataHex.substr(0,2).toUpperCase()){
|
|
var current = parseInt(ret.dataHex.substr(10,4),16)/100;
|
|
var sett = vm.data.map.get(data[i].sbId);
|
|
data[i].current = current
|
|
var sbId = data[i].sbId;
|
|
var beforeStatus = vm.data.mapBefore.get(sbId)
|
|
if(current >= sett){
|
|
switch(sbId){
|
|
case '0B':
|
|
// 如果之前是关闭状态,则打开
|
|
if(!beforeStatus){
|
|
vm.controle1(true);
|
|
vm.saveLog(data[i].typeName+"打开","实时电流"+current+"A,配置电流"+sett+"A","")
|
|
}
|
|
break;
|
|
case '0C':
|
|
if(!beforeStatus){
|
|
vm.controle2(true);
|
|
vm.saveLog(data[i].typeName+"打开","实时电流"+current+"A,配置电流"+sett+"A","")
|
|
}
|
|
break;
|
|
case '0D':
|
|
if(!beforeStatus){
|
|
vm.controle3(true);
|
|
vm.saveLog(data[i].typeName+"打开","实时电流"+current+"A,配置电流"+sett+"A","")
|
|
}
|
|
break;
|
|
case '0E':
|
|
if(!beforeStatus){
|
|
vm.controle4(true);
|
|
vm.saveLog(data[i].typeName+"打开","实时电流"+current+"A,配置电流"+sett+"A","")
|
|
}
|
|
break;
|
|
}
|
|
}else{
|
|
switch(sbId){
|
|
case '0B':
|
|
// 如果之前是打开状态,则关闭
|
|
if(beforeStatus){
|
|
vm.controle1(false);
|
|
vm.saveLog(data[i].typeName+"关闭","实时电流"+current+"A,配置电流"+sett+"A","")
|
|
}
|
|
break;
|
|
case '0C':
|
|
if(beforeStatus){
|
|
vm.controle2(false);
|
|
vm.saveLog(data[i].typeName+"关闭","实时电流"+current+"A,配置电流"+sett+"A","")
|
|
}
|
|
break;
|
|
case '0D':
|
|
if(beforeStatus){
|
|
vm.controle3(false);
|
|
vm.saveLog(data[i].typeName+"关闭","实时电流"+current+"A,配置电流"+sett+"A","")
|
|
}
|
|
break;
|
|
case '0E':
|
|
if(beforeStatus){
|
|
vm.controle4(false);
|
|
vm.saveLog(data[i].typeName+"关闭","实时电流"+current+"A,配置电流"+sett+"A","")
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
vm.data.listData = data
|
|
}
|
|
}
|
|
})
|
|
vm.data.jidianqiInte=setInterval(function () {
|
|
if(vm.data.stopRead){
|
|
vm.sendMsg('FE 01 00 00 00 08 29 C3');
|
|
}
|
|
},2000)
|
|
|
|
// var cmdArr = [];
|
|
// vm.data.listData.forEach(s=>{
|
|
// var cmd = s.sbId+" 03 00 48 00 02";
|
|
// cmd = cmd + " " + CrcUt.GetCrc(cmd);
|
|
// cmdArr.push(cmd);
|
|
// })
|
|
api.showProgress({
|
|
title: '正在初始化...',
|
|
text: '请稍后...',
|
|
modal: true
|
|
});
|
|
|
|
vm.data.dianliu1=setInterval(function () {
|
|
if(vm.data.stopRead){
|
|
vm.data.stopRead = false
|
|
setTimeout(() => {
|
|
vm.sendMsg("0B 03 00 48 00 02 " + CrcUt.GetCrc("0B 03 00 48 00 02"));
|
|
setTimeout(() => {
|
|
vm.data.stopRead = true
|
|
}, 80);
|
|
}, 50);
|
|
}
|
|
},500)
|
|
vm.data.dianliu2=setInterval(function () {
|
|
if(vm.data.stopRead){
|
|
vm.data.stopRead = false
|
|
setTimeout(() => {
|
|
vm.sendMsg("0C 03 00 48 00 02 " + CrcUt.GetCrc("0C 03 00 48 00 02"));
|
|
setTimeout(() => {
|
|
vm.data.stopRead = true
|
|
}, 80);
|
|
}, 50);
|
|
}
|
|
},1000)
|
|
vm.data.dianliu3=setInterval(function () {
|
|
if(vm.data.stopRead){
|
|
vm.data.stopRead = false
|
|
setTimeout(() => {
|
|
vm.sendMsg("0D 03 00 48 00 02 " + CrcUt.GetCrc("0D 03 00 48 00 02"));
|
|
setTimeout(() => {
|
|
vm.data.stopRead = true
|
|
}, 80);
|
|
}, 50);
|
|
}
|
|
},1500)
|
|
vm.data.dianliu4=setInterval(function () {
|
|
if(vm.data.stopRead){
|
|
vm.data.stopRead = false
|
|
setTimeout(() => {
|
|
vm.sendMsg("0E 03 00 48 00 02 " + CrcUt.GetCrc("0E 03 00 48 00 02"));
|
|
setTimeout(() => {
|
|
vm.data.stopRead = true
|
|
}, 80);
|
|
}, 50);
|
|
}
|
|
},2000)
|
|
|
|
// vm.data.dianliuInte=setInterval(function () {
|
|
// vm.data.listData.forEach(s=>{
|
|
// var cmd = s.sbId+" 03 00 48 00 02";
|
|
// cmd = cmd + " " + CrcUt.GetCrc(cmd);
|
|
// if(vm.data.sendStatus && vm.data.stopRead){
|
|
// vm.data.sendStatus = false
|
|
// vm.sendMsg(cmd)
|
|
// console.log(cmd);
|
|
// }
|
|
// })
|
|
// }, 2000);
|
|
setTimeout(() => {
|
|
api.hideProgress();
|
|
}, 3000);
|
|
},
|
|
sendMsg(cmd){
|
|
let ret = serialPortUtil.send({
|
|
index: 0,
|
|
sendType: 'hex',
|
|
data: cmd
|
|
});
|
|
},
|
|
saveLog(action,param,remark){
|
|
const vm = this
|
|
var db = api.require('db');
|
|
dbUtils.execute(db, "INSERT INTO Log (action,param,time,remark) VALUES ('"+action+"','"+param+"','"+vm.currTimeFn(new Date())+"','"+remark+"');", function(ret, err) {
|
|
if(ret.status == false || err.status == false){
|
|
console.log(JSON.stringify(err));
|
|
// api.toast({
|
|
// msg: '日志保存失败',
|
|
// duration: 2000,
|
|
// location: 'middle'
|
|
// });
|
|
}else{
|
|
// api.toast({
|
|
// msg: '日志保存成功',
|
|
// duration: 2000,
|
|
// location: 'middle'
|
|
// });
|
|
console.log('日志保存成功');
|
|
}
|
|
})
|
|
},
|
|
controle1(status){
|
|
console.log("controle1"+status);
|
|
const vm = this;
|
|
vm.data.stopRead = false;
|
|
setTimeout(function () {
|
|
vm.sendMsg(status?'FE 05 00 00 FF 00 98 35':'FE 05 00 00 00 00 D9 C5');
|
|
setTimeout(function () {
|
|
vm.data.stopRead = true;
|
|
}, 50)
|
|
}, 80)
|
|
},
|
|
controle2(status){
|
|
console.log("controle2"+(status?'打开':'关闭'));
|
|
const vm = this;
|
|
vm.data.stopRead = false;
|
|
setTimeout(function () {
|
|
vm.sendMsg(status?'FE 05 00 01 FF 00 C9 F5':'FE 05 00 01 00 00 88 05');
|
|
setTimeout(function () {
|
|
vm.data.stopRead = true;
|
|
}, 50)
|
|
}, 80)
|
|
},
|
|
controle3(status){
|
|
console.log("controle3"+status);
|
|
const vm = this;
|
|
vm.data.stopRead = false;
|
|
setTimeout(function () {
|
|
vm.sendMsg(status?'FE 05 00 02 FF 00 39 F5':'FE 05 00 02 00 00 78 05');
|
|
setTimeout(function () {
|
|
vm.data.stopRead = true;
|
|
}, 50)
|
|
}, 80)
|
|
},
|
|
controle4(status){
|
|
console.log("controle4"+status);
|
|
const vm = this;
|
|
vm.data.stopRead = false;
|
|
setTimeout(function () {
|
|
vm.sendMsg(status?'FE 05 00 03 FF 00 68 35':'FE 05 00 03 00 00 29 C5');
|
|
setTimeout(function () {
|
|
vm.data.stopRead = true;
|
|
}, 50)
|
|
}, 80)
|
|
},
|
|
forJidianqi(jidianqi) {
|
|
if (jidianqi.length != 4) {
|
|
var l = 4 - jidianqi.length
|
|
for (var i = 0; i < l; i++) {
|
|
jidianqi = '0' + jidianqi;
|
|
}
|
|
}
|
|
return jidianqi;
|
|
},
|
|
// 获取当前时间字符串
|
|
currTimeFn(_date) {
|
|
let _year = _date.getFullYear();
|
|
let _month = _date.getMonth() + 1 < 10 ? '0' + (_date.getMonth() + 1) : _date.getMonth() + 1;
|
|
let _day = _date.getDate() < 10 ? '0' + _date.getDate() : _date.getDate();
|
|
let _hour = _date.getHours() < 10 ? '0' + _date.getHours() : _date.getHours();
|
|
let _minutes = _date.getMinutes() < 10 ? '0' + _date.getMinutes() : _date.getMinutes();
|
|
let _seconds = _date.getSeconds() < 10 ? '0' + _date.getSeconds() : _date.getSeconds();
|
|
// return _year + "." + _month + "." + _day + " " + _hour + ":" + _minutes + ":" + _seconds;
|
|
return _year + "." + _month + "." + _day + " " + _hour + ":" + _minutes;
|
|
}
|
|
}
|
|
};
|
|
</script>
|
|
<style>
|
|
.index_wrap{
|
|
width: 100%;
|
|
height: 100%;
|
|
box-sizing: border-box;
|
|
padding: 20px;
|
|
background-image: url("../image/login.png");
|
|
background-size: 120%;
|
|
background-repeat: no-repeat;
|
|
background-position: center;
|
|
}
|
|
.index_title{
|
|
width: 100%;
|
|
text-align: center;
|
|
font-size: 60px;
|
|
color: #ffffff;
|
|
font-weight: bold;
|
|
}
|
|
.index_list{
|
|
margin-top: 50px;
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
.index_inline{
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
margin: 10px 0;
|
|
}
|
|
.inline_item{
|
|
margin: 0 5px;
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
}
|
|
.inline_item_end{
|
|
margin: 0 5px;
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
border: 1px solid silver;
|
|
border-radius: 4px;
|
|
box-sizing: border-box;
|
|
padding: 0 5px;
|
|
background-color: rgba(106, 199, 253, 0.5);
|
|
}
|
|
.inline_item_text{
|
|
font-size: 40px;
|
|
font-weight: bold;
|
|
color: #ffffff;
|
|
margin: 0 5px;
|
|
width: 340px;
|
|
text-align: left;
|
|
border: 1px solid silver;
|
|
border-radius: 4px;
|
|
box-sizing: border-box;
|
|
padding: 0 5px;
|
|
background-color: rgba(106, 199, 253, 0.5);
|
|
}
|
|
.inline_item_text_clu{
|
|
font-size: 40px;
|
|
font-weight: bold;
|
|
color: #ffffff;
|
|
margin: 0 5px;
|
|
width: 140px;
|
|
text-align: left;
|
|
border: 1px solid silver;
|
|
border-radius: 4px;
|
|
box-sizing: border-box;
|
|
padding: 0 5px;
|
|
background-color: rgba(106, 199, 253, 0.5);
|
|
}
|
|
.inline_item_text_end{
|
|
font-size: 40px;
|
|
font-weight: bold;
|
|
color: #ffffff;
|
|
margin: 0 5px;
|
|
width: 340px;
|
|
text-align: left;
|
|
}
|
|
.inline_item_text_type{
|
|
font-size: 40px;
|
|
font-weight: bold;
|
|
color: #ffffff;
|
|
margin: 0 5px;
|
|
text-align: left;
|
|
}
|
|
.inline_item_circle_open{
|
|
width: 40px;
|
|
height: 40px;
|
|
background-color: #09be30;
|
|
border-radius: 50%;
|
|
margin: 0 10px;
|
|
}
|
|
.inline_item_circle_close{
|
|
width: 40px;
|
|
height: 40px;
|
|
background-color: #fd0101;
|
|
border-radius: 50%;
|
|
margin: 0 10px;
|
|
}
|
|
.index_footer{
|
|
width: 80%;
|
|
margin: 50px auto 0;
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
}
|
|
.footer_set{
|
|
font-size: 40px;
|
|
font-weight: bold;
|
|
box-sizing: border-box;
|
|
padding: 10px 20px;
|
|
color: #ffffff;
|
|
}
|
|
.footer_history{
|
|
font-size: 40px;
|
|
font-weight: bold;
|
|
margin-left: 50px;
|
|
box-sizing: border-box;
|
|
padding: 10px 20px;
|
|
color: #ffffff;
|
|
}
|
|
</style>
|