Newer
Older
import {AlertController, IonicPage, NavController, NavParams} from 'ionic-angular';
import {AppService} from '../../service/appHttpService';
import {AppVersion} from '@ionic-native/app-version';
import {AppUpdateService} from '../../service/appUpdateService';
import {Storage} from "@ionic/storage";
version: string = '';
latestVersion: string = '';
isLatest: boolean = true;
pusNumber: boolean;
constructor(public navCtrl: NavController,
public navParams: NavParams,
public appService: AppService,
private appUpdateService: AppUpdateService,
private appVersion: AppVersion,
private storage: Storage,
private alertCtrl: AlertController) {
}
ionViewWillEnter() {
this.getversion();
this.getAppPush();
this.appUpdateService.compariVersion().subscribe(res => {
var data = res.json();
if (data.code == 200) {
this.latestVersion = data.latestVersion;
}
});
}
//获取推送开关
getAppPush() {
this.appService.ObserverHttpGet('/wisdomgroup/modules/common/file/getAppPush', null)
if(res._body == ""){
this.pusNumber = true;
}else{
this.pusNumber = res.json();
}
// if(res.json() == false){
// this.pusNumber = res.json();
// }else{
// this.pusNumber = true;
// }
//保存推送开关
savePush() {
this.appService.ObserverHttpGetAdd('/wisdomgroup/modules/common/file/addAppPush/', this.pusNumber)
//获取最新版本信息
getversion() {
//检测是否需要更新
this.appVersion.getVersionNumber().then((version: string) => {
this.version = version;
this.appUpdateService.compariVersion().subscribe(res => {
var data = res.json();
if (data.code == 200) {
this.latestVersion = data.latestVersion;
if (data.latestVersion != null && data.latestVersion != version) {
this.isLatest = false;
}
}
});
}).catch(err => {
});
}
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//更新
update() {
if (this.isLatest) {
const alert = this.alertCtrl.create({
subTitle: '已是最新版本',
buttons: ['确定']
});
alert.present();
} else {
const confirm = this.alertCtrl.create({
message: '有最新版本,是否更新?',
buttons: [
{
text: '取消',
handler: () => {
console.log('Disagree clicked');
}
},
{
text: '确定',
handler: () => {
this.appUpdateService.downloadApp("/wisdomgroup/app/download");
}
}
]
});
confirm.present();
}
}
//后台退出
logoutApp() {
let length = this.navCtrl.length();
this.navCtrl.remove(length);
this.storage.clear();
this.appService.ObserverHttpGet("/wisdomgroup/app/logout", null)
.subscribe((res: Response) => {
let data = res.json();
this.navCtrl.push('LoginPage');
}, error => {
}
);