|
@@ -1,5 +1,5 @@
|
|
|
import React, { useState, useImperativeHandle, forwardRef } from 'react';
|
|
import React, { useState, useImperativeHandle, forwardRef } from 'react';
|
|
|
-import { Modal, Form, Input, Select, TreeSelect, Row, Col, message } from 'antd';
|
|
|
|
|
|
|
+import { Modal, Form, Input, Select, TreeSelect, Row, Col, message, DatePicker } from 'antd';
|
|
|
import { userApi } from '../../api/user';
|
|
import { userApi } from '../../api/user';
|
|
|
import { deptApi } from '../../api/dept';
|
|
import { deptApi } from '../../api/dept';
|
|
|
import { postApi, PostVO } from '../../api/Post';
|
|
import { postApi, PostVO } from '../../api/Post';
|
|
@@ -8,11 +8,27 @@ import { getIntDictOptions, DICT_TYPE, setDictOptions, DictDataType } from '../.
|
|
|
import { handleTree } from '../../utils/tree';
|
|
import { handleTree } from '../../utils/tree';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
import { dictDataApi } from '../../api/DictData';
|
|
import { dictDataApi } from '../../api/DictData';
|
|
|
|
|
+import dayjs, { Dayjs } from 'dayjs';
|
|
|
|
|
|
|
|
const { TextArea } = Input;
|
|
const { TextArea } = Input;
|
|
|
|
|
+const LONG_TERM_EXPIRE_TIME = '2099-12-31 00:00:00';
|
|
|
|
|
+
|
|
|
|
|
+const toDayjsValue = (value?: Date | string | number): Dayjs | undefined => {
|
|
|
|
|
+ if (!value && value !== 0) {
|
|
|
|
|
+ return undefined;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const normalizedValue =
|
|
|
|
|
+ typeof value === 'string' && /^\d+$/.test(value.trim())
|
|
|
|
|
+ ? Number(value)
|
|
|
|
|
+ : value;
|
|
|
|
|
+
|
|
|
|
|
+ const dayjsValue = dayjs(normalizedValue);
|
|
|
|
|
+ return dayjsValue.isValid() ? dayjsValue : undefined;
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
interface UserFormProps {
|
|
interface UserFormProps {
|
|
|
- onSuccess?: () => void;
|
|
|
|
|
|
|
+ onSuccess?: (type: 'create' | 'update') => void;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface UserFormRef {
|
|
export interface UserFormRef {
|
|
@@ -143,6 +159,7 @@ const UserForm = forwardRef<UserFormRef, UserFormProps>(({ onSuccess }, ref) =>
|
|
|
workstationIds: userData.postIds || userData.workstationIds || [],
|
|
workstationIds: userData.postIds || userData.workstationIds || [],
|
|
|
deptId: userData.deptId,
|
|
deptId: userData.deptId,
|
|
|
sex: sexValue, // 使用处理后的性别值
|
|
sex: sexValue, // 使用处理后的性别值
|
|
|
|
|
+ expireTime: toDayjsValue(userData.expireTime),
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
console.log('设置表单值 - 性别:', {
|
|
console.log('设置表单值 - 性别:', {
|
|
@@ -173,13 +190,17 @@ const UserForm = forwardRef<UserFormRef, UserFormProps>(({ onSuccess }, ref) =>
|
|
|
const submitForm = async () => {
|
|
const submitForm = async () => {
|
|
|
try {
|
|
try {
|
|
|
const values = await form.validateFields();
|
|
const values = await form.validateFields();
|
|
|
|
|
+ const normalizedValues = {
|
|
|
|
|
+ ...values,
|
|
|
|
|
+ expireTime: values.expireTime ? values.expireTime.format('YYYY-MM-DD HH:mm:ss') : undefined,
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
setFormLoading(true);
|
|
setFormLoading(true);
|
|
|
try {
|
|
try {
|
|
|
if (formType === 'create') {
|
|
if (formType === 'create') {
|
|
|
// 新增模式下,处理字段名映射:workstationIds -> postIds
|
|
// 新增模式下,处理字段名映射:workstationIds -> postIds
|
|
|
const createData: any = {
|
|
const createData: any = {
|
|
|
- ...values,
|
|
|
|
|
|
|
+ ...normalizedValues,
|
|
|
};
|
|
};
|
|
|
// 将 workstationIds 映射为 postIds
|
|
// 将 workstationIds 映射为 postIds
|
|
|
if (createData.workstationIds) {
|
|
if (createData.workstationIds) {
|
|
@@ -196,9 +217,9 @@ const UserForm = forwardRef<UserFormRef, UserFormProps>(({ onSuccess }, ref) =>
|
|
|
// 保留原始数据中的字段(这些字段用户不能编辑但需要传递)
|
|
// 保留原始数据中的字段(这些字段用户不能编辑但需要传递)
|
|
|
...(originalUserData || {}),
|
|
...(originalUserData || {}),
|
|
|
// 用表单数据覆盖可编辑字段
|
|
// 用表单数据覆盖可编辑字段
|
|
|
- ...values,
|
|
|
|
|
|
|
+ ...normalizedValues,
|
|
|
// 确保 id 存在
|
|
// 确保 id 存在
|
|
|
- id: originalUserData?.id || values.id,
|
|
|
|
|
|
|
+ id: originalUserData?.id || normalizedValues.id,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 如果密码为空,则移除密码字段
|
|
// 如果密码为空,则移除密码字段
|
|
@@ -235,7 +256,7 @@ const UserForm = forwardRef<UserFormRef, UserFormProps>(({ onSuccess }, ref) =>
|
|
|
message.success(t('form.updateSuccess'));
|
|
message.success(t('form.updateSuccess'));
|
|
|
}
|
|
}
|
|
|
setDialogVisible(false);
|
|
setDialogVisible(false);
|
|
|
- onSuccess?.();
|
|
|
|
|
|
|
+ onSuccess?.(formType);
|
|
|
} catch (error: any) {
|
|
} catch (error: any) {
|
|
|
message.error(error.message || t('form.operationFailed'));
|
|
message.error(error.message || t('form.operationFailed'));
|
|
|
} finally {
|
|
} finally {
|
|
@@ -418,7 +439,37 @@ const UserForm = forwardRef<UserFormRef, UserFormProps>(({ onSuccess }, ref) =>
|
|
|
</Form.Item>
|
|
</Form.Item>
|
|
|
</Col>
|
|
</Col>
|
|
|
<Col span={12}>
|
|
<Col span={12}>
|
|
|
- <Form.Item label={t('form.remark')} name="remark">
|
|
|
|
|
|
|
+ <Form.Item
|
|
|
|
|
+ label={t('form.expireTime')}
|
|
|
|
|
+ name="expireTime"
|
|
|
|
|
+ rules={[{ required: true, message: t('form.expireTimeRequired') }]}
|
|
|
|
|
+ >
|
|
|
|
|
+ <DatePicker
|
|
|
|
|
+ style={{ width: '100%' }}
|
|
|
|
|
+ format="YYYY-MM-DD HH:mm:ss"
|
|
|
|
|
+ showTime={{ format: 'HH:mm:ss' }}
|
|
|
|
|
+ placeholder={t('form.expireTimePlaceholder')}
|
|
|
|
|
+ renderExtraFooter={() => (
|
|
|
|
|
+ <div
|
|
|
|
|
+ style={{ color: '#1677ff', cursor: 'pointer' }}
|
|
|
|
|
+ onClick={() => form.setFieldValue('expireTime', dayjs(LONG_TERM_EXPIRE_TIME))}
|
|
|
|
|
+ >
|
|
|
|
|
+ {t('form.longTermValid')}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+ />
|
|
|
|
|
+ </Form.Item>
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ </Row>
|
|
|
|
|
+
|
|
|
|
|
+ <Row gutter={16}>
|
|
|
|
|
+ <Col span={24}>
|
|
|
|
|
+ <Form.Item
|
|
|
|
|
+ label={t('form.remark')}
|
|
|
|
|
+ name="remark"
|
|
|
|
|
+ labelCol={{ span: 3 }}
|
|
|
|
|
+ wrapperCol={{ span: 21 }}
|
|
|
|
|
+ >
|
|
|
<TextArea rows={3} placeholder={t('form.remarkPlaceholder')} />
|
|
<TextArea rows={3} placeholder={t('form.remarkPlaceholder')} />
|
|
|
</Form.Item>
|
|
</Form.Item>
|
|
|
</Col>
|
|
</Col>
|