@@ -8,76 +8,95 @@ export interface IConsoleStore {
88 consoleList : IConsole [ ] | null ;
99 activeConsoleId : string | number | null ;
1010 workspaceTabList : IWorkspaceTab [ ] | null ;
11+ createConsoleLoading : boolean
1112}
1213
1314export const initConsoleStore = {
1415 consoleList : null ,
1516 activeConsoleId : null ,
1617 workspaceTabList : null ,
17- }
18+ createConsoleLoading : false
19+ } ;
1820
1921export const getSavedConsoleList = ( ) => {
20- historyService . getSavedConsoleList ( {
21- tabOpened : 'y' ,
22- pageNo : 1 ,
23- pageSize : 20 ,
24- } ) . then ( ( res ) => {
25- useWorkspaceStore . setState ( { consoleList : res ?. data } ) ;
26- } ) ;
27- }
22+ historyService
23+ . getSavedConsoleList ( {
24+ tabOpened : 'y' ,
25+ pageNo : 1 ,
26+ pageSize : 20 ,
27+ } )
28+ . then ( ( res ) => {
29+ useWorkspaceStore . setState ( { consoleList : res ?. data } ) ;
30+ } ) ;
31+ } ;
2832
2933export const setActiveConsoleId = ( id : IConsoleStore [ 'activeConsoleId' ] ) => {
3034 useWorkspaceStore . setState ( { activeConsoleId : id } ) ;
31- }
35+ } ;
3236
3337export const setWorkspaceTabList = ( items : IConsoleStore [ 'workspaceTabList' ] ) => {
3438 useWorkspaceStore . setState ( { workspaceTabList : items } ) ;
35- }
39+ } ;
3640
37- export const createConsole = ( params : ICreateConsoleParams ) => {
41+ export const createConsole = ( params : ICreateConsoleParams ) => {
3842 const workspaceTabList = useWorkspaceStore . getState ( ) . workspaceTabList ;
3943 const newConsole = {
4044 ...params ,
4145 name : params . name || 'new console' ,
4246 ddl : params . ddl || '' ,
4347 status : ConsoleStatus . DRAFT ,
4448 operationType : WorkspaceTabType . CONSOLE ,
45- type : params . databaseType
49+ type : params . databaseType ,
4650 } ;
4751
48- return new Promise ( ( resolve , j ) => {
52+ return new Promise ( ( resolve ) => {
4953 if ( ( workspaceTabList ?. length || 0 ) > 20 ) {
50- j ( 'tab数量超过上限' ) ;
51- return
54+ return ;
5255 }
56+ useWorkspaceStore . setState ( { createConsoleLoading : true } ) ;
5357 historyService . createConsole ( newConsole ) . then ( ( res ) => {
58+ // 找到活跃的id的位置
59+ // const activeIndex = workspaceTabList?.findIndex(
60+ // (item) => item?.id === useWorkspaceStore.getState().activeConsoleId,
61+ // );
62+ // // 向活跃的位置后插入数据
63+ // if (activeIndex !== -1) {
64+ // workspaceTabList?.splice(activeIndex + 1, 0, {
65+ // id: res,
66+ // title: newConsole.name,
67+ // type: newConsole.operationType,
68+ // uniqueData: newConsole,
69+ // });
70+ // }
71+
5472 const newList = [
55- ...( workspaceTabList || [ ] ) ,
73+ ...( workspaceTabList || [ ] ) ,
5674 {
5775 id : res ,
5876 title : newConsole . name ,
5977 type : newConsole . operationType ,
6078 uniqueData : newConsole ,
6179 } ,
6280 ] ;
81+
6382 setWorkspaceTabList ( newList ) ;
6483 setActiveConsoleId ( res ) ;
6584 resolve ( res ) ;
85+ } )
86+ . finally ( ( ) => {
87+ useWorkspaceStore . setState ( { createConsoleLoading : false } ) ;
6688 } ) ;
6789 } ) ;
68- }
90+ } ;
6991
7092export const addWorkspaceTab = ( params : IWorkspaceTab ) => {
7193 const workspaceTabList = useWorkspaceStore . getState ( ) . workspaceTabList ;
72- if ( workspaceTabList ?. findIndex ( ( item ) => item ?. id === params ?. id ) !== - 1 ) {
94+ if ( workspaceTabList ?. findIndex ( ( item ) => item ?. id === params ?. id ) !== - 1 ) {
7395 setActiveConsoleId ( params . id ) ;
7496 return ;
7597 }
76-
77- const newList = [
78- ...( workspaceTabList || [ ] ) ,
79- params ,
80- ] ;
98+
99+ const newList = [ ...( workspaceTabList || [ ] ) , params ] ;
81100
82101 setWorkspaceTabList ( newList ) ;
83102 setActiveConsoleId ( params . id ) ;
0 commit comments