Newer
Older
import {Component, ElementRef, ViewChild} from '@angular/core';
import {NavParams, Platform} from 'ionic-angular';
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';
import {TabsPage} from '../pages/tabs/tabs';
import {LoginPage} from "../pages/login/login";
import {Storage} from "@ionic/storage";
import {LoginService} from "../pages/login/login.service";
import {CommonService} from "../core/common.service";
import {timer} from "rxjs/observable/timer";
import {GetRequestService} from "../secret/getRequest.service";
import {AppVersion} from "@ionic-native/app-version";
import {AppUpdateService} from "../core/appUpdate.service";
import {MobileAccessibility} from "@ionic-native/mobile-accessibility";
import {HomePage} from "../pages/home/home";
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild('loadImg') loadImg: ElementRef;
rootPage: any;
showSplash = false;
load = {
imgUrl: null,
httpUrl: null
};
app = {
UpdateTips: false,
AppUrl: '',
UpdateText: '',
};
constructor(private platform: Platform, private statusBar: StatusBar, private commonSer: CommonService,
private getRequest: GetRequestService, private appVersion: AppVersion,
private appUpdate: AppUpdateService,
private mobileAccess: MobileAccessibility,
private splashScreen: SplashScreen, private storage: Storage, private loginSer: LoginService) {
this.platform.ready().then(() => {
//app字体不跟随手机字体大小变化
this.mobileAccess.usePreferredTextZoom(false);
this.statusBar.show();
this.statusBar.overlaysWebView(false);
this.globle.token = value;
this.storage.get('mineInfo').then(
(value) => {
this.globle.userObj = value;
if (value) {
this.rootPage = TabsPage;
} else {
this.rootPage = LoginPage;
}
);
this.storage.get('area').then(
(value) => {
this.globle.area = value;
}
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
});
}
imgLoad() {
timer(500).subscribe(() => this.splashScreen.hide());
console.log('图片加载完成')
}
//检测版本
checkVersion() {
let versionCode;
let platform;
if (this.platform.is('ios')) platform = 'IOS';
if (this.platform.is('android')) platform = 'android';
this.appVersion.getVersionNumber().then((version: string) => {
versionCode = version.split('.').join('');
const data = {
code: platform
};
let res;
const onlineVersion = res.data.AppVersion.split('.').join('');
if (versionCode != onlineVersion) {
this.app.UpdateTips = true;
this.app.AppUrl = res.data.AppUrl;
this.app.UpdateText = res.data.UpdateText;
}
}).catch(err => {
console.log(err);
});
}
//打开链接
openUrl() {
if (this.load.httpUrl) {
this.commonSer.openUrlByBrowser(this.load.httpUrl);
}
}
}