App.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div>
  3. <div class="app" v-cloak>
  4. <transition :name="transitionName">
  5. <keep-alive :include="include" :max="10">
  6. <router-view class="router" ref="router"></router-view>
  7. </keep-alive>
  8. </transition>
  9. </div>
  10. <Footer v-if="footer === true"></Footer>
  11. <Home v-if="home === true"></Home>
  12. </div>
  13. </template>
  14. <script>
  15. function isKeepAlive($route) {
  16. return $route.meta.keepAlive === undefined || $route.meta.keepAlive;
  17. }
  18. import Footer from "@components/Footer";
  19. import Home from "@components/Home";
  20. import { mapGetters } from "vuex";
  21. import { openShareAll } from "@libs/wechat";
  22. import { getShare } from "@api/public";
  23. import { isWeixin } from "@utils/index";
  24. export default {
  25. data() {
  26. return {
  27. transitionName: "fold-right",
  28. include: isKeepAlive(this.$route) ? [this.$route.name] : [],
  29. history: []
  30. };
  31. },
  32. provide() {
  33. return {
  34. app: this
  35. };
  36. },
  37. computed: mapGetters(["footer", "home", "isLogin"]),
  38. components: {
  39. Footer,
  40. Home
  41. },
  42. watch: {
  43. $route(to, from) {
  44. const lastPath = this.history[this.history.length - 1] || {},
  45. { isReplace, isBack } = this.$router;
  46. if (to.meta.idx && from.meta.idx) {
  47. this.transitionName =
  48. to.meta.idx > from.meta.idx ? "fold-left" : "fold-right";
  49. } else if (lastPath.path === to.path) {
  50. this.transitionName = "fold-right";
  51. this.history.pop();
  52. } else {
  53. this.transitionName = "fold-left";
  54. if (!isReplace) this.history.push({ path: from.path, name: from.name });
  55. }
  56. if (isKeepAlive(to) && to.name !== "Login") {
  57. !this.include.includes(to.name) && this.include.push(to.name);
  58. }
  59. if (isKeepAlive(from) && isBack) {
  60. var index = this.include.indexOf(from.name);
  61. index !== -1 && this.include.splice(index, 1);
  62. }
  63. this.$router.isBack = false;
  64. this.$router.isReplace = false;
  65. // console.log(this.transitionName, "change");
  66. }
  67. },
  68. mounted: function() {
  69. this.setOpenShare();
  70. },
  71. methods: {
  72. setOpenShare: function() {
  73. if (isWeixin()) {
  74. getShare().then(res => {
  75. var data = res.data.data;
  76. var configAppMessage = {
  77. desc: data.synopsis,
  78. title: data.title,
  79. link: location.href,
  80. imgUrl: data.img
  81. };
  82. openShareAll(configAppMessage);
  83. });
  84. }
  85. }
  86. }
  87. };
  88. </script>
  89. <style lang="scss">
  90. [v-cloak] {
  91. display: none !important;
  92. }
  93. .router {
  94. position: absolute;
  95. width: 100%;
  96. }
  97. .fold-left-enter-active {
  98. animation-name: fold-left-in;
  99. animation-duration: 0.1s;
  100. }
  101. .fold-left-leave-active {
  102. animation-name: fold-left-out;
  103. animation-duration: 0.1s;
  104. }
  105. @keyframes fold-left-in {
  106. 0% {
  107. -webkit-transform: translate3d(100%, 0, 0);
  108. transform: translate3d(100%, 0, 0);
  109. }
  110. 10% {
  111. -webkit-transform: translate3d(100%, 0, 0);
  112. transform: translate3d(100%, 0, 0);
  113. }
  114. 100% {
  115. -webkit-transform: translate3d(0, 0, 0);
  116. transform: translate3d(0, 0, 0);
  117. }
  118. }
  119. @keyframes fold-left-out {
  120. 0% {
  121. -webkit-transform: translate3d(0, 0, 0);
  122. transform: translate3d(0, 0, 0);
  123. }
  124. 10% {
  125. -webkit-transform: translate3d(0, 0, 0);
  126. transform: translate3d(0, 0, 0);
  127. }
  128. 100% {
  129. -webkit-transform: translate3d(-100%, 0, 0);
  130. transform: translate3d(-100%, 0, 0);
  131. }
  132. }
  133. .fold-right-enter-active {
  134. animation-name: fold-right-in;
  135. animation-duration: 0.1s;
  136. }
  137. .fold-right-leave-active {
  138. animation-name: fold-right-out;
  139. animation-duration: 0.1s;
  140. }
  141. @keyframes fold-right-in {
  142. 0% {
  143. width: 100%;
  144. -webkit-transform: translate3d(-100%, 0, 0);
  145. transform: translate3d(-100%, 0, 0);
  146. }
  147. 10% {
  148. width: 100%;
  149. -webkit-transform: translate3d(-100%, 0, 0);
  150. transform: translate3d(-100%, 0, 0);
  151. }
  152. 100% {
  153. width: 100%;
  154. -webkit-transform: translate3d(0, 0, 0);
  155. transform: translate3d(0, 0, 0);
  156. }
  157. }
  158. @keyframes fold-right-out {
  159. 0% {
  160. width: 100%;
  161. -webkit-transform: translate3d(0, 0, 0);
  162. transform: translate3d(0, 0, 0);
  163. }
  164. 10% {
  165. width: 100%;
  166. -webkit-transform: translate3d(0, 0, 0);
  167. transform: translate3d(0, 0, 0);
  168. }
  169. 100% {
  170. width: 100%;
  171. -webkit-transform: translate3d(100%, 0, 0);
  172. transform: translate3d(100%, 0, 0);
  173. }
  174. }
  175. </style>