App.vue 7.9 KB

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