| 86133 | aaa3f5d | 2025-04-20 21:33:29 +0800 | [diff] [blame] | 1 | import React, { useEffect } from 'react'; |
| 2 | import { |
| 3 | ProForm, |
| 4 | ProFormDigit, |
| 5 | ProFormText, |
| 6 | ProFormRadio, |
| 7 | ProFormTimePicker, |
| 8 | } from '@ant-design/pro-components'; |
| 9 | import { Form, Modal} from 'antd'; |
| 10 | import { useIntl, FormattedMessage } from '@umijs/max'; |
| 11 | import { DictValueEnumObj } from '@/components/DictTag'; |
| 12 | |
| 13 | export type LogininforFormData = Record<string, unknown> & Partial<API.Monitor.Logininfor>; |
| 14 | |
| 15 | export type LogininforFormProps = { |
| 16 | onCancel: (flag?: boolean, formVals?: LogininforFormData) => void; |
| 17 | onSubmit: (values: LogininforFormData) => Promise<void>; |
| 18 | open: boolean; |
| 19 | values: Partial<API.Monitor.Logininfor>; |
| 20 | statusOptions: DictValueEnumObj; |
| 21 | }; |
| 22 | |
| 23 | const LogininforForm: React.FC<LogininforFormProps> = (props) => { |
| 24 | const [form] = Form.useForm(); |
| 25 | |
| 26 | const { statusOptions, } = props; |
| 27 | |
| 28 | useEffect(() => { |
| 29 | form.resetFields(); |
| 30 | form.setFieldsValue({ |
| 31 | infoId: props.values.infoId, |
| 32 | userName: props.values.userName, |
| 33 | ipaddr: props.values.ipaddr, |
| 34 | loginLocation: props.values.loginLocation, |
| 35 | browser: props.values.browser, |
| 36 | os: props.values.os, |
| 37 | status: props.values.status, |
| 38 | msg: props.values.msg, |
| 39 | loginTime: props.values.loginTime, |
| 40 | }); |
| 41 | }, [form, props]); |
| 42 | |
| 43 | const intl = useIntl(); |
| 44 | const handleOk = () => { |
| 45 | form.submit(); |
| 46 | }; |
| 47 | const handleCancel = () => { |
| 48 | props.onCancel(); |
| 49 | form.resetFields(); |
| 50 | }; |
| 51 | const handleFinish = async (values: Record<string, any>) => { |
| 52 | props.onSubmit(values as LogininforFormData); |
| 53 | }; |
| 54 | |
| 55 | return ( |
| 56 | <Modal |
| 57 | width={640} |
| 58 | title={intl.formatMessage({ |
| 59 | id: 'system.logininfor.title', |
| 60 | defaultMessage: '编辑系统访问记录', |
| 61 | })} |
| 62 | open={props.open} |
| 63 | destroyOnClose |
| 64 | forceRender |
| 65 | onOk={handleOk} |
| 66 | onCancel={handleCancel} |
| 67 | > |
| 68 | <ProForm |
| 69 | form={form} |
| 70 | grid={true} |
| 71 | layout="horizontal" |
| 72 | onFinish={handleFinish}> |
| 73 | <ProFormDigit |
| 74 | name="infoId" |
| 75 | label={intl.formatMessage({ |
| 76 | id: 'system.logininfor.info_id', |
| 77 | defaultMessage: '访问编号', |
| 78 | })} |
| 79 | colProps={{ md: 12, xl: 24 }} |
| 80 | placeholder="请输入访问编号" |
| 81 | disabled |
| 82 | hidden={true} |
| 83 | rules={[ |
| 84 | { |
| 85 | required: false, |
| 86 | message: <FormattedMessage id="请输入访问编号!" defaultMessage="请输入访问编号!" />, |
| 87 | }, |
| 88 | ]} |
| 89 | /> |
| 90 | <ProFormText |
| 91 | name="userName" |
| 92 | label={intl.formatMessage({ |
| 93 | id: 'system.logininfor.user_name', |
| 94 | defaultMessage: '用户账号', |
| 95 | })} |
| 96 | colProps={{ md: 12, xl: 24 }} |
| 97 | placeholder="请输入用户账号" |
| 98 | rules={[ |
| 99 | { |
| 100 | required: false, |
| 101 | message: <FormattedMessage id="请输入用户账号!" defaultMessage="请输入用户账号!" />, |
| 102 | }, |
| 103 | ]} |
| 104 | /> |
| 105 | <ProFormText |
| 106 | name="ipaddr" |
| 107 | label={intl.formatMessage({ |
| 108 | id: 'system.logininfor.ipaddr', |
| 109 | defaultMessage: '登录IP地址', |
| 110 | })} |
| 111 | colProps={{ md: 12, xl: 24 }} |
| 112 | placeholder="请输入登录IP地址" |
| 113 | rules={[ |
| 114 | { |
| 115 | required: false, |
| 116 | message: <FormattedMessage id="请输入登录IP地址!" defaultMessage="请输入登录IP地址!" />, |
| 117 | }, |
| 118 | ]} |
| 119 | /> |
| 120 | <ProFormText |
| 121 | name="loginLocation" |
| 122 | label={intl.formatMessage({ |
| 123 | id: 'system.logininfor.login_location', |
| 124 | defaultMessage: '登录地点', |
| 125 | })} |
| 126 | colProps={{ md: 12, xl: 24 }} |
| 127 | placeholder="请输入登录地点" |
| 128 | rules={[ |
| 129 | { |
| 130 | required: false, |
| 131 | message: <FormattedMessage id="请输入登录地点!" defaultMessage="请输入登录地点!" />, |
| 132 | }, |
| 133 | ]} |
| 134 | /> |
| 135 | <ProFormText |
| 136 | name="browser" |
| 137 | label={intl.formatMessage({ |
| 138 | id: 'system.logininfor.browser', |
| 139 | defaultMessage: '浏览器类型', |
| 140 | })} |
| 141 | colProps={{ md: 12, xl: 24 }} |
| 142 | placeholder="请输入浏览器类型" |
| 143 | rules={[ |
| 144 | { |
| 145 | required: false, |
| 146 | message: <FormattedMessage id="请输入浏览器类型!" defaultMessage="请输入浏览器类型!" />, |
| 147 | }, |
| 148 | ]} |
| 149 | /> |
| 150 | <ProFormText |
| 151 | name="os" |
| 152 | label={intl.formatMessage({ |
| 153 | id: 'system.logininfor.os', |
| 154 | defaultMessage: '操作系统', |
| 155 | })} |
| 156 | colProps={{ md: 12, xl: 24 }} |
| 157 | placeholder="请输入操作系统" |
| 158 | rules={[ |
| 159 | { |
| 160 | required: false, |
| 161 | message: <FormattedMessage id="请输入操作系统!" defaultMessage="请输入操作系统!" />, |
| 162 | }, |
| 163 | ]} |
| 164 | /> |
| 165 | <ProFormRadio.Group |
| 166 | valueEnum={statusOptions} |
| 167 | name="status" |
| 168 | label={intl.formatMessage({ |
| 169 | id: 'system.logininfor.status', |
| 170 | defaultMessage: '登录状态', |
| 171 | })} |
| 172 | colProps={{ md: 12, xl: 24 }} |
| 173 | placeholder="请输入登录状态" |
| 174 | rules={[ |
| 175 | { |
| 176 | required: false, |
| 177 | message: <FormattedMessage id="请输入登录状态!" defaultMessage="请输入登录状态!" />, |
| 178 | }, |
| 179 | ]} |
| 180 | /> |
| 181 | <ProFormText |
| 182 | name="msg" |
| 183 | label={intl.formatMessage({ |
| 184 | id: 'system.logininfor.msg', |
| 185 | defaultMessage: '提示消息', |
| 186 | })} |
| 187 | colProps={{ md: 12, xl: 24 }} |
| 188 | placeholder="请输入提示消息" |
| 189 | rules={[ |
| 190 | { |
| 191 | required: false, |
| 192 | message: <FormattedMessage id="请输入提示消息!" defaultMessage="请输入提示消息!" />, |
| 193 | }, |
| 194 | ]} |
| 195 | /> |
| 196 | <ProFormTimePicker |
| 197 | name="loginTime" |
| 198 | label={intl.formatMessage({ |
| 199 | id: 'system.logininfor.login_time', |
| 200 | defaultMessage: '访问时间', |
| 201 | })} |
| 202 | colProps={{ md: 12, xl: 24 }} |
| 203 | placeholder="请输入访问时间" |
| 204 | rules={[ |
| 205 | { |
| 206 | required: false, |
| 207 | message: <FormattedMessage id="请输入访问时间!" defaultMessage="请输入访问时间!" />, |
| 208 | }, |
| 209 | ]} |
| 210 | /> |
| 211 | </ProForm> |
| 212 | </Modal> |
| 213 | ); |
| 214 | }; |
| 215 | |
| 216 | export default LogininforForm; |