import {Component, OnInit} from '@angular/core'; import {PublicService} from '../PublicService'; import {Constants} from '../Constant'; import {LoadingController, ModalController, NavController} from '@ionic/angular'; @Component({ selector: 'app-service-manage', templateUrl: './service-manage.page.html', styleUrls: ['./service-manage.page.scss'], }) export class ServiceManagePage implements OnInit { private isHiddenList = true; private isShowAddServe = false; private serveList = []; private selectedServe = ''; private serveAddress = ''; private servePort = ''; private defaultApiUrl = Constants.hostServe; constructor(private readonly navController: NavController, private readonly publicService: PublicService, private readonly loadingCtrl: LoadingController) { this.serveList = this.publicService.getServeAddress(); this.selectedServe = this.publicService.getApiUrl(); } ngOnInit() { } showList(){ this.isHiddenList = !this.isHiddenList; } listSelect(item){ this.selectedServe = item; this.isHiddenList = true; } deleteItem(index){ this.serveList.splice(index, 1); this.publicService.setServeAddress(this.serveList); if (this.serveList.indexOf(this.selectedServe) === -1){ this.selectedServe = Constants.hostServe; } } addServe(){ this.isShowAddServe = true; } saveServe(){ const serveStr = this.serveAddress + (this.servePort ? ':' + this.servePort : ''); if (serveStr && (serveStr.startsWith('http://') || serveStr.startsWith('https://'))){ this.serveList.push(serveStr); this.unique(); this.publicService.setServeAddress(this.serveList); this.isShowAddServe = false; }else{ this.publicService.presentToast('请正确输入服务器地址'); } } async linkServe() { this.publicService.setApiUrl(this.selectedServe); const load = await this.publicService.showLoading(this.loadingCtrl, '测试连接服务中...'); this.publicService.apiTest().then(res => { window.localStorage.removeItem('token'); window.localStorage.removeItem('odcUser'); this.navController.navigateRoot('/login'); load.dismiss(); }, err => { this.publicService.presentToast('服务异常,请确认服务是否可用。'); load.dismiss(); }); } public unique(){ const x = new Set(this.serveList); this.serveList = [...x]; } public stopPropagation() { this.isHiddenList = true; } back(){ this.navController.back(); } }