index.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { updateSetting } from '@/services/api/system'
  2. import consts from '@/utils/consts'
  3. import { PageContainer } from '@ant-design/pro-layout'
  4. import { Card, Form, Input, Button, message } from 'antd'
  5. import React from 'react'
  6. import { history, useRequest } from '@umijs/max'
  7. const AdminUpdate = () => {
  8. const [form] = Form.useForm()
  9. const { run: tryUpdate } = useRequest(updateSetting, {
  10. manual: true,
  11. onSuccess: () => {
  12. window.localStorage.removeItem('TOKEN_ID')
  13. message.info('当前用户密码已修改,请重新登录。')
  14. history.replace({
  15. pathname: consts.loginPath
  16. })
  17. },
  18. onError: e => {
  19. console.log(e)
  20. }
  21. })
  22. return (
  23. <PageContainer title={false}>
  24. <Card>
  25. <div className="text-2xl mb-7">管理员</div>
  26. <Form
  27. labelCol={{ span: 2 }}
  28. wrapperCol={{ span: 3 }}
  29. layout="horizontal"
  30. form={form}
  31. initialValues={{ username: 'admin' }}>
  32. <Form.Item label="帐号" name="username">
  33. <Input disabled />
  34. </Form.Item>
  35. <Form.Item label="旧密码" name="password" rules={[{ required: true, message: '请输入密码' }]}>
  36. <Input.Password placeholder="请输入" />
  37. </Form.Item>
  38. <Form.Item label="新密码" name="newPassword" rules={[{ required: true, message: '请输入密码' }]}>
  39. <Input.Password placeholder="请输入" />
  40. </Form.Item>
  41. <Form.Item
  42. label="确认新密码"
  43. name="confirmPassword"
  44. rules={[
  45. { required: true, message: '请输入密码' },
  46. ({ getFieldValue }) => ({
  47. validator(_, value) {
  48. if (!value || getFieldValue('newPassword') === value) {
  49. return Promise.resolve()
  50. }
  51. return Promise.reject(new Error('两次输入的密码不一致!'))
  52. }
  53. })
  54. ]}>
  55. <Input.Password placeholder="请输入" />
  56. </Form.Item>
  57. <Form.Item wrapperCol={{ offset: 2, span: 8 }}>
  58. <Button
  59. type="primary"
  60. onClick={() => {
  61. form.validateFields().then(async values => {
  62. await tryUpdate(values)
  63. form.resetFields()
  64. })
  65. }}>
  66. 确定修改
  67. </Button>
  68. </Form.Item>
  69. </Form>
  70. </Card>
  71. </PageContainer>
  72. )
  73. }
  74. export default AdminUpdate