index.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import Header from '@/components/Header'
  2. import Slot from '@/components/Header/slot'
  3. import consts from '@/utils/consts'
  4. import { dayjsFomrat } from '@/utils/util'
  5. import { Button, Form, Input, message } from 'antd'
  6. import React, { useEffect, useState } from 'react'
  7. import { apiProjectInfo, apiSaveProjectInfo } from './api'
  8. import styles from './index.module.scss'
  9. interface iProjectInfo {
  10. projectName: string;
  11. code: string;
  12. createTime: number;
  13. mobile: string;
  14. name: string;
  15. }
  16. export default function Info() {
  17. const [ form ] = Form.useForm()
  18. const [ loading, setLoading ] = useState<boolean>(false)
  19. const [ projectInfo, setProjectInfo ] = useState<iProjectInfo>({
  20. projectName: "",
  21. code: "",
  22. createTime: 0,
  23. mobile: "",
  24. name: ""
  25. })
  26. useEffect(() => {
  27. initData()
  28. }, [])
  29. useEffect(() => {
  30. form.setFieldsValue(
  31. { ...projectInfo,
  32. createTime: dayjsFomrat(projectInfo.createTime, "YYYY-MM-DD"),
  33. mobile: projectInfo.mobile.replace(/(\d{3})(\d{4})(\d{4})/, "$1****$3") + ` (${projectInfo.name})`
  34. })
  35. }, [ projectInfo ])
  36. const initData = async () => {
  37. const { code = -1, data = {} } = await apiProjectInfo()
  38. if (code === consts.RET_CODE.SUCCESS) {
  39. setProjectInfo(data)
  40. }
  41. }
  42. const saveProjectName = async () => {
  43. setLoading(true)
  44. const newName = form.getFieldValue("projectName")
  45. if (newName !== projectInfo.projectName) {
  46. const { code = -1 } = await apiSaveProjectInfo(newName)
  47. if (code === consts.RET_CODE.SUCCESS) {
  48. message.success("更新成功!")
  49. initData()
  50. }
  51. }
  52. setLoading(false)
  53. }
  54. return (
  55. <div className="wrap-contaniner">
  56. <Header title="项目信息">
  57. <Slot position="right">
  58. <Button type="primary" size="small" loading={loading} onClick={() => saveProjectName()}>保存修改</Button>
  59. </Slot>
  60. </Header>
  61. <div className={styles.projectInfo}>
  62. <Form form={form} className={styles.formContent} layout="vertical" size="small">
  63. <Form.Item name="code" label="项目编号">
  64. <Input disabled></Input>
  65. </Form.Item>
  66. <Form.Item name="projectName" label="项目名称">
  67. <Input></Input>
  68. </Form.Item>
  69. <Form.Item name="mobile" label="管理员">
  70. <Input disabled></Input>
  71. </Form.Item>
  72. <Form.Item name="createTime" label="创建时间">
  73. <Input disabled></Input>
  74. </Form.Item>
  75. </Form>
  76. </div>
  77. </div>
  78. )
  79. }