|
|
@@ -0,0 +1,448 @@
|
|
|
+<template>
|
|
|
+ <div class="alarm-config-page">
|
|
|
+ <div class="alarm-config-header">
|
|
|
+ <div class="alarm-config-rollback" @click="router.back()">
|
|
|
+ <img src="../reportmessage/img/rollback.png" /><span>返回</span>
|
|
|
+ </div>
|
|
|
+ <span>{{ formType }}报警配置</span>
|
|
|
+ </div>
|
|
|
+ <div class="alarm-config-content">
|
|
|
+ <div class="alarm-config-form">
|
|
|
+ <el-form
|
|
|
+ ref="formRef"
|
|
|
+ :model="alarmConfigForm"
|
|
|
+ :rules="rules"
|
|
|
+ label-width="auto"
|
|
|
+ :disabled="disableAll"
|
|
|
+ >
|
|
|
+ <el-form-item label="违规类型:" prop="violationType">
|
|
|
+ <el-select
|
|
|
+ class="alarm-config-input"
|
|
|
+ v-model="alarmConfigForm.violationType"
|
|
|
+ placeholder="请选择违规类型"
|
|
|
+ :disabled="disableType"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in AlarmTypes"
|
|
|
+ :key="item.id"
|
|
|
+ :label="item.name"
|
|
|
+ :value="item.id"
|
|
|
+ /></el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="报警等级:" prop="violationLevel">
|
|
|
+ <el-select
|
|
|
+ class="alarm-config-input"
|
|
|
+ v-model="alarmConfigForm.violationLevel"
|
|
|
+ placeholder="请选择报警等级"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in ALARMLEVEL_LIST"
|
|
|
+ :key="item.value"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.value"
|
|
|
+ /></el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="推送渠道:" prop="pushChannel">
|
|
|
+ <el-checkbox-group v-model="(alarmConfigForm.pushChannel as number[])">
|
|
|
+ <el-checkbox
|
|
|
+ v-for="channel in ALARMCHANNEL_LIST"
|
|
|
+ :key="channel.value"
|
|
|
+ :label="channel.label"
|
|
|
+ :value="channel.value"
|
|
|
+ >
|
|
|
+ </el-checkbox>
|
|
|
+ </el-checkbox-group>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="推送阶段:" prop="pushOccasions">
|
|
|
+ <div class="alarm-config-checkbox-group">
|
|
|
+ <!-- v-model="alarmConfigForm.pushOccasions" -->
|
|
|
+ <div v-for="phase in ALARMPHASE_LIST" :key="phase.value">
|
|
|
+ <div
|
|
|
+ v-if="
|
|
|
+ !(phase.value === AlarmPhase.effects && isDevMode) &&
|
|
|
+ alarmConfigForm.pushOccasions
|
|
|
+ "
|
|
|
+ >
|
|
|
+ <el-checkbox
|
|
|
+ v-if="hasInit || route.query.operationType === '1'"
|
|
|
+ :label="phase.label"
|
|
|
+ :checked="alarmConfigForm.pushOccasions.includes(phase.value)"
|
|
|
+ @change="handlePhaseChange(phase.value, $event)"
|
|
|
+ >
|
|
|
+ </el-checkbox>
|
|
|
+ <div
|
|
|
+ v-if="
|
|
|
+ alarmConfigForm.pushPhaseVOList.some((it) => it.pushPhase === phase.value)
|
|
|
+ "
|
|
|
+ >
|
|
|
+ <div class="push-occasions-card">
|
|
|
+ <div style="height: 136px">
|
|
|
+ <PushObject
|
|
|
+ ref="pushObjectRef"
|
|
|
+ :recipientType="alarmConfigForm.pushPhaseVOList.find((it) => it.pushPhase === phase.value)!.recipientType"
|
|
|
+ :userGroupList="(alarmConfigForm.pushPhaseVOList.find((it) => it.pushPhase === phase.value)!.userGroupList as userGroupVOList[])"
|
|
|
+ :customUserList="(alarmConfigForm.pushPhaseVOList.find((it) => it.pushPhase === phase.value)!.customUserList as customUserList[])"
|
|
|
+ :disabled="disableAll"
|
|
|
+ @submit-with-form="
|
|
|
+ handlePhaseSubmit(
|
|
|
+ submitConfigForm.pushPhaseVOList.find(
|
|
|
+ (it) => it.pushPhase === phase.value,
|
|
|
+ )!,
|
|
|
+ $event,
|
|
|
+ )
|
|
|
+ "
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <el-form-item label="自定义内容:">
|
|
|
+ <el-input
|
|
|
+ v-model="
|
|
|
+ alarmConfigForm.pushPhaseVOList.find((it) => it.pushPhase === phase.value)!
|
|
|
+ .content
|
|
|
+ "
|
|
|
+ maxlength="200"
|
|
|
+ resize="none"
|
|
|
+ style="width: 357px"
|
|
|
+ :autosize="{ minRows: 5, maxRows: 5 }"
|
|
|
+ :placeholder="remark"
|
|
|
+ show-word-limit
|
|
|
+ type="textarea"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="创建人:">
|
|
|
+ <el-input class="alarm-config-input" v-model="alarmConfigForm.creator" disabled />
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div style="text-align: right; margin-right: 32px">
|
|
|
+ <el-button :disabled="disableAll" @click="router.back()"> 取 消 </el-button>
|
|
|
+ <el-button :disabled="disableAll" type="primary" @click="debSubmitForm(formRef)">
|
|
|
+ 确 定
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="alarm-config-example">
|
|
|
+ <AlarmExample />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+ import PushObject from '../components/PushObject.vue';
|
|
|
+ import AlarmExample from './components/AlarmExample.vue';
|
|
|
+ import {
|
|
|
+ ElForm,
|
|
|
+ ElFormItem,
|
|
|
+ ElSelect,
|
|
|
+ ElCheckboxGroup,
|
|
|
+ ElCheckbox,
|
|
|
+ ElInput,
|
|
|
+ ElMessage,
|
|
|
+ FormInstance,
|
|
|
+ FormRules,
|
|
|
+ } from 'element-plus';
|
|
|
+ import { ref, watch, onMounted, computed } from 'vue';
|
|
|
+ import { useUserStore } from '@/store/modules/user';
|
|
|
+ import { useRouter, useRoute } from 'vue-router';
|
|
|
+ import {
|
|
|
+ getAlarmConfigDetail,
|
|
|
+ getExistingAlarmType,
|
|
|
+ getDevMode,
|
|
|
+ addAlarmConfig,
|
|
|
+ editAlarmConfig,
|
|
|
+ type AlarmConfigForm,
|
|
|
+ type PushPhaseVOList,
|
|
|
+ // type UserGroupVOItem,
|
|
|
+ // type CustomUserItem,
|
|
|
+ type AvailableAlarmType,
|
|
|
+ } from '@/api/message/message';
|
|
|
+ import {
|
|
|
+ // AlarmLevel,
|
|
|
+ ALARMLEVEL_LIST,
|
|
|
+ // AlarmChannel,
|
|
|
+ ALARMCHANNEL_LIST,
|
|
|
+ AlarmPhase,
|
|
|
+ ALARMPHASE_LIST,
|
|
|
+ } from './types';
|
|
|
+ import { type userGroupVOList, type customUserList } from '../components/PushObject.vue';
|
|
|
+ import _ from 'lodash-es';
|
|
|
+
|
|
|
+ const useUser = useUserStore();
|
|
|
+ const router = useRouter();
|
|
|
+ const route = useRoute();
|
|
|
+ const hasInit = ref(false);
|
|
|
+ const AlarmTypes = ref<AvailableAlarmType[]>([]);
|
|
|
+
|
|
|
+ const remark = computed(() => {
|
|
|
+ return (
|
|
|
+ '您好,智能检测到该车间发生【' +
|
|
|
+ AlarmTypes.value.find((it) => it.id === alarmConfigForm.value.violationType)?.name +
|
|
|
+ '】违规问题,请及时关注并前往处理!'
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
+ const alarmConfigForm = ref<AlarmConfigForm>({
|
|
|
+ violationType: undefined,
|
|
|
+ violationLevel: '',
|
|
|
+ pushChannel: [],
|
|
|
+ pushOccasions: [],
|
|
|
+ pushPhaseVOList: [],
|
|
|
+ creator: useUser.info.nickname,
|
|
|
+ });
|
|
|
+
|
|
|
+ const submitConfigForm = ref<AlarmConfigForm>({
|
|
|
+ alarmMessageId: undefined,
|
|
|
+ violationType: undefined,
|
|
|
+ violationLevel: '',
|
|
|
+ pushChannel: [],
|
|
|
+ pushPhaseVOList: [],
|
|
|
+ });
|
|
|
+
|
|
|
+ // 获取报警配置详情
|
|
|
+ const getAlarmDetail = (configId) => {
|
|
|
+ getAlarmConfigDetail(configId).then((res) => {
|
|
|
+ alarmConfigForm.value.violationType = res.violationType;
|
|
|
+ alarmConfigForm.value.violationLevel = res.violationLevel;
|
|
|
+ alarmConfigForm.value.pushChannel = JSON.parse(res.pushChannel as string);
|
|
|
+ alarmConfigForm.value.pushPhaseVOList = _.cloneDeep(res.pushPhaseVOList);
|
|
|
+ submitConfigForm.value.pushPhaseVOList = _.cloneDeep(res.pushPhaseVOList);
|
|
|
+ alarmConfigForm.value.pushOccasions = res.pushPhaseVOList.map((it) => it.pushPhase);
|
|
|
+ hasInit.value = true;
|
|
|
+
|
|
|
+ // 获取的配置填入违规类型
|
|
|
+ AlarmTypes.value.push({
|
|
|
+ id: res.violationType,
|
|
|
+ name: res.violationName,
|
|
|
+ } as AvailableAlarmType);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const pushObjectRef = ref();
|
|
|
+ const formType = ref('');
|
|
|
+ const disableType = ref(false);
|
|
|
+ const disableAll = ref(false);
|
|
|
+ const isDevMode = ref(false);
|
|
|
+
|
|
|
+ onMounted(() => {
|
|
|
+ getDevMode().then((res) => {
|
|
|
+ isDevMode.value = res;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!route.query.operationType) {
|
|
|
+ router.back();
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (route.query.operationType) {
|
|
|
+ case '1':
|
|
|
+ formType.value = '新建';
|
|
|
+ getExistingAlarmType().then((res) => {
|
|
|
+ AlarmTypes.value = res;
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case '2':
|
|
|
+ formType.value = '编辑';
|
|
|
+ disableType.value = true;
|
|
|
+ getAlarmDetail(route.query.alarmConfigId);
|
|
|
+ break;
|
|
|
+ case '3':
|
|
|
+ formType.value = '查看';
|
|
|
+ disableAll.value = true;
|
|
|
+ getAlarmDetail(route.query.alarmConfigId);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ watch(
|
|
|
+ () => alarmConfigForm.value.pushOccasions,
|
|
|
+ () => {
|
|
|
+ if (!alarmConfigForm.value.pushOccasions) return;
|
|
|
+ alarmConfigForm.value.pushOccasions.forEach((occasion) => {
|
|
|
+ if (!alarmConfigForm.value.pushPhaseVOList.some((it) => it.pushPhase === occasion)) {
|
|
|
+ alarmConfigForm.value.pushPhaseVOList.push({
|
|
|
+ pushPhase: occasion,
|
|
|
+ recipientType: undefined,
|
|
|
+ content: '',
|
|
|
+ });
|
|
|
+ submitConfigForm.value.pushPhaseVOList.push({
|
|
|
+ pushPhase: occasion,
|
|
|
+ recipientType: undefined,
|
|
|
+ content: '',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ alarmConfigForm.value.pushPhaseVOList.forEach((vo) => {
|
|
|
+ if (!alarmConfigForm.value.pushOccasions?.some((occ) => occ === vo.pushPhase)) {
|
|
|
+ alarmConfigForm.value.pushPhaseVOList.splice(
|
|
|
+ alarmConfigForm.value.pushPhaseVOList.findIndex((it) => it.pushPhase === vo.pushPhase),
|
|
|
+ 1,
|
|
|
+ );
|
|
|
+ submitConfigForm.value.pushPhaseVOList.splice(
|
|
|
+ submitConfigForm.value.pushPhaseVOList.findIndex((it) => it.pushPhase === vo.pushPhase),
|
|
|
+ 1,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ {
|
|
|
+ deep: true,
|
|
|
+ },
|
|
|
+ );
|
|
|
+
|
|
|
+ const formRef = ref<FormInstance>();
|
|
|
+
|
|
|
+ const rules = ref<FormRules<AlarmConfigForm>>({
|
|
|
+ violationType: [{ required: true, message: '请选择违规类型', trigger: 'blur' }],
|
|
|
+ violationLevel: [{ required: true, message: '请选择违规等级', trigger: 'blur' }],
|
|
|
+ pushChannel: [{ required: true, message: '请选择推送渠道', trigger: 'change' }],
|
|
|
+ pushOccasions: [{ required: true, message: '请选择推送阶段', trigger: 'change' }],
|
|
|
+ pushPhaseVOList: [{ required: true, message: '请选择推送人员', trigger: 'change' }],
|
|
|
+ });
|
|
|
+
|
|
|
+ const handlePhaseChange = (occasion: number, e) => {
|
|
|
+ if (!alarmConfigForm.value.pushOccasions) return;
|
|
|
+
|
|
|
+ if (e) {
|
|
|
+ if (!alarmConfigForm.value.pushOccasions.includes(occasion)) {
|
|
|
+ alarmConfigForm.value.pushOccasions.push(occasion);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (alarmConfigForm.value.pushOccasions.includes(occasion)) {
|
|
|
+ alarmConfigForm.value.pushOccasions.splice(
|
|
|
+ alarmConfigForm.value.pushOccasions.findIndex((it) => it === occasion),
|
|
|
+ 1,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const handlePhaseSubmit = (phaseForm: PushPhaseVOList, childValue) => {
|
|
|
+ phaseForm.recipientType = childValue.recipientType;
|
|
|
+ switch (childValue.recipientType) {
|
|
|
+ case 1:
|
|
|
+ delete phaseForm.userGroupList;
|
|
|
+ delete phaseForm.customUserList;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ delete phaseForm.customUserList;
|
|
|
+ phaseForm.userGroupList = childValue.userGroupList;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ delete phaseForm.userGroupList;
|
|
|
+ phaseForm.customUserList = childValue.customUserList;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 提交表单
|
|
|
+ const submitForm = async (formEl: FormInstance | undefined) => {
|
|
|
+ if (!formEl) return;
|
|
|
+ formEl.validate((valid, fields) => {
|
|
|
+ if (valid) {
|
|
|
+ const fns = pushObjectRef.value.map((x) => {
|
|
|
+ return x.validateForm();
|
|
|
+ });
|
|
|
+ Promise.all(fns)
|
|
|
+ .then(() => {
|
|
|
+ submitConfigForm.value.violationLevel = alarmConfigForm.value.violationLevel;
|
|
|
+ submitConfigForm.value.pushChannel = alarmConfigForm.value.pushChannel;
|
|
|
+ alarmConfigForm.value.pushPhaseVOList.forEach((vo) => {
|
|
|
+ submitConfigForm.value.pushPhaseVOList.find(
|
|
|
+ (it) => it.pushPhase === vo.pushPhase,
|
|
|
+ )!.content = vo.content || remark.value;
|
|
|
+ });
|
|
|
+ switch (route.query.operationType) {
|
|
|
+ case '1':
|
|
|
+ delete submitConfigForm.value.alarmMessageId;
|
|
|
+ submitConfigForm.value.violationType = alarmConfigForm.value.violationType;
|
|
|
+ addAlarmConfig(submitConfigForm.value)
|
|
|
+ .then(() => {
|
|
|
+ ElMessage.success('新建成功');
|
|
|
+ router.back();
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ ElMessage.error('新建失败', e);
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case '2':
|
|
|
+ delete submitConfigForm.value.violationType;
|
|
|
+ submitConfigForm.value.alarmMessageId = +route.query.alarmConfigId!;
|
|
|
+ editAlarmConfig(submitConfigForm.value)
|
|
|
+ .then(() => {
|
|
|
+ ElMessage.success('编辑成功');
|
|
|
+ router.back();
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ ElMessage.error('编辑失败', e);
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ console.log('表单校验未通过', e);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ console.log('表单校验未通过', fields);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+ const debSubmitForm = _.debounce(submitForm, 500);
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped lang="scss">
|
|
|
+ .alarm-config-page {
|
|
|
+ background-color: rgba(255, 255, 255, 1);
|
|
|
+ .alarm-config-header {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ padding: 16px 0 15px 20px;
|
|
|
+ border-bottom: 1px solid #e9e9e9;
|
|
|
+ .alarm-config-rollback {
|
|
|
+ width: 60px;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .alarm-config-content {
|
|
|
+ display: flex;
|
|
|
+ height: calc(100vh - 137px);
|
|
|
+
|
|
|
+ .alarm-config-form {
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ justify-content: space-between;
|
|
|
+ padding: 20px 0 32px 32px;
|
|
|
+ width: 803px;
|
|
|
+ border-right: 1px solid rgba(0, 0, 0, 0.06);
|
|
|
+ overflow-y: auto;
|
|
|
+
|
|
|
+ .alarm-config-input {
|
|
|
+ max-width: 446px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .alarm-config-checkbox-group {
|
|
|
+ max-height: 556px;
|
|
|
+ overflow: auto;
|
|
|
+
|
|
|
+ .push-occasions-card {
|
|
|
+ padding: 10px 20px;
|
|
|
+ width: 572px;
|
|
|
+ height: 283px;
|
|
|
+ background-color: #fafafa;
|
|
|
+ font-size: 16px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .alarm-config-example {
|
|
|
+ flex: 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+</style>
|