@tmagic/form 1.3.7 → 1.3.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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.7",
2
+ "version": "1.3.8",
3
3
  "name": "@tmagic/form",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@element-plus/icons-vue": "^2.3.1",
35
- "@tmagic/design": "1.3.7",
36
- "@tmagic/utils": "1.3.7",
35
+ "@tmagic/design": "1.3.8",
36
+ "@tmagic/utils": "1.3.8",
37
37
  "lodash-es": "^4.17.21",
38
38
  "sortablejs": "^1.14.0",
39
39
  "vue": "^3.3.8"
package/src/Form.vue CHANGED
@@ -79,7 +79,7 @@ const props = withDefaults(
79
79
  },
80
80
  );
81
81
 
82
- const emit = defineEmits(['change', 'field-input', 'field-change']);
82
+ const emit = defineEmits(['change', 'error', 'field-input', 'field-change']);
83
83
 
84
84
  const tMagicForm = ref<InstanceType<typeof TMagicForm>>();
85
85
  const initialized = ref(false);
@@ -182,6 +182,8 @@ defineExpose({
182
182
  await tMagicForm.value?.validate();
183
183
  return native ? values.value : cloneDeep(toRaw(values.value));
184
184
  } catch (invalidFields: any) {
185
+ emit('error', invalidFields);
186
+
185
187
  const error: string[] = [];
186
188
 
187
189
  Object.entries(invalidFields).forEach(([, ValidateError]) => {
@@ -191,6 +193,7 @@ defineExpose({
191
193
  if (!field && message) error.push(`${message}`);
192
194
  });
193
195
  });
196
+
194
197
  throw new Error(error.join('<br>'));
195
198
  }
196
199
  },
@@ -325,6 +325,15 @@ const newHandler = async (row?: any) => {
325
325
  return;
326
326
  }
327
327
 
328
+ if (typeof props.config.beforeAddRow === 'function') {
329
+ const beforeCheckRes = props.config.beforeAddRow(mForm, {
330
+ model: props.model[modelName.value],
331
+ formValue: mForm?.values,
332
+ prop: props.prop,
333
+ });
334
+ if (!beforeCheckRes) return;
335
+ }
336
+
328
337
  const columns = props.config.items;
329
338
  const enumValues = props.config.enum || [];
330
339
  let enumV = [];
package/src/schema.ts CHANGED
@@ -669,6 +669,8 @@ export interface TableConfig extends FormItem {
669
669
  fixed?: boolean;
670
670
  itemExtra?: string | FilterFunction<string>;
671
671
  rowKey?: string;
672
+ /** table 新增行时前置回调 */
673
+ beforeAddRow?: (mForm: FormState | undefined, data: any) => boolean;
672
674
  }
673
675
 
674
676
  export interface GroupListConfig extends FormItem {
@@ -42,6 +42,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
42
42
  submitForm: (native?: boolean | undefined) => Promise<any>;
43
43
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
44
44
  change: (...args: any[]) => void;
45
+ error: (...args: any[]) => void;
45
46
  "field-input": (...args: any[]) => void;
46
47
  "field-change": (...args: any[]) => void;
47
48
  }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
@@ -79,6 +80,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
79
80
  keyProp: string;
80
81
  }>>> & {
81
82
  onChange?: ((...args: any[]) => any) | undefined;
83
+ onError?: ((...args: any[]) => any) | undefined;
82
84
  "onField-input"?: ((...args: any[]) => any) | undefined;
83
85
  "onField-change"?: ((...args: any[]) => any) | undefined;
84
86
  }, {
@@ -48,6 +48,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
48
48
  readonly size?: "large" | "default" | "small" | undefined;
49
49
  readonly extendState?: ((state: import("./schema").FormState) => Record<string, any> | Promise<Record<string, any>>) | undefined;
50
50
  onChange?: ((...args: any[]) => any) | undefined;
51
+ onError?: ((...args: any[]) => any) | undefined;
51
52
  "onField-input"?: ((...args: any[]) => any) | undefined;
52
53
  "onField-change"?: ((...args: any[]) => any) | undefined;
53
54
  } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
@@ -112,6 +113,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
112
113
  };
113
114
  }>> & {
114
115
  onChange?: ((...args: any[]) => any) | undefined;
116
+ onError?: ((...args: any[]) => any) | undefined;
115
117
  "onField-input"?: ((...args: any[]) => any) | undefined;
116
118
  "onField-change"?: ((...args: any[]) => any) | undefined;
117
119
  }, "config" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "labelWidth" | "disabled" | "stepActive" | "height" | "inline" | "labelPosition">;
