@ticatec/uniface-flexi-module 0.0.2
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/FLEXICRITERIASET_GUIDE.md +1559 -0
- package/FLEXICRITERIASET_GUIDE_CN.md +1133 -0
- package/FLEXIDATATABLE_GUIDE.md +1650 -0
- package/FLEXIDATATABLE_GUIDE_CN.md +1650 -0
- package/FLEXIFORM_GUIDE.md +1068 -0
- package/FLEXIFORM_GUIDE_CN.md +1068 -0
- package/FLEXI_CONTEXT_GUIDE_CN.md +172 -0
- package/MODULE_LOADER_CN.md +228 -0
- package/README.md +307 -0
- package/README_CN.md +51 -0
- package/SANDBOX_CN.md +201 -0
- package/dist/FlexiContext.d.ts +28 -0
- package/dist/FlexiContext.js +45 -0
- package/dist/ModuleLoader.d.ts +41 -0
- package/dist/ModuleLoader.js +55 -0
- package/dist/Sandbox.d.ts +33 -0
- package/dist/Sandbox.js +101 -0
- package/dist/criteria-panel/CriteriaFieldsPanel.svelte +26 -0
- package/dist/criteria-panel/CriteriaFieldsPanel.svelte.d.ts +22 -0
- package/dist/criteria-panel/components/CascadeSelectSearchField.svelte +10 -0
- package/dist/criteria-panel/components/CascadeSelectSearchField.svelte.d.ts +25 -0
- package/dist/criteria-panel/components/DateRangeField.svelte +11 -0
- package/dist/criteria-panel/components/DateRangeField.svelte.d.ts +25 -0
- package/dist/criteria-panel/components/DateSearchField.svelte +10 -0
- package/dist/criteria-panel/components/DateSearchField.svelte.d.ts +24 -0
- package/dist/criteria-panel/components/DateTimeSearchField.svelte +10 -0
- package/dist/criteria-panel/components/DateTimeSearchField.svelte.d.ts +24 -0
- package/dist/criteria-panel/components/InputOptionSelectSearchField.svelte +9 -0
- package/dist/criteria-panel/components/InputOptionSelectSearchField.svelte.d.ts +24 -0
- package/dist/criteria-panel/components/NumberRangeField.svelte +11 -0
- package/dist/criteria-panel/components/NumberRangeField.svelte.d.ts +25 -0
- package/dist/criteria-panel/components/NumberSearchField.svelte +9 -0
- package/dist/criteria-panel/components/NumberSearchField.svelte.d.ts +24 -0
- package/dist/criteria-panel/components/OptionMultiSelectSearchField.svelte +9 -0
- package/dist/criteria-panel/components/OptionMultiSelectSearchField.svelte.d.ts +24 -0
- package/dist/criteria-panel/components/OptionSelectSearchField.svelte +9 -0
- package/dist/criteria-panel/components/OptionSelectSearchField.svelte.d.ts +24 -0
- package/dist/criteria-panel/components/SearchField.svelte +14 -0
- package/dist/criteria-panel/components/SearchField.svelte.d.ts +33 -0
- package/dist/criteria-panel/components/TextSearchField.svelte +9 -0
- package/dist/criteria-panel/components/TextSearchField.svelte.d.ts +24 -0
- package/dist/criteria-panel/components/UnknownCriteriaField.svelte +9 -0
- package/dist/criteria-panel/components/UnknownCriteriaField.svelte.d.ts +24 -0
- package/dist/criteria-panel/index.d.ts +6 -0
- package/dist/criteria-panel/index.js +6 -0
- package/dist/criteria-panel/lib/CriteriaComponentBuilder.d.ts +19 -0
- package/dist/criteria-panel/lib/CriteriaComponentBuilder.js +31 -0
- package/dist/criteria-panel/lib/CriteriaFieldBuilder.d.ts +1 -0
- package/dist/criteria-panel/lib/CriteriaFieldBuilder.js +127 -0
- package/dist/criteria-panel/lib/FlexiCriteriaField.d.ts +38 -0
- package/dist/criteria-panel/lib/FlexiCriteriaField.js +31 -0
- package/dist/criteria-panel/lib/FlexiCriteriaSet.d.ts +24 -0
- package/dist/criteria-panel/lib/FlexiCriteriaSet.js +48 -0
- package/dist/flexi-datatable/FlexiDataTable.d.ts +111 -0
- package/dist/flexi-datatable/FlexiDataTable.js +90 -0
- package/dist/flexi-datatable/index.d.ts +2 -0
- package/dist/flexi-datatable/index.js +2 -0
- package/dist/flexi-form/FlexiCompound.d.ts +34 -0
- package/dist/flexi-form/FlexiCompound.js +84 -0
- package/dist/flexi-form/FlexiFormDialog.svelte +24 -0
- package/dist/flexi-form/FlexiFormDialog.svelte.d.ts +21 -0
- package/dist/flexi-form/FlexiFormPage.svelte +26 -0
- package/dist/flexi-form/FlexiFormPage.svelte.d.ts +25 -0
- package/dist/flexi-form/Schema.d.ts +6 -0
- package/dist/flexi-form/Schema.js +1 -0
- package/dist/flexi-form/components/BreakLine.svelte +1 -0
- package/dist/flexi-form/components/BreakLine.svelte.d.ts +26 -0
- package/dist/flexi-form/components/CardTitleBar.svelte +18 -0
- package/dist/flexi-form/components/CardTitleBar.svelte.d.ts +22 -0
- package/dist/flexi-form/components/CascadeOptionSelectField.svelte +13 -0
- package/dist/flexi-form/components/CascadeOptionSelectField.svelte.d.ts +24 -0
- package/dist/flexi-form/components/CellFieldBuilder.d.ts +1 -0
- package/dist/flexi-form/components/CellFieldBuilder.js +178 -0
- package/dist/flexi-form/components/DateField.svelte +12 -0
- package/dist/flexi-form/components/DateField.svelte.d.ts +24 -0
- package/dist/flexi-form/components/DateTimeField.svelte +13 -0
- package/dist/flexi-form/components/DateTimeField.svelte.d.ts +24 -0
- package/dist/flexi-form/components/InputOptionSelectField.svelte +13 -0
- package/dist/flexi-form/components/InputOptionSelectField.svelte.d.ts +24 -0
- package/dist/flexi-form/components/MemoField.svelte +12 -0
- package/dist/flexi-form/components/MemoField.svelte.d.ts +24 -0
- package/dist/flexi-form/components/NumberField.svelte +12 -0
- package/dist/flexi-form/components/NumberField.svelte.d.ts +24 -0
- package/dist/flexi-form/components/OptionsMultiSelectField.svelte +13 -0
- package/dist/flexi-form/components/OptionsMultiSelectField.svelte.d.ts +24 -0
- package/dist/flexi-form/components/OptionsSelectField.svelte +13 -0
- package/dist/flexi-form/components/OptionsSelectField.svelte.d.ts +24 -0
- package/dist/flexi-form/components/TextField.svelte +12 -0
- package/dist/flexi-form/components/TextField.svelte.d.ts +24 -0
- package/dist/flexi-form/components/UnitNumberField.svelte +12 -0
- package/dist/flexi-form/components/UnitNumberField.svelte.d.ts +24 -0
- package/dist/flexi-form/components/UnknownTypeField.svelte +5 -0
- package/dist/flexi-form/components/UnknownTypeField.svelte.d.ts +18 -0
- package/dist/flexi-form/containers/FlexiPanel.svelte +13 -0
- package/dist/flexi-form/containers/FlexiPanel.svelte.d.ts +33 -0
- package/dist/flexi-form/flexi_card/FlexiCard.d.ts +64 -0
- package/dist/flexi-form/flexi_card/FlexiCard.js +66 -0
- package/dist/flexi-form/flexi_card/FlexiCardPanel.svelte +57 -0
- package/dist/flexi-form/flexi_card/FlexiCardPanel.svelte.d.ts +22 -0
- package/dist/flexi-form/flexi_composite/FlexiComposite.d.ts +50 -0
- package/dist/flexi-form/flexi_composite/FlexiComposite.js +26 -0
- package/dist/flexi-form/flexi_composite/FlexiCompositePanel.svelte +42 -0
- package/dist/flexi-form/flexi_composite/FlexiCompositePanel.svelte.d.ts +25 -0
- package/dist/flexi-form/flexi_composite/README.md +50 -0
- package/dist/flexi-form/flexi_datasheet/FlexiDataSheet.d.ts +4 -0
- package/dist/flexi-form/flexi_datasheet/FlexiDataSheet.js +2 -0
- package/dist/flexi-form/flexi_field/FlexiField.d.ts +76 -0
- package/dist/flexi-form/flexi_field/FlexiField.js +128 -0
- package/dist/flexi-form/flexi_field/FlexiFieldCell.svelte +35 -0
- package/dist/flexi-form/flexi_field/FlexiFieldCell.svelte.d.ts +25 -0
- package/dist/flexi-form/flexi_field/UnknownField.d.ts +3 -0
- package/dist/flexi-form/flexi_field/UnknownField.js +3 -0
- package/dist/flexi-form/flexi_form/FlexiForm.d.ts +127 -0
- package/dist/flexi-form/flexi_form/FlexiForm.js +160 -0
- package/dist/flexi-form/flexi_form/FlexiFormPanel.svelte +57 -0
- package/dist/flexi-form/flexi_form/FlexiFormPanel.svelte.d.ts +25 -0
- package/dist/flexi-form/index.d.ts +11 -0
- package/dist/flexi-form/index.js +11 -0
- package/dist/flexi-form/lib/ComponentBuilder.d.ts +15 -0
- package/dist/flexi-form/lib/ComponentBuilder.js +31 -0
- package/dist/flexi-form/lib/index.d.ts +5 -0
- package/dist/flexi-form/lib/index.js +2 -0
- package/dist/flexi-form/lib/types.d.ts +7 -0
- package/dist/flexi-form/lib/types.js +6 -0
- package/dist/flexi-form/lib/utils.d.ts +10 -0
- package/dist/flexi-form/lib/utils.js +48 -0
- package/dist/i18n-res/i18nRes.d.ts +2 -0
- package/dist/i18n-res/i18nRes.js +8 -0
- package/dist/i18n-res/index.d.ts +2 -0
- package/dist/i18n-res/index.js +2 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/uniface-flexi-module.css +46 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +8 -0
- package/package.json +135 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { FlexiCardSchema } from "../flexi_card/FlexiCard";
|
|
2
|
+
import { type FlexiCompositeSchema } from "../flexi_composite/FlexiComposite";
|
|
3
|
+
import type { LayoutMode } from "../lib";
|
|
4
|
+
import FlexiCard from "../flexi_card/FlexiCard";
|
|
5
|
+
import type { ButtonActions } from "@ticatec/uniface-element/ActionBar";
|
|
6
|
+
import type { Arrangement } from "../lib/types";
|
|
7
|
+
export interface FormElements {
|
|
8
|
+
[key: string]: FlexiCardSchema | FlexiCompositeSchema;
|
|
9
|
+
}
|
|
10
|
+
export interface FormBlockSchema {
|
|
11
|
+
id: string;
|
|
12
|
+
style: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 表单动作
|
|
16
|
+
*/
|
|
17
|
+
export interface FormActionSchema {
|
|
18
|
+
/**
|
|
19
|
+
* 按钮文字
|
|
20
|
+
*/
|
|
21
|
+
label: string;
|
|
22
|
+
/**
|
|
23
|
+
* 类型,primary/secondary/...
|
|
24
|
+
*/
|
|
25
|
+
type: 'default' | 'primary' | 'secondary' | 'third' | 'forth';
|
|
26
|
+
/**
|
|
27
|
+
* 是否禁用
|
|
28
|
+
*/
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* 动作触发的类内方法
|
|
32
|
+
*/
|
|
33
|
+
action: string;
|
|
34
|
+
}
|
|
35
|
+
export interface FlexiFormSchema {
|
|
36
|
+
mode?: LayoutMode;
|
|
37
|
+
arrangement?: Arrangement;
|
|
38
|
+
props?: any;
|
|
39
|
+
elements: FormElements;
|
|
40
|
+
label$style?: string;
|
|
41
|
+
variant?: 'filled' | 'outlined' | '';
|
|
42
|
+
actions?: Array<FormActionSchema>;
|
|
43
|
+
style?: string;
|
|
44
|
+
blocks?: Array<FormBlockSchema>;
|
|
45
|
+
}
|
|
46
|
+
export type FormInvalidateHandler = () => void;
|
|
47
|
+
export default abstract class FlexiForm {
|
|
48
|
+
#private;
|
|
49
|
+
readonly mode: LayoutMode;
|
|
50
|
+
readonly props: any;
|
|
51
|
+
readonly arrangement: Arrangement;
|
|
52
|
+
readonly label$style?: string;
|
|
53
|
+
readonly variant: 'filled' | 'outlined' | '';
|
|
54
|
+
protected readonly elements: FormElements;
|
|
55
|
+
readonly style: string;
|
|
56
|
+
protected constructor(data: any, formSchema: FlexiFormSchema);
|
|
57
|
+
/**
|
|
58
|
+
* 构造表单
|
|
59
|
+
*/
|
|
60
|
+
initialize(): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* 构造所有的卡片
|
|
63
|
+
* @protected
|
|
64
|
+
*/
|
|
65
|
+
protected abstract buildCards(): void;
|
|
66
|
+
/**
|
|
67
|
+
* 根据名称获取一个组合块的定义
|
|
68
|
+
* @param name
|
|
69
|
+
*/
|
|
70
|
+
getCompositeSchema(name: string): FlexiCompositeSchema;
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
* @param value
|
|
74
|
+
* @protected
|
|
75
|
+
*/
|
|
76
|
+
protected set cards(value: Array<FlexiCard>);
|
|
77
|
+
/**
|
|
78
|
+
* 获取表单中的卡片
|
|
79
|
+
*/
|
|
80
|
+
get cards(): Array<FlexiCard>;
|
|
81
|
+
/**
|
|
82
|
+
* 获取表单关联数据
|
|
83
|
+
*/
|
|
84
|
+
get data(): any;
|
|
85
|
+
/**
|
|
86
|
+
* 获取表单的Title
|
|
87
|
+
*/
|
|
88
|
+
abstract getTitle(): string;
|
|
89
|
+
/**
|
|
90
|
+
* 设置表单刷新的处理器
|
|
91
|
+
* @param value
|
|
92
|
+
*/
|
|
93
|
+
setInvalidateHandler(value?: FormInvalidateHandler): void;
|
|
94
|
+
/**
|
|
95
|
+
* 刷新表单
|
|
96
|
+
*/
|
|
97
|
+
invalidate(): void;
|
|
98
|
+
/**
|
|
99
|
+
* 返回表单的操作按钮,比如,保存,提交等
|
|
100
|
+
*/
|
|
101
|
+
getActions(): ButtonActions;
|
|
102
|
+
private extractDictionaries;
|
|
103
|
+
/**
|
|
104
|
+
* 从所有的Field中提取数据字典的名称
|
|
105
|
+
* @param dicts
|
|
106
|
+
* @param fields
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
109
|
+
private extractDictFromFields;
|
|
110
|
+
/**
|
|
111
|
+
*
|
|
112
|
+
* @param formActions
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
115
|
+
private parseFormActions;
|
|
116
|
+
validate(): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* 获取指定的数据字典
|
|
119
|
+
* @param key
|
|
120
|
+
*/
|
|
121
|
+
getDictionary(key: string): Array<any>;
|
|
122
|
+
/**
|
|
123
|
+
* 获取表单的动作
|
|
124
|
+
*/
|
|
125
|
+
get actions(): ButtonActions;
|
|
126
|
+
getBlocks(): Array<FormBlockSchema> | undefined;
|
|
127
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {} from "../flexi_composite/FlexiComposite";
|
|
2
|
+
import FlexiCard from "../flexi_card/FlexiCard";
|
|
3
|
+
import FlexiContext from "../..";
|
|
4
|
+
export default class FlexiForm {
|
|
5
|
+
#blocks;
|
|
6
|
+
#cards = [];
|
|
7
|
+
mode = "flex";
|
|
8
|
+
props = {};
|
|
9
|
+
arrangement = "vertical";
|
|
10
|
+
#data;
|
|
11
|
+
label$style = '';
|
|
12
|
+
variant;
|
|
13
|
+
elements;
|
|
14
|
+
#invalidateHandler;
|
|
15
|
+
#actions;
|
|
16
|
+
#dictionaries;
|
|
17
|
+
style;
|
|
18
|
+
constructor(data, formSchema) {
|
|
19
|
+
this.#blocks = formSchema.blocks;
|
|
20
|
+
this.#data = data;
|
|
21
|
+
this.mode = formSchema.mode ?? 'flex';
|
|
22
|
+
this.arrangement = formSchema.arrangement ?? 'vertical';
|
|
23
|
+
this.props = formSchema.props ?? {};
|
|
24
|
+
this.label$style = formSchema.label$style;
|
|
25
|
+
this.variant = formSchema.variant ?? 'filled';
|
|
26
|
+
this.elements = formSchema.elements;
|
|
27
|
+
this.#actions = this.parseFormActions(formSchema.actions);
|
|
28
|
+
this.#dictionaries = {};
|
|
29
|
+
this.style = formSchema.style ?? '';
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 构造表单
|
|
33
|
+
*/
|
|
34
|
+
async initialize() {
|
|
35
|
+
console.log('构造表单');
|
|
36
|
+
let dicts = this.extractDictionaries();
|
|
37
|
+
this.#dictionaries = await FlexiContext.getInstance().loadDictionaries(dicts);
|
|
38
|
+
this.buildCards();
|
|
39
|
+
this.invalidate(); // 通知UI刷新
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 根据名称获取一个组合块的定义
|
|
43
|
+
* @param name
|
|
44
|
+
*/
|
|
45
|
+
getCompositeSchema(name) {
|
|
46
|
+
return this.elements[name];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @param value
|
|
51
|
+
* @protected
|
|
52
|
+
*/
|
|
53
|
+
set cards(value) {
|
|
54
|
+
this.#cards = value;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 获取表单中的卡片
|
|
58
|
+
*/
|
|
59
|
+
get cards() {
|
|
60
|
+
return this.#cards;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 获取表单关联数据
|
|
64
|
+
*/
|
|
65
|
+
get data() {
|
|
66
|
+
return this.#data;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 设置表单刷新的处理器
|
|
70
|
+
* @param value
|
|
71
|
+
*/
|
|
72
|
+
setInvalidateHandler(value) {
|
|
73
|
+
this.#invalidateHandler = value;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 刷新表单
|
|
77
|
+
*/
|
|
78
|
+
invalidate() {
|
|
79
|
+
this.#invalidateHandler?.();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 返回表单的操作按钮,比如,保存,提交等
|
|
83
|
+
*/
|
|
84
|
+
getActions() {
|
|
85
|
+
return this.#actions;
|
|
86
|
+
}
|
|
87
|
+
extractDictionaries() {
|
|
88
|
+
let dicts = [];
|
|
89
|
+
for (let key in this.elements) {
|
|
90
|
+
const element = this.elements[key];
|
|
91
|
+
if (element.type == "block") {
|
|
92
|
+
this.extractDictFromFields(dicts, element.fields);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const card = element;
|
|
96
|
+
this.extractDictFromFields(dicts, card.fields);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return dicts;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 从所有的Field中提取数据字典的名称
|
|
103
|
+
* @param dicts
|
|
104
|
+
* @param fields
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
extractDictFromFields(dicts, fields) {
|
|
108
|
+
for (let field of fields) {
|
|
109
|
+
if (field.type != "composite") {
|
|
110
|
+
let dictName = field.dictName;
|
|
111
|
+
if (dictName) {
|
|
112
|
+
if (!dicts.includes(dictName)) {
|
|
113
|
+
dicts.push(dictName);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
*
|
|
121
|
+
* @param formActions
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
parseFormActions(formActions) {
|
|
125
|
+
let actions = [];
|
|
126
|
+
if (formActions && formActions.length > 0) {
|
|
127
|
+
for (let formAction of formActions) {
|
|
128
|
+
const handler = async (event) => {
|
|
129
|
+
this[formAction.action]?.();
|
|
130
|
+
};
|
|
131
|
+
actions.push({ label: formAction.label, type: formAction.type, handler });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return actions;
|
|
135
|
+
}
|
|
136
|
+
validate() {
|
|
137
|
+
let valid = true;
|
|
138
|
+
for (const card of this.cards) {
|
|
139
|
+
valid = valid && card.validate();
|
|
140
|
+
}
|
|
141
|
+
this.#invalidateHandler?.();
|
|
142
|
+
return valid;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 获取指定的数据字典
|
|
146
|
+
* @param key
|
|
147
|
+
*/
|
|
148
|
+
getDictionary(key) {
|
|
149
|
+
return [...(this.#dictionaries[key] ?? [])];
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 获取表单的动作
|
|
153
|
+
*/
|
|
154
|
+
get actions() {
|
|
155
|
+
return this.#actions;
|
|
156
|
+
}
|
|
157
|
+
getBlocks() {
|
|
158
|
+
return this.#blocks;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script lang="ts">import FlexiForm from "./FlexiForm";
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
import FlexiCardPanel from "../flexi_card/FlexiCardPanel.svelte";
|
|
4
|
+
let className = '';
|
|
5
|
+
export { className as class };
|
|
6
|
+
export let actions;
|
|
7
|
+
export let readonly = false;
|
|
8
|
+
export let form;
|
|
9
|
+
let style = form.style;
|
|
10
|
+
let blocks;
|
|
11
|
+
onMount(async () => {
|
|
12
|
+
form.setInvalidateHandler(() => {
|
|
13
|
+
refreshCards();
|
|
14
|
+
});
|
|
15
|
+
refreshCards();
|
|
16
|
+
});
|
|
17
|
+
// 响应form的变化
|
|
18
|
+
$: if (form) {
|
|
19
|
+
refreshCards();
|
|
20
|
+
}
|
|
21
|
+
const refreshCards = () => {
|
|
22
|
+
blocks = form.getBlocks() ?? [];
|
|
23
|
+
if (blocks && blocks.length > 1) {
|
|
24
|
+
blocks.forEach(block => block.cards = []);
|
|
25
|
+
const map = new Map(blocks.map((item) => [item.id, item]));
|
|
26
|
+
for (let card of form.cards) {
|
|
27
|
+
let block = (card.block ? map.get(card.block) : blocks[0]) ?? blocks[0];
|
|
28
|
+
block.cards = [...block.cards, card];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
blocks = [{ cards: [...(form.cards || [])] }];
|
|
33
|
+
}
|
|
34
|
+
actions = [...(form.getActions() || [])];
|
|
35
|
+
};
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
<div class="uniface-flexi-form {className}" {style}>
|
|
40
|
+
{#if blocks && blocks.length > 1}
|
|
41
|
+
{#each blocks as block}
|
|
42
|
+
<div style={block.style}>
|
|
43
|
+
{#each block.cards as card}
|
|
44
|
+
<FlexiCardPanel {card} {readonly}/>
|
|
45
|
+
{/each}
|
|
46
|
+
</div>
|
|
47
|
+
{/each}
|
|
48
|
+
{:else}
|
|
49
|
+
<!-- 动态表单 -->
|
|
50
|
+
{#if blocks[0].cards && blocks[0].cards.length > 0}
|
|
51
|
+
{#each blocks[0].cards as card}
|
|
52
|
+
<FlexiCardPanel {card} {readonly}/>
|
|
53
|
+
{/each}
|
|
54
|
+
{/if}
|
|
55
|
+
{/if}
|
|
56
|
+
|
|
57
|
+
</div>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import FlexiForm from "./FlexiForm";
|
|
2
|
+
import type { ButtonActions } from "@ticatec/uniface-element/ActionBar";
|
|
3
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
4
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
5
|
+
$$bindings?: Bindings;
|
|
6
|
+
} & Exports;
|
|
7
|
+
(internal: unknown, props: Props & {
|
|
8
|
+
$$events?: Events;
|
|
9
|
+
$$slots?: Slots;
|
|
10
|
+
}): Exports & {
|
|
11
|
+
$set?: any;
|
|
12
|
+
$on?: any;
|
|
13
|
+
};
|
|
14
|
+
z_$$bindings?: Bindings;
|
|
15
|
+
}
|
|
16
|
+
declare const FlexiFormPanel: $$__sveltets_2_IsomorphicComponent<{
|
|
17
|
+
class?: string;
|
|
18
|
+
actions: ButtonActions;
|
|
19
|
+
readonly?: boolean;
|
|
20
|
+
form: FlexiForm;
|
|
21
|
+
}, {
|
|
22
|
+
[evt: string]: CustomEvent<any>;
|
|
23
|
+
}, {}, {}, string>;
|
|
24
|
+
type FlexiFormPanel = InstanceType<typeof FlexiFormPanel>;
|
|
25
|
+
export default FlexiFormPanel;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import FlexiForm from "./flexi_form/FlexiForm";
|
|
2
|
+
import FlexiCard from "./flexi_card/FlexiCard";
|
|
3
|
+
import FlexiField from "./flexi_field/FlexiField";
|
|
4
|
+
import FlexiFormPage from "./FlexiFormPage.svelte";
|
|
5
|
+
import FlexiFormDialog from "./FlexiFormDialog.svelte";
|
|
6
|
+
import ComponentBuilder from "./lib/ComponentBuilder";
|
|
7
|
+
import FlexiFormPanel from "./flexi_form/FlexiFormPanel.svelte";
|
|
8
|
+
import { registerFormFieldBuilder } from "./components/CellFieldBuilder";
|
|
9
|
+
export { FlexiForm, FlexiCard, FlexiField, FlexiFormPage, FlexiFormDialog, FlexiFormPanel };
|
|
10
|
+
export { ComponentBuilder };
|
|
11
|
+
export { registerFormFieldBuilder };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import FlexiForm from "./flexi_form/FlexiForm";
|
|
2
|
+
import FlexiCard from "./flexi_card/FlexiCard";
|
|
3
|
+
import FlexiField from "./flexi_field/FlexiField";
|
|
4
|
+
import FlexiFormPage from "./FlexiFormPage.svelte";
|
|
5
|
+
import FlexiFormDialog from "./FlexiFormDialog.svelte";
|
|
6
|
+
import ComponentBuilder from "./lib/ComponentBuilder";
|
|
7
|
+
import FlexiFormPanel from "./flexi_form/FlexiFormPanel.svelte";
|
|
8
|
+
import { registerFormFieldBuilder } from "./components/CellFieldBuilder";
|
|
9
|
+
export { FlexiForm, FlexiCard, FlexiField, FlexiFormPage, FlexiFormDialog, FlexiFormPanel };
|
|
10
|
+
export { ComponentBuilder };
|
|
11
|
+
export { registerFormFieldBuilder };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type FlexiFieldSchema } from "../flexi_field/FlexiField";
|
|
2
|
+
export type CellField = {
|
|
3
|
+
component: any;
|
|
4
|
+
props: any;
|
|
5
|
+
};
|
|
6
|
+
export type DictionaryLoader = (name: string) => Array<any>;
|
|
7
|
+
export type BuildField = (schema: FlexiFieldSchema, dictLoader: DictionaryLoader) => CellField;
|
|
8
|
+
export default class ComponentBuilder {
|
|
9
|
+
private static instance;
|
|
10
|
+
private map;
|
|
11
|
+
private constructor();
|
|
12
|
+
static getInstance(): ComponentBuilder;
|
|
13
|
+
register(type: string, builder: BuildField): void;
|
|
14
|
+
buildField(schema: FlexiFieldSchema, dictLoader: DictionaryLoader): CellField;
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {} from "../flexi_field/FlexiField";
|
|
2
|
+
import UnknownTypeField from "../components/UnknownTypeField.svelte";
|
|
3
|
+
const unknownField = {
|
|
4
|
+
component: UnknownTypeField,
|
|
5
|
+
props: {}
|
|
6
|
+
};
|
|
7
|
+
export default class ComponentBuilder {
|
|
8
|
+
static instance;
|
|
9
|
+
map;
|
|
10
|
+
constructor() {
|
|
11
|
+
this.map = new Map;
|
|
12
|
+
}
|
|
13
|
+
static getInstance() {
|
|
14
|
+
if (ComponentBuilder.instance == null) {
|
|
15
|
+
ComponentBuilder.instance = new ComponentBuilder();
|
|
16
|
+
}
|
|
17
|
+
return ComponentBuilder.instance;
|
|
18
|
+
}
|
|
19
|
+
register(type, builder) {
|
|
20
|
+
this.map.set(type, builder);
|
|
21
|
+
}
|
|
22
|
+
buildField(schema, dictLoader) {
|
|
23
|
+
let builder = this.map.get(schema.type);
|
|
24
|
+
if (builder != null) {
|
|
25
|
+
return builder(schema, dictLoader);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return unknownField;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
copyAttrs: (src: any, attrs: Array<string>) => any;
|
|
3
|
+
extractExpression: (str: string) => string | null;
|
|
4
|
+
getParentAndKey: (data: any, keyPath: string) => {
|
|
5
|
+
parent: any;
|
|
6
|
+
key: string;
|
|
7
|
+
};
|
|
8
|
+
formatText: (s: string, obj: any) => string;
|
|
9
|
+
};
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const copyAttrs = (src, attrs) => {
|
|
2
|
+
let obj = {};
|
|
3
|
+
for (let attr of attrs) {
|
|
4
|
+
obj[attr] = src?.[attr];
|
|
5
|
+
}
|
|
6
|
+
return obj;
|
|
7
|
+
};
|
|
8
|
+
const extractExpression = (str) => {
|
|
9
|
+
const match = /^\$exp\{([^}]*)\}$/.exec(str);
|
|
10
|
+
return match ? match[1] : null;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 根据点分路径字符串获取目标属性的父对象和键名。
|
|
14
|
+
* 过程中如果发现父级对象为空(null 或 undefined),会自动为其赋值一个空对象 {}。
|
|
15
|
+
* * @param {object} data - 待查找和/或修改的原始对象。
|
|
16
|
+
* @param data
|
|
17
|
+
* @param {string} keyPath - 点分路径字符串,例如 "a.b.c"。
|
|
18
|
+
*/
|
|
19
|
+
const getParentAndKey = (data, keyPath) => {
|
|
20
|
+
if (!keyPath || typeof keyPath !== 'string') {
|
|
21
|
+
throw Error('invalidate key field');
|
|
22
|
+
}
|
|
23
|
+
if (keyPath.includes('.')) {
|
|
24
|
+
const keys = keyPath.split('.');
|
|
25
|
+
const targetKey = keys.pop();
|
|
26
|
+
let current = data ?? {};
|
|
27
|
+
for (const key of keys) {
|
|
28
|
+
if (current[key] == null) {
|
|
29
|
+
current[key] = {};
|
|
30
|
+
}
|
|
31
|
+
current = current[key];
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
parent: current,
|
|
35
|
+
key: targetKey
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return { parent: data, key: keyPath };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const formatText = (s, obj) => {
|
|
43
|
+
return s.replace(/\{\{(.*?)\}\}/g, (_, key) => {
|
|
44
|
+
key = key.trim();
|
|
45
|
+
return obj.hasOwnProperty(key) ? String(obj[key]) : `{{${key}}}`;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
export default { copyAttrs, extractExpression, getParentAndKey, formatText };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--uniface-form-card-gap: 8px;
|
|
3
|
+
--flexi-form-background-color: #ffffff;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.uniface-flexi-form {
|
|
7
|
+
position: relative;
|
|
8
|
+
width: 100%;
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
background-color: var(--flexi-form-background-color);
|
|
12
|
+
row-gap: var(--uniface-form-card-gap);
|
|
13
|
+
}
|
|
14
|
+
.uniface-flexi-form .uniface-flexi-card {
|
|
15
|
+
position: relative;
|
|
16
|
+
}
|
|
17
|
+
.uniface-flexi-form .uniface-flexi-card .uniface-flexi-card-title-bar {
|
|
18
|
+
padding: 12px 12px 8px 12px;
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: row;
|
|
21
|
+
}
|
|
22
|
+
.uniface-flexi-form .uniface-flexi-card .uniface-flexi-card-title-bar .title-text {
|
|
23
|
+
flex: 1 1 auto;
|
|
24
|
+
font-weight: 600;
|
|
25
|
+
font-size: 1.15em;
|
|
26
|
+
}
|
|
27
|
+
.uniface-flexi-form .uniface-flexi-composite-panel {
|
|
28
|
+
position: relative;
|
|
29
|
+
}
|
|
30
|
+
.uniface-flexi-form .uniface-flexi-composite-panel .flexi-composite-title-bar {
|
|
31
|
+
width: 100%;
|
|
32
|
+
position: relative;
|
|
33
|
+
padding: 12px 12px 6px 12px;
|
|
34
|
+
}
|
|
35
|
+
.uniface-flexi-form .uniface-flexi-composite-panel .flexi-composite-title-bar .title-text {
|
|
36
|
+
flex: 1 1 auto;
|
|
37
|
+
font-weight: 600;
|
|
38
|
+
font-size: 1em;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.uniface-flexi-criteria-panel {
|
|
42
|
+
display: flex;
|
|
43
|
+
flex-direction: row;
|
|
44
|
+
flex-wrap: wrap;
|
|
45
|
+
padding: 8px 0;
|
|
46
|
+
}
|
package/dist/utils.d.ts
ADDED