feat: 面包屑组件增加路由编辑判断

This commit is contained in:
baiqi 2023-06-28 17:11:38 +08:00 committed by fit2-zhao
parent 859367b2ef
commit f1c8bfe713
3 changed files with 20 additions and 6 deletions

View File

@ -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([]);
}

View File

@ -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; // 编辑国际化语言单词
}

View File

@ -73,6 +73,8 @@ const System: AppRouteRecordRaw = {
{
name: 'settingSystemResourcePoolDetail',
locale: 'menu.settings.system.resourcePoolDetail',
editTag: 'id',
editLocale: 'menu.settings.system.resourcePoolEdit',
},
],
},