坐标设置和在线数据搜索

This commit is contained in:
2025-10-11 16:09:11 +08:00
parent 24ae512178
commit a69bccce53
10 changed files with 523 additions and 120 deletions

View File

@ -5,51 +5,50 @@
* typeSonNode:不参与查询的节点的子孙节点是否也不参与匹配默认为false即子节点参与匹配
* */
window.newFuzzySearch = function(
window.newFuzzySearch = function (
treeId,
keyword,
notSearchType = [],
typeSonNode = false,
dispatch = ""
dispatch = ''
) {
//获取所有节点数据
let zTreeObj = $.fn.zTree.getZTreeObj(treeId);
let idKey = zTreeObj.setting.data.simpleData.idKey;
let nodes = zTreeObj.getNodes();
let zTreeObj = $.fn.zTree.getZTreeObj(treeId)
let idKey = zTreeObj.setting.data.simpleData.idKey
let nodes = zTreeObj.getNodes()
//过滤掉不要的
function getCustomNodes(allNodes) {
// let allNode = JSON.parse(JSON.stringify(allNodes))
let notSearchTypeNodesIds = [];
let notSearchTypeNodesIds = []
if (notSearchType.length) {
allNodes.forEach((allNodeItem) => {
if (notSearchType.includes(allNodeItem.sourceType)) {
notSearchTypeNodesIds.push(allNodeItem[idKey]);
notSearchTypeNodesIds.push(allNodeItem[idKey])
}
});
})
//typeSonNode为true时循环notSearchType类型的节点找出其子节点
let res = [];
let res = []
if (typeSonNode) {
notSearchTypeNodesIds.forEach((id, index) => {
let nodes = zTreeObj.transformToArray(
zTreeObj.getNodeByParam(idKey, id, null)
);
let nodes = zTreeObj.transformToArray(zTreeObj.getNodeByParam(idKey, id, null))
nodes.forEach((item) => {
res.push(item[idKey]);
});
});
notSearchTypeNodesIds = res;
res.push(item[idKey])
})
})
notSearchTypeNodesIds = res
}
}
let res = [];
let res = []
allNodes.forEach((item, index) => {
if (!notSearchTypeNodesIds.includes(item[idKey])) {
// console.log(index)
res.push(item);
res.push(item)
}
});
allNodes = res;
return allNodes;
})
allNodes = res
return allNodes
}
/*let allNodes = zTreeObj.transformToArray(nodes);
let nodeChildren = getCustomNodes(allNodes)*/
@ -59,63 +58,60 @@ window.newFuzzySearch = function(
//隐藏所有节点
function hideAllNode(allNodes) {
if (!allNodes || !Array.isArray(allNodes)) {
console.warn("hideAllNode: allNodes 参数无效");
return;
console.warn('hideAllNode: allNodes 参数无效')
return
}
let nodeChildren = getCustomNodes(allNodes);
let nodeChildren = getCustomNodes(allNodes)
if (nodeChildren && nodeChildren.length > 0) {
zTreeObj.hideNodes(nodeChildren);
zTreeObj.hideNodes(nodeChildren)
}
}
//模糊匹配所有符合的节点
function search(contrast, allNodes) {
if (!allNodes || !Array.isArray(allNodes)) {
console.warn("search: allNodes 参数无效");
return;
console.warn('search: allNodes 参数无效')
return
}
let nodeChildren = getCustomNodes(allNodes);
let nodeChildren = getCustomNodes(allNodes)
if (!nodeChildren) {
return;
return
}
hideAllNode(allNodes);
hideAllNode(allNodes)
nodeChildren.forEach((item) => {
if (item.oldname) {
item.sourceName = item.oldname;
zTreeObj.updateNode(item);
item.sourceName = item.oldname
zTreeObj.updateNode(item)
}
if (contrast) {
if ((item.sourceName || "").indexOf(contrast) > -1) {
console.log("sourceName包含关键字");
console.log(item);
console.log(item.sourceName);
if ((item.sourceName || '').indexOf(contrast) > -1) {
console.log('sourceName包含关键字')
console.log(item)
console.log(item.sourceName)
item.oldname = item.sourceName;
item.highlight = true;
let F = new RegExp(contrast, "gi");
item.sourceName = item.oldname.replace(F, function(h) {
let str =
'<span style="color: whitesmoke;background-color: darkred;">' +
h +
"</span>";
return str;
});
item.oldname = item.sourceName
item.highlight = true
let F = new RegExp(contrast, 'gi')
item.sourceName = item.oldname.replace(F, function (h) {
let str = '<span style="color: whitesmoke;background-color: darkred;">' + h + '</span>'
return str
})
// let a = item.name
// a = '<span style="color: whitesmoke;background-color: darkred;">' + a + "</span>"
// item.name = a
zTreeObj.setting.view.nameIsHTML = true;
item.checked = true;
zTreeObj.setting.view.nameIsHTML = true
item.checked = true
// zTreeObj.setting.view.fontCss["color"] = "#8B0000"
zTreeObj.updateNode(item);
zTreeObj.showNode(item);
showNodePath(item);
zTreeObj.updateNode(item)
zTreeObj.showNode(item)
showNodePath(item)
}
/*zTreeObj.updateNode(item);
zTreeObj.showNode(item);
showNodePath(item)*/
}
});
})
/*let searchNodes = zTreeObj.getNodesByParamFuzzy('name', contrast);
console.log('searchNodes', searchNodes)
searchNodes.forEach(function (node) {
@ -123,40 +119,40 @@ window.newFuzzySearch = function(
zTreeObj.showNode(node);
showNodePath(node)
})*/
zTreeObj.expandAll(true);
zTreeObj.expandAll(true)
}
//将查找到的节点父节点按路径设置为显示
function showNodePath(node) {
let parrentNodes = node.getPath();
let parrentNodes = node.getPath()
parrentNodes &&
parrentNodes.forEach(function(node) {
zTreeObj.showNode(node);
});
parrentNodes.forEach(function (node) {
zTreeObj.showNode(node)
})
}
window.treeSearchCb = (value = undefined) => {
let inputValue = value == undefined ? $(keyword).val() : "";
let inputValue = value || ''
// console.log("搜索值", inputValue)
nodes = zTreeObj.getNodes();
let allNodes = zTreeObj.transformToArray(nodes);
let nodeChildren = getCustomNodes(allNodes);
console.log("nodeChildren", nodeChildren);
search(inputValue, allNodes);
nodes = zTreeObj.getNodes()
let allNodes = zTreeObj.transformToArray(nodes)
let nodeChildren = getCustomNodes(allNodes)
console.log('nodeChildren', nodeChildren)
search(inputValue, allNodes)
//当查询条件为空时,显示所有节点
console.log("inputValue", inputValue);
if ((inputValue == null || inputValue === "") && nodeChildren.length >= 0) {
nodeChildren.forEach(function(node) {
console.log('inputValue', inputValue)
if ((inputValue == null || inputValue === '') && nodeChildren.length >= 0) {
nodeChildren.forEach(function (node) {
// node.checked = false
zTreeObj.showNode(node);
});
zTreeObj.showNode(node)
})
// zTreeObj.expandAll(false);
}
};
if (dispatch == "") {
}
if (dispatch == '') {
//input框值改变时
$(keyword).bind("input propertychange", treeSearchCb);
$(keyword).bind('input propertychange', treeSearchCb)
} else {
// $(dispatch).bind('click', treeSearchCb)
}
};
}