@dazhicheng/ui 1.6.19 → 1.6.20

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.
Files changed (27) hide show
  1. package/dist/components/tt-form/index.d.ts +2 -2
  2. package/dist/components/tt-form/src/formApi.d.ts +11 -2
  3. package/dist/components/tt-form/src/group-form/LazyFormField.vue.js +162 -114
  4. package/dist/components/tt-form/src/group-form/groupFormApi.js +0 -6
  5. package/dist/components/tt-form/src/group-form/lazyContext.d.ts +18 -0
  6. package/dist/components/tt-form/src/group-form/lazyContext.js +64 -36
  7. package/dist/components/tt-form/src/group-form/types.d.ts +39 -6
  8. package/dist/components/tt-form/src/group-form/useGroupForm.d.ts +7 -5
  9. package/dist/components/tt-form/src/types.d.ts +58 -26
  10. package/dist/components/tt-form/src/useForm.d.ts +1 -1
  11. package/dist/components/tt-form/src/useForm.js +5 -5
  12. package/dist/components/tt-modal-form/props.d.ts +9 -4
  13. package/dist/components/tt-modal-form/useModalForm.d.ts +1 -1
  14. package/dist/components/tt-table/index.d.ts +15 -0
  15. package/dist/components/tt-table/src/Table.vue.d.ts +9 -0
  16. package/dist/components/tt-table/src/Table.vue.js +240 -242
  17. package/dist/components/tt-table/src/TableForm.vue.d.ts +7 -5
  18. package/dist/components/tt-table/src/TableForm.vue.js +199 -180
  19. package/dist/components/tt-table/src/hooks/usePagination.d.ts +1 -1
  20. package/dist/components/tt-table/src/hooks/usePagination.js +38 -24
  21. package/dist/components/tt-table/src/hooks/useTableRender.d.ts +4 -4
  22. package/dist/components/tt-table/src/props.d.ts +6 -0
  23. package/dist/components/tt-table/src/props.js +5 -0
  24. package/dist/components/tt-table/src/types/table.d.ts +8 -0
  25. package/dist/components/tt-table/src/types/tableForm.d.ts +29 -14
  26. package/dist/components/tt-table/src/utils/table-form-api.d.ts +11 -11
  27. package/package.json +1 -1
