Browse Source

添加面包屑显示

admin_version1.0_2025_06_26
zq 4 weeks ago
parent
commit
f8b34dee9e
  1. 6
      src/App.vue
  2. BIN
      src/assets/separator.png
  3. 166
      src/components/Breadcrumb.vue
  4. 77
      src/components/Breadcrumb1.vue
  5. 2
      src/components/SetLeftMenu.vue
  6. 51
      src/router/index.js
  7. 24
      src/store/index.js
  8. 8
      src/views/DoctorInformation.vue
  9. 42
      src/views/HomeView.vue
  10. 10
      src/views/HosInformation.vue

6
src/App.vue

@ -9,7 +9,7 @@
</el-header>
<el-container :class="(showHeader ? 'short-container' : '')">
<SliderMenu v-if="showSidebar" :menuData="slidermenu" :customize="customize"></SliderMenu>
<el-container>
<el-container class="main-right-content">
<!-- 面包屑导航 -->
<Breadcrumb />
<el-main class="app-content">
@ -87,6 +87,10 @@ export default {
.short-container {
height: calc(100vh - 62px);
}
.main-right-content{
display: flex;
flex-direction: column;
}
::v-deep .el-container .el-main {
// padding: 12px;

BIN
src/assets/separator.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

166
src/components/Breadcrumb.vue

@ -1,77 +1,101 @@
<template>
<el-breadcrumb v-if="showBreadcrumb" separator="/">
<el-breadcrumb-item
v-for="(item, index) in breadcrumbList"
:key="index"
>
<i v-if="item.icon" :class="item.icon"></i>
<span>{{ item.title }}</span>
</el-breadcrumb-item>
</el-breadcrumb>
</template>
<script>
export default {
data() {
return {
breadcrumbList: [],
showBreadcrumb: false //
};
},
watch: {
$route() {
this.updateBreadcrumb();
}
},
mounted() {
this.updateBreadcrumb();
},
methods: {
updateBreadcrumb() {
const currentPath = this.$route.path;
//
if(!this.$parent.menuData)return
const isSubPage = this.isSubPage(currentPath);
this.showBreadcrumb = isSubPage;
if (isSubPage) {
this.breadcrumbList = this.getBreadcrumbList(currentPath);
<div v-if="breadcrumbs.length > 0" class="breadcrumb-container">
<nav>
<ol class="breadcrumb">
<li
v-for="(item, index) in breadcrumbs"
:key="index"
class="breadcrumb-item"
:class="{ active: index === breadcrumbs.length - 1 }"
>
<template v-if="index !== breadcrumbs.length - 1">
<router-link :to="item.path">{{ item.title }}</router-link>
<!-- <span class="separator">/</span> -->
<img class="separator" src="@/assets/separator.png" alt="">
</template>
<template v-else>
<span>{{ item.title }}</span>
</template>
</li>
</ol>
</nav>
</div>
</template>
<script>
export default {
name: 'Breadcrumb',
computed: {
breadcrumbs() {
if (this.$route.meta.hideBreadcrumb) return []
const crumbs = []
let currentRoute = this.$route
//
while (currentRoute) {
crumbs.unshift({
path: currentRoute.path,
title: this.getTitle(currentRoute)
})
// meta.breadcrumbParent
if (currentRoute.meta.breadcrumbParent) {
currentRoute = this.$router.options.routes.find(
r => r.name === currentRoute.meta.breadcrumbParent
)
} else {
this.breadcrumbList = [];
}
},
isSubPage(path) {
console.log(this.$parent.menuData,'this.$parent.menuData==');
//
for (const menu of this.$parent.menuData) {
for (const subMenu of menu.children) {
if (subMenu.path === path) {
return true;
}
}
currentRoute = null
}
return false;
},
getBreadcrumbList(path) {
const breadcrumbList = [];
//
for (const menu of this.$parent.menuData) {
for (const subMenu of menu.children) {
if (subMenu.path === path) {
breadcrumbList.push({ title: menu.title, icon: menu.icon });
breadcrumbList.push({ title: subMenu.title });
break;
}
}
}
return breadcrumbList;
}
return crumbs
}
},
methods: {
getTitle(route) {
return typeof route.meta.title === 'function'
? route.meta.title(route)
: route.meta.title || route.name
}
};
</script>
<style scoped>
.el-breadcrumb {
margin-bottom: 20px;
}
</style>
}
</script>
<style scoped>
/* 保持之前的样式不变 */
.breadcrumb-container {
padding: 16px 12px;
background-color: #f5f5f5;
border-radius: 4px;
}
.breadcrumb {
display: flex;
flex-wrap: wrap;
padding: 0;
margin: 0;
list-style: none;
}
.breadcrumb-item {
display: flex;
align-items: center;
}
.breadcrumb-item a {
color: #626573;
text-decoration: none;
}
.breadcrumb-item.active span {
color: #1E2226;;
}
.separator {
/* margin: 0 5px;
color: #6c757d;; */
width: 12px;
height: 12px;
}
</style>

77
src/components/Breadcrumb1.vue

@ -0,0 +1,77 @@
<template>
<el-breadcrumb v-if="showBreadcrumb" separator="/">
<el-breadcrumb-item
v-for="(item, index) in breadcrumbList"
:key="index"
>
<i v-if="item.icon" :class="item.icon"></i>
<span>{{ item.title }}</span>
</el-breadcrumb-item>
</el-breadcrumb>
</template>
<script>
export default {
data() {
return {
breadcrumbList: [],
showBreadcrumb: false //
};
},
watch: {
$route() {
this.updateBreadcrumb();
}
},
mounted() {
this.updateBreadcrumb();
},
methods: {
updateBreadcrumb() {
const currentPath = this.$route.path;
//
if(!this.$parent.menuData)return
const isSubPage = this.isSubPage(currentPath);
this.showBreadcrumb = isSubPage;
if (isSubPage) {
this.breadcrumbList = this.getBreadcrumbList(currentPath);
} else {
this.breadcrumbList = [];
}
},
isSubPage(path) {
console.log(this.$parent.menuData,'this.$parent.menuData==');
//
for (const menu of this.$parent.menuData) {
for (const subMenu of menu.children) {
if (subMenu.path === path) {
return true;
}
}
}
return false;
},
getBreadcrumbList(path) {
const breadcrumbList = [];
//
for (const menu of this.$parent.menuData) {
for (const subMenu of menu.children) {
if (subMenu.path === path) {
breadcrumbList.push({ title: menu.title, icon: menu.icon });
breadcrumbList.push({ title: subMenu.title });
break;
}
}
}
return breadcrumbList;
}
}
};
</script>
<style scoped>
.el-breadcrumb {
margin-bottom: 20px;
}
</style>

2
src/components/SetLeftMenu.vue

@ -1,6 +1,6 @@
<template>
<aside class="sidebar">
<ul>
<ul style="margin: 0;">
<li v-for="(item, index) in menuList" :key="item.path + random()">
<div
:class="[($route.path == item.path) || (item.noToPath && curIndex == index) ? 'active' : '', 'flex', ($route.path == item.path) ? curIndex = index : '']"

51
src/router/index.js

@ -2,35 +2,45 @@ import Vue from 'vue';
import VueRouter from 'vue-router';
import store from '../store';
import HomeView from '../views/HomeView.vue';
// import UserPosts from '../views/UserPosts.vue';
// import Franchise from '../views/Franchise.vue'
Vue.use(VueRouter)
const whiteSlideList = [ '/ui', '/hosInformation']; //侧边导航白名单
const whiteHeaderList = ['/','/doctorInformation', '/hosInformation','/addNewTreatment'
]; //头部导航名单
const blackHeaderList = [
]; //头部导航名单
const whiteFooterList = ['/','/doctorInformation' ,'/hosInformation','/addNewTreatment'
]; //底部白名单
const routes = [{
const routes = [
{
path: '/',
name: '首页',
component: HomeView,
// component: Franchise
meta: {
title: '医生列表',
hideBreadcrumb: true // 首页不显示面包屑
}
},
{
path: '/doctorInformation',
component: () => import( /* webpackChunkName: "doctorInformation" */ '../views/DoctorInformation.vue'),
name: '医生信息',
children: [
]
component: () => import('../views/DoctorInformation.vue'),
meta: {
title: '编辑信息',
breadcrumbParent: '首页' // 手动指定父级
}
},
{
path: '/hosInformation',
component: () => import( /* webpackChunkName: "hosInformation" */ '../views/HosInformation.vue'),
name: '医院信息',
children: [
]
component: () => import('../views/HosInformation.vue'),
meta: {
title: '编辑医院',
breadcrumbParent: '医生信息' // 手动指定父级
// r如果想隐藏中间层级
// breadcrumbParent: '首页', // 跳过医生信息
// hideInBreadcrumb: true // 可选:隐藏当前项
}
},
{
path: '/addNewTreatment',
component: () => import( /* webpackChunkName: "addNewTreatment" */ '../views/AddNewTreatment.vue'),
@ -41,7 +51,11 @@ const routes = [{
{
path: '/ui',
name: 'ui组件',
component: () => import( /* webpackChunkName: "ui" */ '../views/elementGroups.vue')
component: () => import( /* webpackChunkName: "ui" */ '../views/elementGroups.vue'),
meta: {
title: 'ui示例',
breadcrumbTitle: route => `ui ${route.params.userId}` // 自定义面包屑标题
}
},
{
path: '/super/ranking',
@ -63,21 +77,20 @@ const router = new VueRouter({
routes
})
router.beforeEach((to, from, next) => {
console.log(to.path, 'to.path-----');
if (whiteSlideList.includes(to.path)) {
store.commit('SET_SIDEBAR', true); // 登录页面不显示侧边栏
} else {
store.commit('SET_SIDEBAR', false); // 其他页面显示侧边栏
}
if (whiteFooterList.includes(to.path)) {
store.commit('SET_FOOTER', true); // 登录页面不显示侧边栏
store.commit('SET_FOOTER', true); // 登录页面不显示底部信息
} else {
store.commit('SET_FOOTER', false); // 其他页面显示侧边栏
store.commit('SET_FOOTER', false); // 其他页面显示底部信息
}
if (whiteHeaderList.includes(to.path)) {
store.commit('SET_HEADER', true); // 登录页面不显示侧边栏
if (blackHeaderList.includes(to.path)) {
store.commit('SET_HEADER', false); // 登录页面不显示顶部
} else {
store.commit('SET_HEADER', false); // 其他页面显示侧边栏
store.commit('SET_HEADER', true); // 其他页面显示顶部
}
next();
});

24
src/store/index.js

@ -52,6 +52,30 @@ export default new Vuex.Store({
},
]
}],
menuData: [
{
index: '1',
title: '首页',
path:'/',
icon: 'home',
},
{
index: '2',
title: '订单列表',
icon: 'orderList',
children: [{
index: '2-1',
title: '站点列表',
path: '/agent/siteList'
},
{
index: '2-2',
title: 'ui页面',
path: '/ui'
}
]
},
],
pageName:'医生管理'
},

8
src/views/DoctorInformation.vue

@ -219,11 +219,11 @@ export default {
...mapState(['pageTitle']) // VuexshowSidebar
},
mounted() {
const id = this.$route.query.id; // id
this.doctorId = id;
if (id) {
const doctorId = this.$route.query.doctorId; // id
this.doctorId = doctorId;
if (doctorId) {
//
this.fetchDoctorData(id);
this.fetchDoctorData(doctorId);
}
},
methods: {

42
src/views/HomeView.vue

@ -1,5 +1,6 @@
<template>
<div class="min-width" style="background: #F5F7FA;">
<div class="min-width pagePadding " style="background: #F5F7FA;" >
<p class="pageTitle bold mb24">基础信息</p>
<div class="doctor-list-wrap ">
<p class="pageTitle">医生列表</p>
<el-form>
@ -100,6 +101,7 @@ import GuipTable from '@/components/GuipTable.vue';
import GuipButton from '@/components/GuipButton.vue';
import GuipSwitch from '@/components/GuipSwitch.vue';
import GuipInput from '@/components/GuipInput.vue';
import { mapState } from 'vuex';
export default {
data() {
@ -217,6 +219,8 @@ export default {
this.calculateTotalNum()
},
mounted(){
store.commit('SET_CUSTOMIZE', false);
store.commit('SET_SLIDER_MENU','menuData');
this.getInitData()
},
render() {
@ -224,6 +228,7 @@ export default {
return 'a';
},
computed: {
...mapState(['menuData']) // VuexshowSidebar
},
methods: {
//
@ -353,13 +358,41 @@ export default {
// })
},
addDoctor() {
this.$router.push(`/doctorInformation`)
this.$router.push({
name: '医生信息',
})
// this.$router.push({
// name: '',
// // query: {
// // doctorId: 123,
// // from: 'home'
// // }
// })
// URL/doctorInformation?doctorId=123&from=home
},
addHospital(item) {
this.$router.push(`/hosInformation?doctorId=${item.id}`)
// this.$router.push(`/hosInformation?doctorId=${item.id}`)
this.$router.push({
name: '医院信息',
query: { doctorId: item.id }
})
},
editDoctor(item) {
this.$router.push(`/doctorInformation?id=${item.id}`)
// this.$router.push(`/doctorInformation`)
this.$router.push({
name: '医生信息',
query: { doctorId: item.id }
})
// this.$router.push({
// name: '',
// query: {
// doctorId: item.id,
// }
// })
// this.$router.push(`/doctorInformation?doctorId=${item.id}`)
},
//
handleSelectionChange(index, selection) {
@ -449,7 +482,6 @@ export default {
}
.doctor-list-wrap {
margin: 12px;
background: #fff;
padding: 32px 36px;
height: 100%;

10
src/views/HosInformation.vue

@ -1,6 +1,6 @@
<template>
<div class="site-setting-wrap pagePadding min-flex-right">
<p class="pageTitle bold mt24 mb24">基础信息</p>
<p class="pageTitle bold mb24">基础信息</p>
<div class="siteMessage flex-common" id="siteMessage1">
<p class="littleTitle mb32">基础信息</p>
<el-form :model="form" :rules="siteFormrules" ref="siteForm">
@ -90,9 +90,9 @@
<div class="flex-right">
<GuipFormItem column="column" label="每周出诊安排" :required="true">
<div class="flex weekPlan" slot="formDom">
<GuipSelect v-for="day in weekDays" :key="day.id" v-model="form.worktimes[day.id].plan"
<!-- <GuipSelect v-for="day in weekDays" :key="day.id" v-model="form.worktimes[day.id].plan"
:options="options_weekPlan" @change="weekChange()" :label="day.name" placeholder="休息">
</GuipSelect>
</GuipSelect> -->
</div>
</GuipFormItem>
</div>
@ -895,10 +895,6 @@ export default {
}
}
.el-form-item {
margin-bottom: 0;
}
.siteMessage {
border-radius: 4px;
transition: all .5s;

Loading…
Cancel
Save