index.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* eslint-disable react/no-unescaped-entities */
  2. import { PageContainer } from '@ant-design/pro-layout'
  3. import LeftMenu from './components/LeftMenu'
  4. import { useState, useEffect } from 'react'
  5. import { history, connect, Link } from '@umijs/max'
  6. import type { ProjectModelState, SchemaBaseModelState } from '@umijs/max'
  7. import { createForm } from '@formily/core'
  8. import { createSchemaField } from '@formily/react'
  9. import {
  10. FormItem,
  11. Input,
  12. Switch,
  13. Select,
  14. FormGrid,
  15. FormLayout,
  16. Form,
  17. Radio,
  18. Checkbox,
  19. NumberPicker,
  20. Password,
  21. DatePicker,
  22. TimePicker,
  23. TreeSelect
  24. } from '@formily/antd'
  25. import 'antd/dist/antd.less'
  26. import { projectSchema, institutionSchema, staffSchema } from '@/utils/schema'
  27. import type { ConnectProps } from '@umijs/max'
  28. import { Button } from 'antd'
  29. export enum BaseMenuEnum {
  30. PROJECT = '1',
  31. COMPANY = '2',
  32. STAFF = '3'
  33. }
  34. // prettier 格式化有问题,故先这样写
  35. export enum SchemaEnum {
  36. '1' = projectSchema,
  37. '2' = institutionSchema,
  38. '3' = staffSchema
  39. }
  40. export const menuOptions = [
  41. { label: '项目信息', value: BaseMenuEnum.PROJECT },
  42. { label: '企事业单位信息', value: BaseMenuEnum.COMPANY },
  43. { label: '人员信息', value: BaseMenuEnum.STAFF }
  44. ]
  45. type BaseProps = ConnectProps & {
  46. base: SchemaBaseModelState
  47. pTypeList: { label: string; value: string }[]
  48. }
  49. const Index: React.FC<BaseProps> = ({ base, pTypeList, dispatch }) => {
  50. const [state, setState] = useState({
  51. activeKey: BaseMenuEnum.PROJECT
  52. })
  53. const currentSchema = base?.[state.activeKey]
  54. useEffect(() => {
  55. if (state.activeKey && !base[state.activeKey]) {
  56. dispatch({
  57. type: 'schemaBase/querySchema',
  58. payload: {
  59. columnType: state.activeKey
  60. }
  61. })
  62. }
  63. if (!pTypeList.length) {
  64. dispatch({
  65. type: 'project/queryProjectTypeList'
  66. })
  67. }
  68. }, [state.activeKey])
  69. const gotoDetail = columnType => {
  70. history.push(`/schema/base/${columnType}`)
  71. }
  72. const renderForm = () => {
  73. const normalForm = createForm({
  74. validateFirst: true,
  75. pattern: 'readOnly'
  76. })
  77. const SchemaField = createSchemaField({
  78. components: {
  79. FormLayout,
  80. FormItem,
  81. FormGrid,
  82. Input,
  83. Switch,
  84. Select,
  85. Radio,
  86. Checkbox,
  87. NumberPicker,
  88. Password,
  89. DatePicker,
  90. TimePicker,
  91. TreeSelect
  92. }
  93. })
  94. return (
  95. <Form form={normalForm} labelCol={4} wrapperCol={8}>
  96. <SchemaField schema={currentSchema} />
  97. </Form>
  98. )
  99. }
  100. return (
  101. <PageContainer title={false}>
  102. <div className="h-full w-full flex flex-row">
  103. <LeftMenu
  104. title="基础数据类别"
  105. options={menuOptions}
  106. value={state.activeKey}
  107. onChange={key => setState({ ...state, activeKey: key })}
  108. />
  109. <div className="w-6/7 ml-8 bg-white p-4 rounded-20px">
  110. <div className="flex flex-row-reverse mb-4 w-full">
  111. <Button type="primary" onClick={() => gotoDetail(state.activeKey)}>
  112. 编辑
  113. </Button>
  114. </div>
  115. <div className="max-w-800px">{renderForm()}</div>
  116. </div>
  117. </div>
  118. </PageContainer>
  119. )
  120. }
  121. export default connect(
  122. ({ project, schemaBase }: { project: ProjectModelState; schemaBase: SchemaBaseModelState }) => ({
  123. pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.ID })),
  124. base: schemaBase.base
  125. })
  126. )(Index)