he wei
2025-04-23 b9bd29a1a81f6f7de479e3cc3fdfe3d85fc660bf
src/utils/tree.js
@@ -1,37 +1,45 @@
export function formatAreaTree(item, ids, list) {
  // parentId 不在id列表中;
  // if (item.parentId === 0) {
  if (ids.indexOf(item.parentId) === -1) {
    list.push({
      label: item.areaName,
      id: item.id,
      data: item,
      areaDescript: item.areaDescript,
      charger: item.areaUsers.map((v) => v.uname).join(","),
      children: [],
    });
  } else {
    let isCurrentChild = false;
    for (let i = 0; i < list.length; i++) {
      const listItem = list[i];
      if (listItem.id === item.parentId) {
        isCurrentChild = true;
        listItem.children.push({
          label: item.areaName,
          id: item.id,
          data: item,
          areaDescript: item.areaDescript,
          charger: item.areaUsers.map((v) => v.uname).join(","),
          children: [],
export function formatAreaTree(list) {
  return list.map(item => {
    const result = {
      label: item.stationName1,
      children: []
    };
    if (item.cityList) {
      result.children = item.cityList.map(city => {
        const cityNode = {
          label: city.stationName2,
          children: []
        };
        if (city.countryList) {
          cityNode.children = city.countryList.map(country => {
            const countryNode = {
              label: country.stationName3,
              children: []
            };
            if (country.stationList) {
              countryNode.children = country.stationList.map(station => {
                const stationNode = {
                  label: station.stationName4,
                  stationId: station.stationId,
                  children: []
                };
                if (station.baojiList) {
                  stationNode.children = station.baojiList.map(baoji => {
                    return {
                      label: baoji.baojiName,
                      id: `${baoji.id}-${station.stationId}`,
                    };
        });
      }
                return stationNode;
              });
    }
    for (let i = 0; i < list.length; i++) {
      const listItem = list[i];
      if (!isCurrentChild && listItem.children !== 0) {
        formatAreaTree(item, ids, listItem.children);
            return countryNode;
          });
      }
        return cityNode;
      });
    }
  }
    return result;
  });
}