@@ -2,20 +2,21 @@ import React, { useState, useEffect, useRef, useMemo } from 'react';
22import classnames from 'classnames' ;
33import i18n from '@/i18n' ;
44import { connect } from 'umi' ;
5- import { Input , Cascader , Dropdown , MenuProps } from 'antd' ;
5+ import { Input , Cascader , Dropdown , MenuProps , Pagination } from 'antd' ;
66import Iconfont from '@/components/Iconfont' ;
77import LoadingContent from '@/components/Loading/LoadingContent' ;
88import { IConnectionModelType } from '@/models/connection' ;
99import { IWorkspaceModelType } from '@/models/workspace' ;
1010import Tree from '../Tree' ;
1111import { treeConfig } from '../Tree/treeConfig' ;
12- import { TreeNodeType , WorkspaceTabType } from '@/constants' ;
12+ import { TreeNodeType , WorkspaceTabType , ConsoleStatus , ConsoleOpenedStatus } from '@/constants' ;
1313import { approximateTreeNode } from '@/utils' ;
1414import { useUpdateEffect } from '@/hooks/useUpdateEffect' ;
1515import { v4 as uuidV4 } from 'uuid' ;
16- import { ITreeNode } from '@/typings' ;
16+ import { IPagingData , ITreeNode } from '@/typings' ;
1717import styles from './index.less' ;
1818import { ExportTypeEnum } from '@/typings/resultTable' ;
19+ import historyService from '@/service/history' ;
1920
2021interface IOption {
2122 value : TreeNodeType ;
@@ -33,6 +34,12 @@ const optionsList: IOption[] = [
3334 { value : TreeNodeType . TRIGGERS , label : i18n ( 'workspace.tree.trigger' ) } ,
3435] ;
3536
37+ const defaultPaddingData = {
38+ total : 0 ,
39+ pageSize : 200 ,
40+ pageNo : 1 ,
41+ } ;
42+
3643const dvaModel = connect (
3744 ( { connection, workspace } : { connection : IConnectionModelType ; workspace : IWorkspaceModelType } ) => ( {
3845 connectionModel : connection ,
@@ -54,6 +61,7 @@ const TableList = dvaModel((props: any) => {
5461 const [ curType , setCurType ] = useState < IOption > ( optionsList [ 0 ] ) ;
5562 const [ curList , setCurList ] = useState < ITreeNode [ ] > ( [ ] ) ;
5663 const [ tableLoading , setTableLoading ] = useState < boolean > ( false ) ;
64+ const [ pagingData , setPagingData ] = useState < IPagingData > ( defaultPaddingData ) ;
5765
5866 // 导出表结构
5967 const handleExport = ( exportType : ExportTypeEnum ) => {
@@ -62,6 +70,18 @@ const TableList = dvaModel((props: any) => {
6270
6371 const items : MenuProps [ 'items' ] = useMemo (
6472 ( ) => [
73+ {
74+ label : (
75+ < div className = { styles . operationItem } >
76+ < Iconfont className = { styles . operationIcon } code = "" />
77+ < div className = { styles . operationTitle } > { i18n ( 'common.button.createConsole' ) } </ div >
78+ </ div >
79+ ) ,
80+ key : 'createConsole' ,
81+ onClick : ( ) => {
82+ addConsole ( ) ;
83+ } ,
84+ } ,
6585 {
6686 label : (
6787 < div className = { styles . operationItem } >
@@ -177,26 +197,65 @@ const TableList = dvaModel((props: any) => {
177197 }
178198 } , [ searching ] ) ;
179199
180- function getList ( refresh : boolean = false ) {
200+ const addConsole = ( ) => {
201+ const { dataSourceId, databaseName, schemaName, databaseType } = curWorkspaceParams ;
202+ const params = {
203+ name : `new console` ,
204+ ddl : '' ,
205+ dataSourceId : dataSourceId ! ,
206+ databaseName : databaseName ! ,
207+ schemaName : schemaName ! ,
208+ type : databaseType ,
209+ status : ConsoleStatus . DRAFT ,
210+ tabOpened : ConsoleOpenedStatus . IS_OPEN ,
211+ operationType : WorkspaceTabType . CONSOLE ,
212+ tabType : WorkspaceTabType . CONSOLE ,
213+ } ;
214+
215+ historyService . saveConsole ( params ) . then ( ( res ) => {
216+ dispatch ( {
217+ type : 'workspace/setCreateConsoleIntro' ,
218+ payload : {
219+ id : res ,
220+ type : WorkspaceTabType . CONSOLE ,
221+ title : params . name ,
222+ uniqueData : params ,
223+ } ,
224+ } ) ;
225+ } ) ;
226+ } ;
227+
228+ function getList ( params ?: { pageNo ?: number ; refresh ?: boolean ; searchKey ?: string } ) {
229+ const { refresh = false , searchKey, pageNo = 1 } = params || { } ;
181230 setTableLoading ( true ) ;
182- treeConfig [ curType . value ] . getChildren ! ( {
183- refresh,
184- ...curWorkspaceParams ,
185- extraParams : curWorkspaceParams ,
186- } )
187- . then ( ( res ) => {
188- setCurList ( res ) ;
189- setTableLoading ( false ) ;
190- if ( curType . value === TreeNodeType . TABLES ) {
191- dispatch ( {
192- type : 'workspace/setCurTableList' ,
193- payload : res ,
194- } ) ;
195- }
231+ return new Promise ( ( resolve ) => {
232+ treeConfig [ curType . value ] . getChildren ! ( {
233+ refresh,
234+ ...curWorkspaceParams ,
235+ extraParams : curWorkspaceParams ,
236+ searchKey,
237+ pageNo,
196238 } )
197- . catch ( ( ) => {
198- setTableLoading ( false ) ;
199- } ) ;
239+ . then ( ( res : any ) => {
240+ setCurList ( res . data ) ;
241+ resolve ( res ) ;
242+ setPagingData ( {
243+ total : res . total ,
244+ pageSize : res . pageSize ,
245+ pageNo : res . pageNo ,
246+ } ) ;
247+ if ( curType . value === TreeNodeType . TABLES ) {
248+ dispatch ( {
249+ type : 'workspace/setCurTableList' ,
250+ payload : res . data ,
251+ } ) ;
252+ }
253+ setTableLoading ( false ) ;
254+ } )
255+ . catch ( ( ) => {
256+ setTableLoading ( false ) ;
257+ } ) ;
258+ } ) ;
200259 }
201260
202261 function openSearch ( ) {
@@ -211,20 +270,41 @@ const TableList = dvaModel((props: any) => {
211270 }
212271
213272 function onChange ( value : string ) {
214- setSearchedTableList ( approximateTreeNode ( curList , value ) ) ;
273+ if ( curType . value === TreeNodeType . TABLES ) {
274+ getList ( {
275+ searchKey : value ,
276+ refresh : false ,
277+ } ) . then ( ( res : any ) => {
278+ setSearchedTableList ( approximateTreeNode ( res . data , value ) ) ;
279+ } ) ;
280+ } else {
281+ setSearchedTableList ( approximateTreeNode ( curList , value ) ) ;
282+ }
215283 }
216284
217285 function refreshTableList ( ) {
218286 if ( isReady ) {
219287 setCurList ( [ ] ) ;
220- getList ( true ) ;
288+ getList ( {
289+ refresh : true ,
290+ } ) ;
221291 }
222292 }
223293
224294 function cascaderChange ( value : string [ ] , selectedOptions : IOption [ ] ) {
225295 setCurType ( selectedOptions [ 0 ] ) ;
226296 }
227297
298+ const handelChangePagination = ( pageNo : number ) => {
299+ getList ( {
300+ pageNo,
301+ refresh : false ,
302+ searchKey : inputRef . current ?. input . value ,
303+ } ) . then ( ( res : any ) => {
304+ setSearchedTableList ( approximateTreeNode ( res . data , inputRef . current ?. input . value ) ) ;
305+ } ) ;
306+ } ;
307+
228308 return (
229309 < div className = { styles . tableModule } >
230310 < div className = { styles . leftModuleTitle } >
@@ -274,6 +354,18 @@ const TableList = dvaModel((props: any) => {
274354 < LoadingContent className = { styles . treeBox } isLoading = { tableLoading } >
275355 < Tree className = { styles . tree } initialData = { searchedTableList || curList } />
276356 </ LoadingContent >
357+ { pagingData ?. total > 200 && (
358+ < div className = { styles . paging } >
359+ < Pagination
360+ onChange = { handelChangePagination }
361+ current = { pagingData ?. pageNo }
362+ defaultPageSize = { pagingData ?. pageSize }
363+ simple
364+ size = "small"
365+ total = { pagingData ?. total }
366+ />
367+ </ div >
368+ ) }
277369 </ div >
278370 ) ;
279371} ) ;
0 commit comments