<template>
    <el-container class="hc-layout-main">
        <el-aside class="hc-layout-aside" width="200px">
            <hc-body class="hc-layout-aside-body">
                <div class="hc-layout-aside-logo hc-flex-center h-[46px]">
                    <img :src="logoPng" alt="logo" class="w-[26px]">
                    <span class="ml-[14px] text-[18px] font-bold"> 高速公路<br>投资效益分析工具</span>
                    <hc-upload-bar />
                </div>
                <div class="hc-layout-aside-menu">
                    <MenuBar :cur="menuBarKey" :datas="menuBarData" @change="menuBarChange" />
                </div>
                <div class="hc-layout-aside-user">
                    <UserInfoBar />
                </div>
            </hc-body>
        </el-aside>
        <el-main class="hc-layout-page">
            <hc-body id="hc-main-box">
                <router-view />
            </hc-body>
        </el-main>
    </el-container>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { getMenuData } from '~src/router/routers'
import { initButtons } from '~store/app'

//logo文件
import logoPng from '~src/assets/logo/logo.png'

//初始组合式
const router = useRouter()
const useRoutes = useRoute()

//子组件
import MenuBar from './modules/MenuBar.vue'
import UserInfoBar from './modules/UserInfoBar.vue'

//菜单数据
const menuBarKey = ref(useRoutes.name)
const menuBarData = ref([])

//渲染完成
onMounted(() => {
    getMenuBarData()
    initButtons()
})

//获取菜单数据
const getMenuBarData = async () => {
    menuBarData.value = await getMenuData()
    console.log(menuBarData.value)
}

//菜单被点击
const menuBarChange = ({ code }) => {
    menuBarKey.value = code
    router.push({ name: code })
}
</script>

<style lang="scss">
@import "./index";
</style>

<style lang="scss">
@import "./index";
</style>
