feat: useMenuData

This commit is contained in:
FairyEver 2022-02-18 21:40:30 +08:00
parent 75f9e24536
commit 83824a5422
2 changed files with 28 additions and 10 deletions

View File

@ -1,16 +1,16 @@
<template>
<a-menu-item :key="getMenuId(menu)">
<template #icon>
<d2-icon :name="getMenuIcon(menu)"/>
<a-menu-item :key="menuId">
<template v-if="menuIcon" #icon>
<d2-icon :name="menuIcon"/>
</template>
{{ getMenuTitle(menu) }}
{{ menuTitle }}
</a-menu-item>
</template>
<script>
import { makeNameByUrl } from 'd2/utils/framework/component.js'
import { defineComponent } from 'vue'
import { getMenuId, getMenuTitle, getMenuIcon } from 'd2/utils/framework/menu.js'
import { useMenuData } from 'd2/use/menu.js'
export default defineComponent({
name: makeNameByUrl(import.meta.url),
@ -20,11 +20,15 @@ export default defineComponent({
required: true
}
},
setup () {
setup (props) {
const { menu } = props
const { menuId, menuTitle, menuIcon } = useMenuData(menu)
return {
getMenuId,
getMenuTitle,
getMenuIcon
menuId,
menuTitle,
menuIcon
}
}
})

View File

@ -1,13 +1,27 @@
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { getMenuId, getMenuTitle, getMenuIcon, getMenuUrl } from 'd2/utils/framework/menu.js'
export function useMenu () {
const router = useRouter()
function navigateByMenu (menu) {
router.push(menu.url)
router.push(getMenuUrl(menu.url))
}
return {
navigateByMenu
}
}
export function useMenuData (menu) {
const menuId = computed(() => getMenuId(menu))
const menuTitle = computed(() => getMenuTitle(menu))
const menuIcon = computed(() => getMenuIcon(menu))
return {
menuId,
menuTitle,
menuIcon
}
}