footer-nav.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <div class="footer-nav">
  3. <span
  4. v-if="leftNav"
  5. class="footer-nav-link footer-nav-left"
  6. @click="handleNavClick('prev')">
  7. <i class="el-icon-arrow-left"></i>
  8. {{ leftNav.title || leftNav.name }}
  9. </span>
  10. <span
  11. v-if="rightNav"
  12. class="footer-nav-link footer-nav-right"
  13. @click="handleNavClick('next')">
  14. {{ rightNav.title || rightNav.name }}
  15. <i class="el-icon-arrow-right"></i>
  16. </span>
  17. </div>
  18. </template>
  19. <style>
  20. .footer-nav {
  21. padding: 24px 0;
  22. color: #99a9bf;
  23. font-size: 14px;
  24. &::after {
  25. content: '';
  26. display: block;
  27. clear: both;
  28. }
  29. & i {
  30. transition: .3s;
  31. color: #d9def1;
  32. vertical-align: baseline;
  33. }
  34. }
  35. .footer-nav-link {
  36. cursor: pointer;
  37. transition: .3s;
  38. &:hover {
  39. color: #20a0ff;
  40. & i {
  41. color: #20a0ff;
  42. }
  43. }
  44. }
  45. .footer-nav-left {
  46. float: left;
  47. margin-left: -4px;
  48. }
  49. .footer-nav-right {
  50. float: right;
  51. margin-right: -4px;
  52. }
  53. </style>
  54. <script>
  55. import navConfig from '../nav.config.json';
  56. export default {
  57. data() {
  58. return {
  59. currentComponent: null,
  60. nav: [],
  61. currentIndex: -1,
  62. leftNav: null,
  63. rightNav: null
  64. };
  65. },
  66. watch: {
  67. '$route.path'() {
  68. this.updateNav();
  69. }
  70. },
  71. methods: {
  72. updateNav() {
  73. this.currentComponent = '/' + this.$route.path.split('/')[2];
  74. for (let i = 0, len = this.nav.length; i < len; i++) {
  75. if (this.nav[i].path === this.currentComponent) {
  76. this.currentIndex = i;
  77. break;
  78. }
  79. }
  80. this.leftNav = this.nav[this.currentIndex - 1];
  81. this.rightNav = this.nav[this.currentIndex + 1];
  82. },
  83. handleNavClick(direction) {
  84. this.$router.push(`/component${ direction === 'prev' ? this.leftNav.path : this.rightNav.path }`);
  85. }
  86. },
  87. created() {
  88. this.nav = navConfig[0].children.concat(navConfig[1]);
  89. navConfig[2].groups.map(group => group.list).forEach(list => {
  90. this.nav = this.nav.concat(list);
  91. });
  92. this.updateNav();
  93. }
  94. };
  95. </script>