From 1fc454dae9b761791c9bd46c979dc1433b820479 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Wed, 17 Apr 2024 18:07:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/pages/system/menu/menu.component.html | 4 +- src/app/pages/system/menu/menu.component.ts | 109 ++++++++---------- src/app/servies/menu/menu.service.ts | 26 ++++- src/app/utils/Interceptor.service.ts | 7 +- 4 files changed, 79 insertions(+), 67 deletions(-) diff --git a/src/app/pages/system/menu/menu.component.html b/src/app/pages/system/menu/menu.component.html index 1f569db..918b2a0 100644 --- a/src/app/pages/system/menu/menu.component.html +++ b/src/app/pages/system/menu/menu.component.html @@ -3,6 +3,8 @@
-
+
diff --git a/src/app/pages/system/menu/menu.component.ts b/src/app/pages/system/menu/menu.component.ts index f152c55..43c1566 100644 --- a/src/app/pages/system/menu/menu.component.ts +++ b/src/app/pages/system/menu/menu.component.ts @@ -1,4 +1,4 @@ -import { Component } from '@angular/core'; +import {Component, ViewChild} from '@angular/core'; import {NzTreeComponent} from "ng-zorro-antd/tree"; import {NgForOf, NgIf} from "@angular/common"; import {NzIconDirective} from "ng-zorro-antd/icon"; @@ -15,15 +15,15 @@ import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid"; import {NzButtonComponent} from "ng-zorro-antd/button"; import {NzDescriptionsComponent, NzDescriptionsItemComponent} from "ng-zorro-antd/descriptions"; import {MenuTypePipe} from "../../../pipes/menu/menu-type.pipe"; -import {NzFormDirective, NzFormLabelComponent} from "ng-zorro-antd/form"; +import {NzFormDirective, NzFormLabelComponent, NzFormModule} from "ng-zorro-antd/form"; import {FormGroup, NonNullableFormBuilder, ReactiveFormsModule, Validators} from "@angular/forms"; -import { NzFormModule } from 'ng-zorro-antd/form'; import {NzInputDirective, NzInputGroupComponent} from "ng-zorro-antd/input"; -import { NzModalModule } from 'ng-zorro-antd/modal'; +import {NzModalModule, NzModalService} from 'ng-zorro-antd/modal'; import {NzFlexDirective} from "ng-zorro-antd/flex"; import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select"; import {NzInputNumberComponent} from "ng-zorro-antd/input-number"; import {NzMessageService} from "ng-zorro-antd/message"; +import {NzTreeNode} from "ng-zorro-antd/core/tree/nz-tree-base-node"; @Component({ selector: 'app-menu', @@ -61,7 +61,6 @@ import {NzMessageService} from "ng-zorro-antd/message"; styleUrl: './menu.component.less' }) export class MenuComponent { - // 菜单数据 menuData: any = []; // 菜单树形数据 @@ -74,11 +73,12 @@ export class MenuComponent { editMenuForm: FormGroup; // 编辑菜单标题 editMenuTitle = ''; + @ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent; constructor(private menuService: MenuService, private fb: NonNullableFormBuilder, + private modal: NzModalService, private message: NzMessageService) { - this.queryMenuData(); - this.queryMenuTree2(); + this.queryMenuTree(); this.editMenuForm = this.fb.group({ id: [], @@ -92,36 +92,22 @@ export class MenuComponent { }); } - queryMenuTree2() { - this.menuService.queryRoleMenuTree2('', (data: any) => { + /** + * 获取菜单树 + */ + queryMenuTree() { + this.menuService.queryRoleMenuTreeCustomized('', (data: any) => { this.menuTree = data['return_data']; + this.queryMenuData(); }); } /** - * 查询菜单数据 + * 查询菜单原始数据 */ queryMenuData() { this.menuService.queryMenuList((data: any) => { this.menuData = data['return_data']; - // 获取菜单树形结构 - // this.queryMenuTree(); - }); - } - - /** - * 查询菜单树形结构数据 - */ - queryMenuTree() { - this.menuService.queryRoleMenuTree('', (data: any) => { - const menuList = data['return_data']; - for (const parent of menuList) { - this.menuTree.push({ - key: parent['id'], - title: parent['menuName'], - children: this.recursionChildMenu(this.menuData, parent['id']), - }); - } }); } @@ -142,36 +128,6 @@ export class MenuComponent { } } - /** - * 递归获取子菜单 - * @param dataSource 菜单数据 - * @param parentMenuId 父级菜单id - */ - public recursionChildMenu(dataSource: [], parentMenuId: number) { - let dataTree: any = []; - let collect: any = []; - // 筛选子菜单 - collect = dataSource.filter((o: any) => o.menuPSid == parentMenuId); - - for (const data of collect) { - const childMenuData = this.recursionChildMenu(dataSource, data['id']); - if (childMenuData.length > 0) { - dataTree.push({ - key: data['id'], - title: data['menuName'], - children: childMenuData, - }); - } else { - dataTree.push({ - key: data['id'], - title: data['menuName'], - isLeaf: true - }); - } - } - return dataTree; - } - /** * 编辑菜单 * @param edit 编辑状态 true:增加 false:修改 @@ -209,14 +165,13 @@ export class MenuComponent { */ submitEditMenuForm() { if (this.editMenuForm.valid) { - console.log('submit', this.editMenuForm.value); this.menuService.editMenu(this.editMenuForm.value, (data: any) => { if (data['return_code'] == '000000') { - console.log("获取数据", data); // 刷新数据 - this.queryMenuTree2(); + this.queryMenuTree(); this.message.create('success', '操作成功'); + // 关闭弹窗 this.closeEditMenu(); } else { @@ -239,4 +194,36 @@ export class MenuComponent { closeEditMenu() { this.editMenuVisible = false; } + + /** + * 删除菜单 + */ + showDelMenu() { + this.modal.confirm({ + nzTitle: '提示', + nzContent: '确实删除数据?', + nzOnOk: () => this.delMenu() + }); + } + + /** + * 删除菜单 + */ + delMenu() { + const param = { + menuId: this.menuDetail.id + } + this.menuService.delMenu(param, (data: any) => { + if (data['return_code'] == '000000') { + // 刷新数据 + const s = this.nzTreeComponent.getTreeNodeByKey(""+this.menuDetail.menuPSid) + + + this.message.create('success', '操作成功'); + } else { + this.message.create('error', data['return_msg']); + } + }); + } + } diff --git a/src/app/servies/menu/menu.service.ts b/src/app/servies/menu/menu.service.ts index 5b39c68..cd51ceb 100644 --- a/src/app/servies/menu/menu.service.ts +++ b/src/app/servies/menu/menu.service.ts @@ -22,6 +22,17 @@ export class MenuService { }); } + /** + * 删除菜单 + * @param params + * @param callBack + */ + public delMenu(params: object, callBack:any) { + this.http.post(environment.baseUrl + 'secMenu/delMenu', params).subscribe(data => { + callBack(data); + }); + } + /** * 查询菜单 * @param roleId @@ -33,6 +44,17 @@ export class MenuService { }); } + /** + * 查询菜单详情 + * @param menuId + * @param callBack + */ + public queryMenuDetail(menuId: number, callBack:any) { + this.http.get(environment.baseUrl + 'secMenu/queryDetail?menuId=' + menuId).subscribe(data => { + callBack(data); + }); + } + /** * 查询菜单树 * @param roleId @@ -53,12 +75,12 @@ export class MenuService { * @param roleId * @param callBack */ - public queryRoleMenuTree2(roleId: string, callBack:any) { + public queryRoleMenuTreeCustomized(roleId: string, callBack:any) { let paramStr = ''; if (roleId != null && roleId != '') { paramStr = '?roleId=' + roleId; } - this.http.get(environment.baseUrl + 'secMenu/queryRoleMenuTree2'+paramStr).subscribe(data => { + this.http.post(environment.baseUrl + 'secMenu/queryRoleMenuTreeCustomized'+paramStr, null).subscribe(data => { callBack(data); }); } diff --git a/src/app/utils/Interceptor.service.ts b/src/app/utils/Interceptor.service.ts index 4e8c52a..cb664a6 100644 --- a/src/app/utils/Interceptor.service.ts +++ b/src/app/utils/Interceptor.service.ts @@ -22,9 +22,10 @@ export class InterceptorService implements HttpInterceptor { let modifiedHeaders: HttpHeaders; const token = this.storage.get(USER_TOKEN); if (token != null) { - modifiedHeaders = req.headers.set('Authorization', token); - modifiedHeaders = req.headers.set( 'Cache-Control', 'no-cache',) - modifiedHeaders = req.headers.set( 'Pragma', 'no-cache',) + modifiedHeaders = + req.headers.append('Cache-Control', 'no-cache') + .append('Pragma', 'no-cache') + .append('Authorization', token); } secureReq = req.clone({