coolcare-lite-scada-component 1.0.43 → 1.0.44

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.
@@ -8,3 +8,25 @@
8
8
  left: 50%;
9
9
  transform: translate(-50%, -50%);
10
10
  }
11
+ .totalBox {
12
+ display: flex;
13
+ flex-direction: column;
14
+ width: 300px;
15
+ padding-left: 16px;
16
+ border-left: 1px solid #e8e8e8;
17
+ }
18
+ .totalBox .totalItem {
19
+ display: flex;
20
+ }
21
+ .totalBox .totalItem:not(:last-child) {
22
+ margin-bottom: 8px;
23
+ padding-bottom: 8px;
24
+ border-bottom: 1px solid #e8e8e8;
25
+ }
26
+ .totalBox .totalItem .totalItemTitle {
27
+ width: 80px;
28
+ font-weight: 600;
29
+ }
30
+ .totalBox .totalItem .totalItemContent {
31
+ flex: 1;
32
+ }
@@ -18,11 +18,12 @@ import { Modal, Form, message, InputNumber, DatePicker, Empty, Typography, Butto
18
18
  import moment from 'moment';
19
19
  import { useDebounceFn } from 'ahooks';
20
20
  import { GetPointHistoryData } from "../../services/gateway/Point";
21
- import ModalChoosePoint from "../ModalChoosePoint";
22
21
  import Echarts from "../ECharts";
23
22
  // @ts-ignore
24
23
 
25
24
  import styles from "./index.css";
25
+ import ModalChoosePoint from "../ModalChoosePoint";
26
+ import { dateDiff } from "../../utils/date";
26
27
  var Link = Typography.Link;
27
28
  var RangePicker = DatePicker.RangePicker;
28
29
  var defaultInterval = 2;
@@ -72,26 +73,28 @@ var DialogPointHistory = function DialogPointHistory(_ref) {
72
73
  _useState10 = _slicedToArray(_useState9, 2),
73
74
  pointIdList = _useState10[0],
74
75
  setPointIdList = _useState10[1];
75
- /** 当前点位时间段内是否有报警 */
76
- var _useState11 = useState(false),
76
+ var _useState11 = useState(undefined),
77
77
  _useState12 = _slicedToArray(_useState11, 2),
78
- haveAlarm = _useState12[0],
79
- setHaveAlarm = _useState12[1];
80
- var _useState13 = useState(undefined),
78
+ deviceId = _useState12[0],
79
+ setDeviceId = _useState12[1];
80
+ var _useState13 = useState([]),
81
81
  _useState14 = _slicedToArray(_useState13, 2),
82
- deviceId = _useState14[0],
83
- setDeviceId = _useState14[1];
84
- var _useState15 = useState([]),
82
+ tagList = _useState14[0],
83
+ setTagList = _useState14[1];
84
+ var _useState15 = useState(false),
85
85
  _useState16 = _slicedToArray(_useState15, 2),
86
- tagList = _useState16[0],
87
- setTagList = _useState16[1];
86
+ dataZoom = _useState16[0],
87
+ setDataZoom = _useState16[1];
88
+ var _useState17 = useState([]),
89
+ _useState18 = _slicedToArray(_useState17, 2),
90
+ dataZoomData = _useState18[0],
91
+ setDataZoomData = _useState18[1];
88
92
  var closeModal = function closeModal() {
89
93
  form.resetFields();
90
94
  setLoading(false);
91
95
  setChartOptions(undefined);
92
96
  setIsNoData(false);
93
97
  setVisiblePointSet(false);
94
- setHaveAlarm(false);
95
98
  setPointIdList([]);
96
99
  onCancel === null || onCancel === void 0 ? void 0 : onCancel();
97
100
  };
@@ -165,17 +168,13 @@ var DialogPointHistory = function DialogPointHistory(_ref) {
165
168
  setIsNoData(false);
166
169
  }
167
170
  data.forEach(function (item) {
168
- var _item$pointAlarmTimeF, _item$pointDataList;
171
+ var _item$pointDataList;
169
172
  setTagList(function (old) {
170
173
  return [].concat(_toConsumableArray(old), [{
171
174
  name: "".concat(item.deviceName, "-").concat(item.pointName),
172
175
  key: item.pointId
173
176
  }]);
174
177
  });
175
- // @ts-ignore
176
- if ((_item$pointAlarmTimeF = item.pointAlarmTimeFrameList) === null || _item$pointAlarmTimeF === void 0 ? void 0 : _item$pointAlarmTimeF.length) {
177
- setHaveAlarm(true);
178
- }
179
178
  var pointEnumId = item.pointEnumId,
180
179
  pointEnumItemList = item.pointEnumItemList;
181
180
  var unit = item.unit;
@@ -260,7 +259,7 @@ var DialogPointHistory = function DialogPointHistory(_ref) {
260
259
  }
261
260
  });
262
261
  });
