|
|
@ -1,4 +1,4 @@ |
|
|
|
import { Component } from '@angular/core'; |
|
|
|
import {Component, ViewChild} from '@angular/core'; |
|
|
|
import {NzTableComponent, NzTbodyComponent, NzTheadComponent, NzThMeasureDirective} from "ng-zorro-antd/table"; |
|
|
|
import {NzTableComponent, NzTbodyComponent, NzTheadComponent, NzThMeasureDirective} from "ng-zorro-antd/table"; |
|
|
|
import {NzDividerComponent} from "ng-zorro-antd/divider"; |
|
|
|
import {NzDividerComponent} from "ng-zorro-antd/divider"; |
|
|
|
import {NzFormDirective, NzFormModule} from "ng-zorro-antd/form"; |
|
|
|
import {NzFormDirective, NzFormModule} from "ng-zorro-antd/form"; |
|
|
@ -6,16 +6,21 @@ import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid"; |
|
|
|
import { |
|
|
|
import { |
|
|
|
FormGroup, |
|
|
|
FormGroup, |
|
|
|
NonNullableFormBuilder, |
|
|
|
NonNullableFormBuilder, |
|
|
|
ReactiveFormsModule, |
|
|
|
ReactiveFormsModule, Validators, |
|
|
|
} from "@angular/forms"; |
|
|
|
} from "@angular/forms"; |
|
|
|
import {NzButtonComponent} from "ng-zorro-antd/button"; |
|
|
|
import {NzButtonComponent} from "ng-zorro-antd/button"; |
|
|
|
import {NzIconDirective} from "ng-zorro-antd/icon"; |
|
|
|
import {NzIconDirective} from "ng-zorro-antd/icon"; |
|
|
|
import {NzInputDirective} from "ng-zorro-antd/input"; |
|
|
|
import {NzInputDirective} from "ng-zorro-antd/input"; |
|
|
|
import {NzFlexDirective} from "ng-zorro-antd/flex"; |
|
|
|
import {NzFlexDirective} from "ng-zorro-antd/flex"; |
|
|
|
import {DatePipe, NgForOf} from "@angular/common"; |
|
|
|
import {DatePipe, NgForOf, NgIf} from "@angular/common"; |
|
|
|
import {RoleService} from "../../../servies/role/role.service"; |
|
|
|
import {RoleService} from "../../../servies/role/role.service"; |
|
|
|
import {NzModalService} from "ng-zorro-antd/modal"; |
|
|
|
import {NzModalComponent, NzModalModule, NzModalService} from "ng-zorro-antd/modal"; |
|
|
|
import {NzMessageService} from "ng-zorro-antd/message"; |
|
|
|
import {NzMessageService} from "ng-zorro-antd/message"; |
|
|
|
|
|
|
|
import {NzInputNumberComponent} from "ng-zorro-antd/input-number"; |
|
|
|
|
|
|
|
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select"; |
|
|
|
|
|
|
|
import {DATA} from "../../../data/login/localStorage.namespace"; |
|
|
|
|
|
|
|
import {MenuService} from "../../../servies/menu/menu.service"; |
|
|
|
|
|
|
|
import {NzFormatEmitEvent, NzTreeComponent, NzTreeNodeOptions} from "ng-zorro-antd/tree"; |
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
@Component({ |
|
|
|
selector: 'app-sys-role', |
|
|
|
selector: 'app-sys-role', |
|
|
@ -37,42 +42,79 @@ import {NzMessageService} from "ng-zorro-antd/message"; |
|
|
|
NgForOf, |
|
|
|
NgForOf, |
|
|
|
DatePipe, |
|
|
|
DatePipe, |
|
|
|
NzThMeasureDirective, |
|
|
|
NzThMeasureDirective, |
|
|
|
|
|
|
|
NzInputNumberComponent, |
|
|
|
|
|
|
|
NzModalComponent, |
|
|
|
|
|
|
|
NzOptionComponent, |
|
|
|
|
|
|
|
NzSelectComponent, |
|
|
|
|
|
|
|
NzModalModule, |
|
|
|
|
|
|
|
NgIf, |
|
|
|
|
|
|
|
NzTreeComponent, |
|
|
|
], |
|
|
|
], |
|
|
|
templateUrl: './sys-role.component.html', |
|
|
|
templateUrl: './sys-role.component.html', |
|
|
|
styleUrl: './sys-role.component.less' |
|
|
|
styleUrl: './sys-role.component.less' |
|
|
|
}) |
|
|
|
}) |
|
|
|
export class SysRoleComponent { |
|
|
|
export class SysRoleComponent { |
|
|
|
|
|
|
|
// 表单页数
|
|
|
|
|
|
|
|
tablePageNum = 1; |
|
|
|
// 表单数据
|
|
|
|
// 表单数据
|
|
|
|
tableData: any = { |
|
|
|
tableData: any = { |
|
|
|
total: 0, |
|
|
|
total: 0, |
|
|
|
list: [], |
|
|
|
list: [], |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
// 搜索表单
|
|
|
|
searchForm: FormGroup; |
|
|
|
searchForm: FormGroup; |
|
|
|
|
|
|
|
// 编辑角色弹出框
|
|
|
|
|
|
|
|
editRoleVisible = false; |
|
|
|
|
|
|
|
// 编辑角色表单
|
|
|
|
|
|
|
|
editRoleForm: FormGroup; |
|
|
|
|
|
|
|
// 编辑角色标题
|
|
|
|
|
|
|
|
editRoleTitle = ''; |
|
|
|
|
|
|
|
// 分配角色菜单弹出框
|
|
|
|
|
|
|
|
assignRoleMenuVisible = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 当前需要分配权限角色
|
|
|
|
|
|
|
|
currentAssignRoleId: any = null; |
|
|
|
|
|
|
|
// 菜单树
|
|
|
|
|
|
|
|
menuTree: any = []; |
|
|
|
|
|
|
|
// 菜单已勾选数据
|
|
|
|
|
|
|
|
menuTreeCheckedKeys: any = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent; |
|
|
|
|
|
|
|
|
|
|
|
constructor(private fb: NonNullableFormBuilder, |
|
|
|
constructor(private fb: NonNullableFormBuilder, |
|
|
|
private roleService: RoleService, |
|
|
|
private roleService: RoleService, |
|
|
|
private message: NzMessageService) { |
|
|
|
private menuService: MenuService, |
|
|
|
|
|
|
|
private message: NzMessageService, |
|
|
|
|
|
|
|
private modal: NzModalService) { |
|
|
|
// 初始化搜索框
|
|
|
|
// 初始化搜索框
|
|
|
|
this.searchForm = this.fb.group({ |
|
|
|
this.searchForm = this.fb.group({ |
|
|
|
roleName: [''], |
|
|
|
roleName: [''], |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.queryData(1); |
|
|
|
// 初始化表单
|
|
|
|
|
|
|
|
this.editRoleForm = this.fb.group({ |
|
|
|
|
|
|
|
id: [''], |
|
|
|
|
|
|
|
roleName: ['', [Validators.required]], |
|
|
|
|
|
|
|
roleDesc: [''], |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.menuService.queryMenuTree((data: any) => { |
|
|
|
|
|
|
|
this.menuTree = data['return_data']; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.queryData(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取数据 |
|
|
|
* 获取数据 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
queryData(pageNum: number) { |
|
|
|
queryData() { |
|
|
|
this.searchForm.value.pageNum = pageNum; |
|
|
|
this.searchForm.value.pageNum = this.tablePageNum; |
|
|
|
this.searchForm.value.pageSize = 10; |
|
|
|
this.searchForm.value.pageSize = 10; |
|
|
|
|
|
|
|
this.searchForm.value.time = new Date().getTime(); |
|
|
|
this.roleService.queryList(this.searchForm.value, (data: any) => { |
|
|
|
this.roleService.queryList(this.searchForm.value, (data: any) => { |
|
|
|
console.log(data); |
|
|
|
|
|
|
|
this.tableData = data['return_data']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (data['return_code'] == '000000') { |
|
|
|
if (data['return_code'] == '000000') { |
|
|
|
|
|
|
|
this.tableData = data['return_data']; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -81,7 +123,7 @@ export class SysRoleComponent { |
|
|
|
* 搜索表单提交 |
|
|
|
* 搜索表单提交 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
searchFormSubmit(): void { |
|
|
|
searchFormSubmit(): void { |
|
|
|
this.queryData(1); |
|
|
|
this.queryData(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -91,4 +133,151 @@ export class SysRoleComponent { |
|
|
|
this.searchForm.reset(); |
|
|
|
this.searchForm.reset(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 打开编辑角色模态框 |
|
|
|
|
|
|
|
* @param edit |
|
|
|
|
|
|
|
* @param data |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
showEditRole(edit: boolean, data: any) { |
|
|
|
|
|
|
|
if (edit) { |
|
|
|
|
|
|
|
this.editRoleTitle = '创建角色'; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.editRoleTitle = '修改角色'; |
|
|
|
|
|
|
|
this.editRoleForm.patchValue(data); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.editRoleVisible = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 打开编辑角色模态框 |
|
|
|
|
|
|
|
* @param edit |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
submitEditRoleForm() { |
|
|
|
|
|
|
|
if (this.editRoleForm.valid) { |
|
|
|
|
|
|
|
this.roleService.editRole(this.editRoleForm.value, (data: any) => { |
|
|
|
|
|
|
|
if (data['return_code'] == '000000') { |
|
|
|
|
|
|
|
// 刷新数据
|
|
|
|
|
|
|
|
this.queryData(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.message.create('success', '操作成功'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 关闭弹窗
|
|
|
|
|
|
|
|
this.closeEditRole(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Object.values(this.editRoleForm.controls).forEach(control => { |
|
|
|
|
|
|
|
if (control.invalid) { |
|
|
|
|
|
|
|
control.markAsDirty(); |
|
|
|
|
|
|
|
control.updateValueAndValidity({ onlySelf: true }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 关闭编辑角色模态框 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
closeEditRole() { |
|
|
|
|
|
|
|
this.editRoleVisible = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 展示删除数据 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
showDelData(dataId: number) { |
|
|
|
|
|
|
|
this.modal.confirm({ |
|
|
|
|
|
|
|
nzTitle: '提示', |
|
|
|
|
|
|
|
nzContent: '确实删除数据?', |
|
|
|
|
|
|
|
nzOnOk: () => this.delData(dataId) |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 删除数据 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
delData(dataId: number) { |
|
|
|
|
|
|
|
const param = { |
|
|
|
|
|
|
|
id: dataId |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.roleService.delRole(param, (data: any) => { |
|
|
|
|
|
|
|
if (data['return_code'] == '000000') { |
|
|
|
|
|
|
|
// 刷新数据
|
|
|
|
|
|
|
|
this.queryData(); |
|
|
|
|
|
|
|
this.message.create('success', '操作成功'); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 打开分配角色菜单模态框 |
|
|
|
|
|
|
|
* @param roleId |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
showAssignRoleMenu(roleId: number) { |
|
|
|
|
|
|
|
this.currentAssignRoleId = roleId; |
|
|
|
|
|
|
|
this.menuService.queryRoleMenuArray(roleId, (data: any) => { |
|
|
|
|
|
|
|
this.menuTreeCheckedKeys = data['return_data']; |
|
|
|
|
|
|
|
console.log(this.menuTreeCheckedKeys); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.assignRoleMenuVisible = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 菜单递归 |
|
|
|
|
|
|
|
* @param data |
|
|
|
|
|
|
|
* @param merIds |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
recursionData(data: any, merIds: any): any { |
|
|
|
|
|
|
|
for (let node of data.children) { |
|
|
|
|
|
|
|
merIds.push(node.key) |
|
|
|
|
|
|
|
if (node.children != null) { |
|
|
|
|
|
|
|
this.recursionData(node,merIds); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 提交分配角色菜单权限 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
submitAssignRoleMenu() { |
|
|
|
|
|
|
|
let menuIds: any = []; |
|
|
|
|
|
|
|
// 已勾选的菜单
|
|
|
|
|
|
|
|
const checkedNodeList = this.nzTreeComponent.getCheckedNodeList(); |
|
|
|
|
|
|
|
for (let node of checkedNodeList) { |
|
|
|
|
|
|
|
menuIds.push(node.origin.key); |
|
|
|
|
|
|
|
if (node.origin.children != null) { |
|
|
|
|
|
|
|
menuIds.concat(this.recursionData(node.origin, menuIds)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 半选状态的菜单
|
|
|
|
|
|
|
|
const halfCheckedNodeList = this.nzTreeComponent.getHalfCheckedNodeList(); |
|
|
|
|
|
|
|
for (let node of halfCheckedNodeList) { |
|
|
|
|
|
|
|
menuIds.push(node.key); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const param= { |
|
|
|
|
|
|
|
roleId: this.currentAssignRoleId, |
|
|
|
|
|
|
|
menuIds: menuIds |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
this.menuService.assignMenu(param, (data: any) => { |
|
|
|
|
|
|
|
if (data['return_code'] == '000000') { |
|
|
|
|
|
|
|
this.message.create('success', '操作成功'); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 关闭分配角色菜单模态框 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
closeAssignRoleMenu() { |
|
|
|
|
|
|
|
this.menuTreeCheckedKeys = []; |
|
|
|
|
|
|
|
this.assignRoleMenuVisible = false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|