@dazhicheng/ui 1.5.96 → 1.5.98

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.
@@ -7,4 +7,4 @@ export { default as FormMessage } from './FormMessage.vue';
7
7
  export { default as FormWarnMessage } from './FormWarnMessage.vue';
8
8
  export { default as RenderContent } from './RenderContent.vue';
9
9
  export { FORM_ITEM_INJECTION_KEY } from './injectionKeys';
10
- export { Form, Field as FormField, FieldArray as FormFieldArray } from 'vee-validate';
10
+ export { Form, Field as FormField, FieldArray as FormFieldArray, useFieldArray } from 'vee-validate';
@@ -0,0 +1,53 @@
1
+ import { PropType } from 'vue';
2
+ import { FormSchema } from '../types';
3
+ declare const FormArrayRegister: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
4
+ fieldName: {
5
+ type: PropType<string>;
6
+ required: true;
7
+ };
8
+ arraySchema: {
9
+ type: PropType<FormSchema[]>;
10
+ default: () => FormSchema[];
11
+ };
12
+ formItemClass: {
13
+ type: PropType<NonNullable<FormSchema["formItemClass"]>>;
14
+ default: undefined;
15
+ };
16
+ rules: {
17
+ type: PropType<FormSchema["rules"]>;
18
+ default: undefined;
19
+ };
20
+ virtual: {
21
+ type: BooleanConstructor;
22
+ default: boolean;
23
+ };
24
+ }>, () => (import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
25
+ [key: string]: any;
26
+ }>[] | undefined)[], {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
27
+ fieldName: {
28
+ type: PropType<string>;
29
+ required: true;
30
+ };
31
+ arraySchema: {
32
+ type: PropType<FormSchema[]>;
33
+ default: () => FormSchema[];
34
+ };
35
+ formItemClass: {
36
+ type: PropType<NonNullable<FormSchema["formItemClass"]>>;
37
+ default: undefined;
38
+ };
39
+ rules: {
40
+ type: PropType<FormSchema["rules"]>;
41
+ default: undefined;
42
+ };
43
+ virtual: {
44
+ type: BooleanConstructor;
45
+ default: boolean;
46
+ };
47
+ }>> & Readonly<{}>, {
48
+ rules: import('../types').FormSchemaRuleType | undefined;
49
+ arraySchema: FormSchema<keyof import('../types').BaseFormComponentMap>[];
50
+ formItemClass: NonNullable<string | (() => string) | undefined>;
51
+ virtual: boolean;
52
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
53
+ export { FormArrayRegister };
@@ -1,73 +1,57 @@
1
1
  import { PropType, VNode } from 'vue';
2
2
  import { FormSchema } from '../types';
3
- /**
4
- * @description 根据 virtual 标志选择 LazyFormField 或 FormField 渲染单个字段,
5
- * 消除模板中重复的条件分支
6
- * @property {Record<string, unknown>} fieldConfig - mergeFieldConfig 合并后的完整字段配置
7
- * @property {FormSchema["rules"]} [rules] - 字段校验规则
8
- * @property {boolean} [virtual] - 是否启用虚拟化(LazyFormField)
9
- * @property {Element | null} [scrollElement] - 虚拟化滚动容器
10
- * @property {string} [rootMargin] - IntersectionObserver rootMargin
11
- * @property {number} [estimateFieldHeight] - 预估占位高度
12
- */
13
3
  export declare const FieldRenderer: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
14
- /** mergeFieldConfig 合并后的完整字段配置 */
15
4
  fieldConfig: {
16
- type: PropType<Record<string, unknown>>;
5
+ type: PropType<FormSchema & {
6
+ commonComponentProps: Record<string, any>;
7
+ formFieldProps: Record<string, any>;
8
+ }>;
17
9
  required: true;
18
10
  };
19
- /** 字段校验规则 */
20
11
  rules: {
21
12
  type: PropType<FormSchema["rules"]>;
22
13
  default: undefined;
23
14
  };
24
- /** 是否启用虚拟化 */
25
15
  virtual: {
26
16
  type: BooleanConstructor;
27
17
  default: boolean;
28
18
  };
29
- /** 虚拟化滚动容器 */
30
19
  scrollElement: {
31
20
  type: PropType<Element | null>;
32
21
  default: null;
33
22
  };
34
- /** IntersectionObserver rootMargin */
35
23
  rootMargin: {
36
24
  type: StringConstructor;
37
25
  default: string;
38
26
  };
39
- /** 预估占位高度(px) */
40
27
  estimateFieldHeight: {
41
28
  type: NumberConstructor;
42
29
  default: number;
43
30
  };
44
31
  }>, () => VNode, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
