fix: #319
This commit is contained in:
parent
2095caaa85
commit
b6ee4e5d48
|
@ -5,7 +5,7 @@ import { useRouter } from 'vue-router'
|
|||
import { usePermissionStore } from '@/store/modules/permission'
|
||||
import { filterBreadcrumb } from './helper'
|
||||
import { filter, treeToList } from '@/utils/tree'
|
||||
import type { RouteLocationNormalizedLoaded, RouteMeta } from 'vue-router'
|
||||
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
||||
import { useI18n } from '@/hooks/web/useI18n'
|
||||
import { Icon } from '@/components/Icon'
|
||||
import { useAppStore } from '@/store/modules/app'
|
||||
|
@ -47,15 +47,15 @@ export default defineComponent({
|
|||
const breadcrumbList = treeToList<AppRouteRecordRaw[]>(unref(levelList))
|
||||
return breadcrumbList.map((v) => {
|
||||
const disabled = !v.redirect || v.redirect === 'noredirect'
|
||||
const meta = v.meta as RouteMeta
|
||||
const meta = v.meta
|
||||
return (
|
||||
<ElBreadcrumbItem to={{ path: disabled ? '' : v.path }} key={v.name}>
|
||||
{meta?.icon && breadcrumbIcon.value ? (
|
||||
<>
|
||||
<Icon icon={meta.icon} class="mr-[5px]"></Icon> {t(v?.meta?.title)}
|
||||
<Icon icon={meta.icon} class="mr-[5px]"></Icon> {t(v?.meta?.title || '')}
|
||||
</>
|
||||
) : (
|
||||
t(v?.meta?.title)
|
||||
t(v?.meta?.title || '')
|
||||
)}
|
||||
</ElBreadcrumbItem>
|
||||
)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { pathResolve } from '@/utils/routerHelper'
|
||||
import type { RouteMeta } from 'vue-router'
|
||||
|
||||
export const filterBreadcrumb = (
|
||||
routes: AppRouteRecordRaw[],
|
||||
|
@ -8,7 +7,7 @@ export const filterBreadcrumb = (
|
|||
const res: AppRouteRecordRaw[] = []
|
||||
|
||||
for (const route of routes) {
|
||||
const meta = route?.meta as RouteMeta
|
||||
const meta = route?.meta
|
||||
if (meta.hidden && !meta.canTo) {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { ElSubMenu, ElMenuItem } from 'element-plus'
|
||||
import type { RouteMeta } from 'vue-router'
|
||||
import { hasOneShowingChild } from '../helper'
|
||||
import { isUrl } from '@/utils/is'
|
||||
import { useRenderMenuTitle } from './useRenderMenuTitle'
|
||||
|
@ -14,7 +13,7 @@ export const useRenderMenuItem = (
|
|||
) => {
|
||||
const renderMenuItem = (routers: AppRouteRecordRaw[], parentPath = '/') => {
|
||||
return routers.map((v) => {
|
||||
const meta = (v.meta ?? {}) as RouteMeta
|
||||
const meta = v.meta ?? {}
|
||||
if (!meta.hidden) {
|
||||
const { oneShowingChild, onlyOneChild } = hasOneShowingChild(v.children, v)
|
||||
const fullPath = isUrl(v.path) ? v.path : pathResolve(parentPath, v.path) // getAllParentPath<AppRouteRecordRaw>(allRouters, v.path).join('/')
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import type { RouteMeta } from 'vue-router'
|
||||
import { ref, unref } from 'vue'
|
||||
import { findPath } from '@/utils/tree'
|
||||
|
||||
|
@ -21,7 +20,7 @@ export const hasOneShowingChild = (
|
|||
const onlyOneChild = ref<OnlyOneChildType>()
|
||||
|
||||
const showingChildren = children.filter((v) => {
|
||||
const meta = (v.meta ?? {}) as RouteMeta
|
||||
const meta = v.meta ?? {}
|
||||
if (meta.hidden) {
|
||||
return false
|
||||
} else {
|
||||
|
|
|
@ -173,7 +173,7 @@ export default defineComponent({
|
|||
<Icon icon={item?.meta?.icon}></Icon>
|
||||
</div>
|
||||
{!unref(showTitle) ? undefined : (
|
||||
<p class="break-words mt-5px px-2px">{t(item.meta?.title)}</p>
|
||||
<p class="break-words mt-5px px-2px">{t(item.meta?.title || '')}</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { getAllParentPath } from '@/components/Menu/src/helper'
|
||||
import type { RouteMeta } from 'vue-router'
|
||||
import { isUrl } from '@/utils/is'
|
||||
import { cloneDeep } from 'lodash-es'
|
||||
import { reactive } from 'vue'
|
||||
|
@ -12,7 +11,7 @@ export const tabPathMap = reactive<TabMapTypes>({})
|
|||
|
||||
export const initTabMap = (routes: AppRouteRecordRaw[]) => {
|
||||
for (const v of routes) {
|
||||
const meta = (v.meta ?? {}) as RouteMeta
|
||||
const meta = v.meta ?? {}
|
||||
if (!meta?.hidden) {
|
||||
tabPathMap[v.path] = []
|
||||
}
|
||||
|
@ -26,7 +25,7 @@ export const filterMenusPath = (
|
|||
const res: AppRouteRecordRaw[] = []
|
||||
for (const v of routes) {
|
||||
let data: Nullable<AppRouteRecordRaw> = null
|
||||
const meta = (v.meta ?? {}) as RouteMeta
|
||||
const meta = v.meta ?? {}
|
||||
if (!meta.hidden || meta.canTo) {
|
||||
const allParentPath = getAllParentPath<AppRouteRecordRaw>(allRoutes, v.path)
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import type { RouteMeta, RouteLocationNormalizedLoaded } from 'vue-router'
|
||||
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
||||
import { pathResolve } from '@/utils/routerHelper'
|
||||
|
||||
export const filterAffixTags = (routes: AppRouteRecordRaw[], parentPath = '') => {
|
||||
let tags: RouteLocationNormalizedLoaded[] = []
|
||||
routes.forEach((route) => {
|
||||
const meta = route.meta as RouteMeta
|
||||
const meta = route.meta ?? {}
|
||||
const tagPath = pathResolve(parentPath, route.path)
|
||||
if (meta?.affix) {
|
||||
tags.push({ ...route, path: tagPath, fullPath: tagPath } as RouteLocationNormalizedLoaded)
|
||||
|
|
|
@ -3,7 +3,6 @@ import type {
|
|||
Router,
|
||||
RouteLocationNormalized,
|
||||
RouteRecordNormalized,
|
||||
RouteMeta,
|
||||
RouteRecordRaw
|
||||
} from 'vue-router'
|
||||
import { isUrl } from '@/utils/is'
|
||||
|
@ -47,7 +46,7 @@ export const generateRoutesFn1 = (
|
|||
const res: AppRouteRecordRaw[] = []
|
||||
|
||||
for (const route of routes) {
|
||||
const meta = route.meta as RouteMeta
|
||||
const meta = route.meta ?? {}
|
||||
// skip some route
|
||||
if (meta.hidden && !meta.canTo) {
|
||||
continue
|
||||
|
|
|
@ -32,21 +32,23 @@ import { defineComponent } from 'vue'
|
|||
permission: ['edit','add', 'delete'] 设置该路由的权限
|
||||
}
|
||||
**/
|
||||
|
||||
interface RouteMetaCustom extends Record<string | number | symbol, unknown> {
|
||||
hidden?: boolean
|
||||
alwaysShow?: boolean
|
||||
title?: string
|
||||
icon?: string
|
||||
noCache?: boolean
|
||||
breadcrumb?: boolean
|
||||
affix?: boolean
|
||||
activeMenu?: string
|
||||
noTagsView?: boolean
|
||||
canTo?: boolean
|
||||
permission?: string[]
|
||||
}
|
||||
|
||||
declare module 'vue-router' {
|
||||
interface RouteMeta extends Record<string | number | symbol, unknown> {
|
||||
hidden?: boolean
|
||||
alwaysShow?: boolean
|
||||
title?: string
|
||||
icon?: string
|
||||
noCache?: boolean
|
||||
breadcrumb?: boolean
|
||||
affix?: boolean
|
||||
activeMenu?: string
|
||||
noTagsView?: boolean
|
||||
followAuth?: string
|
||||
canTo?: boolean
|
||||
permission?: string[]
|
||||
}
|
||||
interface RouteMeta extends RouteMetaCustom {}
|
||||
}
|
||||
|
||||
type Component<T = any> =
|
||||
|
@ -57,7 +59,7 @@ type Component<T = any> =
|
|||
declare global {
|
||||
declare interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
|
||||
name: string
|
||||
meta: RouteMeta
|
||||
meta: RouteMetaCustom
|
||||
component?: Component | string
|
||||
children?: AppRouteRecordRaw[]
|
||||
props?: Recordable
|
||||
|
@ -66,7 +68,7 @@ declare global {
|
|||
|
||||
declare interface AppCustomRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
|
||||
name: string
|
||||
meta: RouteMeta
|
||||
meta: RouteMetaCustom
|
||||
component: string
|
||||
path: string
|
||||
redirect: string
|
||||
|
|
Loading…
Reference in New Issue