eoss-ui 0.5.11 → 0.5.12

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 (65) hide show
  1. package/lib/button-group.js +228 -124
  2. package/lib/button.js +167 -75
  3. package/lib/card.js +2 -2
  4. package/lib/cascader.js +2 -2
  5. package/lib/checkbox-group.js +166 -75
  6. package/lib/clients.js +2 -2
  7. package/lib/data-table-form.js +165 -74
  8. package/lib/data-table.js +185 -94
  9. package/lib/date-picker.js +172 -80
  10. package/lib/dialog.js +174 -83
  11. package/lib/enterprise.js +2 -2
  12. package/lib/eoss-ui.common.js +316 -183
  13. package/lib/error-page.js +2 -2
  14. package/lib/flow-group.js +165 -73
  15. package/lib/flow-list.js +200 -83
  16. package/lib/flow.js +200 -92
  17. package/lib/form.js +258 -151
  18. package/lib/handle-user.js +168 -76
  19. package/lib/handler.js +166 -74
  20. package/lib/icons.js +4 -4
  21. package/lib/index.js +1 -1
  22. package/lib/input-number.js +167 -75
  23. package/lib/input.js +169 -77
  24. package/lib/label.js +2 -2
  25. package/lib/layout.js +4 -4
  26. package/lib/login.js +168 -77
  27. package/lib/main.js +209 -118
  28. package/lib/menu.js +2 -2
  29. package/lib/nav.js +167 -75
  30. package/lib/notify.js +2 -2
  31. package/lib/page.js +167 -75
  32. package/lib/pagination.js +2 -2
  33. package/lib/player.js +173 -81
  34. package/lib/qr-code.js +169 -77
  35. package/lib/radio-group.js +167 -75
  36. package/lib/retrial-auth.js +167 -75
  37. package/lib/select-ganged.js +165 -73
  38. package/lib/select.js +166 -74
  39. package/lib/selector-panel.js +166 -75
  40. package/lib/selector.js +167 -75
  41. package/lib/sizer.js +169 -77
  42. package/lib/steps.js +167 -75
  43. package/lib/switch.js +167 -75
  44. package/lib/table-form.js +167 -75
  45. package/lib/tabs-panel.js +2 -2
  46. package/lib/tabs.js +170 -78
  47. package/lib/tips.js +167 -75
  48. package/lib/toolbar.js +2 -2
  49. package/lib/tree-group.js +165 -73
  50. package/lib/tree.js +165 -73
  51. package/lib/upload.js +168 -77
  52. package/lib/utils/util.js +17 -61
  53. package/lib/utils/webSocket.js +134 -0
  54. package/lib/wujie.js +167 -75
  55. package/lib/wxlogin.js +167 -75
  56. package/package.json +1 -1
  57. package/packages/data-table/src/main.vue +2 -2
  58. package/packages/data-table/src/sizer.vue +1 -1
  59. package/packages/flow/src/main.vue +2 -0
  60. package/packages/flow/src/processForm.vue +23 -9
  61. package/packages/flow-list/src/main.vue +25 -2
  62. package/packages/main/src/main.vue +13 -14
  63. package/src/index.js +1 -1
  64. package/src/utils/util.js +38 -81
  65. package/src/utils/webSocket.js +103 -0
@@ -451,8 +451,8 @@ export default {
451
451
  },
