提交代码

master
胡锐 7 months ago
parent 4dacc80880
commit 1fc454dae9
  1. 4
      src/app/pages/system/menu/menu.component.html
  2. 109
      src/app/pages/system/menu/menu.component.ts
  3. 26
      src/app/servies/menu/menu.service.ts
  4. 7
      src/app/utils/Interceptor.service.ts

@ -3,6 +3,8 @@
<div nz-col nzSpan="12">
<nz-card nzTitle="系统菜单">
<nz-tree
#nzTreeComponent
*ngIf="menuTree.length > 0"
[nzData]="menuTree"
[nzShowLine]="true"
[nzExpandAll]="true"
@ -31,7 +33,7 @@
<div nz-row [nzGutter]="12">
<div nz-col nzSpan="8"><button nz-button nzType="primary" (click)="openEditMenu(true)">添加</button></div>
<div nz-col nzSpan="8"><button nz-button nzType="primary" (click)="openEditMenu(false)">修改</button></div>
<div nz-col nzSpan="8"><button nz-button nzType="primary" nzDanger>删除</button></div>
<div nz-col nzSpan="8"><button nz-button nzType="primary" (click)="showDelMenu()" nzDanger>删除</button></div>
</div>
</ng-template>
</div>

@ -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']);
}
});
}
}

@ -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);
});
}

@ -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({

Loading…
Cancel
Save