@@ -126,7 +128,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
126
128
  }>;
127
129
  $root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null;
128
130
  $parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null;
129
- $emit: ((event: "change", ...args: any[]) => void) & ((event: "field-input", ...args: any[]) => void) & ((event: "field-change", ...args: any[]) => void);
131
+ $emit: ((event: "change", ...args: any[]) => void) & ((event: "error", ...args: any[]) => void) & ((event: "field-input", ...args: any[]) => void) & ((event: "field-change", ...args: any[]) => void);
130
132
  $el: any;
131
133
  $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
132
134
  config: {
@@ -190,6 +192,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
190
192
  };
191
193
  }>> & {
192
194
  onChange?: ((...args: any[]) => any) | undefined;
195
+ onError?: ((...args: any[]) => any) | undefined;
193
196
  "onField-input"?: ((...args: any[]) => any) | undefined;
194
197
  "onField-change"?: ((...args: any[]) => any) | undefined;
195
198
  }, {
@@ -202,6 +205,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
202
205
  submitForm: (native?: boolean | undefined) => Promise<any>;
203
206
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
204
207
  change: (...args: any[]) => void;
208
+ error: (...args: any[]) => void;
205
209
  "field-input": (...args: any[]) => void;
206
210
  "field-change": (...args: any[]) => void;
207
211
  }, string, {
@@ -299,6 +303,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
299
303
  };
300
304
  }>> & {
301
305
  onChange?: ((...args: any[]) => any) | undefined;
306
+ onError?: ((...args: any[]) => any) | undefined;
302
307
  "onField-input"?: ((...args: any[]) => any) | undefined;
303
308
  "onField-change"?: ((...args: any[]) => any) | undefined;
304
309
  } & import("vue").ShallowUnwrapRef<{
@@ -316,8 +321,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
316
321
  hide: () => void;
317
322
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
318
323
  change: (...args: any[]) => void;
319
- submit: (...args: any[]) => void;
320
324
  error: (...args: any[]) => void;
325
+ submit: (...args: any[]) => void;
321
326
  }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
322
327
  config?: FormConfig | undefined;
323
328
  values?: Object | undefined;
@@ -51,6 +51,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
51
51
  readonly size?: "large" | "default" | "small" | undefined;
52
52
  readonly extendState?: ((state: import("./schema").FormState) => Record<string, any> | Promise<Record<string, any>>) | undefined;
53
53
  onChange?: ((...args: any[]) => any) | undefined;
54
+ onError?: ((...args: any[]) => any) | undefined;
54
55
  "onField-input"?: ((...args: any[]) => any) | undefined;
55
56
  "onField-change"?: ((...args: any[]) => any) | undefined;
56
57
  } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
@@ -115,6 +116,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
115
116
  };
116
117
  }>> & {
117
118
  onChange?: ((...args: any[]) => any) | undefined;
119
+ onError?: ((...args: any[]) => any) | undefined;
118
120
  "onField-input"?: ((...args: any[]) => any) | undefined;
119
121
  "onField-change"?: ((...args: any[]) => any) | undefined;
120
122
  }, "config" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "labelWidth" | "disabled" | "stepActive" | "height" | "inline" | "labelPosition">;
@@ -129,7 +131,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
129
131
  }>;
130
132
  $root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null;
131
133
  $parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null;
132
- $emit: ((event: "change", ...args: any[]) => void) & ((event: "field-input", ...args: any[]) => void) & ((event: "field-change", ...args: any[]) => void);
134
+ $emit: ((event: "change", ...args: any[]) => void) & ((event: "error", ...args: any[]) => void) & ((event: "field-input", ...args: any[]) => void) & ((event: "field-change", ...args: any[]) => void);
133
135
  $el: any;
134
136
  $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
135
137
  config: {
@@ -193,6 +195,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
193
195
  };
194
196
  }>> & {
195
197
  onChange?: ((...args: any[]) => any) | undefined;
198
+ onError?: ((...args: any[]) => any) | undefined;
196
199
  "onField-input"?: ((...args: any[]) => any) | undefined;
197
200
  "onField-change"?: ((...args: any[]) => any) | undefined;
198
201
  }, {
@@ -205,6 +208,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
205
208
  submitForm: (native?: boolean | undefined) => Promise<any>;
206
209
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
207
210
  change: (...args: any[]) => void;
211
+ error: (...args: any[]) => void;
208
212
  "field-input": (...args: any[]) => void;
209
213
  "field-change": (...args: any[]) => void;
210
214
  }, string, {
@@ -302,6 +306,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
302
306
  };
