用户管理

This commit is contained in:
禾几海
2020-07-11 10:03:22 +08:00
parent 36db5289a4
commit 89ec668b39
4 changed files with 63 additions and 84 deletions

View File

@@ -1,40 +1,16 @@
<div class="inner-content"> <common-table [headData]="headData"
<nz-card nzTitle="用户管理" nzSize="small" [nzExtra]="reload"> [request]="request"
<nz-table #table [nzData]="pageList.list" [nzTotal]="pageList.total" [(nzPageIndex)]="pageIndex" [template]="{role:{temp:role},emailStatus:{temp:emailStatus,param:{true:'已验证',false:'未验证'}}}"
[nzPageSize]="pageSize" [nzLoading]="loading" [nzScroll]="{x:'800px'}" >
(nzPageIndexChange)="getUser()" nzFrontPagination="false"> </common-table>
<thead> <ng-template let-value="value" #role>
<th>邮箱</th> <nz-tag [nzColor]="'blue'" *ngIf="value == 'admin'">{{value}}</nz-tag>
<th>昵称</th> <nz-tag [nzColor]="'purple'" *ngIf="value == 'user'">{{value}}</nz-tag>
<th>角色</th> </ng-template>
<th>邮箱验证状态</th> <ng-template let-value="value" let-originValue="originValue" #emailStatus>
<th>操作</th> <nz-tag [nzColor]="'green'" *ngIf="originValue !='false'">{{value}}</nz-tag>
</thead> <nz-tag [nzColor]="'red'" *ngIf="originValue !='true'">{{value}}</nz-tag>
<tbody> </ng-template>
<tr *ngFor="let data of table.data">
<td>{{data.email}}</td>
<td>{{data.displayName}}</td>
<td>
<nz-tag [nzColor]="'blue'" *ngIf="data.role == 'admin'">{{data.role}}</nz-tag>
<nz-tag [nzColor]="'purple'" *ngIf="data.role == 'user'">{{data.role}}</nz-tag>
</td>
<td>
<nz-tag [nzColor]="'green'" *ngIf="data.emailStatus">已验证</nz-tag>
<nz-tag [nzColor]="'red'" *ngIf="!data.emailStatus">未验证</nz-tag>
</td>
<td>
<a (click)="showModal(true, data)" class="edit-opr">编辑</a>
<nz-divider nzType="vertical"></nz-divider>
<a (click)="showModal(false, data)" class="show-opr">查看</a>
<nz-divider nzType="vertical"></nz-divider>
<a nz-popconfirm nzPopconfirmTitle="确定要删除这个用户吗?" nzOkText="删除" nzCancelText="点错了"
(nzOnConfirm)="deleteUser(data.id)" class="del-opr">删除</a>
</td>
</tr>
</tbody>
</nz-table>
</nz-card>
</div>
<nz-modal [(nzVisible)]="modalData.visible" [nzClosable]="true" [nzTitle]="modalData.title" <nz-modal [(nzVisible)]="modalData.visible" [nzClosable]="true" [nzTitle]="modalData.title"
(nzOnCancel)="modalData.visible = false" (nzOnOk)="modalConfirm()" (nzOnCancel)="modalData.visible = false" (nzOnOk)="modalConfirm()"
@@ -115,8 +91,3 @@
</ng-template> </ng-template>
</nz-modal> </nz-modal>
<ng-template #reload>
<a (click)="getUser()" title="刷新"><i nz-icon nzType="reload" nzTheme="outline"></i></a>
</ng-template>

View File

