提交代码

master
胡锐 7 months ago
parent 5aa3324715
commit a7549d7773
  1. 137
      src/app/pages/account/sys-account/sys-account.component.html
  2. 15
      src/app/pages/account/sys-account/sys-account.component.less
  3. 308
      src/app/pages/account/sys-account/sys-account.component.ts
  4. 16
      src/app/pages/account/sys-role/sys-role.component.html
  5. 3
      src/app/pages/account/sys-role/sys-role.component.less
  6. 6
      src/app/pages/account/sys-role/sys-role.component.ts
  7. 20
      src/app/pipes/account/sys-account-status.pipe.ts
  8. 104
      src/app/servies/account/sys-account.service.ts
  9. 10
      src/app/servies/role/role.service.ts

@ -1 +1,136 @@
<p>系统账户</p> <form nz-form [formGroup]="searchForm" class="search_form">
<div nz-row [nzGutter]="24">
<div nz-col [nzSpan]="4">
<nz-form-item>
<nz-form-label>用户名</nz-form-label>
<nz-form-control>
<input nz-input formControlName="userName" />
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="4">
<nz-form-item>
<nz-form-label>登录账户</nz-form-label>
<nz-form-control>
<input nz-input formControlName="loginName" />
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="4">
<nz-form-item>
<nz-form-label>联系方式</nz-form-label>
<nz-form-control>
<input nz-input formControlName="telephone" />
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="4">
<nz-form-item>
<nz-form-label>状态</nz-form-label>
<nz-form-control>
<nz-select formControlName="status" nzAllowClear>
<nz-option nzValue="1" nzLabel="正常"></nz-option>
<nz-option nzValue="2" nzLabel="禁用"></nz-option>
</nz-select>
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="8">
<button nz-button [nzType]="'primary'" (click)="searchFormSubmit()">搜索</button>
<button nz-button (click)="searchFormReset()">重置</button>
<button nz-button [nzType]="'primary'" (click)="showEditAccount(true, null)">创建</button>
</div>
</div>
</form>
<nz-table #basicTable
[nzBordered]="true"
[nzFrontPagination]="false"
[nzShowQuickJumper]="true"
[nzShowTotal]="totalTemplate"
[(nzPageIndex)]="tablePageNum"
(nzPageIndexChange)="queryData()"
[nzTotal]="tableData.total"
[nzData]="tableData.list" >
<thead>
<tr>
<th nzWidth="80px">用户名</th>
<th nzWidth="50px">登录账户</th>
<th nzWidth="80px">联系方式</th>
<th nzWidth="30px">状态</th>
<th nzWidth="50px">创建时间</th>
<th nzWidth="50px">更新时间</th>
<th nzWidth="50px">操作</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of basicTable.data">
<td>{{data.userName}}</td>
<td>{{data.loginName}}</td>
<td>{{data.telephone}}</td>
<td>{{data.status | sysAccountStatus}}</td>
<td>{{data.createTime | date: 'yyyy-MM-dd HH:mm'}}</td>
<td>{{data.updateTime | date: 'yyyy-MM-dd HH:mm'}}</td>
<td>
<a (click)="showEditAccount(false, data)">修改</a>
<nz-divider nzType="vertical"></nz-divider>
<a nz-dropdown [nzDropdownMenu]="menu">
更多操作
<span nz-icon nzType="down"></span>
</a>
<nz-dropdown-menu #menu="nzDropdownMenu">
<ul nz-menu nzSelectable>
<li nz-menu-item *ngIf="data.status == 1"><a (click)="showDisable(data.id)">禁用账户</a></li>
<li nz-menu-item *ngIf="data.status == 2"><a (click)="showRestore(data.id)">恢复账户</a></li>
<li nz-menu-item><a (click)="showResetPwd(data.id)">密码重置</a></li>
<li nz-menu-item nzDanger (click)="showDelData(data.id)">删除</li>
</ul>
</nz-dropdown-menu>
</td>
</tr>
</tbody>
<ng-template #totalTemplate let-total>总计 {{ total }} 条</ng-template>
</nz-table>
<nz-modal [(nzVisible)]="editAccountVisible" nzTitle="{{editAccountTitle}}" [nzFooter]="null" (nzOnCancel)="closeEditAccount()">
<ng-container *nzModalContent>
<form nz-form [formGroup]="editAccountForm" (ngSubmit)="submitEditAccountForm()">
<nz-form-item>
<nz-form-label [nzSm]="6" [nzXs]="24" nzRequired>用户名</nz-form-label>
<nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="用户名填写有误!">
<input nz-input formControlName="userName"/>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSm]="6" [nzXs]="24" nzRequired>登录账户</nz-form-label>
<nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="登录账户填写有误!">
<input nz-input formControlName="loginName"/>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSm]="6" [nzXs]="24">联系方式</nz-form-label>
<nz-form-control [nzSm]="14" [nzXs]="24">
<input nz-input formControlName="telephone"/>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSm]="6" [nzXs]="24" nzRequired>角色权限</nz-form-label>
<nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="角色权限选择有误!">
<nz-select nzShowSearch formControlName="roleId">
<nz-option *ngFor="let item of roleData" nzValue="{{item.id}}" nzLabel="{{item.roleName}}"></nz-option>
</nz-select>
</nz-form-control>
</nz-form-item>
<div nz-flex [nzJustify]="'center'">
<button nz-button nzType="primary" class="submit-btn">保存</button>
</div>
</form>
</ng-container>
</nz-modal>

