eoss-ui 0.6.67 → 0.6.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/lib/calogin.js +663 -254
  2. package/lib/eoss-ui.common.js +1317 -902
  3. package/lib/flow-list.js +158 -175
  4. package/lib/flow.js +280 -280
  5. package/lib/index.js +1 -1
  6. package/lib/login.js +58 -35
  7. package/lib/main.js +132 -132
  8. package/lib/qr-code.js +13 -13
  9. package/lib/theme-chalk/index.css +1 -1
  10. package/lib/theme-chalk/login.css +1 -1
  11. package/package.json +160 -160
  12. package/packages/.DS_Store +0 -0
  13. package/packages/autocomplete/.DS_Store +0 -0
  14. package/packages/button/index.js +5 -5
  15. package/packages/button/src/main.vue +418 -418
  16. package/packages/button-group/index.js +5 -5
  17. package/packages/button-group/src/main.vue +298 -298
  18. package/packages/calendar/index.js +5 -5
  19. package/packages/calogin/.DS_Store +0 -0
  20. package/packages/calogin/index.js +5 -5
  21. package/packages/calogin/src/main.vue +368 -131
  22. package/packages/calogin/src/plugin.js +915 -748
  23. package/packages/card/index.js +5 -5
  24. package/packages/card/src/main.vue +156 -156
  25. package/packages/cascader/index.js +5 -5
  26. package/packages/cascader/src/main.vue +168 -168
  27. package/packages/checkbox-group/index.js +5 -5
  28. package/packages/checkbox-group/src/main.vue +333 -333
  29. package/packages/clients/index.js +5 -5
  30. package/packages/clients/src/main.vue +151 -151
  31. package/packages/data-table/index.js +5 -5
  32. package/packages/data-table/src/children.vue +39 -39
  33. package/packages/data-table/src/column.vue +989 -989
  34. package/packages/data-table/src/main.vue +1822 -1822
  35. package/packages/data-table/src/sizer.vue +195 -195
  36. package/packages/data-table-form/index.js +5 -5
  37. package/packages/data-table-form/src/checkbox.vue +101 -101
  38. package/packages/data-table-form/src/colgroup.vue +17 -17
  39. package/packages/data-table-form/src/main.vue +181 -181
  40. package/packages/data-table-form/src/radio.vue +65 -65
  41. package/packages/data-table-form/src/table.vue +233 -233
  42. package/packages/data-table-form/src/tbody.vue +336 -336
  43. package/packages/data-table-form/src/thead.vue +68 -68
  44. package/packages/date-picker/.DS_Store +0 -0
  45. package/packages/date-picker/index.js +5 -5
  46. package/packages/date-picker/src/.DS_Store +0 -0
  47. package/packages/date-picker/src/main.vue +236 -236
  48. package/packages/dialog/index.js +5 -5
  49. package/packages/enable-drag/index.js +5 -5
  50. package/packages/enterprise/index.js +5 -5
  51. package/packages/enterprise/src/main.vue +66 -66
  52. package/packages/error-page/index.js +5 -5
  53. package/packages/error-page/src/main.vue +44 -44
  54. package/packages/flow/.DS_Store +0 -0
  55. package/packages/flow/index.js +5 -5
  56. package/packages/flow/src/component/Circulate.vue +351 -351
  57. package/packages/flow/src/component/CommonOpinions.vue +346 -346
  58. package/packages/flow/src/component/CustomPreset.vue +322 -322
  59. package/packages/flow/src/component/FileList.vue +99 -99
  60. package/packages/flow/src/component/Preset.vue +255 -255
  61. package/packages/flow/src/component/SendMsg.vue +241 -241
  62. package/packages/flow/src/component/TimeLimit.vue +190 -190
  63. package/packages/flow/src/component/taskUnionExamine.vue +619 -619
  64. package/packages/flow/src/form.vue +121 -121
  65. package/packages/flow/src/freeStartFlow.vue +2843 -2843
  66. package/packages/flow/src/main.vue +3367 -3367
  67. package/packages/flow/src/processForm.vue +1091 -1091
  68. package/packages/flow/src/processReject.vue +294 -294
  69. package/packages/flow/src/reset.vue +905 -905
  70. package/packages/flow/src/startTaskRead.vue +659 -659
  71. package/packages/flow/src/supervise.vue +149 -149
  72. package/packages/flow/src/table.vue +58 -58
  73. package/packages/flow-group/index.js +5 -5
  74. package/packages/flow-group/src/main.vue +688 -688
  75. package/packages/flow-list/.DS_Store +0 -0
  76. package/packages/flow-list/index.js +5 -5
  77. package/packages/flow-list/src/main.vue +1738 -1757
  78. package/packages/form/index.js +5 -5
  79. package/packages/form/src/main.vue +3581 -3581
  80. package/packages/form/src/table.vue +1426 -1426
  81. package/packages/handle-user/index.js +5 -5
  82. package/packages/handle-user/src/main.vue +138 -138
  83. package/packages/handler/index.js +5 -5
  84. package/packages/handler/src/main.vue +493 -493
  85. package/packages/icon/index.js +5 -5
  86. package/packages/icon/src/main.vue +101 -101
  87. package/packages/icons/index.js +5 -5
  88. package/packages/icons/src/main.vue +81 -81
  89. package/packages/input/index.js +5 -5
  90. package/packages/input/src/main.vue +356 -356
  91. package/packages/input-number/index.js +5 -5
  92. package/packages/input-number/src/main.vue +106 -106
  93. package/packages/label/index.js +5 -5
  94. package/packages/label/src/main.vue +457 -457
  95. package/packages/layout/index.js +5 -5
  96. package/packages/layout/src/item.vue +152 -152
  97. package/packages/layout/src/main.vue +31 -31
  98. package/packages/login/.DS_Store +0 -0
  99. package/packages/login/index.js +5 -5
  100. package/packages/login/src/main.vue +2009 -1988
  101. package/packages/login/src/resetPassword.vue +562 -562
  102. package/packages/main/.DS_Store +0 -0
  103. package/packages/main/index.js +5 -5
  104. package/packages/main/src/.DS_Store +0 -0
  105. package/packages/main/src/default/message.vue +249 -249
  106. package/packages/main/src/default/notice.vue +157 -157
  107. package/packages/main/src/default/userinfo.vue +503 -503
  108. package/packages/main/src/public/online.vue +89 -89
  109. package/packages/main/src/public/search.vue +462 -462
  110. package/packages/main/src/public/settings.vue +221 -221
  111. package/packages/main/src/simplicity/apps.vue +388 -388
  112. package/packages/main/src/simplicity/avatar.vue +83 -83
  113. package/packages/main/src/simplicity/handler.vue +259 -259
  114. package/packages/main/src/simplicity/index.vue +2089 -2089
  115. package/packages/main/src/simplicity/lists.vue +84 -84
  116. package/packages/main/src/simplicity/menu-list.vue +135 -135
  117. package/packages/main/src/simplicity/message.vue +259 -259
  118. package/packages/main/src/simplicity/notice.vue +190 -190
  119. package/packages/main/src/simplicity/router-page.vue +45 -45
  120. package/packages/main/src/simplicity/sub-menu.vue +264 -264
  121. package/packages/main/src/simplicity/user.vue +257 -257
  122. package/packages/main/src/simplicity/userinfo.vue +312 -312
  123. package/packages/menu/.DS_Store +0 -0
  124. package/packages/menu/index.js +5 -5
  125. package/packages/menu/src/main.vue +584 -584
  126. package/packages/nav/index.js +5 -5
  127. package/packages/nav/src/main.vue +351 -351
  128. package/packages/notify/index.js +5 -5
  129. package/packages/notify/src/main.vue +538 -538
  130. package/packages/page/index.js +5 -5
  131. package/packages/page/src/main.vue +167 -167
  132. package/packages/pagination/index.js +5 -5
  133. package/packages/pagination/src/main.vue +96 -96
  134. package/packages/player/index.js +5 -5
  135. package/packages/player/src/main.vue +194 -194
  136. package/packages/qr-code/index.js +5 -5
  137. package/packages/qr-code/src/main.vue +170 -170
  138. package/packages/radio-group/index.js +6 -6
  139. package/packages/radio-group/src/main.vue +319 -319
  140. package/packages/retrial-auth/index.js +5 -5
  141. package/packages/retrial-auth/src/main.vue +280 -280
  142. package/packages/scrollbar/.DS_Store +0 -0
  143. package/packages/select/.DS_Store +0 -0
  144. package/packages/select/index.js +5 -5
  145. package/packages/select/src/main.vue +778 -778
  146. package/packages/select-ganged/index.js +5 -5
  147. package/packages/select-ganged/src/main.vue +724 -724
  148. package/packages/selector/index.js +5 -5
  149. package/packages/selector/src/main.vue +687 -687
  150. package/packages/selector-panel/index.js +5 -5
  151. package/packages/selector-panel/src/main.vue +1027 -1027
  152. package/packages/selector-panel/src/selection.vue +177 -177
  153. package/packages/selector-panel/src/tree.vue +129 -129
  154. package/packages/sizer/index.js +5 -5
  155. package/packages/sizer/src/main.vue +254 -254
  156. package/packages/steps/index.js +5 -5
  157. package/packages/steps/src/main.vue +181 -181
  158. package/packages/switch/index.js +5 -5
  159. package/packages/switch/src/main.vue +154 -154
  160. package/packages/table-form/index.js +5 -5
  161. package/packages/tabs/index.js +5 -5
  162. package/packages/tabs/src/main.vue +788 -788
  163. package/packages/tabs-panel/index.js +5 -5
  164. package/packages/tabs-panel/src/main.vue +29 -29
  165. package/packages/theme-chalk/lib/index.css +1 -1
  166. package/packages/theme-chalk/lib/login.css +1 -1
  167. package/packages/theme-chalk/src/.DS_Store +0 -0
  168. package/packages/theme-chalk/src/base.scss +261 -261
  169. package/packages/theme-chalk/src/button-group.scss +176 -176
  170. package/packages/theme-chalk/src/button.scss +24 -24
  171. package/packages/theme-chalk/src/calendar.scss +113 -113
  172. package/packages/theme-chalk/src/card.scss +99 -99
  173. package/packages/theme-chalk/src/checkbox-group.scss +8 -8
  174. package/packages/theme-chalk/src/clients.scss +87 -87
  175. package/packages/theme-chalk/src/data-table-form.scss +67 -67
  176. package/packages/theme-chalk/src/data-table.scss +293 -293
  177. package/packages/theme-chalk/src/date-picker.scss +7 -7
  178. package/packages/theme-chalk/src/dialog.scss +77 -77
  179. package/packages/theme-chalk/src/enable-drag.scss +181 -181
  180. package/packages/theme-chalk/src/enterprise.scss +5 -5
  181. package/packages/theme-chalk/src/error-page.scss +18 -18
  182. package/packages/theme-chalk/src/flow-group.scss +110 -110
  183. package/packages/theme-chalk/src/flow-list.scss +39 -39
  184. package/packages/theme-chalk/src/flow.scss +343 -343
  185. package/packages/theme-chalk/src/form.scss +496 -496
  186. package/packages/theme-chalk/src/handle-user.scss +40 -40
  187. package/packages/theme-chalk/src/handler.scss +143 -143
  188. package/packages/theme-chalk/src/icon.scss +1792 -1792
  189. package/packages/theme-chalk/src/icons.scss +99 -99
  190. package/packages/theme-chalk/src/input.scss +9 -9
  191. package/packages/theme-chalk/src/label.scss +24 -24
  192. package/packages/theme-chalk/src/layout.scss +46 -46
  193. package/packages/theme-chalk/src/login.scss +981 -981
  194. package/packages/theme-chalk/src/main.scss +663 -663
  195. package/packages/theme-chalk/src/menu.scss +222 -222
  196. package/packages/theme-chalk/src/mixins/color.scss +117 -117
  197. package/packages/theme-chalk/src/nav.scss +111 -111
  198. package/packages/theme-chalk/src/page.scss +3 -3
  199. package/packages/theme-chalk/src/pagination.scss +29 -29
  200. package/packages/theme-chalk/src/player.scss +9 -9
  201. package/packages/theme-chalk/src/qr-code.scss +17 -17
  202. package/packages/theme-chalk/src/radio-group.scss +9 -9
  203. package/packages/theme-chalk/src/retrial-auth.scss +38 -38
  204. package/packages/theme-chalk/src/select-ganged.scss +8 -8
  205. package/packages/theme-chalk/src/select.scss +8 -8
  206. package/packages/theme-chalk/src/selector-panel.scss +204 -204
  207. package/packages/theme-chalk/src/selector.scss +91 -91
  208. package/packages/theme-chalk/src/simplicity.scss +1355 -1355
  209. package/packages/theme-chalk/src/sizer.scss +36 -36
  210. package/packages/theme-chalk/src/steps.scss +88 -88
  211. package/packages/theme-chalk/src/switch.scss +3 -3
  212. package/packages/theme-chalk/src/table-form.scss +1 -1
  213. package/packages/theme-chalk/src/tabs.scss +87 -87
  214. package/packages/theme-chalk/src/tips.scss +7 -7
  215. package/packages/theme-chalk/src/toolbar.scss +179 -179
  216. package/packages/theme-chalk/src/tree-group.scss +72 -72
  217. package/packages/theme-chalk/src/tree.scss +165 -165
  218. package/packages/theme-chalk/src/upload.scss +168 -168
  219. package/packages/theme-chalk/src/wxlogin.scss +3 -3
  220. package/packages/tips/index.js +5 -5
  221. package/packages/tips/src/main.vue +141 -141
  222. package/packages/toolbar/index.js +5 -5
  223. package/packages/toolbar/src/main.vue +430 -430
  224. package/packages/tree/index.js +5 -5
  225. package/packages/tree-group/index.js +5 -5
  226. package/packages/upload/.DS_Store +0 -0
  227. package/packages/upload/index.js +5 -5
  228. package/packages/upload/src/main.vue +1347 -1347
  229. package/packages/upload/src/picture.js +15 -15
  230. package/packages/wujie/index.js +5 -5
  231. package/packages/wujie/src/main.vue +145 -145
  232. package/packages/wxlogin/index.js +5 -5
  233. package/packages/wxlogin/src/main.vue +128 -128
  234. package/src/.DS_Store +0 -0
  235. package/src/config/api.js +291 -291
  236. package/src/config/image.js +2 -2
  237. package/src/index.js +163 -163
  238. package/src/utils/.DS_Store +0 -0
  239. package/src/utils/bus.js +3 -3
  240. package/src/utils/date-util.js +312 -312
  241. package/src/utils/http.js +50 -50
  242. package/src/utils/rules.js +18 -18
  243. package/src/utils/store.js +21 -21
  244. package/src/utils/webSocket.js +107 -107
