index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <section v-if="routerView" class="app-main-container">
  3. <github-corner v-if="githubCorner"></github-corner>
  4. <vab-keel v-if="show" class="vab-keel">
  5. <vab-keel-heading :img="true" />
  6. <vab-keel-text :lines="7" />
  7. <vab-keel-heading :img="true" />
  8. <vab-keel-text :lines="6" />
  9. <vab-keel-heading :img="true" />
  10. <vab-keel-text :lines="8" />
  11. </vab-keel>
  12. <transition mode="out-in" name="fade-transform">
  13. <keep-alive :include="cachedRoutes" :max="keepAliveMaxNum">
  14. <router-view :key="key" class="app-main-height" />
  15. </keep-alive>
  16. </transition>
  17. <footer v-show="footerCopyright" class="footer-copyright">
  18. Copyright
  19. <vab-icon :icon="['fas', 'copyright']"></vab-icon>
  20. {{ title }} {{ fullYear }} by {{ copyright }}
  21. </footer>
  22. </section>
  23. </template>
  24. <script>
  25. import { VabKeel, VabKeelHeading, VabKeelText } from "@/plugins/vabKeel";
  26. import { mapGetters } from "vuex";
  27. import GithubCorner from "../GithubCorner";
  28. import {
  29. copyright,
  30. footerCopyright,
  31. githubCorner,
  32. keepAliveMaxNum,
  33. title,
  34. } from "@/config/settings";
  35. export default {
  36. name: "AppMain",
  37. components: {
  38. VabKeel,
  39. VabKeelHeading,
  40. VabKeelText,
  41. GithubCorner,
  42. },
  43. data() {
  44. return {
  45. show: false,
  46. fullYear: new Date().getFullYear(),
  47. copyright,
  48. title,
  49. keepAliveMaxNum,
  50. routerView: true,
  51. footerCopyright,
  52. githubCorner,
  53. };
  54. },
  55. computed: {
  56. ...mapGetters({
  57. visitedRoutes: "tagsBar/visitedRoutes",
  58. device: "settings/device",
  59. skeleton: "settings/skeleton",
  60. }),
  61. cachedRoutes() {
  62. const cachedRoutesArr = [];
  63. this.visitedRoutes.forEach((item) => {
  64. if (!item.meta.noKeepAlive) {
  65. cachedRoutesArr.push(item.name);
  66. this.handleSkeleton();
  67. }
  68. });
  69. return cachedRoutesArr;
  70. },
  71. key() {
  72. return this.$route.path;
  73. },
  74. },
  75. watch: {
  76. $route: {
  77. handler(route) {
  78. if ("mobile" === this.device) {
  79. this.$store.dispatch("settings/foldSideBar");
  80. }
  81. },
  82. immediate: true,
  83. },
  84. },
  85. created() {
  86. //重载所有路由
  87. this.$baseEventBus.$on("reloadRouterView", () => {
  88. this.routerView = false;
  89. this.$nextTick(() => {
  90. this.routerView = true;
  91. this.handleSkeleton();
  92. });
  93. });
  94. },
  95. mounted() {
  96. this.handleSkeleton();
  97. },
  98. methods: {
  99. handleSkeleton() {
  100. if (this.skeleton) {
  101. this.show = true;
  102. setTimeout(() => {
  103. this.show = false;
  104. }, 200);
  105. }
  106. },
  107. },
  108. };
  109. </script>
  110. <style lang="scss" scoped>
  111. .app-main-container {
  112. position: relative;
  113. width: 100%;
  114. overflow: hidden;
  115. .vab-keel {
  116. margin: $base-padding;
  117. }
  118. .app-main-height {
  119. min-height: $base-app-main-height;
  120. }
  121. .footer-copyright {
  122. min-height: 55px;
  123. line-height: 55px;
  124. color: rgba(0, 0, 0, 0.45);
  125. text-align: center;
  126. border-top: 1px dashed $base-border-color;
  127. }
  128. }
  129. </style>