@ -0,0 +1,15 @@
[nz-form-label] {
overflow: visible;
}
button {
margin-left: 8px;
}
.search-area {
text-align: left;
}
.submit-btn {
width: 150px;
}
.search_form {
margin-bottom: 15px;
}

@ -1,12 +1,318 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import {FormGroup, NonNullableFormBuilder, ReactiveFormsModule, Validators} from "@angular/forms";
import {NzMessageService} from "ng-zorro-antd/message";
import {NzModalComponent, NzModalModule, NzModalService} from "ng-zorro-antd/modal";
import {SysAccountService} from "../../../servies/account/sys-account.service";
import {DatePipe, NgForOf, NgIf} from "@angular/common";
import {NzButtonComponent} from "ng-zorro-antd/button";
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
import {NzDividerComponent} from "ng-zorro-antd/divider";
import {NzFlexDirective} from "ng-zorro-antd/flex";
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
import {NzInputDirective} from "ng-zorro-antd/input";
import {
NzTableCellDirective,
NzTableComponent, NzTableModule,
NzTbodyComponent,
NzTheadComponent,
NzThMeasureDirective, NzTrDirective
} from "ng-zorro-antd/table";
import {NzTreeComponent} from "ng-zorro-antd/tree";
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
import {NzDropDownModule} from "ng-zorro-antd/dropdown";
import {NzIconDirective} from "ng-zorro-antd/icon";
import {SysAccountStatusPipe} from "../../../pipes/account/sys-account-status.pipe";
import {RoleService} from "../../../servies/role/role.service";
@Component({ @Component({
selector: 'app-sys-account', selector: 'app-sys-account',
standalone: true, standalone: true,
imports: [], imports: [
DatePipe,
NgForOf,
NgIf,
NzButtonComponent,
NzColDirective,
NzDividerComponent,
NzFlexDirective,
NzFormControlComponent,
NzFormDirective,
NzFormItemComponent,
NzFormLabelComponent,
NzInputDirective,
NzModalComponent,
NzRowDirective,
NzTableCellDirective,
NzTableComponent,
NzTbodyComponent,
NzThMeasureDirective,
NzTheadComponent,
NzTrDirective,
NzTreeComponent,
ReactiveFormsModule,
NzTableModule,
NzModalModule,
NzSelectComponent,
NzOptionComponent,
NzDropDownModule,
NzIconDirective,
SysAccountStatusPipe,
],
templateUrl: './sys-account.component.html', templateUrl: './sys-account.component.html',
styleUrl: './sys-account.component.less' styleUrl: './sys-account.component.less'
}) })
export class SysAccountComponent { export class SysAccountComponent {
// 表单页数
tablePageNum = 1;
// 表单数据
tableData: any = {
total: 0,
list: [],
};
// 角色数据
roleData: any = [];
// 搜索表单
searchForm: FormGroup;
// 编辑账户弹出框
editAccountVisible = false;
// 编辑账户表单
editAccountForm: FormGroup;
// 编辑账户标题
editAccountTitle = '';
constructor(private fb: NonNullableFormBuilder,
private sysAccountService: SysAccountService,
private roleService: RoleService,
private message: NzMessageService,
private modal: NzModalService) {
// 初始化搜索框
this.searchForm = this.fb.group({
userName: [''],
loginName: [''],
telephone: [''],
status: [''],
});
// 初始化账户表单
this.editAccountForm = this.fb.group({
id: [''],
userName: ['', [Validators.required]],
loginName: ['', [Validators.required]],
telephone: [''],
roleId: ['', [Validators.required]],
});
this.queryAllRole();
this.queryData();
}
/**
*
*/
queryAllRole() {
this.roleService.queryAllRole((data: any) => {
if (data['return_code'] == '000000') {
this.roleData = data['return_data'];
}
});
}
/**
*
*/
queryData() {
this.searchForm.value.pageNum = this.tablePageNum;
this.searchForm.value.pageSize = 10;
this.searchForm.value.time = new Date().getTime();
this.sysAccountService.queryList(this.searchForm.value, (data: any) => {
if (data['return_code'] == '000000') {
this.tableData = data['return_data'];
}
});
}
/**
*
*/
searchFormSubmit(): void {
this.tablePageNum = 1;
this.queryData();
}
/**
*
*/
searchFormReset(): void {
this.searchForm.reset();
}
/**
*
* @param edit true: false
* @param data
*/
showEditAccount(edit: boolean, data: any) {
if (edit) {
this.editAccountTitle = '创建账户';
} else {
this.editAccountTitle = '修改账户';
data['roleId'] = ""+data['roleId']
this.editAccountForm.patchValue(data);
}
this.editAccountVisible = true;
}
/**
*
*/
submitEditAccountForm() {
if (this.editAccountForm.valid) {
this.sysAccountService.editUser(this.editAccountForm.value, (data: any) => {
if (data['return_code'] == '000000') {
// 刷新数据
this.queryData();
this.message.create('success', '操作成功');
// 关闭弹窗
this.closeEditAccount();
} else {
this.message.create('error', data['return_msg']);
}
});
} else {
Object.values(this.editAccountForm.controls).forEach(control => {
if (control.invalid) {
control.markAsDirty();
control.updateValueAndValidity({ onlySelf: true });
}
});
}
}
/**
*
*/
closeEditAccount() {
this.editAccountForm.reset();
this.editAccountVisible = false;
}
/**
*
*/
showRestore(dataId: number) {
this.modal.confirm({
nzTitle: '提示',
nzContent: '确定恢复账户状态?',
nzOnOk: () => this.restore(dataId)
});
}
/**
*
*/
restore(dataId: number) {
const param = {
userId: dataId
}
this.sysAccountService.restore(param, (data: any) => {
if (data['return_code'] == '000000') {
// 刷新数据
this.queryData();
this.message.success("操作成功");
} else {
this.message.create('error', data['return_msg']);
}
});
}
/**
*
*/
showDisable(dataId: number) {
this.modal.confirm({
nzTitle: '提示',
nzContent: '确定禁用账户吗?禁用后无法登录!',
nzOnOk: () => this.disable(dataId)
});
}
/**
*
*/
disable(dataId: number) {
const param = {
userId: dataId
}
this.sysAccountService.disable(param, (data: any) => {
if (data['return_code'] == '000000') {
// 刷新数据
this.queryData();
this.message.success("操作成功");
} else {
this.message.create('error', data['return_msg']);
}
});
}
/**
*
*/
showResetPwd(dataId: number) {
this.modal.confirm({
nzTitle: '提示',
nzContent: '确定重置账户登录密码吗?',
nzOnOk: () => this.resetPwd(dataId)
});
}
/**
*
*/
resetPwd(dataId: number) {
const param = {
userId: dataId
}
this.sysAccountService.resetPwd(param, (data: any) => {
if (data['return_code'] == '000000') {
// 刷新数据
this.queryData();
this.modal.success({
nzTitle: '提示',
nzContent: '密码重置成功,新密码:123456'
});
} else {
this.message.create('error', data['return_msg']);
}
});
}
/**
*
*/
showDelData(dataId: number) {
this.modal.confirm({
nzTitle: '提示',
nzContent: '确定删除该账户数据?',
nzOnOk: () => this.delData(dataId)
});
}
/**
*
*/
delData(dataId: number) {
const param = {
userId: dataId
}
this.sysAccountService.delete(param, (data: any) => {
if (data['return_code'] == '000000') {
// 刷新数据
this.queryData();
this.message.create('success', '操作成功');
} else {
this.message.create('error', data['return_msg']);
}
});
}
} }

