App.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 (lastPath.path === to.path) {
  47. this.transitionName = "fold-right";
  48. this.history.pop();
  49. } else {
  50. this.transitionName = "fold-left";
  51. if (!isReplace) this.history.push({ path: from.path, name: from.name });
  52. }
  53. if (isKeepAlive(to) && to.name !== "Login") {
  54. !this.include.includes(to.name) && this.include.push(to.name);
  55. }
  56. if (isKeepAlive(from) && isBack) {
  57. var index = this.include.indexOf(from.name);
  58. index !== -1 && this.include.splice(index, 1);
  59. }
  60. this.$router.isBack = false;
  61. this.$router.isReplace = false;
  62. console.log(this.transitionName, "change");
  63. }
  64. },
  65. mounted: function() {
  66. this.setOpenShare();
  67. },
  68. methods: {
  69. setOpenShare: function() {
  70. if (isWeixin()) {
  71. getShare().then(res => {
  72. var data = res.data.data;
  73. var configAppMessage = {
  74. desc: data.synopsis,
  75. title: data.title,
  76. link: location.href,
  77. imgUrl: data.img
  78. };
  79. openShareAll(configAppMessage);
  80. });
  81. }
  82. }
  83. }
  84. };
  85. </script>
  86. <style lang="scss">
  87. [v-cloak] {
  88. display: none !important;
  89. }
  90. .router {
  91. position: absolute;
  92. width: 100%;
  93. }
  94. .fold-left-enter-active {
  95. animation-name: fold-left-in;
  96. animation-duration: 0.5s;
  97. }
  98. .fold-left-leave-active {
  99. animation-name: fold-left-out;
  100. animation-duration: 0.5s;
  101. }
  102. @keyframes fold-left-in {
  103. 0% {
  104. -webkit-transform: translate3d(100%, 0, 0);
  105. transform: translate3d(100%, 0, 0);
  106. }
  107. 10% {
  108. -webkit-transform: translate3d(100%, 0, 0);
  109. transform: translate3d(100%, 0, 0);
  110. }
  111. 100% {
  112. -webkit-transform: translate3d(0, 0, 0);
  113. transform: translate3d(0, 0, 0);
  114. }
  115. }
  116. @keyframes fold-left-out {
  117. 0% {
  118. -webkit-transform: translate3d(0, 0, 0);
  119. transform: translate3d(0, 0, 0);
  120. }
  121. 10% {
  122. -webkit-transform: translate3d(0, 0, 0);
  123. transform: translate3d(0, 0, 0);
  124. }
  125. 100% {
  126. -webkit-transform: translate3d(-100%, 0, 0);
  127. transform: translate3d(-100%, 0, 0);
  128. }
  129. }
  130. .fold-right-enter-active {
  131. animation-name: fold-right-in;
  132. animation-duration: 0.5s;
  133. }
  134. .fold-right-leave-active {
  135. animation-name: fold-right-out;
  136. animation-duration: 0.5s;
  137. }
  138. @keyframes fold-right-in {
  139. 0% {
  140. width: 100%;
  141. -webkit-transform: translate3d(-100%, 0, 0);
  142. transform: translate3d(-100%, 0, 0);
  143. }
  144. 10% {
  145. width: 100%;
  146. -webkit-transform: translate3d(-100%, 0, 0);
  147. transform: translate3d(-100%, 0, 0);
  148. }
  149. 100% {
  150. width: 100%;
  151. -webkit-transform: translate3d(0, 0, 0);
  152. transform: translate3d(0, 0, 0);
  153. }
  154. }
  155. @keyframes fold-right-out {
  156. 0% {
  157. width: 100%;
  158. -webkit-transform: translate3d(0, 0, 0);
  159. transform: translate3d(0, 0, 0);
  160. }
  161. 10% {
  162. width: 100%;
  163. -webkit-transform: translate3d(0, 0, 0);
  164. transform: translate3d(0, 0, 0);
  165. }
  166. 100% {
  167. width: 100%;
  168. -webkit-transform: translate3d(100%, 0, 0);
  169. transform: translate3d(100%, 0, 0);
  170. }
  171. }
  172. </style>