<template>
    <template v-for="(item, index) in dataList" :key="index">
        <el-sub-menu :index="item.resourceCode" :show-timeout="100" :hide-timeout="100" v-if="item.children?.length">
            <template #title>
                <!--如果没有图标，用标题第一个字代替-->
                <template v-if="item.icon">
                    <app-icon class="menu-icon" :icon="item.icon" />
                    <span>{{ $t('routes.'+item.resourceCode) }}</span>
                </template>
                <template v-else>
                    <i class="menu-icon menu-icon--text">{{ $t('routes.'+item.resourceCode).slice(0, 1) }}</i>
                    <span>{{ $t('routes.'+item.resourceCode).slice(1) }}</span>
                </template>
            </template>
            <!--如果存在子级，递归组件自身-->
            <app-submenu :data-list="item.children" />
        </el-sub-menu>
        <el-menu-item :index="item.resourceCode" v-else>
            <app-icon class="menu-icon" :icon="item.icon" v-if="item.icon" />
            <span>{{ $t('routes.'+item.resourceCode) }}</span>
        </el-menu-item>
    </template>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue'
import AppIcon from '@pc/components/base/icon/index.vue'

export default defineComponent({
    name: 'AppSubmenu',
    components: {
        AppIcon
    },
    props: {
        dataList: {
            type: Array as PropType<Model.MenusRsp[]>,
            required: true,
        },
    },
})

</script>