@riil-frontend/component-topology 9.0.0-a.1 → 9.0.0-a.3

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 (30) hide show
  1. package/build/index.js +7 -7
  2. package/es/core/editor/components/Toolbar/widgets/EdgeTypeButton/LineType.js +1 -1
  3. package/es/core/hooks/useCiAttributeChange.js +60 -0
  4. package/es/core/hooks/usePolling.js +163 -60
  5. package/es/core/models/AttributeMetricDisplay.js +44 -127
  6. package/es/core/models/TopoApp.js +4 -2
  7. package/es/core/models/attributeFormatter/index.js +5 -6
  8. package/es/core/models/cache/CiCache.d.ts +18 -0
  9. package/es/core/models/cache/CiCache.js +78 -0
  10. package/es/core/models/utils/linkUtils.js +10 -13
  11. package/es/core/store/models/topoBizMod.js +4 -0
  12. package/es/core/store/models/viewer/resourceDetail.js +7 -0
  13. package/es/core/viewer/components/plugins/ResourceDetail/ResourceDetailDrawer.js +10 -9
  14. package/es/core/viewer/components/plugins/ResourceDetail/components/ResourceOverview/ResourceOverview.js +29 -22
  15. package/es/style.js +1 -1
  16. package/lib/core/editor/components/Toolbar/widgets/EdgeTypeButton/LineType.js +1 -1
  17. package/lib/core/hooks/useCiAttributeChange.js +70 -0
  18. package/lib/core/hooks/usePolling.js +166 -61
  19. package/lib/core/models/AttributeMetricDisplay.js +44 -126
  20. package/lib/core/models/TopoApp.js +4 -1
  21. package/lib/core/models/attributeFormatter/index.js +5 -7
  22. package/lib/core/models/cache/CiCache.d.ts +18 -0
  23. package/lib/core/models/cache/CiCache.js +89 -0
  24. package/lib/core/models/utils/linkUtils.js +10 -12
  25. package/lib/core/store/models/topoBizMod.js +4 -0
  26. package/lib/core/store/models/viewer/resourceDetail.js +7 -0
  27. package/lib/core/viewer/components/plugins/ResourceDetail/ResourceDetailDrawer.js +10 -9
  28. package/lib/core/viewer/components/plugins/ResourceDetail/components/ResourceOverview/ResourceOverview.js +29 -22
  29. package/lib/style.js +1 -1
  30. package/package.json +2 -2
@@ -0,0 +1,78 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import { queryCisByIds } from "../../services";
4
+ /**
5
+ * Ci缓存
6
+ */
7
+
8
+ var CiCache = /*#__PURE__*/function () {
9
+ function CiCache() {
10
+ this.ciMap = {};
11
+ }
12
+
13
+ var _proto = CiCache.prototype;
14
+
15
+ /**
16
+ *
17
+ * @param ids {string[]}
18
+ * @returns {Promise<Object>}
19
+ */
20
+ _proto.load =
21
+ /*#__PURE__*/
22
+ function () {
23
+ var _load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(ids) {
24
+ var _this = this;
25
+
26
+ var unloadCiIds, cis, map;
27
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
28
+ while (1) {
29
+ switch (_context.prev = _context.next) {
30
+ case 0:
31
+ unloadCiIds = ids.filter(function (id) {
32
+ return !_this.ciMap[id];
33
+ });
34
+
35
+ if (!unloadCiIds.length) {
36
+ _context.next = 6;
37
+ break;
38
+ }
39
+
40
+ _context.next = 4;
41
+ return queryCisByIds(unloadCiIds);
42
+
43
+ case 4:
44
+ cis = _context.sent;
45
+ cis.forEach(function (ci) {
46
+ _this.ciMap[ci.id] = ci;
47
+ });
48
+
49
+ case 6:
50
+ map = {};
51
+ ids.forEach(function (id) {
52
+ map[id] = _this.ciMap[id];
53
+ });
54
+ return _context.abrupt("return", this.ciMap);
55
+
56
+ case 9:
57
+ case "end":
58
+ return _context.stop();
59
+ }
60
+ }
61
+ }, _callee, this);
62
+ }));
63
+
64
+ function load(_x) {
65
+ return _load.apply(this, arguments);
66
+ }
67
+
68
+ return load;
69
+ }();
70
+
71
+ _proto.getCi = function getCi(id) {
72
+ return this.ciMap[id];
73
+ };
74
+
75
+ return CiCache;
76
+ }();
77
+
78
+ export default new CiCache();
@@ -6,7 +6,8 @@ import _ from 'lodash';
6
6
  import { queryCisByIds, queryModelAsset } from "../../services"; // 查询所有连线
