footer-nav.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. computed: {
  67. lang() {
  68. return this.$route.meta.lang;
  69. }
  70. },
  71. watch: {
  72. '$route.path'() {
  73. this.setNav();
  74. this.updateNav();
  75. }
  76. },
  77. methods: {
  78. setNav() {
  79. let nav = navConfig[this.lang];
  80. this.nav = [nav[0]].concat(nav[2].children);
  81. nav[3].groups.map(group => group.list).forEach(list => {
  82. this.nav = this.nav.concat(list);
  83. });
  84. },
  85. updateNav() {
  86. this.currentComponent = '/' + this.$route.path.split('/')[3];
  87. for (let i = 0, len = this.nav.length; i < len; i++) {
  88. if (this.nav[i].path === this.currentComponent) {
  89. this.currentIndex = i;
  90. break;
  91. }
  92. }
  93. this.leftNav = this.nav[this.currentIndex - 1];
  94. this.rightNav = this.nav[this.currentIndex + 1];
  95. },
  96. handleNavClick(direction) {
  97. this.$router.push(`/${ this.lang }/component${ direction === 'prev' ? this.leftNav.path : this.rightNav.path }`);
  98. }
  99. },
  100. created() {
  101. this.setNav();
  102. this.updateNav();
  103. }
  104. };
  105. </script>