面包屑修改

main
项洋 1 week ago
parent 0012583bc0
commit b9d95fc394

@ -2,7 +2,11 @@
<el-breadcrumb class="app-breadcrumb" separator="/"> <el-breadcrumb class="app-breadcrumb" separator="/">
<transition-group name="breadcrumb"> <transition-group name="breadcrumb">
<el-breadcrumb-item v-for="(item, index) in levelList" :key="item.path"> <el-breadcrumb-item v-for="(item, index) in levelList" :key="item.path">
<span v-if="item.redirect === 'noRedirect' || index == levelList.length - 1" class="no-redirect">{{ item.meta.title }}</span> <span
v-if="item.redirect === 'noRedirect' || index == levelList.length - 1"
class="no-redirect"
>{{ item.meta.title }}</span
>
<a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a> <a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a>
</el-breadcrumb-item> </el-breadcrumb-item>
</transition-group> </transition-group>
@ -10,80 +14,173 @@
</template> </template>
<script setup> <script setup>
import usePermissionStore from '@/store/modules/permission' import usePermissionStore from "@/store/modules/permission";
const route = useRoute() const route = useRoute();
const router = useRouter() const router = useRouter();
const permissionStore = usePermissionStore() const permissionStore = usePermissionStore();
const levelList = ref([]) const levelList = ref([]);
function getBreadcrumb() { function getBreadcrumb() {
// only show routes with meta.title // only show routes with meta.title
let matched = [] //
const pathNum = findPathNum(route.path) let sidebarRouters = permissionStore.sidebarRouters;
// multi-level menu let matched = route.matched.filter((item) => item.meta && item.meta.title);
if (pathNum > 2) { if (matched[0].path == "/assetsAuth") {
const reg = /\/\w+/gi // ----
const pathList = route.path.match(reg).map((item, index) => { const activeRoute = sidebarRouters.filter(
if (index !== 0) item = item.slice(1) (item) => item.path == "/assetsManage"
return item );
}) const childrenRoute = activeRoute[0].children;
getMatched(pathList, permissionStore.defaultRoutes, matched) levelList.value = [
activeRoute[0],
childrenRoute[Number(matched[0].meta.type)],
matched[0],
];
} else if (
matched[0].path == "/taskInfo" ||
matched[0].path == "/taskAudit"
) {
// ----/
const activeRoute = sidebarRouters.filter(
(item) => item.path == "/" && item.children[0].path == "task"
);
levelList.value = [activeRoute[0].children[0], matched[0]];
} else if (
matched[0].path == "/mytaskInfo" ||
matched[0].path == "/mytaskAudit"
) {
// ----/
const activeRoute = sidebarRouters.filter(
(item) => item.path == "/" && item.children[0].path == "myTask"
);
levelList.value = [activeRoute[0].children[0], matched[0]];
} else if (matched[0].path == "/myAssetsAuth") {
// ----
const activeRoute = sidebarRouters.filter(
(item) => item.path == "/myAssets"
);
const childrenRoute = activeRoute[0].children;
levelList.value = [
activeRoute[0],
childrenRoute[Number(matched[0].meta.type)],
matched[0],
];
} else if (matched[0].path == "/taskAuditInfo") {
// ------
const activeRoute = sidebarRouters.filter(
(item) => item.path == "/" && item.children[0].path == "task"
);
const route = sidebarRouters.filter((item) => item.path == "");
const twoActiveRoute = route[0].children.filter(
(item) => item.path == "taskInfo"
);
levelList.value = [
activeRoute[0].children[0],
twoActiveRoute[0],
matched[0],
];
} else if (matched[0].path == "/taskAuditInfolishichakan") {
// ------
const activeRoute = sidebarRouters.filter(
(item) => item.path == "/" && item.children[0].path == "task"
);
const route = sidebarRouters.filter((item) => item.path == "");
const twoActiveRoute = route[0].children.filter(
(item) => item.path == "taskInfo"
);
levelList.value = [
activeRoute[0].children[0],
twoActiveRoute[0],
matched[0],
];
} else if (matched[0].path == "/mytaskAuditInfo") {
// ------
const activeRoute = sidebarRouters.filter(
(item) => item.path == "/" && item.children[0].path == "myTask"
);
const route = sidebarRouters.filter((item) => item.path == "");
const twoActiveRoute = route[0].children.filter(
(item) => item.path == "mytaskInfo"
);
levelList.value = [
activeRoute[0].children[0],
twoActiveRoute[0],
matched[0],
];
} else if (matched[0].path == "/unitAuth") {
// ----//
const activeRoute = sidebarRouters.filter(
(item) => item.path == "/" && item.children[0].path == "unit"
);
levelList.value = [activeRoute[0].children[0], matched[0]];
} else if (matched[0].path == "/assetsAuthRecord") {
// ----/
const activeRoute = sidebarRouters.filter(
(item) => item.path == "/" && item.children[0].path == "assetRecord"
);
levelList.value = [activeRoute[0].children[0], matched[0]];
} else if (matched[0].path == "/unitAssetsAuth") {
// ----/
const activeRoute = sidebarRouters.filter(
(item) => item.path == "/" && item.children[0].path == "unitFill"
);
levelList.value = [activeRoute[0].children[0], matched[0]];
} else { } else {
matched = route.matched.filter((item) => item.meta && item.meta.title) levelList.value = matched.filter(
(item) => item.meta && item.meta.title && item.meta.breadcrumb !== false
);
} }
// };
if (!isDashboard(matched[0])) {
matched = [{ path: "/index", meta: { title: "首页" } }].concat(matched)
}
levelList.value = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
}
function findPathNum(str, char = "/") { function findPathNum(str, char = "/") {
let index = str.indexOf(char) let index = str.indexOf(char);
let num = 0 let num = 0;
while (index !== -1) { while (index !== -1) {
num++ num++;
index = str.indexOf(char, index + 1) index = str.indexOf(char, index + 1);
} }
return num return num;
} }
function getMatched(pathList, routeList, matched) { function getMatched(pathList, routeList, matched) {
let data = routeList.find(item => item.path == pathList[0] || (item.name += '').toLowerCase() == pathList[0]) let data = routeList.find(
(item) =>
item.path == pathList[0] || (item.name += "").toLowerCase() == pathList[0]
);
if (data) { if (data) {
matched.push(data) matched.push(data);
if (data.children && pathList.length) { if (data.children && pathList.length) {
pathList.shift() pathList.shift();
getMatched(pathList, data.children, matched) getMatched(pathList, data.children, matched);
} }
} }
} }
function isDashboard(route) { function isDashboard(route) {
const name = route && route.name const name = route && route.name;
if (!name) { if (!name) {
return false return false;
} }
return name.trim() === 'Index' return name.trim() === "Index";
} }
function handleLink(item) { function handleLink(item) {
const { redirect, path } = item const { redirect, path } = item;
if (redirect) { if (redirect) {
router.push(redirect) router.push(redirect);
return return;
} }
router.push(path) router.push(path);
} }
watchEffect(() => { watchEffect(() => {
// if you go to the redirect page, do not update the breadcrumbs // if you go to the redirect page, do not update the breadcrumbs
if (route.path.startsWith('/redirect/')) { if (route.path.startsWith("/redirect/")) {
return return;
} }
getBreadcrumb() getBreadcrumb();
}) });
getBreadcrumb() getBreadcrumb();
</script> </script>
<style lang='scss' scoped> <style lang="scss" scoped>
.app-breadcrumb.el-breadcrumb { .app-breadcrumb.el-breadcrumb {
display: inline-block; display: inline-block;
font-size: 14px; font-size: 14px;
@ -95,4 +192,4 @@ getBreadcrumb()
cursor: text; cursor: text;
} }
} }
</style> </style>

@ -5,7 +5,7 @@
<div :class="{ hasTagsView: needTagsView, sidebarHide: sidebar.hide }" class="main-container"> <div :class="{ hasTagsView: needTagsView, sidebarHide: sidebar.hide }" class="main-container">
<div :class="{ 'fixed-header': fixedHeader }"> <div :class="{ 'fixed-header': fixedHeader }">
<navbar @setLayout="setLayout" /> <navbar @setLayout="setLayout" />
<tags-view v-if="needTagsView" /> <!-- <tags-view v-if="needTagsView" /> -->
</div> </div>
<app-main /> <app-main />
<settings ref="settingRef" /> <settings ref="settingRef" />

@ -61,12 +61,13 @@ export const constantRoutes = [
path: '', path: '',
component: Layout, component: Layout,
redirect: '/index', redirect: '/index',
hidden: true,
children: [ children: [
{ {
path: '/index', path: '/index',
component: () => import('@/views/index'), component: () => import('@/views/index'),
name: 'Index', name: 'Index',
meta: { title: '首页', icon: 'dashboard', affix: true } meta: { title: '首页', icon: 'dashboard', affix: true, breadcrumb: false }
} }
] ]
}, },

Loading…
Cancel
Save