7
7
 
8
8
  import { getEdges } from "../../../utils/htElementUtils";
9
- import CiTypeCache from "../cache/CiTypeCache"; // const interfaceTypeMap = {
9
+ import CiTypeCache from "../cache/CiTypeCache";
10
+ import CiCache from "../cache/CiCache"; // const interfaceTypeMap = {
10
11
  // "network.interface": {
11
12
  // displayName: "网络接口",
12
13
  // },
@@ -33,10 +34,10 @@ export function isCrucialLink(link) {
33
34
  export function isExitLink(link) {
34
35
  return (link === null || link === void 0 ? void 0 : link.attributes) && !(link !== null && link !== void 0 && link.attributes['destination_id']);
35
36
  }
36
- export function mergeLinksData(links, linkCis, nodes, interfaceCis, interfaceDoc) {
37
+ export function mergeLinksData(links, linkCis, nodes, interfaceCiMap, interfaceDoc) {
37
38
  var linkCiMap = keyBy(links, 'id');
38
39
  return links.map(function (link) {
39
- var _interfaceCis$find, _interfaceCis$find2;
40
+ var _interfaceCiMap$attri, _interfaceCiMap$attri2;
40
41
 
41
42
  var linkCi = linkCiMap[link.id];
42
43
 
@@ -63,14 +64,10 @@ export function mergeLinksData(links, linkCis, nodes, interfaceCis, interfaceDoc
63
64
  destination_type_object: interfaceDoc[attributes.destination_type],
64
65
  // 源/目的接口
65
66
  source_id_object: {
66
- displayName: (_interfaceCis$find = interfaceCis.find(function (node) {
67
- return node.id === attributes.source_id;
68
- })) === null || _interfaceCis$find === void 0 ? void 0 : _interfaceCis$find.attributes['display_name']
67
+ displayName: (_interfaceCiMap$attri = interfaceCiMap[attributes.source_id]) === null || _interfaceCiMap$attri === void 0 ? void 0 : _interfaceCiMap$attri.attributes['display_name']
69
68
  },
70
69
  destination_id_object: {
71
- displayName: (_interfaceCis$find2 = interfaceCis.find(function (node) {
72
- return node.id === attributes.destination_id;
73
- })) === null || _interfaceCis$find2 === void 0 ? void 0 : _interfaceCis$find2.attributes['display_name']
70
+ displayName: (_interfaceCiMap$attri2 = interfaceCiMap[attributes.destination_id]) === null || _interfaceCiMap$attri2 === void 0 ? void 0 : _interfaceCiMap$attri2.attributes['display_name']
74
71
  }
75
72
  })
76
73
  });
@@ -82,7 +79,7 @@ export function getLinksDetail(_x, _x2) {
82
79
 
83
80
  function _getLinksDetail() {
84
81
  _getLinksDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(links, nodes) {
85
- var linkCis, interfaceIds, interfaceTypes, interfaceCis, interfaceDoc;
82
+ var linkCis, interfaceIds, interfaceTypes, interfaceCiMap, interfaceDoc;
86
83
  return _regeneratorRuntime.wrap(function _callee$(_context) {
87
84
  while (1) {
88
85
  switch (_context.prev = _context.next) {
@@ -112,16 +109,16 @@ function _getLinksDetail() {
112
109
  return item !== 'ip';
113
110
  });
114
111
  _context.next = 7;
115
- return queryCisByIds(interfaceIds);
112
+ return CiCache.load(interfaceIds);
116
113
 
117
114
  case 7:
118
- interfaceCis = _context.sent;
115
+ interfaceCiMap = _context.sent;
119
116
  _context.next = 10;
120
117
  return CiTypeCache.getCiTypeMap(interfaceTypes);
121
118
 
122
119
  case 10:
123
120
  interfaceDoc = _context.sent;
124
- return _context.abrupt("return", mergeLinksData(links, linkCis, nodes, interfaceCis, interfaceDoc));
121
+ return _context.abrupt("return", mergeLinksData(links, linkCis, nodes, interfaceCiMap, interfaceDoc));
125
122
 
126
123
  case 12:
127
124
  case "end":
@@ -6,6 +6,10 @@ import rlog from '@riil-frontend/component-topology-utils/es/rlog';
6
6
  export default function (engine) {
7
7
  return {
8
8
  state: {
9
+ /**
10
+ * 格式:{id1: {attributes: {}}}
11
+ */
12
+ ciMap: {},
9
13
  // 指标默认设置
10
14
  resAndMetrics: {},
11
15
  metricDoc: {},
@@ -21,6 +21,13 @@ export default {
21
21
  visible: false,
22
22
  id: null // 资源id
23
23
 
24
+ };
25
+ },
26
+ close: function close() {
27
+ return {
28
+ visible: false,
29
+ id: null // 资源id
30
+
24
31
  };
25
32
  }
26
33
  },
@@ -76,9 +76,7 @@ function ResourceDetailDrawer(props) {
76
76
  }, []); // 解决切换拓扑图隐藏概览
77
77
 
78
78
  useEffect(function () {
79
- resourceDetailDispatchers.update({
80
- visible: false
81
- }); // TODO 其他数据重置
79
+ close(); // TODO 其他数据重置
82
80
  }, [topoId]);
83
81
 
84
82
  function getUser() {
@@ -154,6 +152,12 @@ function ResourceDetailDrawer(props) {
154
152
  }
155
153
  }
156
154
 
155
+ function close() {
156
+ resourceDetailDispatchers.update({
157
+ visible: false
158
+ });
159
+ }
160
+
157
161
  function init(data, targetType) {
158
162
  // console.log('初始化基本信息', data, targetType);
159
163
  var id = data.id,
@@ -214,7 +218,8 @@ function ResourceDetailDrawer(props) {
214
218
  topo: topo,
215
219
  userId: userId,
216
220
  activeData: activeData,
217
- resourceData: resourceData
221
+ resourceData: resourceData,
222
+ onClose: close
218
223
  }));
219
224
  };
220
225
 
@@ -228,11 +233,7 @@ function ResourceDetailDrawer(props) {
228
233
  })),
229
234
  width: 580,
230
235
  hasMask: false,
231
- onClose: function onClose() {
232
- return resourceDetailDispatchers.update({
233
- visible: false
234
- });
235
- }
236
+ onClose: close
236
237
  }, visible && resourceData && renderContent()));
237
238
  }
