Commit 6c5105ef8e729c9f4ea850a0f0e75345cbe4593d

Authored by fengtao
1 parent 051f031e

pref:优化告警配置 告警联系人弹窗

... ... @@ -7,22 +7,96 @@
7 7 width="30%"
8 8 @ok="handleSubmit"
9 9 >
10   - <BasicForm @register="registerForm" />
  10 + <BasicForm @register="registerForm">
  11 + <template #alarmContactSlot="{ model, field }">
  12 + <p style="display: none">{{ field }}</p>
  13 + <p>{{ orgFunc(model['organizationId']) }}</p>
  14 + <a-select
  15 + placeholder="请选择告警联系人"
  16 + mode="multiple"
  17 + v-model:value="model[field]"
  18 + style="width: 418px; margin-top: -5px"
  19 + :options="alarmContactOptions.map((item) => ({ value: item.value, label: item.label }))"
  20 + >
  21 + <template #dropdownRender="{ menuNode: menu }">
  22 + <v-nodes :vnodes="menu" />
  23 + <a-divider style="margin: 4px 0" />
  24 + <div @click="handleOpenAlarmContact" style="padding: 4px 8px; cursor: pointer">
  25 + <plus-outlined />
  26 + 新增告警联系人
  27 + </div>
  28 + </template>
  29 + </a-select>
  30 + </template>
  31 + </BasicForm>
11 32 </BasicDrawer>
  33 + <AlarmContactDrawer @register="registerAlarmContactDrawer" @success="handleSuccess" />
12 34 </template>
13 35 <script lang="ts">
14   - import { defineComponent, ref, computed, unref, reactive } from 'vue';
  36 + import { defineComponent, ref, computed, unref, reactive, watch } from 'vue';
15 37 import { BasicForm, useForm } from '/@/components/Form';
16 38 import { formSchema } from './config.data';
17 39 import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
18 40 import { saveOrEditAlarmConfig, byOrgIdGetAlarmContact } from '/@/api/alarm/config/alarmConfig';
19 41 import { useMessage } from '/@/hooks/web/useMessage';
  42 + import { PlusOutlined } from '@ant-design/icons-vue';
  43 + import { useDrawer } from '/@/components/Drawer';
  44 + import AlarmContactDrawer from '../../alarm/contacts/ContactDrawer.vue';
20 45
21 46 export default defineComponent({
22 47 name: 'ContactDrawer',
23   - components: { BasicDrawer, BasicForm },
  48 + components: {
  49 + BasicDrawer,
  50 + BasicForm,
  51 + AlarmContactDrawer,
  52 + PlusOutlined,
  53 + VNodes: (_, { attrs }) => {
  54 + return attrs.vnodes;
  55 + },
  56 + },
24 57 emits: ['success', 'register'],
25 58 setup(_, { emit }) {
  59 + const alarmContactOptions: any = ref([]);
  60 + const orgId = ref('');
  61 + const orgFunc = (e) => {
  62 + orgId.value = e;
  63 + };
  64 + watch(
  65 + () => orgId.value,
  66 + async (newValue: string) => {
  67 + if (newValue) {
  68 + //获取告警联系人
  69 + const res = await byOrgIdGetAlarmContact(newValue);
  70 + if (res) {
  71 + alarmContactOptions.value = res.map((m) => {
  72 + return { label: m.username, value: m.id };
  73 + });
  74 + } else {
  75 + alarmContactOptions.value = [];
  76 + }
  77 + } else {
  78 + alarmContactOptions.value = [];
  79 + }
  80 + }
  81 + );
  82 + const [registerAlarmContactDrawer, { openDrawer }] = useDrawer();
  83 + async function handleSuccess() {
  84 + //获取告警联系人
  85 + const res = await byOrgIdGetAlarmContact(orgId.value);
  86 + if (res) {
  87 + alarmContactOptions.value = res.map((m) => {
  88 + return { label: m.username, value: m.id };
  89 + });
  90 + } else {
  91 + alarmContactOptions.value = [];
  92 + }
  93 + }
  94 + // 新增或编辑
  95 + const handleOpenAlarmContact = () => {
  96 + openDrawer(true, {
  97 + isUpdate: false,
  98 + });
  99 + };
26 100 const isUpdate = ref(true);
27 101 let allData: any = reactive({});
28 102 const editId = ref('');
... ... @@ -112,6 +186,11 @@
112 186 registerDrawer,
113 187 registerForm,
114 188 handleSubmit,
  189 + alarmContactOptions,
  190 + orgFunc,
  191 + handleOpenAlarmContact,
  192 + registerAlarmContactDrawer,
  193 + handleSuccess,
115 194 };
116 195 },
117 196 });
... ...
... ... @@ -2,7 +2,6 @@ import { BasicColumn, FormSchema } from '/@/components/Table';
2 2 import { getOrganizationList } from '/@/api/system/system';
3 3 import { copyTransFun } from '/@/utils/fnUtils';
4 4 import { findDictItemByCode } from '/@/api/system/dict';
5   -import { byOrgIdGetAlarmContact } from '/@/api/alarm/config/alarmConfig';
6 5
7 6 // 表格列数据
8 7 export const columns: BasicColumn[] = [
... ... @@ -101,8 +100,7 @@ export const formSchema: FormSchema[] = [
101 100 label: '所属组织',
102 101 component: 'ApiTreeSelect',
103 102 required: true,
104   - componentProps: ({ formActionType }) => {
105   - const { updateSchema, setFieldsValue } = formActionType;
  103 + componentProps: () => {
106 104 return {
107 105 maxLength: 250,
108 106 placeholder: '请选择所属组织',
... ... @@ -111,25 +109,6 @@ export const formSchema: FormSchema[] = [
111 109 copyTransFun(data as any as any[]);
112 110 return data;
113 111 },
114   - async onChange(e) {
115   - setFieldsValue({
116   - alarmContactId: [],
117   - });
118   - const res = await byOrgIdGetAlarmContact(e);
119   - let opts = [];
120   - if (res.length !== 0) {
121   - opts = res.map((m) => {
122   - return { label: m.username, value: m.id };
123   - });
124   - updateSchema({
125   - field: 'alarmContactId',
126   - componentProps: {
127   - mode: 'multiple',
128   - options: opts,
129   - },
130   - });
131   - }
132   - },
133 112 };
134 113 },
135 114 },
... ... @@ -137,6 +116,7 @@ export const formSchema: FormSchema[] = [
137 116 field: 'alarmContactId',
138 117 label: '告警联系人',
139 118 component: 'Select',
  119 + slot: 'alarmContactSlot',
140 120 required: true,
141 121 },
142 122 {
... ...