SOURCE

var testData = {
    "code": 200,
    "data": {
        "company": "",
        "id": 18640,
        "menus": [
            {
                "children": [
                    {
                        "children": [],
                        "icon": "",
                        "id": "19",
                        "menuType": "1",
                        "name": "公告模板",
                        "parentId": "18",
                        "perms": "",
                        "sort": 1,
                        "url": "/announcementTemplate"
                    },
                    {
                        "children": [],
                        "icon": "",
                        "id": "20",
                        "menuType": "1",
                        "name": "经营基础信息",
                        "parentId": "18",
                        "perms": "",
                        "sort": 2,
                        "url": "/basicInformation"
                    },
                    {
                        "children": [],
                        "icon": "",
                        "id": "21",
                        "menuType": "1",
                        "name": "基础设备信息",
                        "parentId": "18",
                        "perms": "",
                        "sort": 3,
                        "url": "/basicEquipmentInformation"
                    },
                    {
                        "children": [],
                        "icon": "",
                        "id": "22",
                        "menuType": "1",
                        "name": "营运战区",
                        "parentId": "18",
                        "perms": "",
                        "sort": 4,
                        "url": "/operationalTheater"
                    },
                    {
                        "children": [],
                        "icon": "",
                        "id": "23",
                        "menuType": "1",
                        "name": "营运区划",
                        "parentId": "18",
                        "perms": "",
                        "sort": 5,
                        "url": "/operationDivision"
                    },
                    {
                        "children": [],
                        "icon": "",
                        "id": "24",
                        "menuType": "1",
                        "name": "门店组",
                        "parentId": "18",
                        "perms": "",
                        "sort": 6,
                        "url": "/storeGroup"
                    }
                ],
                "icon": "el-icon-s-goods",
                "id": "18",
                "menuType": "0",
                "name": "基础设置",
                "parentId": "0",
                "perms": "",
                "sort": 0,
                "url": ""
            },
            {
                "children": [
                    {
                        "children": [
                            {
                                "children": [],
                                "icon": "",
                                "id": "40",
                                "menuType": "2",
                                "name": "市级",
                                "parentId": "26",
                                "perms": "cityCode",
                                "sort": 0,
                                "url": ""
                            },
                            {
                                "children": [],
                                "icon": "",
                                "id": "41",
                                "menuType": "2",
                                "name": "县级区",
                                "parentId": "26",
                                "perms": "districtCode",
                                "sort": 0,
                                "url": ""
                            },
                            {
                                "children": [],
                                "icon": "",
                                "id": "39",
                                "menuType": "2",
                                "name": "省级",
                                "parentId": "26",
                                "perms": "provinceCode",
                                "sort": 0,
                                "url": ""
                            }
                        ],
                        "icon": "",
                        "id": "26",
                        "menuType": "1",
                        "name": "区划信息卡",
                        "parentId": "25",
                        "perms": "",
                        "sort": 1,
                        "url": "/zoningInformationCard"
                    },
                    {
                        "children": [],
                        "icon": "",
                        "id": "27",
                        "menuType": "1",
                        "name": "门店商圈信息",
                        "parentId": "25",
                        "perms": "",
                        "sort": 2,
                        "url": "/storeBusinessCircleInformation"
                    },
                    {
                        "children": [],
                        "icon": "",
                        "id": "28",
                        "menuType": "1",
                        "name": "门店配置信息",
                        "parentId": "25",
                        "perms": "",
                        "sort": 3,
                        "url": "/storeConfigurationInformation"
                    },
                    {
                        "children": [],
                        "icon": "",
                        "id": "29",
                        "menuType": "1",
                        "name": "门店信息审核",
                        "parentId": "25",
                        "perms": "",
                        "sort": 4,
                        "url": "/storeInformationReview"
                    }
                ],
                "icon": "el-icon-s-goods",
                "id": "25",
                "menuType": "0",
                "name": "门店信息",
                "parentId": "0",
                "perms": "",
                "sort": 1,
                "url": ""
            },
            {
                "children": [],
                "icon": "el-icon-s-goods",
                "id": "30",
                "menuType": "1",
                "name": "外送商圈信息",
                "parentId": "0",
                "perms": "",
                "sort": 2,
                "url": "/areaInformation"
            },
            {
                "children": [],
                "icon": "el-icon-s-goods",
                "id": "31",
                "menuType": "1",
                "name": "外送商圈分布",
                "parentId": "0",
                "perms": "",
                "sort": 3,
                "url": "/areaDistribution"
            },
            {
                "children": [
                    {
                        "children": [],
                        "icon": "",
                        "id": "33",
                        "menuType": "1",
                        "name": "用户管理",
                        "parentId": "32",
                        "perms": "",
                        "sort": 1,
                        "url": "/user"
                    },
                    {
                        "children": [],
                        "icon": "",
                        "id": "34",
                        "menuType": "1",
                        "name": "角色管理",
                        "parentId": "32",
                        "perms": "",
                        "sort": 2,
                        "url": "/role"
                    },
                    {
                        "children": [],
                        "icon": "",
                        "id": "35",
                        "menuType": "1",
                        "name": "菜单管理",
                        "parentId": "32",
                        "perms": "",
                        "sort": 3,
                        "url": "/systemMenu"
                    }
                ],
                "icon": "el-icon-s-goods",
                "id": "32",
                "menuType": "0",
                "name": "系统管理",
                "parentId": "0",
                "perms": "",
                "sort": 4,
                "url": ""
            }
        ],
        "operatinDistrictCode": "1,2,3,4,5",
        "operationAreaCode": "1,2,3,4,5",
        "permissions": null,
        "position": "",
        "storeRole": 0,
        "token": "eyJhbGciOiJIUzI1NiJ9.eyJjdXJyZW50VGltZU1pbGxzIjoiMTYwNjkwMTMxNjAxNyIsInVzZXJOYW1lIjoidGVzdDEiLCJzdWIiOiJ0ZXN0MSIsImV4cCI6MTYwNjkwNDkxNiwiaWF0IjoxNjA2OTAxMzE2fQ.mbpqR94YoFwvRZrulrgG7PZ3gIJx5IoIcPtKFPZeWqs",
        "userId": "test1",
        "userName": "test1",
        "userType": 0
    },
    "msg": "成功"
}





function resurFun(){
    var str = ''
    const testFunc = function(list){
        list.forEach(function(row){
            if(row.menuType === '2'){
                 str += row.perms + ";"
            }
            if(row.children.length){
                // console.log(row.children)
                testFunc(row.children)
            }
        })
    }
    testFunc(testData.data.menus)
    console.log(str)
}



resurFun()
console 命令行工具 X clear

                    
>
console