Files
4.0/src/renderer/components/Tree/treeSetting.js
2025-09-02 10:01:05 +08:00

740 lines
25 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import * as treeNodeOption from "./treeNode";
import { hideSource, showSource } from "@/api/gisAPI";
import { cusRenderNode, cusRenderNode2d } from "./treeNode";
import { updatePid } from "../../api/gisAPI";
import { cusUpdateNode } from "./treeNode";
import { ipcRenderer, contextBridge } from "electron";
import { set } from "nprogress";
let nodes = [];
const tree = {
data() {
return {
treeObj: null,
setting: {
edit: {
enable: true,
showRemoveBtn: false,
showRenameBtn: false,
drag: {
isMove: true,
isCopy: false,
},
},
check: {
enable: true,
nocheckInherit: false,
chkboxType: { Y: "ps", N: "s" },
},
view: {
selectedMulti: true,
// autoCancelSelected: true
},
data: {
key: {
//zdatas数据中表示节点name的属性key
name: "source_name",
checked: "is_show",
},
simpleData: {
enable: true,
idKey: "source_id",
pIdKey: "p_id",
nameKey: "source_name",
},
},
callback: {
onRightClick: this.onRightClick,
beforeDrag: this.beforeDrag,
onDrop: this.onDrop,
beforeRemove: this.beforeRemove,
beforeDrop: this.beforeDrop,
// beforeCollapse: this.beforeCollapse,
onRemove: this.onRemove,
onMouseDown: this.onMouseDown,
onClick: this.onClick,
onDblClick: this.onDblClick,
beforeClick: this.zTreeBeforeClick,
onCheck: this.onCheck,
onExpand: this.addChildNodes,
},
},
};
},
methods: {
addChildNodes(event, treeId, treeNode) {
if (treeNode.children.length) return;
var treeObj = $.fn.zTree.getZTreeObj(treeId);
//加载shp gdb kml子级数据
if (treeNode.source_type == "FeatureCollection") {
var newnodes = window._entityMap.get(treeNode.fid).getAllNode();
if (newnodes) {
let arrt = treeNode.detail.hasOwnProperty("fieldName")
? treeNode.detail.fieldName
: treeNode.detail.defaultfieldName;
newnodes.list.forEach((it) => {
let zijiNodes = [];
if (it.name == treeNode.source_name) {
if (it.features && it.features.length) {
it.features.forEach((item) => {
let ziNode = {
source_id: item.id,
source_type: item.type,
source_name: item.properties[arrt],
detail: { ...item, info: { type: "richText" } },
is_show: 1,
fid: treeNode.fid,
};
zijiNodes.push(ziNode);
});
}
}
let childNode = treeObj.getNodeByParam(
"source_id",
treeNode.source_id,
null
);
if (childNode) {
treeObj.addNodes(childNode, zijiNodes, true);
}
});
}
}
},
setOptions2d(node) {
if (node.source_type !== "directory") {
node.icon = treeNodeOption.cusNodeIcon(node.source_type);
if (node.is_show) treeNodeOption.cusRenderNode2d(node);
}
},
/**
* 设置node节点的属性
* @param node
*/
setOptions(node) {
if (node.source_type !== "directory") {
node.icon = treeNodeOption.cusNodeIcon(node);
if (
(node.is_show && node.source_type != "path") ||
node.source_type == "path"
) {
if (!["pressModel", "terrainDig"].includes(node.source_type)) {
treeNodeOption.cusRenderNode(node, false);
}
}
}
},
/**
* 对象数组按照key属性进行排序
* @param key
* @returns {function(*, *): *}
*/
keysort(key) {
return function(a, b) {
return a[key] - b[key];
};
},
zTreeBeforeClick(treeId, treeNode, clickFlag) {
this.$changeComponentShow(".rightMenu", false);
this.treeObj.cancelSelectedNode();
},
/**
* 树形节点右键点击
* @param event 事件对象
* @param treeId 树形结构id
* @param treeNode 鼠标右键点击时所在节点的 JSON 数据对象
*/
onRightClick(event, treeId, treeNode) {
//没按ctrl的时候执行&& !treeNodeOption.getSelectedNodes(this.treeObj).length <2
let selectNodes = treeNodeOption.getSelectedNodes(this.treeObj);
let isnewSelect = true; //是否为新选中
selectNodes.forEach((item) => {
if (treeNode && item.source_id == treeNode.source_id)
isnewSelect = false;
});
console.log("selectNodes1111111111111111111111", selectNodes);
if (!event.ctrlKey && (selectNodes.length < 2 || isnewSelect))
treeNodeOption.cusSelectNode(this.treeObj, treeNode);
let menus = treeNodeOption.showRightMenu(event, this.treeObj);
let ids = [
"模型图层",
"特效图层",
"标绘图层",
"二维军标图层",
"三维军标图层",
];
// 判断source_ids中如果包含ids中的id则不显示右键菜单
if (treeNode && treeNode.source_id) {
if (ids.includes(treeNode.source_id)) {
menus = [
"addDirectory",
"addResource",
"pictureLocation",
"importPanorama",
];
}
}
console.log("treeNode", treeNode);
console.log(menus);
if (menus.length == 0) {
return;
}
// this.$changeComponentShow(".rightMenu", true);
// if (window.childNo) {
let that = this;
let menuBox = document.querySelector(".rightMenu");
menuBox.style.display = "block";
that.$nextTick(() => {
$root_home_index.$refs.tree.$refs.rightMenu.initMenu(menus, treeNode);
});
// }
},
beforeDrag(treeId, treeNodes) {
console.log("beforeDrag", treeId, treeNodes);
// if(treeNodes[0].isleaf == true){ //叶子节点
// return false
// }else{
// return true
// }
},
/**
* 用于捕获节点拖拽操作结束的事件回调函数
* @param event 事件对象
* @param treeId 树形结构id
* @param treeNodes 被拖拽的节点 JSON 数据集合
* @param targetNode 成为 treeNodes 拖拽结束的目标节点 JSON 数据对象
* @param moveType
*/
onDrop(event, treeId, treeNodes, targetNode, moveType) {
console.log("用于捕获节点拖拽操作结束的事件回调函数");
console.log("1111", treeId, treeNodes, moveType, targetNode);
// 获取check的node下所有的节点得到所有的id
let nodes = this.treeObj.getSelectedNodes();
let source_ids = [];
nodes.forEach((item) => {
source_ids.push(item.source_id);
});
let updateTree = (nodes, p_id) => {
nodes.forEach((item) => {
item.p_id = p_id;
this.treeObj.updateNode(item);
});
};
window.AllNodes = this.treeObj.getNodes();
/* else {*/
if (targetNode == null) {
updatePid(
{
source_ids,
p_id: "",
trees: [
{
source_id: treeNodes[0].source_id,
tree_index: treeNodes[0].getIndex(),
},
],
},
(res) => {
// updateTree(nodes, -1);
}
);
} else {
// let ParentNode = nodes[0].getParentNode();
let Nodes = this.treeObj.getNodesByParam(
"level",
treeNodes[0].level,
null
);
console.log("Nodes", Nodes, treeNodes);
let trees = [];
Nodes.forEach((item) => {
trees.push({
source_id: item.source_id,
tree_index: item.getIndex(),
});
});
let p_id = ["prev", "next"].includes(moveType)
? targetNode.p_id
: targetNode.source_id;
if (p_id == "") {
p_id = -1;
}
console.log("p_id", this.treeObj.getSelectedNodes());
updatePid({ source_ids, p_id, trees }, (res) => {
console.log(res);
});
}
},
/**
* 用于捕获节点拖拽操作结束之前的事件<E4BA8B><E4BBB6>调函数并且根据返回值确定是否允许此拖拽操作
* @param treeId 树形结构id
* @param treeNodes 被拖拽的节点 JSON 数据集合
* @param targetNode treeNodes 被拖拽放开的目标节点 JSON 数据对象
* @param moveType 指定移动到目标节点的相对位置《"inner":成为子节点,"prev"
* 成为同级前一个节点,"next":成为同级后一个节点》
* @returns {boolean} 返回 falsezTree 将恢复被拖拽的节点,也无法触发 onDrop 事件回调函数
*/
beforeDrop(treeId, treeNodes, targetNode, moveType) {
if (
["prev", "next", "inner"].includes(moveType) &&
[
"模型图层",
"特效图层",
"标绘图层",
"二维军标图层",
"三维军标图层",
].includes(treeNodes[0].source_id)
) {
return false;
}
if (
["prev", "next", "inner"].includes(moveType) &&
["pressModel", "terrainDig"].includes(treeNodes[0].source_type)
) {
return false;
}
if (["prev", "next"].includes(moveType)) {
let parent = this.treeObj.getNodeByParam(
"source_id",
targetNode.p_id,
null
);
if (
parent &&
!treeNodeOption.nodeType[parent.source_type].allowChildren
)
return false;
}
if (targetNode) {
if (
moveType == "inner" &&
!treeNodeOption.nodeType[targetNode.source_type].allowChildren
) {
return false;
}
}
},
/**
* 用于捕获zTree上鼠标按键按下后的事件回调函数
* @param event
* @param treeId
* @param treeNode
*/
onMouseDown(event, treeId, treeNode) {
// console.log(treeNode);
// window.treeNode = treeNode
// treeNodeOption.cusSelectNode(this.treeObj, treeNode);
/*this.$changeComponentShow(".rightMenu", false);
this.treeObj.cancelSelectedNode()*/
let isShift = event.shiftKey;
let isCtrl = event.ctrlKey;
if ((!isShift && !isCtrl) || !treeNode) {
nodes = [];
}
let ids = [
"模型图层",
"特效图层",
"标绘图层",
"二维军标图层",
"三维军标图层",
];
if (treeNode) {
if (ids.includes(treeNode.source_type)) {
return false;
}
}
console.log("nodes", treeNode);
if (treeNode) {
nodes.push(treeNode);
//根据编辑表单的回调,控制图层的勾选显示
//判断是否是图层文件
if (isCtrl) {
let isSelected = this.treeObj
.getSelectedNodes()
.some((node) => node.source_id === treeNode.source_id);
if (isSelected) {
console.log("isSelected", isSelected, nodes);
// 如果节点已选中,则取消选中
nodes = nodes.filter(
(node) => node.source_id !== treeNode.source_id
);
} else {
// 如果节点未选中,则添加到选中列表
nodes.push(treeNode);
}
}
if (
treeNode.source_type !== "directory" &&
treeNode.source_type !== "layer"
) {
if (
!(
_entityMap.get(treeNode.source_id) &&
_entityMap.get(treeNode.source_id).Dialog
)
) {
return;
}
_entityMap.get(treeNode.source_id).Dialog.showCallBack = () => {
// 获取check的node下所有的节点得到所有的id
treeNode.is_show = !treeNode.is_show;
let nodes = this.treeObj.transformToArray(treeNode);
let source_ids = [];
nodes.forEach((item) => {
source_ids.push(item.source_id);
});
//根据source_id获取对应的资源更改其在地球上的显示状态
let sourceStatus = (source_ids, status) => {
source_ids.forEach((id) => {
let source = window._entityMap.get(id);
let node = this.treeObj.getNodeByParam("source_id", id, null);
if (window.right_entityMap.get(treeNode.source_id))
window.right_entityMap.get(treeNode.source_id).show = status;
window._entityMap.get(treeNode.source_id).show = status;
node.is_show = status;
cusUpdateNode(node);
});
};
// 调用接口更改数据库is_show的值
if (treeNode.is_show)
showSource({ source_ids }, (data) => {
sourceStatus(source_ids, treeNode.is_show);
});
else
hideSource({ source_ids }, (data) => {
sourceStatus(source_ids, treeNode.is_show);
});
};
}
} else {
this.treeObj.cancelSelectedNode();
this.$changeComponentShow(".rightMenu", false);
}
},
// onMouseDown(event, treeId, treeNode) {
// let isShift = event.shiftKey;
// let isCtrl = event.ctrlKey;
// // 如果点击的不是节点,清空选择并隐藏右键菜单
// if (!treeNode) {
// nodes = [];
// this.treeObj.cancelSelectedNode();
// this.$changeComponentShow(".rightMenu", false);
// return;
// }
// // 处理 Ctrl 键多选
// if (isCtrl) {
// let isSelected = this.treeObj
// .getSelectedNodes()
// .some((node) => node.source_id === treeNode.source_id);
// if (isSelected) {
// console.log("isSelected");
// // 如果节点已选中,则取消选中
// this.treeObj.cancelSelectedNode(treeNode);
// nodes = nodes.filter((node) => node.source_id !== treeNode.source_id);
// } else {
// console.log("如果节点未选中,则添加到选中列表");
// // 如果节点未选中,则添加到选中列表
// this.treeObj.selectNode(treeNode, true);
// nodes.push(treeNode);
// }
// /* nodes.forEach((item) => {
// // this.treeObj.selectNode(item, true);
// }); */
// } else if (!isShift) {
// // 如果没有按下Ctrl或Shift则只选中当前节点
// nodes = [treeNode];
// this.treeObj.cancelSelectedNode();
// this.treeObj.selectNode(treeNode, true);
// } else {
// // Shift 多选逻辑保持不变
// nodes.push(treeNode);
// }
// // 处理非目录和非图层类型的节点
// if (
// treeNode.source_type !== "directory" &&
// treeNode.source_type !== "layer"
// ) {
// if (
// !(
// _entityMap.get(treeNode.source_id) &&
// _entityMap.get(treeNode.source_id).Dialog
// )
// ) {
// return;
// }
// _entityMap.get(treeNode.source_id).Dialog.showCallBack = () => {
// // 获取check的node下所有的节点得到所有的id
// treeNode.is_show = !treeNode.is_show;
// let nodes = this.treeObj.transformToArray(treeNode);
// let source_ids = [];
// nodes.forEach((item) => {
// source_ids.push(item.source_id);
// });
// //根据source_id获取对应的资源更改其在地球上的显示状态
// let sourceStatus = (source_ids, status) => {
// source_ids.forEach((id) => {
// let source = window._entityMap.get(id);
// let node = this.treeObj.getNodeByParam("source_id", id, null);
// if (window.right_entityMap.get(treeNode.source_id)) {
// window.right_entityMap.get(treeNode.source_id).show = status;
// }
// window._entityMap.get(treeNode.source_id).show = status;
// node.is_show = status;
// cusUpdateNode(node);
// });
// };
// // 调用接口更改数据库is_show的值
// if (treeNode.is_show) {
// showSource({ source_ids }, (data) => {
// sourceStatus(source_ids, treeNode.is_show);
// });
// } else {
// hideSource({ source_ids }, (data) => {
// sourceStatus(source_ids, treeNode.is_show);
// });
// }
// };
// } else {
// this.treeObj.cancelSelectedNode();
// this.$changeComponentShow(".rightMenu", false);
// }
// },
onClick(e, treeId, treeNode, clickFlagNumber) {
let isShift = e.shiftKey;
let isCtrl = e.ctrlKey;
// 点击文件夹下面所有的source_id
if (isShift) {
if (nodes.length > 1) {
//如果是按下shift键
let pId = treeNode.p_id;
let nodeIndexs = [];
nodes.forEach((item) => {
nodeIndexs.push(item.getIndex());
});
let Nodes = this.treeObj.getNodesByParam("p_id", pId, null);
nodeIndexs.sort((x, y) => x - y);
let minIndex = nodeIndexs[0];
let maxIndex = nodeIndexs[nodeIndexs.length - 1];
Nodes.forEach((item) => {
let i = item.getIndex();
if (i >= minIndex && i <= maxIndex) {
this.treeObj.selectNode(item, true);
}
});
}
}
if (isCtrl) {
nodes.forEach((item) => {
this.treeObj.selectNode(item, true);
});
}
//物理沙盘-传输对方数据
// if (nodes[0].source_type === 'point') {
// ipcRenderer.send('setNodes', '110');
// ipcRenderer.on("replayRenderer", (event, data) => {
// this.$message.success(data)
// });
// }
if (!isCtrl || !isShift) {
let source_ids = [];
console.log("treeNode", treeNode);
// 判断是否是图层文件
if (treeNode.source_type == "directory") {
// 获取treeNode下面的所有souer_id
if (treeNode.children) {
treeNode.children.forEach((item) => {
source_ids.push(item.source_id);
});
}
} else {
source_ids.push(treeNode.source_id);
}
console.log("source_ids", source_ids);
YJ.Global.splitScreen.setActiveId(source_ids);
}
},
/**
* 捕获 zTree 上鼠标双击之后的事件回调函数s
* @param event
* @param treeId
* @param treeNode
*/
onDblClick(event, treeId, treeNode) {
console.log("双击文件夹", treeNode);
let entity = window._entityMap.get(treeNode.source_id);
// if (!entity) {
// this.$message.warning("无资源数据");
// }
//飞行漫游
if (treeNode.source_type === "roam") {
this.$message("单击鼠标右键可结束当前漫游");
YJ.Global.FlyRoam.flyTo(window.Earth1, treeNode.detail.points);
return;
}
// 轨迹运动
if (treeNode.source_type === "path") {
if (window.$PATH) {
window.$PATH.viewFollow = false;
}
window.$PATH = entity;
entity.viewFollow = true;
return;
} else {
if (window.$PATH) {
window.$PATH.viewFollow = false;
}
}
if (treeNode.source_type === "Feature") {
console.log("shon", treeNode);
window._entityMap.get(treeNode.fid).flyTo(treeNode.source_id);
return;
}
// "groundImage"
if (treeNode.source_type === "groundImage") {
window._entityMap.get(treeNode.source_id).load(() => {
window._entityMap.get(treeNode.source_id).flyTo();
});
}
if (
treeNode.source_type === "node" ||
treeNode.source_type === "element"
) {
let bim = window._entityMap
.get(treeNode.fid)
.featureFlyto(treeNode.source_id.split("_")[0]);
console.log("双击", bim, treeNode.source_id.split("_")[0]);
return;
}
if (treeNode && entity) {
window._entityMap.get(treeNode.source_id).flyTo();
window.right_entityMap.get(treeNode.source_id) &&
window.right_entityMap.get(treeNode.source_id).flyTo();
// if (treeNode.source_type == "path") {
// $root_home_index.$refs.editor.$refs.path.trajectoryObj[
// treeNode.source_id + "obj"
// ].cameraAttached = true;
// window._entityMap.get(treeNode.source_id).playing = true;
// } else {
// if (treeNode.detail.hasOwnProperty("customView")) {
// YJ.Global.flyTo(treeNode.detail.customView);
// } else {
// window._entityMap.get(treeNode.source_id).flyTo();
// window.right_entityMap.get(treeNode.source_id) &&
// window.right_entityMap.get(treeNode.source_id).flyTo();
// }
// }
}
},
/**
* 捕获 checkbox / radio 被勾选 或 取消勾选的事件回调函数
* @param event
* @param treeId
* @param treeNode
*/
onCheck(event, treeId, treeNode) {
console.log(treeNode);
// 获取check的node下所有的节点得到所有的id
let nodes = this.treeObj.transformToArray(treeNode);
let source_ids = [];
nodes.forEach((item) => {
if (item.isHidden == false) {
source_ids.push(item.source_id);
}
});
//根据source_id获取对应的资源更改其在地球上的显示状态
let sourceStatus = (source_ids, status) => {
source_ids.forEach((id) => {
// let node1 = this.treeObj.getNodeByParam("source_id", id, null);
// console.log("ddddddddddddddddddddddd", id, node1);
// let source1 = window._entityMap.get(id);
// console.log("source1", source1);
// return;
let source = window._entityMap.get(id);
let node = this.treeObj.getNodeByParam("source_id", id, null);
console.log("source", source, node);
node.source_name = node.oldname || node.source_name;
if (node.source_type == "Feature") {
let shp = window._entityMap.get(node.fid);
shp.setShow(status, id);
return;
}
if (node.source_type == "FeatureCollection") {
let shp = window._entityMap.get(node.fid);
console.log("shp", shp);
node.children.forEach((item) => {
shp.setShow(status, item.source_id);
console.log("item", status, item);
});
return;
}
if (node.source_type == "pressModel") {
let p_entity = window._entityMap.get(node.p_id);
let entity = window._entityMap.get(node.source_id);
if (p_entity && status == true) {
p_entity.show = status;
}else if(entity){
entity.show = status;
}
}
if (node.source_type == "node" || node.source_type == "element") {
let bim = window._entityMap.get(node.fid);
bim.featureShow(node.source_id.split("_")[0], status);
}
if (node.source_type == "roam") {
let num;
if (status) {
num = Infinity;
} else {
num = 0;
}
node.detail.repeat = num;
YJ.Global.FlyRoam.setRepeat(num);
}
if (window.right_entityMap.get(treeNode.source_id))
window.right_entityMap.get(treeNode.source_id).show = status;
if (node.source_type == "path") {
let pathModel = window._entityMap.get(id);
// console.log("pathModel+++++++++++++", pathModel, pathModel.modelShow);
if (pathModel) {
pathModel.show = status;
// pathModel.modelShow = status;
}
} else {
if (source) {
source.show = status;
} else {
cusRenderNode(node);
}
}
});
};
//调用接口更改数据库is_show的值
if (treeNode.is_show) {
showSource({ source_ids }, (data) => {
console.log(data);
sourceStatus(source_ids, treeNode.is_show);
});
} else {
hideSource({ source_ids }, (data) => {
console.log(data);
sourceStatus(source_ids, treeNode.is_show);
});
}
// YJ.Global.splitScreen.setActiveId([]);
},
},
};
export default tree;