index.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import logo from '@/assets/img/loginlogo.png'
  2. import { userStore } from '@/store/mobx'
  3. import { iFromValues, iLoginProps, iRetrieveFormProps } from '@/types/login'
  4. import consts from '@/utils/consts'
  5. import { Button, Form, Input, Modal } from 'antd'
  6. import React, { useState } from 'react'
  7. import { RouteComponentProps, withRouter } from 'react-router-dom'
  8. import { apiProject } from "./api"
  9. import styles from './index.module.scss'
  10. import QueueAnim from 'rc-queue-anim'
  11. import './index.scss'
  12. // 正常登录Form表单
  13. const initLoginState = {
  14. projectInfo: '',
  15. projectCode: '',
  16. visible: false,
  17. user: userStore.userInfo
  18. }
  19. type iState = typeof initLoginState
  20. const NormalLoginForm: React.FC<iLoginProps> = () => {
  21. const [ state, setState ] = useState<iState>(initLoginState)
  22. const onFinish = (values: iFromValues) => {
  23. userStore.login(values)
  24. }
  25. const handleProjectCode = async (e: any) => {
  26. const projectCode = e.target?.value
  27. const { code = -1, data = [] } = await apiProject(projectCode)
  28. if (code === consts.RET_CODE.SUCCESS) {
  29. if (data.length && data[0].name) {
  30. setState({ ...state, projectInfo: data[0].name })
  31. }
  32. }
  33. }
  34. const setVisible = (label: boolean) => {
  35. setState({ ...state, visible: label })
  36. }
  37. const handleForgetPsw = () => {
  38. setState({ ...state, visible: !state.visible })
  39. }
  40. return (
  41. <Form
  42. name="normal_login"
  43. className={styles.loginForm}
  44. // initialValues={{ password: '123456', code : '234' }}
  45. onFinish={onFinish}
  46. >
  47. <h4>纵横工程建设项目管理系统</h4>
  48. <h5 className={[ 'project-title' ].join(' ')} >{state.projectInfo}</h5>
  49. <QueueAnim >
  50. <div key="code">
  51. <Form.Item
  52. name="code"
  53. rules={[ { required: true, message: '请输入项目编号!' } ]}
  54. >
  55. <Input placeholder="项目编号" onChange={handleProjectCode} />
  56. </Form.Item>
  57. </div>
  58. <div key="account">
  59. <Form.Item
  60. name="account"
  61. rules={[ { required: true, message: '请输入账号!' } ]}
  62. >
  63. <Input placeholder="登录账号" />
  64. </Form.Item>
  65. </div>
  66. <div key="password">
  67. <Form.Item
  68. name="password"
  69. rules={[ { required: true, message: '请输入密码!' } ]}
  70. >
  71. <Input.Password type="password" placeholder="密码" />
  72. </Form.Item>
  73. </div>
  74. <div key="button">
  75. <Form.Item>
  76. <Button type="primary" htmlType="submit">登录</Button>
  77. </Form.Item>
  78. </div>
  79. {/* <div className={styles.textRight}>
  80. <span onClick={this.handleForgetPsw}>忘记密码?</span>
  81. </div> */}
  82. {/* <RetrieveForm visible={state.visible} setVisible={setVisible} /> */}
  83. </QueueAnim>
  84. </Form>
  85. )
  86. }
  87. // 找回密码Form表单
  88. const RetrieveForm: React.FC<iRetrieveFormProps> = ({ visible, setVisible }) => {
  89. const handleOk = () => {
  90. console.log('ok')
  91. }
  92. const handleCancel = () => {
  93. console.log('cancel')
  94. setVisible(!visible)
  95. }
  96. return (
  97. <Modal
  98. title="找回密码"
  99. visible={visible}
  100. onOk={handleOk}
  101. onCancel={handleCancel}
  102. cancelText="取消"
  103. closable={false}
  104. okText="重置密码"
  105. />
  106. )
  107. }
  108. const Login = (props: RouteComponentProps) => {
  109. const { history } = props
  110. return (
  111. <div className="login-container">
  112. <div className="login-content">
  113. <div className="form-sign pi-flex pi-flex-row">
  114. <div className="pi-flex-sub">
  115. <img src={logo} />
  116. </div>
  117. <div className="pi-flex-sub">
  118. <NormalLoginForm history={history} />
  119. </div>
  120. </div>
  121. <footer>
  122. <p className="mb-1">Copyright © 2019 <a href="https://smartcost.com.cn">珠海纵横创新软件有限公司</a>.All Rights Reserved.<a className="mb-2" href="http://www.miitbeian.gov.cn">粤ICP备14032472号</a></p>
  123. </footer>
  124. </div>
  125. </div>
  126. )
  127. }
  128. export default withRouter(Login)