App.vue 11 KB

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