@@ -134,12 +134,19 @@ export interface ArraySchemaContext {
134
134
  export type FormActions = FormContext<GenericObject> & {
135
135
  arrayAction?: FormArrayActions;
136
136
  };
137
+ /**
138
+ * 表单值写入入参。
139
+ *
140
+ * 已声明的字段按 `TValues` 校验类型,同时允许写入嵌套数组路径(如 `list.0.name`)这类
141
+ * 不在 `TValues` 里的键,与 `setValues` 的运行时口径一致。
142
+ */
143
+ export type FormValuesInput<TValues extends Record<string, any> = Record<string, any>> = Partial<TValues> & Record<string, unknown>;
137
144
  /** 表单 schema 回调的公共参数类型 */
138
- export type CustomRenderType<TValues extends Record<string, any> = Record<string, any>> = ((value: TValues, formApi: FormApi) => Component | VNodeChild) | string;
145
+ export type CustomRenderType<TValues extends Record<string, any> = Record<string, any>> = ((value: TValues, formApi: ExtendedFormApi<TValues>) => Component | VNodeChild) | string;
139
146
  export type FormSchemaRuleType = "required" | "selectRequired" | null | (Record<never, never> & string) | ZodTypeAny;
140
- export type FormItemDependenciesCondition<TResult = boolean | PromiseLike<boolean>, TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: FormApi) => TResult;
141
- export type FormItemDependenciesConditionWithRules<TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: FormApi) => FormSchemaRuleType | PromiseLike<FormSchemaRuleType>;
142
- export type FormItemDependenciesConditionWithProps<TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: FormApi) => MaybeComponentProps | PromiseLike<MaybeComponentProps>;
147
+ export type FormItemDependenciesCondition<TResult = boolean | PromiseLike<boolean>, TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: ExtendedFormApi<TValues>) => TResult;
148
+ export type FormItemDependenciesConditionWithRules<TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: ExtendedFormApi<TValues>) => FormSchemaRuleType | PromiseLike<FormSchemaRuleType>;
149
+ export type FormItemDependenciesConditionWithProps<TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: ExtendedFormApi<TValues>) => MaybeComponentProps | PromiseLike<MaybeComponentProps>;
143
150
  export interface FormItemDependencies<TValues extends Record<string, any> = Record<string, any>> {
144
151
  /**
145
152
  * 组件参数
@@ -190,7 +197,7 @@ export interface FormItemDependencies<TValues extends Record<string, any> = Reco
190
197
  * - 允许声明 `triggerFields` 作为依赖触发源
191
198
  */
192
199
  export type ArrayRegisterDependencies<TValues extends Record<string, any> = Record<string, any>> = Pick<FormItemDependencies<TValues>, "if" | "show" | "rules" | "disabled" | "triggerFields">;
193
- export type ComponentProps<TValues extends Record<string, any> = Record<string, any>> = ((value: TValues, formApi: FormApi) => MaybeComponentProps) | MaybeComponentProps;
200
+ export type ComponentProps<TValues extends Record<string, any> = Record<string, any>> = ((value: TValues, formApi: ExtendedFormApi<TValues>) => MaybeComponentProps) | MaybeComponentProps;
194
201
  export interface FormCommonConfig<TValues extends Record<string, any> = Record<string, any>> {
195
202
  /**
196
203
  * 在Label后显示一个冒号
@@ -262,9 +269,9 @@ export interface FormCommonConfig<TValues extends Record<string, any> = Record<s
262
269
  */
263
270
  wrapperClass?: string;
264
271
  }
265
- export type RenderComponentContentType<TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: FormApi) => Record<string, any>;
266
- export type HandleSubmitFn = (values: Record<string, any>) => Promise<void> | void;
267
- export type HandleResetFn = (values: Record<string, any>) => Promise<void> | void;
272
+ export type RenderComponentContentType<TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: ExtendedFormApi<TValues>) => Record<string, any>;
273
+ export type HandleSubmitFn<TValues extends Record<string, any> = Record<string, any>> = (values: TValues) => Promise<void> | void;
274
+ export type HandleResetFn<TValues extends Record<string, any> = Record<string, any>> = (values: TValues) => Promise<void> | void;
268
275
  export type FieldMappingTime = [
269
276
  string,
270
277
  [
@@ -486,15 +493,15 @@ export interface TtFormProps<TValues extends Record<string, any> = Record<string
486
493
  /**
487
494
  * 表单重置回调
488
495
  */
489
- handleReset?: HandleResetFn;
496
+ handleReset?: HandleResetFn<TValues>;
490
497
  /**
491
498
  * 表单提交回调
492
499
  */
493
- handleSubmit?: HandleSubmitFn;
500
+ handleSubmit?: HandleSubmitFn<TValues>;
494
501
  /**
495
502
  * 表单值变化回调
496
503
  */
497
- handleValuesChange?: (values: Record<string, any>, fieldsChanged: string[]) => void;
504
+ handleValuesChange?: (values: TValues, fieldsChanged: string[]) => void;
498
505
  /**
499
506
  * 重置按钮参数
500
507
  */
@@ -524,38 +531,63 @@ export interface TtFormProps<TValues extends Record<string, any> = Record<string
524
531
  */
525
532
  submitOnEnter?: boolean;
526
533
  }
527
- export type ExtendedFormApi = Omit<FormApi, "getValues" | "validate" | "setState"> & {
534
+ /**
535
+ * 表单 api 对外类型。
536
+ *
537
+ * `FormApi` 类本身不带泛型(内部按 `Record<string, any>` 处理),泛型只在这一层对外收窄:
538
+ * 凡是吃/吐表单值与 schema 的方法都按 `TValues` 重新声明,其余方法沿用类的签名。
539
+ * 这样 `useForm<Data>()` 之后再调 `setState({ schema })` / `updateSchema` / `appendFields`,
540
+ * schema 里的 `dependencies` 回调依旧能推断出 `Data`。
541
+ *
542
+ * 这里保持 `Omit<类, ...>` 的写法(与改动前一致):`Omit` 会抹掉类的私有成员,所以本类型
543
+ * 不能反向赋给 `FormApi`,但改动前就是这样,业务受影响面没变;换成与类交叉虽然能反向赋值,
544
+ * 代价是同名方法变成重载对、收窄签名匹配失败时静默退回类的宽松签名,
545
+ * `setValues({ age: "1" })` 这种字段类型写错就查不出来了。
546
+ * 分组表单那侧因为改动前直接暴露的是类本身,必须用交叉,见 `ExtendedGroupFormApi`。
547
+ */
548
+ export type ExtendedFormApi<TValues extends Record<string, any> = Record<string, any>> = Omit<FormApi, "appendFields" | "getState" | "getValues" | "setValues" | "setState" | "updateSchema" | "validate"> & {
528
549
  /**
529
550
  * @description 设置表单状态,支持扩展字段(如 navAnchorProps、groupSchema 等)
530
- * @param {Partial<TtFormProps & Record<string, any>> | ((prev: TtFormProps & Record<string, any>) => Partial<TtFormProps & Record<string, any>>)} stateOrFn - 新状态或更新函数
551
+ * @param stateOrFn - 新状态或更新函数
552
+ */
553
+ setState: (stateOrFn: ((prev: TtFormProps<TValues> & Record<string, any>) => Partial<TtFormProps<TValues> & Record<string, any>>) | Partial<TtFormProps<TValues> & Record<string, any>>) => void;
554
+ /**
555
+ * @description 读取当前表单状态
556
+ */
557
+ getState: () => null | TtFormProps<TValues>;
558
+ /**
559
+ * @description 写入表单值,已声明字段按 `TValues` 校验类型
560
+ */
561
+ setValues: (fields: FormValuesInput<TValues>, filterFields?: boolean, shouldValidate?: boolean) => Promise<void>;
562
+ /**
563
+ * @description 按 fieldName 局部更新 schema
531
564
  */
532
- setState: (stateOrFn: ((prev: TtFormProps & Record<string, any>) => Partial<TtFormProps & Record<string, any>>) | Partial<TtFormProps & Record<string, any>>) => void;
565
+ updateSchema: (schema: Partial<FormSchema<TValues>>[]) => void;
533
566
  /**
534
567
  * 校验表单,支持通过第二个参数控制是否滚动到第一个错误分组
568
+ *
569
+ * 返回类型直接取 `FormApi.validate`,与运行时实际返回保持一致(`errors` 的值可能是 undefined)。
535
570
  * @param {any} [opts] - 原始 validate 选项
536
571
  * @param {boolean} [scrollToError] - 是否滚动到第一个错误分组,不传时使用全局配置 scrollToFirstError
537
572
  */
538
- validate: (opts?: any, scrollToError?: boolean) => Promise<{
539
- valid: boolean;
540
- errors: Record<string, string>;
541
- results?: any;
542
- }>;
573
+ validate: (opts?: any, scrollToError?: boolean) => ReturnType<FormApi["validate"]>;
543
574
  /**
544
575
  * 获取表单值
545
576
  * @param {boolean} [isGroup] - 为 true 时返回按分组 key 嵌套的对象,默认 false 返回扁平值
546
577
  * @returns {Promise<T>} 表单值
547
578
  */
548
- getValues: <T = Record<string, any>>(isGroup?: boolean) => Promise<T>;
549
- useStore: <T = NoInfer<TtFormProps>>(selector?: (state: NoInfer<TtFormProps>) => T) => Readonly<Ref<T>>;
579
+ getValues: <T = TValues>(isGroup?: boolean) => Promise<T>;
580
+ useStore: <T = NoInfer<TtFormProps<TValues>>>(selector?: (state: NoInfer<TtFormProps<TValues>>) => T) => Readonly<Ref<T>>;
550
581
  /** 滚动到指定分组(仅 useGroupForm 场景下可用) */
551
582
  scrollToGroup?: (key: string) => void;
552
583
  /**
553
- * 在指定分组中增量插入字段,无需全量重建 schema
554
- * @param {string} groupKey - 目标分组的 key
555
- * @param {any[]} fields - 要插入的字段或子结构(实际类型为 GroupFormSchema[])
556
- * @param {InsertPosition} [position] - 插入位置:before/after 匹配 fieldName、slot content 或 group key;省略则追加到末尾
584
+ * 增量插入字段,无需全量重建 schema
585
+ *
586
+ * `useGroupForm` 下由 `GroupFormApi` 覆盖,接收的是分组 schema 树节点。
587
+ * @param fields - 要插入的字段或子结构
588
+ * @param position - 插入位置:before/after 匹配 fieldName、slot content 或 group key;省略则追加到末尾
557
589
  */
558
- appendFields?: (groupKey: string, fields: any[], position?: {
590
+ appendFields: (fields: FormSchema<TValues>[], position?: {
559
591
  before?: string;
560
592
  after?: string;
561
593
  }) => void;
@@ -1,2 +1,2 @@
1
1
  import { ExtendedFormApi, TtFormProps } from './types';
2
- export declare function useForm<TValues extends Record<string, any> = Record<string, any>>(options: TtFormProps<TValues>): readonly [import('vue').DefineSetupFnComponent<TtFormProps<TValues>, {}, {}, TtFormProps<TValues> & {}, import('vue').PublicProps>, ExtendedFormApi];
2
+ export declare function useForm<TValues extends Record<string, any> = Record<string, any>>(options: TtFormProps<TValues>): readonly [import('vue').DefineSetupFnComponent<TtFormProps<TValues>, {}, {}, TtFormProps<TValues> & {}, import('vue').PublicProps>, ExtendedFormApi<TValues>];
@@ -4,12 +4,12 @@ import { FormApi as A } from "./formApi.js";
4
4
  import S from "./index.vue2.js";
5
5
  /* empty css */
6
6
  function C(t) {
7
- const n = a(t), e = new A(t), m = e;
8
- m.useStore = (r) => p(e.store, r);
7
+ const n = a(t), e = new A(t), r = e;
8
+ r.useStore = (m) => p(e.store, m);
9
9
  const i = c(
10
- (r, { attrs: o, slots: s }) => (f(() => {
10
+ (m, { attrs: o, slots: s }) => (f(() => {
11
11
  e.unmount();
12
- }), e.setState({ ...r, ...o }), () => u(S, { ...r, ...o, formApi: m }, s)),
12
+ }), e.setState({ ...m, ...o }), () => u(S, { ...m, ...o, formApi: r }, s)),
13
13
  {
14
14
  name: "TtForm",
15
15
  inheritAttrs: !1
@@ -21,7 +21,7 @@ function C(t) {
21
21
  e.setState({ schema: t.schema });
22
22
  },
23
23
  { immediate: !0 }
24
- ), [i, m];
24
+ ), [i, r];
25
25
  }
26
26
  export {
27
27
  C as useForm
@@ -1,9 +1,14 @@
1
- import { GroupFormApi, TtExtendedFormApi, TtFormProps, UseGroupFormOptions } from '../tt-form';
1
+ import { ExtendedGroupFormApi, TtExtendedFormApi, TtFormProps, UseGroupFormOptions } from '../tt-form';
2
2
  import { ModalApiOptions, TtModalExtendedModalApi } from '../tt-modal';
3
3
  /** modal-form 使用的表单类型。 */
4
4
  export type ModalFormType = "form" | "groupForm";
5
- /** modal-form 对外暴露的表单 API 类型。 */
6
- export type ModalFormApi<TType extends ModalFormType = "form"> = TType extends "groupForm" ? GroupFormApi : TtExtendedFormApi;
5
+ /**
6
+ * modal-form 对外暴露的表单 API 类型。
7
+ *
8
+ * `TValues` 跟着 `formProps` 走,`getFormApi` 拿到的 api 上 `getValues` / `setState({ schema })`
9
+ * 等方法也按业务的值类型收窄。
10
+ */
11
+ export type ModalFormApi<TType extends ModalFormType = "form", TValues extends Record<string, any> = Record<string, any>> = TType extends "groupForm" ? ExtendedGroupFormApi<TValues> : TtExtendedFormApi<TValues>;
7
12
  /** 根据表单类型收窄的表单配置。 */
8
13
  type ModalFormProps<TValues extends Record<string, any>, TType extends ModalFormType> = TType extends "groupForm" ? Partial<UseGroupFormOptions<TValues>> : Partial<TtFormProps<TValues>>;
9
14
  export type TtModalFormProps<TType extends ModalFormType = "form", TValues extends Record<string, any> = Record<string, any>> = {
@@ -40,7 +45,7 @@ export type TtModalFormProps<TType extends ModalFormType = "form", TValues exten
40
45
  /** modal props */
41
46
  modalProps?: ModalApiOptions;
42
47
  /** 获取formApi的回调 */
43
- getFormApi?: (api: ModalFormApi<TType>) => void;
48
+ getFormApi?: (api: ModalFormApi<TType, TValues>) => void;
44
49
  /** 获取modalApi的回调 */
45
50
  getModalApi?: (api: TtModalExtendedModalApi) => void;
46
51
  /** 处理TtSelect(非多选回显值) */
@@ -2,6 +2,6 @@ import { TtModalExtendedModalApi } from '../tt-modal';
2
2
  import { ModalFormApi, ModalFormType, TtModalFormProps } from './props';
3
3
  /** 创建普通表单或分组表单的弹窗表单。 */
4
4
  export declare function useModalForm<TType extends ModalFormType = "form", TValues extends Record<string, any> = Record<string, any>>(options: TtModalFormProps<TType, TValues>): readonly [import('vue').DefineSetupFnComponent<Partial<TtModalFormProps<ModalFormType>>, {}, {}, Partial<TtModalFormProps<ModalFormType>> & {}, import('vue').PublicProps>, {
5
- readonly formApi: import('vue').Ref<ModalFormApi<TType> | undefined, ModalFormApi<TType> | undefined>;
5
+ readonly formApi: import('vue').Ref<ModalFormApi<TType, TValues> | undefined, ModalFormApi<TType, TValues> | undefined>;
6
6
  readonly modalApi: import('vue').Ref<TtModalExtendedModalApi | undefined, TtModalExtendedModalApi | undefined>;
7
7
  }];
@@ -207,6 +207,10 @@ export declare const TtTable: import('../../../../utils/src').SFCWithInstall<{
207
207
  type: import('vue').PropType<import('.').TtTableProps["beforeFetch"]>;
208
208
  default: null;
209
209
  };
210
+ beforePageChange: {
211
+ type: import('vue').PropType<import('.').TtTableProps["beforePageChange"]>;
212
+ default: null;
213
+ };
210
214
  data: {
211
215
  type: import('vue').PropType<import('.').TtTableProps["data"]>;
212
216
  default: () => import('.').TtTableProps["data"];
@@ -523,6 +527,7 @@ export declare const TtTable: import('../../../../utils/src').SFCWithInstall<{
523
527
  api: (...arg: any[]) => Promise<any>;
524
528
  afterFetch: ((data: any[], res: Recordable | Recordable[]) => Promise<any[]>) | undefined;
525
529
  beforeFetch: ((params: Recordable) => Promise<Recordable>) | undefined;
530
+ beforePageChange: ((page: import("vxe-table").VxeGridPropTypes.PagerConfig) => boolean | Promise<boolean>) | undefined;
526
531
  }, true, {}, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, {
527
532
  wrapRef: HTMLDivElement;
528
533
  xGrid: (import('vxe-table').VxeGridMethods<any> & {
@@ -894,6 +899,10 @@ export declare const TtTable: import('../../../../utils/src').SFCWithInstall<{
894
899
  type: import('vue').PropType<import('.').TtTableProps["beforeFetch"]>;
895
900
  default: null;
896
901
  };
902
+ beforePageChange: {
903
+ type: import('vue').PropType<import('.').TtTableProps["beforePageChange"]>;
904
+ default: null;
905
+ };
897
906
  data: {
898
907
  type: import('vue').PropType<import('.').TtTableProps["data"]>;
899
908
  default: () => import('.').TtTableProps["data"];
@@ -1208,6 +1217,7 @@ export declare const TtTable: import('../../../../utils/src').SFCWithInstall<{
1208
1217
  api: (...arg: any[]) => Promise<any>;
1209
1218
  afterFetch: ((data: any[], res: Recordable | Recordable[]) => Promise<any[]>) | undefined;
1210
1219
  beforeFetch: ((params: Recordable) => Promise<Recordable>) | undefined;
1220
+ beforePageChange: ((page: import("vxe-table").VxeGridPropTypes.PagerConfig) => boolean | Promise<boolean>) | undefined;
1211
1221
  }>;
1212
1222
  __isFragment?: never;
1213
1223
  __isTeleport?: never;
@@ -1312,6 +1322,10 @@ export declare const TtTable: import('../../../../utils/src').SFCWithInstall<{
1312
1322
  type: import('vue').PropType<import('.').TtTableProps["beforeFetch"]>;
1313
1323
  default: null;
1314
1324
  };
1325
+ beforePageChange: {
1326
+ type: import('vue').PropType<import('.').TtTableProps["beforePageChange"]>;
1327
+ default: null;
1328
+ };
1315
1329
  data: {
1316
1330
  type: import('vue').PropType<import('.').TtTableProps["data"]>;
1317
1331
  default: () => import('.').TtTableProps["data"];
@@ -1628,6 +1642,7 @@ export declare const TtTable: import('../../../../utils/src').SFCWithInstall<{
1628
1642
  api: (...arg: any[]) => Promise<any>;
1629
1643
  afterFetch: ((data: any[], res: Recordable | Recordable[]) => Promise<any[]>) | undefined;
1630
1644
  beforeFetch: ((params: Recordable) => Promise<Recordable>) | undefined;
1645
+ beforePageChange: ((page: import("vxe-table").VxeGridPropTypes.PagerConfig) => boolean | Promise<boolean>) | undefined;
1631
1646
  }, {}, string, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, import('vue').ComponentProvideOptions> & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & (new () => {
1632
1647
  $slots: Readonly<{
1633
1648
  [key: string]: (props: import('../../../../utils/src').Recordable) => void;
@@ -393,6 +393,10 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
393
393
  type: import('vue').PropType<TtTableProps["beforeFetch"]>;
394
394
  default: null;
395
395
  };
396
+ beforePageChange: {
397
+ type: import('vue').PropType<TtTableProps["beforePageChange"]>;
398
+ default: null;
399
+ };
396
400
  data: {
397
401
  type: import('vue').PropType<TtTableProps["data"]>;
398
402
  default: () => TtTableProps["data"];
@@ -744,6 +748,10 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
744
748
  type: import('vue').PropType<TtTableProps["beforeFetch"]>;
745
749
  default: null;
746
750
  };
751
+ beforePageChange: {
752
+ type: import('vue').PropType<TtTableProps["beforePageChange"]>;
753
+ default: null;
754
+ };
747
755
  data: {
748
756
  type: import('vue').PropType<TtTableProps["data"]>;
749
757
  default: () => TtTableProps["data"];
@@ -967,6 +975,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
967
975
  api: (...arg: any[]) => Promise<any>;
968
976
  afterFetch: ((data: any[], res: globalThis.Recordable | globalThis.Recordable[]) => Promise<any[]>) | undefined;
969
977
  beforeFetch: ((params: globalThis.Recordable) => Promise<globalThis.Recordable>) | undefined;
978
+ beforePageChange: ((page: import("vxe-table").VxeGridPropTypes.PagerConfig) => boolean | Promise<boolean>) | undefined;
970
979
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {
971
980
  wrapRef: HTMLDivElement;
972
981
  xGrid: (import('vxe-table').VxeGridMethods<any> & {