App.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 == 'forced') {
  158. $A.token("");
  159. $A.storage("userInfo", {});
  160. $A.triggerUserInfoListener({});
  161. //
  162. let content = $A.jsonParse(msgDetail.content)
  163. let id = 'inip_' + Math.round(Math.random() * 10000);
  164. let ip = content.ip;
  165. let ip2 = ip.substring(0, ip.lastIndexOf('.')) + '.*';
  166. this.$Modal.warning({
  167. title: this.$L("系统提示"),
  168. content: this.$L('您的帐号在其他地方(%)登录,您被迫退出,如果这不是您本人的操作,请注意帐号安全!', '<span id="' + id + '">' + ip2 + '</span>'),
  169. onOk: () => {
  170. this.goForward({path: '/'}, true);
  171. }
  172. });
  173. this.$nextTick(() => {
  174. $A.getIpInfo(ip, (res) => {
  175. if (res.ret === 1) {
  176. $A("span#" + id).text(res.data.textSmall);
  177. $A("span#" + id).attr("title", ip2);
  178. }
  179. });
  180. });
  181. return;
  182. } else if (msgDetail.messageType != 'send') {
  183. return;
  184. }
  185. let content = $A.jsonParse(msgDetail.content)
  186. if (content.type == 'taskA') {
  187. $A.triggerTaskInfoListener(content.act, content.taskDetail, false);
  188. }
  189. }).connection(force);
  190. }
  191. }
  192. }
  193. }
  194. </script>
  195. <style>
  196. body { overflow-x: hidden; }
  197. </style>
  198. <!--suppress CssUnusedSymbol -->
  199. <style scoped>
  200. .child-view {
  201. position: absolute;
  202. width: 100%;
  203. min-height: 100%;
  204. background-color: #f1f2f7;
  205. transition: all .3s cubic-bezier(.55, 0, .1, 1);
  206. }
  207. .app-slide-no-leave-to {display: none;}
  208. /**
  209. * 左右模式
  210. */
  211. .app-slide-left-leave-active{z-index:1;transform:translate(0,0)}
  212. .app-slide-left-leave-to{z-index:1;transform:translate(0,0)}
  213. .app-slide-left-enter-active{opacity:0;z-index:2;transform:translate(30%,0)}
  214. .app-slide-left-enter-to{opacity:1;z-index:2;transform:translate(0,0)}
  215. .app-slide-right-leave-active{opacity:1;z-index:2;transform:translate(0,0)}
  216. .app-slide-right-leave-to{opacity:0;z-index:2;transform:translate(30%,0)}
  217. .app-slide-right-enter-active{z-index:1;transform:translate(0,0)}
  218. .app-slide-right-enter{z-index:1;transform:translate(0,0)}
  219. /**
  220. * 上下模式
  221. */
  222. .app-slide-up-leave-active{z-index:1;transform:translate(0,0)}
  223. .app-slide-up-leave-to{z-index:1;transform:translate(0,0)}
  224. .app-slide-up-enter-active{opacity:0;z-index:2;transform:translate(0,20%)}
  225. .app-slide-up-enter-to{opacity:1;z-index:2;transform:translate(0,0)}
  226. .app-slide-down-leave-active{opacity:1;z-index:2;transform:translate(0,0)}
  227. .app-slide-down-leave-to{opacity:0;z-index:2;transform:translate(0,20%)}
  228. .app-slide-down-enter-active{z-index:1;transform:translate(0,0)}
  229. .app-slide-down-enter{z-index:1;transform:translate(0,0)}
  230. </style>