|
|
@@ -12,6 +12,12 @@ export interface EmailNotifyFormRef {
|
|
|
open: (type: string, id?: number) => void;
|
|
|
}
|
|
|
|
|
|
+// 提醒时长下拉选项:天 0-30,时 0-23,分 0-59,秒 0-59
|
|
|
+const DURATION_DAYS_OPTIONS = Array.from({ length: 31 }, (_, i) => i);
|
|
|
+const DURATION_HOURS_OPTIONS = Array.from({ length: 24 }, (_, i) => i);
|
|
|
+const DURATION_MINUTES_OPTIONS = Array.from({ length: 60 }, (_, i) => i);
|
|
|
+const DURATION_SECONDS_OPTIONS = Array.from({ length: 60 }, (_, i) => i);
|
|
|
+
|
|
|
const EmailNotifyForm = forwardRef<EmailNotifyFormRef, EmailNotifyFormProps>(({ onSuccess }, ref) => {
|
|
|
const { t } = useTranslation();
|
|
|
const [dialogVisible, setDialogVisible] = useState(false);
|
|
|
@@ -21,12 +27,11 @@ const EmailNotifyForm = forwardRef<EmailNotifyFormRef, EmailNotifyFormProps>(({
|
|
|
const [form] = Form.useForm();
|
|
|
const [templateList, setTemplateList] = useState<Array<{ label: string; value: string }>>([]);
|
|
|
|
|
|
- // 时间单位配置
|
|
|
const timeUnits = [
|
|
|
- { name: 'days', label: t('common.day'), options: Array.from({ length: 31 }, (_, i) => i) },
|
|
|
- { name: 'hours', label: t('common.hour'), options: Array.from({ length: 24 }, (_, i) => i) },
|
|
|
- { name: 'minutes', label: t('common.minute'), options: Array.from({ length: 60 }, (_, i) => i) },
|
|
|
- { name: 'seconds', label: t('common.second'), options: Array.from({ length: 60 }, (_, i) => i) },
|
|
|
+ { name: 'days', label: t('common.day'), options: DURATION_DAYS_OPTIONS },
|
|
|
+ { name: 'hours', label: t('common.hour'), options: DURATION_HOURS_OPTIONS },
|
|
|
+ { name: 'minutes', label: t('common.minute'), options: DURATION_MINUTES_OPTIONS },
|
|
|
+ { name: 'seconds', label: t('common.second'), options: DURATION_SECONDS_OPTIONS },
|
|
|
];
|
|
|
|
|
|
const [timeValues, setTimeValues] = useState({
|
|
|
@@ -44,37 +49,53 @@ const EmailNotifyForm = forwardRef<EmailNotifyFormRef, EmailNotifyFormProps>(({
|
|
|
form.resetFields();
|
|
|
setTimeValues({ days: 0, hours: 0, minutes: 0, seconds: 0 });
|
|
|
|
|
|
- // 加载邮件模板列表
|
|
|
+ // 先加载邮件模板列表(编辑时回显模板依赖该列表)
|
|
|
+ let templates: Array<{ label: string; value: string }> = [];
|
|
|
try {
|
|
|
const response = await emailTemplateApi.getMailTemplatePage({
|
|
|
pageNo: 1,
|
|
|
pageSize: -1,
|
|
|
});
|
|
|
- setTemplateList(
|
|
|
- response.list.map((item) => ({
|
|
|
- label: item.name,
|
|
|
- value: item.code,
|
|
|
- }))
|
|
|
- );
|
|
|
+ templates = (response.list || []).map((item) => ({
|
|
|
+ label: item.name,
|
|
|
+ value: item.code,
|
|
|
+ }));
|
|
|
+ setTemplateList(templates);
|
|
|
} catch (error) {
|
|
|
console.error(t('mailTemplate.fetchListFailed'), error);
|
|
|
setTemplateList([]);
|
|
|
}
|
|
|
|
|
|
- // 修改时,设置数据
|
|
|
+ // 修改时,拉取详情并回显(调用 iscs/mail-notify-config/selectMailNotifyConfigById?id=xxx)
|
|
|
+ if (type === 'update' && (id == null || id === undefined)) {
|
|
|
+ message.warning(t('notificationManagement.getEmailListFailed') || '缺少记录 ID,无法加载详情');
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (id) {
|
|
|
setFormLoading(true);
|
|
|
try {
|
|
|
const data = await mailNotifyConfigApi.getIsMailNotifyConfigById(id);
|
|
|
+ if (!data) {
|
|
|
+ message.error(t('notificationManagement.getEmailListFailed'));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const recordId = (data as any).id ?? data.configId;
|
|
|
+ const name = data.name ?? data.configName ?? '';
|
|
|
+ let templateCode = data.templateCode ?? (data as any).templateCode ?? '';
|
|
|
+ if (!templateCode && (data as any).templateName && templates.length > 0) {
|
|
|
+ const byName = templates.find((t) => t.label === (data as any).templateName);
|
|
|
+ if (byName) templateCode = byName.value;
|
|
|
+ }
|
|
|
+ const status = data.status != null ? String(data.status) : '1';
|
|
|
+
|
|
|
form.setFieldsValue({
|
|
|
- configId: data.configId,
|
|
|
- name: data.name || data.configName,
|
|
|
- templateCode: data.templateCode,
|
|
|
- status: data.status || '1',
|
|
|
+ id: recordId,
|
|
|
+ name,
|
|
|
+ templateCode,
|
|
|
+ status,
|
|
|
});
|
|
|
|
|
|
- // 转换时间
|
|
|
- const totalSeconds = data.reminderTime || 0;
|
|
|
+ const totalSeconds = Number(data.reminderTime) || 0;
|
|
|
setTimeValues({
|
|
|
days: Math.floor(totalSeconds / (24 * 60 * 60)),
|
|
|
hours: Math.floor((totalSeconds % (24 * 60 * 60)) / (60 * 60)),
|
|
|
@@ -82,7 +103,7 @@ const EmailNotifyForm = forwardRef<EmailNotifyFormRef, EmailNotifyFormProps>(({
|
|
|
seconds: totalSeconds % 60,
|
|
|
});
|
|
|
} catch (error: any) {
|
|
|
- message.error(error.message || t('notificationManagement.getEmailListFailed'));
|
|
|
+ message.error(error?.message || t('notificationManagement.getEmailListFailed'));
|
|
|
} finally {
|
|
|
setFormLoading(false);
|
|
|
}
|
|
|
@@ -111,10 +132,10 @@ const EmailNotifyForm = forwardRef<EmailNotifyFormRef, EmailNotifyFormProps>(({
|
|
|
|
|
|
if (formType === 'create') {
|
|
|
await mailNotifyConfigApi.addIsMailNotifyConfig(data);
|
|
|
- message.success(t('common.createSuccess'));
|
|
|
+ message.success(t('notificationManagement.addEmailNotifySuccess') || '邮件提醒新增成功');
|
|
|
} else {
|
|
|
await mailNotifyConfigApi.updateIsMailNotifyConfig(data);
|
|
|
- message.success(t('common.updateSuccess'));
|
|
|
+ message.success(t('notificationManagement.updateEmailNotifySuccess') || '邮件提醒保存成功');
|
|
|
}
|
|
|
setDialogVisible(false);
|
|
|
onSuccess?.();
|
|
|
@@ -148,6 +169,9 @@ const EmailNotifyForm = forwardRef<EmailNotifyFormRef, EmailNotifyFormProps>(({
|
|
|
status: '1',
|
|
|
}}
|
|
|
>
|
|
|
+ <Form.Item name="id" hidden>
|
|
|
+ <Input type="hidden" />
|
|
|
+ </Form.Item>
|
|
|
<Form.Item
|
|
|
label={t('notificationManagement.reminderItem')}
|
|
|
name="name"
|