@ -1,6 +1,6 @@
<form nz-form [formGroup]="searchForm"> <form nz-form [formGroup]="searchForm">
<div nz-row [nzGutter]="24"> <div nz-row [nzGutter]="24">
<div nz-col [nzSpan]="8"> <div nz-col [nzSpan]="4">
<nz-form-item> <nz-form-item>
<nz-form-label>角色名称</nz-form-label> <nz-form-label>角色名称</nz-form-label>
<nz-form-control> <nz-form-control>
@ -8,13 +8,11 @@
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
</div> </div>
<div nz-col [nzSpan]="8"> <div nz-col [nzSpan]="4">
<div class="search-area"> <button nz-button [nzType]="'primary'" (click)="searchFormSubmit()">搜索</button>
<button nz-button [nzType]="'primary'" (click)="searchFormSubmit()">搜索</button> <button nz-button (click)="searchFormReset()">重置</button>
<button nz-button (click)="searchFormReset()">重置</button> <button nz-button [nzType]="'primary'" (click)="showEditRole(true, null)">创建</button>
<button nz-button [nzType]="'primary'" (click)="showEditRole(true, null)">创建</button> </div>
</div>
</div>
</div> </div>
</form> </form>
@ -32,7 +30,7 @@
<th nzWidth="80px">角色名称</th> <th nzWidth="80px">角色名称</th>
<th nzWidth="100px">角色描述</th> <th nzWidth="100px">角色描述</th>
<th nzWidth="50px">创建时间</th> <th nzWidth="50px">创建时间</th>
<th nzWidth="50px">修改时间</th> <th nzWidth="50px">更新时间</th>
<th nzWidth="50px">操作</th> <th nzWidth="50px">操作</th>
</tr> </tr>
</thead> </thead>

