|
|
|
|
@ -1,23 +1,21 @@
|
|
|
|
|
import { ElSubMenu, ElMenuItem } from 'element-plus'
|
|
|
|
|
import type { RouteMeta } from 'vue-router'
|
|
|
|
|
import { getAllParentPath, hasOneShowingChild } from '../helper'
|
|
|
|
|
import { hasOneShowingChild } from '../helper'
|
|
|
|
|
import { isUrl } from '@/utils/is'
|
|
|
|
|
import { useRenderMenuTitle } from './useRenderMenuTitle'
|
|
|
|
|
import { useDesign } from '@/hooks/web/useDesign'
|
|
|
|
|
import { pathResolve } from '@/utils/routerHelper'
|
|
|
|
|
|
|
|
|
|
export const useRenderMenuItem = (
|
|
|
|
|
allRouters: AppRouteRecordRaw[] = [],
|
|
|
|
|
// allRouters: AppRouteRecordRaw[] = [],
|
|
|
|
|
menuMode: 'vertical' | 'horizontal'
|
|
|
|
|
) => {
|
|
|
|
|
const renderMenuItem = (routers?: AppRouteRecordRaw[]) => {
|
|
|
|
|
return (routers || allRouters).map((v) => {
|
|
|
|
|
const renderMenuItem = (routers: AppRouteRecordRaw[], parentPath = '/') => {
|
|
|
|
|
return routers.map((v) => {
|
|
|
|
|
const meta = (v.meta ?? {}) as RouteMeta
|
|
|
|
|
if (!meta.hidden) {
|
|
|
|
|
const { oneShowingChild, onlyOneChild } = hasOneShowingChild(v.children, v)
|
|
|
|
|
const fullPath = isUrl(v.path)
|
|
|
|
|
? v.path
|
|
|
|
|
: getAllParentPath<AppRouteRecordRaw>(allRouters, v.path).join('/')
|
|
|
|
|
const fullPath = isUrl(v.path) ? v.path : pathResolve(parentPath, v.path) // getAllParentPath<AppRouteRecordRaw>(allRouters, v.path).join('/')
|
|
|
|
|
|
|
|
|
|
const { renderMenuTitle } = useRenderMenuTitle()
|
|
|
|
|
|
|
|
|
|
@ -46,7 +44,7 @@ export const useRenderMenuItem = (
|
|
|
|
|
>
|
|
|
|
|
{{
|
|
|
|
|
title: () => renderMenuTitle(meta),
|
|
|
|
|
default: () => renderMenuItem(v.children)
|
|
|
|
|
default: () => renderMenuItem(v.children!, fullPath)
|
|
|
|
|
}}
|
|
|
|
|
</ElSubMenu>
|
|
|
|
|
)
|
|
|
|
|
|