dcim-topology2d 1.1.5 → 2.0.2

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 (77) hide show
  1. package/chart-diagram/src/echarts/index.js +88 -96
  2. package/chart-diagram/src/register.js +3 -3
  3. package/chart-diagram/src/utils/changeOptions.d.ts +4 -4
  4. package/chart-diagram/src/utils/changeOptions.js +172 -144
  5. package/chart-diagram/src/utils/conversion.d.ts +12 -12
  6. package/chart-diagram/src/utils/conversion.js +278 -137
  7. package/chart-diagram/src/utils/render.d.ts +5 -0
  8. package/chart-diagram/src/utils/render.js +107 -0
  9. package/core/index.d.ts +1 -0
  10. package/core/index.js +1 -0
  11. package/core/src/activeLayer.js +0 -6
  12. package/core/src/calling.js +3 -0
  13. package/core/src/canvas.js +1 -0
  14. package/core/src/common.d.ts +1 -2
  15. package/core/src/common.js +124 -614
  16. package/core/src/core.js +65 -49
  17. package/core/src/divLayer.d.ts +0 -3
  18. package/core/src/divLayer.js +14 -32
  19. package/core/src/element/common.d.ts +5 -0
  20. package/core/src/element/common.js +52 -0
  21. package/core/src/element/iframe.d.ts +3 -0
  22. package/core/src/element/iframe.js +12 -0
  23. package/core/src/element/index.d.ts +4 -0
  24. package/core/src/element/index.js +4 -0
  25. package/core/src/element/select.d.ts +11 -0
  26. package/core/src/element/select.js +199 -0
  27. package/core/src/element/tab.d.ts +1 -0
  28. package/core/src/element/tab.js +22 -0
  29. package/core/src/healps/changeData.d.ts +1 -2
  30. package/core/src/healps/changeData.js +16 -122
  31. package/core/src/middles/default.js +3 -1
  32. package/core/src/middles/nodes/arbitrarygraph.js +11 -9
  33. package/core/src/middles/nodes/formselect.d.ts +2 -0
  34. package/core/src/middles/nodes/formselect.js +73 -0
  35. package/core/src/middles/nodes/iframe.js +21 -4
  36. package/core/src/middles/nodes/index.d.ts +1 -0
  37. package/core/src/middles/nodes/index.js +1 -0
  38. package/core/src/models/node.d.ts +4 -0
  39. package/core/src/models/node.js +25 -22
  40. package/core/src/models/pen.js +7 -8
  41. package/core/src/models/rect.js +2 -2
  42. package/core/src/options.d.ts +1 -0
  43. package/core/src/preview.js +45 -31
  44. package/core/src/renderLayer.d.ts +10 -6
  45. package/core/src/renderLayer.js +36 -43
  46. package/core/src/store/data.d.ts +19 -17
  47. package/core/src/store/data.js +38 -12
  48. package/core/src/utils/assignment.d.ts +6 -0
  49. package/core/src/utils/assignment.js +138 -0
  50. package/core/src/utils/construction.d.ts +9 -3
  51. package/core/src/utils/construction.js +6 -1
  52. package/core/src/utils/conversion.d.ts +3 -0
  53. package/core/src/utils/conversion.js +67 -0
  54. package/core/src/utils/index.d.ts +2 -1
  55. package/core/src/utils/index.js +2 -1
  56. package/core/src/utils/math.d.ts +1 -0
  57. package/core/src/utils/math.js +3 -0
  58. package/core/src/utils/onmousevent.d.ts +3 -0
  59. package/core/src/utils/onmousevent.js +28 -7
  60. package/core/src/utils/params.d.ts +7 -0
  61. package/core/src/utils/params.js +125 -0
  62. package/package.json +1 -1
  63. package/static/echartsDefaultData.js +27 -107
  64. package/static/element.js +14 -0
  65. package/static/form.js +11 -0
  66. package/static/index.js +2 -1
  67. package/store/actions.js +17 -0
  68. package/store/clear.js +72 -0
  69. package/store/index.js +2 -0
  70. package/style/common.css +18 -0
  71. package/style/editor.css +13 -0
  72. package/style/index.css +3 -12
  73. package/style/select.css +143 -0
  74. package/core/src/utils/dom.d.ts +0 -9
  75. package/core/src/utils/dom.js +0 -103
  76. package/core/src/utils/dom.js.map +0 -1
  77. package/static/echartsStore.js +0 -14
@@ -3,15 +3,20 @@ import {DivLayer} from './divLayer';
3
3
  import {AnimateLayer} from './animateLayer';
4
4
  import {RenderLayer} from './renderLayer';
5
5
  import {Offscreen} from './offscreen';
6
- import {Line, Node, Point, EventAction} from './models';
7
- import {setConfItemNode, setStatisticalData} from './healps';
8
- import {s8, formatPadding, getRect} from './utils';
6
+ import {Line, Node, Point} from './models';
7
+ import {
8
+ s8,
9
+ formatPadding,
10
+ getRect,
11
+ setInitNodeDataValidat,
12
+ setDefaultNodeValidat,
13
+ initSwitchTabData,
14
+ setInitConfData,
15
+ } from './utils';
9
16
  import { useStore, clearStore } from './store'
10
- import {POLL} from './poll';
11
- import axios from 'axios';
12
17
  import * as mqtt from './mqtt.min';
13
- import { destroyEcharts } from "../../static";
14
-
18
+ import { switchTabDataPool } from "../../store";
19
+ import {setElementSwitchTabState} from './element';
15
20
  var MoveInType;