238
239
 
@@ -489,32 +489,39 @@ export default function ResourceOverview(props) {
489
489
  switch (_context5.prev = _context5.next) {
490
490
  case 0:
491
491
  _context5.t0 = item.dataIndex;
492
- _context5.next = _context5.t0 === 'display_name' ? 3 : _context5.t0 === 'ciName' ? 7 : _context5.t0 === 'res_address' ? 10 : _context5.t0 === 'imageName' ? 17 : 21;
492
+ _context5.next = _context5.t0 === 'display_name' ? 3 : _context5.t0 === 'ciName' ? 6 : _context5.t0 === 'res_address' ? 9 : _context5.t0 === 'imageName' ? 16 : 20;
493
493
  break;
494
494
 
495
495
  case 3:
496
- link = "/default/pagecenter/resDetail/view/" + id + "?resId=" + id + "&domainCode=" + ciTypeMeta.domain + "&title=" + attributeMap.display_name + "&ciCode=" + ciType; // 资源跳转链接
497
-
498
- value = /*#__PURE__*/React.createElement("span", {
499
- onClick: onClose
500
- }, /*#__PURE__*/React.createElement(Link, {
501
- className: styles.link,
502
- title: attributeMap.display_name || '',
503
- to: formatUrl(link)
504
- }, attributeMap.display_name || '-'));
496
+ // 无监控模板不能跳转详情。跳转前需判定资源实例数据属性中是否包含support_templates属性。若不包含,则不能跳转
497
+ if (attributeMap.support_templates) {
498
+ link = "/default/pagecenter/resDetail/view/" + id + "?resId=" + id + "&domainCode=" + ciTypeMeta.domain + "&title=" + attributeMap.display_name + "&ciCode=" + ciType; // 资源跳转链接
499
+
500
+ value = /*#__PURE__*/React.createElement("span", {
501
+ onClick: onClose
502
+ }, /*#__PURE__*/React.createElement(Link, {
503
+ className: styles.link,
504
+ disabled: true,
505
+ title: attributeMap.display_name || '',
506
+ to: formatUrl(link)
507
+ }, attributeMap.display_name || '-'));
508
+ } else {
509
+ value = attributeMap.display_name || '-';
510
+ }
511
+
505
512
  contentTitle = attributeMap.display_name || '-';
506
- return _context5.abrupt("break", 22);
513
+ return _context5.abrupt("break", 21);
507
514
 
508
- case 7:
515
+ case 6:
509
516
  value = ciTypeMeta.displayName;
510
517
  contentTitle = value;
511
- return _context5.abrupt("break", 22);
518
+ return _context5.abrupt("break", 21);
512
519
 
513
- case 10:
514
- _context5.next = 12;
520
+ case 9:
521
+ _context5.next = 11;
515
522
  return getAddressFormat(attributeMap);
516
523
 
517
- case 12:
524
+ case 11:
518
525
  address = _context5.sent;
519
526
  owned_computer_room = attributeMap.owned_computer_room, owned_cabinet = attributeMap.owned_cabinet; // 跳转3D机房定位设备
520
527
 
@@ -534,18 +541,18 @@ export default function ResourceOverview(props) {
534
541
  }
535
542
 
536
543
  contentTitle = address;
537
- return _context5.abrupt("break", 22);
544
+ return _context5.abrupt("break", 21);
538
545
 
539
- case 17:
546
+ case 16:
540
547
  node = topo.getDataModel().getDataByTag(id);
541
548
  value = (node === null || node === void 0 ? void 0 : node.a('customName')) || (node === null || node === void 0 ? void 0 : node.a('name')) || '-';
542
549
  contentTitle = value;
543
- return _context5.abrupt("break", 22);
550
+ return _context5.abrupt("break", 21);
544
551
 
545
- case 21:
546
- return _context5.abrupt("break", 22);
552
+ case 20:
553
+ return _context5.abrupt("break", 21);
547
554
 
548
- case 22:
555
+ case 21:
549
556
  case "end":
550
557
  return _context5.stop();
551
558
  }
package/es/style.js CHANGED
@@ -3,10 +3,10 @@ import '@alifd/next/es/box/style';
3
3
  import '@alifd/next/es/message/style';
4
4
  import '@riil-frontend/component-topology-utils/es/style';
5
5
  import '@riil-frontend/component-riil-event-emitter/es/style';
6
+ import '@riil-frontend/utils/es/style';
6
7
  import '@alifd/next/es/drawer/style';
7
8
  import '@alifd/next/es/menu-button/style';
8
9
  import '@alifd/next/es/search/style';
9
- import '@riil-frontend/utils/es/style';
10
10
  import '@alifd/next/es/tab/style';
11
11
  import '@alifd/next/es/table/style';
12
12
  import '@riil-frontend/component-table-layout/es/style';
@@ -37,7 +37,7 @@ var LINE_TYPE_OPTIONS = [{
37
37
  label: '双折线',
38
38
  icon: 'topo_linear_icon_bilinear'
39
39
  }, {
40
- value: 'flex',
40
+ value: 'doublearc',
41
41
  label: '双弧线',
42
42
  icon: 'topo_linear_icon_arcline'
43
43
  }];
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports["default"] = useCiAttributeChange;
7
+
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
10
+ var _rlog = _interopRequireDefault(require("@riil-frontend/component-topology-utils/es/rlog"));
11
+
12
+ var _react = require("react");
13
+
14
+ var _CiCache = _interopRequireDefault(require("../models/cache/CiCache"));
15
+
16
+ var _useTopoEventListener = _interopRequireDefault(require("./useTopoEventListener"));
17
+
18
+ function mergeData(cis, ciChangeData) {
19
+ if (!cis.find(function (item) {
20
+ return item.id === ciChangeData.id;
21
+ })) {
22
+ return cis;
23
+ }
24
+
25
+ return cis.map(function (ci) {
26
+ if (ci.id === ciChangeData.id) {
27
+ return (0, _extends2["default"])({}, ci, {
28
+ attributes: (0, _extends2["default"])({}, ci.attributes, ciChangeData.attributes)
29
+ });
30
+ }
31
+
32
+ return ci;
33
+ });
34
+ }
35
+ /**
36
+ * 监听ci属性变更
37
+ *
38
+ * @param {*} props
39
+ */
40
+
41
+
42
+ function useCiAttributeChange(props) {
43
+ var topo = props.topo;
44
+ (0, _useTopoEventListener["default"])({
45
+ type: 'attribute',
46
+ onMessage: function onMessage(ciChangeData) {
47
+ // 更新拓扑数据
48
+ var topoData = topo.store.getModelState('topoMod').data;
49
+
50
+ if (topoData) {
51
+ var newData = (0, _extends2["default"])({}, topoData, {
52
+ nodes: mergeData(topoData.nodes, ciChangeData),
53
+ links: mergeData(topoData.links, ciChangeData),
54
+ linkGroups: mergeData(topoData.linkGroups, ciChangeData)
55
+ });
56
+ var topoDispatchers = topo.store.getModelDispatchers('topoMod');
57
+ topoDispatchers.update({
58
+ data: newData
59
+ });
60
+ } // 更新缓存
61
+
62
+
63
+ var ci = _CiCache["default"].getCi(ciChangeData.id);
64
+
65
+ if (ci) {
66
+ ci.attributes = (0, _extends2["default"])({}, ci.attributes, ciChangeData.attributes);
67
+ }
68
+ }
69
+ });
70
+ }
@@ -7,10 +7,10 @@ exports["default"] = void 0;
7
7
 
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
 
10
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
-
12
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
11
 
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
14
  var _react = require("react");
15
15
 
16
16
  var _ahooks = require("ahooks");
@@ -19,6 +19,14 @@ var _lodash = _interopRequireDefault(require("lodash"));
19
19
 
20
20
  var _rlog = _interopRequireDefault(require("@riil-frontend/component-topology-utils/es/rlog"));
21
21
 
22
+ var _topo = _interopRequireDefault(require("@riil-frontend/component-topology-common/es/services/topo"));
23
+
24
+ var _componentRiilEventEmitter = require("@riil-frontend/component-riil-event-emitter");
25
+
26
+ var _DictCache = _interopRequireDefault(require("../models/cache/DictCache"));
27
+
28
+ var _useCiAttributeChange = _interopRequireDefault(require("./useCiAttributeChange"));
29
+
22
30
  /**
23
31
  * 轮询获取指标hooks
24
32
  * @param {*} props
@@ -26,12 +34,156 @@ var _rlog = _interopRequireDefault(require("@riil-frontend/component-topology-ut
26
34
  var usePolling = function usePolling(props) {
27
35
  var topo = props.topo;
28
36
  var store = topo.store;
37
+ (0, _useCiAttributeChange["default"])({
38
+ topo: topo
39
+ });
29
40
  var bizState = store.useModelState('topoBizMod');
30
41
  var resAndMetrics = bizState.resAndMetrics,
31
42
  pollingSwitch = bizState.pollingSwitch;
32
43
  var displayConfig = topo.store.useModelState('displayConfig');
33
44
  var resourceOverviewState = topo.store.useModelState('topoBaseInfoOverview');
34
- var resIdsList = resAndMetrics === null || resAndMetrics === void 0 ? void 0 : resAndMetrics.resIdsList; // 轮询hooks
45
+ var resIdsList = resAndMetrics === null || resAndMetrics === void 0 ? void 0 : resAndMetrics.resIdsList;
46
+ /**
47
+ * 查询拓扑图资源的属性指标
48
+ *
49
+ * @returns {array}
50
+ */
51
+
52
+ function fetchData() {
53
+ return _fetchData.apply(this, arguments);
54
+ }
55
+ /**
56
+ *
57
+ * @returns {{id, attributes: object[], metrics: object[]}[]} 属性和指标
58
+ */
59
+
60
+
61
+ function _fetchData() {
62
+ _fetchData = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
63
+ var _topo$store$getModelS, resIdsList, nodeIdsList, codes, param, _yield$Promise$all, ciMetricResult, transformLinkData;
64
+
65
+ return _regenerator["default"].wrap(function _callee$(_context) {
66
+ while (1) {
67
+ switch (_context.prev = _context.next) {
68
+ case 0:
69
+ transformLinkData = function _transformLinkData(data) {
70
+ var _topo$dataModel$getDa = topo.dataModel.getData(),
71
+ links = _topo$dataModel$getDa.links,
72
+ linkGroups = _topo$dataModel$getDa.linkGroups;
73
+
74
+ var link = [].concat(links, linkGroups).find(function (item) {
75
+ return item.id === data.id;
76
+ });
77
+
78
+ if (!link) {
79
+ return data;
80
+ }
81
+
82
+ return (0, _extends2["default"])({}, data, {
83
+ attributeMap: link.attributes || {}
84
+ });
85
+ };
86
+
87
+ _topo$store$getModelS = topo.store.getModelState('topoBizMod').resAndMetrics, resIdsList = _topo$store$getModelS.resIdsList, nodeIdsList = _topo$store$getModelS.nodeIdsList; // rlog.debug('根据ci的id获取属性的值-getCiArrByIds', resIdsList, metrics);
88
+ // 无资源,不查询
89
+
90
+ if (resIdsList.length) {
91
+ _context.next = 4;
92
+ break;
93
+ }
94
+
95
+ return _context.abrupt("return", []);
96
+
97
+ case 4:
98
+ // 需要查询的指标列表
99
+ codes = topo.attributeMetricDisplay.getResourceMetricCodes();
100
+ param = {
101
+ ciId: nodeIdsList,
102
+ codes: codes,
103
+ // 过滤掉不需要查询的
104
+ relationId: topo.attributeMetricDisplay.getEdges().map(function (edge) {
105
+ return {
106
+ ciId: edge.id,
107
+ operation: edge.operation
108
+ };
109
+ })
110
+ };
111
+ _context.t0 = Promise;
112
+ _context.t1 = // 查询指标值
113
+ _topo["default"].ciInfo.batchQueryCiInfo(param);
114
+ _context.next = 10;
115
+ return _DictCache["default"].init();
116
+
117
+ case 10:
118
+ _context.t2 = _context.sent;
119
+ _context.t3 = [_context.t1, _context.t2];
120
+ _context.next = 14;
121
+ return _context.t0.all.call(_context.t0, _context.t3);
122
+
123
+ case 14:
124
+ _yield$Promise$all = _context.sent;
125
+ ciMetricResult = _yield$Promise$all[0];
126
+ return _context.abrupt("return", ciMetricResult.map(function (data) {
127
+ var ci = topo.dataModel.getDataById(data.id);
128
+ var resultData = (0, _extends2["default"])({}, data, ci, {
129
+ attributeMap: (0, _extends2["default"])({}, (ci === null || ci === void 0 ? void 0 : ci.attributes) || {})
130
+ });
131
+ resultData = transformLinkData(resultData); // 特殊处理:ipv6 从ipv6_address_list取第一个
132
+
133
+ // 特殊处理:ipv6 从ipv6_address_list取第一个
134
+ if (resultData.attributeMap.ipv6_address_list && !resultData.attributeMap.ipv6_address) {
135
+ resultData.attributeMap.ipv6_address = (resultData.attributeMap.ipv6_address_list || '').split(',')[0];
136
+ }
137
+
138
+ return resultData;
139
+ }));
140
+
141
+ case 17:
142
+ case "end":
143
+ return _context.stop();
144
+ }
145
+ }
146
+ }, _callee);
147
+ }));
148
+ return _fetchData.apply(this, arguments);
149
+ }
150
+
151
+ function refresh() {
152
+ return _refresh.apply(this, arguments);
153
+ } // 轮询hooks
154
+
155
+
156
+ function _refresh() {
157
+ _refresh = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
158
+ var data;
159
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
160
+ while (1) {
161
+ switch (_context2.prev = _context2.next) {
162
+ case 0:
163
+ if (!(!pollingSwitch || !(resAndMetrics !== null && resAndMetrics !== void 0 && resAndMetrics.resIdsList.length))) {
164
+ _context2.next = 2;
165
+ break;
166
+ }
167
+
168
+ return _context2.abrupt("return");
169
+
170
+ case 2:
171
+ _context2.next = 4;
172
+ return fetchData();
173
+
174
+ case 4:
175
+ data = _context2.sent;
176
+ return _context2.abrupt("return", data);
177
+
178
+ case 6:
179
+ case "end":
180
+ return _context2.stop();
181
+ }
182
+ }
183
+ }, _callee2);
184
+ }));
185
+ return _refresh.apply(this, arguments);
186
+ }
35
187
 