45
- /** mergeFieldConfig 合并后的完整字段配置 */
46
32
  fieldConfig: {
47
- type: PropType<Record<string, unknown>>;
33
+ type: PropType<FormSchema & {
34
+ commonComponentProps: Record<string, any>;
35
+ formFieldProps: Record<string, any>;
36
+ }>;
48
37
  required: true;
49
38
  };
50
- /** 字段校验规则 */
51
39
  rules: {
52
40
  type: PropType<FormSchema["rules"]>;
53
41
  default: undefined;
54
42
  };
55
- /** 是否启用虚拟化 */
56
43
  virtual: {
57
44
  type: BooleanConstructor;
58
45
  default: boolean;
59
46
  };
60
- /** 虚拟化滚动容器 */
61
47
  scrollElement: {
62
48
  type: PropType<Element | null>;
63
49
  default: null;
64
50
  };
65
- /** IntersectionObserver rootMargin */
66
51
  rootMargin: {
67
52
  type: StringConstructor;
68
53
  default: string;
69
54
  };
70
- /** 预估占位高度(px) */
71
55
  estimateFieldHeight: {
72
56
  type: NumberConstructor;
73
57
  default: number;
@@ -1,23 +1,9 @@
1
- import { FormCommonConfig, FormRenderProps, FormShape } from '../types';
1
+ import { FormCommonConfig, FormRenderProps } from '../types';
2
2
  type Props = FormRenderProps;
3
3
  type __VLS_Props = Props & {
4
4
  globalCommonConfig?: FormCommonConfig;
5
5
  };
6
- declare function __VLS_template(): {
7
- attrs: Partial<{}>;
8
- slots: Partial<Record<string, (_: {
9
- values: Record<string, any>;
10
- formActions: import('../types').FormActions;
11
- }) => any>> & Partial<Record<string, (_: any) => any>> & {
12
- default?(_: {
13
- shapes: FormShape[];
14
- }): any;
15
- };
16
- refs: {
17
- wrapperRef: HTMLDivElement;
18
- };
19
- rootEl: any;
20
- };
6
+ declare function __VLS_template(): any;
21
7
  type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
22
8
  declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
23
9
  submit: (event: any) => any;
@@ -29,9 +15,7 @@ declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}
29
15
  showCollapseButton: boolean;
30
16
  wrapperClass: import('../types').WrapperClassType;
31
17
  globalCommonConfig: FormCommonConfig;
32
- }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
33
- wrapperRef: HTMLDivElement;
34
- }, any>;
18
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, any, any>;
35
19
  declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
36
20
  export default _default;