16
21
  (function (MoveInType) {
17
22
  MoveInType[MoveInType["None"] = 0] = "None";
@@ -29,7 +34,6 @@ var Common = /** @class */ (function () {
29
34
  function Common(parent, options) {
30
35
  var _this = this;
31
36
  _this.moveInType = MoveInType;
32
- this.mqttDataSouse = axios.CancelToken.source();
33
37
  this.mouseDown = null;
34
38
  this.renderTimer = 0;
35
39
  this.lastRender = 0;
@@ -85,7 +89,6 @@ var Common = /** @class */ (function () {
85
89
  _this.offscreen.render();
86
90
  break;
87
91
  }
88
- _this.divLayer.playNext(e.data.nextAnimate);
89
92
  _this.dispatch('animateEnd', e);
90
93
  });
91
94
  this.subcribeTableData = Store.subscribe('SYNC:tableData', function (data) {
@@ -113,7 +116,6 @@ var Common = /** @class */ (function () {
113
116
  }
114
117
  };
115
118
  this.openCount = 0;
116
- this.timmerByTopology = null;
117
119
  this.lastTranlated = {x: 0, y: 0};
118
120
  this.moveIn = {
119
121
  type: 'None',
@@ -126,17 +128,6 @@ var Common = /** @class */ (function () {
126
128
  lineControlPoint: null,
127
129
  eventNode: null
128
130
  };
129
- this.initType = ''; // 初始化类型
130
- this.pathRewrite = '';
131
- this.initData = null; // 初始化数据
132
- this.tagParams = {}; // 数据属性的集合,对应不同的事件类型
133
- this.assetPoperties = {}; // 固定的资产详情的集合
134
- this.isExistAssetKey = false; // 是否存在固定的资产详情
135
- this.pollTime = { // 轮询的方式的定时器
136
- Poll: null,
137
- Poll1: null,
138
- Poll2: null,
139
- };
140
131
  this.tip = '';
141
132
  this.rendering = false;
142
133
  this.isFullScreen = false;
@@ -177,53 +168,46 @@ var Common = /** @class */ (function () {
177
168
  window.topology = this;
178
169
  }
179
170
 
180
- Common.prototype.conversionData = function (obj, type) {
171
+ Common.prototype.conversionData = function (obj) {
181
172
  this.clear();
182
- let data = JSON.parse(JSON.stringify(obj));
183
- if (!data) {
184
- data = {pens: []};
173
+ if (!obj) {
174
+ obj = {pens: []};
185
175
  }
176
+ let data = JSON.parse(JSON.stringify(obj));
186
177
  Object.assign(this.store.data, data);
187
178
  this.store.data.pens = [];
188
179
  this.openCount = 0
180
+ const type = this.store.options.type;
189
181
  // for old data.
190
182
  if (data.nodes) {
191
183
  for (var _i = 0, _a = data.nodes; _i < _a.length; _i++) {
192
- _a[_i].TID = this.id;
184
+ setInitNodeDataValidat(_a[_i], this.id, type, _i);
193
185
  const item = new Node(_a[_i]);
194
186
  this.store.data.pens.push(item);
195
- this.store.pens[item.id] = item;
196
- this.setSwitchTabData(item, _i);
197
- // 初始化图表数据
198
- if (item.name === 'echarts' && item.data && type !== 'mqtt') {
199
- item.data.echarts.option = setStatisticalData(item, 'def');
200
- }
187
+ ///this.store.pens[item.id] = item;
188
+ initSwitchTabData(item);
201
189
  }
202
190
  for (var _b = 0, _c = data.lines; _b < _c.length; _b++) {
203
191
  _c[_b].TID = this.id;
204
192
  const item = new Line(_c[_b]);
205
193
  this.store.data.pens.push(item);
206
- this.store.pens[item.id] = item;
194
+ //this.store.pens[item.id] = item;
207
195
  }
208
196
  }
209
197
  // end.
210
198
  if (data.pens) {
211
199
  for (var _d = 0, _e = data.pens; _d < _e.length; _d++) {
212
200
  const item = _e[_d];
213
- item.TID = this.id;
214
201
  if (!item.from) {
202
+ setInitNodeDataValidat(item, this.id, type, _d);
215
203
  const node = new Node(item);
216
204
  this.store.data.pens.push(node);
217
- this.store.pens[item.id] = node;
218
- this.setSwitchTabData(node, _d);
219
- // 初始化图表数据
220
- if (node.name === 'echarts' && node.data && type !== 'mqtt') {
221
- node.data.echarts.option = setStatisticalData(node, 'def');
222
- }
205
+ //this.store.pens[item.id] = node;
206
+ initSwitchTabData(node);
223
207
  } else {
224
208
  const linNode = new Line(item);
225
209
  this.store.data.pens.push(linNode);
226
- this.store.pens[item.id] = linNode;
210
+ //this.store.pens[item.id] = linNode;
227
211
  }
228
212
  }
229
213
  }
@@ -235,37 +219,6 @@ var Common = /** @class */ (function () {
235
219
  this.store.parentElem.scrollLeft = 0;
236
220
  this.store.parentElem.scrollTop = 0;
237
221
  };
238
- Common.prototype.setSwitchTabData = function (node, index, type) {
239
- if (type) {
240
- let topologyChangeData = Store.get('TCD:topologyChangeData');
241
- if (topologyChangeData) {
242
- const switchTabData = node.tags.find((t) => {
243
- return t.includes('switchTabType');
244
- });
245
- const switchTabTypeData = topologyChangeData[`${switchTabData}Data`];
246
- if (switchTabTypeData) {
247
- delete switchTabTypeData[node.id];
248
- for (let switchNode of Object.values(switchTabTypeData)) {
249
- if (switchNode.tagOrder > index) switchNode.tagOrder--;
250
- }
251
- }
252
- }
253
- return;
254
- }
255
- if (node.tags && node.tags.length > 0) {
256
- const tagTypeData = node.tags.find((t) => {
257
- return t === 'statisticType' || t.includes('switchTabType');
258
- });
259
- if (tagTypeData) {
260
- node.tagOrder = index;
261
- let topologyChangeData = Store.get('TCD:topologyChangeData');
262
- if (!topologyChangeData) topologyChangeData = {};
263
- if (!topologyChangeData[`${tagTypeData}Data`]) topologyChangeData[`${tagTypeData}Data`] = {};
264
- topologyChangeData[`${tagTypeData}Data`][node.id] = node;
265
- Store.set('TCD:topologyChangeData', topologyChangeData);
266
- }
267
- }
268
- };
269
222
  Common.prototype.canvasResize = function (size) {
270
223
  try {
271
224
  this.canvas.resize(size);
@@ -417,116 +370,70 @@ var Common = /** @class */ (function () {
417
370
  };
418
371
  // 获取表格分页数据
419
372
  Common.prototype.getSyncTableDataFromServer = async function (data, node) {
420
- const path = this.pathRewrite ? this.pathRewrite + '/user/cockpit/mqtt-echart' : '/user/cockpit/mqtt-echart';
421
- const ret = await axios.post(path, data);
422
- //console.log('ret.data==========', ret, ret.data)
423
- const tableData = {};
424
- tableData[node.id] = {loading: true};
425
- Store.set('SYNC:tableData', tableData);
426
- if (ret.data && ret.data.data) {
427
- console.log(ret.data.data)
428
- tableData[node.id] = {
429
- loading: false,
430
- tableBody: ret.data.data.rows,
431
- total: ret.data.data.total
432
- }
433
- Store.set('SYNC:tableData', tableData);
434
- this.render();
435
- }
436
- if (ret.error) {
437
- console.log('获取数据失败==================')
438
- } else {
439
- console.log('获取数据成功==================')
440
- }
441
-
373
+ // const path = this.pathRewrite ? mqttEchartApi.replace('/topo-api', this.pathRewrite): mqttEchartApi;
374
+ // const ret = await axios.post(path, data);
375
+ // //console.log('ret.data==========', ret, ret.data)
376
+ // const tableData = {};
377
+ // tableData[node.id] = {loading: true};
378
+ // Store.set('SYNC:tableData', tableData);
379
+ // if (ret.data && ret.data.data) {
380
+ // console.log(ret.data.data)
381
+ // tableData[node.id] = {
382
+ // loading: false,
383
+ // tableBody: ret.data.data.rows,
384
+ // total: ret.data.data.total
385
+ // }
386
+ // Store.set('SYNC:tableData', tableData);
387
+ // this.render();
388
+ // }
389
+ // if (ret.error) {
390
+ // console.log('获取数据失败==================')
391
+ // } else {
392
+ // console.log('获取数据成功==================')
393
+ // }
442
394
  };
443
395
  Common.prototype.switchStaticsCheckType = function (node, staticTypeNode) {
396
+ const staticType = staticTypeNode.dcimStaticForType;
397
+ if(!staticType || staticType === 'NONE') return;
444
398
  // 点击切换统计图统计类别
445
399
  const switchTabData = node.tags.find((t) => {
446
400
  return t.includes('switchTabType');
447
401
  }); // 获取按钮组类型
448
402
  if(!switchTabData) return;
449
- const topologyChangeData = Store.get('TCD:topologyChangeData'); // 获取所有按钮组和按类型统计图组数据
403
+ const topologyChangeData = switchTabDataPool; // 获取所有按钮组和按类型统计图组数据
450
404
  const changeNode = topologyChangeData[`${switchTabData}Data`]; // 分别获取按钮组数据
405
+ if(!changeNode[node.id]) return;
451
406
  // 如果存在按钮组节点数据
452
- if (changeNode[node.id]) {
453
- for (let switchNode of Object.values(changeNode)) {
454
- if (this.store.data.pens[switchNode.tagOrder]) {
455
- this.store.data.pens[switchNode.tagOrder].activeImgeIndex = switchNode.id !== node.id;
407
+ const tabAreaData = topologyChangeData[`${switchTabData}AreaData`];
408
+ for (let switchNode of Object.values(changeNode)) {
409
+ const penNode = this.store.data.pens[switchNode.order];
410
+ if(!penNode) return;
411
+ penNode.activeImgeIndex = switchNode.id !== node.id;
412
+ if(staticType === 'SH'){
413
+ // 对显示隐藏的功能进行交互处理
414
+ const areaNode = tabAreaData[switchNode.bindStaticId];
415
+ if(areaNode && this.store.data.pens[areaNode.order]) {
416
+ const tagNode = this.store.data.pens[areaNode.order];
417
+ tagNode.visible = !(switchNode.id !== node.id);
418
+ setElementSwitchTabState(tagNode);
456
419
  }
457
420
  }
458
421
  }
459
- if (node.bindStaticId) {
460
- const statisticTypeData = topologyChangeData.statisticTypeData;
461
- if(!statisticTypeData) return;
462
- const findCurentEchart = statisticTypeData[node.bindStaticId]; // 获取当前点中的节点绑定的统计图表数据
422
+ // 对绑定的图表进行数据处理
423
+ if (node.bindStaticId && ['DAY', 'WEEK', 'MONTH', 'YEAR'].includes(staticType)) {
424
+ const findCurentEchart = tabAreaData[node.bindStaticId]; // 获取当前点中的节点绑定的统计图表数据
463
425
  if (findCurentEchart && findCurentEchart.data.params) {
464
- findCurentEchart.data.params['staticForType'] = staticTypeNode.dcimStaticForType; // 统计类型赋值
465
- const mqttSyncData = Store.get('mqtt:responseData');
466
- if (mqttSyncData) setConfItemNode(findCurentEchart, mqttSyncData);
426
+ const cn = this.store.data.pens[findCurentEchart.order];
427
+ cn.data.params['staticForType'] = staticType; // 统计类型赋值
428
+ cn.elementRendered = false;
467
429
  }
468
430
  }
431
+ this.store.data.dataResize = 1;
469
432
  this.render();
470
433
  };
471
434
  Common.prototype.s8 = function () {
472
435
  return s8()
473
436
  };
474
- // Common.prototype.openSocket = function (url) {
475
- // this.closeSocket();
476
- // if (url || this.store.data.websocket) {
477
- // this.socket = new Socket(url || this.store.data.websocket, this.store.data);
478
- // }
479
- // };
480
- // Common.prototype.closeSocket = function () {
481
- // if (this.socket) {
482
- // this.socket.close();
483
- // }
484
- // };
485
- Common.prototype.openMqtt = function (url, options) {
486
- this.closeMqtt();
487
- if (url || this.store.data.mqttUrl) {
488
- url = url || this.store.data.mqttUrl;
489
- const mqttTopics = this.initData && this.initData.mqttTopics ? this.initData.mqttTopics : this.store.data.mqttTopics;
490
- options = options || this.store.data.mqttOptions
491
- let topics = mqttTopics
492
- this.isEnd = false;
493
- // let num = 0; // 记录推送的次数,用于判单丢失情况
494
- this.mqttClient = mqtt.connect(url, options);
495
- var _this = this;
496
- this.mqttClient.on('message', function (topic, message) {
497
- //console.log('openMqtt11===================', topic, message)
498
- if (!_this.store.data.pens.length || !topic || topic != _this.store.data.mqttTopics) {
499
- return;
500
- }
501
- if (!this.isEnd) {
502
- _this.doMqttDrow(message.toString())
503
- }
504
- });
505
- if (topics) {
506
- this.mqttClient.subscribe(topics.split(','));
507
- }
508
- }
509
- };
510
- Common.prototype.openPoll = function (message, val) {
511
- if (message) {
512
- this.poll = new POLL(this.store.data, message, val);
513
- }
514
- };
515
- Common.prototype.clearInterValAll = function () {
516
- clearTimeout(this.timmerByTopology);
517
- this.timmerByTopology = null;
518
- };
519
- Common.prototype.closeMqtt = function () {
520
- if (this.mqttClient) {
521
- this.isEnd = true
522
- this.mqttClient.end();
523
- }
524
- };
525
- Common.prototype.closePoll = function () {
526
- for (let key in this.pollTime) {
527
- clearInterval(this.pollTime[key])
528
- }
529
- };
530
437
  Common.prototype.setNodeText = function () {
531
438
  this.inputObj.text = this.input.value;
532
439
  this.input.style.zIndex = '-1';
@@ -718,470 +625,79 @@ var Common = /** @class */ (function () {
718
625
  if (this.store.options.on) {
719
626
  this.store.options.on(event, data);
720
627
  }
721
- if (event === 'node' && data.name == 'tablePagination' && this.store.options.type !== 'topology') {
722
- const tableNodes = Store.get('FORM:tableData').data.tableNodes[data.paginationData.bindFromTableId];
723
- const pageSize = data.paginationData.pageSize;
724
- const offset = (parseInt(data.paginationData.pageNumber) - 1) * pageSize;
725
- const params = {
726
- id: tableNodes.id, // 表格ID
727
- limit: data.paginationData.pageSize,
728
- offset: offset
729
- };
730
- this.getSyncTableDataFromServer(params, tableNodes);
731
- }
732
- };
733
- Common.prototype.onContent = async function (resetDCIM, data, type) {
734
- //this.shareComponentData = data.shareComponent // 共享组件数据
735
- if (resetDCIM) {
736
- if (resetDCIM.pathRewrite != '') {
737
- this.pathRewrite = resetDCIM.pathRewrite // 路径重写
738
- }
739
- if (resetDCIM.mqttUrl) {
740
- data.mqttUrl = resetDCIM.mqttUrl
741
- data.mqttOptions.username = resetDCIM.mqttUsername
742
- data.mqttOptions.password = resetDCIM.mqttPassword
743
- }
744
- }
745
- this.initType = type
746
- this.initData = data
747
- const canvasData = data ? data : this.store.data
748
- //this.topologyDetailData = initData
749
- const url = canvasData.mqttUrl
750
- // if(url && url.indexOf('://') > -1){
751
- this.onContentForEventType('Mqtt')
628
+ // 先注释掉
629
+ // if (event === 'node' && data.name == 'tablePagination' && this.store.options.type !== 'topology') {
630
+ // const tableNodes = Store.get('FORM:tableData').data.tableNodes[data.paginationData.bindFromTableId];
631
+ // const pageSize = data.paginationData.pageSize;
632
+ // const offset = (parseInt(data.paginationData.pageNumber) - 1) * pageSize;
633
+ // const params = {
634
+ // id: tableNodes.id, // 表格ID
635
+ // limit: data.paginationData.pageSize,
636
+ // offset: offset
637
+ // };
638
+ // this.getSyncTableDataFromServer(params, tableNodes);
752
639
  // }
753
- if (canvasData.pollUrl) {
754
- this.onContentForEventType('Poll')
755
- }
756
- if (canvasData.pollUrl1) {
757
- this.onContentForEventType('Poll1')
758
- }
759
- if (canvasData.pollUrl2) {
760
- this.onContentForEventType('Poll2')
761
- }
762
- };
763
- Common.prototype.onContentForEventType = async function (eventType) {
764
- // 获取属性中数据的集合
765
- if (!this.initType) await this.initTagParams(eventType);
766
- let tagParams = this.tagParams[eventType]
767
- if (eventType === 'Mqtt') {
768
- // 连接测试,MQTT
769
- this.onMqttContent(tagParams)
770
- } else if (eventType.indexOf('Poll') > -1) {
771
- // 连接测试,轮询地址
772
- this.onPollContent(tagParams, eventType)
773
- }
774
- };
775
- Common.prototype.clearTagParams = function (eventType) {
776
- this.tagParams[eventType] = {};
777
- this.tagParams[eventType].tagIds = [];
778
- this.tagParams[eventType].kpiAddrs = [];
779
- this.tagParams[eventType].tagEcharts = [];
780
- this.tagParams[eventType].assetIds = [];
781
- this.tagParams[eventType].areaIds = [];
782
- // this.tagParams[eventType].cockpitLayoutData = [];//统计图表组件类型ID
783
- this.tagParams[eventType].echartData = [];//统计图表组件类型ID
784
640
  };
785
- Common.prototype.initTagParams = async function (eventType) {
786
- this.clearTagParams(eventType)
787
- const pensData = this.store.data.pens
788
- let tagParams = this.getTagParams(pensData, eventType);
789
- // 详情页面,即URL配置了资产id的页面
790
- let assetId = this.getUrlParams('assetId')
791
- // console.log('详情页面,即URL配置了资产id的页面',assetId,eventType, tagParams)
792
- if (assetId && eventType === 'Mqtt') {
793
- //if(assetId){
794
- // 获取属性中绑定指标数据的集合
795
- await this.getTagParamsForKpiAddrs(assetId, tagParams)
796
- // 存在固定的资产详情,更新页面数据
797
- // if(this.assetPoperties && this.isExistAssetKey === true){
798
- if (this.assetPoperties) {
799
- // 更新画布上固定的资产详情对应的值
800
- //const canvasPens = this.pathRewrite ? canvasData.pens : this.canvas.data.pens
801
- this.renderForAssetPoperties(pensData);
802
- }
641
+ Common.prototype.onContent = function (resetDCIM, data) {
642
+ if(!data) data = this.store.data;
643
+ let connectParams = {
644
+ mqttUrl: data.mqttUrl,
645
+ username: data.mqttOptions.username,
646
+ password: data.mqttOptions.password,
647
+ mqttTopics: data.mqttTopics,
648
+ clientId: s8()
649
+ };
650
+ if (resetDCIM && resetDCIM.mqttUrl) {
651
+ connectParams.mqttUrl = resetDCIM.mqttUrl;
652
+ connectParams.username = resetDCIM.mqttUsername;
653
+ connectParams.password = resetDCIM.mqttPassword;
803
654
  }
655
+ // 连接测试,MQTT
656
+ this.openMqtt(connectParams);
804
657
  };
805
- Common.prototype.getTagParams = function (pens, eventType) {
658
+ Common.prototype.openMqtt = function (connectParams) {
806
659
  const _this = this;
807
- pens.forEach((pen) => {
808
- if (pen.children != undefined && pen.children.length > 0) {
809
- _this.getTagParams(pen.children, eventType)
810
- } else {
811
- _this.getTagParamsChildren(pen, eventType)
812
- }
813
- })
814
- return this.tagParams[eventType]
815
- };
816
- Common.prototype.getTagParamsChildren = function (pen, eventType) {
817
- let tagIds = []
818
- let kpiAddrs = []
819
- let assetIds = []
820
- let areaIds = []
821
- let tagEcharts = []
822
- // let cockpitLayoutData = []
823
- let echartData = []
824
- let isEventType = false;
825
- for (var _b = 0, _c = pen.events; _b < _c.length; _b++) {
826
- var event_1 = _c[_b];
827
- if ((event_1.type === 3 && eventType === 'Mqtt') || (event_1.type === 4 && eventType === 'Poll')
828
- || (event_1.type === 5 && eventType === 'Poll1') || (event_1.type === 6 && eventType === 'Poll2')) {
829
- isEventType = true;
830
- }
660
+ _this.closeMqtt();
661
+ if(!connectParams.mqttUrl) return;
662
+ _this.isEnd = false;
663
+ const url = connectParams.mqttUrl.replace('ip', location.hostname);
664
+ _this.mqttClient = mqtt.connect(url, connectParams);
665
+ _this.mqttClient.on('message', function (topic, message) {
666
+ //console.log('openMqtt11===================', topic, message)
667
+ if (!topic || topic != connectParams.mqttTopics) return;
668
+ if (!this.isEnd) _this.doMqttDrow(message.toString());
669
+ });
670
+ const topics = connectParams.mqttTopics;
671
+ if (topics) {
672
+ this.mqttClient.subscribe(topics.split(','));
831
673
  }
832
- if (isEventType === true) {
833
- if (pen.data != undefined && this.checkType(pen.data) === 'Array' && pen.data.length > 0) {
834
- pen.data.forEach((item) => {
835
- if (item.key === 'tagId') {
836
- tagIds.push(item.value)
837
- }
838
- if (item.key === 'kpiAddr') {
839
- kpiAddrs.push(item.value)
840
- }
841
- if (item.key === 'assetKey') {
842
- this.isExistAssetKey = true
843
- }
844
- if (item.key === 'assetId') {
845
- assetIds.push(item.value)
846
- }
847
- if (item.key === 'areaId') {
848
- areaIds.push(item.value)
849
- }
850
- })
851
- }
852
- // else if(pen.data != undefined && this.checkType(pen.data) === 'Object' && pen.tags != undefined && this.checkType(pen.tags) === 'Array' && pen.tags.length>0){
853
- // pen.tags.forEach((item)=>{
854
- // if( item.indexOf('echart') > -1){
855
- // tagEcharts.push(item)
856
- // }
857
- // })
858
- // }
859
- else if (pen.data != undefined && this.checkType(pen.data) === 'Object' && this.checkType(pen.data.params) === 'Object') {
860
-
861
- // pen.data.echarts && pen.data.echarts.option.series.length > 1 ? echartData.push(pen.data.params.id) : cockpitLayoutData.push(pen.data.params.id)
862
- echartData.push(pen.data.params.id)
863
-
864
- }
865
- this.tagParams[eventType].tagIds = [...new Set(this.tagParams[eventType].tagIds.concat(tagIds))]
866
- this.tagParams[eventType].kpiAddrs = [...new Set(this.tagParams[eventType].kpiAddrs.concat(kpiAddrs))]
867
- this.tagParams[eventType].assetIds = [...new Set(this.tagParams[eventType].assetIds.concat(assetIds))]
868
- this.tagParams[eventType].areaIds = [...new Set(this.tagParams[eventType].areaIds.concat(areaIds))]
869
- this.tagParams[eventType].tagEcharts = [...new Set(this.tagParams[eventType].tagEcharts.concat(tagEcharts))]
870
- // this.tagParams[eventType].cockpitLayoutData = [...new Set(this.tagParams[eventType].cockpitLayoutData.concat(cockpitLayoutData))]
871
- this.tagParams[eventType].echartData = [...new Set(this.tagParams[eventType].echartData.concat(echartData))]
674
+ };
675
+ Common.prototype.closeMqtt = function () {
676
+ if (this.mqttClient) {
677
+ this.isEnd = true
678
+ this.mqttClient.end();
872
679
  }
873
680
  };
874
- Common.prototype.getMqttData = async function (tagParams, panelData) {
875
- let ret = null;
876
- let data = {};
877
- let path = '';
878
- let assetData = null;
879
- let pathRewrite = this.pathRewrite;
681
+ Common.prototype.doMqttDrow = function (ret) {
880
682
  let canvasData = this.store.data;
881
- let mqttTopics = this.store.data.mqttTopics;
882
- let tagParamsData = tagParams;
883
- let detailJson = null;
884
- Store.set('TIMEOUT:currentPage', `locationPath${this.s8()}`);
885
- if (panelData) {
886
- this.store.data.mqttTopics = mqttTopics
887
- pathRewrite = panelData.pathRewrite;
888
- canvasData = JSON.parse(JSON.stringify(panelData.data));
889
- mqttTopics = panelData.mqttTopics;
890
- if (panelData.assetId) {
891
- const detailData = await this.getTagParamsForKpiAddrs(panelData.assetId, tagParams, pathRewrite);
892
- if (detailData.data) {
893
- tagParamsData.tagIds = detailData.tagIds;
894
- assetData = detailData.data.asset;
895
- detailJson = detailData.data;
896
- tagParamsData.echartAssemblyData = detailJson.echartAssemblyData;
897
- }
898
- }
899
- }
900
- tagParamsData.locationPath = Store.get('TIMEOUT:currentPage');
901
- if (!tagParams) {
902
- data = this.theData
903
- path = this.thePath
904
- } else {
905
- data = {
906
- tagIds: tagParamsData.tagIds.join(","),
907
- assetIds: tagParamsData.assetIds.join(","),
908
- areaIds: tagParamsData.areaIds.join(","),
909
- routingkey: mqttTopics,
910
- echart: tagParamsData.tagEcharts.join(","),
911
- echartData: tagParamsData.echartData
912
- }
913
- if (tagParamsData.echartAssemblyData) {
914
- data.echartAssemblyData = tagParamsData.echartAssemblyData;
915
- }
916
- //const pathRewrite = panelData ? panelData.pathRewrite : this.pathRewrite
917
- path = pathRewrite ? pathRewrite + '/user/cockpit/mqtt-data' : '/user/cockpit/mqtt-data'
918
- this.thePath = path
919
- this.theData = data
920
- }
921
- let drawedData = null
922
- data.cancelToken = this.mqttDataSouse.token;
923
- ret = await axios.post(path, data).catch(function(th) {
924
- if(axios.isCancel(th)) {
925
- console.log('请求取消了----', th.message);
926
- } else {
927
- console.log('请求失败----')
928
- }
929
- });
930
- if (ret.data && ret.data.data) {
931
- if (assetData) ret.data.data.asset = assetData
932
- drawedData = this.mqttDataDrawing(canvasData, ret.data.data, detailJson)
933
- }
934
- this.clearInterValAll();
935
- this.timmerByTopology = setTimeout(() => {
936
- const locationPath = Store.get('TIMEOUT:currentPage');
937
- if (locationPath === tagParamsData.locationPath) {
938
- this.getMqttData(tagParamsData);
939
- }
940
- }, 180000); // 每3分钟定时请求,超过3分钟未收到MQTT将停止推送数据 180000
941
- if (ret.error) {
942
- return null;
943
- } else {
944
- return {
945
- mqttData: drawedData,
946
- detailData: detailJson
947
- }
948
- }
683
+ ret = JSON.parse(ret);
684
+ //console.log('处理消息', ret)
685
+ this.mqttDataDrawing(canvasData.pens, ret)
949
686
  };
950
- Common.prototype.mqttDataDrawing = function (data, retData, detailJson) {
951
- const syncData = retData
952
- const detailData = detailJson ? detailJson.data : [];
687
+ Common.prototype.mqttDataDrawing = function (data, retData) {
953
688
  // console.log('收到消息', syncData)
954
- Store.set('mqtt:responseData', syncData);
955
- data.pens.map((item) => {
956
- item.TID = this.id;
689
+ data.map((item) => {
690
+ if(this.store.options.type === 'topology') setInitConfData(item);
691
+ setDefaultNodeValidat(item, retData);
957
692
  if (item.children && item.children.length) {
958
- item.children.map((_item) => {
959
- item.defaultFillStyle = item.fillStyle;
960
- item.defaultFontColor = item.font.color;
961
- if (item.name === 'line') item.defaultLineColor = item.strokeStyle;
962
- if (!_item.data) return
963
- //const node = detailData.length > 0 ? detailData : syncData
964
- const functionData = _item.events.filter((ev) => {
965
- return ev.action === EventAction.Function
966
- })
967
- const dataValue = functionData[0]
968
- if (functionData.length > 0 && dataValue.value && retData) {
969
- _item.data.map((d) => {
970
- const {kpiData, tagData} = retData;
971
- const key = d.key;
972
- const value = d.value;
973
- const _syncItem = key === 'tagId' ? tagData[value] : kpiData[value];
974
- if ((key === 'tagId' || key === 'kpiAddr') && _syncItem) {
975
- const isControl = parseInt(_syncItem.isControlDis); // 是否可控,0可控,1不可控
976
- if (!isControl) {
977
- d.tagVal = value
978
- d.controlParams = _syncItem
979
- // delete _syncItem[value]
980
- // Object.assign(d, _syncItem)
981
- }
982
- }
983
- })
984
- //console.log('定制函数=====')
985
- try {
986
- const func = new Function('pen', 'params', dataValue.value)
987
- func(_item, JSON.stringify(retData))
988
- }catch (e) {
989
- console.log(`自定义函数 ${item.id} 出错>>>`, e);
990
- }
991
- } else {
992
- // console.log('默认函数')
993
- setConfItemNode(_item, syncData);
994
- }
995
- this.machAnimateReset(item);
996
- })
997
- } else {
998
- item.defaultFillStyle = item.fillStyle;
999
- item.defaultFontColor = item.font.color;
1000
- if (item.name === 'line') item.defaultLineColor = item.strokeStyle;
1001
- if (!item.data) return
1002
- //const node = detailData.length > 0 ? detailData : syncData
1003
- const functionData = item.events.filter((ev) => {
1004
- return ev.action === EventAction.Function
1005
- })
1006
- const dataValue = functionData[0]
1007
- if (functionData.length > 0 && dataValue.value && retData) {
1008
- item.data.map((d) => {
1009
- const {kpiData, tagData} = retData;
1010
- const key = d.key;
1011
- const value = d.value;
1012
- const _syncItem = key === 'tagId' ? tagData[value] : kpiData[value];
1013
- if ((key === 'tagId' || key === 'kpiAddr') && _syncItem) {
1014
- const isControl = parseInt(_syncItem.isControlDis); // 是否可控,0可控,1不可控
1015
- if (!isControl) {
1016
- d.tagVal = value;
1017
- d.controlParams = _syncItem;
1018
- // delete _syncItem[value]
1019
- // Object.assign(d, _syncItem)
1020
- }
1021
- }
1022
- });
1023
- try {
1024
- const func = new Function('pen', 'params', dataValue.value);
1025
- func(item, JSON.stringify(retData));
1026
- }catch (e) {
1027
- console.log(`自定义函数 ${item.id} 出错>>>`, e);
1028
- }
1029
- } else {
1030
- // console.log('默认函数')
1031
- setConfItemNode(item, syncData);
1032
- }
1033
- this.machAnimateReset(item);
693
+ this.mqttDataDrawing(item.children, retData);
1034
694
  }
1035
695
  })
1036
- // console.log('执行完毕')
696
+ //console.log('执行完毕-----', this.store.data.pens)
1037
697
  this.render();
1038
698
  this.animate(true);
1039
699
  return data
1040
700
  };
1041
- Common.prototype.machAnimateReset = function (pen) {
1042
- if (!pen.animateFrames || pen.animateFrames.length <= 0) return;
1043
- for (var _a = 0, _af = pen.animateFrames; _a < _af.length; _a++) {
1044
- var ani = _af[_a];
1045
- ani.state.strokeStyle = pen.strokeStyle;
1046
- ani.state.fillStyle = pen.fillStyle;
1047
- }
1048
- };
1049
- Common.prototype.getTagParamsForKpiAddrs = async function (assetId, tagParams, apiStr) {
1050
- let params = {
1051
- assetId: assetId,
1052
- tagIds: tagParams.tagIds.join(","),
1053
- kpiAddrs: tagParams.kpiAddrs.join(","),
1054
- echartAssemblyIds: tagParams.echartData,
1055
- }
1056
- let pathRewrite = apiStr ? apiStr : this.pathRewrite
1057
- const path = pathRewrite ? pathRewrite + '/place/place_monitor/getPlaceAssetDetail' : '/place/place_monitor/getPlaceAssetDetail'
1058
- let ret = await axios.post(path, params);
1059
- // 遍历得到属性中绑定指标数据的集合
1060
- const tagIds = this.getTagIdsForKpiAddrs(ret.data);
1061
- // 详情页面,固定的资产详情的数据集合
1062
- this.assetPoperties = ret.asset
1063
-
1064
- return {
1065
- data: ret.data,
1066
- echartAssemblyData: ret.echartAssemblyData,
1067
- tagIds: tagIds
1068
- }
1069
- };
1070
- Common.prototype.getTagIdsForKpiAddrs = function (data) {
1071
- let tagIds = [];
1072
- const delData = this.pathRewrite ? data : data.data;
1073
- if (delData && delData.length > 0) {
1074
- delData.forEach((item) => {
1075
- tagIds.push(item.tagId);
1076
- })
1077
- this.tagParams.detailAssetData = data;
1078
- this.tagParams.Mqtt.tagIds = tagIds;
1079
- }
1080
- return tagIds
1081
- };
1082
- Common.prototype.renderForAssetPoperties = function (pens) {
1083
- const _this = this;
1084
- pens.forEach((pen) => {
1085
- if (pen.children != undefined) {
1086
- _this.renderForAssetPoperties(pen.children)
1087
- } else {
1088
- _this.renderForAssetPopertiesChildren(pen)
1089
- }
1090
- })
1091
- };
1092
- Common.prototype.renderForAssetPopertiesChildren = function (pen) {
1093
- if (pen.data != undefined && pen.data != '' && typeof pen.data === 'object' && Array.isArray(pen.data) && pen.data.length > 0) {
1094
- pen.data.forEach((item) => {
1095
- Object.keys(this.assetPoperties).forEach(key => {
1096
- if (item.key === 'assetKey') {
1097
- if (item.value === key) {
1098
- if (key === 'imgUrl' || key === 'principleImg') {
1099
- pen.text = ''
1100
- pen.image = this.pathRewrite ? this.pathRewrite + this.assetPoperties[key] : this.assetPoperties[key]
1101
- } else {
1102
- pen.text = this.assetPoperties[key]
1103
- }
1104
- }
1105
- }
1106
- })
1107
- })
1108
- }
1109
- };
1110
- Common.prototype.onMqttContent = async function (tagParams) {
1111
- if (!this.initType) this.store.data.mqttTopics = 'mqtt-' + s8();
1112
- // 告知MQTT属性中数据的集合
1113
- const ret = !this.initType ? await this.getMqttData(tagParams) : this.initType;
1114
- if (ret) {
1115
- let mqttUrlStr = this.store.data.mqttUrl, mqttOption = this.store.data.mqttOptions
1116
- if (this.initData) {
1117
- const {mqttUrl, mqttOptions} = this.initData
1118
- mqttUrlStr = mqttUrl
1119
- mqttOption = mqttOptions
1120
- }
1121
- mqttOption.clientId = s8()
1122
- this.openMqtt(mqttUrlStr, mqttOption);
1123
- } else {
1124
- console.log('请求出错')
1125
- }
1126
- };
1127
- Common.prototype.onPollContent = function (tagParams, eventType) {
1128
- const index = eventType[4] ? eventType[4] : ''
1129
- // const url = 'pollUrl'+index;
1130
- // const second = 'pollSecond'+index;
1131
- const pollUrl = this.store.data['pollUrl' + index]
1132
- const pollSecond = this.store.data['pollSecond' + index]
1133
- this.onpollStop(eventType);
1134
- if (pollUrl && pollSecond) {
1135
- this.renderForPoll(tagParams, pollUrl, eventType);
1136
- if (pollSecond != 0) { // 轮询
1137
- let millisecond = parseInt(pollSecond * 1000)
1138
- this.pollTime[eventType] = setInterval(() => {
1139
- this.renderForPoll(tagParams, pollUrl, eventType);
1140
- }, millisecond);
1141
- }
1142
- }
1143
- };
1144
- Common.prototype.onpollStop = function (eventType) {
1145
- if (this.pollTime[eventType]) {
1146
- clearInterval(this.pollTime[eventType])
1147
- }
1148
- };
1149
- Common.prototype.renderForPoll = async function (tagParams, pollUrl, eventType) {
1150
- let data = {
1151
- tagIds: tagParams.tagIds.join(","),
1152
- // assetIds: tagParams.assetIds.join(","),
1153
- // echart: tagParams.tagEcharts.join(",")
1154
- }
1155
- const _this = this
1156
- axios.post(pollUrl, data)
1157
- .then((res) => {
1158
- _this.openPoll(res, eventType);
1159
- })
1160
- .catch((error) => {
1161
- console.log('轮询地址,连接失败', error)
1162
- _this.onpollStop(eventType);
1163
- });
1164
- };
1165
- Common.prototype.getUrlParams = function (name) {
1166
- var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
1167
- var r = window.location.search.substr(1).match(reg)
1168
- if (r != null) return unescape(r[2])
1169
- return null
1170
- };
1171
- Common.prototype.checkType = function (data) {
1172
- return Object.prototype.toString.call(data).slice(8, -1)
1173
- };
1174
- Common.prototype.mqttLostMessage = function () {
1175
- // console.log('发送请求mqtt-data')
1176
- this.getMqttData(this.tagParams.Mqtt);
1177
- };
1178
- Common.prototype.doMqttDrow = function (ret) {
1179
- let canvasData = this.store.data;
1180
- ret = JSON.parse(ret);
1181
- // console.log('处理消息')
1182
- // console.log('this.canvas.data',this.canvas.data)
1183
- this.mqttDataDrawing(canvasData, ret)
1184
- };
1185
701
  Common.prototype.hidePenByTag = function (pens, val) {
1186
702
  const _this = this;
1187
703
  pens.forEach((pen) => {
@@ -1236,15 +752,11 @@ var Common = /** @class */ (function () {
1236
752
  }
1237
753
  }
1238
754
  }
1239
- this.render();
1240
755
  };
1241
756
  Common.prototype.destroyStatic = function () {
1242
- this.mqttDataSouse.cancel();
1243
757
  this.clear('destroy');
1244
- this.clearInterValAll();
1245
758
  //this.closeSocket();
1246
759
  this.closeMqtt();
1247
- this.closePoll();
1248
760
  cancelAnimationFrame(this.renderTimer);
1249
761
  this.subcribe.unsubscribe();
1250
762
  this.subcribeRender.unsubscribe();
@@ -1260,9 +772,7 @@ var Common = /** @class */ (function () {
1260
772
  this.offscreen.destroy();
1261
773
  this.offscreen = null;
1262
774
  this.store.parentElem = null;
1263
- destroyEcharts();
1264
775
  Store.set('form:tableData', null);
1265
- Store.set('TIMEOUT:currentPage', `empty${this.s8()}`);
1266
776
  Store.set('FORM:tableData', {
1267
777
  data: {
1268
778
  tableNodes: {},