@nywqs/scada-engine 1.1.27 → 1.1.28

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.
@@ -0,0 +1,184 @@
1
+ /**
2
+ * 组件数据适配器类型定义
3
+ * 负责将原始数据转换为组件需要的格式
4
+ */
5
+ /**
6
+ * 数据提取器函数类型
7
+ * 用于从原始数据中提取需要的值
8
+ */
9
+ export type DataExtractor = (rawData: any) => any;
10
+ /**
11
+ * 数据转换器函数类型
12
+ * 用于将提取的数据转换为组件需要的格式
13
+ */
14
+ export type DataTransformer = (value: any, componentConfig?: any) => any;
15
+ /**
16
+ * 数据验证器函数类型
17
+ * 用于验证数据格式是否符合组件要求
18
+ */
19
+ export type DataValidator = (value: any) => boolean;
20
+ /**
21
+ * 组件数据适配器配置
22
+ */
23
+ export interface ComponentDataAdapter {
24
+ /**
25
+ * 数据转换函数(必需)
26
+ * 将提取的数据转换为组件需要的格式
27
+ *
28
+ * @param value - 从原始数据中提取的值
29
+ * @param componentConfig - 组件的配置(可选)
30
+ * @returns 组件需要的数据格式
31
+ *
32
+ * @example
33
+ * // 数值转仪表盘格式
34
+ * transform: (value, config) => ({
35
+ * value: Number(value),
36
+ * min: config.min || 0,
37
+ * max: config.max || 100
38
+ * })
39
+ */
40
+ transform: DataTransformer;
41
+ /**
42
+ * 数据验证函数(可选)
43
+ * 验证数据是否符合要求
44
+ *
45
+ * @param value - 需要验证的值
46
+ * @returns 验证是否通过
47
+ *
48
+ * @example
49
+ * validate: (value) => typeof value === 'number'
50
+ */
51
+ validate?: DataValidator;
52
+ /**
53
+ * 默认值(可选)
54
+ * 当数据为空或验证失败时使用
55
+ */
56
+ defaultValue?: any;
57
+ /**
58
+ * 错误处理函数(可选)
59
+ * 当转换失败时调用
60
+ */
61
+ onError?: (error: Error, value: any) => any;
62
+ }
63
+ /**
64
+ * 数据绑定配置(增强版)
65
+ */
66
+ export interface DataBindingConfig {
67
+ /**
68
+ * 数据源 ID
69
+ */
70
+ dataSourceId: string;
71
+ /**
72
+ * 目标属性(组件的哪个属性)
73
+ */
74
+ targetProperty: string;
75
+ /**
76
+ * 数据路径(JSONPath 或点分隔路径)
77
+ * 用于从原始数据中提取值
78
+ *
79
+ * @example
80
+ * 'temperature'
81
+ * 'sensors[0].data.temp'
82
+ * 'payload.devices.find(d => d.id === "001").value'
83
+ */
84
+ dataPath?: string;
85
+ /**
86
+ * 自定义数据提取器
87
+ * 当 dataPath 不够灵活时使用
88
+ */
89
+ extractor?: DataExtractor;
90
+ /**
91
+ * 映射配置(保留向后兼容)
92
+ */
93
+ mapping?: MappingConfig;
94
+ /**
95
+ * 是否启用
96
+ */
97
+ enabled?: boolean;
98
+ }
99
+ /**
100
+ * 映射配置(保留向后兼容)
101
+ */
102
+ export interface MappingConfig {
103
+ type: 'direct' | 'boolean' | 'range' | 'enum' | 'custom';
104
+ trueValue?: any;
105
+ falseValue?: any;
106
+ rangeRules?: Array<{
107
+ min: number;
108
+ max: number;
109
+ value: any;
110
+ }>;
111
+ enumMappings?: Record<string, any>;
112
+ customFunction?: string;
113
+ }
114
+ /**
115
+ * 数据适配器工具类
116
+ */
117
+ export declare class DataAdapterUtils {
118
+ /**
119
+ * 从原始数据中提取值(使用数据路径)
120
+ *
121
+ * @param rawData - 原始数据
122
+ * @param dataPath - 数据路径(点分隔或数组索引)
123
+ * @returns 提取的值
124
+ *
125
+ * @example
126
+ * extractByPath({ a: { b: { c: 1 } } }, 'a.b.c') // 返回 1
127
+ * extractByPath({ arr: [1, 2, 3] }, 'arr[1]') // 返回 2
128
+ */
129
+ static extractByPath(rawData: any, dataPath: string): any;
130
+ /**
131
+ * 使用提取器从原始数据中提取值
132
+ *
133
+ * @param rawData - 原始数据
134
+ * @param extractor - 提取器函数
135
+ * @returns 提取的值
136
+ */
137
+ static extractByFunction(rawData: any, extractor: DataExtractor): any;
138
+ /**
139
+ * 应用数据适配器
140
+ *
141
+ * @param value - 提取的值
142
+ * @param adapter - 数据适配器
143
+ * @param componentConfig - 组件配置
144
+ * @returns 转换后的值
145
+ */
146
+ static applyAdapter(value: any, adapter: ComponentDataAdapter | undefined, componentConfig?: any): any;
147
+ /**
148
+ * 应用旧版映射配置(向后兼容)
149
+ */
150
+ static applyMapping(value: any, mapping: MappingConfig | undefined): any;
151
+ }
152
+ /**
153
+ * 预设的数据适配器
154
+ */
155
+ export declare const PresetDataAdapters: {
156
+ /**
157
+ * 直传适配器(不做任何转换)
158
+ */
159
+ passthrough: ComponentDataAdapter;
160
+ /**
161
+ * 数值适配器(转换为数字)
162
+ */
163
+ number: ComponentDataAdapter;
164
+ /**
165
+ * 字符串适配器
166
+ */
167
+ string: ComponentDataAdapter;
168
+ /**
169
+ * 布尔适配器
170
+ */
171
+ boolean: ComponentDataAdapter;
172
+ /**
173
+ * 百分比适配器(0-1 转换为 0-100)
174
+ */
175
+ percentage: ComponentDataAdapter;
176
+ /**
177
+ * 仪表盘适配器
178
+ */
179
+ gauge: ComponentDataAdapter;
180
+ /**
181
+ * 颜色映射适配器
182
+ */
183
+ colorMap: ComponentDataAdapter;
184
+ };
@@ -1,4 +1,5 @@
1
1
  import { Graph } from '@antv/x6';
