SOURCE

const tree = {
    type: 'folder',
    children: [
        {
            type: 'page',
            label: 11,
            children: [
                {
                    type: 'page',
                    label: 22,
                    children: [
                        {
                            type: 'page',
                            label: 33,
                            children: []
                        },
                    ]
                },
            ]
        },
        {
            type: 'folder',
            label: 11,
            children: [
                {
                    type: 'page',
                    label: 55,
                    children: [
                        {
                            type: 'page',
                            label: 77,
                            children: []
                        },
                    ]
                },
                {
                    type: 'page',
                    label: 66,
                    children: []
                },
            ]
        },
    ]
}

function test(node, parent, index) {
    if (node.type === 'page') {
        console.log('map', node)
        const item = [];
        function dfs(node2) {
            item.push(node2);
            node2.children&&node2.children.map(n2 => {
                dfs(n2);
            })
            delete node2.children
        }
        dfs(node)
        // console.log(item.length, index, '-----')
        parent.children.splice(index, 1, ...item)
    } else {
        node.children.map((c, i) => {
            test(c, node, i)
        })
    }
}

// tree.children.map((item, index) => {
//     // console.log('map')
//     test(item, tree, index)
// })

for (let i =0;i<tree.children.length;i++){
    test(tree.children[i], tree, i)
}
console.log(tree);
console 命令行工具 X clear

                    
>
console