公共组件 #18
@@ -1,36 +1,18 @@
|
|||||||
<div class="inner-content">
|
<common-table #commonTableComponent
|
||||||
<nz-card nzTitle="友链管理" nzSize="small" [nzExtra]="reload">
|
cardTitle="友链管理"
|
||||||
<button nz-button (click)="addLink()" style="margin-bottom: 15px">新增</button>
|
[request]="request"
|
||||||
<nz-table #table [nzData]="pageList.list" [nzTotal]="pageList.total" [(nzPageIndex)]="pageIndex"
|
[headData]="headData"
|
||||||
[nzPageSize]="pageSize" [nzLoading]="loading" [nzScroll]="{x:'1200px'}"
|
[template]="{open:{temp:open,param:{true:'可见',false:'不可见'}},delete:{temp:deleteTemp,param:{true:'已删除',false:'未删除'}}}"
|
||||||
(nzPageIndexChange)="getLinks()" nzFrontPagination="false">
|
>
|
||||||
<thead>
|
</common-table>
|
||||||
<th>友链名称</th>
|
|
||||||
<th>友链地址</th>
|
|
||||||
<th>是否可见</th>
|
|
||||||
<th>操作</th>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr *ngFor="let data of table.data">
|
|
||||||
<td>{{data.name}}</td>
|
|
||||||
<td><a [href]="data.url" target="_blank">{{data.url}}</a></td>
|
|
||||||
<td>
|
|
||||||
<input type="checkbox" disabled [checked]="data.open">
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a (click)="showEdit(data)" class="edit-opr">编辑</a>
|
|
||||||
<nz-divider nzType="vertical"></nz-divider>
|
|
||||||
<a nz-popconfirm nzPopconfirmTitle="确定要删除这条友链吗?" nzOkText="删除" nzCancelText="点错了"
|
|
||||||
(nzOnConfirm)="delete(data.id)" class="del-opr">删除</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</nz-table>
|
|
||||||
</nz-card>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ng-template #reload>
|
<ng-template #open let-value="value">
|
||||||
<a (click)="getLinks()" title="刷新"><i nz-icon nzType="reload" nzTheme="outline"></i></a>
|
<label nz-checkbox nzDisabled [ngModel]="value"></label>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<ng-template let-value="value" let-originValue="originValue" #deleteTemp>
|
||||||
|
<nz-tag [nzColor]="'blue'" *ngIf="originValue=='false'">{{value}}</nz-tag>
|
||||||
|
<nz-tag [nzColor]="'#ff5500'" *ngIf="originValue!='false'">{{value}}</nz-tag>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
<nz-modal [(nzVisible)]="modalVisible" [nzTitle]="modalTitle" (nzOnOk)="modalConfirm()"
|
<nz-modal [(nzVisible)]="modalVisible" [nzTitle]="modalTitle" (nzOnOk)="modalConfirm()"
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
import {Component, OnInit} from '@angular/core';
|
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||||
import {PageList, Response} from '../../../class/HttpReqAndResp';
|
import {RequestObj, Response} from '../../../class/HttpReqAndResp';
|
||||||
import {Link} from '../../../class/Link';
|
import {Link} from '../../../class/Link';
|
||||||
import {ApiService} from '../../../api/api.service';
|
import {ApiService} from '../../../api/api.service';
|
||||||
import {NzMessageService} from 'ng-zorro-antd';
|
import {NzMessageService} from 'ng-zorro-antd';
|
||||||
import {FormControl, FormGroup, Validators} from '@angular/forms';
|
import {FormControl, FormGroup, Validators} from '@angular/forms';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {Title} from '@angular/platform-browser';
|
import {Title} from '@angular/platform-browser';
|
||||||
|
import {CommonTableComponent} from '../components/common-table/common-table.component';
|
||||||
|
import {Data} from '../components/common-table/data';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-admin-link',
|
selector: 'app-admin-link',
|
||||||
templateUrl: './admin-link.component.html',
|
templateUrl: './admin-link.component.html'
|
||||||
styleUrls: ['./admin-link.component.less']
|
|
||||||
})
|
})
|
||||||
export class AdminLinkComponent implements OnInit {
|
export class AdminLinkComponent implements OnInit {
|
||||||
|
|
||||||
@@ -25,35 +26,51 @@ export class AdminLinkComponent implements OnInit {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pageList: PageList<Link> = new PageList<Link>();
|
|
||||||
loading: boolean = true;
|
|
||||||
pageIndex: number = 1;
|
|
||||||
pageSize: number = 10;
|
|
||||||
modalVisible: boolean = false;
|
modalVisible: boolean = false;
|
||||||
modalTitle: string = '';
|
modalTitle: string = '';
|
||||||
formGroup: FormGroup;
|
formGroup: FormGroup;
|
||||||
|
request: RequestObj;
|
||||||
getLinks = () => this.apiService.adminLinks(this.pageSize, this.pageIndex).subscribe({
|
@ViewChild('commonTableComponent') commonTableComponent: CommonTableComponent<Link>
|
||||||
next: data => this.pageList = data.result,
|
headData: Data<Link>[];
|
||||||
error: () => this.loading = false,
|
|
||||||
complete: () => this.loading = false,
|
|
||||||
})
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.getLinks();
|
this.request = {
|
||||||
|
path: '/admin/links',
|
||||||
|
method: 'GET',
|
||||||
|
queryParam: {
|
||||||
|
count: 10,
|
||||||
|
page: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.headData = [
|
||||||
|
{title: '主键', fieldValue: 'id', show: false, primaryKey: true},
|
||||||
|
{title: '友链名称', fieldValue: 'name', show: true},
|
||||||
|
{title: '友链地址', fieldValue: 'url', show: true},
|
||||||
|
{title: '是否可见', fieldValue: 'open', show: true},
|
||||||
|
{title: '描述', fieldValue: 'desc', show: false},
|
||||||
|
{title: '图标', fieldValue: 'iconPath', show: false},
|
||||||
|
{title: '状态', fieldValue: 'delete', show: true},
|
||||||
|
{
|
||||||
|
title: '操作', fieldValue: '', show: true, isActionColumns: true, action: [
|
||||||
|
{name: '访问', click: (data) => window.open(data.url)},
|
||||||
|
{name: '编辑', click: (data) => this.showEdit(data)},
|
||||||
|
{name: '删除', color: 'red', needConfirm: true, click: (data) => this.delete(data.id)},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(id: number) {
|
delete(id: number) {
|
||||||
this.apiService.deleteLink(id).subscribe({
|
this.apiService.deleteLink(id).subscribe({
|
||||||
next: data => {
|
next: data => {
|
||||||
this.messageService.success('删除成功');
|
this.messageService.success('删除成功');
|
||||||
this.getLinks();
|
this.commonTableComponent.getData();
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.loading = false;
|
|
||||||
this.messageService.error('删除失败');
|
this.messageService.error('删除失败');
|
||||||
},
|
},
|
||||||
complete: () => this.loading = false,
|
complete: () => null,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +101,7 @@ export class AdminLinkComponent implements OnInit {
|
|||||||
observable.subscribe({
|
observable.subscribe({
|
||||||
next: data => this.messageService.success('操作成功'),
|
next: data => this.messageService.success('操作成功'),
|
||||||
error: err => this.messageService.error('操作失败,' + err.msg),
|
error: err => this.messageService.error('操作失败,' + err.msg),
|
||||||
complete: () => this.getLinks()
|
complete: () => this.commonTableComponent.getData()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,9 @@ import {NgModule} from '@angular/core';
|
|||||||
import {CommonModule} from '@angular/common';
|
import {CommonModule} from '@angular/common';
|
||||||
import {RouterModule} from '@angular/router';
|
import {RouterModule} from '@angular/router';
|
||||||
import {AdminLinkComponent} from './admin-link.component';
|
import {AdminLinkComponent} from './admin-link.component';
|
||||||
import {
|
import {CommonTableModule} from '../components/common-table/common-table.module';
|
||||||
NzButtonModule,
|
import {NzCheckboxModule, NzFormModule, NzInputModule, NzModalModule, NzSelectModule, NzTagModule} from 'ng-zorro-antd';
|
||||||
NzCardModule,
|
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||||
NzDividerModule,
|
|
||||||
NzFormModule, NzIconModule, NzInputModule,
|
|
||||||
NzModalModule,
|
|
||||||
NzPopconfirmModule, NzSelectModule,
|
|
||||||
NzTableModule
|
|
||||||
} from 'ng-zorro-antd';
|
|
||||||
import {ReactiveFormsModule} from '@angular/forms';
|
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
@@ -21,17 +14,16 @@ import {ReactiveFormsModule} from '@angular/forms';
|
|||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
RouterModule.forChild([{path: '', component: AdminLinkComponent}]),
|
RouterModule.forChild([{path: '', component: AdminLinkComponent}]),
|
||||||
NzCardModule,
|
CommonTableModule,
|
||||||
NzTableModule,
|
NzCheckboxModule,
|
||||||
NzDividerModule,
|
|
||||||
NzPopconfirmModule,
|
|
||||||
NzModalModule,
|
NzModalModule,
|
||||||
|
FormsModule,
|
||||||
NzFormModule,
|
NzFormModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
NzInputModule,
|
NzInputModule,
|
||||||
NzSelectModule,
|
NzSelectModule,
|
||||||
NzButtonModule,
|
NzTagModule,
|
||||||
NzIconModule
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class AdminLinkModule {
|
export class AdminLinkModule {
|
||||||
|
|||||||
Reference in New Issue
Block a user