diff --git a/index/src/app/view/admin/admin-comment/admin-comment.component.ts b/index/src/app/view/admin/admin-comment/admin-comment.component.ts
index c7804f3..c17b567 100644
--- a/index/src/app/view/admin/admin-comment/admin-comment.component.ts
+++ b/index/src/app/view/admin/admin-comment/admin-comment.component.ts
@@ -43,7 +43,7 @@ export class AdminCommentComponent implements OnInit {
},
error: err => {
this.loading = false;
- this.messageService.success(err.msg);
+ this.messageService.error(err.msg);
},
complete: () => this.loading = false
})
diff --git a/index/src/app/view/admin/admin-link/admin-link.component.html b/index/src/app/view/admin/admin-link/admin-link.component.html
index b5d07e0..8ce023f 100644
--- a/index/src/app/view/admin/admin-link/admin-link.component.html
+++ b/index/src/app/view/admin/admin-link/admin-link.component.html
@@ -1 +1,62 @@
-
admin-link works!
+
+
+
+
+
diff --git a/index/src/app/view/admin/admin-link/admin-link.component.ts b/index/src/app/view/admin/admin-link/admin-link.component.ts
index 8a6cf9b..ec3fd0b 100644
--- a/index/src/app/view/admin/admin-link/admin-link.component.ts
+++ b/index/src/app/view/admin/admin-link/admin-link.component.ts
@@ -1,15 +1,91 @@
-import { Component, OnInit } from '@angular/core';
+import {Component, OnInit} from '@angular/core';
+import {PageList, Response} from '../../../class/HttpReqAndResp';
+import {Link} from '../../../class/Link';
+import {ApiService} from '../../../api/api.service';
+import {NzMessageService} from 'ng-zorro-antd';
+import {FormControl, FormGroup, Validators} from '@angular/forms';
+import {Observable} from "rxjs";
@Component({
- selector: 'app-admin-link',
- templateUrl: './admin-link.component.html',
- styleUrls: ['./admin-link.component.less']
+ selector: 'app-admin-link',
+ templateUrl: './admin-link.component.html',
+ styleUrls: ['./admin-link.component.less']
})
export class AdminLinkComponent implements OnInit {
- constructor() { }
+ constructor(private apiService: ApiService, private messageService: NzMessageService) {
+ this.formGroup = new FormGroup({
+ id: new FormControl(null),
+ name: new FormControl(null, [Validators.required]),
+ url: new FormControl(null, [Validators.required, Validators.pattern(/^(https:\/\/|http:\/\/|)([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)]),
+ open: new FormControl(null, [Validators.required]),
+ oper: new FormControl(null)
+ })
+ }
- ngOnInit(): void {
- }
+ pageList: PageList = new PageList();
+ loading: boolean = true;
+ pageIndex: number = 1;
+ pageSize: number = 10;
+ modalVisible: boolean = false;
+ modalTitle: string = '';
+ formGroup: FormGroup;
+ getLinks = () => this.apiService.adminLinks(this.pageSize, this.pageIndex).subscribe({
+ next: data => this.pageList = data.result,
+ error: () => this.loading = false,
+ complete: () => this.loading = false,
+ })
+
+ ngOnInit(): void {
+ this.getLinks();
+ }
+
+ delete(id: number) {
+ this.apiService.deleteLink(id).subscribe({
+ next: data => {
+ this.messageService.success('删除成功');
+ this.getLinks();
+ },
+ error: () => {
+ this.loading = false;
+ this.messageService.error('删除失败');
+ },
+ complete: () => this.loading = false,
+ })
+ }
+
+ showEdit(data: Link) {
+ this.modalVisible = true;
+ this.modalTitle = '编辑友链信息';
+ this.formGroup.patchValue(data);
+ this.formGroup.controls.oper.setValue('edit')
+ }
+
+ modalConfirm() {
+ this.modalVisible = false;
+ const linkReq: Link = new Link();
+ linkReq.name = this.formGroup.value.name;
+ linkReq.url = this.formGroup.value.url;
+ linkReq.open = this.formGroup.value.open;
+ const oper = this.formGroup.value.oper;
+ let observable: Observable>;
+ if (oper === 'edit') {
+ linkReq.id = this.formGroup.value.id;
+ observable = this.apiService.updateLink(linkReq);
+ } else if (oper === 'add') {
+ observable = this.apiService.createLink(linkReq);
+ }
+ observable.subscribe({
+ next: data => this.messageService.success('操作成功'),
+ error: err => this.messageService.success('操作失败,', err.msg),
+ complete: () => this.getLinks()
+ })
+ }
+
+ addLink() {
+ this.modalVisible = true;
+ this.modalTitle = '新增友链信息';
+ this.formGroup.controls.oper.setValue('add')
+ }
}
diff --git a/index/src/app/view/admin/admin-link/admin-link.module.ts b/index/src/app/view/admin/admin-link/admin-link.module.ts
index d873613..961d6e4 100644
--- a/index/src/app/view/admin/admin-link/admin-link.module.ts
+++ b/index/src/app/view/admin/admin-link/admin-link.module.ts
@@ -2,6 +2,16 @@ import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {RouterModule} from '@angular/router';
import {AdminLinkComponent} from './admin-link.component';
+import {
+ NzButtonModule,
+ NzCardModule,
+ NzDividerModule,
+ NzFormModule, NzInputModule,
+ NzModalModule,
+ NzPopconfirmModule, NzSelectModule,
+ NzTableModule
+} from "ng-zorro-antd";
+import {ReactiveFormsModule} from "@angular/forms";
@NgModule({
@@ -10,7 +20,17 @@ import {AdminLinkComponent} from './admin-link.component';
],
imports: [
CommonModule,
- RouterModule.forChild([{path: '', component: AdminLinkComponent}])
+ RouterModule.forChild([{path: '', component: AdminLinkComponent}]),
+ NzCardModule,
+ NzTableModule,
+ NzDividerModule,
+ NzPopconfirmModule,
+ NzModalModule,
+ NzFormModule,
+ ReactiveFormsModule,
+ NzInputModule,
+ NzSelectModule,
+ NzButtonModule
]
})
export class AdminLinkModule {