index.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div v-if="routerView" class="app-main-container">
  3. <vab-github-corner />
  4. <transition mode="out-in" name="fade-transform">
  5. <keep-alive :include="cachedRoutes" :max="keepAliveMaxNum">
  6. <router-view :key="key" class="app-main-height" />
  7. </keep-alive>
  8. </transition>
  9. <footer v-show="footerCopyright" class="footer-copyright">
  10. Copyright
  11. <vab-icon :icon="['fas', 'copyright']"></vab-icon>
  12. vue-admin-better 开源免费版 {{ fullYear }}
  13. </footer>
  14. </div>
  15. </template>
  16. <script>
  17. import { mapActions, mapGetters } from 'vuex'
  18. import { copyright, footerCopyright, keepAliveMaxNum, title } from '@/config'
  19. export default {
  20. name: 'VabAppMain',
  21. data() {
  22. return {
  23. show: false,
  24. fullYear: new Date().getFullYear(),
  25. copyright,
  26. title,
  27. keepAliveMaxNum,
  28. routerView: true,
  29. footerCopyright,
  30. }
  31. },
  32. computed: {
  33. ...mapGetters({
  34. visitedRoutes: 'tabsBar/visitedRoutes',
  35. device: 'settings/device',
  36. }),
  37. cachedRoutes() {
  38. const cachedRoutesArr = []
  39. this.visitedRoutes.forEach((item) => {
  40. if (!item.meta.noKeepAlive) {
  41. cachedRoutesArr.push(item.name)
  42. }
  43. })
  44. return cachedRoutesArr
  45. },
  46. key() {
  47. return this.$route.path
  48. },
  49. },
  50. watch: {
  51. $route: {
  52. handler(route) {
  53. if ('mobile' === this.device) this.foldSideBar()
  54. },
  55. immediate: true,
  56. },
  57. },
  58. created() {
  59. //重载所有路由
  60. this.$baseEventBus.$on('reload-router-view', () => {
  61. this.routerView = false
  62. this.$nextTick(() => {
  63. this.routerView = true
  64. })
  65. })
  66. },
  67. mounted() {},
  68. methods: {
  69. ...mapActions({
  70. foldSideBar: 'settings/foldSideBar',
  71. }),
  72. },
  73. }
  74. </script>
  75. <style lang="scss" scoped>
  76. .app-main-container {
  77. position: relative;
  78. width: 100%;
  79. overflow: hidden;
  80. .vab-keel {
  81. margin: $base-padding;
  82. }
  83. .app-main-height {
  84. min-height: $base-app-main-height;
  85. }
  86. .footer-copyright {
  87. min-height: 55px;
  88. line-height: 55px;
  89. color: rgba(0, 0, 0, 0.45);
  90. text-align: center;
  91. border-top: 1px dashed $base-border-color;
  92. }
  93. }
  94. </style>