import { Injectable } from "@angular/core" ; @ Injectable ( ) export class ScreenService { fsChangeEvents = { } ; fsEvent = 'fullscreenchange' ; fsEvents = [ this . fsEvent , 'webkit' + this . fsEvent , 'moz' + this . fsEvent , 'MS' + this . fsEvent ] ; document = document as any ; window = window as any ; param el param didFull fullScreen ( el , didFull ) { if ( typeof el === 'string' ) el = this . document . querySelector ( el ) ; if ( el && el . tagName ) { const rfs = el . requestFullScreen || el . webkitRequestFullScreen || el . mozRequestFullScreen || el . msRequestFullScreen ; rfs ? rfs . call ( el ) : this . sendF11 ( ) ; if ( fn . isFun ( didFull ) ) { let timer ; timer = fn . interval ( 100 , ( ) => { if ( this . isFullScreen ( ) ) clearInterval ( timer ) , fn . defer ( didFull ) ; } ) ; } } } param didExit exitFullScreen ( didExit ) { const cfs = this . document . cancelFullScreen || this . document . webkitCancelFullScreen || this . document . mozCancelFullScreen || this . document . exitFullScreen ; cfs ? cfs . call ( document ) : this . sendF11 ( ) ; if ( fn . isFun ( didExit ) ) { let timer ; timer = fn . interval ( 100 , ( ) => { if ( ! this . isFullScreen ( ) ) clearInterval ( timer ) , fn . defer ( didExit ) ; } ) ; } } sendF11 ( ) { if ( this . window . ActiveXObject ) { const ws = new this . window . ActiveXObject ( 'WScript.Shell' ) ; if ( ws ) ws . SendKeys ( '{F11}' ) ; } } /**
     * [fn.isFullScreen] 检测是否全屏状态
     */ isFullScreen ( ) { return ! ! ( this . document . fullscreenElement || this . document . msFullscreenElement || this . document . mozFullScreenElement || this . document . webkitFullscreenElement ) ; } param callback fullScreenChange ( callback ) { if ( fn . isFun ( callback ) ) { const eventId = fn . randomId ( 32 ) ; this . fsChangeEvents [ eventId ] = callback ; fn . forEach ( this . fsEvents , e => { this . document . addEventListener ( e , this . fsChangeEvents [ eventId ] ) ; } ) ; return { 'remove' : ( ) => { this . rmFsChangeEvent ( eventId ) ; } } ; } } rmFsChangeEvent ( eventId ) { fn . forEach ( this . fsEvents , e => { this . document . removeEventListener ( e , this . fsChangeEvents [ eventId ] ) ; } ) ; delete this . fsChangeEvents [ eventId ] ; } }