36
188
  var _useRequest = (0, _ahooks.useRequest)(refresh, {
37
189
  pollingInterval: 60 * 1000,
@@ -42,30 +194,13 @@ var usePolling = function usePolling(props) {
42
194
  if (result) {
43
195
  var dd = _lodash["default"].cloneDeep(result);
44
196
 
45
- topo.attributeMetricDisplay.loadAttributeAndMetric(dd);
197
+ topo.attributeMetricDisplay.loadData(dd);
46
198
  }
47
199
  }
48
200
  }),
49
201
  loading = _useRequest.loading,
50
202
  startPoll = _useRequest.run,
51
- stopPoll = _useRequest.cancel;
52
-
53
- function convertData(data) {
54
- return data.map(function (item) {
55
- return (0, _extends2["default"])({}, item, {
56
- attributes: convertAttrMap(item.attributes),
57
- metrics: convertAttrMap(item.metrics)
58
- });
59
- });
60
- }
61
-
62
- function convertAttrMap(attrs) {
63
- var map = {};
64
- attrs.forEach(function (attr) {
65
- map[attr.code] = attr.value;
66
- });
67
- return map;
68
- } // 需要刷新数据的场景:显示模式、资源变化、配置变化、开关开启、概览
203
+ stopPoll = _useRequest.cancel; // 需要刷新数据的场景:显示模式、资源变化、配置变化、开关开启、概览
69
204
 
