import { useState } from 'react' ; import { useModel } from 'umi' ; export default ( ) => { const { setStateByObjectKeys , pageSchema , selectPageIndex } = useModel ( 'bridge' ) ; const [ page , setPage ] = useState < { createModalVisible : boolean ; configModalVisible : boolean ; } > ( { createModalVisible : false , configModalVisible : false , } ) ; const openCreatePageDrawer = function ( ) { setPage ( { ... page , createModalVisible : true , } ) ; } ; const closeCreatePageDrawer = function ( ) { setPage ( { ... page , createModalVisible : false , } ) ; } ; const onCreatePage = function ( newPage ) { const newPageSchame = [ ... pageSchema , newPage ] ; const newSelectPageIndex = selectPageIndex !== - 1 ? selectPageIndex : 0 ; setPage ( { createModalVisible : false , configModalVisible : false , } ) ; setStateByObjectKeys ( { pageSchema : newPageSchame , selectPageIndex : newSelectPageIndex , } ) ; } ; const openConfigPageDrawer = function ( ) { setPage ( { ... page , configModalVisible : true , } ) ; } ; const closeConfigPageDrawer = function ( ) { setPage ( { ... page , configModalVisible : false , } ) ; } ; return { page , setPage , openCreatePageDrawer , closeCreatePageDrawer , onCreatePage , openConfigPageDrawer , closeConfigPageDrawer , } ; } ;