coolcare-lite-scada-component 2.0.27 → 2.0.29

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.
@@ -90,7 +90,7 @@ var EleFanComponent = function EleFanComponent(_ref) {
90
90
  className: styles.wrap
91
91
  }, /*#__PURE__*/React.createElement("img", {
92
92
  className: "".concat(styles['fan-img'], " ").concat(fanIsOn ? styles.on : ''),
93
- src: "/fan.png"
93
+ src: "http://10.189.40.132:9000/iot/fan.png"
94
94
  })));
95
95
  };
96
96
  export default /*#__PURE__*/memo(EleFanComponent, reactShapeNodeAreEqual);
@@ -39,11 +39,13 @@ declare namespace Ele {
39
39
  /** 打开链接 */
40
40
  | 'open-url'
41
41
  /** 点位值写入 */
42
- | 'write-point';
42
+ | 'write-point'
43
+ /** 场景组态切换 */
44
+ | 'freedom-scene-switch';
43
45
  export type Event = {
44
46
  type: EventType;
45
47
  action: EventAction;
46
- value?: string;
48
+ value?: any;
47
49
  payload?: any;
48
50
  };
49
51
 
@@ -142,4 +144,4 @@ declare namespace Ele {
142
144
  /** 12px | 12px 12px 12px 12px */
143
145
  margin?: `${number}px` | `${number}px ${number}px ${number}px ${number}px`;
144
146
  };
145
- }
147
+ }
@@ -53,6 +53,9 @@ export default function handleEleEvent() {
53
53
  return isString(v.identifierName);
54
54
  }));
55
55
  return;
56
+ case 'freedom-scene-switch':
57
+ emitter.emit("freedom-scene-switch-".concat(payload.namespace), event.value ? Number(event.value) : undefined);
58
+ return;
56
59
  default:
57
60
  return;
58
61
  }
@@ -27,10 +27,11 @@ import emitter from "../../../utils/events";
27
27
  import { GetDevicePoint } from "../../../services/gateway/Device";
28
28
  import "./index.css";
29
29
  /** 刷新频率 */
30
- var RefreshFrequency = 5 * 1000;
30
+ var RefreshFrequency = 1.5 * 60 * 1000;
31
31
  var Player = function Player(_ref) {
32
32
  var jsonConfig = _ref.jsonConfig,
33
- query = _ref.query;
33
+ query = _ref.query,
34
+ onEvent = _ref.onEvent;
34
35
  var graphRef = useRef(null);
35
36
  var wrapRef = useRef(null);
36
37
  var playerRef = useRef(null);
@@ -250,6 +251,43 @@ var Player = function Player(_ref) {
250
251
  emitter.off(eventName, handler);
251
252
  };
252
253
  }, [query, mittMeta]);
