index.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. export const generateFieldIsCreated = (field: GeneralField) => {
  50. if (!field.value) {
  51. field.setDecoratorProps({
  52. addonAfter: (
  53. <span>
  54. 开启后,该账号添加成功后将成为
  55. <Link to="/project/created" className="text-primary">
  56. "项目创建人"
  57. </Link>
  58. </span>
  59. )
  60. })
  61. } else {
  62. field.setDecoratorProps({
  63. addonAfter: (
  64. <div>
  65. <span className="text-red-500">需要移除请进入</span>
  66. <Link to="/project/created" className="text-primary">
  67. "项目创建人"
  68. </Link>
  69. </div>
  70. )
  71. })
  72. }
  73. }
  74. const Index: React.FC<BaseProps> = ({ base, pTypeList, dispatch }) => {
  75. const [state, setState] = useState({
  76. activeKey: BaseMenuEnum.PROJECT
  77. })
  78. const currentSchema = base?.[state.activeKey]
  79. useEffect(() => {
  80. if (state.activeKey && !base[state.activeKey]) {
  81. dispatch({
  82. type: 'schemaBase/querySchema',
  83. payload: {
  84. columnType: state.activeKey
  85. }
  86. })
  87. }
  88. if (!pTypeList.length) {
  89. dispatch({
  90. type: 'project/queryProjectTypeList'
  91. })
  92. }
  93. }, [state.activeKey])
  94. const gotoDetail = columnType => {
  95. history.push({
  96. pathname: '/work-setting/schema/detail',
  97. state: { columnType }
  98. })
  99. }
  100. const renderForm = () => {
  101. const normalForm = createForm({
  102. validateFirst: true,
  103. pattern: 'readOnly'
  104. })
  105. const SchemaField = createSchemaField({
  106. components: {
  107. FormLayout,
  108. FormItem,
  109. FormGrid,
  110. Input,
  111. Switch,
  112. Select,
  113. Radio,
  114. Checkbox,
  115. NumberPicker,
  116. Password,
  117. DatePicker,
  118. TimePicker,
  119. TreeSelect
  120. }
  121. })
  122. return (
  123. <Form form={normalForm} labelCol={4} wrapperCol={8}>
  124. <SchemaField schema={currentSchema} />
  125. </Form>
  126. )
  127. }
  128. return (
  129. <PageContainer title={false}>
  130. <div className="h-full w-full flex flex-row">
  131. <LeftMenu
  132. title="基础数据类别"
  133. options={menuOptions}
  134. value={state.activeKey}
  135. onChange={key => setState({ ...state, activeKey: key })}
  136. />
  137. <div className="w-6/7 ml-8 bg-white p-4 rounded-20px">
  138. <div className="flex flex-row-reverse mb-4 w-full">
  139. <Button type="primary" onClick={() => gotoDetail(state.activeKey)}>
  140. 编辑
  141. </Button>
  142. </div>
  143. <div className="max-w-800px">{renderForm()}</div>
  144. </div>
  145. </div>
  146. </PageContainer>
  147. )
  148. }
  149. export default connect(
  150. ({ project, schemaBase }: { project: ProjectModelState; schemaBase: SchemaBaseModelState }) => ({
  151. pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.ID })),
  152. base: schemaBase.base
  153. })
  154. )(Index)