@ticatec/uniface-flexi-module 0.2.6 → 0.2.8

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.
@@ -6,4 +6,4 @@ export let variant;
6
6
  export let events = null;
7
7
  </script>
8
8
 
9
- <InputOptionSelect {...props} {...events} {variant} bind:value={criteria[keyField]} {...events}/>
9
+ <InputOptionSelect {...props} {...events} {variant} bind:value={criteria[keyField]}/>
@@ -84,8 +84,8 @@ const buildCascadeField = (schema, dictLoader) => {
84
84
  const props = schema.props;
85
85
  return {
86
86
  component: CascadeSelectSearchField,
87
- keyFields: { keyField: schema.keys.valueField, textField: schema.keys.textField },
88
- props: utils.propsFilter(props, ['value', "disabled", "readonly", "mandatory", "displayMode"])
87
+ keyFields: { keyField: schema.keys.valueField },
88
+ props: { ...utils.propsFilter(props, ['value', "disabled", "readonly", "mandatory", "displayMode"]), nodes: [dictLoader(schema.dictName)] }
89
89
  };
90
90
  };
91
91
  const buildInputOptionsField = (schema, dictLoader) => {
@@ -17,6 +17,8 @@ export interface FlexiCriteriaFieldSchema {
17
17
  label: string;
18
18
  /** 事件 */
19
19
  events?: Record<string, string>;
20
+ /** 事件 */
21
+ methods?: Record<string, string>;
20
22
  /** 在卡片/Block中所在单元格的属性,flex布局和grid布局对应的属性也不一样*/
21
23
  size?: 'x15' | 'x20' | 'x25' | 'x30' | 'x35' | 'x40';
22
24
  /** 字段的属性 */
@@ -29,6 +29,12 @@ export default class FlexiCriteriaField {
29
29
  this.#props[key] = utils.getScopeVariable(cellField.props[key]);
30
30
  }
31
31
  }
32
+ if (schema.methods) {
33
+ for (let key in schema.methods) {
34
+ let method = schema.methods[key];
35
+ this.#props[key] = (...args) => set[method]?.(...args);
36
+ }
37
+ }
32
38
  this.keys = cellField.keyFields;
33
39
  }
34
40
  get props() {
@@ -14,18 +14,15 @@ export default class FlexiCriteriaSet {
14
14
  this._arrangement = schema.arrangement ?? 'vertical';
15
15
  this._label$style = schema.label$style;
16
16
  this._variant = schema.variant ?? 'outlined';
17
- const dicts = [];
17
+ const dicts = schema.fields.filter(item => item.dictName != null).map(item => item.dictName);
18
+ this.#dictionaries = dicts.length > 0 ? await FlexiContext.getInstance().loadDictionaries(dicts) : {};
18
19
  for (const fieldSchema of schema.fields) {
19
- if (fieldSchema.dictName && !dicts.includes(fieldSchema.dictName)) {
20
- dicts.push(fieldSchema.dictName);
21
- }
22
20
  const field = new FlexiCriteriaField(this, fieldSchema);
23
21
  this.#fields.push(field);
24
22
  if (fieldSchema.name) {
25
23
  this.field[fieldSchema.name] = field;
26
24
  }
27
25
  }
28
- this.#dictionaries = await FlexiContext.getInstance().loadDictionaries(dicts);
29
26
  }
30
27
  setInvalidateHandler(value) {
31
28
  this.#onInvalidate = value;
@@ -66,6 +66,17 @@ export default abstract class FlexiForm {
66
66
  * @private
67
67
  */
68
68
  private isProxy;
69
+ /**
70
+ * 将响应式数据转换为纯对象(用于序列化)
71
+ * @param obj 响应式数据对象
72
+ * @returns 纯对象
73
+ */
74
+ private toRawObject;
75
+ /**
76
+ * 获取可序列化的表单数据(不包含Proxy)
77
+ * @returns 纯对象数据
78
+ */
79
+ getRawData(): any;
69
80
  /**
70
81
  * 构造表单
71
82
  */
@@ -29,6 +29,17 @@ export default class FlexiForm {
29
29
  createReactiveData(data) {
30
30
  const self = this;
31
31
  const createProxy = (target, path = '') => {
32
+ // 添加toJSON方法到目标对象,用于JSON序列化
33
+ if (!target.toJSON) {
34
+ Object.defineProperty(target, 'toJSON', {
35
+ enumerable: false,
36
+ configurable: true,
37
+ writable: false,
38
+ value: function () {
39
+ return self.toRawObject(this);
40
+ }
41
+ });
42
+ }
32
43
  return new Proxy(target, {
33
44
  set(obj, prop, value) {
34
45
  if (typeof prop === 'symbol') {
@@ -75,6 +86,33 @@ export default class FlexiForm {
75
86
  return false;
76
87
  }
77
88
  }
89
+ /**
90
+ * 将响应式数据转换为纯对象(用于序列化)
91
+ * @param obj 响应式数据对象
92
+ * @returns 纯对象
93
+ */
94
+ toRawObject(obj) {
95
+ if (obj === null || typeof obj !== 'object') {
96
+ return obj;
97
+ }
98
+ if (Array.isArray(obj)) {
99
+ return obj.map(item => this.toRawObject(item));
100
+ }
101
+ const result = {};
102
+ for (const key in obj) {
103
+ if (obj.hasOwnProperty(key)) {
104
+ result[key] = this.toRawObject(obj[key]);
105
+ }
106
+ }
107
+ return result;
108
+ }
109
+ /**
110
+ * 获取可序列化的表单数据(不包含Proxy)
111
+ * @returns 纯对象数据
112
+ */
113
+ getRawData() {
114
+ return this.toRawObject(this.#data);
115
+ }
78
116
  /**
79
117
  * 构造表单
80
118
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ticatec/uniface-flexi-module",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "A flexible form framework for Svelte applications with dynamic field types, criteria panels, and modular components",
5
5
  "keywords": [
6
6
  "svelte",