import { Component, OnInit } from '@angular/core'; import { PublicService } from '../../PublicService'; import { Constants } from '../../Constant'; import { AlertController, NavController } from '@ionic/angular'; import { AppVersion } from '@ionic-native/app-version/ngx'; @Component({ selector: 'app-sys-setting', templateUrl: './sys-setting.page.html', styleUrls: ['./sys-setting.page.scss'], }) export class SysSettingPage implements OnInit { private user = this.publicService.getCurrentUser(); private userConfig = this.user.userConfig; private toggleValue; constructor(private readonly navController: NavController, private readonly appVersion: AppVersion, private readonly alertController: AlertController, private readonly publicService: PublicService) { } ngOnInit() { const isAutoLogin = this.user.userConfig.isAutoLogin; if (isAutoLogin === '0'){ this.toggleValue = false; }else{ this.toggleValue = true; } } toCheckVersion() { this.appVersion .getVersionNumber() .then(async (value: any) => { const alert = await this.alertController.create({ message: '当期版本 ' + value + '', cssClass: 'alert-default', buttons: [ // { // text: '取消' // }, { text: '确定', handler: () => { // this.download(downUrl); } } ] }); await alert.present(); console.log(value); }) .catch(err => { console.log('getVersionNumber:' + err); }); // this.appVersion // .getVersionNumber() // .then((value: any) => { // console.log(value); // }) // .catch(err => { // console.log('getVersionNumber:' + err); // }); } toggleChange(){ if (this.toggleValue){ this.userConfig.isAutoLogin = '1'; }else{ this.userConfig.isAutoLogin = '0'; } this.publicService.updateUserConfig(this.userConfig).then(res => { if (res.code === Constants.SUCCESS){ this.publicService.setCurrentUser(this.user); }else{ this.publicService.presentToast(res.msg); } }, err => { this.publicService.checkNetworkToast(err); }); } back(){ this.navController.back(); } }