2023-10-09 16:27:44 +08:00
|
|
|
<!--
|
|
|
|
filename: EquipmentDrawer.vue
|
|
|
|
author: liubin
|
|
|
|
date: 2023-08-22 14:38:56
|
|
|
|
description:
|
|
|
|
-->
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<el-drawer
|
|
|
|
:visible="visible"
|
|
|
|
:show-close="false"
|
|
|
|
:wrapper-closable="false"
|
|
|
|
class="drawer"
|
|
|
|
custom-class="mes-drawer"
|
|
|
|
size="60%"
|
|
|
|
@closed="$emit('destroy')">
|
|
|
|
<SmallTitle slot="title">
|
|
|
|
{{
|
|
|
|
mode.includes('detail')
|
|
|
|
? '详情'
|
|
|
|
: mode.includes('edit')
|
|
|
|
? '编辑'
|
|
|
|
: '新增'
|
|
|
|
}}
|
|
|
|
</SmallTitle>
|
|
|
|
|
|
|
|
<div class="drawer-body flex">
|
|
|
|
<div class="drawer-body__content">
|
|
|
|
<section v-for="(section, index) in sections" :key="section.key">
|
|
|
|
<SmallTitle v-if="index != 0">{{ section.name }}</SmallTitle>
|
|
|
|
|
|
|
|
<div class="form-part" v-if="section.key == 'base'">
|
|
|
|
<el-skeleton v-if="!showForm" animated />
|
2023-10-10 09:40:22 +08:00
|
|
|
<BaseInfoForm
|
2023-10-09 16:27:44 +08:00
|
|
|
key="drawer-dialog-form"
|
|
|
|
v-if="showForm"
|
|
|
|
ref="form"
|
2023-10-10 09:40:22 +08:00
|
|
|
:disabled="mode.includes('detail')"
|
2023-10-09 16:27:44 +08:00
|
|
|
:dataForm="form"
|
|
|
|
:rows="formRows" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="section.key == 'attrs'" style="margin-top: 12px">
|
|
|
|
<base-table
|
|
|
|
v-loading="attrListLoading"
|
|
|
|
:table-props="section.props"
|
2023-10-09 17:01:19 +08:00
|
|
|
:page="attrQuery?.params.pageNo || 1"
|
|
|
|
:limit="attrQuery?.params.pageSize || 10"
|
2023-10-09 16:27:44 +08:00
|
|
|
:table-data="list"
|
|
|
|
:add-button-show="mode.includes('detail') ? null : '添加属性'"
|
|
|
|
@emitButtonClick="handleAddAttr"
|
|
|
|
@emitFun="handleEmitFun">
|
|
|
|
<method-btn
|
|
|
|
v-if="section.tableBtn"
|
|
|
|
slot="handleBtn"
|
|
|
|
label="操作"
|
|
|
|
:method-list="tableBtn"
|
|
|
|
@clickBtn="handleTableBtnClick" />
|
|
|
|
</base-table>
|
|
|
|
|
|
|
|
<!-- 分页组件 -->
|
|
|
|
<pagination
|
|
|
|
v-show="total > 0"
|
|
|
|
:total="total"
|
|
|
|
:page.sync="attrQuery.params.pageNo"
|
|
|
|
:limit.sync="attrQuery.params.pageSize"
|
|
|
|
@pagination="getAttrList" />
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="drawer-body__footer">
|
2023-10-10 14:22:00 +08:00
|
|
|
<el-button style="" @click="handleCancel">取消</el-button>
|
2023-10-09 16:27:44 +08:00
|
|
|
<el-button v-if="mode == 'detail'" type="primary" @click="toggleEdit">
|
|
|
|
编辑
|
|
|
|
</el-button>
|
2023-10-10 14:22:00 +08:00
|
|
|
<el-button v-else type="primary" @click="handleCancel">确定</el-button>
|
2023-10-10 09:40:22 +08:00
|
|
|
<!-- sections的第二项必须是 属性列表 -->
|
|
|
|
<!-- <el-button
|
2023-10-09 16:27:44 +08:00
|
|
|
v-if="sections[1].allowAdd"
|
|
|
|
type="primary"
|
|
|
|
@click="handleAddAttr">
|
|
|
|
添加属性
|
2023-10-10 09:40:22 +08:00
|
|
|
</el-button> -->
|
2023-10-09 16:27:44 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- 属性对话框 -->
|
|
|
|
<base-dialog
|
|
|
|
v-if="sections[1].allowAdd"
|
|
|
|
:dialogTitle="attrTitle"
|
|
|
|
:dialogVisible="attrFormVisible"
|
|
|
|
width="45%"
|
|
|
|
:append-to-body="true"
|
|
|
|
custom-class="baseDialog"
|
|
|
|
@close="closeAttrForm"
|
|
|
|
@cancel="closeAttrForm"
|
|
|
|
@confirm="submitAttrForm">
|
|
|
|
<DialogForm
|
|
|
|
v-if="attrFormVisible"
|
|
|
|
ref="attrForm"
|
2023-10-10 09:40:22 +08:00
|
|
|
:disabled="mode.includes('detail')"
|
|
|
|
v-model="attrForm"
|
2023-10-09 16:27:44 +08:00
|
|
|
:rows="attrRows" />
|
|
|
|
</base-dialog>
|
|
|
|
</el-drawer>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-10-10 09:40:22 +08:00
|
|
|
import BaseInfoForm from '@/components/DialogForm';
|
2023-10-09 17:01:19 +08:00
|
|
|
import DialogForm from './dialogForm';
|
2023-10-09 16:27:44 +08:00
|
|
|
|
|
|
|
const SmallTitle = {
|
|
|
|
name: 'SmallTitle',
|
|
|
|
props: ['size'],
|
|
|
|
data() {
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
methods: {},
|
|
|
|
render: function (h) {
|
|
|
|
return h(
|
|
|
|
'span',
|
|
|
|
{
|
|
|
|
class: 'small-title',
|
|
|
|
style: {
|
|
|
|
fontSize: '18px',
|
|
|
|
lineHeight:
|
|
|
|
this.size == 'lg' ? '24px' : this.size == 'sm' ? '18px' : '20px',
|
|
|
|
fontWeight: 500,
|
|
|
|
fontFamily: '微软雅黑, Microsoft YaHei, Arial, Helvetica, sans-serif',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
this.$slots.default
|
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
2023-10-10 09:40:22 +08:00
|
|
|
components: { SmallTitle, DialogForm, BaseInfoForm },
|
2023-10-09 17:01:19 +08:00
|
|
|
props: ['sections', 'defaultMode', 'dataId'], // dataId 作为一个通用的存放id的字段
|
2023-10-09 16:27:44 +08:00
|
|
|
data() {
|
|
|
|
return {
|
2023-10-09 17:01:19 +08:00
|
|
|
mode: '',
|
2023-10-09 16:27:44 +08:00
|
|
|
visible: false,
|
|
|
|
showForm: false,
|
|
|
|
total: 0,
|
|
|
|
form: {},
|
|
|
|
list: [],
|
|
|
|
attrTitle: '',
|
|
|
|
attrForm: {
|
|
|
|
id: null,
|
2023-10-10 09:40:22 +08:00
|
|
|
equipmentGroupId: '',
|
|
|
|
code: '',
|
|
|
|
type: '',
|
|
|
|
grade: '',
|
|
|
|
alarmCode: '',
|
|
|
|
alarmContent: '',
|
|
|
|
plcParamName: '',
|
2023-10-09 16:27:44 +08:00
|
|
|
},
|
|
|
|
attrFormVisible: false,
|
|
|
|
attrRows: [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
input: true,
|
|
|
|
label: '报警编码', // 自动生成
|
|
|
|
prop: 'code',
|
|
|
|
url: '/base/equipment-group-alarm/getCode',
|
|
|
|
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
select: true,
|
|
|
|
label: '报警类型', // 固定选项
|
|
|
|
prop: 'type',
|
|
|
|
options: [
|
|
|
|
{ label: '布尔型', value: 2 },
|
|
|
|
{ label: '字符型', value: 1 },
|
|
|
|
],
|
|
|
|
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
select: true,
|
|
|
|
label: '报警级别', // 字典
|
|
|
|
prop: 'grade',
|
|
|
|
options: this.getDictDatas(this.DICT_TYPE.EQU_ALARM_LEVEL),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: true,
|
|
|
|
label: '设备报警编码', // 对应到设备实际的报警编码
|
|
|
|
prop: 'alarmCode',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
input: true,
|
|
|
|
label: '参数列名', // 在实时数据库的列名
|
|
|
|
prop: 'plcParamName',
|
|
|
|
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: true,
|
|
|
|
label: '报警内容',
|
|
|
|
prop: 'alarmContent',
|
|
|
|
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
2023-10-09 17:01:19 +08:00
|
|
|
attrQuery: {
|
|
|
|
params: {
|
|
|
|
pageNo: 1,
|
2023-10-10 09:40:22 +08:00
|
|
|
pageSize: 10,
|
|
|
|
},
|
2023-10-09 17:01:19 +08:00
|
|
|
}, // 属性列表的请求
|
2023-10-09 16:27:44 +08:00
|
|
|
infoQuery: null, // 基本信息的请求
|
|
|
|
attrFormSubmitting: false,
|
|
|
|
attrListLoading: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
formRows() {
|
|
|
|
return this.sections[0].rows.map((row) => {
|
|
|
|
return row.map((col) => {
|
|
|
|
return {
|
|
|
|
...col,
|
|
|
|
bind: {
|
|
|
|
// 详情 模式下,禁用各种输入
|
2023-10-10 14:22:00 +08:00
|
|
|
// disabled: this.mode == 'detail',
|
|
|
|
disabled: true
|
2023-10-09 16:27:44 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
tableBtn() {
|
|
|
|
return this.mode == 'detail' ? [] : this.sections[1].tableBtn;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
2023-10-09 17:01:19 +08:00
|
|
|
this.mode = this.defaultMode || 'detail';
|
2023-10-09 16:27:44 +08:00
|
|
|
for (const section of this.sections) {
|
|
|
|
// 请求具体信息
|
|
|
|
if ('url' in section) {
|
|
|
|
const query = {
|
|
|
|
url: section.url,
|
|
|
|
method: section.method || 'get',
|
|
|
|
params: section.queryParams || null,
|
|
|
|
data: section.data || null,
|
|
|
|
};
|
|
|
|
// debugger;
|
|
|
|
this.$axios(query).then(({ data }) => {
|
|
|
|
if (section.key == 'base') {
|
|
|
|
this.form = data;
|
|
|
|
this.showForm = true;
|
|
|
|
this.infoQuery = query;
|
|
|
|
} else if (section.key == 'attrs') {
|
|
|
|
this.attrQuery = query;
|
|
|
|
this.list = data.list;
|
|
|
|
this.total = data.total;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleTableBtnClick({ type, data }) {
|
|
|
|
switch (type) {
|
|
|
|
case 'edit':
|
|
|
|
this.handleEditAttr(data.id);
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
this.handleDeleteAttr(data.id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEmitFun(val) {
|
|
|
|
console.log('handleEmitFun', val);
|
|
|
|
},
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this.visible = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
async getAttrList() {
|
|
|
|
this.attrListLoading = true;
|
|
|
|
const res = await this.$axios(this.attrQuery);
|
|
|
|
if (res.code == 0) {
|
|
|
|
this.list = res.data.list;
|
|
|
|
this.total = res.data.total;
|
|
|
|
}
|
|
|
|
this.attrListLoading = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
// 保存表单
|
|
|
|
handleSave() {
|
|
|
|
this.$refs['form'][0].validate(async (valid) => {
|
|
|
|
if (valid) {
|
|
|
|
const isEdit = this.mode == 'edit';
|
|
|
|
await this.$axios({
|
|
|
|
url: this.sections[0][isEdit ? 'urlUpdate' : 'urlCreate'],
|
|
|
|
method: isEdit ? 'put' : 'post',
|
|
|
|
data: this.form,
|
|
|
|
});
|
|
|
|
this.$modal.msgSuccess(`${isEdit ? '更新' : '创建'}成功`);
|
|
|
|
this.visible = false;
|
|
|
|
this.$emit('refreshDataList');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
handleCancel() {
|
|
|
|
this.visible = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
// 开启编辑
|
|
|
|
toggleEdit() {
|
|
|
|
this.mode = 'edit';
|
|
|
|
},
|
|
|
|
|
|
|
|
// 新增属性
|
|
|
|
handleAddAttr() {
|
2023-10-10 09:40:22 +08:00
|
|
|
if (!this.dataId) return this.$message.error('请先创建设备分组信息');
|
2023-10-09 16:27:44 +08:00
|
|
|
this.attrForm = {
|
|
|
|
id: null,
|
2023-10-10 09:40:22 +08:00
|
|
|
equipmentGroupId: this.dataId,
|
|
|
|
code: '',
|
|
|
|
type: '',
|
|
|
|
grade: '',
|
|
|
|
alarmCode: '',
|
|
|
|
alarmContent: '',
|
|
|
|
plcParamName: '',
|
2023-10-09 16:27:44 +08:00
|
|
|
};
|
2023-10-10 09:40:22 +08:00
|
|
|
this.attrTitle = '添加设备分组报警';
|
2023-10-09 16:27:44 +08:00
|
|
|
this.attrFormVisible = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
// 编辑属性
|
|
|
|
async handleEditAttr(attrId) {
|
|
|
|
const res = await this.$axios({
|
|
|
|
url: this.sections[1].urlDetail,
|
|
|
|
method: 'get',
|
|
|
|
params: { id: attrId },
|
|
|
|
});
|
|
|
|
if (res.code == 0) {
|
|
|
|
this.attrForm = res.data;
|
2023-10-10 09:40:22 +08:00
|
|
|
this.attrTitle = '编辑设备分组报警';
|
2023-10-09 16:27:44 +08:00
|
|
|
this.attrFormVisible = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// 删除属性
|
|
|
|
handleDeleteAttr(attrId) {
|
2023-10-10 09:40:22 +08:00
|
|
|
this.$confirm('确定删除该分组报警?', '提示', {
|
2023-10-09 16:27:44 +08:00
|
|
|
confirmButtonText: '确定',
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
type: 'warning',
|
|
|
|
})
|
|
|
|
.then(async () => {
|
|
|
|
const res = await this.$axios({
|
|
|
|
url: this.sections[1].urlDelete,
|
|
|
|
method: 'delete',
|
|
|
|
params: { id: attrId },
|
|
|
|
});
|
|
|
|
if (res.code == 0) {
|
|
|
|
this.$message({
|
|
|
|
message: '删除成功',
|
|
|
|
type: 'success',
|
|
|
|
duration: 1500,
|
|
|
|
onClose: () => {
|
|
|
|
this.getAttrList();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
},
|
|
|
|
|
|
|
|
// 提交属性表
|
|
|
|
async submitAttrForm() {
|
|
|
|
this.$refs['attrForm'].validate((valid) => {
|
|
|
|
if (!valid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const isEdit = this.attrForm.id != null;
|
|
|
|
this.attrFormSubmitting = true;
|
|
|
|
const res = await this.$axios({
|
|
|
|
url: isEdit ? this.sections[1].urlUpdate : this.sections[1].urlCreate,
|
|
|
|
method: isEdit ? 'put' : 'post',
|
|
|
|
data: this.attrForm,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (res.code == 0) {
|
|
|
|
this.closeAttrForm();
|
|
|
|
this.$message({
|
|
|
|
message: `${isEdit ? '更新' : '创建'}成功`,
|
|
|
|
type: 'success',
|
|
|
|
duration: 1500,
|
|
|
|
onClose: () => {
|
|
|
|
this.getAttrList();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.attrFormSubmitting = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
closeAttrForm() {
|
|
|
|
this.attrFormVisible = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
handleClick(raw) {
|
|
|
|
if (raw.type === 'delete') {
|
2023-10-10 09:40:22 +08:00
|
|
|
this.$confirm(`确定删除该报警?`, '提示', {
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
type: 'warning',
|
|
|
|
})
|
2023-10-09 16:27:44 +08:00
|
|
|
.then(() => {
|
|
|
|
deleteProductAttr(raw.data.id).then(({ data }) => {
|
|
|
|
this.$message({
|
|
|
|
message: '操作成功',
|
|
|
|
type: 'success',
|
|
|
|
duration: 1500,
|
|
|
|
onClose: () => {
|
|
|
|
this.getList();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
} else {
|
|
|
|
this.addNew(raw.data.id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.drawer >>> .el-drawer {
|
|
|
|
border-radius: 8px 0 0 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.drawer >>> .el-drawer__header {
|
|
|
|
margin: 0;
|
|
|
|
padding: 32px 32px 24px;
|
|
|
|
border-bottom: 1px solid #dcdfe6;
|
|
|
|
margin-bottom: 0px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.small-title::before {
|
|
|
|
content: '';
|
|
|
|
display: inline-block;
|
|
|
|
vertical-align: top;
|
|
|
|
width: 4px;
|
|
|
|
height: 22px;
|
|
|
|
border-radius: 1px;
|
|
|
|
margin-right: 8px;
|
|
|
|
background-color: #0b58ff;
|
|
|
|
}
|
|
|
|
|
|
|
|
.drawer-body {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.drawer-body__content {
|
|
|
|
flex: 1;
|
|
|
|
/* background: #eee; */
|
|
|
|
padding: 20px 30px;
|
|
|
|
overflow-y: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.drawer-body__footer {
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
padding: 18px;
|
|
|
|
}
|
|
|
|
</style>
|