Newer
Older
import {Component, ViewChild} from '@angular/core';
import {Platform, AlertController, Content} from 'ionic-angular';
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';
import {Storage} from "@ionic/storage";
import {LoginPage} from '../pages/login/login';
import {AppVersion} from '@ionic-native/app-version';
import {AppUpdateService} from "../service/appUpdate.service";
import {Keyboard} from '@ionic-native/keyboard';
import {Response} from "@angular/http";
import {TabsPage} from "../pages/tabs/tabs";
import {AppService} from "../service/http.service";
import {MobileAccessibility} from "@ionic-native/mobile-accessibility";
import {ScreenOrientation} from "@ionic-native/screen-orientation";
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Content) content: Content;
rootPage;
user;
constructor(platform: Platform,
public statusBar: StatusBar,
public splashScreen: SplashScreen,
private alertCtrl: AlertController,
private keyboard: Keyboard,
private appUpdateService: AppUpdateService,
private appVersion: AppVersion,
public appService: AppService) {
platform.ready().then(() => {
this.splashScreen.hide();
this.statusBar.show();
this.statusBar.overlaysWebView(false);
this.statusBar.backgroundColorByHexString('#e12724');
this.statusBar.styleLightContent();
if (platform.is('android')) {
this.screenOrientation.lock('portrait-primary'); //锁定竖屏
}
timer(4500).subscribe((res) => {
this.showSplash = false;
//检测是否需要更新
this.appVersion.getVersionNumber().then((version: string) => {
this.appUpdateService.compariVersion().subscribe(res => {
let data = res.json();
if (data.code == 200) {
if (data.latestVersion != null && data.latestVersion != version) {
this.appUpdateService.detectionUpgrade(data.androidDownload, true); //提示升级
}
}
});
}).catch(err => {
console.log('getVersionNumber:' + err);
});
}
loadLogin() {
this.storage.get("userLoginInfo").then((value) => {
if (value != null && value != '') {
this.user = value;
this.appService.ObserverHttpPost("/wisdomgroup/app/loginpost", this.user)
.subscribe((res: Response) => {
let data = res.json();
if (data["code"] == '200') {
this.storage.set('user', data.data);
this.user.userid = data.data.id;
this.storage.set('userLoginInfo', this.user);
this.rootPage = TabsPage;
} else {
this.appService.alert('手机号或密码错误!');
this.rootPage = LoginPage;
}
}, error => {
this.rootPage = LoginPage;
this.appService.alert('网络异常!');
}
);
this.appService.ObserverHttpPost("/wisdomgroup/modules/message/findAllActivityForAppWithXQ", null)
.subscribe((res: Response) => {
let data = res.json();
let num = 0;
if (data.length > 0) {
data.forEach(e => {
if (e.isRead == 0) num++;