263
-
262
+ chart.current.getEchartsInstance().resize();
264
263
  // 应用图形配置
265
264
  setChartOptions({
266
265
  color: ['#2297E8', '#48CE38', '#F8D156', '#FD9827', '#9764DC', '#1FCA6A'],
@@ -392,12 +391,16 @@ var DialogPointHistory = function DialogPointHistory(_ref) {
392
391
  title: "\u5386\u53F2\u6570\u636E\u66F2\u7EBF",
393
392
  open: visible,
394
393
  closable: true,
395
- width: 1300,
394
+ width: 1600,
396
395
  zIndex: 42000,
397
396
  footer: null,
398
397
  onCancel: closeModal,
399
398
  afterClose: closeModal,
400
399
  getContainer: false
400
+ }, /*#__PURE__*/React.createElement("div", {
401
+ className: "row"
402
+ }, /*#__PURE__*/React.createElement("div", {
403
+ className: "flex1"
401
404
  }, /*#__PURE__*/React.createElement(Form, {
402
405
  requiredMark: false,
403
406
  form: form,
@@ -479,12 +482,125 @@ var DialogPointHistory = function DialogPointHistory(_ref) {
479
482
  loading: loading,
480
483
  style: {
481
484
  height: '500px'
485
+ },
486
+ onEvents: {
487
+ datazoom: function datazoom(params) {
488
+ var _chart$current, _chart$current$getEch;
489
+ // 获取当前 echarts 实例
490
+ var myChart = chart === null || chart === void 0 ? void 0 : (_chart$current = chart.current) === null || _chart$current === void 0 ? void 0 : (_chart$current$getEch = _chart$current.getEchartsInstance) === null || _chart$current$getEch === void 0 ? void 0 : _chart$current$getEch.call(_chart$current);
491
+ if (!myChart) return;
492
+
493
+ // 获取当前配置
494
+ var option = myChart.getOption();
495
+ // 获取缩放范围
496
+ var startValue = params.start;
497
+ var endValue = params.end;
498
+ if (startValue === 0 && endValue === 100) {
499
+ setDataZoom(false);
500
+ return;
501
+ }
502
+ // 获取所有系列的数据
503
+ var visibleData = option.series.filter(function (item) {
504
+ return ['totalenergy', 'tlwatercs', 'tlhgscs'].includes(item.identifierName);
505
+ }).map(function (series) {
506
+ // 获取当前显示范围的数据
507
+ var data = series.data.filter(function (_, index) {
508
+ var percent = index / series.data.length * 100;
509
+ return percent >= startValue && percent <= endValue;
510
+ });
511
+ return {
512
+ name: series.name,
513
+ data: data
514
+ };
515
+ });
516
+ if (visibleData.length) {
517
+ setDataZoomData(visibleData);
518
+ setDataZoom(true);
519
+ } else {
520
+ setDataZoom(false);
521
+ }
522
+ console.log('当前显示的数据集合:', visibleData);
523
+ }
482
524
  }
483
525
  }), isNoData && /*#__PURE__*/React.createElement(Empty, {
484
526
  className: styles['chart-empty'],
485
527
  image: Empty.PRESENTED_IMAGE_SIMPLE,
486
528
  description: "\u6682\u65E0\u70B9\u4F4D\u5386\u53F2\u6570\u636E"
487
- })), /*#__PURE__*/React.createElement(ModalChoosePoint, {
529
+ }))), pointIdList.some(function (item) {
530
+ return ['totalenergy', 'tlwatercs', 'tlhgscs'].some(function (_item) {
531
+ return item.includes(_item);
532
+ });
533
+ }) ? /*#__PURE__*/React.createElement("div", {
534
+ className: styles.totalBox
535
+ }, /*#__PURE__*/React.createElement("div", {
536
+ className: styles.totalItem
537
+ }, /*#__PURE__*/React.createElement("div", {
538
+ className: styles.totalItemTitle
539
+ }, /*#__PURE__*/React.createElement("span", null, "\u65F6\u95F4\u8DE8\u5EA6\uFF1A")), /*#__PURE__*/React.createElement("div", {
540
+ className: styles.totalItemContent
541
+ }, /*#__PURE__*/React.createElement("span", null, dataZoom && dataZoomData.length ? function (_longestSeries$data) {
542
+ var longestSeries = dataZoomData.reduce(function (prev, curr) {
543
+ var _prev$data, _curr$data;
544
+ return ((prev === null || prev === void 0 ? void 0 : (_prev$data = prev.data) === null || _prev$data === void 0 ? void 0 : _prev$data.length) || 0) > ((curr === null || curr === void 0 ? void 0 : (_curr$data = curr.data) === null || _curr$data === void 0 ? void 0 : _curr$data.length) || 0) ? prev : curr;
545
+ });
546
+ if (!(longestSeries === null || longestSeries === void 0 ? void 0 : (_longestSeries$data = longestSeries.data) === null || _longestSeries$data === void 0 ? void 0 : _longestSeries$data.length)) return '-';
547
+ var firstPoint = longestSeries.data[0];
548
+ var lastPoint = longestSeries.data[longestSeries.data.length - 1];
549
+ return firstPoint && lastPoint ? dateDiff(firstPoint[0], lastPoint[0]) : '-';
550
+ }() : function () {
551
+ var dateRange = form.getFieldValue('dateRange');
552
+ return (dateRange === null || dateRange === void 0 ? void 0 : dateRange[0]) && (dateRange === null || dateRange === void 0 ? void 0 : dateRange[1]) ? dateDiff(dateRange[0], dateRange[1]) : '-';
553
+ }()))), /*#__PURE__*/React.createElement("div", {
554
+ className: styles.totalItem
555
+ }, /*#__PURE__*/React.createElement("div", {
556
+ className: styles.totalItemTitle
557
+ }, /*#__PURE__*/React.createElement("span", null, "\u8017", ['电', '水', '气'][['totalenergy', 'tlwatercs', 'tlhgscs'].findIndex(function (item) {
558
+ return pointIdList[0].includes(item);
559
+ })], "\u91CF\uFF1A")), /*#__PURE__*/React.createElement("div", {
560
+ className: styles.totalItemContent
561
+ }, (dataZoom ? dataZoomData : ((chartOptions === null || chartOptions === void 0 ? void 0 : chartOptions.series) || []).filter(function (item) {
562
+ return ['totalenergy', 'tlwatercs', 'tlhgscs'].includes(item.identifierName);
563
+ })).map(function (item) {
564
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", null, item.name, ": "), /*#__PURE__*/React.createElement("span", null, parseFloat((Math.max.apply(Math, _toConsumableArray(item.data.map(function (_item) {
565
+ return _item[1];
566
+ }))) - Math.min.apply(Math, _toConsumableArray(item.data.map(function (_item) {
567
+ return _item[1];
568
+ })))).toFixed(2))));
569
+ }))), /*#__PURE__*/React.createElement("div", {
570
+ className: styles.totalItem
571
+ }, /*#__PURE__*/React.createElement("div", {
572
+ className: styles.totalItemTitle
573
+ }, /*#__PURE__*/React.createElement("span", null, "\u671F\u672B\u503C\uFF1A")), /*#__PURE__*/React.createElement("div", {
574
+ className: styles.totalItemContent
575
+ }, ((dataZoom ? dataZoomData : chartOptions === null || chartOptions === void 0 ? void 0 : chartOptions.series.filter(function (item) {
576
+ return ['totalenergy', 'tlwatercs', 'tlhgscs'].includes(item.identifierName);
577
+ })) || []).map(function (item) {
578
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", null, item.name, ": "), /*#__PURE__*/React.createElement("span", null, Math.max.apply(Math, _toConsumableArray(item.data.map(function (_item) {
579
+ return _item[1];
580
+ })))));
581
+ }))), /*#__PURE__*/React.createElement("div", {
582
+ className: styles.totalItem
583
+ }, /*#__PURE__*/React.createElement("div", {
584
+ className: styles.totalItemTitle
585
+ }, /*#__PURE__*/React.createElement("span", null, "\u671F\u521D\u503C\uFF1A")), /*#__PURE__*/React.createElement("div", {
586
+ className: styles.totalItemContent
587
+ }, ((dataZoom ? dataZoomData : chartOptions === null || chartOptions === void 0 ? void 0 : chartOptions.series.filter(function (item) {
588
+ return ['totalenergy', 'tlwatercs', 'tlhgscs'].includes(item.identifierName);
589
+ })) || []).map(function (item) {
590
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", null, item.name, ": "), /*#__PURE__*/React.createElement("span", null, Math.min.apply(Math, _toConsumableArray(item.data.map(function (_item) {
591
+ return _item[1];
592
+ })))));
593
+ }))), /*#__PURE__*/React.createElement("div", {
594
+ className: styles.totalItem
595
+ }, /*#__PURE__*/React.createElement("div", {
596
+ className: styles.totalItemTitle
597
+ }, /*#__PURE__*/React.createElement("span", null, "\u8BA1\u91CF\u5355\u4F4D\uFF1A")), /*#__PURE__*/React.createElement("div", {
598
+ className: styles.totalItemContent
599
+ }, ((chartOptions === null || chartOptions === void 0 ? void 0 : chartOptions.series.filter(function (item) {
600
+ return ['totalenergy', 'tlwatercs', 'tlhgscs'].includes(item.identifierName);
601
+ })[0]) || {
602
+ unit: ''
603
+ }).unit))) : null), /*#__PURE__*/React.createElement(ModalChoosePoint, {
488
604
  visible: visiblePointSet,
489
605
  onSubmit: function onSubmit(val) {
490
606
  setPointIdList(function (pre) {
@@ -6,6 +6,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
7
  import React from "react";
8
8
  import { useEffect, useRef, useImperativeHandle, forwardRef } from 'react';
9
+ import { Spin } from 'antd';
9
10
  import { useSize } from 'ahooks';
10
11
  // 引入 echarts 核心模块,核心模块提供了 echarts 使用必须要的接口。
11
12
 
@@ -14,12 +15,14 @@ import styles from "./index.css";
14
15
  /** 默认的颜色组 */
15
16
  export var defaultColors = ['#1890FF', '#04C74C', '#FFCD00', '#253076', '#8F30E9', '#03C7C3'];
16
17
  var EChartsComponent = function EChartsComponent(_ref, ref) {
17
- var option = _ref.option,
18
+ var id = _ref.id,
19
+ option = _ref.option,
18
20
  style = _ref.style,
19
21
  className = _ref.className,
20
22
  _ref$loading = _ref.loading,
21
- loading = _ref$loading === void 0 ? false : _ref$loading;
22
- var echartLoaderStatus = useExternal('https://front-end-assets.oss-cn-shanghai.aliyuncs.com/package/echarts/5.2.2/echarts.min.js', {
23
+ loading = _ref$loading === void 0 ? false : _ref$loading,
24
+ onEvents = _ref.onEvents;
25
+ var echartLoaderStatus = useExternal('https://cdn.sinocold.net/package/echarts/5.2.2/echarts.min.js', {
23
26
  type: 'js',
24
27
  js: {
25
28
  async: true
@@ -41,34 +44,33 @@ var EChartsComponent = function EChartsComponent(_ref, ref) {
41
44
  useEffect(function () {
42
45
  if (wrapRef.current && echartLoaderStatus === 'ready') {
43
46
  // 初始化图表
47
+ // @ts-ignore
44
48
  chartInstance.current = window.echarts.init(wrapRef.current);
49
+ // 绑定事件
50
+ if (onEvents && chartInstance.current) {
51
+ Object.keys(onEvents).forEach(function (eventName) {
52
+ var _chartInstance$curren;
53
+ (_chartInstance$curren = chartInstance.current) === null || _chartInstance$curren === void 0 ? void 0 : _chartInstance$curren.on(eventName, onEvents[eventName]);
54
+ });
55
+ }
45
56
  // wrapRef.current.style.removeProperty('position')
46
57
  return function () {
47
- var _chartInstance$curren;
58
+ var _chartInstance$curren3;
48
59
  // 组件卸载时,调用 ECharts 的销毁函数
49
- (_chartInstance$curren = chartInstance.current) === null || _chartInstance$curren === void 0 ? void 0 : _chartInstance$curren.dispose();
60
+ Object.keys(onEvents).forEach(function (eventName) {
61
+ var _chartInstance$curren2;
62
+ (_chartInstance$curren2 = chartInstance.current) === null || _chartInstance$curren2 === void 0 ? void 0 : _chartInstance$curren2.off(eventName);
63
+ });
64
+ (_chartInstance$curren3 = chartInstance.current) === null || _chartInstance$curren3 === void 0 ? void 0 : _chartInstance$curren3.dispose();
50
65
  };
51
66
  }
52
67
  return function () {};
53
68
  }, [echartLoaderStatus]);
54
69
  useEffect(function () {
55
- var _chartInstance$curren2;
70
+ var _chartInstance$curren4;
56
71
  // 在 wrap 大小改变后,resize 图表
57
- (_chartInstance$curren2 = chartInstance.current) === null || _chartInstance$curren2 === void 0 ? void 0 : _chartInstance$curren2.resize();
72
+ (_chartInstance$curren4 = chartInstance.current) === null || _chartInstance$curren4 === void 0 ? void 0 : _chartInstance$curren4.resize();
58
73
  }, [size]);
59
- useEffect(function () {
60
- if (loading) {
61
- var _chartInstance$curren3;
62
- (_chartInstance$curren3 = chartInstance.current) === null || _chartInstance$curren3 === void 0 ? void 0 : _chartInstance$curren3.showLoading({
63
- color: '#40a9ff',
64
- lineWidth: 2,
65
- text: '加载中...'
66
- });
67
- } else {
68
- var _chartInstance$curren4;
69
- (_chartInstance$curren4 = chartInstance.current) === null || _chartInstance$curren4 === void 0 ? void 0 : _chartInstance$curren4.hideLoading();
70
- }
71
- }, [loading]);
72
74
  useEffect(function () {
73
75
  // 监听 props.option, 变更后重新渲染图表
74
76
  if (!option) {
@@ -84,11 +86,17 @@ var EChartsComponent = function EChartsComponent(_ref, ref) {
84
86
  }, option));
85
87
  }
86
88
  }, [option, echartLoaderStatus]);
87
- return /*#__PURE__*/React.createElement("div", {
88
- style: style
89
+ return /*#__PURE__*/React.createElement(Spin, {
90
+ spinning: loading || echartLoaderStatus === 'loading',
91
+ delay: 200
89
92
  }, /*#__PURE__*/React.createElement("div", {
93
+ id: id,
90
94
  ref: wrapRef,
91
- className: "".concat(styles.echarts, " ").concat(className)
95
+ className: "".concat(styles.echarts, " ").concat(className),
96
+ style: style || {
97
+ height: '220px',
98
+ width: '100%'
99
+ }
92
100
  }));
93
101
  };
94
102
  export default /*#__PURE__*/forwardRef(EChartsComponent);
@@ -0,0 +1,7 @@
1
+ export function dateDiff(str, end) {
2
+ var diff = (new Date(end).getTime() - new Date(str).getTime()) / 1000;
3
+ var d = Math.floor(diff / (60 * 60 * 24));
4
+ var h = Math.floor(diff % (60 * 60 * 24) / 60 / 60);
5
+ var m = Math.floor(diff % (60 * 60) / 60);
6
+ return "".concat(d ? "".concat(d, "\u5929") : '').concat(h ? "".concat(h, "\u5C0F\u65F6") : '', "".concat(m, "\u5206\u949F"));
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coolcare-lite-scada-component",
3
- "version": "1.0.43",
3
+ "version": "1.0.44",
4
4
  "scripts": {
5
5
  "start": " umi dev",
6
6
  "build:prod": "UMI_ENV=prod umi build",