App.vue 7.8 KB

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