footer-nav.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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;
  22. color: #99a9bf;
  23. font-size: 14px;
  24. &::after {
  25. content: '';
  26. display: block;
  27. clear: both;
  28. }
  29. & i {
  30. color: #d9def1;
  31. vertical-align: baseline;
  32. }
  33. }
  34. .footer-nav-link {
  35. cursor: pointer;
  36. &:hover {
  37. color: #5e6d82;
  38. & i {
  39. color: #5e6d82;
  40. }
  41. }
  42. }
  43. .footer-nav-left {
  44. float: left;
  45. }
  46. .footer-nav-right {
  47. float: right;
  48. }
  49. </style>
  50. <script>
  51. import navConfig from '../nav.config.json';
  52. export default {
  53. data() {
  54. return {
  55. currentComponent: null,
  56. nav: [],
  57. currentIndex: -1,
  58. leftNav: null,
  59. rightNav: null
  60. };
  61. },
  62. watch: {
  63. '$route.path'() {
  64. this.updateNav();
  65. }
  66. },
  67. methods: {
  68. updateNav() {
  69. this.currentComponent = '/' + this.$route.path.split('/')[2];
  70. for (let i = 0, len = this.nav.length; i < len; i++) {
  71. if (this.nav[i].path === this.currentComponent) {
  72. this.currentIndex = i;
  73. break;
  74. }
  75. }
  76. this.leftNav = this.nav[this.currentIndex - 1];
  77. this.rightNav = this.nav[this.currentIndex + 1];
  78. },
  79. handleNavClick(direction) {
  80. this.$router.push(`/component${ direction === 'prev' ? this.leftNav.path : this.rightNav.path }`);
  81. }
  82. },
  83. created() {
  84. navConfig[0].groups.map(group => group.list).forEach(list => {
  85. this.nav = this.nav.concat(list);
  86. });
  87. this.nav = this.nav.concat(navConfig[1].children);
  88. this.updateNav();
  89. }
  90. }
  91. </script>