App.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <div id="app">
  3. <transition :name="transitionName">
  4. <keep-alive>
  5. <router-view class="child-view"></router-view>
  6. </keep-alive>
  7. </transition>
  8. <w-spinner></w-spinner>
  9. </div>
  10. </template>
  11. <script>
  12. import WSpinner from "./components/WSpinner";
  13. export default {
  14. components: {WSpinner},
  15. data () {
  16. return {
  17. transitionName: null,
  18. }
  19. },
  20. mounted() {
  21. this.sessionStorage('/', 1);
  22. //
  23. let hash = window.location.hash;
  24. if (hash.indexOf("#") === 0) {
  25. hash = hash.substr(1);
  26. if (hash !== '/' && this.sessionStorage(hash) === 0) {
  27. this.sessionStorage(hash, this.sessionStorage('::count') + 1);
  28. }
  29. }
  30. },
  31. watch: {
  32. '$route' (To, From) {
  33. if (this.transitionName === null) {
  34. this.transitionName = 'app-slide-no';
  35. return;
  36. }
  37. if (typeof To.name === 'undefined' || typeof From.name === 'undefined') {
  38. return;
  39. }
  40. this.slideType(To, From)
  41. }
  42. },
  43. methods: {
  44. slideType(To, From) {
  45. let isBack = this.$router.isBack;
  46. this.$router.isBack = false;
  47. //
  48. let ToIndex = this.sessionStorage(To.path);
  49. let FromIndex = this.sessionStorage(From.path);
  50. if (ToIndex && ToIndex < FromIndex) {
  51. isBack = true; //后退
  52. this.sessionStorage(true, ToIndex);
  53. }else{
  54. isBack = false; //前进
  55. this.sessionStorage(To.path, this.sessionStorage('::count') + 1);
  56. }
  57. //
  58. if (To.meta.slide === false || From.meta.slide === false)
  59. {
  60. //取消动画
  61. this.transitionName = 'app-slide-no'
  62. }
  63. else if (To.meta.slide === 'up' || From.meta.slide === 'up' || To.meta.slide === 'down' || From.meta.slide === 'down')
  64. {
  65. //上下动画
  66. if (isBack) {
  67. this.transitionName = 'app-slide-down'
  68. } else {
  69. this.transitionName = 'app-slide-up'
  70. }
  71. }
  72. else
  73. {
  74. //左右动画(默认)
  75. if (isBack) {
  76. this.transitionName = 'app-slide-right'
  77. } else {
  78. this.transitionName = 'app-slide-left'
  79. }
  80. }
  81. },
  82. sessionStorage(path, num) {
  83. let conut = 0;
  84. let history = JSON.parse(window.sessionStorage['__history__'] || '{}');
  85. if (path === true) {
  86. let items = {};
  87. for(let i in history){
  88. if (history.hasOwnProperty(i)) {
  89. if (parseInt(history[i]) <= num) {
  90. items[i] = history[i];
  91. conut++;
  92. }
  93. }
  94. }
  95. history = items;
  96. history['::count'] = Math.max(num, conut);
  97. window.sessionStorage['__history__'] = JSON.stringify(history);
  98. return history;
  99. }
  100. if (typeof num === 'undefined') {
  101. return parseInt(history[path] || 0);
  102. }
  103. if (path === "/") num = 1;
  104. history[path] = num;
  105. for(let key in history){ if (history.hasOwnProperty(key) && key !== '::count') { conut++; } }
  106. history['::count'] = Math.max(num, conut);
  107. window.sessionStorage['__history__'] = JSON.stringify(history);
  108. }
  109. }
  110. }
  111. </script>
  112. <style>
  113. body { overflow-x: hidden; }
  114. </style>
  115. <!--suppress CssUnusedSymbol -->
  116. <style scoped>
  117. .child-view {
  118. position: absolute;
  119. width: 100%;
  120. min-height: 100%;
  121. background-color: #f1f2f7;
  122. transition: all .3s cubic-bezier(.55, 0, .1, 1);
  123. }
  124. .app-slide-no-leave-to {display: none;}
  125. /**
  126. * 左右模式
  127. */
  128. .app-slide-left-leave-active{z-index:1;transform:translate(0,0)}
  129. .app-slide-left-leave-to{z-index:1;transform:translate(0,0)}
  130. .app-slide-left-enter-active{opacity:0;z-index:2;transform:translate(30%,0)}
  131. .app-slide-left-enter-to{opacity:1;z-index:2;transform:translate(0,0)}
  132. .app-slide-right-leave-active{opacity:1;z-index:2;transform:translate(0,0)}
  133. .app-slide-right-leave-to{opacity:0;z-index:2;transform:translate(30%,0)}
  134. .app-slide-right-enter-active{z-index:1;transform:translate(0,0)}
  135. .app-slide-right-enter{z-index:1;transform:translate(0,0)}
  136. /**
  137. * 上下模式
  138. */
  139. .app-slide-up-leave-active{z-index:1;transform:translate(0,0)}
  140. .app-slide-up-leave-to{z-index:1;transform:translate(0,0)}
  141. .app-slide-up-enter-active{opacity:0;z-index:2;transform:translate(0,20%)}
  142. .app-slide-up-enter-to{opacity:1;z-index:2;transform:translate(0,0)}
  143. .app-slide-down-leave-active{opacity:1;z-index:2;transform:translate(0,0)}
  144. .app-slide-down-leave-to{opacity:0;z-index:2;transform:translate(0,20%)}
  145. .app-slide-down-enter-active{z-index:1;transform:translate(0,0)}
  146. .app-slide-down-enter{z-index:1;transform:translate(0,0)}
  147. </style>