2024-11-19 18:03:43 +08:00
|
|
|
<template>
|
|
|
|
<div id="editRecordPlan" v-loading="loading" style="text-align: left;">
|
|
|
|
<el-dialog
|
|
|
|
title="录制计划"
|
|
|
|
width="700px"
|
|
|
|
top="2rem"
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
:visible.sync="showDialog"
|
|
|
|
:destroy-on-close="true"
|
|
|
|
@close="close()"
|
|
|
|
>
|
|
|
|
<div id="shared" style="margin-right: 20px;">
|
2024-11-20 18:37:39 +08:00
|
|
|
<el-form >
|
2024-11-21 23:20:56 +08:00
|
|
|
<el-form-item label="名称">
|
|
|
|
<el-input type="text" v-model="planName"></el-input>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item>
|
|
|
|
<ByteWeektimePicker v-model="byteTime" name="name"/>
|
|
|
|
</el-form-item>
|
2024-11-19 18:03:43 +08:00
|
|
|
<el-form-item>
|
2024-11-20 18:37:39 +08:00
|
|
|
<div style="float: right; margin-top: 20px">
|
2024-11-19 18:03:43 +08:00
|
|
|
<el-button type="primary" @click="onSubmit">保存</el-button>
|
|
|
|
<el-button @click="close">取消</el-button>
|
|
|
|
</div>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
</div>
|
|
|
|
</el-dialog>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { ByteWeektimePicker } from 'byte-weektime-picker'
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "editRecordPlan",
|
|
|
|
props: {},
|
|
|
|
components: {ByteWeektimePicker},
|
|
|
|
created() {
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
options: [],
|
|
|
|
loading: false,
|
2024-11-21 23:20:56 +08:00
|
|
|
edit: false,
|
|
|
|
planName: null,
|
|
|
|
id: null,
|
2024-11-19 18:03:43 +08:00
|
|
|
showDialog: false,
|
|
|
|
endCallback: "",
|
|
|
|
byteTime: "",
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
2024-11-21 23:20:56 +08:00
|
|
|
openDialog: function (recordPlan, endCallback) {
|
2024-11-19 18:03:43 +08:00
|
|
|
this.endCallback = endCallback;
|
|
|
|
this.showDialog = true;
|
2024-11-20 18:37:39 +08:00
|
|
|
this.byteTime= "";
|
2024-11-21 23:20:56 +08:00
|
|
|
if (recordPlan) {
|
|
|
|
this.edit = true
|
|
|
|
this.planName = recordPlan.name
|
|
|
|
this.id = recordPlan.id
|
|
|
|
this.$axios({
|
|
|
|
method: 'get',
|
|
|
|
url: "/api/record/plan/get",
|
|
|
|
params: {
|
|
|
|
planId: recordPlan.id,
|
|
|
|
}
|
|
|
|
}).then((res) => {
|
2024-11-28 10:15:03 +08:00
|
|
|
if (res.data.code === 0 && res.data.data.planItemList) {
|
2024-11-21 23:20:56 +08:00
|
|
|
this.byteTime = this.plan2Byte(res.data.data.planItemList)
|
|
|
|
}
|
|
|
|
}).catch((error) => {
|
|
|
|
console.error(error)
|
|
|
|
});
|
2024-11-20 18:37:39 +08:00
|
|
|
|
|
|
|
}
|
2024-11-19 18:03:43 +08:00
|
|
|
},
|
|
|
|
onSubmit: function () {
|
2024-11-20 18:37:39 +08:00
|
|
|
let planList = this.byteTime2PlanList();
|
2024-11-21 23:20:56 +08:00
|
|
|
if (!this.edit) {
|
|
|
|
this.$axios({
|
|
|
|
method: 'post',
|
|
|
|
url: "/api/record/plan/add",
|
|
|
|
data: {
|
|
|
|
name: this.planName,
|
|
|
|
planItemList: planList
|
|
|
|
}
|
|
|
|
}).then((res) => {
|
|
|
|
if (res.data.code === 0) {
|
|
|
|
this.$message({
|
|
|
|
showClose: true,
|
|
|
|
message: '添加成功',
|
|
|
|
type: 'success',
|
|
|
|
});
|
|
|
|
this.showDialog = false;
|
|
|
|
this.endCallback()
|
|
|
|
} else {
|
|
|
|
this.$message({
|
|
|
|
showClose: true,
|
|
|
|
message: res.data.msg,
|
|
|
|
type: 'error'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}).catch((error) => {
|
|
|
|
console.error(error)
|
|
|
|
});
|
|
|
|
}else {
|
|
|
|
this.$axios({
|
|
|
|
method: 'post',
|
|
|
|
url: "/api/record/plan/update",
|
|
|
|
data: {
|
|
|
|
id: this.id,
|
|
|
|
name: this.planName,
|
|
|
|
planItemList: planList
|
|
|
|
}
|
|
|
|
}).then((res) => {
|
|
|
|
if (res.data.code === 0) {
|
|
|
|
this.$message({
|
|
|
|
showClose: true,
|
|
|
|
message: '更新成功',
|
|
|
|
type: 'success',
|
|
|
|
});
|
|
|
|
this.showDialog = false;
|
|
|
|
this.endCallback()
|
|
|
|
} else {
|
|
|
|
this.$message({
|
|
|
|
showClose: true,
|
|
|
|
message: res.data.msg,
|
|
|
|
type: 'error'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}).catch((error) => {
|
|
|
|
console.error(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-11-19 18:03:43 +08:00
|
|
|
},
|
|
|
|
close: function () {
|
|
|
|
this.showDialog = false;
|
2024-11-21 23:20:56 +08:00
|
|
|
this.id = null
|
|
|
|
this.planName = null
|
|
|
|
this.byteTime = ""
|
|
|
|
this.endCallback = ""
|
2024-11-19 18:03:43 +08:00
|
|
|
if(this.endCallback) {
|
|
|
|
this.endCallback();
|
|
|
|
}
|
|
|
|
},
|
2024-11-20 18:37:39 +08:00
|
|
|
byteTime2PlanList() {
|
|
|
|
if (this.byteTime.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const DayTimes = 24 * 2;
|
|
|
|
let planList = []
|
|
|
|
let week = 1;
|
|
|
|
// 把 336长度的 list 分成 7 组,每组 48 个
|
|
|
|
for (let i = 0; i < this.byteTime.length; i += DayTimes) {
|
|
|
|
let planArray = this.byteTime2Plan(this.byteTime.slice(i, i + DayTimes));
|
|
|
|
if(!planArray || planArray.length === 0) {
|
|
|
|
week ++;
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for (let j = 0; j < planArray.length; j++) {
|
|
|
|
planList.push({
|
2024-11-28 10:15:03 +08:00
|
|
|
planId: this.id,
|
2024-11-27 22:44:22 +08:00
|
|
|
start: planArray[j].start,
|
|
|
|
stop: planArray[j].stop,
|
2024-11-20 18:37:39 +08:00
|
|
|
weekDay: week
|
|
|
|
})
|
|
|
|
}
|
|
|
|
week ++;
|
|
|
|
}
|
|
|
|
return planList
|
|
|
|
},
|
|
|
|
byteTime2Plan(weekItem){
|
2024-11-27 22:44:22 +08:00
|
|
|
let start = null;
|
|
|
|
let stop = null;
|
2024-11-20 18:37:39 +08:00
|
|
|
let result = []
|
2024-11-28 10:15:03 +08:00
|
|
|
console.log("===================")
|
2024-11-20 18:37:39 +08:00
|
|
|
for (let i = 0; i < weekItem.length; i++) {
|
|
|
|
let item = weekItem[i]
|
2024-11-28 10:15:03 +08:00
|
|
|
console.log(item)
|
2024-11-27 22:44:22 +08:00
|
|
|
if (item === '1') { // 表示选中
|
|
|
|
stop = i
|
|
|
|
if (start === null ) {
|
|
|
|
start = i
|
|
|
|
}
|
2024-11-28 10:15:03 +08:00
|
|
|
if (i === weekItem.length - 1 && start != null && stop != null) {
|
2024-11-27 22:44:22 +08:00
|
|
|
result.push({
|
|
|
|
start: start,
|
|
|
|
stop: stop,
|
|
|
|
})
|
2024-11-20 18:37:39 +08:00
|
|
|
}
|
|
|
|
} else {
|
2024-11-28 10:15:03 +08:00
|
|
|
if (stop !== null){
|
2024-11-20 18:37:39 +08:00
|
|
|
result.push({
|
2024-11-27 22:44:22 +08:00
|
|
|
start: start,
|
|
|
|
stop: stop,
|
2024-11-20 18:37:39 +08:00
|
|
|
})
|
2024-11-28 10:15:03 +08:00
|
|
|
start = null
|
|
|
|
stop = null
|
2024-11-20 18:37:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2024-11-21 23:20:56 +08:00
|
|
|
},
|
|
|
|
plan2Byte(planList) {
|
|
|
|
let byte = ""
|
|
|
|
let indexArray = {}
|
|
|
|
for (let i = 0; i < planList.length; i++) {
|
2024-11-27 22:44:22 +08:00
|
|
|
|
|
|
|
let weekDay = planList[i].weekDay
|
|
|
|
let index = planList[i].start
|
|
|
|
let endIndex = planList[i].stop
|
2024-11-21 23:20:56 +08:00
|
|
|
for (let j = index; j <= endIndex; j++) {
|
2024-11-27 22:44:22 +08:00
|
|
|
indexArray["key_" + (j + (weekDay - 1 )*48)] = 1
|
2024-11-21 23:20:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let i = 0; i < 336; i++) {
|
2024-11-27 22:44:22 +08:00
|
|
|
if (indexArray["key_" + i]){
|
2024-11-21 23:20:56 +08:00
|
|
|
byte += "1"
|
|
|
|
}else {
|
|
|
|
byte += "0"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return byte
|
2024-11-20 18:37:39 +08:00
|
|
|
}
|
2024-11-19 18:03:43 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|