This commit is contained in:
Taric Xin
2021-12-29 19:46:29 +08:00
parent f6f17a410d
commit a99a15e570
20 changed files with 425 additions and 131 deletions

View File

@ -0,0 +1,120 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { Menu } from '@delon/theme';
import { NzModalService } from 'ng-zorro-antd/modal';
import { MenuManagerService } from './../../services/menu-manager.service';
@Component({
selector: 'app-menu-manager-components-index',
templateUrl: './index.component.html',
styleUrls: ['./index.component.less'],
})
export class MenuManagerComponentsIndexComponent implements OnInit {
selectedPlatform!: { name: string; appId: string; enName: string };
menus: Array<any> = [];
platforms: Array<any> = [];
currentSelectedNode: any;
transferData!: string;
dropType = {
dropPrev: true,
dropNext: true,
dropInner: true,
};
constructor(public service: MenuManagerService, private modal: NzModalService) { }
ngOnInit(): void {
this.initData();
}
initData(): void {
this.platforms = [
{ name: '运维平台', appId: 'D40B4EFC33FC4803864934872A11B0CE', enName: 'scm-soc-ui' },
{ name: '运营后台', appId: '2537B72DDA534361AE4931903F0BFEB3', enName: 'scm-ows-ui' },
{ name: '供应商平台', appId: '0CEE254099064665872B777CF9FCBB6B', enName: 'scm-cvc-ui' },
// { name: '代理商平台', appId: '737BB699C8894B2D81F21FC667A21169', enName: 'scm-cac-ui' },
// { name: '分销商平台', appId: '0D00C7CC306A4CACA5AF95BBD1251980', enName: 'scm-cdc-ui' },
// { name: '开放平台', appId: '7B216DD933CB4922BD9094ED8F96B0B4', enName: 'scm-opc-ui' },
];
}
platformChange(e: { name: string; appId: string }) {
if (e) {
this.loadMenus(e.appId);
} else {
this.menus = [];
this.currentSelectedNode = null;
}
}
loadMenus(appId: string) {
this.service.request(this.service.$api_get_all, { appId }, 'POST', true, 'FORM').subscribe((res) => {
this.menus = res;
});
}
editValueChange(event: any) {
console.log('editChanged', event);
}
menuImport() {
if (!this.selectedPlatform) {
return;
}
this.service.http.request('GET', `assets/tmp/_mock/platform/${this.selectedPlatform.enName}.json`).subscribe((res: any) => {
// console.log(res);
this.addMenu(res.menu);
});
}
addMenu(menus: Array<Menu>, parentId: string = '') {
menus.forEach((r) => {
if (parentId !== '') {
r.parentId = parentId;
}
this.service.request(this.service.$api_get_one, { appId: this.selectedPlatform.appId, i18n: r.i18n }).subscribe((res) => {
// 如果res.data存在则更新菜单
if (res.data) {
r.id = res.data.id;
}
this.service
.addOne({ appId: this.selectedPlatform.appId, ...r, isLeaf: !(r.children && r.children.length > 0) })
.subscribe((result) => {
if (result) {
if (r.children && r.children.length > 0) {
this.addMenu(r.children, result.id);
}
}
});
});
});
this.loadMenus(this.selectedPlatform.appId);
}
addMenuRecursion() {
}
delMenu(appId: string, menus: Array<Menu>) {
if (!menus || menus.length === 0) {
return;
}
let notice = `确认删除菜单[${menus[0].text}]?`;
if (menus.length > 1) {
notice = `确认删除勾选的${menus.length}行菜单记录?`;
}
const ids = menus.map((r) => r.id);
this.modal.confirm({
nzTitle: '<i>删除确认</i>',
nzContent: `<b>${notice}</b><br>是否删除?`,
nzOnOk: () =>
this.service.delMany(ids).subscribe((res) => {
if (res === true) {
this.service.msgSrv.success('删除成功!');
}
}),
});
}
}