@tmagic/form 1.7.0-beta.0 → 1.7.0-beta.1
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/tmagic-form.js +37 -7
- package/dist/tmagic-form.umd.cjs +37 -7
- package/package.json +4 -4
- package/src/Form.vue +53 -5
- package/src/fields/Textarea.vue +1 -0
- package/types/index.d.ts +13 -0
package/dist/tmagic-form.js
CHANGED
|
@@ -2806,6 +2806,31 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
|
|
|
2806
2806
|
e.preventDefault();
|
|
2807
2807
|
}
|
|
2808
2808
|
};
|
|
2809
|
+
const getTextByName = (name, config = props.config) => {
|
|
2810
|
+
if (!name || !Array.isArray(config)) return void 0;
|
|
2811
|
+
const nameParts = name.split(".");
|
|
2812
|
+
const findInConfig = (configs, parts) => {
|
|
2813
|
+
if (parts.length === 0) return void 0;
|
|
2814
|
+
const [currentPart, ...remainingParts] = parts;
|
|
2815
|
+
for (const item of configs) {
|
|
2816
|
+
if (item.name === currentPart) {
|
|
2817
|
+
if (remainingParts.length === 0) {
|
|
2818
|
+
return typeof item.text === "string" ? item.text : void 0;
|
|
2819
|
+
}
|
|
2820
|
+
if (item.items && Array.isArray(item.items)) {
|
|
2821
|
+
const result = findInConfig(item.items, remainingParts);
|
|
2822
|
+
if (result !== void 0) return result;
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
if (item.items && Array.isArray(item.items)) {
|
|
2826
|
+
const result = findInConfig(item.items, parts);
|
|
2827
|
+
if (result !== void 0) return result;
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
return void 0;
|
|
2831
|
+
};
|
|
2832
|
+
return findInConfig(config, nameParts);
|
|
2833
|
+
};
|
|
2809
2834
|
__expose({
|
|
2810
2835
|
values,
|
|
2811
2836
|
lastValuesProcessed,
|
|
@@ -2819,22 +2844,26 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
|
|
|
2819
2844
|
},
|
|
2820
2845
|
submitForm: async (native) => {
|
|
2821
2846
|
try {
|
|
2822
|
-
await tMagicFormRef.value?.validate();
|
|
2847
|
+
const result = await tMagicFormRef.value?.validate();
|
|
2848
|
+
if (result !== true) {
|
|
2849
|
+
throw result;
|
|
2850
|
+
}
|
|
2823
2851
|
changeRecords.value = [];
|
|
2824
2852
|
return native ? values.value : cloneDeep(toRaw(values.value));
|
|
2825
2853
|
} catch (invalidFields) {
|
|
2826
2854
|
emit("error", invalidFields);
|
|
2827
2855
|
const error = [];
|
|
2828
|
-
Object.entries(invalidFields).forEach(([, ValidateError]) => {
|
|
2856
|
+
Object.entries(invalidFields).forEach(([prop, ValidateError]) => {
|
|
2829
2857
|
ValidateError.forEach(({ field, message }) => {
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2858
|
+
const name = field || prop;
|
|
2859
|
+
const text = getTextByName(name, props.config) || name;
|
|
2860
|
+
error.push(`${text} -> ${message}`);
|
|
2833
2861
|
});
|
|
2834
2862
|
});
|
|
2835
2863
|
throw new Error(error.join("<br>"));
|
|
2836
2864
|
}
|
|
2837
|
-
}
|
|
2865
|
+
},
|
|
2866
|
+
getTextByName
|
|
2838
2867
|
});
|
|
2839
2868
|
return (_ctx, _cache) => {
|
|
2840
2869
|
return openBlock(), createBlock(unref(TMagicForm), {
|
|
@@ -4250,9 +4279,10 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
|
|
|
4250
4279
|
clearable: "",
|
|
4251
4280
|
placeholder: __props.config.placeholder,
|
|
4252
4281
|
disabled: __props.disabled,
|
|
4282
|
+
rows: __props.config.rows,
|
|
4253
4283
|
"onUpdate:modelValue": changeHandler,
|
|
4254
4284
|
onInput: inputHandler
|
|
4255
|
-
}, null, 8, ["model-value", "size", "placeholder", "disabled"]);
|
|
4285
|
+
}, null, 8, ["model-value", "size", "placeholder", "disabled", "rows"]);
|
|
4256
4286
|
};
|
|
4257
4287
|
}
|
|
4258
4288
|
});
|
package/dist/tmagic-form.umd.cjs
CHANGED
|
@@ -5736,6 +5736,31 @@
|
|
|
5736
5736
|
e.preventDefault();
|
|
5737
5737
|
}
|
|
5738
5738
|
};
|
|
5739
|
+
const getTextByName = (name, config = props.config) => {
|
|
5740
|
+
if (!name || !Array.isArray(config)) return void 0;
|
|
5741
|
+
const nameParts = name.split(".");
|
|
5742
|
+
const findInConfig = (configs, parts) => {
|
|
5743
|
+
if (parts.length === 0) return void 0;
|
|
5744
|
+
const [currentPart, ...remainingParts] = parts;
|
|
5745
|
+
for (const item of configs) {
|
|
5746
|
+
if (item.name === currentPart) {
|
|
5747
|
+
if (remainingParts.length === 0) {
|
|
5748
|
+
return typeof item.text === "string" ? item.text : void 0;
|
|
5749
|
+
}
|
|
5750
|
+
if (item.items && Array.isArray(item.items)) {
|
|
5751
|
+
const result = findInConfig(item.items, remainingParts);
|
|
5752
|
+
if (result !== void 0) return result;
|
|
5753
|
+
}
|
|
5754
|
+
}
|
|
5755
|
+
if (item.items && Array.isArray(item.items)) {
|
|
5756
|
+
const result = findInConfig(item.items, parts);
|
|
5757
|
+
if (result !== void 0) return result;
|
|
5758
|
+
}
|
|
5759
|
+
}
|
|
5760
|
+
return void 0;
|
|
5761
|
+
};
|
|
5762
|
+
return findInConfig(config, nameParts);
|
|
5763
|
+
};
|
|
5739
5764
|
__expose({
|
|
5740
5765
|
values,
|
|
5741
5766
|
lastValuesProcessed,
|
|
@@ -5749,22 +5774,26 @@
|
|
|
5749
5774
|
},
|
|
5750
5775
|
submitForm: async (native) => {
|
|
5751
5776
|
try {
|
|
5752
|
-
await tMagicFormRef.value?.validate();
|
|
5777
|
+
const result = await tMagicFormRef.value?.validate();
|
|
5778
|
+
if (result !== true) {
|
|
5779
|
+
throw result;
|
|
5780
|
+
}
|
|
5753
5781
|
changeRecords.value = [];
|
|
5754
5782
|
return native ? values.value : cloneDeep(vue.toRaw(values.value));
|
|
5755
5783
|
} catch (invalidFields) {
|
|
5756
5784
|
emit("error", invalidFields);
|
|
5757
5785
|
const error = [];
|
|
5758
|
-
Object.entries(invalidFields).forEach(([, ValidateError]) => {
|
|
5786
|
+
Object.entries(invalidFields).forEach(([prop, ValidateError]) => {
|
|
5759
5787
|
ValidateError.forEach(({ field, message }) => {
|
|
5760
|
-
|
|
5761
|
-
|
|
5762
|
-
|
|
5788
|
+
const name = field || prop;
|
|
5789
|
+
const text = getTextByName(name, props.config) || name;
|
|
5790
|
+
error.push(`${text} -> ${message}`);
|
|
5763
5791
|
});
|
|
5764
5792
|
});
|
|
5765
5793
|
throw new Error(error.join("<br>"));
|
|
5766
5794
|
}
|
|
5767
|
-
}
|
|
5795
|
+
},
|
|
5796
|
+
getTextByName
|
|
5768
5797
|
});
|
|
5769
5798
|
return (_ctx, _cache) => {
|
|
5770
5799
|
return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicForm), {
|
|
@@ -7180,9 +7209,10 @@
|
|
|
7180
7209
|
clearable: "",
|
|
7181
7210
|
placeholder: __props.config.placeholder,
|
|
7182
7211
|
disabled: __props.disabled,
|
|
7212
|
+
rows: __props.config.rows,
|
|
7183
7213
|
"onUpdate:modelValue": changeHandler,
|
|
7184
7214
|
onInput: inputHandler
|
|
7185
|
-
}, null, 8, ["model-value", "size", "placeholder", "disabled"]);
|
|
7215
|
+
}, null, 8, ["model-value", "size", "placeholder", "disabled", "rows"]);
|
|
7186
7216
|
};
|
|
7187
7217
|
}
|
|
7188
7218
|
});
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.7.0-beta.
|
|
2
|
+
"version": "1.7.0-beta.1",
|
|
3
3
|
"name": "@tmagic/form",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"vue": "^3.5.22",
|
|
53
53
|
"typescript": "^5.9.3",
|
|
54
|
-
"@tmagic/design": "1.7.0-beta.
|
|
55
|
-
"@tmagic/form-schema": "1.7.0-beta.
|
|
56
|
-
"@tmagic/utils": "1.7.0-beta.
|
|
54
|
+
"@tmagic/design": "1.7.0-beta.1",
|
|
55
|
+
"@tmagic/form-schema": "1.7.0-beta.1",
|
|
56
|
+
"@tmagic/utils": "1.7.0-beta.1"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
59
59
|
"typescript": {
|
package/src/Form.vue
CHANGED
|
@@ -196,6 +196,46 @@ const submitHandler = (e: SubmitEvent) => {
|
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
+
/**
|
|
200
|
+
* 通过 name 从 config 中查找对应的 text
|
|
201
|
+
* @param name - 字段名,支持点分隔的路径格式,如 'a.b.c'
|
|
202
|
+
* @param config - 表单配置数组
|
|
203
|
+
* @returns 找到的 text 值,如果未找到则返回 undefined
|
|
204
|
+
*/
|
|
205
|
+
const getTextByName = (name: string, config: FormConfig = props.config): string | undefined => {
|
|
206
|
+
if (!name || !Array.isArray(config)) return undefined;
|
|
207
|
+
|
|
208
|
+
const nameParts = name.split('.');
|
|
209
|
+
|
|
210
|
+
const findInConfig = (configs: FormConfig, parts: string[]): string | undefined => {
|
|
211
|
+
if (parts.length === 0) return undefined;
|
|
212
|
+
|
|
213
|
+
const [currentPart, ...remainingParts] = parts;
|
|
214
|
+
|
|
215
|
+
for (const item of configs) {
|
|
216
|
+
if (item.name === currentPart) {
|
|
217
|
+
if (remainingParts.length === 0) {
|
|
218
|
+
return typeof item.text === 'string' ? item.text : undefined;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (item.items && Array.isArray(item.items)) {
|
|
222
|
+
const result = findInConfig(item.items, remainingParts);
|
|
223
|
+
if (result !== undefined) return result;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (item.items && Array.isArray(item.items)) {
|
|
228
|
+
const result = findInConfig(item.items, parts);
|
|
229
|
+
if (result !== undefined) return result;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return undefined;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
return findInConfig(config, nameParts);
|
|
237
|
+
};
|
|
238
|
+
|
|
199
239
|
defineExpose({
|
|
200
240
|
values,
|
|
201
241
|
lastValuesProcessed,
|
|
@@ -212,7 +252,12 @@ defineExpose({
|
|
|
212
252
|
|
|
213
253
|
submitForm: async (native?: boolean): Promise<any> => {
|
|
214
254
|
try {
|
|
215
|
-
await tMagicFormRef.value?.validate();
|
|
255
|
+
const result = await tMagicFormRef.value?.validate();
|
|
256
|
+
// tdesign 错误通过返回值返回
|
|
257
|
+
// element-plus 通过throw error
|
|
258
|
+
if (result !== true) {
|
|
259
|
+
throw result;
|
|
260
|
+
}
|
|
216
261
|
changeRecords.value = [];
|
|
217
262
|
return native ? values.value : cloneDeep(toRaw(values.value));
|
|
218
263
|
} catch (invalidFields: any) {
|
|
@@ -220,16 +265,19 @@ defineExpose({
|
|
|
220
265
|
|
|
221
266
|
const error: string[] = [];
|
|
222
267
|
|
|
223
|
-
Object.entries(invalidFields).forEach(([, ValidateError]) => {
|
|
268
|
+
Object.entries(invalidFields).forEach(([prop, ValidateError]) => {
|
|
224
269
|
(ValidateError as ValidateError[]).forEach(({ field, message }) => {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
270
|
+
const name = field || prop;
|
|
271
|
+
const text = getTextByName(name, props.config) || name;
|
|
272
|
+
|
|
273
|
+
error.push(`${text} -> ${message}`);
|
|
228
274
|
});
|
|
229
275
|
});
|
|
230
276
|
|
|
231
277
|
throw new Error(error.join('<br>'));
|
|
232
278
|
}
|
|
233
279
|
},
|
|
280
|
+
|
|
281
|
+
getTextByName,
|
|
234
282
|
});
|
|
235
283
|
</script>
|
package/src/fields/Textarea.vue
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ declare const __VLS_export$v: _vue_runtime_core.DefineComponent<__VLS_Props$u, {
|
|
|
65
65
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
66
66
|
resetForm: () => void;
|
|
67
67
|
submitForm: (native?: boolean) => Promise<any>;
|
|
68
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
68
69
|
}, {}, {}, {}, _vue_runtime_core.ComponentOptionsMixin, _vue_runtime_core.ComponentOptionsMixin, {
|
|
69
70
|
change: (...args: any[]) => void;
|
|
70
71
|
error: (...args: any[]) => void;
|
|
@@ -152,6 +153,7 @@ declare const __VLS_base$4: _vue_runtime_core.DefineComponent<__VLS_Props$t, {
|
|
|
152
153
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
153
154
|
resetForm: () => void;
|
|
154
155
|
submitForm: (native?: boolean) => Promise<any>;
|
|
156
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
155
157
|
}, {}, {}, {}, _vue_runtime_core.ComponentOptionsMixin, _vue_runtime_core.ComponentOptionsMixin, {
|
|
156
158
|
change: (...args: any[]) => void;
|
|
157
159
|
error: (...args: any[]) => void;
|
|
@@ -210,6 +212,7 @@ declare const __VLS_base$4: _vue_runtime_core.DefineComponent<__VLS_Props$t, {
|
|
|
210
212
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
211
213
|
resetForm: () => void;
|
|
212
214
|
submitForm: (native?: boolean) => Promise<any>;
|
|
215
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
213
216
|
}, {}, {}, {}, {
|
|
214
217
|
disabled: boolean;
|
|
215
218
|
labelWidth: string;
|
|
@@ -255,6 +258,7 @@ declare const __VLS_base$4: _vue_runtime_core.DefineComponent<__VLS_Props$t, {
|
|
|
255
258
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
256
259
|
resetForm: () => void;
|
|
257
260
|
submitForm: (native?: boolean) => Promise<any>;
|
|
261
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
258
262
|
}, {}, {}, {}, _vue_runtime_core.ComponentOptionsMixin, _vue_runtime_core.ComponentOptionsMixin, {
|
|
259
263
|
change: (...args: any[]) => void;
|
|
260
264
|
error: (...args: any[]) => void;
|
|
@@ -313,6 +317,7 @@ declare const __VLS_base$4: _vue_runtime_core.DefineComponent<__VLS_Props$t, {
|
|
|
313
317
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
314
318
|
resetForm: () => void;
|
|
315
319
|
submitForm: (native?: boolean) => Promise<any>;
|
|
320
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
316
321
|
}, {}, {}, {}, {
|
|
317
322
|
disabled: boolean;
|
|
318
323
|
labelWidth: string;
|
|
@@ -418,6 +423,7 @@ declare const __VLS_base$3: _vue_runtime_core.DefineComponent<__VLS_Props$s, {
|
|
|
418
423
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
419
424
|
resetForm: () => void;
|
|
420
425
|
submitForm: (native?: boolean) => Promise<any>;
|
|
426
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
421
427
|
}, {}, {}, {}, _vue_runtime_core.ComponentOptionsMixin, _vue_runtime_core.ComponentOptionsMixin, {
|
|
422
428
|
change: (...args: any[]) => void;
|
|
423
429
|
error: (...args: any[]) => void;
|
|
@@ -476,6 +482,7 @@ declare const __VLS_base$3: _vue_runtime_core.DefineComponent<__VLS_Props$s, {
|
|
|
476
482
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
477
483
|
resetForm: () => void;
|
|
478
484
|
submitForm: (native?: boolean) => Promise<any>;
|
|
485
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
479
486
|
}, {}, {}, {}, {
|
|
480
487
|
disabled: boolean;
|
|
481
488
|
labelWidth: string;
|
|
@@ -521,6 +528,7 @@ declare const __VLS_base$3: _vue_runtime_core.DefineComponent<__VLS_Props$s, {
|
|
|
521
528
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
522
529
|
resetForm: () => void;
|
|
523
530
|
submitForm: (native?: boolean) => Promise<any>;
|
|
531
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
524
532
|
}, {}, {}, {}, _vue_runtime_core.ComponentOptionsMixin, _vue_runtime_core.ComponentOptionsMixin, {
|
|
525
533
|
change: (...args: any[]) => void;
|
|
526
534
|
error: (...args: any[]) => void;
|
|
@@ -579,6 +587,7 @@ declare const __VLS_base$3: _vue_runtime_core.DefineComponent<__VLS_Props$s, {
|
|
|
579
587
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
580
588
|
resetForm: () => void;
|
|
581
589
|
submitForm: (native?: boolean) => Promise<any>;
|
|
590
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
582
591
|
}, {}, {}, {}, {
|
|
583
592
|
disabled: boolean;
|
|
584
593
|
labelWidth: string;
|
|
@@ -686,6 +695,7 @@ declare const __VLS_base$2: _vue_runtime_core.DefineComponent<__VLS_Props$r, {
|
|
|
686
695
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
687
696
|
resetForm: () => void;
|
|
688
697
|
submitForm: (native?: boolean) => Promise<any>;
|
|
698
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
689
699
|
}, {}, {}, {}, _vue_runtime_core.ComponentOptionsMixin, _vue_runtime_core.ComponentOptionsMixin, {
|
|
690
700
|
change: (...args: any[]) => void;
|
|
691
701
|
error: (...args: any[]) => void;
|
|
@@ -744,6 +754,7 @@ declare const __VLS_base$2: _vue_runtime_core.DefineComponent<__VLS_Props$r, {
|
|
|
744
754
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
745
755
|
resetForm: () => void;
|
|
746
756
|
submitForm: (native?: boolean) => Promise<any>;
|
|
757
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
747
758
|
}, {}, {}, {}, {
|
|
748
759
|
disabled: boolean;
|
|
749
760
|
labelWidth: string;
|
|
@@ -789,6 +800,7 @@ declare const __VLS_base$2: _vue_runtime_core.DefineComponent<__VLS_Props$r, {
|
|
|
789
800
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
790
801
|
resetForm: () => void;
|
|
791
802
|
submitForm: (native?: boolean) => Promise<any>;
|
|
803
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
792
804
|
}, {}, {}, {}, _vue_runtime_core.ComponentOptionsMixin, _vue_runtime_core.ComponentOptionsMixin, {
|
|
793
805
|
change: (...args: any[]) => void;
|
|
794
806
|
error: (...args: any[]) => void;
|
|
@@ -847,6 +859,7 @@ declare const __VLS_base$2: _vue_runtime_core.DefineComponent<__VLS_Props$r, {
|
|
|
847
859
|
changeHandler: (v: FormValue, eventData: ContainerChangeEventData) => void;
|
|
848
860
|
resetForm: () => void;
|
|
849
861
|
submitForm: (native?: boolean) => Promise<any>;
|
|
862
|
+
getTextByName: (name: string, config?: FormConfig) => string | undefined;
|
|
850
863
|
}, {}, {}, {}, {
|
|
851
864
|
disabled: boolean;
|
|
852
865
|
labelWidth: string;
|