<template>
    <el-scrollbar>
        <el-menu :default-active="curKey" class="hc-aside-menu" unique-opened text-color="#fff">
            <MenuItem :cur="curKey" :datas="datas" @change="MenuClick" />
        </el-menu>
    </el-scrollbar>
</template>

<script setup>
import { ref, watch } from 'vue'
import MenuItem from './MenuItem.vue'

const props = defineProps({
    datas: {
        type: Array,
        default: () => ([]),
    },
    cur: {
        type: String,
        default: 'home-index',
    },
})

//事件
const emit = defineEmits(['change'])

//监听
const curKey = ref(props.cur)
watch(() => props.cur, (cur) => {
    curKey.value = cur
})

//处理菜单数据
const setMenuItem = async (item) => {
    curKey.value = item?.code || ''
    emit('change', item)
}

//菜单被点击
const MenuClick = (item) => {
    setMenuItem(item)
}
</script>
