提交代码

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"> <div nz-col nzSpan="12">
<nz-card nzTitle="系统菜单"> <nz-card nzTitle="系统菜单">
<nz-tree <nz-tree
#nzTreeComponent
*ngIf="menuTree.length > 0"
[nzData]="menuTree" [nzData]="menuTree"
[nzShowLine]="true" [nzShowLine]="true"
[nzExpandAll]="true" [nzExpandAll]="true"
@ -31,7 +33,7 @@
<div nz-row [nzGutter]="12"> <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(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" (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> </div>
</ng-template> </ng-template>
</div> </div>

@ -1,4 +1,4 @@
import { Component } from '@angular/core'; import {Component, ViewChild} from '@angular/core';
import {NzTreeComponent} from "ng-zorro-antd/tree"; import {NzTreeComponent} from "ng-zorro-antd/tree";
import {NgForOf, NgIf} from "@angular/common"; import {NgForOf, NgIf} from "@angular/common";
import {NzIconDirective} from "ng-zorro-antd/icon"; 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 {NzButtonComponent} from "ng-zorro-antd/button";
import {NzDescriptionsComponent, NzDescriptionsItemComponent} from "ng-zorro-antd/descriptions"; import {NzDescriptionsComponent, NzDescriptionsItemComponent} from "ng-zorro-antd/descriptions";
import {MenuTypePipe} from "../../../pipes/menu/menu-type.pipe"; 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 {FormGroup, NonNullableFormBuilder, ReactiveFormsModule, Validators} from "@angular/forms";
import { NzFormModule } from 'ng-zorro-antd/form';
import {NzInputDirective, NzInputGroupComponent} from "ng-zorro-antd/input"; 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 {NzFlexDirective} from "ng-zorro-antd/flex";
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select"; import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
import {NzInputNumberComponent} from "ng-zorro-antd/input-number"; import {NzInputNumberComponent} from "ng-zorro-antd/input-number";
import {NzMessageService} from "ng-zorro-antd/message"; import {NzMessageService} from "ng-zorro-antd/message";
import {NzTreeNode} from "ng-zorro-antd/core/tree/nz-tree-base-node";
@Component({ @Component({
selector: 'app-menu', selector: 'app-menu',
@ -61,7 +61,6 @@ import {NzMessageService} from "ng-zorro-antd/message";
styleUrl: './menu.component.less' styleUrl: './menu.component.less'
}) })
export class MenuComponent { export class MenuComponent {
// 菜单数据 // 菜单数据
menuData: any = []; menuData: any = [];
// 菜单树形数据 // 菜单树形数据
@ -74,11 +73,12 @@ export class MenuComponent {
editMenuForm: FormGroup; editMenuForm: FormGroup;
// 编辑菜单标题 // 编辑菜单标题
editMenuTitle = ''; editMenuTitle = '';
@ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent;
constructor(private menuService: MenuService, constructor(private menuService: MenuService,
private fb: NonNullableFormBuilder, private fb: NonNullableFormBuilder,
private modal: NzModalService,
private message: NzMessageService) { private message: NzMessageService) {
this.queryMenuData(); this.queryMenuTree();
this.queryMenuTree2();
this.editMenuForm = this.fb.group({ this.editMenuForm = this.fb.group({
id: [], 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.menuTree = data['return_data'];
this.queryMenuData();
}); });
} }
/** /**
* *
*/ */
queryMenuData() { queryMenuData() {
this.menuService.queryMenuList((data: any) => { this.menuService.queryMenuList((data: any) => {
this.menuData = data['return_data']; 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 * @param edit true false
@ -209,14 +165,13 @@ export class MenuComponent {
*/ */
submitEditMenuForm() { submitEditMenuForm() {
if (this.editMenuForm.valid) { if (this.editMenuForm.valid) {
console.log('submit', this.editMenuForm.value);
this.menuService.editMenu(this.editMenuForm.value, (data: any) => { this.menuService.editMenu(this.editMenuForm.value, (data: any) => {
if (data['return_code'] == '000000') { if (data['return_code'] == '000000') {
console.log("获取数据", data);
// 刷新数据 // 刷新数据
this.queryMenuTree2(); this.queryMenuTree();
this.message.create('success', '操作成功'); this.message.create('success', '操作成功');
// 关闭弹窗 // 关闭弹窗
this.closeEditMenu(); this.closeEditMenu();
} else { } else {
@ -239,4 +194,36 @@ export class MenuComponent {
closeEditMenu() { closeEditMenu() {
this.editMenuVisible = false; 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 * @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 * @param roleId
@ -53,12 +75,12 @@ export class MenuService {
* @param roleId * @param roleId
* @param callBack * @param callBack
*/ */
public queryRoleMenuTree2(roleId: string, callBack:any) { public queryRoleMenuTreeCustomized(roleId: string, callBack:any) {
let paramStr = ''; let paramStr = '';
if (roleId != null && roleId != '') { if (roleId != null && roleId != '') {
paramStr = '?roleId=' + 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); callBack(data);
}); });
} }

@ -22,9 +22,10 @@ export class InterceptorService implements HttpInterceptor {
let modifiedHeaders: HttpHeaders; let modifiedHeaders: HttpHeaders;
const token = this.storage.get(USER_TOKEN); const token = this.storage.get(USER_TOKEN);
if (token != null) { if (token != null) {
modifiedHeaders = req.headers.set('Authorization', token); modifiedHeaders =
modifiedHeaders = req.headers.set( 'Cache-Control', 'no-cache',) req.headers.append('Cache-Control', 'no-cache')
modifiedHeaders = req.headers.set( 'Pragma', 'no-cache',) .append('Pragma', 'no-cache')
.append('Authorization', token);
} }
secureReq = req.clone({ secureReq = req.clone({

Loading…
Cancel
Save