breadcrumb.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <div class="listRouterBox">
  3. <span class="location">当前位置:</span>
  4. <el-breadcrumb :separator-icon="ArrowRight">
  5. <el-breadcrumb-item>
  6. <NuxtLink to="/">首页</NuxtLink>
  7. </el-breadcrumb-item>
  8. <!--第一种情况 当前是2级的列表页 start-->
  9. <el-breadcrumb-item v-if="routeLevel==1">
  10. <span class="routeName">
  11. {{name}}
  12. </span>
  13. </el-breadcrumb-item>
  14. <!--第一种情况 当前是2级的列表页 end-->
  15. <!--第二种情况 当前是3级的列表页 start-->
  16. <el-breadcrumb-item v-if="routeLevel==2">
  17. <NuxtLink :to="`/${parent_pinyin}/list-1.html`" class="routeName">
  18. {{parent_name}}
  19. </NuxtLink>
  20. </el-breadcrumb-item>
  21. <el-breadcrumb-item v-if="routeLevel==2">
  22. <span class="routeName">
  23. {{name}}
  24. </span>
  25. </el-breadcrumb-item>
  26. <!--第二种情况 当前是3级的列表页 end-->
  27. <!--第三种情况 当前是2级的详情页 start-->
  28. <el-breadcrumb-item v-if="routeLevel==3">
  29. <NuxtLink :to="`/${pinyin}/index.html`">{{name}}</NuxtLink>
  30. </el-breadcrumb-item>
  31. <el-breadcrumb-item v-if="routeLevel==3">
  32. <span class="routeName">
  33. {{ articleName }}
  34. </span>
  35. </el-breadcrumb-item>
  36. <!--第三种情况 当前是2级的详情页 end-->
  37. <!--第四种情况 当前是3级的详情页 start-->
  38. <el-breadcrumb-item v-if="routeLevel==4">
  39. <NuxtLink :to="`/${parent_pinyin}/list-1.html`" class="routeName">
  40. {{parent_name}}
  41. </NuxtLink>
  42. </el-breadcrumb-item>
  43. <el-breadcrumb-item v-if="routeLevel==4">
  44. <NuxtLink :to="`/${parent_pinyin}/${pinyin}/list-1.html`">
  45. {{parent_name}}
  46. </NuxtLink>
  47. </el-breadcrumb-item>
  48. <el-breadcrumb-item v-if="routeLevel==4">
  49. <span class="routeName">
  50. {{ articleName }}
  51. </span>
  52. </el-breadcrumb-item>
  53. <!--第四种情况 当前是3级的详情页 end-->
  54. </el-breadcrumb>
  55. </div>
  56. </template>
  57. <script setup>
  58. import { ref } from 'vue';
  59. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus';
  60. import { ArrowRight } from '@element-plus/icons-vue';
  61. //获得页面的routeId导航池id
  62. const props = defineProps({
  63. routeId: Number,
  64. articleName: String,
  65. });
  66. //1.获得当前路由的层级
  67. const route = useRoute();
  68. const routeLevel = ref(0);
  69. //判断当前处于哪个层级
  70. //第二层的列表
  71. if(route.name=='dir-dir-list-id'){
  72. routeLevel.value = 2
  73. }
  74. //第一层的列表
  75. if(route.name=='dir-list-id'){
  76. routeLevel.value = 1
  77. }
  78. //第二层详情
  79. if(route.name=='dir-dir-id'){
  80. routeLevel.value = 4
  81. }
  82. //第一层详情
  83. if(route.name=='dir-id'){
  84. routeLevel.value = 3
  85. }
  86. //2.获得当前栏目的名称 面包屑的最后一级
  87. const name = ref('')
  88. const pinyin = ref('');
  89. //3.获得父级栏目 面包屑倒数第二级
  90. const parent_name = ref("");
  91. const parent_id = ref("");
  92. const parent_pinyin = ref("");
  93. const parent_children_count = ref(0);
  94. const pageName = await requestDataPromise('/web/getOneWebsiteCategory', {
  95. method: 'GET',
  96. query: {
  97. 'catid': props.routeId
  98. },
  99. });
  100. if (pageName.code == 200) {
  101. //最后一级
  102. name.value = pageName.data.alias
  103. pinyin.value = pageName.data.aLIas_pinyin;
  104. //倒数第二级 如果存在
  105. parent_name.value = pageName.data.parent_name;
  106. parent_id.value = pageName.data.parent_id;
  107. parent_pinyin.value = pageName.data.parent_pinyin;
  108. parent_children_count.value = pageName.data.children_count;
  109. }
  110. </script>
  111. <style lang="less" scoped>
  112. //导航条
  113. .listRouterBox {
  114. width: 100%;
  115. height: 52px;
  116. font-family: Microsoft YaHei, Microsoft YaHei;
  117. font-weight: 400;
  118. font-size: 16px;
  119. color: #999;
  120. text-align: left;
  121. font-style: normal;
  122. text-transform: none;
  123. .routeName {
  124. color: #333;
  125. }
  126. :deep(.el-breadcrumb) {
  127. display: inline-block;
  128. vertical-align: -4px;
  129. }
  130. :deep(.el-breadcrumb__inner a),
  131. :deep(.el-breadcrumb__inner.is-link) {
  132. color: #999;
  133. font-weight: 400;
  134. text-decoration: none;
  135. transition: var(--el-transition-color);
  136. }
  137. span {
  138. font-family: Microsoft YaHei, Microsoft YaHei;
  139. font-weight: 400;
  140. font-size: 20px;
  141. color: #999;
  142. line-height: 23px;
  143. text-align: left;
  144. font-style: normal;
  145. text-transform: none;
  146. }
  147. .location {
  148. margin-right: 20px;
  149. width: 100px;
  150. height: 22px;
  151. font-family: Microsoft YaHei, Microsoft YaHei;
  152. font-weight: 400;
  153. font-size: 20px;
  154. color: #999;
  155. line-height: 23px;
  156. text-align: left;
  157. font-style: normal;
  158. text-transform: none;
  159. }
  160. }
  161. </style>