import { Component } from '@angular/core' ; import { IonicPage , NavController , NavParams , PopoverController } from 'ionic-angular' ; import { DomSanitizer } from "@angular/platform-browser" ; import { BrowserPopoverPage } from "./browser-popover" ; /**
 * Generated class for the BrowserPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */ @ IonicPage ( ) @ Component ( { selector : 'page-browser' , templateUrl : 'browser.html' , } ) export class BrowserPage { browser : any = { isLoaded : false , proObj : null , progress : 0 , secUrl : '' , title : '加载中' , url : '' , share : null } ; shareConfig : any = { isShow : true } ; constructor ( public navCtrl , private params , private sanitizer , private popoverCtrl ) { let browser = this . params . get ( 'browser' ) ; if ( browser ) { this . browser . title = browser . title ; this . browser . url = browser . url ; this . browser . secUrl = this . sanitizer . bypassSecurityTrustResourceUrl ( browser . url ) ; if ( browser . share ) { this . browser . share = browser . share ; } } else { this . browser . secUrl = this . sanitizer . bypassSecurityTrustResourceUrl ( this . browser . url ) ; } this . reload ( ) ; } ionViewDidLoad ( ) { if ( ! this . browser . proObj ) { this . browser . proObj = document . getElementById ( 'progress' ) ; } this . onprogress ( ) ; } private random ( min , max ) { return Math . floor ( Math . random ( ) * ( max - min + 1 ) + min ) ; } private onprogress ( ) { let timeout = this . random ( 10 , 30 ) ; let timer = setTimeout ( ( ) => { if ( this . browser . isLoaded ) { this . browser . proObj . style . width = '100%' ; clearTimeout ( timer ) ; return ; } this . browser . progress += this . random ( 1 , 5 ) ; if ( this . browser . progress > 90 ) { this . browser . progress = 90 ; } this . browser . proObj . style . width = this . browser . progress + '%' ; this . onprogress ( ) ; } , timeout ) ; } loaded ( ) { this . browser . isLoaded = true ; } presentPopover ( myEvent ) { let cb = { refresh : ( ) => { this . reload ( ) ; } , close : ( ) => { this . navCtrl . pop ( ) ; } , share : null } ; if ( this . browser . share ) { cb . share = ( ) => { this . share ( ) ; } ; } let popover = this . popoverCtrl . create ( 'BrowserPopoverPage' , { callback : cb } ) ; popover . present ( { ev : myEvent } ) ; } reload ( ) { let title = this . browser . title ; let url = this . browser . secUrl ; this . browser . title = '加载中' ; this . browser . secUrl = this . sanitizer . bypassSecurityTrustResourceUrl ( '' ) ; setTimeout ( ( ) => { this . browser . isLoaded = false ; this . browser . progress = 0 ; if ( ! this . browser . proObj ) { this . browser . proObj = document . getElementById ( 'progress' ) ; } this . onprogress ( ) ; this . browser . title = title ; this . browser . secUrl = url ; } , 10 ) ; } share ( ) { this . shareConfig . isShow = true ; } }