lanjianrong 3 éve
szülő
commit
5663cb8162

+ 1 - 6
config/routes.ts

@@ -67,12 +67,7 @@
             hideInMenu: true,
             component: './Institutions/Company/List'
           },
-          {
-            path: 'add',
-            name: 'add',
-            hideInMenu: true,
-            component: './Institutions/Company/Add'
-          },
+
           {
             path: 'detail',
             name: 'detail',

+ 0 - 59
src/pages/Institutions/Company/Add/index.tsx

@@ -1,59 +0,0 @@
-import { useEffect } from 'react'
-import { BaseMenuEnum } from '@/pages/Schema/Base'
-import { connect, useRequest, history } from 'umi'
-import FormRender, { useForm } from 'form-render'
-import type { SchemaBaseModelState } from '@/pages/Schema/Base/model'
-import type { ConnectProps } from 'umi'
-import { PageContainer } from '@ant-design/pro-layout'
-import { Button, message } from 'antd'
-import { addInstitution, updateInstitution } from '@/services/api/institution'
-
-type CompanyAddProps = ConnectProps & {
-  schema?: Record<string, any> | null
-}
-const CompanyAdd: React.FC<CompanyAddProps> = ({ dispatch, schema }) => {
-  const form = useForm()
-  useEffect(() => {
-    dispatch({
-      type: 'schemaBase/querySchema',
-      payload: {
-        columnType: BaseMenuEnum.COMPANY
-      }
-    })
-  }, [])
-  const { run: tryUpdateInstitution } = useRequest(updateInstitution, {
-    manual: true,
-    onSuccess: () => {
-      message.success('更新成功')
-      history.push('/institutions/company/list')
-    }
-  })
-  const { run: tryAddInstitution } = useRequest(addInstitution, {
-    manual: true,
-    onSuccess: () => {
-      message.success('创建成功')
-      history.push('/institutions/company/list')
-    }
-  })
-  const onFinish = (formData, errors) => {
-    console.log('formData:', formData, 'errors', errors)
-    tryAddInstitution(formData)
-  }
-
-  return (
-    <PageContainer title={false}>
-      <div className="bg-white p-4">
-        {schema && <FormRender form={form} schema={JSON.parse(schema)} onFinish={onFinish} />}
-        <div className="ml-137px">
-          <Button type="primary" onClick={form.submit}>
-            提交
-          </Button>
-        </div>
-      </div>
-    </PageContainer>
-  )
-}
-
-export default connect(({ schemaBase }: { schemaBase: SchemaBaseModelState }) => ({
-  schema: schemaBase.base[BaseMenuEnum.COMPANY]?.schema
-}))(CompanyAdd)

+ 35 - 10
src/pages/Institutions/Company/List/components/CompanyDrawer.tsx

@@ -1,18 +1,20 @@
-import { useRequest } from 'umi'
-import { useRef, useEffect } from 'react'
-import { Drawer, message } from 'antd'
-import type { FormInstance } from 'antd'
+import { connect, useRequest } from 'umi'
+import { useEffect } from 'react'
+import FormRender, { useForm } from 'form-render'
+import { Drawer, message, Button } from 'antd'
 import { addInstitution, updateInstitution } from '@/services/api/institution'
 import { BaseMenuEnum } from '@/pages/Schema/Base'
-import type { SchemaBaseModelState } from '@/pages/Schema/Base/model'
 import { ModalType } from '@/utils/enum'
+import type { SchemaBaseModelState } from '@/pages/Schema/Base/model'
+import type { ConnectProps } from 'umi'
 
-type CompanyModalProps = {
+type CompanyModalProps = ConnectProps & {
   visible: boolean
   setVisible: (visible: boolean) => void
   type: ModalType
   defaultFormData?: API.InstitutionListItem
   reload: () => void
+  schema?: Record<string, any> | null
 }
 
 const CompanyDrawer: React.FC<CompanyModalProps> = ({
@@ -20,9 +22,21 @@ const CompanyDrawer: React.FC<CompanyModalProps> = ({
   setVisible,
   type,
   defaultFormData,
+  schema,
   // pTypeList,
   reload
 }) => {
+  const form = useForm()
+  useEffect(() => {
+    if (visible && !schema) {
+      dispatch({
+        type: 'schemaBase/querySchema',
+        payload: {
+          columnType: BaseMenuEnum.COMPANY
+        }
+      })
+    }
+  }, [visible])
   const { run: tryUpdateInstitution } = useRequest(updateInstitution, {
     manual: true,
     onSuccess: () => {
@@ -36,14 +50,13 @@ const CompanyDrawer: React.FC<CompanyModalProps> = ({
     }
   })
 
-  const onFinish = async (formData, errors) => {
-    console.log('formData:', formData, 'errors', errors)
+  const onFinish = async formData => {
     try {
       // 执行表单提交
       if (type === ModalType.ADD) {
-        await tryAddInstitution(values)
+        await tryAddInstitution(formData)
       } else {
-        await tryUpdateInstitution(values)
+        await tryUpdateInstitution(formData)
       }
       setVisible(false)
       reload()
@@ -52,6 +65,18 @@ const CompanyDrawer: React.FC<CompanyModalProps> = ({
       message.error(error)
     }
   }
+
+  const onMount = () => {
+    console.log(defaultFormData)
+
+    form.setValues({ ...defaultFormData })
+    // delay().then(() => {
+    //   form.setSchemaByPath('projectTypeID', {
+    //     enum: pTypeList.map(item => item.value),
+    //     enumNames: pTypeList.map(item => item.label)
+    //   })
+    // })
+  }
   return (
     <Drawer
       width="50vw"

+ 6 - 9
src/pages/Institutions/Company/List/index.tsx

@@ -1,7 +1,6 @@
 import dayjs from 'dayjs'
 import ProTable from '@ant-design/pro-table'
 import consts from '@/utils/consts'
-// import CompanyModal, { ModalType } from '../Detail/components/CompanyModal'
 import { Button } from 'antd'
 import { useRef, useState, useEffect } from 'react'
 import { connect, history } from 'umi'
@@ -12,8 +11,8 @@ import type { ProjectModelState } from '../../model'
 import type { SchemaBaseModelState } from '@/pages/Schema/Base/model'
 import { BaseMenuEnum } from '@/pages/Schema/Base'
 import { PageContainer } from '@ant-design/pro-layout'
-import CompanyDrawer, { ModalType } from './components/CompanyDrawer'
-// import CompanyName from './CompanyName'
+import CompanyDrawer from './components/CompanyDrawer'
+import { ModalType } from '@/utils/enum'
 
 type ListProps = ConnectProps & {
   pTypeList: { label: string; value: string }[]
@@ -136,8 +135,7 @@ const CompanyList: React.FC<ListProps> = ({ base, dispatch, pTypeList }) => {
   ]
 
   function generateColumns(c, s) {
-    // if (!s) return c
-    console.log(s && JSON.parse(s))
+    if (!s) return c
     // 新的列
     const nC = [...c]
     if (s) {
@@ -178,9 +176,8 @@ const CompanyList: React.FC<ListProps> = ({ base, dispatch, pTypeList }) => {
           },
           actions: [
             <Button
-              onClick={
-                () => setState({ ...state, visible: true, currentModalType: ModalType.ADD })
-                // history.push('/institutions/company/add', {})
+              onClick={() =>
+                setState({ ...state, visible: true, currentModalType: ModalType.ADD })
               }>
               新建企事业单位
             </Button>
@@ -193,7 +190,7 @@ const CompanyList: React.FC<ListProps> = ({ base, dispatch, pTypeList }) => {
         defaultFormData={state.defaultFormData}
         pTypeList={pTypeList}
         visible={state.visible}
-        reloadTable={() => tRef.current?.reload()}
+        reload={() => tRef.current?.reload()}
         setVisible={(visible: boolean) => setState({ ...state, visible })}
       />
       {/* <CompanyModal