|
@@ -15,14 +15,29 @@
|
|
|
theme="dark"
|
|
|
mode="inline"
|
|
|
>
|
|
|
- <a-menu-item
|
|
|
+ <component
|
|
|
+ :is="menu.children?.length ? SubMenu: MenuItem"
|
|
|
v-for="menu in menus"
|
|
|
:key="menu.name"
|
|
|
- @click="toPageHandle(menu.name)"
|
|
|
+ :title="menu.meta?.title || menu.name"
|
|
|
+ @click="menu.children?.length ? null :toPageHandle(menu.name)"
|
|
|
>
|
|
|
- <user-outlined />
|
|
|
- <span class="nav-text">{{ menu.name }}</span>
|
|
|
- </a-menu-item>
|
|
|
+ <template #icon>
|
|
|
+ <component :is="getIcon(menu.meta?.icon)" />
|
|
|
+ </template>
|
|
|
+ <template v-if="menu.children?.length">
|
|
|
+ <MenuItem
|
|
|
+ v-for="child in menu.children"
|
|
|
+ :key="child.name"
|
|
|
+ @click="toPageHandle(child.name)"
|
|
|
+ >
|
|
|
+ <span class="nav-text">{{ child.meta?.title || child.name }}</span>
|
|
|
+ </MenuItem>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <span class="nav-text">{{ menu.meta?.title || menu.name }}</span>
|
|
|
+ </template>
|
|
|
+ </component>
|
|
|
</a-menu>
|
|
|
</a-layout-sider>
|
|
|
</template>
|
|
@@ -30,7 +45,9 @@
|
|
|
import { ref, computed, watch, toRef } from 'vue';
|
|
|
import { useRouter, useRoute, onBeforeRouteUpdate } from 'vue-router';
|
|
|
import { AppStore } from '@/store/modules/app';
|
|
|
- import type { RouteRecordName, RouteLocationNormalized } from 'vue-router'
|
|
|
+ import type { RouteRecordName, RouteLocationNormalized, RouteMeta } from 'vue-router'
|
|
|
+ import { MenuItem, SubMenu } from 'ant-design-vue';
|
|
|
+ import * as Icon from '@ant-design/icons-vue';
|
|
|
|
|
|
const router = useRouter()
|
|
|
const route = useRoute()
|
|
@@ -40,14 +57,10 @@
|
|
|
const matchRouteHandle = (to: RouteLocationNormalized) => {
|
|
|
menus.value.forEach(el => {
|
|
|
if (el.name === to.name) {
|
|
|
- console.log(el, to);
|
|
|
selectedKeys.value = [to.name as string]
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
- // onBeforeRouteUpdate(to => {
|
|
|
- // matchRouteHandle(to)
|
|
|
- // })
|
|
|
matchRouteHandle(route)
|
|
|
const toHomeHandle = () => {
|
|
|
router.push('/')
|
|
@@ -55,6 +68,10 @@
|
|
|
const toPageHandle = (name: RouteRecordName | undefined) => {
|
|
|
router.push({ name })
|
|
|
}
|
|
|
+ const getIcon = (name: unknown) => {
|
|
|
+ // 这里将字符串假定为UserOutlined来通过Icon的类型校验
|
|
|
+ return Icon[name as 'UserOutlined'] || 'AppstoreOutlined'
|
|
|
+ }
|
|
|
</script>
|
|
|
|
|
|
<style lang="less" scoped>
|