NavTop.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div class="nav-main">
  3. <span
  4. v-for="nav in navs"
  5. :key="nav.id"
  6. class="nav-span"
  7. :class="{ 'nav-active': activeNav === nav.id }"
  8. >
  9. <a
  10. class="nav-link"
  11. @click="toggleNav(nav)"
  12. >
  13. <span class="nav-icon">
  14. <!-- <i :class="['iconfont-bigscreen', nav.icon]" /> -->
  15. </span>
  16. {{ nav.name }}
  17. </a>
  18. </span>
  19. <span class="nav-span nav-span-last" />
  20. </div>
  21. </template>
  22. <script lang='ts'>
  23. export default {
  24. name: 'NavMain',
  25. components: {},
  26. data () {
  27. return {
  28. nc: null,
  29. activeNav: 0
  30. }
  31. },
  32. props: {
  33. navs: {
  34. type: Array,
  35. required: true
  36. }
  37. },
  38. watch: {
  39. $route () {
  40. const nav = this.navs.find(m => m.path === this.$route.path)
  41. if (nav) {
  42. this.activeNav = nav.id
  43. }
  44. }
  45. },
  46. mounted () {
  47. const nav = this.navs.find(m => m.path === this.$route.path)
  48. this.activeNav = nav ? nav.id : 0
  49. },
  50. beforeDestroy () {
  51. },
  52. methods: {
  53. toggleNav (nav) {
  54. this.activeNav = nav.id
  55. this.$emit('change', nav)
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .nav-main {
  62. z-index: 10;
  63. display: flex;
  64. top: 30px;
  65. position: sticky;
  66. width: 100%;
  67. margin-top: 109px;
  68. min-width: 1024px;
  69. user-select: none;
  70. .nav-span {
  71. position: relative;
  72. top: 1px;
  73. // background-image: url('./images/line.png');
  74. background-repeat: repeat-x;
  75. background-position: 0 34px;
  76. .nav-link {
  77. display: flex;
  78. align-items: center;
  79. transition: color 0.2s;
  80. text-decoration: none !important;
  81. color: var(--bs-el-title);
  82. width: auto;
  83. min-width: 140px;
  84. line-height: 40px;
  85. font-size: 14px;
  86. text-align: left;
  87. cursor: pointer;
  88. padding: 0 40px;
  89. &.nav-active,
  90. &:hover {
  91. color: var(--bs-el-text) !important;
  92. }
  93. }
  94. .nav-icon {
  95. margin-right: 5px;
  96. }
  97. &.nav-active {
  98. background-color: var(--bs-background-1);
  99. &:after{
  100. content: '';
  101. position: absolute;
  102. top: 0;
  103. left: 0;
  104. width: 100%;
  105. height: 2px;
  106. background-color: var(--bs-el-color-primary);
  107. }
  108. // background-image: url('./images/tab.png');
  109. // background-size: 100% 100%;
  110. // background-repeat: no-repeat;
  111. // background-position: center bottom;
  112. /* border-bottom: 1px solid var(--bs-background-1); */
  113. /* background-color: var(--bs-background-1) */
  114. }
  115. }
  116. .nav-span-last {
  117. flex: 1;
  118. }
  119. }
  120. </style>