254
+
255
+ // 监听场景组态切换事件
256
+ useEffect(function () {
257
+ var handler = /*#__PURE__*/function () {
258
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(scadaId) {
259
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
260
+ while (1) switch (_context4.prev = _context4.next) {
261
+ case 0:
262
+ onEvent === null || onEvent === void 0 ? void 0 : onEvent({
263
+ event: 'freedom-scene-switch',
264
+ payload: {
265
+ scadaId: scadaId
266
+ }
267
+ });
268
+ console.log('[186]-index.tsx', onEvent, {
269
+ event: 'freedom-scene-switch',
270
+ payload: {
271
+ scadaId: scadaId
272
+ }
273
+ });
274
+ case 2:
275
+ case "end":
276
+ return _context4.stop();
277
+ }
278
+ }, _callee4);
279
+ }));
280
+ return function handler(_x4) {
281
+ return _ref6.apply(this, arguments);
282
+ };
283
+ }();
284
+ var mittMeta = getMittMeta(query);
285
+ var eventName = "freedom-scene-switch-".concat(mittMeta.namespace);
286
+ emitter.on(eventName, handler);
287
+ return function () {
288
+ emitter.off(eventName, handler);
289
+ };
290
+ }, [query, onEvent]);
253
291
  useEffect(function () {
254
292
  if (!playerRef.current) return;
255
293
  graphRef.current = new Graph({
@@ -308,23 +346,23 @@ var Player = function Player(_ref) {
308
346
  // scene === 'device' 加载设备点位数据
309
347
  useEffect(function () {
310
348
  var fetchDevicePoints = /*#__PURE__*/function () {
311
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(deviceId) {
349
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(deviceId) {
312
350
  var res, pointList;
313
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
314
- while (1) switch (_context4.prev = _context4.next) {
351
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
352
+ while (1) switch (_context5.prev = _context5.next) {
315
353
  case 0:
316
- _context4.next = 2;
354
+ _context5.next = 2;
317
355
  return GetDevicePoint({
318
356
  deviceIdList: [deviceId]
319
357
  }, []);
320
358
  case 2:
321
- res = _context4.sent;
359
+ res = _context5.sent;
322
360
  if (res.success) {
323
- _context4.next = 6;
361
+ _context5.next = 6;
324
362
  break;
325
363
  }
326
364
  message.error('设备点位数据获取失败');
327
- return _context4.abrupt("return");
365
+ return _context5.abrupt("return");
328
366
  case 6:
329
367
  pointList = res.data || [];
330
368
  pointList.forEach(function (v) {
@@ -333,12 +371,12 @@ var Player = function Player(_ref) {
333
371
  });
334
372
  case 8:
335
373
  case "end":
336
- return _context4.stop();
374
+ return _context5.stop();
337
375
  }
338
- }, _callee4);
376
+ }, _callee5);
339
377
  }));
340
- return function fetchDevicePoints(_x4) {
341
- return _ref6.apply(this, arguments);
378
+ return function fetchDevicePoints(_x5) {
379
+ return _ref7.apply(this, arguments);
342
380
  };
343
381
  }();
344
382
  var timer;
@@ -358,23 +396,23 @@ var Player = function Player(_ref) {
358
396
  // scene === 'freedom' 加载设备点位数据
359
397
  useEffect(function () {
360
398
  var fetchDevicePoints = /*#__PURE__*/function () {
361
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(ids) {
399
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(ids) {
362
400
  var res, pointList;
363
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
364
- while (1) switch (_context5.prev = _context5.next) {
401
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
402
+ while (1) switch (_context6.prev = _context6.next) {
365
403
  case 0:
366
- _context5.next = 2;
404
+ _context6.next = 2;
367
405
  return GetDevicePoint({
368
406
  pointIdList: ids
369
407
  }, []);
370
408
  case 2:
371
- res = _context5.sent;
409
+ res = _context6.sent;
372
410
  if (res.success) {
373
- _context5.next = 6;
411
+ _context6.next = 6;
374
412
  break;
375
413
  }
376
414
  message.error('设备点位数据获取失败');
377
- return _context5.abrupt("return");
415
+ return _context6.abrupt("return");
378
416
  case 6:
379
417
  pointList = res.data || [];
380
418
  pointList.forEach(function (v) {
@@ -382,12 +420,12 @@ var Player = function Player(_ref) {
382
420
  });
383
421
  case 8:
384
422
  case "end":
385
- return _context5.stop();
423
+ return _context6.stop();
386
424
  }
387
- }, _callee5);
425
+ }, _callee6);
388
426
  }));
389
- return function fetchDevicePoints(_x5) {
390
- return _ref7.apply(this, arguments);
427
+ return function fetchDevicePoints(_x6) {
428
+ return _ref8.apply(this, arguments);
391
429
  };
392
430
  }();
393
431
  var timer;
@@ -9,7 +9,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
9
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
10
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
11
11
  import React from "react";
12
- import { useEffect, useState, useRef } from 'react';
12
+ import { useEffect, useState } from 'react';
13
13
  import { message } from 'antd';
14
14
  import { queryToObject } from "../../utils";
15
15
  import { GetProductConfiguration } from "../../services/product/Product";
@@ -21,7 +21,8 @@ import ScadaEmpty from "./components/Empty";
21
21
  import styles from "./index.css";
22
22
  import { storeToken } from "../../utils/auth";
23
23
  var Display = function Display(_ref) {
24
- var query_ = _ref.query_;
24
+ var query_ = _ref.query_,
25
+ onEvent = _ref.onEvent;
25
26
  var _useState = useState(),
26
27
  _useState2 = _slicedToArray(_useState, 2),
27
28
  jsonConfig = _useState2[0],
@@ -30,7 +31,7 @@ var Display = function Display(_ref) {
30
31
  _useState4 = _slicedToArray(_useState3, 2),
31
32
  loading = _useState4[0],
32
33
  setLoading = _useState4[1];
33
- var queryRef = useRef(query_ || queryToObject(window.location.href));
34
+ var q = query_ || queryToObject(window.location.href);
34
35
  useEffect(function () {
35
36
  if (query_) {
36
37
  // 被当成组件使用时(非 iframe ),设置接口请求的 prefix
@@ -42,11 +43,13 @@ var Display = function Display(_ref) {
42
43
 
43
44
  // 获取组态配置
44
45
  useEffect(function () {
45
- var query = queryRef.current;
46
+ var query = query_ || queryToObject(window.location.href);
46
47
  if (!query) return;
47
48
  if (query.token && query.xToken) {
48
49
  storeToken(query.token, query.xToken);
49
50
  }
51
+
52
+ // 产品组态
50
53
  if (query.scene === 'product') {
51
54
  var fetchProductScadaConfig = /*#__PURE__*/function () {
52
55
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
@@ -106,6 +109,8 @@ var Display = function Display(_ref) {
106
109
  }();
107
110
  fetchProductScadaConfig();
108
111
  }
112
+
113
+ // 设备组态
109
114
  if (query.scene === 'device') {
110
115
  var fetchDeviceScadaConfig = /*#__PURE__*/function () {
111
116
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
@@ -160,10 +165,12 @@ var Display = function Display(_ref) {
160
165
  }();
161
166
  fetchDeviceScadaConfig();
162
167
  }
168
+
169
+ // 场景组态
163
170
  if (query.scene === 'freedom') {
164
171
  var _fetchDeviceScadaConfig = /*#__PURE__*/function () {
165
172
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
166
- var _data$list, _yield$GetCompanyConf, success, data, scadaConfig;
173
+ var _data$list, _configJSON$cells, _yield$GetCompanyConf, success, data, scadaConfig, configJSON;
167
174
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
168
175
  while (1) switch (_context3.prev = _context3.next) {
169
176
  case 0:
@@ -187,25 +194,39 @@ var Display = function Display(_ref) {
187
194
  return _context3.abrupt("return");
188
195
  case 10:
189
196
  scadaConfig = data.list[0].config;
197
+ configJSON = JSON.parse(scadaConfig || '{}'); // 修复后端保存数据时,因json数据种存在"%"而导致的"%"数据丢失问题
198
+ if (configJSON === null || configJSON === void 0 ? void 0 : (_configJSON$cells = configJSON.cells) === null || _configJSON$cells === void 0 ? void 0 : _configJSON$cells.length) {
199
+ configJSON === null || configJSON === void 0 ? void 0 : configJSON.cells.forEach(function (item) {
200
+ var _item$attrs, _item$attrs$body, _item$attrs2, _item$attrs2$body, _item$attrs2$body$ref, _item$attrs3, _item$attrs3$body, _item$attrs5, _item$attrs5$body, _item$attrs6, _item$attrs6$body, _item$attrs6$body$ref, _item$attrs7, _item$attrs7$body;
201
+ if ((item === null || item === void 0 ? void 0 : (_item$attrs = item.attrs) === null || _item$attrs === void 0 ? void 0 : (_item$attrs$body = _item$attrs.body) === null || _item$attrs$body === void 0 ? void 0 : _item$attrs$body.refWidth) && (item === null || item === void 0 ? void 0 : (_item$attrs2 = item.attrs) === null || _item$attrs2 === void 0 ? void 0 : (_item$attrs2$body = _item$attrs2.body) === null || _item$attrs2$body === void 0 ? void 0 : (_item$attrs2$body$ref = _item$attrs2$body.refWidth) === null || _item$attrs2$body$ref === void 0 ? void 0 : _item$attrs2$body$ref.indexOf('%')) === -1 && !isNaN(Number(item === null || item === void 0 ? void 0 : (_item$attrs3 = item.attrs) === null || _item$attrs3 === void 0 ? void 0 : (_item$attrs3$body = _item$attrs3.body) === null || _item$attrs3$body === void 0 ? void 0 : _item$attrs3$body.refWidth))) {
202
+ var _item$attrs4, _item$attrs4$body;
203
+ item.attrs.body.refWidth = "".concat(item === null || item === void 0 ? void 0 : (_item$attrs4 = item.attrs) === null || _item$attrs4 === void 0 ? void 0 : (_item$attrs4$body = _item$attrs4.body) === null || _item$attrs4$body === void 0 ? void 0 : _item$attrs4$body.refWidth, "%");
204
+ }
205
+ if ((item === null || item === void 0 ? void 0 : (_item$attrs5 = item.attrs) === null || _item$attrs5 === void 0 ? void 0 : (_item$attrs5$body = _item$attrs5.body) === null || _item$attrs5$body === void 0 ? void 0 : _item$attrs5$body.refHeight) && (item === null || item === void 0 ? void 0 : (_item$attrs6 = item.attrs) === null || _item$attrs6 === void 0 ? void 0 : (_item$attrs6$body = _item$attrs6.body) === null || _item$attrs6$body === void 0 ? void 0 : (_item$attrs6$body$ref = _item$attrs6$body.refHeight) === null || _item$attrs6$body$ref === void 0 ? void 0 : _item$attrs6$body$ref.indexOf('%')) === -1 && !isNaN(Number(item === null || item === void 0 ? void 0 : (_item$attrs7 = item.attrs) === null || _item$attrs7 === void 0 ? void 0 : (_item$attrs7$body = _item$attrs7.body) === null || _item$attrs7$body === void 0 ? void 0 : _item$attrs7$body.refHeight))) {
206
+ var _item$attrs8, _item$attrs8$body;
207
+ item.attrs.body.refHeight = "".concat(item === null || item === void 0 ? void 0 : (_item$attrs8 = item.attrs) === null || _item$attrs8 === void 0 ? void 0 : (_item$attrs8$body = _item$attrs8.body) === null || _item$attrs8$body === void 0 ? void 0 : _item$attrs8$body.refHeight, "%");
208
+ }
209
+ });
210
+ }
190
211
  if (scadaConfig) {
191
212
  setJsonConfig(JSON.parse((scadaConfig || '{}').replaceAll('https://coolcare-scada.oss-cn-shanghai.aliyuncs.com/', 'http://10.189.40.132:9000/iot/').replaceAll('https://front-end-assets.oss-cn-shanghai.aliyuncs.com/', 'http://10.189.40.132:9000/iot/')));
192
213
  }
193
- _context3.next = 18;
214
+ _context3.next = 20;
194
215
  break;
195
- case 14:
196
- _context3.prev = 14;
216
+ case 16:
217
+ _context3.prev = 16;
197
218
  _context3.t0 = _context3["catch"](0);
198
219
  console.error(_context3.t0);
199
220
  message.error('组态配置获取失败');
200
- case 18:
201
- _context3.prev = 18;
221
+ case 20:
222
+ _context3.prev = 20;
202
223
  setLoading(false);
203
- return _context3.finish(18);
204
- case 21:
224
+ return _context3.finish(20);
225
+ case 23:
205
226
  case "end":
206
227
  return _context3.stop();
207
228
  }
208
- }, _callee3, null, [[0, 14, 18, 21]]);
229
+ }, _callee3, null, [[0, 16, 20, 23]]);
209
230
  }));
210
231
  return function _fetchDeviceScadaConfig() {
211
232
  return _ref4.apply(this, arguments);
@@ -213,7 +234,7 @@ var Display = function Display(_ref) {
213
234
  }();
214
235
  _fetchDeviceScadaConfig();
215
236
  }
216
- }, []);
237
+ }, [query_]);
217
238
  useEffect(function () {
218
239
  window.addEventListener('message', function (e) {
219
240
  var data = e.data;
@@ -230,9 +251,10 @@ var Display = function Display(_ref) {
230
251
  return /*#__PURE__*/React.createElement("div", {
231
252
  className: styles.wrap,
232
253
  id: "scada-body"
233
- }, !!queryRef.current && /*#__PURE__*/React.createElement(Player, {
254
+ }, !!q && /*#__PURE__*/React.createElement(Player, {
234
255
  jsonConfig: jsonConfig,
235
- query: queryRef.current
256
+ query: q,
257
+ onEvent: onEvent
236
258
  }), !loading && !jsonConfig && /*#__PURE__*/React.createElement(ScadaEmpty, null));
237
259
  };
238
260
  export default Display;
@@ -35,6 +35,9 @@ var actionOptions = [{
35
35
  }, {
36
36
  label: '点位写入',
37
37
  value: 'write-point'
38
+ }, {
39
+ label: '场景组态切换',
40
+ value: 'freedom-scene-switch'
38
41
  }];
39
42
  var formLayout = {
40
43
  wrapperCol: {
@@ -170,16 +173,30 @@ var FormBindEvent = function FormBindEvent() {
170
173
  shouldUpdate: true
171
174
  }, function (_ref5) {
172
175
  var getFieldValue = _ref5.getFieldValue;
173
- return getFieldValue(['events', index, 'action']) === 'open-url' && /*#__PURE__*/React.createElement(Form.Item, _extends({}, field, {
174
- key: "".concat(field.key, "value"),
175
- label: "\u94FE\u63A5\xA0",
176
- name: [field.name, 'value'],
177
- fieldKey: [field.fieldKey, 'value'],
178
- rules: [{
179
- required: true,
180
- message: '请输入'
181
- }]
182
- }), /*#__PURE__*/React.createElement(Input, null));
176
+ if (getFieldValue(['events', index, 'action']) === 'open-url') {
177
+ return /*#__PURE__*/React.createElement(Form.Item, _extends({}, field, {
178
+ key: "".concat(field.key, "value"),
179
+ label: "\u94FE\u63A5\xA0",
180
+ name: [field.name, 'value'],
181
+ fieldKey: [field.fieldKey, 'value'],
182
+ rules: [{
183
+ required: true,
184
+ message: '请输入'
185
+ }]
186
+ }), /*#__PURE__*/React.createElement(Input, null));
187
+ }
188
+ if (getFieldValue(['events', index, 'action']) === 'freedom-scene-switch') {
189
+ return /*#__PURE__*/React.createElement(Form.Item, _extends({}, field, {
190
+ key: "".concat(field.key, "value"),
191
+ label: "\u573A\u666FID\xA0",
192
+ name: [field.name, 'value'],
193
+ fieldKey: [field.fieldKey, 'value'],
194
+ rules: [{
195
+ required: true,
196
+ message: '请输入'
197
+ }]
198
+ }), /*#__PURE__*/React.createElement(Input, null));
199
+ }
183
200
  }));
184
201
  }), /*#__PURE__*/React.createElement(Form.Item, {
185
202
  wrapperCol: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coolcare-lite-scada-component",
3
- "version": "2.0.27",
3
+ "version": "2.0.29",
4
4
  "scripts": {
5
5
  "start": "umi dev",
6
6
  "build:prod": "UMI_ENV=prod umi build",
@@ -13,7 +13,7 @@
13
13
  "test": "umi-test",
14
14
  "test:coverage": "umi-test --coverage",
15
15
  "analyze": "ANALYZE=1 umi build",
16
- "deploy:prod": "docker build -t xiiman-docker.pkg.coding.net/coolcare-lite/coolcare-scada/yimin:master-2024-11-12-2 . && docker push xiiman-docker.pkg.coding.net/coolcare-lite/coolcare-scada/yimin:master-2024-11-12-2"
16
+ "deploy:prod": "docker build -t xiiman-docker.pkg.coding.net/coolcare-lite/coolcare-scada/yimin:master-2024-12-1 . && docker push xiiman-docker.pkg.coding.net/coolcare-lite/coolcare-scada/yimin:master-2024-12-1"
17
17
  },
18
18
  "main": "./es/componentIndex.js",
19
19
  "module": "./es/componentIndex.js",