App.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. let token = $A.hashParameter("token");
  24. if ($A.count(token) > 10) {
  25. $.setToken(token);
  26. $A.getUserInfo(true);
  27. let path = $A.removeURLParameter(window.location.href,'token');
  28. if ($A.strExists(path, "#")) {
  29. this.goForward({path: $A.getMiddle(path, '#')}, true);
  30. }
  31. }
  32. //
  33. this.sessionStorage('/', 1);
  34. //
  35. let hash = window.location.hash;
  36. if (hash.indexOf("#") === 0) {
  37. hash = hash.substr(1);
  38. if (hash !== '/' && this.sessionStorage(hash) === 0) {
  39. this.sessionStorage(hash, this.sessionStorage('::count') + 1);
  40. }
  41. }
  42. //
  43. setInterval(() => {
  44. this.searchEnter();
  45. }, 1000);
  46. //
  47. this.handleWebSocket();
  48. $A.setOnUserInfoListener("app", () => { this.handleWebSocket() });
  49. },
  50. watch: {
  51. '$route' (To, From) {
  52. if (this.transitionName === null) {
  53. this.transitionName = 'app-slide-no';
  54. return;
  55. }
  56. if (typeof To.name === 'undefined' || typeof From.name === 'undefined') {
  57. return;
  58. }
  59. this.slideType(To, From)
  60. }
  61. },
  62. methods: {
  63. slideType(To, From) {
  64. let isBack = this.$router.isBack;
  65. this.$router.isBack = false;
  66. //
  67. let ToIndex = this.sessionStorage(To.path);
  68. let FromIndex = this.sessionStorage(From.path);
  69. if (ToIndex && ToIndex < FromIndex) {
  70. isBack = true; //后退
  71. this.sessionStorage(true, ToIndex);
  72. }else{
  73. isBack = false; //前进
  74. this.sessionStorage(To.path, this.sessionStorage('::count') + 1);
  75. }
  76. //
  77. if (To.meta.slide === false || From.meta.slide === false)
  78. {
  79. //取消动画
  80. this.transitionName = 'app-slide-no'
  81. }
  82. else if (To.meta.slide === 'up' || From.meta.slide === 'up' || To.meta.slide === 'down' || From.meta.slide === 'down')
  83. {
  84. //上下动画
  85. if (isBack) {
  86. this.transitionName = 'app-slide-down'
  87. } else {
  88. this.transitionName = 'app-slide-up'
  89. }
  90. }
  91. else
  92. {
  93. //左右动画(默认)
  94. if (isBack) {
  95. this.transitionName = 'app-slide-right'
  96. } else {
  97. this.transitionName = 'app-slide-left'
  98. }
  99. }
  100. },
  101. sessionStorage(path, num) {
  102. let conut = 0;
  103. let history = JSON.parse(window.sessionStorage['__history__'] || '{}');
  104. if (path === true) {
  105. let items = {};
  106. for(let i in history){
  107. if (history.hasOwnProperty(i)) {
  108. if (parseInt(history[i]) <= num) {
  109. items[i] = history[i];
  110. conut++;
  111. }
  112. }
  113. }
  114. history = items;
  115. history['::count'] = Math.max(num, conut);
  116. window.sessionStorage['__history__'] = JSON.stringify(history);
  117. return history;
  118. }
  119. if (typeof num === 'undefined') {
  120. return parseInt(history[path] || 0);
  121. }
  122. if (path === "/") num = 1;
  123. history[path] = num;
  124. for(let key in history){ if (history.hasOwnProperty(key) && key !== '::count') { conut++; } }
  125. history['::count'] = Math.max(num, conut);
  126. window.sessionStorage['__history__'] = JSON.stringify(history);
  127. },
  128. searchEnter() {
  129. let row = $A(".sreachBox");
  130. if (row.length === 0) {
  131. return;
  132. }
  133. if (row.attr("data-enter-init") === "init") {
  134. return;
  135. }
  136. row.attr("data-enter-init", "init");
  137. //
  138. let buttons = row.find("button[type='button']");
  139. let button = null;
  140. if (buttons.length === 0) {
  141. return;
  142. }
  143. buttons.each((index, item) => {
  144. if ($A(item).text().indexOf("搜索")) {
  145. button = $A(item);
  146. }
  147. });
  148. if (button === null) {
  149. return;
  150. }
  151. row.find("input.ivu-input").keydown(function(e) {
  152. if (e.keyCode == 13) {
  153. if (!button.hasClass("ivu-btn-loading") ) {
  154. button.click();
  155. }
  156. }
  157. });
  158. },
  159. handleWebSocket() {
  160. if ($A.getToken() === false) {
  161. $A.WSOB.close();
  162. } else {
  163. $A.WSOB.setOnMsgListener("app", (msgDetail) => {
  164. if (msgDetail.username == $A.getUserName()) {
  165. return;
  166. }
  167. switch (msgDetail.messageType) {
  168. case 'open':
  169. window.localStorage.setItem("__::WookTeam:config", $A.jsonStringify(msgDetail.config));
  170. break;
  171. case 'close':
  172. window.localStorage.setItem("__::WookTeam:config", $A.jsonStringify({}));
  173. break;
  174. case 'info':
  175. if (msgDetail.body.type == 'update') {
  176. $A.getUserInfo(true);
  177. }
  178. break;
  179. case 'user':
  180. if (msgDetail.body.type == 'taskA') {
  181. $A.triggerTaskInfoListener(msgDetail.body.act, msgDetail.body.taskDetail, false);
  182. }
  183. break;
  184. case 'kick':
  185. $A.token("");
  186. $A.storage("userInfo", {});
  187. $A.triggerUserInfoListener({});
  188. //
  189. let id = 'inip_' + Math.round(Math.random() * 10000);
  190. let ip = msgDetail.body.ip;
  191. let ip2 = ip.substring(0, ip.lastIndexOf('.')) + '.*';
  192. this.$Modal.warning({
  193. title: this.$L("系统提示"),
  194. content: this.$L('您的帐号在其他地方(%)登录,您被迫退出,如果这不是您本人的操作,请注意帐号安全!', '<span id="' + id + '">' + ip2 + '</span>'),
  195. onOk: () => {
  196. this.goForward({path: '/'}, true);
  197. }
  198. });
  199. this.$nextTick(() => {
  200. $A.getIpInfo(ip, (res) => {
  201. if (res.ret === 1) {
  202. $A("span#" + id).text(res.data.textSmall);
  203. $A("span#" + id).attr("title", ip2);
  204. }
  205. });
  206. });
  207. break;
  208. }
  209. });
  210. }
  211. }
  212. }
  213. }
  214. </script>
  215. <style>
  216. body { overflow-x: hidden; }
  217. </style>
  218. <!--suppress CssUnusedSymbol -->
  219. <style scoped>
  220. .child-view {
  221. position: absolute;
  222. width: 100%;
  223. min-height: 100%;
  224. background-color: #f1f2f7;
  225. transition: all .3s cubic-bezier(.55, 0, .1, 1);
  226. }
  227. .app-slide-no-leave-to {display: none;}
  228. /**
  229. * 左右模式
  230. */
  231. .app-slide-left-leave-active{z-index:1;transform:translate(0,0)}
  232. .app-slide-left-leave-to{z-index:1;transform:translate(0,0)}
  233. .app-slide-left-enter-active{opacity:0;z-index:2;transform:translate(30%,0)}
  234. .app-slide-left-enter-to{opacity:1;z-index:2;transform:translate(0,0)}
  235. .app-slide-right-leave-active{opacity:1;z-index:2;transform:translate(0,0)}
  236. .app-slide-right-leave-to{opacity:0;z-index:2;transform:translate(30%,0)}
  237. .app-slide-right-enter-active{z-index:1;transform:translate(0,0)}
  238. .app-slide-right-enter{z-index:1;transform:translate(0,0)}
  239. /**
  240. * 上下模式
  241. */
  242. .app-slide-up-leave-active{z-index:1;transform:translate(0,0)}
  243. .app-slide-up-leave-to{z-index:1;transform:translate(0,0)}
  244. .app-slide-up-enter-active{opacity:0;z-index:2;transform:translate(0,20%)}
  245. .app-slide-up-enter-to{opacity:1;z-index:2;transform:translate(0,0)}
  246. .app-slide-down-leave-active{opacity:1;z-index:2;transform:translate(0,0)}
  247. .app-slide-down-leave-to{opacity:0;z-index:2;transform:translate(0,20%)}
  248. .app-slide-down-enter-active{z-index:1;transform:translate(0,0)}
  249. .app-slide-down-enter{z-index:1;transform:translate(0,0)}
  250. </style>