70
205
 
71
206
  (0, _react.useEffect)(function () {
@@ -87,46 +222,16 @@ var usePolling = function usePolling(props) {
87
222
  stopPoll();
88
223
  }
89
224
  };
90
- }, [pollingSwitch, resIdsList, displayConfig, resourceOverviewState.id, resourceOverviewState.metricCodes]);
91
- /**
92
- *
93
- * @returns {{id, attributes: object[], metrics: object[]}[]} 属性和指标
94
- */
95
-
96
- function refresh() {
97
- return _refresh.apply(this, arguments);
98
- }
99
-
100
- function _refresh() {
101
- _refresh = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
102
- return _regenerator["default"].wrap(function _callee$(_context) {
103
- while (1) {
104
- switch (_context.prev = _context.next) {
105
- case 0:
106
- if (!(!pollingSwitch || !(resAndMetrics !== null && resAndMetrics !== void 0 && resAndMetrics.resIdsList.length))) {
107
- _context.next = 2;
108
- break;
109
- }
110
-
111
- return _context.abrupt("return");
112
-
113
- case 2:
114
- _context.next = 4;
115
- return topo.attributeMetricDisplay.fetchData();
116
-
117
- case 4:
118
- return _context.abrupt("return", _context.sent);
119
-
120
- case 5:
121
- case "end":
122
- return _context.stop();
123
- }
124
- }
125
- }, _callee);
126
- }));
127
- return _refresh.apply(this, arguments);
128
- }
225
+ }, [pollingSwitch, resIdsList, displayConfig, resourceOverviewState.id, resourceOverviewState.metricCodes]); // 属性变更监听更新
129
226
 
227
+ (0, _componentRiilEventEmitter.useCbbEventListener)('topo', {
228
+ name: 'topo',
229
+ onMessage: function onMessage(message) {
230
+ if (message.type === 'attribute') {
231
+ var data = message.data;
232
+ }
233
+ }
234
+ });
130
235
  return {
131
236
  startPoll: startPoll,
132
237
  stopPoll: stopPoll