views.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div class="app-views">
  3. <router-view v-slot="{ Component }">
  4. <transition :name="app.info.router.transition || 'none'">
  5. <keep-alive :include="caches" :key="key">
  6. <component :is="Component" />
  7. </keep-alive>
  8. </transition>
  9. </router-view>
  10. </div>
  11. </template>
  12. <script lang="ts" name="app-views" setup>
  13. import { computed, onMounted, onUnmounted, ref } from "vue";
  14. import { useBase } from "/$/base";
  15. import { useCool } from "/@/cool";
  16. const { mitt } = useCool();
  17. const { process, app } = useBase();
  18. // 缓存数
  19. const key = ref(1);
  20. // 缓存列表
  21. const caches = computed(() => {
  22. return process.list
  23. .filter((e) => e.meta?.keepAlive)
  24. .map((e) => {
  25. return e.path.substring(1, e.path.length).replace(/\//g, "-");
  26. });
  27. });
  28. // 刷新页面
  29. function refresh() {
  30. key.value += 1;
  31. }
  32. onMounted(() => {
  33. mitt.on("view.refresh", refresh);
  34. });
  35. onUnmounted(() => {
  36. mitt.off("view.refresh");
  37. });
  38. </script>
  39. <style lang="scss" scoped>
  40. .app-views {
  41. flex: 1;
  42. overflow: hidden;
  43. margin: 0 10px 10px 10px;
  44. width: calc(100% - 20px);
  45. box-sizing: border-box;
  46. border-radius: 4px;
  47. position: relative;
  48. .none-enter-active {
  49. position: absolute;
  50. }
  51. .slide-enter-active {
  52. position: absolute;
  53. top: 0;
  54. width: 100%;
  55. transition: all 0.4s ease-in-out 0.2s;
  56. }
  57. .slide-leave-active {
  58. position: absolute;
  59. top: 0;
  60. width: 100%;
  61. transition: all 0.4s ease-in-out;
  62. }
  63. .slide-enter-to {
  64. transform: translate3d(0, 0, 0);
  65. opacity: 1;
  66. }
  67. .slide-enter-from {
  68. transform: translate3d(-5%, 0, 0);
  69. opacity: 0;
  70. }
  71. .slide-leave-to {
  72. transform: translate3d(5%, 0, 0);
  73. opacity: 0;
  74. }
  75. .slide-leave-from {
  76. transform: translate3d(0, 0, 0);
  77. opacity: 1;
  78. }
  79. }
  80. </style>