edit.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. <template>
  2. <div class="system-edit-dic-container">
  3. <el-dialog :title="(ruleForm.id !== 0 ? '修改' : '添加') + '告警'" v-model="isShowDialog" width="50%">
  4. <el-form :model="ruleForm" ref="formRef" :rules="rules" size="default" label-width="110px">
  5. <el-form-item label="名称" prop="name">
  6. <el-input v-model="ruleForm.name" placeholder="请输入名称" />
  7. </el-form-item>
  8. <el-form-item label="告警级别" prop="level">
  9. <el-radio-group v-model="ruleForm.level">
  10. <el-radio :label="item.level" v-for="item in levelData">{{ item.name }}</el-radio>
  11. </el-radio-group>
  12. </el-form-item>
  13. <el-form-item label="选择产品" prop="productKey">
  14. <el-select v-model="ruleForm.productKey" filterable placeholder="请选择产品" @change="setType()">
  15. <el-option v-for="item in productData" :key="item.key" :label="item.name" :value="item.key">
  16. <span style="float: left">{{ item.name }}</span>
  17. <span style="float: right; font-size: 13px">{{ item.key }}</span>
  18. </el-option>
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item label="选择设备" prop="deviceKey">
  22. <el-select v-model="ruleForm.deviceKey" filterable placeholder="请选择设备">
  23. <el-option v-for="item in sourceData" :key="item.key" :label="item.name" :value="item.key">
  24. <span style="float: left">{{ item.name }}</span>
  25. <span style="float: right; font-size: 13px">{{ item.key }}</span>
  26. </el-option>
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item label="触发方式" prop="triggerType" v-if="ruleForm.productKey">
  30. <el-radio-group v-model="ruleForm.triggerType" @change="getRadio()">
  31. <el-radio :label="item.type" v-for="item in typeData">{{ item.title }}</el-radio>
  32. </el-radio-group>
  33. </el-form-item>
  34. <el-divider content-position="left">触发条件</el-divider>
  35. <div class="box-content">
  36. <div v-for="(item, index) in requestParams" :key="index">
  37. <div style="text-align: center" v-if="index > 0">
  38. <el-icon><Top /></el-icon>
  39. <div>
  40. <el-select v-model="item.andOr" placeholder="选择条件关系">
  41. <el-option label="无" :value="0" />
  42. <el-option label="并且" :value="1" />
  43. <el-option label="或" :value="2" />
  44. </el-select>
  45. </div>
  46. <el-icon><Bottom /></el-icon>
  47. </div>
  48. <div
  49. style="
  50. padding: 10px;
  51. border: 1px solid var(--next-border-color-light);
  52. background-color: var(--next-border-color-light);
  53. margin-bottom: 10px;
  54. position: relative;
  55. "
  56. >
  57. <div class="conicon" style="width: 100%; text-align: right; position: absolute; right: -8px; top: -8px; color: red">
  58. <el-icon @click="delParams(index)"><CircleClose /></el-icon>
  59. </div>
  60. <div style="display: flex">
  61. <el-divider content-position="left">参数设置</el-divider>
  62. </div>
  63. <div v-for="(aaa, bbb) in item.filters" :key="bbb">
  64. <div style="text-align: center" v-if="bbb > 0">
  65. <el-icon><Top /></el-icon>
  66. <div>
  67. <el-select v-model="aaa.andOr" placeholder="选择条件关系" style="width: 150px">
  68. <el-option label="无" :value="0" />
  69. <el-option label="并且" :value="1" />
  70. <el-option label="或" :value="2" />
  71. </el-select>
  72. </div>
  73. <el-icon><Bottom /></el-icon>
  74. </div>
  75. <div class="content-f">
  76. <el-select v-model="aaa.key" placeholder="选择参数" style="width: 320px">
  77. <el-option v-for="a in triData" :key="a.paramKey" :label="a.title" :value="a.paramKey" />
  78. </el-select>
  79. <el-select v-model="aaa.operator" placeholder="选择操作符" style="width: 320px">
  80. <el-option v-for="b in operData" :key="b.type" :label="b.title" :value="b.type" />
  81. </el-select>
  82. <el-input v-model="aaa.value" placeholder="请输入条件值" style="width: 320px" />
  83. <div class="conicon">
  84. <el-icon @click="delParamss(index, bbb)"><Delete /></el-icon>
  85. </div>
  86. </div>
  87. </div>
  88. <el-button type="primary" class="addbutton" @click="addParams(index)">增加条件</el-button>
  89. </div>
  90. </div>
  91. </div>
  92. <el-button type="success" class="addbutton" @click="addParamss">增加分组</el-button>
  93. <el-divider content-position="left">执行动作</el-divider>
  94. <div class="box-content">
  95. <div v-for="(item, index) in action" :key="index">
  96. <div
  97. style="
  98. padding: 10px;
  99. border: 1px solid var(--next-border-color-light);
  100. background-color: var(--next-border-color-light);
  101. margin-bottom: 10px;
  102. position: relative;
  103. "
  104. >
  105. <div class="conicon" style="width: 100%; text-align: right; position: absolute; right: -8px; top: -8px; color: red">
  106. <el-icon @click="delAction(index)"><CircleClose /></el-icon>
  107. </div>
  108. <div style="display: flex">
  109. <el-divider content-position="left">消息通知</el-divider>
  110. </div>
  111. <div class="content-f">
  112. <el-select v-model="item.sendGateway" placeholder="请选择通知方式" style="width: 320px" @change="getNode(item.sendGateway, index)">
  113. <el-option v-for="a in notice_send_gateway" :key="a.value" :label="a.label" :value="a.value" />
  114. </el-select>
  115. <el-select v-model="item.noticeConfig" placeholder="请选择通知配置" style="width: 320px" @change="getTem(item.noticeConfig, index)">
  116. <el-option v-for="b in sendGatewayData[index]" :key="b.id" :label="b.title" :value="b.id" />
  117. </el-select>
  118. <el-select v-model="item.noticeTemplate" placeholder="请选择通知模板" style="width: 320px">
  119. <el-option v-for="c in noticeConfigData[index]" :key="c.id" :label="c.title" :value="c.id" />
  120. </el-select>
  121. </div>
  122. <div>
  123. <div style="display: flex; margin-bottom: 10px" v-for="(ph, phindex) in item.addressee" :key="phindex">
  124. <el-input v-model="ph.phone" placeholder="请输入接收人信息" style="width: 320px" />
  125. <el-icon style="width: 32px; height: 32px; font-size: 24px" v-if="phindex == 0" @click="AddPhone(index)"><CirclePlus /></el-icon>
  126. <el-icon style="width: 32px; height: 32px; font-size: 24px" v-if="phindex > 0" @click="DelPhone(index, phindex)"
  127. ><Remove
  128. /></el-icon>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. <el-button type="success" class="addbutton" @click="addAction">增加执行</el-button>
  135. </el-form>
  136. <template #footer>
  137. <span class="dialog-footer">
  138. <el-button @click="onCancel" size="default">取 消</el-button>
  139. <el-button type="primary" @click="onSubmit" size="default">{{ ruleForm.id !== 0 ? '修 改' : '添 加' }}</el-button>
  140. </span>
  141. </template>
  142. </el-dialog>
  143. </div>
  144. </template>
  145. <script lang="ts">
  146. import { reactive, toRefs, defineComponent, ref, unref, getCurrentInstance } from 'vue';
  147. import api from '/@/api/datahub';
  148. import iotapi from '/@/api/device';
  149. import alarm from '/@/api/alarm';
  150. import notice from '/@/api/notice';
  151. import { ElMessage } from 'element-plus';
  152. import { Delete, Plus, CircleClose, Top, Bottom, Minus, Right, CirclePlus, Remove } from '@element-plus/icons-vue';
  153. interface RuleFormState {
  154. id: number;
  155. name: string;
  156. triggerType: number;
  157. level: string;
  158. productKey: string;
  159. deviceKey: string;
  160. triggerCondition: string;
  161. }
  162. interface DicState {
  163. isShowDialog: boolean;
  164. ruleForm: RuleFormState;
  165. rules: {};
  166. sourceData: [];
  167. productData: [];
  168. typeData: [];
  169. triData: [];
  170. operData: [];
  171. levelData: [];
  172. requestParams: {};
  173. triggerCondition: {};
  174. action: {};
  175. tempData: {};
  176. sendGatewayData: {};
  177. noticeConfigData: {};
  178. }
  179. export default defineComponent({
  180. name: 'Edit',
  181. components: { Delete, Plus, CircleClose, Minus, Right, Top, Bottom, CirclePlus, Remove },
  182. setup(prop, { emit }) {
  183. const myRef = ref<HTMLElement | null>(null);
  184. const formRef = ref<HTMLElement | null>(null);
  185. const { proxy } = getCurrentInstance() as any;
  186. const { notice_send_gateway } = proxy.useDict('notice_send_gateway');
  187. const state = reactive<DicState>({
  188. id: 0,
  189. isShowDialog: false,
  190. sourceData: [],
  191. tempData: [],
  192. productData: [],
  193. typeData: [],
  194. triData: [],
  195. operData: [],
  196. levelData: [],
  197. sendGatewayData: [],
  198. noticeConfigData: [],
  199. action: [
  200. {
  201. sendGateway: '',
  202. noticeConfig: '',
  203. noticeTemplate: '',
  204. addressee: [
  205. {
  206. phone: '',
  207. },
  208. ],
  209. },
  210. ],
  211. requestParams: [
  212. {
  213. andOr: '',
  214. filters: [
  215. {
  216. key: '',
  217. operator: '',
  218. value: '',
  219. andOr: 0,
  220. },
  221. ],
  222. },
  223. ],
  224. ruleForm: {
  225. id: 0,
  226. name: '',
  227. triggerType: 1,
  228. level: '',
  229. productKey: '',
  230. deviceKey: '',
  231. action: [
  232. {
  233. sendGateway: '',
  234. noticeConfig: '',
  235. noticeTemplate: '',
  236. addressee: {},
  237. },
  238. ],
  239. triggerCondition: [
  240. {
  241. andOr: '',
  242. filters: [
  243. {
  244. key: '',
  245. operator: '',
  246. value: '',
  247. andOr: 0,
  248. },
  249. ],
  250. },
  251. ],
  252. },
  253. rules: {
  254. name: [{ required: true, message: '告警名称不能为空', trigger: 'blur' }],
  255. level: [{ required: true, message: '告警级别不能为空', trigger: 'blur' }],
  256. productKey: [{ required: true, message: '请选择产品', trigger: 'blur' }],
  257. deviceKey: [{ required: true, message: '请选择设备', trigger: 'blur' }],
  258. },
  259. });
  260. // 打开弹窗
  261. const openDialog = (row: RuleFormState | null) => {
  262. resetForm();
  263. getDevData();
  264. if (row) {
  265. alarm.common.detail(row.id).then((res: any) => {
  266. state.requestParams = res.data.condition.triggerCondition;
  267. res.data.performAction.action.forEach(function (value, index) {
  268. notice.config.getList({ sendGateway: value.sendGateway }).then((res: any) => {
  269. state.sendGatewayData[index] = res.Data;
  270. });
  271. if(value.noticeConfig){
  272. notice.template.configIddetail(value.noticeConfig).then((res: any) => {
  273. state.noticeConfigData[index] = [res];
  274. });
  275. }
  276. });
  277. state.action = res.data.performAction.action;
  278. state.action.forEach(function (value, index) {
  279. state.action[index].addressee = value.addressee.map((p) => {
  280. return { phone: p };
  281. });
  282. });
  283. state.ruleForm = res.data;
  284. setType();
  285. });
  286. }
  287. state.isShowDialog = true;
  288. };
  289. //获取设备列表
  290. const getDevData = () => {
  291. iotapi.product.getLists({ status: 1 }).then((res: any) => {
  292. state.productData = res.product || [];
  293. });
  294. alarm.common.levelall('').then((res: any) => {
  295. state.levelData = res.list || [];
  296. });
  297. alarm.common.operator('').then((res: any) => {
  298. state.operData = res.list || [];
  299. });
  300. };
  301. const resetForm = () => {
  302. state.requestParams = [
  303. {
  304. andOr: '',
  305. filters: [
  306. {
  307. key: '',
  308. operator: '',
  309. value: '',
  310. andOr: 0,
  311. },
  312. ],
  313. },
  314. ];
  315. state.action = [
  316. {
  317. sendGateway: '',
  318. noticeConfig: '',
  319. noticeTemplate: '',
  320. addressee: [
  321. {
  322. phone: '',
  323. },
  324. ],
  325. },
  326. ];
  327. state.ruleForm = {
  328. id: 0,
  329. name: '',
  330. triggerType: 1,
  331. level: '',
  332. productKey: '',
  333. deviceKey: '',
  334. action: [
  335. {
  336. sendGateway: '',
  337. noticeConfig: '',
  338. noticeTemplate: '',
  339. addressee: {},
  340. },
  341. ],
  342. triggerCondition: [
  343. {
  344. andOr: '',
  345. filters: [
  346. {
  347. key: '',
  348. operator: '',
  349. value: '',
  350. andOr: 0,
  351. },
  352. ],
  353. },
  354. ],
  355. };
  356. };
  357. // 关闭弹窗
  358. const closeDialog = () => {
  359. state.isShowDialog = false;
  360. };
  361. // 取消
  362. const onCancel = () => {
  363. closeDialog();
  364. };
  365. // 新增
  366. const onSubmit = () => {
  367. const formWrap = unref(formRef) as any;
  368. if (!formWrap) return;
  369. formWrap.validate((valid: boolean) => {
  370. if (valid) {
  371. state.ruleForm.triggerCondition = state.requestParams;
  372. state.action.forEach(function (value, index) {
  373. state.action[index].addressee = value.addressee.map((p) => {
  374. return p.phone;
  375. });
  376. });
  377. state.ruleForm.action = state.action;
  378. if (state.ruleForm.id !== 0) {
  379. //修改
  380. alarm.common.edit(state.ruleForm).then(() => {
  381. ElMessage.success('告警修改成功');
  382. closeDialog(); // 关闭弹窗
  383. emit('typeList');
  384. });
  385. } else {
  386. //添加
  387. alarm.common.add(state.ruleForm).then(() => {
  388. ElMessage.success('告警添加成功');
  389. closeDialog(); // 关闭弹窗
  390. emit('dataList');
  391. });
  392. }
  393. }
  394. });
  395. };
  396. const AddPhone = (index) => {
  397. state.action[index].addressee.push({
  398. phone: '',
  399. });
  400. };
  401. const DelPhone = (index, bbb) => {
  402. state.action[index].addressee.splice(bbb, 1);
  403. };
  404. const addAction = () => {
  405. state.action.push({
  406. sendGateway: '',
  407. noticeConfig: '',
  408. noticeTemplate: '',
  409. addressee: [
  410. {
  411. phone: '',
  412. },
  413. ],
  414. });
  415. };
  416. const delAction = (index) => {
  417. state.action.splice(index, 1);
  418. };
  419. const delParams = (index) => {
  420. state.requestParams.splice(index, 1);
  421. };
  422. const delParamss = (index, bbb) => {
  423. state.requestParams[index].filters.splice(bbb, 1);
  424. };
  425. const addParamss = () => {
  426. state.requestParams.push({
  427. andOr: '',
  428. filters: [
  429. {
  430. key: '',
  431. operator: '',
  432. value: '',
  433. andOr: '',
  434. },
  435. ],
  436. });
  437. };
  438. const addParams = (index) => {
  439. state.requestParams[index].filters.push({
  440. key: '',
  441. operator: '',
  442. value: '',
  443. andOr: '',
  444. });
  445. };
  446. const setType = () => {
  447. let product_id = 0;
  448. state.productData.forEach((item, index) => {
  449. if (item.key == state.ruleForm.productKey) {
  450. product_id = item.id;
  451. }
  452. });
  453. api.common.getdevList({ productId: product_id }).then((res: any) => {
  454. state.sourceData = res.device;
  455. });
  456. alarm.common.trigger_type(state.ruleForm.productKey).then((res: any) => {
  457. state.typeData = res.list || [];
  458. });
  459. gettriData();
  460. };
  461. const getRadio=()=>{
  462. gettriData();
  463. }
  464. const gettriData=()=>{
  465. alarm.common.trigger_params({productKey:state.ruleForm.productKey,triggerType:state.ruleForm.triggerType}).then((res: any) => {
  466. state.triData = res.list || [];
  467. });
  468. }
  469. const getNode = (event, index) => {
  470. state.action[index].noticeConfig = '';
  471. notice.config.getList({ sendGateway: event }).then((res: any) => {
  472. state.sendGatewayData[index] = res.Data;
  473. });
  474. };
  475. const getTem = (event, index) => {
  476. state.action[index].noticeTemplate = '';
  477. notice.template.configIddetail(event).then((res: any) => {
  478. state.noticeConfigData[index] = [res];
  479. });
  480. };
  481. return {
  482. getRadio,
  483. gettriData,
  484. getTem,
  485. getNode,
  486. delAction,
  487. addAction,
  488. AddPhone,
  489. DelPhone,
  490. setType,
  491. addParams,
  492. addParamss,
  493. delParamss,
  494. delParams,
  495. openDialog,
  496. closeDialog,
  497. getDevData,
  498. onCancel,
  499. onSubmit,
  500. formRef,
  501. notice_send_gateway,
  502. myRef,
  503. ...toRefs(state),
  504. };
  505. },
  506. });
  507. </script>
  508. <style>
  509. .inline {
  510. display: inline-flex;
  511. }
  512. .el-input__wrapper {
  513. width: 98%;
  514. }
  515. .box-content {
  516. border: 1px solid #e8e8e8;
  517. margin: 10px;
  518. padding: 10px;
  519. }
  520. .content-f {
  521. display: flex;
  522. margin-bottom: 10px;
  523. }
  524. .content-f .el-input__wrapper {
  525. margin-right: 5px;
  526. }
  527. .addbutton {
  528. width: 100%;
  529. margin-top: 10px;
  530. background: #fff;
  531. border: 1px solid #d1d1d1;
  532. color: #8d8b8b;
  533. }
  534. .conicon {
  535. width: 55px;
  536. height: 25px;
  537. font-size: 28px;
  538. line-height: 28px;
  539. cursor: pointer;
  540. }
  541. .jv-node {
  542. margin-left: 25px;
  543. }
  544. </style>