1- import { IConnectionDetails } from "@/typings"
2-
3- export interface ConnectionState {
4- curConnection : IConnectionDetails
5- connectionList : IConnectionDetails [ ]
1+ import { IConnectionDetails } from '@/typings/connection' ;
2+ import { Effect , Reducer } from 'umi' ;
3+ import connectionService from '@/service/connection' ;
4+ import { IPageResponse } from '@/typings/common' ;
5+
6+ /**
7+ * 数据源相关 - 链接池、数据库、schema、表
8+ */
9+ export interface ConnectionModelState {
10+ curConnection ?: IConnectionDetails ;
11+ connectionList : IConnectionDetails [ ] ;
612}
713
14+ export interface ConnectionModelType {
15+ namespace : 'connection' ;
16+ state : ConnectionModelState ;
17+ reducers : {
18+ // 设置连接池列表
19+ setConnectionList : Reducer < ConnectionModelState > ;
20+ setCurConnection : Reducer < ConnectionModelState > ;
21+ } ;
22+ effects : {
23+ // setConnectionList: Effect;
24+ } ;
25+ }
826
9- export default {
10- namespace : 'connection' ,
11- state : {
12- curConnection : null ,
13- connectionList : [ ] ,
27+ // const ConnectionModel:ConnectionModelType = {
28+ const ConnectionModel = {
29+ namespace : 'connection' ,
30+ state : {
31+ curConnection : undefined ,
32+ connectionList : [ ] ,
33+ } ,
34+ reducers : {
35+ // 设置连接池列表
36+ setConnectionList ( state : ConnectionModelState , { payload } : { payload : ConnectionModelState [ 'connectionList' ] } ) {
37+ return {
38+ ...state ,
39+ connectionList : payload ,
40+ } ;
1441 } ,
1542
16- reducers : {
17- // 获取连接池列表
18- setConnectionList ( state : ConnectionState , { payload } : { payload : ConnectionState [ 'connectionList' ] } ) {
19- return {
20- ...state ,
21- connectionList : payload
22- }
23- } ,
43+ // 设置当前选着的Connection
44+ setCurConnection ( state : ConnectionModelState , { payload } : { payload : ConnectionModelState [ 'curConnection' ] } ) {
45+ return { ...state , curConnection : payload } ;
46+ } ,
2447
25- // 设置当前选着的Connection
26- setCurConnection (
27- state : ConnectionState ,
28- { payload } : { payload : ConnectionState [ 'curConnection' ] } ,
29- ) {
30- return { ...state , curConnection : payload }
31- } ,
48+ } ,
3249
50+ effects : {
51+ * fetchConnectionList ( _ , { call, put } ) {
52+ const res = ( yield connectionService . getList ( { pageNo : 1 , pageSize : 999 } ) ) as IPageResponse < IConnectionDetails > ;
53+ console . log ( 'fetchConnectionList==>' , res . data ) ;
54+ yield put ( {
55+ type : 'setConnectionList' ,
56+ payload : res . data ,
57+ } ) ;
58+ } ,
3359
60+ } ,
61+ } ;
3462
35- }
36- }
63+ export default ConnectionModel ;
0 commit comments