树形结构扁平化

function flattenTreeData(treeData, parentId = '0') {
  return treeData.reduce((acc, item) => {
    if (item.pid === parentId) {
      acc.push(item);
      if (item.children && item.children.length > 0) {
        return acc.concat(flattenTreeData(item.children, item.id));
      }
      return acc;
    }
    return acc;
  }, []);
}