|  | @@ -1,36 +1,60 @@
 | 
	
		
			
				|  |  |  import Generator from 'fr-generator'
 | 
	
		
			
				|  |  | -import React, { useRef } from 'react'
 | 
	
		
			
				|  |  | +import React, { useRef, useState, useEffect } from 'react'
 | 
	
		
			
				|  |  |  import { PageContainer } from '@ant-design/pro-layout'
 | 
	
		
			
				|  |  |  import { connect, useRequest } from 'umi'
 | 
	
		
			
				|  |  | +import type { ConnectProps } from 'umi'
 | 
	
		
			
				|  |  |  import type { RouteComponentProps } from 'react-router'
 | 
	
		
			
				|  |  |  import type { SchemaBaseModelState } from './model'
 | 
	
		
			
				|  |  |  import { updateSchema } from '@/services/api/schema'
 | 
	
		
			
				|  |  |  import { message } from 'antd'
 | 
	
		
			
				|  |  | +import { menuOptions } from '.'
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -type DetailProps = RouteComponentProps
 | 
	
		
			
				|  |  | +type DetailProps = RouteComponentProps & ConnectProps
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -const Detail: React.FC<DetailProps> = ({ base, location }) => {
 | 
	
		
			
				|  |  | -  const genRef = useRef(null)
 | 
	
		
			
				|  |  | +const Detail: React.FC<DetailProps> = ({ dispatch, base, location }) => {
 | 
	
		
			
				|  |  |    const {
 | 
	
		
			
				|  |  | -    query: { columnType },
 | 
	
		
			
				|  |  | -    state: { ID }
 | 
	
		
			
				|  |  | +    query: { columnType, ID }
 | 
	
		
			
				|  |  |    } = location
 | 
	
		
			
				|  |  | -  console.log(columnType)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const genRef = useRef(null)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  // const [schema, setSchema] = useState(
 | 
	
		
			
				|  |  | +  //   () => (base?.[columnType] && JSON.parse(base?.[columnType]?.schema)) || {}
 | 
	
		
			
				|  |  | +  // )
 | 
	
		
			
				|  |  | +  // console.log(base?.[columnType]?.schema)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const { run: tryUpdateSchema } = useRequest(updateSchema, {
 | 
	
		
			
				|  |  |      manual: true,
 | 
	
		
			
				|  |  | -    onSuccess: () => {
 | 
	
		
			
				|  |  | +    onSuccess: result => {
 | 
	
		
			
				|  |  |        message.success('更新成功')
 | 
	
		
			
				|  |  | +      // console.log(genRef.current?.getValue())
 | 
	
		
			
				|  |  | +      dispatch({
 | 
	
		
			
				|  |  | +        type: 'schemaBase/changeSchemaByColumnType',
 | 
	
		
			
				|  |  | +        payload: {
 | 
	
		
			
				|  |  | +          ID,
 | 
	
		
			
				|  |  | +          columnType,
 | 
	
		
			
				|  |  | +          schema: result.schema
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +      })
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    })
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  const schema = base?.[columnType]?.schema
 | 
	
		
			
				|  |  | +  useEffect(() => {
 | 
	
		
			
				|  |  | +    if (columnType && !base[columnType]) {
 | 
	
		
			
				|  |  | +      dispatch({
 | 
	
		
			
				|  |  | +        type: 'schemaBase/querySchema',
 | 
	
		
			
				|  |  | +        payload: {
 | 
	
		
			
				|  |  | +          columnType
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +      })
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  }, [columnType])
 | 
	
		
			
				|  |  |    return (
 | 
	
		
			
				|  |  | -    <PageContainer title={false}>
 | 
	
		
			
				|  |  | -      <div className="bg-white shadow-card p-4" style={{ height: 'calc(100vh - 146px)' }}>
 | 
	
		
			
				|  |  | +    <PageContainer title={menuOptions[columnType]?.label + '数据模型'}>
 | 
	
		
			
				|  |  | +      <div className="bg-white shadow-card p-4" style={{ height: 'calc(100vh - 196px)' }}>
 | 
	
		
			
				|  |  |          <Generator
 | 
	
		
			
				|  |  |            ref={genRef}
 | 
	
		
			
				|  |  | -          defaultValue={(schema && JSON.parse(schema)) || {}}
 | 
	
		
			
				|  |  | +          defaultValue={(base?.[columnType] && JSON.parse(base?.[columnType]?.schema)) || {}}
 | 
	
		
			
				|  |  |            controlButtons={[true, true]}
 | 
	
		
			
				|  |  |            extraButtons={[
 | 
	
		
			
				|  |  |              true,
 | 
	
	
		
			
				|  | @@ -40,12 +64,13 @@ const Detail: React.FC<DetailProps> = ({ base, location }) => {
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                text: '提交',
 | 
	
		
			
				|  |  |                type: 'primary',
 | 
	
		
			
				|  |  | -              onClick: () => {
 | 
	
		
			
				|  |  | -                // console.log(schema)
 | 
	
		
			
				|  |  | -                tryUpdateSchema({
 | 
	
		
			
				|  |  | +              onClick: async () => {
 | 
	
		
			
				|  |  | +                const newSchema = JSON.stringify(genRef.current?.getValue())
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                await tryUpdateSchema({
 | 
	
		
			
				|  |  |                    ID,
 | 
	
		
			
				|  |  |                    columnType,
 | 
	
		
			
				|  |  | -                  schema: JSON.stringify(genRef.current?.getValue())
 | 
	
		
			
				|  |  | +                  schema: newSchema
 | 
	
		
			
				|  |  |                  })
 | 
	
		
			
				|  |  |                }
 | 
	
		
			
				|  |  |              }
 |