编辑代码

const nodes = {
    data: {
        "id": "电子产品",
        "label": "文件夹3",
        "type": "folder",
        "path": "/产品图片/电子产品",
        "description": "",
        "publlshed": "2022-12-1 12:36:41",
        "publlshedBy": "admin",
        "createTime": "2022-12-1 12:36:41",
        "tags": [],
        "children": []
    },
    id: 1160,
    isCurrent: true,
    level: 2,
    parent: {
        data: {
            "id": "产品图片",
            "label": "文件夹2",
            "type": "folder",
            "path": "/产品图片",
            "description": "",
            "publlshed": "2022-12-1 12:36:41",
            "publlshedBy": "admin",
            "createTime": "2022-12-1 12:36:41",
            "tags": [],
            "children": [
                {
                    "id": "奢侈品",
                    "label": "奢侈品",
                    "type": "folder",
                    "path": "/产品图片/奢侈品",
                    "description": "",
                    "publlshed": "2022-12-1 12:36:41",
                    "publlshedBy": "admin",
                    "createTime": "2022-12-1 12:36:41",
                    "tags": [],
                    "children": []
                },
                {
                    "id": "电子产品",
                    "label": "电子产品",
                    "type": "folder",
                    "path": "/产品图片/电子产品",
                    "description": "",
                    "publlshed": "2022-12-1 12:36:41",
                    "publlshedBy": "admin",
                    "createTime": "2022-12-1 12:36:41",
                    "tags": [],
                    "children": []
                }
            ]
        },
        id: 1158,
        isCurrent: false,
        level: 1,
        parent: {
            data: {
                "id": "产品图片",
                "label": "文件夹1",
                "type": "folder",
                "path": "/产品图片",
                "description": "",
                "publlshed": "2022-12-1 12:36:41",
                "publlshedBy": "admin",
                "createTime": "2022-12-1 12:36:41",
                "tags": [],
                "children": [
                    {
                        "id": "奢侈品",
                        "label": "奢侈品",
                        "type": "folder",
                        "path": "/产品图片/奢侈品",
                        "description": "",
                        "publlshed": "2022-12-1 12:36:41",
                        "publlshedBy": "admin",
                        "createTime": "2022-12-1 12:36:41",
                        "tags": [],
                        "children": []
                    },
                    {
                        "id": "电子产品",
                        "label": "电子产品",
                        "type": "folder",
                        "path": "/产品图片/电子产品",
                        "description": "",
                        "publlshed": "2022-12-1 12:36:41",
                        "publlshedBy": "admin",
                        "createTime": "2022-12-1 12:36:41",
                        "tags": [],
                        "children": []
                    }
                ]
            },
            id: 1152,
            isCurrent: false,
            level: 0,
        }
    }
}

let bar = [];

const getNodePath = (node) => {
    if (node.parent) {
        getNodePath(node.parent)
    }
    bar.push(node.data)

}
getNodePath(nodes)
console.log(bar)