37
21
  type __VLS_WithTemplateSlots<T, S> = T & {
@@ -2,6 +2,7 @@ import { FormState, GenericObject, ResetFormOpts, ValidationOptions } from 'vee-
2
2
  import { ComponentPublicInstance } from 'vue';
3
3
  import { Recordable, StateHandler } from '../../../../../utils/src';
4
4
  import { FormActions, FormSchema, TtFormProps } from './types';
5
+ import { FieldArrayContext } from './types/forms';
5
6
  import { Store } from './shared/store';
6
7
  export declare class FormApi {
7
8
  form: FormActions;
@@ -9,10 +10,15 @@ export declare class FormApi {
9
10
  state: null | TtFormProps;
10
11
  stateHandler: StateHandler;
11
12
  store: Store<TtFormProps>;
13
+ private readonly _arrayFields;
12
14
  /**
13
15
  * 组件实例映射
14
16
  */
15
17
  private componentRefMap;
18
+ /**
19
+ * @description 数组字段操作集合
20
+ */
21
+ private readonly _arrayAction;
16
22
  private latestSubmissionValues;
17
23
  private prevState;
18
24
  constructor(options?: TtFormProps);
@@ -130,4 +136,76 @@ export declare class FormApi {
130
136
  * 避免 `removeFields` / 删项后 `getValues` 仍带出旧字段。
131
137
  */
132
138
  private updateState;
139
+ /**
140
+ * @description 注册数组方法
141
+ * @param name 需要注册的数组字段
142
+ * @param actions 操作方法
143
+ */
144
+ registerArrayField(name: string, actions: FieldArrayContext): void;
145
+ unregisterArrayField(name: string): void;
146
+ /** @description 数组字段操作集合 */
147
+ get arrayAction(): {
148
+ /**
149
+ * @description 获取指定数组字段的操作上下文
150
+ * @param name 数组字段名(例如 `fieldName的值 数组下才生效`)
151
+ * @returns 只读
152
+ */
153
+ get: <TValue = unknown>(name: string) => Readonly<FieldArrayContext<TValue>> | undefined;
154
+ /**
155
+ * @description 在数组末尾新增一项
156
+ * @param name 数组字段名(例如 `fieldName的值 数组下才生效`)
157
+ * @param value 要追加的数组项值
158
+ */
159
+ push: <TValue = unknown>(name: string, value: TValue) => void | undefined;
160
+ /**
161
+ * @description 删除指定索引的项
162
+ * @param name 数组字段名(例如 `fieldName的值 数组下才生效`)
163
+ * @param idx 要删除的索引位置
164
+ */
165
+ remove: (name: string, idx: number) => void | undefined;
166
+ /**
167
+ * @description 整体替换数组值
168
+ * @template TValue 数组项类型
169
+ * @param name 数组字段名(例如 `fieldName的值 数组下才生效`)
170
+ * @param values 新的完整数组字段
171
+ */
172
+ replace: <TValue = unknown>(name: string, values: TValue[]) => void | undefined;
173
+ /**
174
+ * @description更新指定索引的项
175
+ * @param name 数组字段名(例如 `fieldName的值 数组下才生效`)
176
+ * @param idx 要更新的索引位置
177
+ * @param value 更新后的数组项值
178
+ */
179
+ update: <TValue = unknown>(name: string, idx: number, value: TValue) => void | undefined;
180
+ /**
181
+ * @description 在指定索引插入一项
182
+ * @template TValue 数组项类型
183
+ * @param name 数组字段名(例如 `fieldName的值 数组下才生效`)
184
+ * @param idx 插入位置索引
185
+ * @param value 要插入的数组项值
186
+ */
187
+ insert: <TValue = unknown>(name: string, idx: number, value: TValue) => void | undefined;
188
+ /**
189
+ * @description 在数组头部新增一项
190
+ * @template TValue 数组项类型
191
+ * @param name 数组字段名(例如 `fieldName的值 数组下才生效`)
192
+ * @param value 要插入到头部的数组项值
193
+ */
194
+ prepend: <TValue = unknown>(name: string, value: TValue) => void | undefined;
195
+ /**
196
+ * @description 将项从旧索引移动到新索引
197
+ * @param name 数组字段名(例如 `fieldName的值 数组下才生效`)
198
+ * @param oldIdx 原索引位置
199
+ * @param newIdx 新索引位置
200
+ */
201
+ move: (name: string, oldIdx: number, newIdx: number) => void | undefined;
202
+ /**
203
+ * @description 交换两个索引位置的项
204
+ * @param name 数组字段名(例如 `fieldName的值 数组下才生效`)
205
+ * @param indexA 第一个索引位置
206
+ * @param indexB 第二个索引位置
207
+ */
208
+ swap: (name: string, indexA: number, indexB: number) => void | undefined;
209
+ };
210
+ private _getArrayFieldActions;
133
211
  }
@@ -9,11 +9,11 @@ declare const __VLS_component: import('vue').DefineComponent<GroupSectionProps,
9
9
  commonConfig: import('../types').FormCommonConfig;
10
10
  compact: boolean;
11
11
  layout: string;
12
- globalCommonConfig: import('../types').FormCommonConfig;
13
12
  virtual: boolean;
14
13
  rootMargin: string;
15
14
  estimateFieldHeight: number;
16
15
  scrollElement: Element | null;
16
+ globalCommonConfig: import('../types').FormCommonConfig;
17
17
  depth: number;
18
18
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
19
19
  declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
@@ -1,7 +1,9 @@
1
1
  import { LazyFormFieldProps } from './types';
2
2
  declare function __VLS_template(): {
3
3
  attrs: Partial<{}>;
4
- slots: Partial<Record<{}, (_: any) => any>>;
4
+ slots: {
5
+ default?(_: any): any;
6
+ };
5
7
  refs: {
6
8
  containerRef: HTMLDivElement;
7
9
  };
@@ -144,6 +144,13 @@ export declare class GroupFormApi extends FormApi {
144
144
  * @returns {boolean} 是否属于隐藏分组
145
145
  */
146
146
  private _isFieldInHiddenGroup;
147
+ /**
148
+ * @description 判断错误键是否命中字段(支持数组/对象嵌套键)
149
+ * @param {string} errorKey - 错误键(如 a[0].b)
150
+ * @param {string} field - schema 字段(如 a)
151
+ * @returns {boolean}
152
+ */
153
+ private _matchFieldOrNested;
147
154
  /**
148
155
  * @description 按当前 store 中的 groupSchema(若无则用初始 schema)重置折叠状态:
149
156
  * 先清空已有 key,再按 `defaultCollapsed` 写入默认值。
@@ -263,5 +270,16 @@ export declare class GroupFormApi extends FormApi {
263
270
  /**
264
271
  * @description 卸载分组表单时恢复初始schema
265
272
  */
273
+ get arrayAction(): {
274
+ get: <TValue = unknown>(name: string) => Readonly<import('../types').FieldArrayContext<TValue>> | undefined;
275
+ push: <TValue = unknown>(name: string, value: TValue) => void;
276
+ remove: (name: string, idx: number) => void;
277
+ replace: <TValue = unknown>(name: string, values: TValue[]) => void;
278
+ update: <TValue = unknown>(name: string, idx: number, value: TValue) => void;
279
+ insert: <TValue = unknown>(name: string, idx: number, value: TValue) => void;
280
+ prepend: <TValue = unknown>(name: string, value: TValue) => void;
281
+ move: (name: string, oldIdx: number, newIdx: number) => void;
282
+ swap: (name: string, indexA: number, indexB: number) => void;
283
+ };
266
284
  unmount(): void;
267
285
  }
@@ -41,7 +41,7 @@ export interface FormRowSchema {
41
41
  /** 是否显示,支持布尔值或函数 (values, actions) => boolean | Promise<boolean>,默认 true */
42
42
  ifShow?: IfShowConditionType;
43
43
  }
44
- export type GroupFormSchema = FormGroupSchema | FormRowSchema | FormSlotSchema | FormSchema;
44
+ export type GroupFormSchema = FormSchema | FormGroupSchema | FormRowSchema | FormSlotSchema;
45
45
  /**
46
46
  * 导航锚点基础配置:排除由内部维护的 `items` 与 `modelValue`,增加 `show` 控制是否渲染。
47
47
  * @property {boolean} [show] - 是否显示悬浮导航,默认 true
@@ -85,7 +85,9 @@ export type GroupFormState = TtFormProps & GroupFormExtraState;
85
85
  /** LazyFormField 组件 props */
86
86
  export interface LazyFormFieldProps {
87
87
  /** 传给 FormField 的完整 props(通过 v-bind 透传) */
88
- fieldProps: Record<string, unknown>;
88
+ fieldProps: FormSchema & {
89
+ commonComponentProps: Record<string, any>;
90
+ };
89
91
  /** FormSchema.rules */
90
92
  rules?: FormSchema["rules"];
91
93
  /** FormSchema.formItemClass(用于外层 class) */
@@ -0,0 +1,2 @@
1
+ import { FieldArrayContext } from '../types/forms';
2
+ export declare function useArrayRegistry(name: string): readonly [(actions?: FieldArrayContext) => void, () => void];
@@ -5,9 +5,7 @@ interface Props extends TtFormProps {
5
5
  declare function __VLS_template(): {
6
6
  attrs: Partial<{}>;
7
7
  slots: Partial<Record<string, (_: any) => any>> & {
8
- default?(_: {
9
- shapes: import('./types').FormShape[];
10
- }): any;
8
+ default?(_: any): any;
11
9
  'reset-before'?(_: {}): any;
12
10
  'submit-before'?(_: {}): any;
13
11
  'expand-before'?(_: {}): any;
@@ -93,7 +93,7 @@ export type FieldEntry<TValue = unknown> = {
93
93
  isLast: boolean;
94
94
  };
95
95
  export type FieldArrayContext<TValue = unknown> = {
96
- fields: Ref<FieldEntry<TValue>[]>;
96
+ fields: FieldEntry<TValue>[];
97
97
  remove: (idx: number) => void;
98
98
  replace: (newArray: TValue[]) => void;
99
99
  update: (idx: number, value: TValue) => void;
@@ -6,6 +6,7 @@ import { TtTextProps } from '../../tt-text';
6
6
  import { TtSelectProp } from '../../tt-select';
7
7
  import { TtUploadProps } from '../../tt-upload';
8
8
  import { Props as TtApiComponentProps } from '../../tt-api-component';
9
+ import { FieldEntry, FieldArrayContext } from './types/forms';
9
10
  import { FormApi } from './formApi';
10
11
  export type FormLayout = "horizontal" | "inline" | "vertical";
11
12
  export interface BaseFormComponentMap {
@@ -57,7 +58,20 @@ export type MaybeComponentPropKey = "options" | "placeholder" | "title" | keyof
57
58
  export type MaybeComponentProps = {
58
59
  [K in MaybeComponentPropKey]?: any;
59
60
  };
60
- export type FormActions = FormContext<GenericObject>;
61
+ export interface FormArrayActions {
62
+ get: <TValue = unknown>(name: string) => Readonly<FieldArrayContext<TValue>> | undefined;
63
+ push: <TValue = unknown>(name: string, value: TValue) => void;
64
+ remove: (name: string, idx: number) => void;
65
+ replace: <TValue = unknown>(name: string, values: TValue[]) => void;
66
+ update: <TValue = unknown>(name: string, idx: number, value: TValue) => void;
67
+ insert: <TValue = unknown>(name: string, idx: number, value: TValue) => void;
68
+ prepend: <TValue = unknown>(name: string, value: TValue) => void;
69
+ move: (name: string, oldIdx: number, newIdx: number) => void;
70
+ swap: (name: string, indexA: number, indexB: number) => void;
71
+ }
72
+ export type FormActions = FormContext<GenericObject> & {
73
+ arrayAction?: FormArrayActions;
74
+ };
61
75
  export type CustomRenderType = ((value: Partial<Record<string, any>>, actions: FormActions) => Component | string) | string;
62
76
  export type FormSchemaRuleType = "required" | "selectRequired" | null | (Record<never, never> & string) | ZodTypeAny;
63
77
  type FormItemDependenciesCondition<T = boolean | PromiseLike<boolean>> = (value: Partial<Record<string, any>>, actions: FormActions) => T;
@@ -220,6 +234,15 @@ export interface FormSchema<T extends BaseFormComponentType = BaseFormComponentT
220
234
  toolTip?: TtTextProps;
221
235
  /** 非label文字气泡设置 */
222
236
  toolTipText?: CustomRenderType;
237
+ /** 是否使用动态新增 */
238
+ useArraySchema?: true;
239
+ /**
240
+ * 动态新增表单项配置
241
+ * @description 支持直接传入配置数组 或 动态函数生成
242
+ * @example arraySchema: []
243
+ * @example arraySchema: (entry, index) => []
244
+ */
245
+ arraySchema?: FormSchema[] | ((entry: FieldEntry, currentIndex: number) => FormSchema[]);
223
246
  }
224
247
  /** 插槽 scope 参数,传递给渲染函数或具名插槽 */
225
248
  export interface FormSlotScope {
@@ -228,6 +251,15 @@ export interface FormSlotScope {
228
251
  /** 表单操作方法(validate / resetForm / getValues 等) */
229
252
  formActions: FormActions;
230
253
  }
254
+ /**
255
+ * Extra slot props exposed for `useArraySchema: true` fields.
256
+ */
257
+ export interface FormArraySlotScope extends FormSlotScope {
258
+ arrayEntry?: unknown;
259
+ arrayAction?: unknown;
260
+ arrayIndex?: number;
261
+ fieldName?: string;
262
+ }
231
263
  /**
232
264
  * 自定义插槽 schema,在表单字段之间插入任意自定义内容。
233
265
  * content 为字符串时作为具名插槽名,在模板中用 `<template #slotName="{ values, formActions }">` 编写;