ny
23 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<script lang="ts" setup>
import type { FormSchema } from '@jnpf/ui/form';
 
import { computed, reactive, ref, unref } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicForm, useForm } from '@jnpf/ui/form';
import { BasicPopup, usePopupInner } from '@jnpf/ui/popup';
 
import { getInfo as getSendMessageConfig } from '#/api/msgCenter/sendConfig';
import { create, getInfo, update } from '#/api/system/message';
import MsgModal from '#/components/FlowProcess/src/propPanel/components/MsgModal.vue';
import { $t } from '#/locales';
import { useBaseStore } from '#/store';
 
const emit = defineEmits(['register', 'reload']);
const id = ref('');
const state = reactive({
  sendConfigId: '',
  sendConfigName: '',
});
const baseStore = useBaseStore();
const schemas: FormSchema[] = [
  {
    field: 'title',
    label: '标题',
    component: 'Input',
    componentProps: { placeholder: '请输入' },
    rules: [{ required: true, trigger: 'blur', message: '必填' }],
  },
  {
    field: 'toUserIds',
    label: '用户',
    component: 'UsersSelect',
    componentProps: { placeholder: '全部用户', multiple: true },
  },
  {
    field: 'category',
    label: '类型',
    component: 'Select',
    defaultValue: '1',
    componentProps: { placeholder: '请选择', showSearch: true, fieldNames: { value: 'enCode' } },
    rules: [{ required: true, trigger: 'change', message: '必填' }],
    colProps: { span: 12 },
  },
  {
    field: 'expirationTime',
    label: '失效时间',
    helpMessage: '当前时间超过失效时间,状态更新已过期',
    component: 'DatePicker',
    componentProps: { placeholder: '请选择', format: 'YYYY-MM-DD HH:mm:ss' },
    colProps: { span: 12 },
  },
  {
    field: 'files',
    label: '附件',
    component: 'UploadFile',
  },
  {
    field: 'coverImage',
    label: '封面图片',
    helpMessage: '门户公告通知缩略图展示,无设置则系统默认图片',
    component: 'UploadImgSingle',
  },
  {
    field: 'bodyText',
    label: '内容',
    component: 'Editor',
    defaultValue: '',
  },
  {
    field: 'excerpt',
    label: '摘要',
    component: 'Input',
    defaultValue: '',
    componentProps: { placeholder: '请输入' },
  },
  {
    field: 'remindCategory',
    label: '提醒方式',
    component: 'Select',
    defaultValue: 1,
    componentProps: {
      placeholder: '请选择',
      options: [
        { id: 1, fullName: '默认' },
        { id: 2, fullName: '自定义' },
        { id: 3, fullName: '不提醒' },
      ],
      allowClear: false,
    },
    rules: [{ required: true, trigger: 'change', message: '必填', type: 'number' }],
    colProps: { span: 12 },
  },
  {
    ifShow: ({ values }) => values.remindCategory === 2,
    field: 'sendConfigId',
    label: '发送配置',
    component: 'Select',
    slot: 'sendConfigId',
    rules: [{ required: true, trigger: 'change', message: '必填' }],
    colProps: { span: 12 },
  },
];
const getTitle = computed(() => (unref(id) ? $t('common.editText') : $t('common.addText')));
const { createMessage } = useMessage();
const [registerForm, { setFieldsValue, validate, resetFields, updateSchema, clearValidate }] = useForm({ labelWidth: 100, schemas });
const [registerPopup, { closePopup, changeLoading, changeOkLoading }] = usePopupInner(init);
 
async function init(data) {
  resetFields();
  id.value = data.id;
  state.sendConfigId = '';
  state.sendConfigName = '';
  setFieldsValue({
    files: [],
    coverImage: undefined,
  });
  const noticeTypeOptions = (await baseStore.getDictionaryData('NoticeType')) as any[];
  updateSchema({ field: 'category', componentProps: { options: noticeTypeOptions } });
  if (id.value) {
    changeLoading(true);
    getInfo(id.value).then((res) => {
      const data = {
        ...res.data,
        files: res.data.files ? JSON.parse(res.data.files) : [],
        toUserIds: res.data.toUserIds ? res.data.toUserIds.split(',') : [],
      };
      state.sendConfigId = data.sendConfigId || '';
      getSendConfigName();
      setFieldsValue(data);
      changeLoading(false);
    });
  }
}
function onMsgChange(val, row) {
  if (!val) {
    state.sendConfigId = '';
    state.sendConfigName = '';
    setFieldsValue({ sendConfigId: state.sendConfigId });
    return;
  }
  if (state.sendConfigId === val) return;
  state.sendConfigId = val;
  state.sendConfigName = row.fullName;
  setFieldsValue({ sendConfigId: state.sendConfigId });
  clearValidate('sendConfigId');
}
function getSendConfigName() {
  if (!state.sendConfigId) return;
  getSendMessageConfig(state.sendConfigId).then((res) => {
    state.sendConfigName = res.data.fullName;
  });
}
async function handleSubmit() {
  const values = await validate();
  if (!values) return;
  changeOkLoading(true);
  const query = {
    ...values,
    id: id.value,
    files: JSON.stringify(values.files),
    toUserIds: values.toUserIds ? values.toUserIds.join(',') : '',
  };
  const formMethod = id.value ? update : create;
  formMethod(query)
    .then((res) => {
      createMessage.success(res.msg);
      changeOkLoading(false);
      closePopup();
      emit('reload');
    })
    .catch(() => {
      changeOkLoading(false);
    });
}
</script>
<template>
  <BasicPopup v-bind="$attrs" @register="registerPopup" :title="getTitle" show-ok-btn @ok="handleSubmit">
    <a-alert message="提醒方式设置在【消息中心】-【消息发送配置】维护;选择默认则站内信提醒,选择自定义则取自定义模板配置。" type="warning" show-icon />
    <BasicForm @register="registerForm" class="!mt-[10px] !px-[10px]">
      <template #sendConfigId="{ model, field }">
        <MsgModal :value="model[field]" :title="state.sendConfigName" placeholder="请选择" message-source="1" @change="onMsgChange" />
      </template>
    </BasicForm>
  </BasicPopup>
</template>