App.vue 7.6 KB

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