Skip to content

Commit

Permalink
fix: #319
Browse files Browse the repository at this point in the history
  • Loading branch information
kailong321200875 committed Aug 25, 2023
1 parent 2095caa commit b6ee4e5
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 34 deletions.
8 changes: 4 additions & 4 deletions src/components/Breadcrumb/src/Breadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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>
)
Expand Down
3 changes: 1 addition & 2 deletions src/components/Breadcrumb/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { pathResolve } from '@/utils/routerHelper'
import type { RouteMeta } from 'vue-router'

export const filterBreadcrumb = (
routes: AppRouteRecordRaw[],
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/Menu/src/components/useRenderMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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('/')
Expand Down
3 changes: 1 addition & 2 deletions src/components/Menu/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { RouteMeta } from 'vue-router'
import { ref, unref } from 'vue'
import { findPath } from '@/utils/tree'

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/components/TabMenu/src/TabMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
)
Expand Down
5 changes: 2 additions & 3 deletions src/components/TabMenu/src/helper.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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] = []
}
Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/components/TagsView/src/helper.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/utils/routerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
Router,
RouteLocationNormalized,
RouteRecordNormalized,
RouteMeta,
RouteRecordRaw
} from 'vue-router'
import { isUrl } from '@/utils/is'
Expand Down Expand Up @@ -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
Expand Down
34 changes: 18 additions & 16 deletions types/router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> =
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b6ee4e5

Please sign in to comment.