import { SyncEvent } from '../../event/SyncEvent' ; import { createDivWithClassName } from '../../utils/dom' ; import { Mode } from '../../utils/types' ; import { AbstractWhiteboard } from '../AbstractWhiteboard/index' ; const prefix = 'fcw-board' ; export class MirrorWhiteboard extends AbstractWhiteboard { mode : Mode = 'mirror' ; /** 初始化操作 */ protected init ( ) { this . imgsContainer = createDivWithClassName ( `${ prefix }-imgs` , this . target ) ; this . pagesContainer = createDivWithClassName ( `${ prefix }-pages` , this . target ) ; if ( ! this . eventHub ) { throw new Error ( 'Invalid eventHub' ) ; } this . eventHub . on ( 'sync' , ( ev ) => { if ( ev . target !== 'whiteboard' || ! ev . border ) { return ; } if ( ev . event === 'borderSnap' ) { this . applySnap ( ev . border ) ; } if ( ev . event === 'borderChangePage' && ev . id === this . id ) { if ( this . isInitialized ) { this . onPageChange ( ev . border . visiblePageIndex ) ; } } if ( ev . event === 'finish' && ev . id === this . id ) { this . destroy ( ) ; } } ) ; } public destroy ( ) { super . destroy ( ) ; } /** 响应页面切换的事件 */ onPageChange ( nextPageIndex ) { if ( this . visiblePageIndex === nextPageIndex ) { return ; } this . siema . goTo ( nextPageIndex ) ; this . visiblePageIndex = nextPageIndex ; this . pages . forEach ( ( page , i ) => { if ( nextPageIndex === i ) { page . show ( ) ; } else { page . hide ( ) ; } } ) ; this . emit ( { event : 'borderChangePage' , id : this . id , target : 'whiteboard' , border : this . captureSnap ( ) , } ) ; } }