import { createStore } from 'dahlia-store' ; export const popupStore = createStore ( { popups : [ ] as any [ ] , open ( name ) { if ( isPopupExist ( popupStore . popups , name ) ) { popupStore . popups = getNewPopups ( popupStore . popups , name , true ) ; return ; } popupStore . popups = [ ... popupStore . popups , { name , data : { } , isOpen : true } ] ; } , close ( name ) { popupStore . popups = getNewPopups ( popupStore . popups , name , false ) ; } , closeAll ( ) { popupStore . popups = closeAll ( popupStore . popups ) ; } , getPopup ( name ) { return popupStore . popups . find ( item => item . name === name ) ; } , } ) ; /**
 * popup是否打开过
 */ function isPopupExist ( popups , name ) { const result = popups . filter ( item => { return item . name === name ; } ) ; return result . length > 0 ; } function getNewPopups ( popups , name , isOpen ) { return popups . map ( item => { if ( item . name === name ) item . isOpen = isOpen ; return item ; } ) ; } function closeAll ( popups ) { return popups . map ( item => { item . isOpen = false ; return item ; } ) ; }