提交 47f388ff 编写于 作者: Mosher's avatar Mosher

update:新增树节点上下文菜单权限计算逻辑

上级 a278cdd1
import { deepCopy, deepObjectMerge, IActionParam, IParam, isEmpty, MDControl } from "@core";
import { deepCopy, deepObjectMerge, IActionParam, IParam, isEmpty, isExistAndNotEmpty, MDControl, UIUtil } from "@core";
import { TreeControlProps } from "./tree-control-prop";
import { TreeControlState } from "./tree-control-state";
......@@ -88,7 +88,7 @@ export class TreeControl extends MDControl {
public useLoad() {
const { viewSubject, controlName } = this.state;
const load = async (node?: any, isFirst: boolean = false): Promise<any> => {
if (node?.dataRef?.children) {
if (node?.children && node.children.length) {
return null;
}
const {
......@@ -98,22 +98,22 @@ export class TreeControl extends MDControl {
let curNode: any = {};
curNode = deepObjectMerge(curNode, node);
const params: any = {
srfnodeid: node?.dataRef && node.dataRef.id ? node.dataRef.id : '#',
srfnodeid: node && node.id ? node.id : '#',
srfnodefilter: srfnodefilter,
parentData: curNode.dataRef?.curData
parentData: curNode?.curData
}
let tempContext: any = this.computecurNodeContext(curNode);
if (curNode.dataRef && curNode.dataRef.sefparentdename) {
Object.assign(tempContext, { srfparentdename: curNode.dataRef.srfparentdename });
Object.assign(tempViewParams, { srfparentdename: curNode.dataRef.srfparentdename });
if (curNode && curNode.sefparentdename) {
Object.assign(tempContext, { srfparentdename: curNode.srfparentdename });
Object.assign(tempViewParams, { srfparentdename: curNode.srfparentdename });
}
if (curNode.dataRef && curNode.dataRef.srfparentdemapname) {
Object.assign(tempContext, { srfparentdemapname: curNode.dataRef.srfparentdemapname });
Object.assign(tempViewParams, { srfparentdemapname: curNode.dataRef.srfparentdemapname });
if (curNode && curNode.srfparentdemapname) {
Object.assign(tempContext, { srfparentdemapname: curNode.srfparentdemapname });
Object.assign(tempViewParams, { srfparentdemapname: curNode.srfparentdemapname });
}
if (curNode.dataRef && curNode.dataRef.srfparentkey) {
Object.assign(tempContext, { srfparentkey: curNode.dataRef.srfparentkey });
Object.assign(tempViewParams, { srfparentkey: curNode.dataRef.srfparentkey });
if (curNode && curNode.srfparentkey) {
Object.assign(tempContext, { srfparentkey: curNode.srfparentkey });
Object.assign(tempViewParams, { srfparentkey: curNode.srfparentkey });
}
Object.assign(params, { viewParams: tempViewParams });
try {
......@@ -132,7 +132,13 @@ export class TreeControl extends MDControl {
items.value.push(item);
});
} else {
node.dataRef.children = data;
const nodeData = this.getTreeNodeById(node.id);
data.forEach((item: any) => {
item.parentNodeId = node.id;
});
if (nodeData) {
nodeData.children = data;
}
}
const isSelectedAll = node?.checked;
this.setDefaultSelection(data, isRoot, isSelectedAll);
......@@ -205,12 +211,19 @@ export class TreeControl extends MDControl {
protected refreshParent() {
const { currentSelectedNode } = this.state;
console.log(1111, "刷新父", currentSelectedNode);
if (currentSelectedNode && currentSelectedNode.parentNodeId) {
// 父节点
const parentNode = this.getTreeNodeById(currentSelectedNode.parentNodeId);
if (parentNode) {
delete parentNode.children;
// this.load(parentNode);
}
}
}
protected refreshAll() {
const { currentSelectedNode } = this.state;
console.log(1111, "刷新全部", currentSelectedNode);
// this.load({}, true);
}
/**
......@@ -222,7 +235,7 @@ export class TreeControl extends MDControl {
protected formatExpanded(items: IParam[]) {
const { expandedKeys } = this.state;
items.forEach((item: any) => {
if (item.expanded) {
if (item.expanded && expandedKeys.findIndex((key: string) => key === item.id) === -1) {
expandedKeys.push(item.id);
}
})
......@@ -381,6 +394,7 @@ export class TreeControl extends MDControl {
protected onContextMenuClick(node: any, { key, domEvent: event }: any) {
const { context, viewParams, contextMenus } = this.state;
const action = contextMenus[node.nodeType]?.find((item: IParam) => item.name === key);
this.state.currentSelectedNode = node;
if (!action) {
console.warn("上下文菜单执行参数不足");
return;
......@@ -395,6 +409,68 @@ export class TreeControl extends MDControl {
App.getAppActionService().execute(action, inputParam);
}
/**
* @description 树节点右键点击
* @protected
* @param {*} { event, node }
* @memberof TreeControl
*/
protected onRightClick({ event, node }: any) {
// 计算节点上下文菜单权限
this.computeNodeContextMenuState(node, event);
}
/**
* @description 计算节点上下文菜单权限
* @private
* @param {*} node
* @param {MouseEvent} event
* @memberof TreeControl
*/
private computeNodeContextMenuState(node: any, event: MouseEvent) {
const { contextMenus, UIService } = this.state;
if (contextMenus && contextMenus[node.nodeType]) {
UIUtil.calcActionItemAuthState(node, contextMenus[node.nodeType], UIService);
}
}
/**
* @description 根据节点标识获取父节点
* @private
* @param {string} id 节点标识
* @return {*}
* @memberof TreeControl
*/
private getTreeNodeById(id: string): any {
const { items } = toRefs(this.state);
if (!isExistAndNotEmpty(id) || (!items.value || items.value.length === 0)) {
return null;
}
let node: any = null;
const getNode = (item: any): boolean => {
let flag: boolean = false;
if (item.id === id) {
node = item;
flag = true;
}
if (item.children && item.children.length > 0) {
for (const child of item.children) {
if (getNode(child)) {
flag = true;
break;
}
}
}
return flag;
}
for (const item of items.value) {
if (getNode(item)) {
break;
}
}
return node;
}
/**
* @description 安装部件所有功能模块的方法
* @return {*}
......@@ -406,7 +482,7 @@ export class TreeControl extends MDControl {
...superParams,
onTreeNodeSelect: this.onTreeNodeSelect.bind(this),
onContextMenuClick: this.onContextMenuClick.bind(this),
load: this.useLoad(),
onRightClick: this.onRightClick.bind(this)
};
}
}
\ No newline at end of file
......@@ -47,7 +47,7 @@ const getCustomText = (scriptCode: any) => {
}
// 安装功能模块,提供状态和能力方法
const { name, state, load, onTreeNodeSelect, onContextMenuClick } = new TreeControl(ctrlState, props, emit).moduleInstall();
const { name, state, load, onTreeNodeSelect, onContextMenuClick, onRightClick } = new TreeControl(ctrlState, props, emit).moduleInstall();
{{#and ctrl.psAppCounterRef ctrl.psAppCounterRef.psAppCounter}}
// 获取计数器数据
......@@ -75,7 +75,8 @@ defineExpose({ name, state });
show-icon
v-model:expandedKeys="state.expandedKeys"
v-model:selectedKeys="state.selectedKeys"
@select="onTreeNodeSelect">
@select="onTreeNodeSelect"
@rightClick="onRightClick">
<template #icon="node">
<span class="app-tree-node__icon">
<template v-if="node.iconCustomCode && node.iconScriptCode">
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册