2
+ import { BindingConfig } from '../types/binding';
2
3
 
3
4
  /**
4
5
  * 数据绑定服务类
@@ -13,30 +14,58 @@ export declare class DataBindingService {
13
14
  /**
14
15
  * 初始化数据绑定监听
15
16
  */
16
- initDataBinding(): void;
17
+ private initDataBinding;
17
18
  /**
18
- * 同步数据到节点
19
+ * 处理数据源更新
19
20
  */
20
- private syncDataToNodes;
21
+ private handleDataUpdate;
21
22
  /**
22
- * 根据设备数据更新节点
23
+ * 更新单个节点的数据
23
24
  */
24
- private updateNodeFromDeviceData;
25
+ private updateNodeData;
25
26
  /**
26
- * 应用映射规则
27
+ * 从原始数据中提取点位值
28
+ *
29
+ * @param rawData 原始数据(后端返回的JSON)
30
+ * @param pointId 点位ID(如 "liquid_level")
31
+ * @returns 点位值
27
32
  */
28
- private applyMapping;
33
+ private extractPointValue;
29
34
  /**
30
- * 手动更新设备数据(用于外部传入的设备数据)
35
+ * 应用值映射转换
36
+ *
37
+ * @param value 原始值
38
+ * @param mapping 映射配置
39
+ * @returns 转换后的值
31
40
  */
32
- updateDeviceData(deviceData: any): void;
41
+ private applyValueMapping;
42
+ /**
43
+ * 布尔映射
44
+ */
45
+ private applyBooleanMapping;
46
+ /**
47
+ * 范围映射
48
+ */
49
+ private applyRangeMapping;
50
+ /**
51
+ * 枚举映射
52
+ */
53
+ private applyEnumMapping;
54
+ /**
55
+ * 应用更新到节点
56
+ */
57
+ private applyUpdatesToNode;
33
58
  /**
34
59
  * 获取节点的绑定配置
35
60
  */
36
- getNodeBindings(nodeId: string): any[];
61
+ getNodeBindings(nodeId: string): BindingConfig[];
37
62
  /**
38
63
  * 更新节点的绑定配置
39
64
  */
40
- updateNodeBindings(nodeId: string, bindings: any[]): boolean;
65
+ updateNodeBindings(nodeId: string, bindings: BindingConfig[]): boolean;
66
+ /**
67
+ * 清理资源
68
+ */
69
+ destroy(): void;
41
70
  }
42
71
  export declare const dataBindingService: DataBindingService;
@@ -8,9 +8,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
8
8
  close: () => void;
9
9
  }, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_TypePropsToRuntimeProps<Props>>> & Readonly<{
10
10
  onSave?: (() => any) | undefined;
11
+ onValidate?: (() => any) | undefined;
11
12
  onClear?: (() => any) | undefined;
12
13
  onClose?: (() => any) | undefined;
13
- onValidate?: (() => any) | undefined;
14
14
  }>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
15
15
  export default _default;
16
16
  type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nywqs/scada-engine",
3
- "version": "1.1.27",
3
+ "version": "1.1.28",
4
4
  "description": "自研 SCADA 组态引擎 - 基于 AntV X6",
5
5
  "type": "module",
6
6
  "main": "./dist/scada-engine.umd.js",