场景模型测试工具
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.

654 lines
20 KiB

2 years ago
<template>
<div class="app-container home">
2 years ago
<el-row :gutter="20">
<el-col :span="24" :xs="24">
<el-form :model="queryParams" ref="queryRef" :inline="true" label-width="68px">
<el-form-item label="设备名称">
<el-select v-model="queryParams.devName" placeholder="请选择设备" @change="handleDevChange">
2 years ago
<el-option label="所有" value="0" />
<el-option v-for="item in devArr" :key="item.deviceId" :label="item.deviceName" :value="item.deviceId" />
2 years ago
</el-select>
</el-form-item>
2 years ago
<!-- <el-form-item label="状态" prop="status">-->
<!-- <el-select v-model="queryParams.status" placeholder="请选择状态" style="width: 240px" @change="handleStatusChangeFun">-->
<!-- <el-option label="所有" value="" />-->
<!-- <el-option label="开启" value="1" />-->
<!-- <el-option label="停止" value="0" />-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<el-form-item label="创建日期" style="width: 308px;">
<el-date-picker v-model="queryParams.dateRange"
2 years ago
value-format="YYYY-MM-DD"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
></el-date-picker>
2 years ago
</el-form-item>
<el-form-item class="mr30">
2 years ago
<el-button class="mybtn" type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button class="mybtn" icon="Refresh" @click="resetQuery">重置</el-button>
2 years ago
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" icon="Plus" @click="handleAdd">新增</el-button>
</el-col>
</el-row>
<div class="dev_control_table">
<el-table :data="timingList" height="685px">
2 years ago
<el-table-column label="序号" type="index" width="60" :index="indexMethod1"></el-table-column>
2 years ago
<el-table-column label="设备名称" align="center" prop="deviceName"/>
2 years ago
<el-table-column label="任务描述" align="center" prop="controlContext"/>
2 years ago
<!-- <el-table-column label="状态" align="center">-->
<!-- <template v-slot="scope">-->
<!--&lt;!&ndash; <el-tag class="ml-2" :type="timerStatus">暂停</el-tag>&ndash;&gt;-->
<!-- <el-tag class="ml-2" effect="dark" :type="scope.row.timerStatus == 0 ? 'info':'success'" disable-transitions>{{ scope.row.timerStatus == 0 ? '停止' : '开启' }}</el-tag>-->
<!-- </template>-->
<!-- </el-table-column>-->
<el-table-column label="执行日期" align="center" prop="runday"/>
<el-table-column label="执行时间" align="center" prop="runtime"/>
2 years ago
<el-table-column label="创建者" align="center" prop="createBy"/>
2 years ago
<el-table-column label="创建时间" align="center" prop="createTime"/>
2 years ago
<el-table-column label="操作" align="center" prop="handle">
2 years ago
<template v-slot="scope">
2 years ago
<!-- <el-button size="small" :type="scope.row.timerStatus == 0 ? 'success':''" @click="getUpDateStatusFun(scope)">{{ scope.row.timerStatus == 0 ? '开启' : '停止' }}</el-button>-->
<el-button type="danger" size="small" :icon="Delete" @click="getDeleteTimerFun(scope)">删除</el-button>
2 years ago
</template>
</el-table-column>
</el-table>
<el-pagination
v-model:current-page="currentPage"
v-model:page-size="pageSize"
:page-sizes="[5, 10, 20, 50]"
:small="small"
:disabled="disabled"
:background="background"
layout="total, sizes, prev, pager, next, jumper"
2 years ago
:total="total"
2 years ago
@size-change="handleSizeChange"
@current-change="handleCurrentChange"/>
</div>
</el-col>
</el-row>
<!-- 新增对话框 -->
<el-dialog :title="title" v-model="open" width="600px" append-to-body>
<el-form :model="timingForm" ref="userRef" label-width="80px">
<el-row>
<el-col :span="24">
<el-form-item label="设备名称">
<el-select v-model="timingForm.dev" placeholder="请选择设备" @change="handleDevChange">
<el-option v-for="item in devArr" :key="item.deviceId" :label="item.deviceName" :value="item.deviceId" />
</el-select>
</el-form-item>
</el-col>
2 years ago
<el-col :span="24">
2 years ago
<el-form-item label="任务描述" prop="content">
<el-input disabled v-model="timingForm.controlContext" placeholder="请输入任务描述"/>
2 years ago
</el-form-item>
</el-col>
2 years ago
<el-col :span="24">
<el-form-item label="控制指令" prop="code">
2 years ago
<el-radio-group v-model="timingForm.checkedRadio" @change="checkedRadio" style="display: flex; flex-wrap: wrap;">
2 years ago
<div style="display: flex; margin-bottom: 10px; width: 100%">
<el-radio label="启" border/>
<el-radio label="停" border/>
</div>
2 years ago
<!-- <div class="tempRadioBox">-->
<!-- <div class="tempRadio">-->
<!-- <el-radio v-model="timingForm.checkedRadio" class="radio" label="进水温度" border @change="radioChange"/>-->
<!-- <el-input v-model="timingForm.inTemp" class="input"/>-->
<!-- </div>-->
<!-- <div class="tempRadio">-->
<!-- <el-radio v-model="timingForm.checkedRadio" class="radio" label="出水温度" border @change="radioChange"/>-->
<!-- <el-input v-model="timingForm.outTemp" class="input"/>-->
<!-- </div>-->
<!-- <div class="tempRadio">-->
<!-- <el-radio v-model="timingForm.checkedRadio" class="radio" label="温度" border @change="radioChange"/>-->
<!-- <el-input v-model="timingForm.temp" class="input"/>-->
<!-- </div>-->
<!-- </div>-->
2 years ago
</el-radio-group>
</el-form-item>
</el-col>
2 years ago
<el-col :span="24">
2 years ago
<el-form-item label="执行次数">
2 years ago
<el-radio-group v-model="timingForm.day">
2 years ago
<el-radio label="每天" @change="handleEveryday"/>
2 years ago
</el-radio-group>
<div class="collapse">
<el-collapse v-model="activeName" accordion>
<el-collapse-item title="星期几" name="1">
2 years ago
<el-checkbox-group v-model="week" @change="handleCheckboxClick" >
<el-checkbox style='width:90px' label="2">星期一</el-checkbox>
<el-checkbox style='width:90px' label="3">星期二</el-checkbox>
<el-checkbox style='width:90px' label="4">星期三</el-checkbox>
<el-checkbox style='width:90px' label="5">星期四</el-checkbox>
<el-checkbox style='width:90px' label="6">星期五</el-checkbox>
<el-checkbox style='width:90px' label="7">星期六</el-checkbox>
<el-checkbox style='width:90px' label="8">星期日</el-checkbox>
</el-checkbox-group>
</el-collapse-item>
<el-collapse-item title="仅此一次" name="2">
<el-date-picker v-model="value1" type="date" placeholder="请选择日期"/>
</el-collapse-item>
</el-collapse>
</div>
2 years ago
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="执行时间" prop="executeTime">
<el-time-picker v-model="timingForm.executeTime" placeholder="请选择执行时间" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</template>
</el-dialog>
2 years ago
</div>
</template>
<script setup name="Index">
2 years ago
import {Delete,SwitchButton} from '@element-plus/icons-vue'
import {ElMessage, ElMessageBox} from "element-plus";
2 years ago
import {ref, reactive, watch, onMounted, watchEffect} from "vue";
2 years ago
import {getList, getAddTimer, getDeleteTimer, getUpDateStatus} from '@/api/control/timer'
import { getDevice,getControlDeviceList } from '@/api/control/manual'
2 years ago
/** 页面加载时*/
onMounted(()=>{
formattedDateFun()
getListFun()
getAllDev()
2 years ago
})
/** 格式化日期*/
const YYYYMMDD = ref();
const timer = ref()
function formattedDateFun(){
let date = new Date()
let year = date.getFullYear()
let month = (date.getMonth()+1).toString().padStart(2, '0');
let day = date.getDate().toString().padStart(2, '0');
let hours = date.getHours()
let minutes = date.getMinutes()
let seconds = date.getSeconds()
YYYYMMDD.value = `${year}-${month}-${day}`
timer.value = `${hours}:${minutes}:${seconds}`
console.log(YYYYMMDD.value)
console.log(timer.value)
}
2 years ago
/** 筛选处理 */
2 years ago
//选择的日期
// const dateRange = ref([]);
2 years ago
const startDate = ref()
const endDate = ref()
2 years ago
const data = reactive({
queryParams: {
2 years ago
devName:'0',
status: '',
dateRange:[],
2 years ago
}
});
//监听开始日期和结束日期
const wacthSelectDate = watch(()=> data.queryParams.dateRange,(val) =>{
console.log(val[0])
startDate.value = val[0]
console.log(val[1])
endDate.value = val[1]
})
2 years ago
//拿到选择的状态val
const statusVal = ref()
function handleStatusChangeFun(val){
console.log('状态id',val)
statusVal.value = val
}
2 years ago
//搜索按钮
function handleQuery(){
2 years ago
getListFun()
2 years ago
}
//重置按钮
function resetQuery(){
data.queryParams.dateRange = [];
currentPage.value = 1;
pageSize.value = 20;
startDate.value = null;
endDate.value = null;
devId.value = null;
2 years ago
data.queryParams.devName = '0'
statusVal.value = ''
console.log('重置后的状态值为',statusVal.value)
2 years ago
getListFun()
2 years ago
}
/** 数据表格处理 */
2 years ago
const timingList = ref([])
2 years ago
const currentPage = ref(1)
const pageSize = ref(20)
2 years ago
const total = ref()
2 years ago
const small = ref(false)
const background = ref(false)
const disabled = ref(false)
//翻页时不刷新序号
function indexMethod1(index){
return index+(currentPage.value-1)*pageSize.value+1
}
2 years ago
//获取表格信息
2 years ago
function getListFun(){
getList({
"timerId":null,
"deviceId":devId.value,
2 years ago
"controlContext":null,
2 years ago
"timerStatus":statusVal.value,
2 years ago
"createStart":startDate.value,
"createEnd": endDate.value,
"pageNum": currentPage.value,
"pageSize": pageSize.value
}).then((res)=>{
total.value = res.total
timingList.value = res.rows
2 years ago
for(let i = 0;i < timingList.value.length;i++){
if(timingList.value[i].runday.length != 10){ // 如果不是日期类型的
2 years ago
let rundayArr = timingList.value[i].runday.split(','); // 将字符串拆成数组
let rundayStr = '';
for(let j = 0;j < rundayArr.length;j++){
switch(rundayArr[j]){
case '0':
rundayStr = '每天';
break;
case '1':
rundayStr += '星期一';
break;
case '2':
rundayStr += '星期二';
break;
case '3':
rundayStr += '星期三';
break;
case '4':
rundayStr += '星期四';
break;
case '5':
rundayStr += '星期五';
break;
case '6':
rundayStr += '星期六';
break;
case '7':
rundayStr += '星期日';
break;
}
if(j < rundayArr.length - 1){
rundayStr += ',';
}
}
timingList.value[i].runday = rundayStr;
}
}
2 years ago
})
}
2 years ago
const handleSizeChange = (val) => {
console.log(`${val}`)
getListFun()
2 years ago
}
const handleCurrentChange = (val) => {
console.log(`${val}`)
getListFun()
}
2 years ago
//开启停止按钮
2 years ago
// function getUpDateStatusFun(scope){
// //scope.row.timerStatus取反,传入的值取反
// scope.row.timerStatus = scope.row.timerStatus === 1 ? 0 : 1;
// getUpDateStatus(scope.row.timerId,scope.row.timerStatus).then((res)=>{
// console.log(res)
// if(res.code == 200){
// ElMessage({
// type: 'success',
// message: res.msg,
// })
// if(scope.row.timerStatus == 0){
// scope.row.timerStatus = 1
// }else{
// scope.row.timerStatus = 0
// }
// getListFun()
// }
// })
// }
//删除定时任务
2 years ago
//删除任务
function getDeleteTimerFun(e){
2 years ago
console.log(e)
ElMessageBox.confirm(
'确定要删除此条定时任务吗?',
'提示',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(() => {
2 years ago
getDeleteTimer(e.row.timerId).then((res)=>{
if(res.code == 200){
ElMessage({
type: 'success',
message: '删除成功!',
})
getListFun()
}
})
}).catch(() => {})
2 years ago
}
/** 新增定时处理 */
const open = ref(false);
const title = ref();
const activeName = ref('1')
const value1 = ref('')
const devArr = ref([])
const selectDate = ref()
2 years ago
const timingForm = reactive({
dev:'',
2 years ago
controlContext:'设备启停',
2 years ago
intemp:'',
outtemp:'',
checkedRadio:'',
inTemp:'',
outTemp:'',
temp:'',
2 years ago
day:'',
executeTime:'',
})
//拿到选择的设备id
2 years ago
const devId = ref()
function handleDevChange(id){
devId.value = id
2 years ago
console.log('设备id:',devId.value)
}
2 years ago
//监听:输入的任务描述
const watchContent = watch(()=> timingForm.content,(val)=>{
console.log(val)
})
2 years ago
//监听:选中的是哪个指令
const code = ref()
2 years ago
const codeValue = ref()
2 years ago
const watchCode = watch(()=> timingForm.checkedRadio,(val)=>{
2 years ago
if(val == '启'){
timingForm.inTemp = ''
timingForm.outTemp = ''
timingForm.temp = ''
code.value = 'startandstop'
codeValue.value = 1
}
if(val == '停'){
2 years ago
timingForm.inTemp = ''
timingForm.outTemp = ''
timingForm.temp = ''
code.value = 'startandstop'
2 years ago
codeValue.value = 2
2 years ago
}
if(val == '进水温度'){
timingForm.outTemp = ''
timingForm.temp = ''
code.value = 'inTemp'
}
if(val == '出水温度'){
timingForm.inTemp = ''
timingForm.temp = ''
code.value = 'outTemp'
}
if(val == '温度'){
timingForm.outTemp = ''
timingForm.inTemp = ''
code.value = 'temp'
}
2 years ago
console.log('控制指令:',code.value)
2 years ago
})
2 years ago
// //监听:输入的进水温度值
// const tempValue = ref()
// const watchInTempValue = watch(()=>timingForm.inTemp,(val)=>{
// tempValue.value = val
// console.log('进水温度',tempValue.value)
// })
// //监听:输入的出水温度值
// const watchOutTempValue = watch(()=>timingForm.outTemp,(val)=>{
// tempValue.value = val
// console.log('出水温度',tempValue.value)
// })
// //监听:输入的温度值
// const watchTempValue = watch(()=>timingForm.temp,(val)=>{
// tempValue.value = val
// console.log('温度',tempValue.value)
// })
//选中每天
function handleEveryday(val){
2 years ago
value1.value = '';
2 years ago
week.value = [];
selectDate.value = 0
console.log('选择每天:',selectDate.value)
}
//勾选的星期
const week = ref([])
function handleCheckboxClick() {
if(week.value.length === 7){
timingForm.day = '每天';
selectDate.value = 0
}else if(week.value.length < 7 && week.value.length > 0){
timingForm.day = '';
value1.value = '';
let strNum = week.value.join(',')
selectDate.value = strNum
}
console.log('选择星期:',selectDate.value)
}
//监听:选择仅此一次将每天和星期几清空
const watchValue1 = watch(()=> value1.value,(val) => {
const date = new Date(val.toLocaleString());
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
selectDate.value = `${year}-${month}-${day}`;
2 years ago
console.log('选择日期:',selectDate.value)
if(value1.value != null){
timingForm.day = '';
2 years ago
week.value = [];
}
})
2 years ago
//监听:选择的执行时间
2 years ago
const selectTimer = ref()
const watchTime = watch(()=> timingForm.executeTime, (val) => {
let date = new Date(val)
let hours = date.getHours()
let minutes = date.getMinutes()
let seconds = date.getSeconds()
selectTimer.value = `${hours}:${minutes}:${seconds}`
2 years ago
console.log('选择时间:',selectTimer.value)
})
//获取可控所有设备
function getAllDev(){
getControlDeviceList().then((res)=>{
devArr.value = res.data
})
}
//新增按钮
2 years ago
function handleAdd() {
open.value = true;
title.value = "新增定时任务";
};
//确定新增
2 years ago
function submitForm() {
open.value = false;
getAddTimer({
"deviceId":devId.value,
2 years ago
"controlKey":code.value,
2 years ago
"controlValue":codeValue.value,
"status":null,
"runday":selectDate.value,
"runtime":selectTimer.value
}).then((res)=>{
if(res.code == 200){
ElMessage({
message: res.msg,
type: 'success',
})
2 years ago
devId.value = null;
getListFun()
}
})
2 years ago
};
//取消新增
2 years ago
function cancel() {
open.value = false;
};
2 years ago
2 years ago
const { queryParams } = toRefs(data);
2 years ago
</script>
<style scoped lang="scss">
2 years ago
.dev_control_table{
position: relative;
width: 100%;
2 years ago
//min-height: 740px;
2 years ago
background-color: #2F3D8A;
}
.mr30{
margin-left: 100px;
margin-top: -4px;
}
.collapse{
margin-bottom: -1px;
2 years ago
}
.tempInput{
width: 20%;
background-color: #ddd;
border-radius: 4px;
}
.tempRadioBox{
display: flex;
justify-content: space-between;
width: 100%;
.tempRadio{
display: flex;
margin-right: 20px;
&:nth-child(3){
margin-right: 0px;
}
.radio{
margin-right: 0px;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
padding-right: 2px;
border-right: 0px;
}
.input{
width: 60px;
height: 32px;
}
}
}
//::v-deep .el-input__wrapper{
// border-top-left-radius: 0px;
// border-bottom-left-radius: 0px;
//}
2 years ago
::v-deep .el-button{
border-radius: 2px;
}
::v-deep .mb8{
margin-bottom: 12px;
}
2 years ago
::v-deep .el-pagination{
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
}
::v-deep .el-pagination__total{
color: #f3ffff;
}
::v-deep .el-pagination__jump{
color: #f3ffff;
}
::v-deep .el-pager{
margin: 0 5px;
}
::v-deep .el-table .el-table__body-wrapper{
background-color: #2F3D8A;
}
::v-deep .el-form-item__content{
display: inline-block;
2 years ago
}
2 years ago
::v-deep .el-input__inner{
2 years ago
//color: #f3ffff !important;
color: #606266 !important;
2 years ago
}
::v-deep .el-date-editor .el-range-input{
2 years ago
//color: #f3ffff;
color: #606266 !important;
2 years ago
}
::v-deep .el-scrollbar__wrap.el-scrollbar__wrap--hidden-default{
background-color: rgba(47,61,138);
}
2 years ago
@media (max-width:960px) {
.app-container{
padding: 8px;
}
.dev_control_table{
height: 540px !important;
}
.mb8{
margin-bottom: 0px;
}
.mybtn{
margin-bottom: 0px !important;
}
::v-deep .el-button{
margin-bottom: 8px;
font-size: 12px;
}
::v-deep .el-form-item--default .el-form-item__label{
height: 30px;
line-height: 30px;
font-size: 12px;
}
::v-deep .el-form-item--default .el-form-item__content{
line-height: 30px;
font-size: 12px;
}
::v-deep .el-form--inline .el-form-item{
margin-right: 20px;
}
}
2 years ago
</style>