package/src/utils/http.js CHANGED
@@ -1,50 +1,50 @@
1
- // 封装请求参数
2
- import util from './util.js';
3
-
4
- // function request({
5
- // method = 'get',
6
- // url,
7
- // data = {},
8
- // params = {},
9
- // headers = {},
10
- // format = true,
11
- // mix = true
12
- // }) {
13
- // if (
14
- // method.toLowerCase() === 'post' &&
15
- // !Object.prototype.hasOwnProperty.call(data, 'userId') &&
16
- // util.getStorage('userId')
17
- // ) {
18
- // data.userId = util.getStorage('userId');
19
- // }
20
- // if (
21
- // (method === 'get' || method === 'GET') &&
22
- // !Object.prototype.hasOwnProperty.call(params, 'userId') &&
23
- // util.getStorage('userId')
24
- // ) {
25
- // params.userId = util.getStorage('userId');
26
- // }
27
- // if (format && (method === 'post' || method === 'POST')) {
28
- // data = qs.stringify(data);
29
- // headers['content-type'] = 'application/x-www-form-urlencoded';
30
- // }
31
- // if (!mix && (method === 'get' || method === 'GET')) {
32
- // data = {};
33
- // }
34
- // if (!mix && (method === 'post' || method === 'POST')) {
35
- // params = {};
36
- // }
37
- // return http({
38
- // method,
39
- // url,
40
- // data,
41
- // params,
42
- // headers
43
- // });
44
- // }
45
-
46
- function request(params) {
47
- return util.ajax({mix: true, ...params});
48
- }
49
-
50
- export default request;
1
+ // 封装请求参数
2
+ import util from './util.js';
3
+
4
+ // function request({
5
+ // method = 'get',
6
+ // url,
7
+ // data = {},
8
+ // params = {},
9
+ // headers = {},
10
+ // format = true,
11
+ // mix = true
12
+ // }) {
13
+ // if (
14
+ // method.toLowerCase() === 'post' &&
15
+ // !Object.prototype.hasOwnProperty.call(data, 'userId') &&
16
+ // util.getStorage('userId')
17
+ // ) {
18
+ // data.userId = util.getStorage('userId');
19
+ // }
20
+ // if (
21
+ // (method === 'get' || method === 'GET') &&
22
+ // !Object.prototype.hasOwnProperty.call(params, 'userId') &&
23
+ // util.getStorage('userId')
24
+ // ) {
25
+ // params.userId = util.getStorage('userId');
26
+ // }
27
+ // if (format && (method === 'post' || method === 'POST')) {
28
+ // data = qs.stringify(data);
29
+ // headers['content-type'] = 'application/x-www-form-urlencoded';
30
+ // }
31
+ // if (!mix && (method === 'get' || method === 'GET')) {
32
+ // data = {};
33
+ // }
34
+ // if (!mix && (method === 'post' || method === 'POST')) {
35
+ // params = {};
36
+ // }
37
+ // return http({
38
+ // method,
39
+ // url,
40
+ // data,
41
+ // params,
42
+ // headers
43
+ // });
44
+ // }
45
+
46
+ function request(params) {
47
+ return util.ajax({mix: true, ...params});
48
+ }
49
+
50
+ export default request;
@@ -1,18 +1,18 @@
1
- // 手机号
2
- const phone = {pattern: new RegExp('^[1][3, 4, 5, 6, 7, 8, 9][0-9]{9}$'), message: '手机号不合法'};
3
- // 身份证
4
- const idCard = {pattern: new RegExp('(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)'), message: '身份证号不合法'};
5
- // 座机号
6
- const telephone = {pattern: new RegExp('^(\\d{3,4}-)?\\d{7,8}$'), message: '座机号不合法'};
7
- // IP
8
- const ip = {pattern: new RegExp('^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$'), message: 'IP地址不合法'};
9
- // 银行卡号
10
- const bankCard = {pattern: new RegExp('^([1-9]{1})(\\d{14}|\\d{18})$'), message: '银行卡号不合法'};
11
-
12
- export default {
13
- phone,
14
- idCard,
15
- telephone,
16
- ip,
17
- bankCard
18
- };
1
+ // 手机号
2
+ const phone = {pattern: new RegExp('^[1][3, 4, 5, 6, 7, 8, 9][0-9]{9}$'), message: '手机号不合法'};
3
+ // 身份证
4
+ const idCard = {pattern: new RegExp('(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)'), message: '身份证号不合法'};
5
+ // 座机号
6
+ const telephone = {pattern: new RegExp('^(\\d{3,4}-)?\\d{7,8}$'), message: '座机号不合法'};
7
+ // IP
8
+ const ip = {pattern: new RegExp('^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$'), message: 'IP地址不合法'};
9
+ // 银行卡号
10
+ const bankCard = {pattern: new RegExp('^([1-9]{1})(\\d{14}|\\d{18})$'), message: '银行卡号不合法'};
11
+
12
+ export default {
13
+ phone,
14
+ idCard,
15
+ telephone,
16
+ ip,
17
+ bankCard
18
+ };
@@ -1,21 +1,21 @@
1
- let store = {
2
- state: {},
3
- set(name, value) {
4
- this.state[name] = value;
5
- },
6
- get(name) {
7
- return this.state[name];
8
- },
9
- clear(name) {
10
- this.state[name] = null;
11
- },
12
- remove(name) {
13
- if (name) {
14
- delete this.state[name];
15
- } else {
16
- this.state = {};
17
- }
18
- }
19
- };
20
- window.__store = store;
21
- export default store;
1
+ let store = {
2
+ state: {},
3
+ set(name, value) {
4
+ this.state[name] = value;
5
+ },
6
+ get(name) {
7
+ return this.state[name];
8
+ },
9
+ clear(name) {
10
+ this.state[name] = null;
11
+ },
12
+ remove(name) {
13
+ if (name) {
14
+ delete this.state[name];
15
+ } else {
16
+ this.state = {};
17
+ }
18
+ }
19
+ };
20
+ window.__store = store;
21
+ export default store;
@@ -1,107 +1,107 @@
1
- import SockJS from 'sockjs-client';
2
- import Stomp from 'stompjs';
3
- class WebSocket {
4
- // 构造函数
5
- constructor() {
6
- this.host = sessionStorage.getItem('wshost') || '';
7
- this.tryTimes = 1; // 重连次数
8
- this.callback = null; // 回调函数
9
- this.client = null; // stomp对象
10
- this.reconTimeout = null; // 重连延时器
11
- this.debug = true; // 调试
12
- this.interval = 20; // 重连间隔时间
13
- this.vm = null;
14
- this.nextDate = 0;
15
- this.connects = 1;
16
- this.recon = false;
17
- this.sendTimeout = null;
18
- this.socket = null;
19
- this.subscription = null;
20
- }
21
-
22
- /** socket连接 */
23
- connect() {
24
- if (!this.client) {
25
- // 连接SockJS
26
- this.socket = new SockJS(this.host + this.url, {timeout: 60000});
27
- this.client = Stomp.over(this.socket);
28
- }
29
-
30
- // 日志不打印
31
- if (!this.debug) {
32
- this.client.debug = () => {};
33
- }
34
-
35
- // 向服务器发起websocket连接
36
- this.client.connect({}, () => {
37
- this.recon = true;
38
- // tryTimes定义重置
39
- this.connects = 1;
40
- // 订阅消息
41
- this.subscribe();
42
- }, (error) => {
43
- this.unsubscribe();
44
- this.client = null;
45
- let diffSecond = parseInt((new Date() - this.nextDate) / 1000, 10);
46
- if (this.connects > 5 && diffSecond < this.interval) {
47
- this.error && this.error(error);
48
- } else {
49
- this.reconTimeout = setTimeout(() => {
50
- this.connect();
51
- this.connects++;
52
- }, 5000);
53
- }
54
- });
55
- }// 清除订阅
56
- unsubscribe() {
57
- if (this.subscription) {
58
- this.subscription.unsubscribe();
59
- this.subscription = null;
60
- }
61
- }
62
- /** 订阅服务端 */
63
- subscribe() {
64
- // 订阅服务端提供的某个topic
65
- this.subscription = this.client.subscribe(this.take, (response) => {
66
- if (response && (this.callback || this.success)) {
67
- let callback = this.callback || this.success;
68
- callback(JSON.parse(response.body));
69
- }
70
- });
71
- }
72
-
73
- /** 赋值、初始化socket */
74
- init(option, vm) {
75
- for (let i in option) {
76
- this[i] = option[i];
77
- }
78
- this.vm = vm;
79
- // 初始化连接
80
- this.connect();
81
- }
82
-
83
- /** 发送消息 */
84
- send(data) {
85
- if (this.recon) {
86
- clearTimeout(this.sendTimeout);
87
- this.client.send(this.take, {}, typeof data === 'string' ? data : JSON.stringify(data));
88
- } else {
89
- this.sendTimeout = setTimeout(() => {
90
- this.send(data);
91
- }, 1000);
92
- }
93
- }
94
-
95
- /** 销毁 */
96
- destroy() {
97
- // 断开连接,清除定时器
98
- this.unsubscribe();
99
- if (this.client) {
100
- this.client.disconnect();
101
- };
102
- this.reconTimeout && clearTimeout(this.reconTimeout);
103
- this.sendTimeout && clearTimeout(this.sendTimeout);
104
- }
105
- }
106
-
107
- export default WebSocket;
1
+ import SockJS from 'sockjs-client';
2
+ import Stomp from 'stompjs';
3
+ class WebSocket {
4
+ // 构造函数
5
+ constructor() {
6
+ this.host = sessionStorage.getItem('wshost') || '';
7
+ this.tryTimes = 1; // 重连次数
8
+ this.callback = null; // 回调函数
9
+ this.client = null; // stomp对象
10
+ this.reconTimeout = null; // 重连延时器
11
+ this.debug = true; // 调试
12
+ this.interval = 20; // 重连间隔时间
13
+ this.vm = null;
14
+ this.nextDate = 0;
15
+ this.connects = 1;
16
+ this.recon = false;
17
+ this.sendTimeout = null;
18
+ this.socket = null;
19
+ this.subscription = null;
20
+ }
21
+
22
+ /** socket连接 */
23
+ connect() {
24
+ if (!this.client) {
25
+ // 连接SockJS
26
+ this.socket = new SockJS(this.host + this.url, {timeout: 60000});
27
+ this.client = Stomp.over(this.socket);
28
+ }
29
+
30
+ // 日志不打印
31
+ if (!this.debug) {
32
+ this.client.debug = () => {};
33
+ }
34
+
35
+ // 向服务器发起websocket连接
36
+ this.client.connect({}, () => {
37
+ this.recon = true;
38
+ // tryTimes定义重置
39
+ this.connects = 1;
40
+ // 订阅消息
41
+ this.subscribe();
42
+ }, (error) => {
43
+ this.unsubscribe();
44
+ this.client = null;
45
+ let diffSecond = parseInt((new Date() - this.nextDate) / 1000, 10);
46
+ if (this.connects > 5 && diffSecond < this.interval) {
47
+ this.error && this.error(error);
48
+ } else {
49
+ this.reconTimeout = setTimeout(() => {
50
+ this.connect();
51
+ this.connects++;
52
+ }, 5000);
53
+ }
54
+ });
55
+ }// 清除订阅
56
+ unsubscribe() {
57
+ if (this.subscription) {
58
+ this.subscription.unsubscribe();
59
+ this.subscription = null;
60
+ }
61
+ }
62
+ /** 订阅服务端 */
63
+ subscribe() {
64
+ // 订阅服务端提供的某个topic
65
+ this.subscription = this.client.subscribe(this.take, (response) => {
66
+ if (response && (this.callback || this.success)) {
67
+ let callback = this.callback || this.success;
68
+ callback(JSON.parse(response.body));
69
+ }
70
+ });
71
+ }
72
+
73
+ /** 赋值、初始化socket */
74
+ init(option, vm) {
75
+ for (let i in option) {
76
+ this[i] = option[i];
77
+ }
78
+ this.vm = vm;
79
+ // 初始化连接
80
+ this.connect();
81
+ }
82
+
83
+ /** 发送消息 */
84
+ send(data) {
85
+ if (this.recon) {
86
+ clearTimeout(this.sendTimeout);
87
+ this.client.send(this.take, {}, typeof data === 'string' ? data : JSON.stringify(data));
88
+ } else {
89
+ this.sendTimeout = setTimeout(() => {
90
+ this.send(data);
91
+ }, 1000);
92
+ }
93
+ }
94
+
95
+ /** 销毁 */
96
+ destroy() {
97
+ // 断开连接,清除定时器
98
+ this.unsubscribe();
99
+ if (this.client) {
100
+ this.client.disconnect();
101
+ };
102
+ this.reconTimeout && clearTimeout(this.reconTimeout);
103
+ this.sendTimeout && clearTimeout(this.sendTimeout);
104
+ }
105
+ }
106
+
107
+ export default WebSocket;