Skip to content
app.component.ts 3.66 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, ViewChild} from '@angular/core';
wangqinghua's avatar
wangqinghua committed
import {Platform, AlertController, Content} from 'ionic-angular';
wangqinghua's avatar
wangqinghua committed
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/appUpdateService';
import {Keyboard} from '@ionic-native/keyboard';
import {Badge} from '@ionic-native/badge';
wangqinghua's avatar
wangqinghua committed
import {Response} from "@angular/http";
import {TabsPage} from "../pages/tabs/tabs";
wangqinghua's avatar
wangqinghua committed
import {Geolocation} from "@ionic-native/geolocation";
wangqinghua's avatar
wangqinghua committed
import {AppService} from "../service/appHttpService";
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
@Component({
wangqinghua's avatar
wangqinghua committed
    templateUrl: 'app.html'
wangqinghua's avatar
wangqinghua committed
})
export class MyApp {

wangqinghua's avatar
wangqinghua committed
    @ViewChild(Content) content: Content;
    rootPage;
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    user;
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    constructor(platform: Platform,
                public statusBar: StatusBar,
                public splashScreen: SplashScreen,
                alertCtrl: AlertController,
                keyboard: Keyboard,
                appUpdateService: AppUpdateService,
                appVersion: AppVersion,
                private geolocation: Geolocation,
                badge: Badge,
                // public navCtrl: NavController,
                public storage: Storage,
                public appService: AppService) {
        platform.ready().then(() => {
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
            this.splashScreen.hide();
            this.statusBar.show();
            this.statusBar.overlaysWebView(false);
            this.statusBar.backgroundColorByHexString('#19b5ff');
            this.statusBar.styleLightContent();
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
            //检测是否需要更新
            appVersion.getVersionNumber().then((version: string) => {
                appUpdateService.compariVersion().subscribe(res => {
                    let data = res.json();
                    if (data.code == 200) {
                        if (data.latestVersion != null && data.latestVersion != version) {
                            appUpdateService.detectionUpgrade(data.androidDownload, true); //提示升级
                        }
                    }
                });
            }).catch(err => {
                console.log('getVersionNumber:' + err);
            });
        });
wangqinghua's avatar
wangqinghua committed


wangqinghua's avatar
wangqinghua committed
        this.loadLogin();
    }
wangqinghua's avatar
wangqinghua committed


wangqinghua's avatar
wangqinghua committed
    loadLogin() {
        this.storage.get("userLoginInfo").then((value) => {
            if (value != null && value != '') {
                this.user = value;
wangqinghua's avatar
wangqinghua committed
                if(this.user.remember){
                    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 => {
wangqinghua's avatar
wangqinghua committed
                                this.rootPage = LoginPage;
wangqinghua's avatar
wangqinghua committed
                                this.appService.alert('网络异常!');
wangqinghua's avatar
wangqinghua committed
                            }
wangqinghua's avatar
wangqinghua committed
                        );
                }else{
                    this.rootPage = LoginPage;
                }

wangqinghua's avatar
wangqinghua committed
            }
            else {
                this.rootPage = LoginPage;
            }
        });
    }
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
}