452
452
  theads: {
453
453
  get() {
454
- if (typeof this.thead === 'string') {
455
- this.theadData.length && this.setMinWidth(this.theadData);
454
+ if (this.theadData.length) {
455
+ this.setMinWidth(this.theadData);
456
456
  return this.theadData;
457
457
  }
458
458
  this.setMinWidth(this.thead);
@@ -95,7 +95,7 @@ export default {
95
95
  this.visible = true;
96
96
  },
97
97
  getThead(res, data) {
98
- res.forEach(item => {
98
+ res.forEach((item) => {
99
99
  if (
100
100
  item.type !== 'index' &&
101
101
  item.type !== 'selection' &&
@@ -307,6 +307,7 @@
307
307
  :multiple="true"
308
308
  :selectUserList="selectReadUserList"
309
309
  :options="userOptions"
310
+ title="分阅用户"
310
311
  :mix="true"
311
312
  :types="types"
312
313
  @change="changeSelectReadUser($event, 'nextReadUserId')"
@@ -327,6 +328,7 @@
327
328
  :options="presetOptions"
328
329
  :radioList="presetReadUserId"
329
330
  :presetEdit="1"
331
+ title="分阅用户"
330
332
  :mix="true"
331
333
  :types="types"
332
334
  @change="changeSelectReadUser($event, 'presetReadUserId')"
@@ -145,6 +145,7 @@
145
145
  :multiple="true"
146
146
  :selectUserList="selectReadUserList"
147
147
  :options="userOptions"
148
+ title="分阅用户"
148
149
  :mix="true"
149
150
  :types="types"
150
151
  @change="changeSelectReadUser($event, 'nextReadUserId')"
@@ -163,6 +164,7 @@
163
164
  :multiple="true"
164
165
  :selectUserList="selectPresetUserList"
165
166
  :options="presetOptions"
167
+ title="分阅用户"
166
168
  :radioList="presetReadUserId"
167
169
  :presetEdit="1"
168
170
  :mix="true"
@@ -181,10 +183,7 @@
181
183
  v-model="nextNode.handleExplain"
182
184
  />
183
185
  </el-form-item>
184
- <el-form-item
185
- prop="noticeType"
186
- label="通知方式"
187
- >
186
+ <el-form-item prop="noticeType" label="通知方式">
188
187
  <el-checkbox-group v-model="nextNode.noticeType">
189
188
  <el-checkbox
190
189
  v-for="item of nextNode.noticeList"
@@ -331,11 +330,17 @@ export default {
331
330
  tabs: {
332
331
  employee: {
333
332
  param: {
334
- filid: sessionStorage.getItem('orgId'),
333
+ filid: JSON.parse(sessionStorage.getItem('mainConfig')).userModel
334
+ .orgId,
335
335
  name: '本单位用户'
336
336
  }
337
337
  },
338
- department: { param: { filid: sessionStorage.getItem('orgId') } }
338
+ department: {
339
+ param: {
340
+ filid: JSON.parse(sessionStorage.getItem('mainConfig')).userModel
341
+ .orgId
342
+ }
343
+ }
339
344
  },
340
345
  nextUserTabs: {},
341
346
  selectPresetUserList: [],
@@ -383,7 +388,6 @@ export default {
383
388
  mounted() {
384
389
  this.getStartFlow(this.processDefinitionId);
385
390
  this.newOpinion = this.opinion;
386
-
387
391
  },
388
392
  methods: {
389
393
  getIsShowNextUser(val) {
@@ -401,7 +405,12 @@ export default {
401
405
  if (val == 7 || val == 8) {
402
406
  this.nextUserTypes = ['department'];
403
407
  this.nextUserTabs = {
404
- department: { param: { filid: sessionStorage.getItem('orgId') } }
408
+ department: {
409
+ param: {
410
+ filid: JSON.parse(sessionStorage.getItem('mainConfig'))
411
+ .userModel.orgId
412
+ }
413
+ }
405
414
  };
406
415
  this.multiple = true;
407
416
  } else if (val == 9 || val == 10) {
@@ -412,7 +421,12 @@ export default {
412
421
  this.nextUserTypes = ['department', 'enterprise'];
413
422
  this.nextUserTabs = {
414
423
  enterprise: { param: { filid: 'other' } },
415
- department: { param: { filid: sessionStorage.getItem('orgId') } }
424
+ department: {
425
+ param: {
426
+ filid: JSON.parse(sessionStorage.getItem('mainConfig'))
427
+ .userModel.orgId
428
+ }
429
+ }
416
430
  };
417
431
  this.multiple = true;
418
432
  }
@@ -8,7 +8,7 @@
8
8
  (item.type == 'splitReading' &&
9
9
  splitReadingData &&
10
10
  splitReadingData.length > 0) ||
11
- (item.type == 'preset' && presetData && presetData.length > 0) ||
11
+ (item.type == 'preset' && presetData && presetData.length > 0 && currentUserHasPresetInfoAuth) ||
12
12
  (item.type != 'splitReading' && item.type != 'preset')
13
13
  "
14
14
  >
@@ -128,6 +128,7 @@ export default {
128
128
  pressTableList: [],
129
129
  currentPage: 1,
130
130
  pageSize: 20,
131
+ currentUserHasPresetInfoAuth:false,
131
132
  pressThead: [
132
133
  {
133
134
  title: '催办节点',
@@ -320,6 +321,7 @@ export default {
320
321
  label: '经办部门',
321
322
  field: 'deptid',
322
323
  align: 'center',
324
+ key:'jbbm',
323
325
  showOverflowTooltip: true,
324
326
  width: 150
325
327
  },
@@ -327,6 +329,7 @@ export default {
327
329
  label: '步骤',
328
330
  field: 'itemname',
329
331
  align: 'center',
332
+ key:'bz',
330
333
  showOverflowTooltip: true,
331
334
  width: 110
332
335
  },
@@ -334,6 +337,7 @@ export default {
334
337
  label: '办理人',
335
338
  field: 'userName',
336
339
  align: 'center',
340
+ key:'blr',
337
341
  showOverflowTooltip: true,
338
342
  width: 110
339
343
  },
@@ -342,11 +346,13 @@ export default {
342
346
  field: 'deptName',
343
347
  align: 'center',
344
348
  showOverflowTooltip: true,
349
+ key:'blrbm',
345
350
  width: 110
346
351
  },
347
352
  {
348
353
  label: '状态',
349
354
  field: 'pendstate',
355
+ key:'zt',
350
356
  align: 'center',
351
357
  showOverflowTooltip: true,
352
358
  width: 80,
@@ -369,6 +375,7 @@ export default {
369
375
  field: 'doresult',
370
376
  align: 'center',
371
377
  showOverflowTooltip: true,
378
+ key:'blyj',
372
379
  render: (h, params) => {
373
380
  return h(
374
381
  'span',
@@ -381,6 +388,7 @@ export default {
381
388
  label: '验签',
382
389
  field: 'authTypeStr',
383
390
  align: 'center',
391
+ key:'yq',
384
392
  showOverflowTooltip: true,
385
393
  width: 70,
386
394
  render: (h, params) => {
@@ -393,6 +401,7 @@ export default {
393
401
  },
394
402
  {
395
403
  label: '附件',
404
+ key:'fj',
396
405
  field: 'hasAdjunct',
397
406
  align: 'center',
398
407
  showOverflowTooltip: true,
@@ -414,6 +423,7 @@ export default {
414
423
  label: '时间',
415
424
  field: 'doetime',
416
425
  align: 'center',
426
+ key:'sj',
417
427
  showOverflowTooltip: true,
418
428
  width: 150,
419
429
  render: (h, params) => {
@@ -428,6 +438,7 @@ export default {
428
438
  label: '代办人',
429
439
  field: 'douserid',
430
440
  align: 'center',
441
+ key:'dbr',
431
442
  showOverflowTooltip: true,
432
443
  width: 80,
433
444
  hide: _that.flowTableInfo.hasAgent != '1'
@@ -436,6 +447,7 @@ export default {
436
447
  label: '催办',
437
448
  field: 'pressTimes',
438
449
  align: 'center',
450
+ key:'cb',
439
451
  showOverflowTooltip: true,
440
452
  width: 150,
441
453
  render: (h, params) => {
@@ -472,6 +484,7 @@ export default {
472
484
  {
473
485
  label: '经办部门',
474
486
  field: 'deptid',
487
+ key:'jbbm',
475
488
  align: 'center',
476
489
  showOverflowTooltip: true,
477
490
  width: 150
@@ -480,6 +493,7 @@ export default {
480
493
  label: '步骤',
481
494
  field: 'itemname',
482
495
  align: 'center',
496
+ key:'bz',
483
497
  showOverflowTooltip: true,
484
498
  width: 110
485
499
  },
@@ -487,6 +501,7 @@ export default {
487
501
  label: '办理人',
488
502
  field: 'userName',
489
503
  align: 'center',
504
+ key:'blr',
490
505
  showOverflowTooltip: true,
491
506
  width: 110
492
507
  },
@@ -494,6 +509,7 @@ export default {
494
509
  label: '状态',
495
510
  field: 'pendstate',
496
511
  align: 'center',
512
+ key:'zt',
497
513
  showOverflowTooltip: true,
498
514
  width: 80,
499
515
  render: (h, params) => {
@@ -514,6 +530,7 @@ export default {
514
530
  label: '办理意见',
515
531
  field: 'doresult',
516
532
  align: 'center',
533
+ key:'blyj',
517
534
  showOverflowTooltip: true,
518
535
  render: (h, params) => {
519
536
  return h(
@@ -527,6 +544,7 @@ export default {
527
544
  label: '验签',
528
545
  field: 'authTypeStr',
529
546
  align: 'center',
547
+ key:'yq',
530
548
  showOverflowTooltip: true,
531
549
  width: 70,
532
550
  render: (h, params) => {
@@ -541,6 +559,7 @@ export default {
541
559
  label: '附件',
542
560
  field: 'hasAdjunct',
543
561
  align: 'center',
562
+ key:'fj',
544
563
  showOverflowTooltip: true,
545
564
  width: 70,
546
565
  render: (h, params) => {
@@ -560,6 +579,7 @@ export default {
560
579
  label: '时间',
561
580
  field: 'doetime',
562
581
  align: 'center',
582
+ key:'sj',
563
583
  showOverflowTooltip: true,
564
584
  width: 150,
565
585
  render: (h, params) => {
@@ -574,6 +594,7 @@ export default {
574
594
  label: '代办人',
575
595
  field: 'douserid',
576
596
  align: 'center',
597
+ key:'dbr',
577
598
  showOverflowTooltip: true,
578
599
  width: 80,
579
600
  hide: _that.flowTableInfo.hasAgent != '1'
@@ -582,6 +603,7 @@ export default {
582
603
  label: '催办',
583
604
  field: 'pressTimes',
584
605
  align: 'center',
606
+ key:'cb',
585
607
  showOverflowTooltip: true,
586
608
  width: 150,
587
609
  render: (h, params) => {
@@ -1084,12 +1106,13 @@ export default {
1084
1106
  const {
1085
1107
  status,
1086
1108
  message,
1087
- data: { presetInfoList, presetInfoListHiddenColumns, canDelete }
1109
+ data: { presetInfoList, presetInfoListHiddenColumns, canDelete,currentUserHasPresetInfoAuth }
1088
1110
  } = res;
1089
1111
  this.loading.close();
1090
1112
  if (status == 'success') {
1091
1113
  presetInfoList && (this.presetData = presetInfoList);
1092
1114
  this.presetInfoListHiddenColumns = presetInfoListHiddenColumns;
1115
+ this.currentUserHasPresetInfoAuth = currentUserHasPresetInfoAuth
1093
1116
  this.canDelete = canDelete;
1094
1117
  } else {
1095
1118
  this.$message.error(message || '系统错误,请联系管理员!');
@@ -254,6 +254,8 @@ import notice from './notice.vue';
254
254
  import AsyncComponent from './async-component/index.vue';
255
255
  import {
256
256
  //authCenter,
257
+ wss,
258
+ topic,
257
259
  mainConfig,
258
260
  updateUserCustomInfo,
259
261
  getComplexApplications,
@@ -540,8 +542,6 @@ export default {
540
542
  copyright: { comp: '', data: {} }
541
543
  },
542
544
  pageLoading: false,
543
- close: null,
544
- connect: 0,
545
545
  wjName: 'singlespa',
546
546
  menus: '',
547
547
  //头部导航
@@ -618,7 +618,8 @@ export default {
618
618
  navIds: null,
619
619
  timer: null,
620
620
  pid: null,
621
- showPage: false
621
+ showPage: false,
622
+ webSocket: null
622
623
  };
623
624
  },
624
625
  created() {
@@ -1874,11 +1875,11 @@ export default {
1874
1875
  },
1875
1876
  //开启weosocket
1876
1877
  initWebSocket() {
1877
- util
1878
- .socket()
1879
- .then((res, close) => {
1880
- this.close = close;
1881
- let data = res.data;
1878
+ this.webSocket = util.socket({
1879
+ url: wss,
1880
+ take: topic,
1881
+ success: (res) => {
1882
+ let data = res.data || {};
1882
1883
  for (let i in data) {
1883
1884
  if (data[i] !== null && data[i] !== undefined) {
1884
1885
  if (i === 'onlineUserNums' && data[i] > 0) {
@@ -1910,10 +1911,8 @@ export default {
1910
1911
  if (util.win.eventBus) {
1911
1912
  util.win.eventBus.$emit('websocket', data);
1912
1913
  }
1913
- })
1914
- .catch((err) => {
1915
- console.log(err);
1916
- });
1914
+ }
1915
+ });
1917
1916
  },
1918
1917
  handleOpened(res) {
1919
1918
  if (res === undefined) {
@@ -2048,8 +2047,8 @@ export default {
2048
2047
  },
2049
2048
  beforeDestroy() {
2050
2049
  this.timer = null;
2051
- if (this.close) {
2052
- this.close();
2050
+ if (this.webSocket) {
2051
+ this.webSocket.destroy();
2053
2052
  }
2054
2053
  }
2055
2054
  };
package/src/index.js CHANGED
@@ -117,7 +117,7 @@ if (typeof window !== 'undefined' && window.Vue) {
117
117
  }
118
118
 
119
119
  export default {
120
- version: '0.5.11',
120
+ version: '0.5.12',
121
121
  install,
122
122
  Button,
123
123
  ButtonGroup,
package/src/utils/util.js CHANGED
@@ -7,12 +7,11 @@
7
7
 
8
8
  /* eslint-disable indent */
9
9
  const sm2 = require('sm-crypto').sm2;
10
- import { authCenter, wss, topic } from '../config/api';
10
+ import { authCenter } from '../config/api';
11
11
  import axios from 'axios';
12
12
  import qs from 'qs';
13
13
  import JSONbig from 'json-bigint';
14
- import SockJS from 'sockjs-client';
15
- import Stomp from 'stompjs';
14
+ import WebSocket from './webSocket';
16
15
 
17
16
  const win = window.__WUJIE_RAW_WINDOW__ ? window.__WUJIE_RAW_WINDOW__ : window;
18
17
 
@@ -1997,29 +1996,29 @@ const isLogined = function ({
1997
1996
  }).catch(e => { });
1998
1997
  } else
1999
1998
  if (
2000
- token ||
2001
- to.path === '/' ||
2002
- to.path === '/404' ||
2003
- exclude.indexOf(to.path) > -1 || exclude.indexOf(to.name) > -1 ||
2004
- to.path === '/login' ||
2005
- (token && to.path === '/main')
2006
- ) {
2007
- if (redirect && (to.path === '/main' || to.path === '/login')) {
2008
- window.location.replace(urlJoinParams({ url: `.${to.path}.html`, param: to.query }));
2009
- } else {
2010
- next();
2011
- }
2012
- } else {
2013
- if (loginPage) {
2014
- win.top.location.replace(loginPage);
2015
- } else if (document.referrer) {
2016
- win.top.location.replace(document.referrer);
2017
- } else if (win.top.location.href.indexOf('main.html') > -1) {
2018
- win.top.location.href = './login.html';
1999
+ token ||
2000
+ to.path === '/' ||
2001
+ to.path === '/404' ||
2002
+ exclude.indexOf(to.path) > -1 || exclude.indexOf(to.name) > -1 ||
2003
+ to.path === '/login' ||
2004
+ (token && to.path === '/main')
2005
+ ) {
2006
+ if (redirect && (to.path === '/main' || to.path === '/login')) {
2007
+ window.location.replace(urlJoinParams({ url: `.${to.path}.html`, param: to.query }));
2008
+ } else {
2009
+ next();
2010
+ }
2019
2011
  } else {
2020
- next('/login');
2012
+ if (loginPage) {
2013
+ win.top.location.replace(loginPage);
2014
+ } else if (document.referrer) {
2015
+ win.top.location.replace(document.referrer);
2016
+ } else if (win.top.location.href.indexOf('main.html') > -1) {
2017
+ win.top.location.href = './login.html';
2018
+ } else {
2019
+ next('/login');
2020
+ }
2021
2021
  }
2022
- }
2023
2022
  }
2024
2023
  };
2025
2024
  const isLogged = function (res) {
@@ -2472,67 +2471,25 @@ const setStorage = function ({ type, key, value }) {
2472
2471
  * @author huangbo
2473
2472
  * @date 2022年5月7日
2474
2473
  * @param {String} [url] - 连接地址
2474
+ * @param {String} [send] - 是否发送消息
2475
2475
  * @param {String} [take] - 订阅地址
2476
2476
  * @param {String} [debug] - 调试
2477
2477
  * @param {String} [interval] - 重连间隔时间
2478
- **/
2479
- function socket(options) {
2480
- let nextDate = 0;
2481
- let connect = 1;
2482
- return new Promise((resolve, reject) => {
2483
- let wshost = getStorage('wshost') || '';
2484
- let option = {
2485
- url: wshost + wss,
2486
- take: topic,
2487
- debug: true,
2488
- interval: 20
2489
- };
2490
- let websocket = win.websocket || {};
2491
- if (options && isObject(options)) {
2492
- option = { ...option, ...options };
2493
- }
2494
- let key = window.btoa(option.url);
2495
- if (!websocket[key]) {
2496
- websocket[key] = { socket: new SockJS(option.url) };
2497
- win.websocket = websocket;
2498
- }
2499
-
2500
- let client = websocket[key] ? websocket[key].client : null;
2501
- if (!client) {
2502
- client = websocket[key].client = Stomp.over(websocket[key].socket);
2503
- !option.debug && (client.debug = null);
2478
+ * @param {Function} [success] - 调试
2479
+ * @param {Function} [error] - 重连间隔时间
2480
+ **/
2481
+ function socket(option, vm) {
2482
+ let options = {};
2483
+ for (let i in option) {
2484
+ if (i === 'send') {
2485
+ options['isSend'] = option[i];
2486
+ } else {
2487
+ options[i] = option[i];
2504
2488
  }
2505
- client.connect(
2506
- {},
2507
- () => {
2508
- client.subscribe(option.take, (response) => {
2509
- let res = JSON.parse(response.body);
2510
- resolve(res, () => {
2511
- client.disconnect();
2512
- win.top.websocket && win.top.websocket[key] && delete win.top.websocket[key];
2513
- }, client, websocket[key]);
2514
- });
2515
- },
2516
- (error) => {
2517
- let diffSecond = parseInt((new Date() - nextDate) / 1000, 10);
2518
- if (connect > 5 && diffSecond < option.interval) {
2519
- client.disconnect();
2520
- if (win.top.websocket) {
2521
- if (Object.keys(win.top.websocket).length > 1) {
2522
- delete win.top.websocket[key];
2523
- } else {
2524
- delete win.top.websocket;
2525
- }
2526
- }
2527
- } else {
2528
- win.top.websocket && win.top.websocket[key] && setTimeout(() => {
2529
- socket(options);
2530
- }, 5000);
2531
- }
2532
- reject(error);
2533
- }
2534
- );
2535
- });
2489
+ }
2490
+ const socket = new WebSocket();
2491
+ socket.init(options, vm);
2492
+ return socket;
2536
2493
  }
2537
2494
  /**
2538
2495
  * sum
@@ -0,0 +1,103 @@
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.isSend = false;
19
+ }
20
+
21
+ /** socket连接 */
22
+ connect() {
23
+ if (!this.client) {
24
+ // 连接SockJS
25
+ let socket = new SockJS(this.host + this.url);
26
+ // 获取STOMP子协议的客户端对象
27
+ this.client = Stomp.over(socket);
28
+
29
+ }
30
+
31
+ // 日志不打印
32
+ if (!this.debug) {
33
+ console.log(111);
34
+ this.client.debug = () => {};
35
+ }
36
+
37
+ // 向服务器发起websocket连接
38
+ this.client.connect({}, () => {
39
+ this.recon = true;
40
+ // tryTimes定义重置
41
+ this.connects = 1;
42
+ // 订阅消息
43
+ // if (!this.isSend) {
44
+ this.subscribe();
45
+ // }
46
+ }, (error) => {
47
+ let diffSecond = parseInt((new Date() - this.nextDate) / 1000, 10);
48
+ if (this.connects > 5 && diffSecond < this.interval) {
49
+ this.client.disconnect();
50
+ this.error && this.error(error);
51
+ } else {
52
+ this.reconTimeout = setTimeout(() => {
53
+ this.connect();
54
+ this.connects++;
55
+ }, 5000);
56
+ }
57
+ });
58
+ }
59
+ /** 订阅服务端 */
60
+ subscribe() {
61
+ // 订阅服务端提供的某个topic
62
+ this.client.subscribe(this.take, (response) => {
63
+ if (response && (this.callback || this.success)) {
64
+ let callback = this.callback || this.success;
65
+ callback(JSON.parse(response.body));
66
+ }
67
+ });
68
+ }
69
+
70
+ /** 赋值、初始化socket */
71
+ init(option, vm) {
72
+ for (let i in option) {
73
+ this[i] = option[i];
74
+ }
75
+ this.vm = vm;
76
+ // 初始化连接
77
+ this.connect();
78
+ }
79
+
80
+ /** 发送消息 */
81
+ send(data) {
82
+ if (this.recon) {
83
+ clearTimeout(this.sendTimeout);
84
+ this.client.send(this.take, {}, typeof data === 'string' ? data : JSON.stringify(data));
85
+ } else {
86
+ this.sendTimeout = setTimeout(() => {
87
+ this.send(data);
88
+ }, 1000);
89
+ }
90
+ }
91
+
92
+ /** 销毁 */
93
+ destroy() {
94
+ // 断开连接,清除定时器
95
+ if (this.client) {
96
+ this.client.disconnect();
97
+ };
98
+ this.reconTimeout && clearTimeout(this.reconTimeout);
99
+ this.sendTimeout && clearTimeout(this.sendTimeout);
100
+ }
101
+ }
102
+
103
+ export default WebSocket;