@@ -2,15 +2,15 @@ import {Component, OnInit} from '@angular/core';
import {NzMessageService} from 'ng-zorro-antd'; import {NzMessageService} from 'ng-zorro-antd';
import {Title} from '@angular/platform-browser'; import {Title} from '@angular/platform-browser';
import {FormControl, FormGroup} from '@angular/forms'; import {FormControl, FormGroup} from '@angular/forms';
import {PageList} from '../../../class/HttpReqAndResp'; import {RequestObj} from '../../../class/HttpReqAndResp';
import {ApiService} from '../../../api/api.service'; import {ApiService} from '../../../api/api.service';
import {User} from '../../../class/User'; import {User} from '../../../class/User';
import {GlobalUserService} from '../../../services/global-user.service'; import {GlobalUserService} from '../../../services/global-user.service';
import {Data} from '../components/common-table/data';
@Component({ @Component({
selector: 'app-admin-user', selector: 'app-admin-user',
templateUrl: './admin-user.component.html', templateUrl: './admin-user.component.html'
styleUrls: ['./admin-user.component.less']
}) })
export class AdminUserComponent implements OnInit { export class AdminUserComponent implements OnInit {
@@ -32,12 +32,7 @@ export class AdminUserComponent implements OnInit {
}) })
} }
pageIndex: number = 1;
pageSize: number = 10;
pageList: PageList<User> = new PageList<User>();
user: User; user: User;
loading: boolean = true;
modalData = { modalData = {
visible: false, visible: false,
title: null, title: null,
@@ -46,29 +41,44 @@ export class AdminUserComponent implements OnInit {
} }
formGroup: FormGroup; formGroup: FormGroup;
headData: Data<User>[];
request: RequestObj;
ngOnInit(): void { ngOnInit(): void {
this.title.setTitle('小海博客 | 用户管理') this.title.setTitle('小海博客 | 用户管理')
this.getUser(); this.request = {
path: '/admin/users',
method: 'GET',
queryParam: {
count: 1,
page: 10
}
};
this.headData = [
{fieldValue: 'id', title: '主键', primaryKey: true, show: false},
{fieldValue: 'email', title: '邮箱', show: true},
{fieldValue: 'displayName', title: '昵称', show: true},
{fieldValue: 'role', title: '角色', show: true},
{fieldValue: 'emailStatus', title: '邮箱验证状态', show: true},
{fieldValue: 'desc', title: '描述', show: false},
{fieldValue: 'avatarImgUrl', title: '头像', show: false},
{fieldValue: 'recentlyLandedDate', title: '最近登录日期', show: false},
{
fieldValue: '', title: '操作', show: true, isActionColumns: true,
action: [
{name: '查看', click: data => this.showModal(false, data)},
{name: '编辑', color: 'blue', click: data => this.showModal(true, data)},
{name: '删除', color: 'red', needConfirm: true, click: data => this.deleteUser(data.id)}
]
},
];
} }
getUser = () => this.apiService.adminUsers(this.pageSize, this.pageIndex).subscribe({
next: data => this.pageList = data.result,
complete: () => this.loading = false,
error: err => this.loading = false
})
deleteUser(id) { deleteUser(id) {
this.loading = true;
this.apiService.deleteUser(id).subscribe({ this.apiService.deleteUser(id).subscribe({
next: data => { next: data => this.messageService.success('删除成功'),
this.messageService.success('删除成功') error: err => this.messageService.error(err.msg)
this.loading = false;
this.getUser();
},
error: err => {
this.messageService.error(err.msg)
this.loading = false
}
}) })
} }
@@ -84,7 +94,6 @@ export class AdminUserComponent implements OnInit {
this.modalData.visible = false this.modalData.visible = false
this.apiService.adminUpdateUser(this.formGroup.value).subscribe({ this.apiService.adminUpdateUser(this.formGroup.value).subscribe({
next: data => { next: data => {
this.getUser();
this.messageService.success('修改用户信息成功'); this.messageService.success('修改用户信息成功');
this.userService.refreshUserInfo(); this.userService.refreshUserInfo();
} }

View File

@@ -2,16 +2,17 @@ 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 {AdminUserComponent} from './admin-user.component'; import {AdminUserComponent} from './admin-user.component';
import {ReactiveFormsModule} from '@angular/forms';
import {CommonTableModule} from '../components/common-table/common-table.module';
import { import {
NzButtonModule, NzButtonModule,
NzCardModule, NzFormModule,
NzDividerModule, NzFormModule, NzIconModule, NzInputModule, NzGridModule,
NzModalModule, NzIconModule,
NzPopconfirmModule, NzRadioModule, NzSelectModule, NzInputModule, NzModalModule,
NzTableModule, NzRadioModule,
NzTagModule NzSelectModule, NzTagModule
} from 'ng-zorro-antd'; } from 'ng-zorro-antd';
import {ReactiveFormsModule} from '@angular/forms';
@NgModule({ @NgModule({
@@ -21,19 +22,17 @@ import {ReactiveFormsModule} from '@angular/forms';
imports: [ imports: [
CommonModule, CommonModule,
RouterModule.forChild([{path: '', component: AdminUserComponent}]), RouterModule.forChild([{path: '', component: AdminUserComponent}]),
NzCardModule,
NzTableModule,
NzPopconfirmModule,
NzDividerModule,
NzTagModule,
NzModalModule,
NzButtonModule,
NzFormModule,
ReactiveFormsModule, ReactiveFormsModule,
CommonTableModule,
NzGridModule,
NzButtonModule,
NzInputModule, NzInputModule,
NzSelectModule, NzIconModule,
NzRadioModule, NzRadioModule,
NzIconModule NzSelectModule,
NzFormModule,
NzModalModule,
NzTagModule
] ]
}) })