|
@@ -1,13 +1,14 @@
|
|
|
import { connect, useRequest } from 'umi'
|
|
|
import { useEffect } from 'react'
|
|
|
import { Button, message } from 'antd'
|
|
|
-import { addProject, updateProject } from '@/services/api/project'
|
|
|
+import { addProject, getProject, updateProject } from '@/services/api/project'
|
|
|
import { delay } from '@/utils/util'
|
|
|
import FormRender, { useForm } from 'form-render'
|
|
|
import { BaseMenuEnum } from '@/pages/Schema/Base'
|
|
|
import type { SchemaBaseModelState } from '@/pages/Schema/Base/model'
|
|
|
import type { ConnectProps } from 'umi'
|
|
|
import type { ProjectModelState } from '../../model'
|
|
|
+import consts from '@/utils/consts'
|
|
|
|
|
|
export enum ModalType {
|
|
|
ADD = 0,
|
|
@@ -21,9 +22,7 @@ type ProjectModalProps = ConnectProps & {
|
|
|
readOnly: boolean
|
|
|
type: ModalType
|
|
|
defaultFormData?: {
|
|
|
- ID: string
|
|
|
- name: string
|
|
|
- projectTypeID: string
|
|
|
+ dataID: string
|
|
|
}
|
|
|
pTypeList: API.ProjectTypeList
|
|
|
reload: () => void
|
|
@@ -64,25 +63,28 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- const onMount = () => {
|
|
|
- const currentFormData = { ...defaultFormData }
|
|
|
- const keys = Object.keys(currentFormData)
|
|
|
- keys.forEach(key => {
|
|
|
- if (currentFormData[key] instanceof Object) {
|
|
|
- const targetMap = currentFormData[key]
|
|
|
- delete currentFormData[key]
|
|
|
- currentFormData[`${key}ID`] = targetMap.ID
|
|
|
- }
|
|
|
- })
|
|
|
- form.setValues(type === ModalType.ADD ? {} : { ...currentFormData })
|
|
|
- delay(80).then(() => {
|
|
|
- // console.log(pTypeList)
|
|
|
+ const onMount = async () => {
|
|
|
+ const { code = -1, data = {} } = await getProject({ ID: defaultFormData.dataID })
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ const currentFormData = { ...data }
|
|
|
+ const keys = Object.keys(currentFormData)
|
|
|
+ keys.forEach(key => {
|
|
|
+ if (currentFormData[key] instanceof Object) {
|
|
|
+ const targetMap = currentFormData[key]
|
|
|
+ delete currentFormData[key]
|
|
|
+ currentFormData[`${key}ID`] = targetMap.ID
|
|
|
+ }
|
|
|
+ })
|
|
|
+ form.setValues(type === ModalType.ADD ? {} : { ...currentFormData })
|
|
|
+ delay(80).then(() => {
|
|
|
+ // console.log(pTypeList)
|
|
|
|
|
|
- form.setSchemaByPath('projectTypeID', {
|
|
|
- enum: pTypeList.map(item => item.value),
|
|
|
- enumNames: pTypeList.map(item => item.label)
|
|
|
+ form.setSchemaByPath('projectTypeID', {
|
|
|
+ enum: pTypeList.map(item => item.value),
|
|
|
+ enumNames: pTypeList.map(item => item.label)
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const onFinish = async (formData, errors) => {
|
|
@@ -102,10 +104,6 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
|
|
|
}
|
|
|
return (
|
|
|
<div>
|
|
|
- <div className="text-xl mb-6">
|
|
|
- {type === ModalType.ADD ? '新增项目' : null}
|
|
|
- {type === ModalType.UPDATE ? '编辑项目' : null}
|
|
|
- </div>
|
|
|
{schema && <FormRender form={form} schema={schema} onFinish={onFinish} onMount={onMount} />}
|
|
|
<div className="ml-120px">
|
|
|
{/* * 重置会导致下拉框的options丢失
|