SOURCE

const res = {
	"code": 200,
	"msg": "succ",
	"data": {
		"id": 3,
		"groups": "其他",
		"name": "商家首页 - 默认",
		"page_id": "xgaugooilxg7",
		"detail": {
			"boxStyle": {

			},
			"component": "page",
			"slots": {
				"nav": {
					"boxStyle": {

					},
					"component": "store-home-nav",
					"slots": {
						"favorite": {
							"boxStyle": {

							},
							"component": "favorite",
							"flag": "favorite",
							"moduleBuildId": 65,
							"name": "商家首页-收藏",
							"rank": 10,
							"config": {
								"collectionColor": "",
								"collectionStyle": {

								}
							}
						}
					},
					"flag": "storeHomeNav",
					"moduleBuildId": 64,
					"name": "商家首页-nav",
					"rank": 10,
					"config": {

					}
				},
				"modules": [{
						"boxStyle": {

						},
						"component": "share-info",
						"flag": "shareInfo",
						"moduleBuildId": 13,
						"name": "分享信息",
						"rank": 1,
						"config": {
							"pathShare": "/GDLPKTFLUN7C/3qlr3vowqajd/index?storeId={storeId}&from=share",
							"shareCover": "https://images.wosaimg.com/eb/fc347b178aaf6798fdd3e3a2160918b2e47f1b.jpeg",
							"title": "欢迎使用收钱吧"
						}
					},
					{
						"boxStyle": {

						},
						"component": "cover",
						"flag": "cover",
						"moduleBuildId": 25,
						"name": "头图",
						"rank": 2,
						"config": {
							"cover": "https://images.wosaimg.com/0c/11cf485f115787eb0b6d78e388505ec1c6cc84.webp"
						}
					},
					{
						"boxStyle": {
							"margin": "-75px 12px 0px"
						},
						"component": "basic",
						"flag": "storeInfo",
						"moduleBuildId": 26,
						"name": "商家首页-门店信息",
						"rank": 20,
						"config": {
							"storeBasicAddressCheckCoverStyle": {
								"bottom": 0,
								"width": "46rpx",
								"position": "absolute",
								"height": "76rpx"
							},
							"showStoreBasicAddressCheck": true,
							"themeName": "default",
							"storeBasicAddressCheckCoverUrl": "https://marketing-static.shouqianba.com/themes/default/icon_store_basic_check_address.webp",
							"storeBasicStyle": {

							},
							"hideStoreBasicIcon": false,
							"storeBasicAddressCheckStyle": {
								"position": "relative"
							},
							"storeBasicAddressClass": "split-line-right"
						}
					},
					{
						"boxStyle": {
							"margin": "10px 12px 0px"
						},
						"component": "service-list",
						"flag": "serviceList",
						"moduleBuildId": 27,
						"name": "商家首页-服务列表",
						"rank": 30,
						"config": {
							"servicePayOrderSmallCoverUrl": "https://marketing-static.shouqianba.com/themes/default/service_pay_order_small.webp",
							"themeName": "default",
							"serviceSubscribeOrderCoverUrl": "https://marketing-static.shouqianba.com/themes/default/service_subscribe_order.webp",
							"serviceTakeOutOrderCoverUrl": "https://marketing-static.shouqianba.com/themes/default/service_take_out_order.webp",
							"servicePayOrderCoverUrl": "https://marketing-static.shouqianba.com/themes/default/service_pay_order.webp",
							"servicePreOrderCoverUrl": "https://marketing-static.shouqianba.com/themes/default/service_pre_order.webp",
							"servicePreOrderSmallCoverUrl": "https://marketing-static.shouqianba.com/themes/default/service_pre_order_small.webp"
						}
					},
					{
						"boxStyle": {
							"margin": "10px 12px 0"
						},
						"component": "store-member-info-card",
						"flag": "storeMemberInfoCard",
						"moduleBuildId": 46,
						"name": "商家首页-营销-store-member-info-card",
						"rank": 40,
						"config": {
							"storeMemberInfoCard": ".memberCard{background:#fff}.themeColor{color:#000}.subColor{color:#666}"
						}
					},
					{
						"boxStyle": {
							"margin": "10px 12px 0"
						},
						"component": "store-activities",
						"flag": "storeActivities",
						"moduleBuildId": 48,
						"name": "商家首页-营销-storedActivity",
						"rank": 50,
						"config": {
							"storeActivities": {
								"storedActivity": ".themeColor{color:#f13c2b;}.singleWrapper{width:702rpx;margin-bottom:20rpx;margin-right:auto;margin-left:auto;background-color:#fff;box-shadow:0 2rpx 8rpx 0 rgba(181,181,181,0.14);border-radius:16rpx;}.title{padding:28rpx 30rpx 20rpx 30rpx;color:#000;font-size:34rpx;font-weight:600;line-height:48rpx;}.singleActivityPrice{padding-right:8rpx;padding-left:8rpx;font-weight:bold;line-height:48rpx;font-family:Lato-Bold,Lato;font-size:48rpx;}.singleActivityWrapper{padding-right:30rpx;padding-bottom:40rpx;padding-left:30rpx;}.singleActivity{position:relative;display:flex;align-items:center;justify-content:space-between;height:160rpx;padding-left:30rpx;padding-right:30rpx;box-shadow:0 3rpx 8rpx 0 rgba(234,175,125,0.16);border-radius:12rpx;box-sizing:border-box;background-image:url('https://images.wosaimg.com/e7/9b96a40e40d7e2360330519ec95817f0e9d8bd.png');background-size:cover;background-repeat:no-repeat;}.singleActivityPriceWrapper{display:flex;align-items:center;}.singleActivityPriceRecharge{display:flex;align-items:flex-end;color:#000;font-weight:500;line-height:28rpx;font-size:24rpx;}.singleActivityPriceDiscount{display:flex;align-items:flex-end;margin-left:24rpx;font-weight:500;line-height:28rpx;font-size:24rpx;}.singleActivityPriceDesc{padding-bottom:3px;}.singleActivityText{display:flex;flex-direction:column;align-items:center;flex-wrap:nowrap;width:30rpx;color:#fff;line-height:32rpx;font-weight:500;font-size:26rpx;}.recommendLeftIcon{position:absolute;top:0;left:0;width:64rpx;height:30rpx;background-image:url('https://images.wosaimg.com/d6/9ecb75dedbb2bd078fe1e6a33b193771c45bdc.png');background-repeat:no-repeat;background-size:cover;}.recommendRightIcon{position:absolute;top:0;right:0;width:64rpx;height:30rpx;background-image:url('https://images.wosaimg.com/2b/cb8b381228f778325d85adab6426ba74d16462.png');background-repeat:no-repeat;background-size:cover;}.wrapper{width:702rpx;margin-bottom:20rpx;margin-right:auto;margin-left:auto;background-color:#fff;box-shadow:0 2rpx 8rpx 0 rgba(181,181,181,0.14);border-radius:16rpx;}.activityScroll{white-space:nowrap;}.activityWrapper{padding-left:30rpx;padding-bottom:40rpx;}.firstActivityGap{display:none;}.activityItem{position:relative;display:inline-flex;align-items:center;justify-content:space-between;flex-direction:column;width:198rpx;height:189rpx;margin-right:20rpx;vertical-align:top;background-image:url('https://images.wosaimg.com/2b/30bf882f1150f232cfa6d507e6dff6f06aa5ee.png');background-size:cover;background-repeat:no-repeat;box-sizing:border-box;}.activityPriceWrapper{padding-top:36rpx;text-align:center;}.activityPriceRecharge{display:flex;align-items:flex-end;justify-content:center;color:#000;font-weight:500;line-height:28rpx;font-size:24rpx;}.activityPriceRechargeContent{padding-right:4rpx;padding-bottom:2rpx;padding-left:4rpx;font-weight:bold;line-height:28rpx;font-size:42rpx;font-family:Lato-Bold,Lato;}.activityPriceDiscount{display:flex;align-items:flex-end;justify-content:center;margin-top:17rpx;color:#000;font-weight:500;line-height:28rpx;font-size:20rpx;}.activityPriceDiscountContent{padding-right:4rpx;padding-bottom:3rpx;padding-left:4rpx;font-weight:bold;line-height:28rpx;font-size:30rpx;font-family:Lato-Bold,Lato;}.activityText{padding-top:9rpx;padding-bottom:11rpx;text-align:center;color:#fff;font-weight:500;line-height:37rpx;font-size:26rpx;}",
								"couponActivity": ".themeColor{color:#f13c2b;}.singleWrapper{width:702rpx;margin-bottom:20rpx;margin-right:auto;margin-left:auto;background-color:#fff;box-shadow:0 2rpx 8rpx 0 rgba(181,181,181,0.14);border-radius:16rpx;}.title{padding:28rpx 30rpx 20rpx 30rpx;color:#000;font-size:34rpx;font-weight:600;line-height:48rpx;}.singleActivityWrapper{padding-right:30rpx;padding-bottom:40rpx;padding-left:30rpx;}.singleActivity{position:relative;height:170rpx;box-sizing:border-box;background-image:url('https://images.wosaimg.com/c7/66e048dd93034485d5fad35bd651f6b75951a7.png');background-size:cover;background-repeat:no-repeat;filter:drop-shadow(0 3rpx 8rpx rgba(255,141,80,0.2));}.singleActivityContent{display:flex;align-items:center;height:100%;}.singleActivityContentReceived{}.singleActivityReceivedIcon{position:absolute;top:0;right:0;width:104rpx;height:96rpx;background-size:cover;background-repeat:no-repeat;background-image:url('https://images.wosaimg.com/cb/fe904bdc40eacdbc57f7645da13927e350cb3e.png');}.singleActivityName{position:absolute;top:0;left:0;padding:3rpx 14rpx 3rpx 11rpx;color:#fff;font-weight:500;line-height:28rpx;font-size:20rpx;background-image:linear-gradient(298deg,#f13c2b 0%,#ff786c 100%);border-top-left-radius:16rpx;border-bottom-right-radius:16rpx;}.singleActivityLeft{display:flex;flex-direction:column;align-items:center;justify-content:center;width:185rpx;height:100%;}.singleActivityDiscountWrapper{display:flex;align-items:flex-end;}.singleActivityDiscountIcon{font-weight:600;line-height:45rpx;font-size:32rpx;}.singleActivityDiscountPrice{padding-right:4rpx;padding-bottom:3rpx;line-height:60rpx;font-size:68rpx;font-weight:bold;font-family:Lato-Bold,Lato;}.singleActivityDiscountDesc{margin-top:5rpx;font-weight:400;line-height:28rpx;font-size:20rpx;}.singleActivityRight{margin-left:41rpx;}.singleActivityRightTitle{color:#000;font-weight:500;line-height:45rpx;font-size:32rpx;}.singleActivityRightTitleReceived{}.singleActivityRightSubTitle{margin-top:4rpx;color:#999;font-weight:400;line-height:33rpx;font-size:24rpx;}.wrapper{width:702rpx;margin-bottom:20rpx;margin-right:auto;margin-left:auto;background-color:#fff;box-shadow:0 2rpx 8rpx 0 rgba(181,181,181,0.14);border-radius:16rpx;}.activityWrapper{padding-left:30rpx;padding-bottom:40rpx;}.activityScroll{white-space:nowrap;}.firstActivityGap{display:none;}.activityItemWrapper{position:relative;display:inline-block;width:190rpx;height:210rpx;vertical-align:top;}.activityItem{display:inline-flex;flex-direction:column;align-items:center;width:100%;height:100%;padding-top:24rpx;vertical-align:top;background-image:url('https://images.wosaimg.com/05/2c31b4b27cc772185ad83b7f0ec35477da6efc.png');background-size:cover;background-repeat:no-repeat;box-sizing:border-box;overflow:hidden;}.activityReceivedIcon{position:absolute;top:0;right:0;z-index:1;width:59rpx;height:61rpx;background-image:url('https://images.wosaimg.com/66/d68c23c11e8f6e9bdd9b8dac072f2c045932b3.png');background-size:cover;background-repeat:no-repeat;}.activityItemWithMarginRight{margin-right:36rpx;}.activityName{padding:4rpx 18rpx;font-weight:400;color:#fff;line-height:30rpx;font-size:22rpx;background-color:#f13c2b;border-radius:19rpx;}.activityDiscount{display:flex;align-items:flex-end;margin-top:16rpx;color:#f13c2b;}.activityDiscountPrice{padding-right:1rpx;font-weight:bold;line-height:60rpx;font-size:68rpx;font-family:Lato-Bold,Lato;}.activityDiscountIcon{font-weight:600;line-height:30rpx;font-size:22rpx;}.activityDiscountDesc{margin-top:29rpx;font-weight:400;color:#f13c2b;line-height:30rpx;font-size:22rpx;}.activityDiscountDescReceived{}",
								"combine": ".themecolor{}.wrapper{width:702rpx;margin-bottom:20rpx;margin-right:auto;margin-left:auto;background-color:#fff;box-shadow:0 2rpx 8rpx 0 rgba(181,181,181,0.14);border-radius:16rpx;}.title{padding:28rpx 30rpx 20rpx 30rpx;color:#000;font-size:34rpx;font-weight:600;line-height:48rpx;}.activityWrapper{padding-left:30rpx;padding-right:30rpx;padding-bottom:40rpx;}.activity{display:flex;align-items:center;height:166rpx;padding-right:30rpx;padding-left:30rpx;border:2rpx solid #ffc5a5;background-color:#fff5f0;box-shadow:0 3rpx 8rpx 0 rgba(255,141,80,0.2);border-radius:12rpx;box-sizing:border-box;}.activityPriceDiscountWrapper{display:flex;flex-shrink:0;flex-direction:column;align-items:center;justify-content:center;width:158rpx;height:124rpx;padding-right:34rpx;box-sizing:border-box;background-size:cover;background-repeat:no-repeat;background-image:url('https://images.wosaimg.com/52/4760c8403979f13b527d926fe38c92cfa09a8f.png');}.activityPriceDiscount{display:flex;align-items:flex-end;}.activityPriceDiscountIcon{padding-bottom:2rpx;color:#fff;font-weight:500;line-height:26rpx;font-size:26rpx;}.activityPriceDiscountContent{margin-left:4rpx;color:#fff;font-weight:bold;line-height:48rpx;font-size:48rpx;font-family:Lato-Bold,Lato;}.activityPriceDiscountDesc{margin-top:7rpx;color:#fff;font-weight:400;line-height:24rpx;font-size:22rpx;}.activityPriceWrapper{flex-grow:1;margin-left:30rpx;}.activityPriceNumAndDiscount{display:flex;align-items:center;color:#000;font-weight:500;line-height:45rpx;font-size:32rpx;}.activityPriceNum{margin-right:12rpx;padding:1rpx 10rpx;color:#262626;font-weight:500;line-height:30rpx;font-size:22rpx;background-image:linear-gradient(287deg,#ffc116 0%,#ffd54d 100%);border-radius:6rpx;}.activityPrice{display:flex;align-items:flex-end;margin-top:3rpx;color:#f13c2b;}.activityPriceIcon{padding-bottom:3rpx;line-height:37rpx;font-size:26rpx;}.activityPriceContent{padding-left:4rpx;font-weight:bold;line-height:55rpx;font-size:46rpx;font-family:Lato-Bold,Lato;}.activityButton{flex-shrink:0;padding:6rpx 28rpx;color:#fff;font-weight:600;line-height:40rpx;font-size:28rpx;background-image:linear-gradient(299deg,#f34734 0%,#fa7d64 100%);border-radius:30rpx;}"
							}
						}
					},
					{
						"boxStyle": {
							"margin": "10px 12px 0"
						},
						"component": "store-member-card",
						"flag": "storeMemberCard",
						"moduleBuildId": 51,
						"name": "商家首页-营销-store-member-card",
						"rank": 80,
						"config": {
							"storeMemberCard": ".storeMemberCard{}.storeMemberCardWrapper{padding:30rpx 24rpx;background:#fff;border-radius:12rpx;box-shadow:0 2rpx 8rpx 0 rgba(181,181,181,0.14);}.headerName{color:#000;}.headerMore{color:#000;}.membershipCard{background-image:url('https://images.wosaimg.com/fc/dc3d204cfa7475bcfc844a0ce93d8d0ba4da58.png');}.membershipCardIcon{background-image:url('https://images.wosaimg.com/69/e58660d93845e9bccb896c33e72baa17dece34.png');}.membershipCardName{color:#e8bd77;}.membershipCardNameTips{color:#c49954;}.membershipCardBalance{color:#e8bd77;}.membershipCardUnit{color:#e8bd77;}.membershipCardButton{background:linear-gradient(58deg,#daad81 0%,#f2e0ce 100%);color:#43362a;}.storedCard{background-image:url('https://images.wosaimg.com/fc/dc3d204cfa7475bcfc844a0ce93d8d0ba4da58.png');}.storedCardIcon{background-image:url('https://images.wosaimg.com/69/e58660d93845e9bccb896c33e72baa17dece34.png');}.storedCardName{color:#e8bd77;}.storedCardNameTips{color:#c49954;}.storedCardBalance{color:#e8bd77;}.storedCardBalanceUnit{color:#e8bd77;}.storedCardButton{background:linear-gradient(58deg,#daad81 0%,#f2e0ce 100%);color:#43362a;}"
						}
					}
				]
			},
			"moduleBuildId": 12,
			"name": "页面",
			"rank": 1,
			"config": {

			}
		},
	}
}

const detail = res.data.detail;



let index = 0

function indeed(obj,tree = []){
    const {slots} = obj;
    if(!slots) return;
    for(let key in slots){
        if(slots[key] instanceof Array){
            let element = slots[key];
             
            const child = []
            element.forEach(item=>{
                const { slots,name } = item;
                let children = [];
                if(slots){
                    children = indeed(item)
                }
                child.push({
                    title: name,
                    key:index++,
                    isLeaf: children.length === 0,
                    children: children
                })
            })
            tree.push({
                title: key,
                key:index++,
                children:child
            })
        }else{
             let element = slots[key];
             const {name} = element;
             let children = [];
             if(element.slots){
                children = indeed(element)
            }
            tree.push({
                title: name,
                key:index++,
                isLeaf: children.length === 0,
                children,
            })
        }
    }
    return tree;
}

function result(){
    return [{
        title:'页面',
        key: index++,
        children: indeed(detail)
    }]
}
console.log(result())
console 命令行工具 X clear

                    
>
console