This commit is contained in:
Taric Xin
2021-12-30 15:36:16 +08:00
parent 838bf749d4
commit 315a684dad
7 changed files with 820 additions and 168 deletions

View File

@ -1,12 +1,13 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { Menu } from '@delon/theme';
import { EAEnvironmentService } from '@shared';
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'],
styleUrls: ['./index.component.less']
})
export class MenuManagerComponentsIndexComponent implements OnInit {
selectedPlatform!: { name: string; appId: string; enName: string };
@ -17,9 +18,9 @@ export class MenuManagerComponentsIndexComponent implements OnInit {
dropType = {
dropPrev: true,
dropNext: true,
dropInner: true,
dropInner: true
};
constructor(public service: MenuManagerService, private modal: NzModalService) { }
constructor(private envSrv: EAEnvironmentService, public service: MenuManagerService, private modal: NzModalService) {}
ngOnInit(): void {
this.initData();
@ -27,13 +28,10 @@ export class MenuManagerComponentsIndexComponent implements OnInit {
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' },
{ name: '货主PC', appId: 'A48F72F0A304427F921794BAD86B3522', enName: 'tms-smc-web' },
{ name: '运营后台', appId: this.envSrv.env.appId, enName: 'tms-obc-web' }
];
this.selectedPlatform = this.platforms[0];
}
platformChange(e: { name: string; appId: string }) {
@ -46,41 +44,40 @@ export class MenuManagerComponentsIndexComponent implements OnInit {
}
loadMenus(appId: string) {
this.service.request(this.service.$api_get_all, { appId }, 'POST', true, 'FORM').subscribe((res) => {
this.service.request(this.service.$api_get_all, { appId }, 'POST', true, 'FORM').subscribe(res => {
console.log(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.service.http.request('GET', `assets/mocks/platform/${this.selectedPlatform.enName}.json`).subscribe((res: any) => {
this.addMenu(res.menu);
});
}
addMenu(menus: Array<Menu>, parentId: string = '') {
menus.forEach((r) => {
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) => {
this.service.request(this.service.$api_get_one, { appId: this.selectedPlatform.appId }, 'POST', false).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) => {
.subscribe(result => {
if (result) {
if (r.children && r.children.length > 0) {
this.addMenu(r.children, result.id);
@ -90,12 +87,10 @@ export class MenuManagerComponentsIndexComponent implements OnInit {
});
});
this.loadMenus(this.selectedPlatform.appId);
// this.loadMenus(this.selectedPlatform.appId);
}
addMenuRecursion() {
}
addMenuRecursion() {}
delMenu(appId: string, menus: Array<Menu>) {
if (!menus || menus.length === 0) {
@ -105,16 +100,16 @@ export class MenuManagerComponentsIndexComponent implements OnInit {
if (menus.length > 1) {
notice = `确认删除勾选的${menus.length}行菜单记录?`;
}
const ids = menus.map((r) => r.id);
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) => {
this.service.delMany(ids).subscribe(res => {
if (res === true) {
this.service.msgSrv.success('删除成功!');
}
}),
})
});
}
}