From 94de1745b4b69eeeb1ac8c5d3508ce87258afc25 Mon Sep 17 00:00:00 2001 From: haoyahui <2032914783@qq.com> Date: 星期四, 16 十一月 2023 09:22:06 +0800 Subject: [PATCH] 库存管理 --- admin-web/src/utils/index.js | 37 ++++++++++++++++++++++++++++++++++++- 1 files changed, 36 insertions(+), 1 deletions(-) diff --git a/admin-web/src/utils/index.js b/admin-web/src/utils/index.js index fede7c7..c57d51a 100644 --- a/admin-web/src/utils/index.js +++ b/admin-web/src/utils/index.js @@ -1,4 +1,3 @@ - import Cookies from 'js-cookie'; /** * Created by PanJiaChen on 16/11/18. @@ -405,3 +404,39 @@ return staff.some((item) => item.avatar === JavaInfo.account); } } + +// 閫氳繃瀛愰泦id鏌ュ埌鎵�浠ョ浉鍏崇埗绾d骞惰繑鍥炴暟缁� +export function findParentIds(dataSource, nodeId) { + const parentIds = [nodeId]; // 鐢ㄤ簬瀛樺偍鎵�鏈夌埗鑺傜偣ID鐨勬暟缁� + + // 瀹氫箟涓�涓�掑綊鍑芥暟锛岀敤浜庨亶鍘嗘暣妫垫爲骞舵煡鎵惧瓙鑺傜偣鐨勬墍鏈夌埗鑺傜偣 + function traverse(node, nodeId) { + if (node.id === nodeId) { + // 濡傛灉褰撳墠鑺傜偣鐨処D绛変簬瀛愯妭鐐圭殑ID锛屽垯琛ㄧず宸茬粡鎵惧埌浜嗗瓙鑺傜偣锛屽彲浠ュ紑濮嬪悜涓婃煡鎵剧埗鑺傜偣 + return true; // 杩斿洖true琛ㄧず宸茬粡鎵惧埌浜嗗瓙鑺傜偣 + } + + if (node.children) { + // 濡傛灉褰撳墠鑺傜偣鏈夊瓙鑺傜偣锛屽垯缁х画閬嶅巻瀛愯妭鐐� + for (const childNode of node.children) { + if (traverse(childNode, nodeId)) { + // 濡傛灉鍦ㄥ瓙鑺傜偣涓壘鍒颁簡瀛愯妭鐐圭殑鐖惰妭鐐癸紝鍒欏皢褰撳墠鑺傜偣鐨処D娣诲姞鍒扮埗鑺傜偣ID鏁扮粍涓紝骞惰繑鍥瀟rue琛ㄧず宸茬粡鎵惧埌浜嗗瓙鑺傜偣 + parentIds.unshift(node.id); + return true; + } + } + } + + return false; // 濡傛灉褰撳墠鑺傜偣涓嶆槸瀛愯妭鐐圭殑鐖惰妭鐐癸紝鍒欒繑鍥瀎alse + } + + // 浠庢牴鑺傜偣寮�濮嬮亶鍘嗘暣妫垫爲锛屽苟璋冪敤閫掑綊鍑芥暟鏌ユ壘瀛愯妭鐐圭殑鎵�鏈夌埗鑺傜偣 + for (const node of dataSource) { + if (traverse(node, nodeId)) { + // 濡傛灉鍦ㄥ綋鍓嶈妭鐐圭殑瀛愭爲涓壘鍒颁簡瀛愯妭鐐圭殑鐖惰妭鐐癸紝鍒欑洿鎺ラ��鍑哄惊鐜� + break; + } + } + + return parentIds; // 杩斿洖鎵�鏈夌埗鑺傜偣ID鐨勬暟缁� +} \ No newline at end of file -- Gitblit v1.9.1