index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div
  3. class="crumbs"
  4. :class="{
  5. dark: isDarkTheme
  6. }"
  7. >
  8. <ul>
  9. <li v-if="list[0]">
  10. <span class="name" :title="rootName || list[0].name" @click="onClickPath(0)">{{rootName || list[0].name}}</span>
  11. </li>
  12. <li v-if="list.length > 3">...</li>
  13. <li v-if="list.length > 2">
  14. <span class="name" :title="list[list.length - 2].name" @click="onClickPath(list.length - 2)">{{list[list.length - 2].name}}</span>
  15. </li>
  16. <li v-if="list.length > 1">
  17. <span class="name" :title="list[list.length - 1].name" @click="onClickPath(list.length - 1)">{{list[list.length - 1].name}}</span>
  18. </li>
  19. </ul>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. props: {
  25. isDarkTheme: {
  26. type: Boolean,
  27. default: false,
  28. },
  29. list: {
  30. type: Array,
  31. required: true,
  32. },
  33. rootName: {
  34. type: String,
  35. required: true,
  36. },
  37. },
  38. methods: {
  39. onClickPath(idx) {
  40. if (idx !== this.list.length - 1) {
  41. this.$emit('click-path', idx)
  42. }
  43. }
  44. }
  45. }
  46. </script>
  47. <style lang="less" scoped>
  48. .crumbs{
  49. >ul{
  50. display: flex;
  51. align-items: center;
  52. >li{
  53. font-size: 14px;
  54. color: #969799;
  55. // line-height: 28px;
  56. .name{
  57. max-width: 285px;
  58. overflow: hidden;
  59. white-space: pre;
  60. text-overflow: ellipsis;
  61. cursor: pointer;
  62. }
  63. &::after {
  64. content: '>';
  65. margin-left: 7px;
  66. margin-right: 7px;
  67. }
  68. &:last-of-type{
  69. font-size: 14px;
  70. // font-weight: bold;
  71. color: #333333;
  72. line-height: 28px;
  73. .name {
  74. cursor: default;
  75. }
  76. &::after {
  77. content: '';
  78. }
  79. }
  80. }
  81. }
  82. }
  83. .crumbs.dark {
  84. >ul{
  85. >li{
  86. color: rgba(255, 255, 255, 0.6);
  87. &:last-of-type{
  88. color: #fff;
  89. }
  90. }
  91. }
  92. }
  93. </style>