import { ChangeDetectorRef, Component } from '@angular/core'; import { Serve, MessageService } from 'pz-unit'; import { Router } from '@angular/router'; import { ServeUrl } from 'environments/environment'; @Component({ selector: 'app-config', template: `

配置个服务器地址吧

历史记录

服务器地址 创建时间 操作 {{data.serve}} {{data.createTime | date: 'yyyy-MM-dd HH:mm'}} 应用 删除
` }) export class ServerConfigComponent { public isVisible = false; public add: string; public serveLog: {serve: string, createTime: Date}[] = []; public nowSto = Serve(ServeUrl); public constructor(private router: Router, private msg: MessageService, private readonly changeDetectorRef: ChangeDetectorRef) { this.serveLog = localStorage.servelog ? JSON.parse(localStorage.servelog) : []; this.add = this.nowSto; this.msg.configSubject.subscribe( (v: boolean) => { this.isVisible = v; this.changeDetectorRef.detectChanges(); } ); } public saveDeploy(serve?: string) { let log = serve ? serve : this.add; if (log.lastIndexOf('/') !== log.length - 1 ) { log = `${log}/`; } if ( Serve(ServeUrl) === log ) { this.add = log; return true; } else { localStorage.add = log; this.add = log; this.serveLog = this.serveLog.filter( x => x.serve !== log ); this.serveLog.unshift({serve: log, createTime: new Date()}); localStorage.servelog = JSON.stringify(this.serveLog); this.msg.success('修改成功,2秒后返回首页'); setTimeout(() => { window.location.replace('/'); }, 2000); } } public delDeploy(serve?: string) { this.serveLog = this.serveLog.filter( x => x.serve !== serve ); localStorage.servelog = JSON.stringify(this.serveLog); } public handleOk(): void { this.isVisible = false; this.saveDeploy(); } public handleCancel(): void { this.isVisible = false; } }