App.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. setInterval(() => {
  32. this.searchEnter();
  33. }, 1000);
  34. },
  35. watch: {
  36. '$route' (To, From) {
  37. if (this.transitionName === null) {
  38. this.transitionName = 'app-slide-no';
  39. return;
  40. }
  41. if (typeof To.name === 'undefined' || typeof From.name === 'undefined') {
  42. return;
  43. }
  44. this.slideType(To, From)
  45. }
  46. },
  47. methods: {
  48. slideType(To, From) {
  49. let isBack = this.$router.isBack;
  50. this.$router.isBack = false;
  51. //
  52. let ToIndex = this.sessionStorage(To.path);
  53. let FromIndex = this.sessionStorage(From.path);
  54. if (ToIndex && ToIndex < FromIndex) {
  55. isBack = true; //后退
  56. this.sessionStorage(true, ToIndex);
  57. }else{
  58. isBack = false; //前进
  59. this.sessionStorage(To.path, this.sessionStorage('::count') + 1);
  60. }
  61. //
  62. if (To.meta.slide === false || From.meta.slide === false)
  63. {
  64. //取消动画
  65. this.transitionName = 'app-slide-no'
  66. }
  67. else if (To.meta.slide === 'up' || From.meta.slide === 'up' || To.meta.slide === 'down' || From.meta.slide === 'down')
  68. {
  69. //上下动画
  70. if (isBack) {
  71. this.transitionName = 'app-slide-down'
  72. } else {
  73. this.transitionName = 'app-slide-up'
  74. }
  75. }
  76. else
  77. {
  78. //左右动画(默认)
  79. if (isBack) {
  80. this.transitionName = 'app-slide-right'
  81. } else {
  82. this.transitionName = 'app-slide-left'
  83. }
  84. }
  85. },
  86. sessionStorage(path, num) {
  87. let conut = 0;
  88. let history = JSON.parse(window.sessionStorage['__history__'] || '{}');
  89. if (path === true) {
  90. let items = {};
  91. for(let i in history){
  92. if (history.hasOwnProperty(i)) {
  93. if (parseInt(history[i]) <= num) {
  94. items[i] = history[i];
  95. conut++;
  96. }
  97. }
  98. }
  99. history = items;
  100. history['::count'] = Math.max(num, conut);
  101. window.sessionStorage['__history__'] = JSON.stringify(history);
  102. return history;
  103. }
  104. if (typeof num === 'undefined') {
  105. return parseInt(history[path] || 0);
  106. }
  107. if (path === "/") num = 1;
  108. history[path] = num;
  109. for(let key in history){ if (history.hasOwnProperty(key) && key !== '::count') { conut++; } }
  110. history['::count'] = Math.max(num, conut);
  111. window.sessionStorage['__history__'] = JSON.stringify(history);
  112. },
  113. searchEnter() {
  114. let row = $A(".sreachBox");
  115. if (row.length === 0) {
  116. return;
  117. }
  118. if (row.attr("data-enter-init") === "init") {
  119. return;
  120. }
  121. row.attr("data-enter-init", "init");
  122. //
  123. let buttons = row.find("button[type='button']");
  124. let button = null;
  125. if (buttons.length === 0) {
  126. return;
  127. }
  128. buttons.each((index, item) => {
  129. if ($A(item).text().indexOf("搜索")) {
  130. button = $A(item);
  131. }
  132. });
  133. if (button === null) {
  134. return;
  135. }
  136. row.find("input.ivu-input").keydown(function(e) {
  137. if (e.keyCode == 13) {
  138. if (!button.hasClass("ivu-btn-loading") ) {
  139. button.click();
  140. }
  141. }
  142. });
  143. }
  144. }
  145. }
  146. </script>
  147. <style>
  148. body { overflow-x: hidden; }
  149. </style>
  150. <!--suppress CssUnusedSymbol -->
  151. <style scoped>
  152. .child-view {
  153. position: absolute;
  154. width: 100%;
  155. min-height: 100%;
  156. background-color: #f1f2f7;
  157. transition: all .3s cubic-bezier(.55, 0, .1, 1);
  158. }
  159. .app-slide-no-leave-to {display: none;}
  160. /**
  161. * 左右模式
  162. */
  163. .app-slide-left-leave-active{z-index:1;transform:translate(0,0)}
  164. .app-slide-left-leave-to{z-index:1;transform:translate(0,0)}
  165. .app-slide-left-enter-active{opacity:0;z-index:2;transform:translate(30%,0)}
  166. .app-slide-left-enter-to{opacity:1;z-index:2;transform:translate(0,0)}
  167. .app-slide-right-leave-active{opacity:1;z-index:2;transform:translate(0,0)}
  168. .app-slide-right-leave-to{opacity:0;z-index:2;transform:translate(30%,0)}
  169. .app-slide-right-enter-active{z-index:1;transform:translate(0,0)}
  170. .app-slide-right-enter{z-index:1;transform:translate(0,0)}
  171. /**
  172. * 上下模式
  173. */
  174. .app-slide-up-leave-active{z-index:1;transform:translate(0,0)}
  175. .app-slide-up-leave-to{z-index:1;transform:translate(0,0)}
  176. .app-slide-up-enter-active{opacity:0;z-index:2;transform:translate(0,20%)}
  177. .app-slide-up-enter-to{opacity:1;z-index:2;transform:translate(0,0)}
  178. .app-slide-down-leave-active{opacity:1;z-index:2;transform:translate(0,0)}
  179. .app-slide-down-leave-to{opacity:0;z-index:2;transform:translate(0,20%)}
  180. .app-slide-down-enter-active{z-index:1;transform:translate(0,0)}
  181. .app-slide-down-enter{z-index:1;transform:translate(0,0)}
  182. </style>