feat: 面包屑组件增加路由编辑判断
This commit is contained in:
parent
859367b2ef
commit
f1c8bfe713
|
@ -1,14 +1,14 @@
|
|||
<template>
|
||||
<a-breadcrumb v-if="showBreadcrumb" class="z-10 mb-[-8px] mt-[8px]">
|
||||
<a-breadcrumb-item v-for="crumb of appStore.breadcrumbList" :key="crumb.name" @click="jumpTo(crumb.name)">
|
||||
{{ t(crumb.locale) }}
|
||||
{{ isEdit ? t(crumb.editLocale || crumb.locale) : t(crumb.locale) }}
|
||||
</a-breadcrumb-item>
|
||||
</a-breadcrumb>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useRouter, RouteRecordName } from 'vue-router';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useRouter, useRoute, RouteRecordName } from 'vue-router';
|
||||
import { useAppStore } from '@/store';
|
||||
import { listenerRouteChange } from '@/utils/route-listener';
|
||||
import { useI18n } from '@/hooks/useI18n';
|
||||
|
@ -16,11 +16,14 @@
|
|||
const appStore = useAppStore();
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const showBreadcrumb = computed(() => {
|
||||
const b = appStore.getCurrentTopMenu.meta?.breadcrumbs;
|
||||
return b && b.length > 0;
|
||||
});
|
||||
|
||||
const isEdit = ref(false);
|
||||
|
||||
/**
|
||||
* 监听路由变化,存储打开及选中的菜单
|
||||
*/
|
||||
|
@ -33,7 +36,14 @@
|
|||
} else if ((name as string).includes(appStore.currentTopMenu.name as string)) {
|
||||
// 顶部菜单内下钻的父子路由命名是包含关系,子路由会携带完整的父路由名称
|
||||
const currentRoute = router.currentRoute.value.matched[1].children.find((e) => e.name === name);
|
||||
appStore.setBreadcrumbList(currentRoute?.meta?.breadcrumbs);
|
||||
const currentBreads = currentRoute?.meta?.breadcrumbs;
|
||||
appStore.setBreadcrumbList(currentBreads);
|
||||
// 下钻的三级路由一版都会区分编辑添加场景,根据场景展示不同的国际化路由信息
|
||||
const editTag = currentBreads && currentBreads[currentBreads.length - 1].editTag;
|
||||
setTimeout(() => {
|
||||
// 路由异步挂载,这里使用同步或者nextTick都取不到变化后的路由参数,所以使用定时器
|
||||
isEdit.value = editTag && route.query[editTag];
|
||||
}, 0);
|
||||
} else {
|
||||
appStore.setBreadcrumbList([]);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import type { RouteRecordName } from 'vue-router';
|
||||
|
||||
export interface BreadcrumbItem {
|
||||
name: RouteRecordName;
|
||||
locale: string;
|
||||
name: RouteRecordName; // 路由名称
|
||||
locale: string; // 国际化语言单词
|
||||
editTag?: string; // 编辑标识,指路由地址参数,面包屑组件会根据此参数判断是否为编辑页面
|
||||
editLocale?: string; // 编辑国际化语言单词
|
||||
}
|
||||
|
|
|
@ -73,6 +73,8 @@ const System: AppRouteRecordRaw = {
|
|||
{
|
||||
name: 'settingSystemResourcePoolDetail',
|
||||
locale: 'menu.settings.system.resourcePoolDetail',
|
||||
editTag: 'id',
|
||||
editLocale: 'menu.settings.system.resourcePoolEdit',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue