liding
2 天以前 8d24d963f8b82163685c34b816998a904f08234d
src/utils/standardTree.js
@@ -36,7 +36,10 @@
  let cur = node;
  while (cur && cur.parent) {
    if (isLeaf(cur.data)) {
      tokens.push(cur.label, leafMarker);
      const leafValue = cur.data && cur.data.standardMethodId
        ? (cur.data.value || cur.label)
        : cur.label;
      tokens.push(leafValue, leafMarker);
    } else {
      tokens.push(cur.label);
    }
@@ -75,6 +78,14 @@
// 去掉路径末段,用于「当前是叶子但查不到标准」时回退到父级查询
export function dropLastLabel(path) {
  if (!path) return '';
  const idx = path.lastIndexOf(' - ');
  return idx === -1 ? '' : path.slice(0, idx);
  const tokens = path.split(' - ');
  if (tokens.length <= 1) return '';
  // 叶子路径格式为“行业 - null - 标准”或“行业 -  - 标准”。
  // 去掉标准名后还要去掉仅用于标识叶子的占位段,父路径才是真实的行业路径。
  tokens.pop();
  const marker = tokens[tokens.length - 1];
  if (marker === '' || marker === 'null') {
    tokens.pop();
  }
  return tokens.join(' - ');
}