<template>
|
<div class="AddBox">
|
<div class="title">{{ editData.type ? "修改" : "添加" }}{{ type === "separate" ? "独立" : "联动" }}场景</div>
|
|
<div class="close iconfont" @click="close"></div>
|
|
<el-form :model="ruleForm" :rules="rules" ref="form">
|
<div class="label">场景名称</div>
|
<el-form-item prop="scene_name">
|
<!-- <el-input class="h32" v-model="ruleForm.scene_name" placeholder="请输入"></el-input> -->
|
|
<el-select v-model="ruleForm.scene_name" filterable placeholder="请选择">
|
<el-option v-for="item in scene_nameOptions" :key="item.value" :label="item.label" :value="item.value">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
|
<div class="label">事件等级</div>
|
<el-form-item>
|
<el-select class="h32" v-model="ruleForm.alarm_level" placeholder="请选择">
|
<el-option v-for="item in eventLevel" :key="item.value" :label="item.label" :value="item.value"></el-option>
|
</el-select>
|
</el-form-item>
|
|
<div class="label">时间段</div>
|
<el-form-item prop="time_rule_id">
|
<el-select class="h32 left" v-model="ruleForm.time_rule_id" placeholder="请选择">
|
<el-option
|
v-for="item in VideoManageData.TimeRules"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id"
|
></el-option>
|
</el-select>
|
|
<i class="iconfont" @click="showTimeSlider = true"></i>
|
</el-form-item>
|
|
<div class="label">场景描述</div>
|
<el-form-item>
|
<el-input class="h32" v-model="ruleForm.desc" type="textarea"></el-input>
|
</el-form-item>
|
|
<div class="label">事件声音</div>
|
<el-form-item>
|
<el-select v-model="ruleForm.voice" placeholder="请选择" value-key="id" @change="selSound" class="h32 left">
|
<el-option v-for="item in soundList" :key="item.id" :label="item.name" :value="item"></el-option>
|
</el-select>
|
<span @click="togglePlayer" v-show="ruleForm.voiceId.length">
|
<i v-if="togglePlay" class="iconfont"></i>
|
<i v-else class="iconfont"></i>
|
</span>
|
</el-form-item>
|
</el-form>
|
|
<div class="btns">
|
<div class="confirmBtn button" @click="save">保存</div>
|
<div class="cancelBtn button" @click="close">取消</div>
|
</div>
|
|
<TimeSlider v-if="showTimeSlider" @close="showTimeSlider = false"></TimeSlider>
|
</div>
|
</template>
|
|
<script>
|
import { getSoundList } from "@/api/event"
|
import TimeSlider from "@/views/hashrate/CameraManage/CameraRules/components/TimeSlider"
|
|
export default {
|
props: {
|
type: {
|
type: String
|
},
|
editData: {}
|
},
|
components: {
|
TimeSlider
|
},
|
mounted() {
|
console.log(this.editData)
|
this.getSounds()
|
this.eventAudio.addEventListener("ended", () => {
|
this.togglePlay = true
|
})
|
},
|
data() {
|
return {
|
scene_nameOptions: [
|
{
|
value: "明火",
|
label: "明火"
|
},
|
{
|
value: "烟雾",
|
label: "烟雾"
|
},
|
{
|
value: "翻越围栏",
|
label: "翻越围栏"
|
},
|
{
|
value: "区域入侵",
|
label: "区域入侵"
|
},
|
{
|
value: "人员撤离",
|
label: "人员撤离"
|
},
|
{
|
value: "人员离岗",
|
label: "人员离岗"
|
},
|
{
|
value: "人员聚集",
|
label: "人员聚集"
|
},
|
{
|
value: "打电话",
|
label: "打电话"
|
},
|
{
|
value: "抽烟",
|
label: "抽烟"
|
},
|
{
|
value: "未佩戴安全帽",
|
label: "未佩戴安全帽"
|
},
|
{
|
value: "未穿着工作服",
|
label: "未穿着工作服"
|
},
|
{
|
value: "睡岗",
|
label: "睡岗"
|
}
|
],
|
ruleForm: {
|
alarm_level: 1,
|
scene_name: "",
|
desc: "",
|
template_id: "",
|
time_rule_id: "",
|
voice: {},
|
voiceId: ""
|
},
|
eventLevel: [
|
{
|
label: "一级",
|
value: 1
|
},
|
{
|
label: "二级",
|
value: 2
|
},
|
{
|
label: "三级",
|
value: 3
|
},
|
{
|
label: "四级",
|
value: 4
|
},
|
{
|
label: "五级",
|
value: 5
|
}
|
],
|
rules: {
|
scene_name: [{ required: true, message: "请选择场景名称", trigger: "blur" }],
|
time_rule_id: [{ required: true, message: "请选择时间段", trigger: "blur" }]
|
},
|
soundPath: "",
|
togglePlay: true,
|
eventAudio: new Audio(),
|
soundList: [],
|
showTimeSlider: false
|
}
|
},
|
|
methods: {
|
//编辑时回填数据
|
initEditData() {
|
this.ruleForm = {
|
alarm_level: this.editData.rule.alarm_level,
|
scene_name: this.editData.rule.scene_name,
|
desc: this.editData.rule.desc,
|
template_id: this.editData.rule.template_id,
|
time_rule_id: this.editData.rule.time_rule_id,
|
voice: this.editData.rule.voice,
|
voiceId: this.editData.rule.voiceId,
|
index: this.editData.index
|
}
|
this.soundList.forEach((item) => {
|
if (item.id == this.editData.rule.voiceId) {
|
this.ruleForm.voiceId = item.id
|
this.ruleForm.voice = item
|
}
|
})
|
},
|
getSounds() {
|
let _this = this
|
getSoundList()
|
.then((res) => {
|
if (res.success) {
|
_this.soundList = [{ id: "", name: "空", path: "" }].concat(res.data.voices)
|
if (_this.editData.type) {
|
_this.initEditData()
|
}
|
}
|
})
|
.catch((e) => console.log(e))
|
},
|
selSound(sound) {
|
this.soundPath = sound.path
|
this.ruleForm.voiceId = sound.id
|
this.togglePlay = true
|
this.eventAudio.pause()
|
this.$forceUpdate()
|
// this.eventAudio.
|
},
|
togglePlayer() {
|
if (!this.soundPath) {
|
this.$notify({
|
type: "info",
|
message: "请先选择一个声音!"
|
})
|
return false
|
}
|
this.eventAudio.src = this.soundPath
|
if (this.togglePlay) {
|
this.eventAudio.play()
|
this.togglePlay = false
|
} else {
|
this.eventAudio.pause()
|
this.togglePlay = true
|
}
|
},
|
close() {
|
this.$emit("close")
|
},
|
save() {
|
this.$refs["form"].validate((valid) => {
|
if (valid) {
|
this.$emit("save", {
|
action: this.editData.type ? "edit" : "add",
|
data: this.ruleForm
|
})
|
} else {
|
return false
|
}
|
})
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.AddBox {
|
position: fixed;
|
top: 0;
|
bottom: 0;
|
right: 0;
|
width: 400px;
|
background-color: #fff;
|
box-shadow: 0px 2px 16px 0px rgba(0, 43, 106, 0.25);
|
|
z-index: 2002;
|
|
.title {
|
box-sizing: border-box;
|
padding: 20px;
|
height: 64px;
|
border-bottom: 1px solid #e9ebee;
|
font-size: 18px;
|
font-weight: 700;
|
}
|
|
.close {
|
position: absolute;
|
top: 20px;
|
right: 20px;
|
font-size: 12px;
|
color: #666;
|
cursor: pointer;
|
}
|
|
.el-form {
|
box-sizing: border-box;
|
padding: 0 20px;
|
|
.label {
|
margin-top: 30px;
|
margin-bottom: 6px;
|
font-size: 14px;
|
color: #666;
|
}
|
|
.left ::v-deep {
|
margin-right: 10px;
|
width: 334px;
|
}
|
|
.iconfont {
|
color: #0065ff;
|
font-size: 16px;
|
cursor: pointer;
|
}
|
}
|
|
.btns {
|
position: absolute;
|
display: flex;
|
align-items: center;
|
left: 0;
|
right: 0;
|
bottom: 0;
|
height: 72px;
|
border-top: 1px solid #e9ebee;
|
text-align: center;
|
line-height: 32px;
|
|
.cancelBtn {
|
width: 60px;
|
height: 32px;
|
border: 1px solid #0064ff;
|
font-size: 14px;
|
color: #0064ff;
|
}
|
|
.confirmBtn {
|
margin-left: 20px;
|
margin-right: 10px;
|
width: 60px;
|
height: 32px;
|
border: 1px solid #0064ff;
|
font-size: 14px;
|
color: #fff;
|
background-color: #0064ff;
|
}
|
}
|
}
|
</style>
|