@ticatec/uniface-flexi-module 0.2.5 → 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.
- package/dist/criteria-panel/components/InputOptionSelectSearchField.svelte +1 -1
- package/dist/criteria-panel/lib/CriteriaFieldBuilder.js +2 -2
- package/dist/criteria-panel/lib/FlexiCriteriaField.d.ts +2 -0
- package/dist/criteria-panel/lib/FlexiCriteriaField.js +6 -0
- package/dist/criteria-panel/lib/FlexiCriteriaSet.js +2 -5
- package/dist/flexi-form/components/CascadeOptionSelectField.svelte +3 -1
- package/dist/flexi-form/components/CellFieldBuilder.js +1 -1
- package/dist/flexi-form/flexi_field/FlexiField.d.ts +4 -0
- package/dist/flexi-form/flexi_field/FlexiField.js +4 -0
- package/dist/flexi-form/flexi_form/FlexiForm.d.ts +11 -0
- package/dist/flexi-form/flexi_form/FlexiForm.js +38 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +10 -1
- package/package.json +1 -1
|
@@ -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
|
|
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;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts">import CascadeOptionSelect from "@ticatec/uniface-element/CascadeOptionsSelect";
|
|
2
2
|
import FlexiField from "../flexi_field/FlexiField";
|
|
3
|
+
import utils from "../../utils";
|
|
3
4
|
export let field;
|
|
4
5
|
export let readonly;
|
|
5
6
|
export let disabled;
|
|
@@ -7,7 +8,8 @@ export let variant;
|
|
|
7
8
|
$: props = field.props;
|
|
8
9
|
$: data = field.data;
|
|
9
10
|
$: events = field.events;
|
|
11
|
+
$: text = field.dataFields['textField'] ? utils.extractFieldValue(field.rawData, field.dataFields['textField']) ?? '' : '';
|
|
10
12
|
</script>
|
|
11
13
|
|
|
12
|
-
<CascadeOptionSelect bind:value={data[field.keyField]} variant={variant??field.variant} readonly={readonly || field.isReadonly}
|
|
14
|
+
<CascadeOptionSelect bind:value={data[field.keyField]} variant={variant??field.variant} readonly={readonly || field.isReadonly} {text}
|
|
13
15
|
disabled={disabled || field.disabled} {...props} {...events}/>
|
|
@@ -106,7 +106,7 @@ const buildUnitNumberField = (schema, dictLoader) => {
|
|
|
106
106
|
const buildCascadeOptionSelect = (schema, dictLoader) => {
|
|
107
107
|
const props = schema.props;
|
|
108
108
|
if (schema.dictName) {
|
|
109
|
-
props.
|
|
109
|
+
props.nodes = [dictLoader(schema.dictName)];
|
|
110
110
|
}
|
|
111
111
|
return {
|
|
112
112
|
component: CascadeOptionSelectField,
|
|
@@ -22,6 +22,8 @@ export interface FlexiFieldSchema {
|
|
|
22
22
|
type: string;
|
|
23
23
|
/** 字段的名称 */
|
|
24
24
|
keyField: string;
|
|
25
|
+
/** 其他的数据字段 */
|
|
26
|
+
dataFields: Record<string, string>;
|
|
25
27
|
/** 字段的名称 */
|
|
26
28
|
name: string;
|
|
27
29
|
/** 关联的数据字典项目 */
|
|
@@ -49,8 +51,10 @@ export interface FlexiFieldSchema {
|
|
|
49
51
|
}
|
|
50
52
|
export default class FlexiField {
|
|
51
53
|
#private;
|
|
54
|
+
readonly rawData: any;
|
|
52
55
|
readonly data: any;
|
|
53
56
|
readonly keyField: string;
|
|
57
|
+
readonly dataFields: Record<string, string>;
|
|
54
58
|
readonly component: typeof SvelteComponent;
|
|
55
59
|
readonly variant?: "" | "outlined" | "filled";
|
|
56
60
|
visibility: Visibility;
|
|
@@ -6,8 +6,10 @@ import i18nRes from "../../i18n-res";
|
|
|
6
6
|
import { i18nUtils } from "@ticatec/i18n";
|
|
7
7
|
export default class FlexiField {
|
|
8
8
|
#parent;
|
|
9
|
+
rawData;
|
|
9
10
|
data;
|
|
10
11
|
keyField;
|
|
12
|
+
dataFields;
|
|
11
13
|
component;
|
|
12
14
|
variant;
|
|
13
15
|
visibility = Visibility.View;
|
|
@@ -29,6 +31,7 @@ export default class FlexiField {
|
|
|
29
31
|
this.isReadonly = schema.readonly == true;
|
|
30
32
|
this.disabled = schema.disabled == true;
|
|
31
33
|
this.required = schema.required == true;
|
|
34
|
+
this.dataFields = schema.dataFields;
|
|
32
35
|
this.#cell = schema.cell;
|
|
33
36
|
const card = parent instanceof FlexiCard ? parent : parent.card;
|
|
34
37
|
if (schema.events) {
|
|
@@ -52,6 +55,7 @@ export default class FlexiField {
|
|
|
52
55
|
this.#props[key] = (...args) => card[classMethod]?.(...args);
|
|
53
56
|
}
|
|
54
57
|
}
|
|
58
|
+
this.rawData = data;
|
|
55
59
|
const result = utils.getParentAndKey(data, schema.keyField);
|
|
56
60
|
this.keyField = result?.key;
|
|
57
61
|
this.data = result?.parent;
|
|
@@ -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/dist/utils.d.ts
CHANGED
|
@@ -8,5 +8,6 @@ declare const _default: {
|
|
|
8
8
|
formatText: (s: string, obj: any) => string;
|
|
9
9
|
propsFilter: (attrs: any, excludes?: Array<string>) => any;
|
|
10
10
|
getScopeVariable: (key: string) => any;
|
|
11
|
+
extractFieldValue: (data: any, keyPath: string) => any;
|
|
11
12
|
};
|
|
12
13
|
export default _default;
|
package/dist/utils.js
CHANGED
|
@@ -62,10 +62,19 @@ const getParentAndKey = (data, keyPath) => {
|
|
|
62
62
|
return { parent: data, key: keyPath };
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* 萃取字段值
|
|
67
|
+
* @param data
|
|
68
|
+
* @param keyPath
|
|
69
|
+
*/
|
|
70
|
+
const extractFieldValue = (data, keyPath) => {
|
|
71
|
+
let nestObj = getParentAndKey(data, keyPath);
|
|
72
|
+
return nestObj.parent[nestObj.key];
|
|
73
|
+
};
|
|
65
74
|
const formatText = (s, obj) => {
|
|
66
75
|
return s.replace(/\{\{(.*?)\}\}/g, (_, key) => {
|
|
67
76
|
key = key.trim();
|
|
68
77
|
return obj.hasOwnProperty(key) ? String(obj[key]) : `{{${key}}}`;
|
|
69
78
|
});
|
|
70
79
|
};
|
|
71
|
-
export default { copyAttrs, extractExpression, getParentAndKey, formatText, propsFilter, getScopeVariable };
|
|
80
|
+
export default { copyAttrs, extractExpression, getParentAndKey, formatText, propsFilter, getScopeVariable, extractFieldValue };
|
package/package.json
CHANGED