@ -4,9 +4,6 @@
button { button {
margin-left: 8px; margin-left: 8px;
} }
.search-area {
text-align: right;
}
.submit-btn { .submit-btn {
width: 150px; width: 150px;
} }

@ -142,8 +142,8 @@ export class SysRoleComponent {
/** /**
* *
* @param edit * @param edit ture false
* @param data * @param data
*/ */
showEditRole(edit: boolean, data: any) { showEditRole(edit: boolean, data: any) {
if (edit) { if (edit) {
@ -197,7 +197,7 @@ export class SysRoleComponent {
showDelData(dataId: number) { showDelData(dataId: number) {
this.modal.confirm({ this.modal.confirm({
nzTitle: '提示', nzTitle: '提示',
nzContent: '确删除数据?', nzContent: '确删除数据?',
nzOnOk: () => this.delData(dataId) nzOnOk: () => this.delData(dataId)
}); });
} }

@ -0,0 +1,20 @@
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'sysAccountStatus',
standalone: true
})
export class SysAccountStatusPipe implements PipeTransform {
transform(value: number): string {
switch (value) {
case 1:
return '正常';
case 2:
return '禁用';
default:
return '未知';
}
}
}

@ -0,0 +1,104 @@
import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {environment} from "../../../environments/environment";
import {ObjectData} from "../../utils/objectData.service";
@Injectable({
providedIn: 'root'
})
export class SysAccountService {
constructor(private http: HttpClient) { }
/**
*
*
* @param params
* @param callBack
*/
public editUser(params: object, callBack:any) {
this.http.post(environment.baseUrl + 'secUser/editUser', params).subscribe(data => {
callBack(data);
});
}
/**
*
* @param params
* @param callBack
*/
public delete(params: object, callBack:any) {
this.http.post(environment.baseUrl + 'secUser/delete', params).subscribe(data => {
callBack(data);
});
}
/**
*
* @param params
* @param callBack
*/
public restore(params: object, callBack:any) {
this.http.post(environment.baseUrl + 'secUser/restore', params).subscribe(data => {
callBack(data);
});
}
/**
*
* @param params
* @param callBack
*/
public disable(params: object, callBack:any) {
this.http.post(environment.baseUrl + 'secUser/disable', params).subscribe(data => {
callBack(data);
});
}
/**
*
* @param userId
* @param callBack
*/
public resetPwd(param: object, callBack:any) {
this.http.post(environment.baseUrl + 'secUser/resetPwd', param).subscribe(data => {
callBack(data);
});
}
/**
*
* @param userId
* @param callBack
*/
public queryDetail(userId: number, callBack:any) {
this.http.get(environment.baseUrl + 'secUser/queryDetail?userId='+userId).subscribe(data => {
callBack(data);
});
}
/**
*
* @param params
* @param callBack
*/
public queryList(params: object, callBack:any) {
this.http.get(environment.baseUrl + 'secUser/queryList?'+ObjectData.objectByString(params)).subscribe(data => {
callBack(data);
});
}
/**
*
* @param params
* @param callBack
*/
public queryLoginLogList(params: object, callBack:any) {
this.http.get(environment.baseUrl + 'secUser/queryLoginLogList?'+ObjectData.objectByString(params)).subscribe(data => {
callBack(data);
});
}
}

@ -54,4 +54,14 @@ export class RoleService {
}); });
} }
/**
*
* @param callBack
*/
public queryAllRole(callBack:any) {
this.http.get(environment.baseUrl + 'secRole/queryAllRole').subscribe(data => {
callBack(data);
});
}
} }

Loading…
Cancel
Save