@@ -7,7 +7,7 @@ import ColumnList, { IColumnListRef } from './ColumnList';
77import BaseInfo , { IBaseInfoRef } from './BaseInfo' ;
88import sqlService , { IModifyTableSqlParams } from '@/service/sql' ;
99import ExecuteSQL from '@/components/ExecuteSQL' ;
10- import { IEditTableInfo , IWorkspaceTab } from '@/typings' ;
10+ import { IEditTableInfo , IWorkspaceTab , IColumnTypes } from '@/typings' ;
1111import { DatabaseTypeCode , WorkspaceTabType } from '@/constants' ;
1212import i18n from '@/i18n' ;
1313import lodash from 'lodash' ;
@@ -33,10 +33,28 @@ interface IContext extends IProps {
3333 baseInfoRef : React . RefObject < IBaseInfoRef > ;
3434 columnListRef : React . RefObject < IColumnListRef > ;
3535 indexListRef : React . RefObject < IIndexListRef > ;
36+ databaseSupportField : IDatabaseSupportField ;
3637}
3738
3839export const Context = createContext < IContext > ( { } as any ) ;
3940
41+ interface IOption {
42+ label : string ;
43+ value : string | number | null ;
44+ }
45+
46+ // 列字段类型,select组件的options需要的数据结构
47+ interface IColumnTypesOption extends IColumnTypes {
48+ label : string ;
49+ value : string | number | null ;
50+ }
51+ export interface IDatabaseSupportField {
52+ columnTypes : IColumnTypesOption [ ] ;
53+ charsets : IOption [ ] ;
54+ collations : IOption [ ] ;
55+ indexTypes : IOption [ ] ;
56+ }
57+
4058export default memo ( ( props : IProps ) => {
4159 const { databaseName, dataSourceId, tableName, schemaName, changeTabDetails, tabDetails, databaseType } = props ;
4260 const [ tableDetails , setTableDetails ] = useState < IEditTableInfo > ( { } as any ) ;
@@ -69,6 +87,12 @@ export default memo((props: IProps) => {
6987 ] ;
7088 } , [ ] ) ;
7189 const [ currentTab , setCurrentTab ] = useState < ITabItem > ( tabList [ 0 ] ) ;
90+ const [ databaseSupportField , setDatabaseSupportField ] = useState < IDatabaseSupportField > ( {
91+ columnTypes : [ ] ,
92+ charsets : [ ] ,
93+ collations : [ ] ,
94+ indexTypes : [ ] ,
95+ } ) ;
7296
7397 function changeTab ( item : ITabItem ) {
7498 setCurrentTab ( item ) ;
@@ -78,8 +102,59 @@ export default memo((props: IProps) => {
78102 if ( tableName ) {
79103 getTableDetails ( { } ) ;
80104 }
105+ getDatabaseFieldTypeList ( ) ;
81106 } , [ ] ) ;
82107
108+ // 获取数据库字段类型列表
109+ const getDatabaseFieldTypeList = ( ) => {
110+ sqlService
111+ . getDatabaseFieldTypeList ( {
112+ dataSourceId,
113+ databaseName,
114+ } )
115+ . then ( ( res ) => {
116+ const columnTypes =
117+ res ?. columnTypes ?. map ( ( i ) => {
118+ return {
119+ ...i ,
120+ value : i . typeName ,
121+ label : i . typeName ,
122+ } ;
123+ } ) || [ ] ;
124+
125+ const charsets =
126+ res ?. charsets ?. map ( ( i ) => {
127+ return {
128+ value : i . charsetName ,
129+ label : i . charsetName ,
130+ } ;
131+ } ) || [ ] ;
132+
133+ const collations =
134+ res ?. collations ?. map ( ( i ) => {
135+ return {
136+ value : i . collationName ,
137+ label : i . collationName ,
138+ } ;
139+ } ) || [ ] ;
140+
141+ const indexTypes =
142+ res ?. indexTypes ?. map ( ( i ) => {
143+ return {
144+ value : i . typeName ,
145+ label : i . typeName ,
146+ } ;
147+ } ) || [ ] ;
148+
149+ setDatabaseSupportField ( {
150+ columnTypes,
151+ charsets,
152+ collations,
153+ indexTypes,
154+ } ) ;
155+ } ) ;
156+ } ;
157+
83158 const getTableDetails = ( { tableNameProps } : { tableNameProps ?: string } ) => {
84159 if ( ! tableName ) return ;
85160 const params = {
@@ -150,6 +225,7 @@ export default memo((props: IProps) => {
150225 baseInfoRef,
151226 columnListRef,
152227 indexListRef,
228+ databaseSupportField,
153229 } }
154230 >
155231 < div className = { classnames ( styles . box ) } >
0 commit comments