303
307
  }>> & {
304
308
  onChange?: ((...args: any[]) => any) | undefined;
309
+ onError?: ((...args: any[]) => any) | undefined;
305
310
  "onField-input"?: ((...args: any[]) => any) | undefined;
306
311
  "onField-change"?: ((...args: any[]) => any) | undefined;
307
312
  } & import("vue").ShallowUnwrapRef<{
@@ -321,8 +326,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
321
326
  hide: () => void;
322
327
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
323
328
  change: (...args: any[]) => void;
324
- submit: (...args: any[]) => void;
325
329
  error: (...args: any[]) => void;
330
+ submit: (...args: any[]) => void;
326
331
  close: (...args: any[]) => void;
327
332
  }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
328
333
  config?: FormConfig | undefined;
@@ -54,6 +54,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
54
54
  readonly size?: "large" | "default" | "small" | undefined;
55
55
  readonly extendState?: ((state: import("./schema").FormState) => Record<string, any> | Promise<Record<string, any>>) | undefined;
56
56
  onChange?: ((...args: any[]) => any) | undefined;
57
+ onError?: ((...args: any[]) => any) | undefined;
57
58
  "onField-input"?: ((...args: any[]) => any) | undefined;
58
59
  "onField-change"?: ((...args: any[]) => any) | undefined;
59
60
  } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
@@ -118,6 +119,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
118
119
  };
119
120
  }>> & {
120
121
  onChange?: ((...args: any[]) => any) | undefined;
122
+ onError?: ((...args: any[]) => any) | undefined;
121
123
  "onField-input"?: ((...args: any[]) => any) | undefined;
122
124
  "onField-change"?: ((...args: any[]) => any) | undefined;
123
125
  }, "config" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "labelWidth" | "disabled" | "stepActive" | "height" | "inline" | "labelPosition">;
@@ -132,7 +134,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
132
134
  }>;
133
135
  $root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null;
134
136
  $parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null;
135
- $emit: ((event: "change", ...args: any[]) => void) & ((event: "field-input", ...args: any[]) => void) & ((event: "field-change", ...args: any[]) => void);
137
+ $emit: ((event: "change", ...args: any[]) => void) & ((event: "error", ...args: any[]) => void) & ((event: "field-input", ...args: any[]) => void) & ((event: "field-change", ...args: any[]) => void);
136
138
  $el: any;
137
139
  $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
138
140
  config: {
@@ -196,6 +198,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
196
198
  };
197
199
  }>> & {
198
200
  onChange?: ((...args: any[]) => any) | undefined;
201
+ onError?: ((...args: any[]) => any) | undefined;
199
202
  "onField-input"?: ((...args: any[]) => any) | undefined;
200
203
  "onField-change"?: ((...args: any[]) => any) | undefined;
201
204
  }, {
@@ -208,6 +211,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
208
211
  submitForm: (native?: boolean | undefined) => Promise<any>;
209
212
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
210
213
  change: (...args: any[]) => void;
214
+ error: (...args: any[]) => void;
211
215
  "field-input": (...args: any[]) => void;
212
216
  "field-change": (...args: any[]) => void;
213
217
  }, string, {
@@ -305,6 +309,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
305
309
  };
306
310
  }>> & {
307
311
  onChange?: ((...args: any[]) => any) | undefined;
312
+ onError?: ((...args: any[]) => any) | undefined;
308
313
  "onField-input"?: ((...args: any[]) => any) | undefined;
309
314
  "onField-change"?: ((...args: any[]) => any) | undefined;
310
315
  } & import("vue").ShallowUnwrapRef<{
@@ -323,8 +328,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
323
328
  handleClose: () => void;
324
329
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
325
330
  change: (...args: any[]) => void;
326
- submit: (...args: any[]) => void;
327
331
  error: (...args: any[]) => void;
332
+ submit: (...args: any[]) => void;
328
333
  close: (...args: any[]) => void;
329
334
  closed: (...args: any[]) => void;
330
335
  open: (...args: any[]) => void;
package/types/schema.d.ts CHANGED
@@ -552,6 +552,8 @@ export interface TableConfig extends FormItem {
552
552
  fixed?: boolean;
553
553
  itemExtra?: string | FilterFunction<string>;
554
554
  rowKey?: string;
555
+ /** table 新增行时前置回调 */
556
+ beforeAddRow?: (mForm: FormState | undefined, data: any) => boolean;
555
557
  }
556
558
  export interface GroupListConfig extends FormItem {
557
559
  type: 'table' | 'groupList' | 'group-list';