This commit is contained in:
Taric Xin
2022-01-20 13:51:18 +08:00
parent ec285a095b
commit a76a9f0718
6 changed files with 172 additions and 123 deletions

View File

@ -3,6 +3,7 @@ import { STComponent, STColumn, STRequestOptions, STChange } from '@delon/abc/st
import { SFComponent, SFSchema } from '@delon/form';
import { Menu } from '@delon/theme';
import { EAEnvironmentService } from '@shared';
import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzModalService } from 'ng-zorro-antd/modal';
import { SettingRoleEditComponent } from 'src/app/routes/sys-setting/components/role-management/edit/edit.component';
import { MenuManagerService } from './../../services/menu-manager.service';
@ -39,32 +40,10 @@ export class MenuManagerComponentsIndexComponent implements OnInit {
}
};
columns: STColumn[] = [
{ title: '角色名称', index: 'roleName' },
{ title: '角色描述', index: 'roleDescription' },
{ title: '创建人手机号', index: 'telephone' },
{
title: '创建时间',
index: 'createTime',
className: 'text-left',
type: 'date'
},
{
title: '操作',
buttons: [
{
text: '编辑',
click: item => this.roleAction(item)
},
{
text: '删除',
click: item => this.deleteAction(item)
}
]
}
];
selectedRows: any[] = [];
mapOfExpandedData: { [key: string]: any[] } = {};
listOfMapData: any[] = [];
constructor(private envSrv: EAEnvironmentService, public service: MenuManagerService, private modal: NzModalService) {
this.initData();
}
@ -77,6 +56,19 @@ export class MenuManagerComponentsIndexComponent implements OnInit {
{ name: '运营后台', appId: this.envSrv.env.appId, enName: 'tms-obc-web' }
];
this.selectedPlatform = this.platforms[0];
this.loadMemu(this.selectedPlatform.appId);
}
loadMemu(appId: string) {
this.service.request(this.service.$api_get_all, { appId }, 'POST', false).subscribe(res => {
if (res) {
this.listOfMapData = res;
this.listOfMapData.forEach(item => {
this.mapOfExpandedData[item.key] = this.convertTreeToList(item);
});
console.log(this.listOfMapData, this.mapOfExpandedData);
}
});
}
platformChange(e: { name: string; appId: string }) {
@ -167,24 +159,11 @@ export class MenuManagerComponentsIndexComponent implements OnInit {
this.service.request(this.service.$api_del_many, ids).subscribe(res => {});
}
beforeReq = (requestOptions: STRequestOptions) => {
if (this.sf) {
Object.assign(requestOptions.body, { ...this.sf.value });
}
Object.assign(requestOptions.body, { appId: this.selectedPlatform.appId });
return requestOptions;
};
stChange(e: STChange): void {
switch (e.type) {
case 'sort':
this.selectedRows = e.checkbox!;
break;
}
changeMemu(key: number) {
this.selectedPlatform = this.platforms[key];
this.loadMemu(this.selectedPlatform.appId);
}
changeMemu(key: string) {}
roleAction(item?: any) {
const modal = this.modal.create({
nzContent: SettingRoleEditComponent,
@ -219,4 +198,64 @@ export class MenuManagerComponentsIndexComponent implements OnInit {
resetSF() {
this.sf.reset();
}
collapse(array: TreeNodeInterface[], data: TreeNodeInterface, $event: boolean): void {
if (!$event) {
if (data.children) {
data.children.forEach(d => {
const target = array.find(a => a.key === d.key)!;
target.expand = false;
this.collapse(array, target, false);
});
} else {
return;
}
}
}
convertTreeToList(root: TreeNodeInterface): TreeNodeInterface[] {
const stack: TreeNodeInterface[] = [];
const array: TreeNodeInterface[] = [];
const hashMap = {};
stack.push({ ...root, level: 0, expand: true });
while (stack.length !== 0) {
const node = stack.pop()!;
this.visitNode(node, hashMap, array);
if (node.children) {
for (let i = node.children.length - 1; i >= 0; i--) {
stack.push({ ...node.children[i], level: node.level! + 1, expand: false, parent: node, iconType: this.formatIcon(node.children[i].icon) });
}
}
}
return array;
}
visitNode(node: TreeNodeInterface, hashMap: { [key: string]: boolean }, array: TreeNodeInterface[]): void {
if (!hashMap[node.key]) {
hashMap[node.key] = true;
array.push(node);
}
}
private formatIcon(icon: any) {
let value = icon;
// compatible `anticon anticon-user`
if (~icon.indexOf(`anticon-`)) {
value = value.split('-').slice(1).join('-');
}
return value;
}
}
export interface TreeNodeInterface {
key: string;
name: string;
age?: number;
level?: number;
expand?: boolean;
address?: string;
children?: TreeNodeInterface[];
parent?: TreeNodeInterface;
[key: string]: any;
}