123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593 |
- <template>
- <div class="system-edit-dic-container">
- <el-dialog :title="(ruleForm.id !== 0 ? '修改' : '添加') + '告警'" v-model="isShowDialog" width="50%">
- <el-form :model="ruleForm" ref="formRef" :rules="rules" size="default" label-width="110px">
- <el-form-item label="名称" prop="name">
- <el-input v-model="ruleForm.name" placeholder="请输入名称" />
- </el-form-item>
- <el-form-item label="告警级别" prop="level">
- <el-radio-group v-model="ruleForm.level">
- <el-radio :label="item.level" v-for="item in levelData">{{ item.name }}</el-radio>
- </el-radio-group>
- </el-form-item>
- <el-form-item label="选择产品" prop="productKey">
- <el-select v-model="ruleForm.productKey" filterable placeholder="请选择产品" @change="setType()">
- <el-option v-for="item in productData" :key="item.key" :label="item.name" :value="item.key">
- <span style="float: left">{{ item.name }}</span>
- <span style="float: right; font-size: 13px">{{ item.key }}</span>
- </el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="选择设备" prop="deviceKey">
- <el-select v-model="ruleForm.deviceKey" filterable placeholder="请选择设备">
- <el-option v-for="item in sourceData" :key="item.key" :label="item.name" :value="item.key">
- <span style="float: left">{{ item.name }}</span>
- <span style="float: right; font-size: 13px">{{ item.key }}</span>
- </el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="触发方式" prop="triggerType" v-if="ruleForm.productKey">
- <el-radio-group v-model="ruleForm.triggerType" @change="getRadio()">
- <el-radio :label="item.type" v-for="item in typeData">{{ item.title }}</el-radio>
- </el-radio-group>
- </el-form-item>
- <el-divider content-position="left">触发条件</el-divider>
- <div class="box-content">
- <div v-for="(item, index) in requestParams" :key="index">
- <div style="text-align: center" v-if="index > 0">
- <el-icon><Top /></el-icon>
- <div>
- <el-select v-model="item.andOr" placeholder="选择条件关系">
- <el-option label="无" :value="0" />
- <el-option label="并且" :value="1" />
- <el-option label="或" :value="2" />
- </el-select>
- </div>
- <el-icon><Bottom /></el-icon>
- </div>
- <div
- style="
- padding: 10px;
- border: 1px solid var(--next-border-color-light);
- background-color: var(--next-border-color-light);
- margin-bottom: 10px;
- position: relative;
- "
- >
- <div class="conicon" style="width: 100%; text-align: right; position: absolute; right: -8px; top: -8px; color: red">
- <el-icon @click="delParams(index)"><CircleClose /></el-icon>
- </div>
- <div style="display: flex">
- <el-divider content-position="left">参数设置</el-divider>
- </div>
- <div v-for="(aaa, bbb) in item.filters" :key="bbb">
- <div style="text-align: center" v-if="bbb > 0">
- <el-icon><Top /></el-icon>
- <div>
- <el-select v-model="aaa.andOr" placeholder="选择条件关系" style="width: 150px">
- <el-option label="无" :value="0" />
- <el-option label="并且" :value="1" />
- <el-option label="或" :value="2" />
- </el-select>
- </div>
- <el-icon><Bottom /></el-icon>
- </div>
- <div class="content-f">
- <el-select v-model="aaa.key" placeholder="选择参数" style="width: 320px">
- <el-option v-for="a in triData" :key="a.paramKey" :label="a.title" :value="a.paramKey" />
- </el-select>
- <el-select v-model="aaa.operator" placeholder="选择操作符" style="width: 320px">
- <el-option v-for="b in operData" :key="b.type" :label="b.title" :value="b.type" />
- </el-select>
- <el-input v-model="aaa.value" placeholder="请输入条件值" style="width: 320px" />
- <div class="conicon">
- <el-icon @click="delParamss(index, bbb)"><Delete /></el-icon>
- </div>
- </div>
- </div>
- <el-button type="primary" class="addbutton" @click="addParams(index)">增加条件</el-button>
- </div>
- </div>
- </div>
- <el-button type="success" class="addbutton" @click="addParamss">增加分组</el-button>
- <el-divider content-position="left">执行动作</el-divider>
- <div class="box-content">
- <div v-for="(item, index) in action" :key="index">
- <div
- style="
- padding: 10px;
- border: 1px solid var(--next-border-color-light);
- background-color: var(--next-border-color-light);
- margin-bottom: 10px;
- position: relative;
- "
- >
- <div class="conicon" style="width: 100%; text-align: right; position: absolute; right: -8px; top: -8px; color: red">
- <el-icon @click="delAction(index)"><CircleClose /></el-icon>
- </div>
- <div style="display: flex">
- <el-divider content-position="left">消息通知</el-divider>
- </div>
- <div class="content-f">
- <el-select v-model="item.sendGateway" placeholder="请选择通知方式" style="width: 320px" @change="getNode(item.sendGateway, index)">
- <el-option v-for="a in notice_send_gateway" :key="a.value" :label="a.label" :value="a.value" />
- </el-select>
- <el-select v-model="item.noticeConfig" placeholder="请选择通知配置" style="width: 320px" @change="getTem(item.noticeConfig, index)">
- <el-option v-for="b in sendGatewayData[index]" :key="b.id" :label="b.title" :value="b.id" />
- </el-select>
- <el-select v-model="item.noticeTemplate" placeholder="请选择通知模板" style="width: 320px">
- <el-option v-for="c in noticeConfigData[index]" :key="c.id" :label="c.title" :value="c.id" />
- </el-select>
- </div>
- <div>
- <div style="display: flex; margin-bottom: 10px" v-for="(ph, phindex) in item.addressee" :key="phindex">
- <el-input v-model="ph.phone" placeholder="请输入接收人信息" style="width: 320px" />
- <el-icon style="width: 32px; height: 32px; font-size: 24px" v-if="phindex == 0" @click="AddPhone(index)"><CirclePlus /></el-icon>
- <el-icon style="width: 32px; height: 32px; font-size: 24px" v-if="phindex > 0" @click="DelPhone(index, phindex)"
- ><Remove
- /></el-icon>
- </div>
- </div>
- </div>
- </div>
- </div>
- <el-button type="success" class="addbutton" @click="addAction">增加执行</el-button>
- </el-form>
- <template #footer>
- <span class="dialog-footer">
- <el-button @click="onCancel" size="default">取 消</el-button>
- <el-button type="primary" @click="onSubmit" size="default">{{ ruleForm.id !== 0 ? '修 改' : '添 加' }}</el-button>
- </span>
- </template>
- </el-dialog>
- </div>
- </template>
- <script lang="ts">
- import { reactive, toRefs, defineComponent, ref, unref, getCurrentInstance } from 'vue';
- import api from '/@/api/datahub';
- import iotapi from '/@/api/device';
- import alarm from '/@/api/alarm';
- import notice from '/@/api/notice';
- import { ElMessage } from 'element-plus';
- import { Delete, Plus, CircleClose, Top, Bottom, Minus, Right, CirclePlus, Remove } from '@element-plus/icons-vue';
- interface RuleFormState {
- id: number;
- name: string;
- triggerType: number;
- level: string;
- productKey: string;
- deviceKey: string;
- triggerCondition: string;
- }
- interface DicState {
- isShowDialog: boolean;
- ruleForm: RuleFormState;
- rules: {};
- sourceData: [];
- productData: [];
- typeData: [];
- triData: [];
- operData: [];
- levelData: [];
- requestParams: {};
- triggerCondition: {};
- action: {};
- tempData: {};
- sendGatewayData: {};
- noticeConfigData: {};
- }
- export default defineComponent({
- name: 'Edit',
- components: { Delete, Plus, CircleClose, Minus, Right, Top, Bottom, CirclePlus, Remove },
- setup(prop, { emit }) {
- const myRef = ref<HTMLElement | null>(null);
- const formRef = ref<HTMLElement | null>(null);
- const { proxy } = getCurrentInstance() as any;
- const { notice_send_gateway } = proxy.useDict('notice_send_gateway');
- const state = reactive<DicState>({
- id: 0,
- isShowDialog: false,
- sourceData: [],
- tempData: [],
- productData: [],
- typeData: [],
- triData: [],
- operData: [],
- levelData: [],
- sendGatewayData: [],
- noticeConfigData: [],
- action: [
- {
- sendGateway: '',
- noticeConfig: '',
- noticeTemplate: '',
- addressee: [
- {
- phone: '',
- },
- ],
- },
- ],
- requestParams: [
- {
- andOr: '',
- filters: [
- {
- key: '',
- operator: '',
- value: '',
- andOr: 0,
- },
- ],
- },
- ],
- ruleForm: {
- id: 0,
- name: '',
- triggerType: 1,
- level: '',
- productKey: '',
- deviceKey: '',
- action: [
- {
- sendGateway: '',
- noticeConfig: '',
- noticeTemplate: '',
- addressee: {},
- },
- ],
- triggerCondition: [
- {
- andOr: '',
- filters: [
- {
- key: '',
- operator: '',
- value: '',
- andOr: 0,
- },
- ],
- },
- ],
- },
- rules: {
- name: [{ required: true, message: '告警名称不能为空', trigger: 'blur' }],
- level: [{ required: true, message: '告警级别不能为空', trigger: 'blur' }],
- productKey: [{ required: true, message: '请选择产品', trigger: 'blur' }],
- deviceKey: [{ required: true, message: '请选择设备', trigger: 'blur' }],
- },
- });
- // 打开弹窗
- const openDialog = (row: RuleFormState | null) => {
- resetForm();
- getDevData();
- if (row) {
- alarm.common.detail(row.id).then((res: any) => {
- state.requestParams = res.data.condition.triggerCondition;
- res.data.performAction.action.forEach(function (value, index) {
- notice.config.getList({ sendGateway: value.sendGateway }).then((res: any) => {
- state.sendGatewayData[index] = res.Data;
- });
- if(value.noticeConfig){
- notice.template.configIddetail(value.noticeConfig).then((res: any) => {
- state.noticeConfigData[index] = [res];
- });
- }
- });
- state.action = res.data.performAction.action;
- state.action.forEach(function (value, index) {
- state.action[index].addressee = value.addressee.map((p) => {
- return { phone: p };
- });
- });
- state.ruleForm = res.data;
- setType();
- });
- }
- state.isShowDialog = true;
- };
- //获取设备列表
- const getDevData = () => {
- iotapi.product.getLists({ status: 1 }).then((res: any) => {
- state.productData = res.product || [];
- });
- alarm.common.levelall('').then((res: any) => {
- state.levelData = res.list || [];
- });
- alarm.common.operator('').then((res: any) => {
- state.operData = res.list || [];
- });
- };
- const resetForm = () => {
- state.requestParams = [
- {
- andOr: '',
- filters: [
- {
- key: '',
- operator: '',
- value: '',
- andOr: 0,
- },
- ],
- },
- ];
- state.action = [
- {
- sendGateway: '',
- noticeConfig: '',
- noticeTemplate: '',
- addressee: [
- {
- phone: '',
- },
- ],
- },
- ];
- state.ruleForm = {
- id: 0,
- name: '',
- triggerType: 1,
- level: '',
- productKey: '',
- deviceKey: '',
- action: [
- {
- sendGateway: '',
- noticeConfig: '',
- noticeTemplate: '',
- addressee: {},
- },
- ],
- triggerCondition: [
- {
- andOr: '',
- filters: [
- {
- key: '',
- operator: '',
- value: '',
- andOr: 0,
- },
- ],
- },
- ],
- };
- };
- // 关闭弹窗
- const closeDialog = () => {
- state.isShowDialog = false;
- };
- // 取消
- const onCancel = () => {
- closeDialog();
- };
- // 新增
- const onSubmit = () => {
- const formWrap = unref(formRef) as any;
- if (!formWrap) return;
- formWrap.validate((valid: boolean) => {
- if (valid) {
- state.ruleForm.triggerCondition = state.requestParams;
- state.action.forEach(function (value, index) {
- state.action[index].addressee = value.addressee.map((p) => {
- return p.phone;
- });
- });
- state.ruleForm.action = state.action;
- if (state.ruleForm.id !== 0) {
- //修改
- alarm.common.edit(state.ruleForm).then(() => {
- ElMessage.success('告警修改成功');
- closeDialog(); // 关闭弹窗
- emit('typeList');
- });
- } else {
- //添加
- alarm.common.add(state.ruleForm).then(() => {
- ElMessage.success('告警添加成功');
- closeDialog(); // 关闭弹窗
- emit('dataList');
- });
- }
- }
- });
- };
- const AddPhone = (index) => {
- state.action[index].addressee.push({
- phone: '',
- });
- };
- const DelPhone = (index, bbb) => {
- state.action[index].addressee.splice(bbb, 1);
- };
- const addAction = () => {
- state.action.push({
- sendGateway: '',
- noticeConfig: '',
- noticeTemplate: '',
- addressee: [
- {
- phone: '',
- },
- ],
- });
- };
- const delAction = (index) => {
- state.action.splice(index, 1);
- };
- const delParams = (index) => {
- state.requestParams.splice(index, 1);
- };
- const delParamss = (index, bbb) => {
- state.requestParams[index].filters.splice(bbb, 1);
- };
- const addParamss = () => {
- state.requestParams.push({
- andOr: '',
- filters: [
- {
- key: '',
- operator: '',
- value: '',
- andOr: '',
- },
- ],
- });
- };
- const addParams = (index) => {
- state.requestParams[index].filters.push({
- key: '',
- operator: '',
- value: '',
- andOr: '',
- });
- };
- const setType = () => {
- let product_id = 0;
- state.productData.forEach((item, index) => {
- if (item.key == state.ruleForm.productKey) {
- product_id = item.id;
- }
- });
- api.common.getdevList({ productId: product_id }).then((res: any) => {
- state.sourceData = res.device;
- });
- alarm.common.trigger_type(state.ruleForm.productKey).then((res: any) => {
- state.typeData = res.list || [];
- });
- gettriData();
-
- };
- const getRadio=()=>{
- gettriData();
- }
- const gettriData=()=>{
- alarm.common.trigger_params({productKey:state.ruleForm.productKey,triggerType:state.ruleForm.triggerType}).then((res: any) => {
- state.triData = res.list || [];
- });
- }
- const getNode = (event, index) => {
- state.action[index].noticeConfig = '';
- notice.config.getList({ sendGateway: event }).then((res: any) => {
- state.sendGatewayData[index] = res.Data;
- });
- };
- const getTem = (event, index) => {
- state.action[index].noticeTemplate = '';
- notice.template.configIddetail(event).then((res: any) => {
- state.noticeConfigData[index] = [res];
- });
- };
- return {
- getRadio,
- gettriData,
- getTem,
- getNode,
- delAction,
- addAction,
- AddPhone,
- DelPhone,
- setType,
- addParams,
- addParamss,
- delParamss,
- delParams,
- openDialog,
- closeDialog,
- getDevData,
- onCancel,
- onSubmit,
- formRef,
- notice_send_gateway,
- myRef,
- ...toRefs(state),
- };
- },
- });
- </script>
- <style>
- .inline {
- display: inline-flex;
- }
- .el-input__wrapper {
- width: 98%;
- }
- .box-content {
- border: 1px solid #e8e8e8;
- margin: 10px;
- padding: 10px;
- }
- .content-f {
- display: flex;
- margin-bottom: 10px;
- }
- .content-f .el-input__wrapper {
- margin-right: 5px;
- }
- .addbutton {
- width: 100%;
- margin-top: 10px;
- background: #fff;
- border: 1px solid #d1d1d1;
- color: #8d8b8b;
- }
- .conicon {
- width: 55px;
- height: 25px;
- font-size: 28px;
- line-height: 28px;
- cursor: pointer;
- }
- .jv-node {
- margin-left: 25px;
- }
- </style>
-
|