@flexem/fc-gui 3.0.0-alpha.116 → 3.0.0-alpha.118

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.
@@ -72,6 +72,7 @@ export class ReadableElement extends ConditionalEnableElement {
72
72
  });
73
73
  }
74
74
  reportValueChanged(value) {
75
+ var _a, _b, _c, _d;
75
76
  forEach(this.elementStates, elementState => {
76
77
  if (elementState.variableName === value.variableName || elementState.variableName === value.systemName) {
77
78
  elementState.state = value.state;
@@ -85,20 +86,21 @@ export class ReadableElement extends ConditionalEnableElement {
85
86
  }
86
87
  if (value.systemName === '设备状态') {
87
88
  let name = value.customStatus;
88
- const language = window.abp.localization.currentCulture.name;
89
+ const language = ((_b = (_a = window.abp.localization) === null || _a === void 0 ? void 0 : _a.currentCulture) === null || _b === void 0 ? void 0 : _b.name) || ((_d = (_c = this.localization.localizationService) === null || _c === void 0 ? void 0 : _c.translate) === null || _d === void 0 ? void 0 : _d.currentLang);
90
+ const isChinese = language === 'zh-Hans' || language === 'zh';
89
91
  if (!name) {
90
92
  switch (value.state) {
91
93
  case 1:
92
- name = language === 'zh-Hans' ? '在线' : 'Online';
94
+ name = isChinese ? '在线' : 'Online';
93
95
  break;
94
96
  case 3:
95
- name = language === 'zh-Hans' ? '离线' : 'Offline';
97
+ name = isChinese ? '离线' : 'Offline';
96
98
  break;
97
99
  case 4:
98
- name = language === 'zh-Hans' ? '告警' : 'Alarming';
100
+ name = isChinese ? '告警' : 'Alarming';
99
101
  break;
100
102
  case 5:
101
- name = language === 'zh-Hans' ? '未绑定' : 'Unbound';
103
+ name = isChinese ? '未绑定' : 'Unbound';
102
104
  break;
103
105
  default:
104
106
  }
@@ -16,7 +16,6 @@ export declare class TextStateElement {
16
16
  constructor(textStates: TextState[], width: number, height: number, logger: LoggerService, version?: number, faultFlickers?: IndicatorLightFaultFlicker[]);
17
17
  switchToState(stateId: number): void;
18
18
  private getforeignObjectElement;
19
- private createNewForeignObjectText;
20
19
  private removeForeignObjectlement;
21
20
  private doFaultFlicker;
22
21
  private clearFlickerInterval;
@@ -1,5 +1,4 @@
1
1
  import { Flicker } from '../../../model';
2
- import { isNil } from 'lodash';
3
2
  export class TextStateElement {
4
3
  constructor(textStates, width, height, logger, version, faultFlickers) {
5
4
  this.textStates = textStates;
@@ -23,7 +22,7 @@ export class TextStateElement {
23
22
  return;
24
23
  }
25
24
  const content = textState.text.content;
26
- if (content === '') {
25
+ if (content === '' || content == null) {
27
26
  this.removeForeignObjectlement();
28
27
  return;
29
28
  }
@@ -33,72 +32,51 @@ export class TextStateElement {
33
32
  this.logger.debug('The font is undefined.');
34
33
  return;
35
34
  }
36
- const foreignObjectElement = this.getforeignObjectElement();
37
- foreignObjectElement.innerHTML = '';
38
- const text = this.createNewForeignObjectText(content, font);
39
- foreignObjectElement.appendChild(text);
40
- this.doFaultFlicker(foreignObjectElement, stateId);
35
+ const textElement = this.getforeignObjectElement();
36
+ // 清空旧内容
37
+ textElement.textContent = '';
38
+ // 设置 text-anchor 和 dominant-baseline
39
+ textElement.setAttribute('text-anchor', 'middle');
40
+ textElement.setAttribute('dominant-baseline', 'middle');
41
+ textElement.setAttribute('pointer-events', 'auto');
42
+ // 拆分换行
43
+ const lines = content.split('\n');
44
+ const fontSize = parseInt(font.fontSize, 10);
45
+ const lineHeight = fontSize + 4;
46
+ // 总高度 = 行数 * 行高
47
+ const totalHeight = lines.length * lineHeight;
48
+ // 调整文本整体垂直居中(通过 dy)
49
+ const startY = (this.height / 2) - (totalHeight / 2) + (lineHeight / 2);
50
+ // 添加每行文本
51
+ for (let i = 0; i < lines.length; i++) {
52
+ const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
53
+ tspan.setAttribute('x', (this.width / 2).toString());
54
+ tspan.setAttribute('y', startY + i * lineHeight + 'px');
55
+ tspan.textContent = lines[i].replace(/ /g, '\u00A0');
56
+ tspan.setAttribute('font-size', font.fontSize);
57
+ tspan.setAttribute('fill', font.color);
58
+ tspan.setAttribute('font-family', font.fontFamily);
59
+ tspan.setAttribute('font-weight', font.isBold ? 'bold' : 'normal');
60
+ tspan.setAttribute('font-style', font.isItalic ? 'italic' : 'normal');
61
+ tspan.setAttribute('text-decoration', font.isUnderline ? 'underline' : 'none');
62
+ tspan.setAttribute('text-anchor', 'middle');
63
+ tspan.setAttribute('dominant-baseline', 'middle');
64
+ textElement.appendChild(tspan);
65
+ }
66
+ this.doFaultFlicker(textElement, stateId);
41
67
  }
42
68
  getforeignObjectElement() {
43
69
  if (!this.textElement) {
44
- this.textElement = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
45
- this.textElement.setAttribute('width', this.width.toString());
46
- this.textElement.setAttribute('height', this.height.toString());
70
+ this.textElement = document.createElementNS('http://www.w3.org/2000/svg', 'text');
71
+ this.textElement.setAttribute('x', (this.width / 2).toString());
72
+ this.textElement.setAttribute('y', (this.height / 2).toString());
73
+ this.textElement.setAttribute('text-anchor', 'middle');
74
+ this.textElement.setAttribute('dominant-baseline', 'middle');
75
+ this.textElement.setAttribute('pointer-events', 'auto'); // 确保能接收事件
47
76
  this._element.appendChild(this.textElement);
48
77
  }
49
78
  return this.textElement;
50
79
  }
51
- createNewForeignObjectText(content, font) {
52
- if (font && !font.fontFamily.includes(',msyh')) {
53
- font.fontFamily += ',msyh';
54
- }
55
- const bodyDiv = document.createElement('div');
56
- bodyDiv.style.textAlign = font.textAlign ? font.textAlign : 'center';
57
- bodyDiv.style.userSelect = 'none';
58
- bodyDiv.style.display = 'table-cell';
59
- bodyDiv.style.verticalAlign = 'middle';
60
- if (isNil(content)) {
61
- content = '';
62
- }
63
- let textArray = content.toString().split('\n');
64
- textArray = textArray.map(item => {
65
- return item.toString().replace(/\s/g, '&nbsp;');
66
- });
67
- const fragment = document.createDocumentFragment();
68
- for (let index = 0; index < textArray.length; index++) {
69
- const textDiv = document.createElement('div');
70
- textDiv.innerHTML = textArray[index] ? textArray[index] : '&nbsp;';
71
- let fontString = '';
72
- if (font.isItalic) {
73
- fontString += 'italic ';
74
- }
75
- if (font.isBold) {
76
- fontString += 'bold ';
77
- }
78
- textDiv.style.wordBreak = 'break-word';
79
- textDiv.style.color = font.color;
80
- let lineHeight = 0;
81
- lineHeight = parseInt(font.fontSize, 10) + 5;
82
- fontString += font.fontSize + 'px/' + lineHeight + 'px ' + font.fontFamily;
83
- textDiv.style.font = fontString;
84
- if (font.isUnderline) {
85
- textDiv.style.textDecoration = 'underline';
86
- }
87
- fragment.appendChild(textDiv);
88
- }
89
- bodyDiv.appendChild(fragment);
90
- const contentDiv = document.createElement('div');
91
- contentDiv.style.display = 'table';
92
- contentDiv.style.width = '100%';
93
- contentDiv.style.height = '100%';
94
- contentDiv.appendChild(bodyDiv);
95
- const containerDiv = document.createElement('div');
96
- containerDiv.style.overflow = 'hidden';
97
- containerDiv.style.width = this.width.toString() + 'px';
98
- containerDiv.style.height = this.height.toString() + 'px';
99
- containerDiv.appendChild(contentDiv);
100
- return containerDiv;
101
- }
102
80
  removeForeignObjectlement() {
103
81
  if (this.textElement) {
104
82
  this._element.removeChild(this.textElement);
@@ -1 +1 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"TextStateElement":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","module":"./text-state.model","name":"TextState","line":18,"character":45}]},{"__symbolic":"reference","name":"number"},{"__symbolic":"reference","name":"number"},{"__symbolic":"reference","module":"../../../logger","name":"LoggerService","line":21,"character":33},{"__symbolic":"reference","name":"number"},{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","module":"../../../model/switch-indicator-light/indicator-light-fault-flicker","name":"IndicatorLightFaultFlicker","line":23,"character":41}]}]}],"switchToState":[{"__symbolic":"method"}],"getforeignObjectElement":[{"__symbolic":"method"}],"createNewForeignObjectText":[{"__symbolic":"method"}],"removeForeignObjectlement":[{"__symbolic":"method"}],"doFaultFlicker":[{"__symbolic":"method"}],"clearFlickerInterval":[{"__symbolic":"method"}]}}}}]
1
+ [{"__symbolic":"module","version":4,"metadata":{"TextStateElement":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","module":"./text-state.model","name":"TextState","line":17,"character":45}]},{"__symbolic":"reference","name":"number"},{"__symbolic":"reference","name":"number"},{"__symbolic":"reference","module":"../../../logger","name":"LoggerService","line":20,"character":33},{"__symbolic":"reference","name":"number"},{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","module":"../../../model/switch-indicator-light/indicator-light-fault-flicker","name":"IndicatorLightFaultFlicker","line":22,"character":41}]}]}],"switchToState":[{"__symbolic":"method"}],"getforeignObjectElement":[{"__symbolic":"method"}],"removeForeignObjectlement":[{"__symbolic":"method"}],"doFaultFlicker":[{"__symbolic":"method"}],"clearFlickerInterval":[{"__symbolic":"method"}]}}}}]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "main": "bundles/fc-gui.umd.js",
3
- "version": "3.0.0-alpha.116",
3
+ "version": "3.0.0-alpha.118",
4
4
  "module": "public_api.js",
5
5
  "typings": "public_api.d.ts",
6
6
  "license": "UNLICENSED",