@dazhicheng/ui 1.5.99 → 1.5.101

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.
@@ -0,0 +1,4 @@
1
+ /** 此处后端没有提供注释 POST /dataTypeContext/queryDataPermissionDetail */
2
+ export declare function queryDataPermissionDetailDataTypeContext(params: IamAPI.UserDataPermissionQueryParam, options?: {
3
+ [key: string]: any;
4
+ }): Promise<IamAPI.DataPermissionDetailDTO[]>;
@@ -4,6 +4,7 @@ import { ComputedRef, MaybeRef, MaybeRefOrGetter, Ref } from 'vue';
4
4
  import { FlattenAndSetPathsType, GenericObject, MapValuesPathsToRefs, MaybeArray, MaybePromise } from './common';
5
5
  import { Path, PathValue } from './paths';
6
6
  import { FieldValidationMetaInfo } from './shared';
7
+ import { Recordable } from '../../../../../../utils/src';
7
8
  export type ValidationResult<TValue = unknown> = {
8
9
  errors: string[];
9
10
  valid: boolean;
@@ -86,13 +87,13 @@ export type PathState<TInput = unknown, TOutput = TInput> = {
86
87
  };
87
88
  validate?: FieldValidator<TOutput>;
88
89
  };
89
- export type FieldEntry<TValue = unknown> = {
90
+ export type FieldEntry<TValue = Recordable> = {
90
91
  value: TValue;
91
92
  key: string | number;
92
93
  isFirst: boolean;
93
94
  isLast: boolean;
94
95
  };
95
- export type FieldArrayContext<TValue = unknown> = {
96
+ export type FieldArrayContext<TValue = Recordable> = {
96
97
  fields: FieldEntry<TValue>[];
97
98
  remove: (idx: number) => void;
98
99
  replace: (newArray: TValue[]) => void;
@@ -58,6 +58,7 @@ export type MaybeComponentPropKey = "options" | "placeholder" | "title" | keyof
58
58
  export type MaybeComponentProps = {
59
59
  [K in MaybeComponentPropKey]?: any;
60
60
  };
61
+ /** 数组操作方法 */
61
62
  export interface FormArrayActions {
62
63
  get: <TValue = unknown>(name: string) => Readonly<FieldArrayContext<TValue>> | undefined;
63
64
  push: <TValue = unknown>(name: string, value: TValue) => void;
@@ -0,0 +1,152 @@
1
+ import { TtFormSchema } from '../components/tt-form';
2
+ import { Recordable } from '../../../utils/src';
3
+ import { MaybeRef, Ref } from 'vue';
4
+ /**
5
+ * 数据权限接口支持的联动数据类型。
6
+ *
7
+ * - platformId:平台
8
+ * - shopId:店铺,默认会跟随平台值联动过滤
9
+ * - purchasePlaceId:采购地
10
+ * - businessType:业务线
11
+ * - lockUserId:锁单人
12
+ */
13
+ export type DataType = "platformId" | "shopId" | "purchasePlaceId" | "businessType" | "lockUserId";
14
+ /**
15
+ * 表单使用场景。
16
+ *
17
+ * list 用于查询筛选场景;action 用于新增、编辑等操作场景。
18
+ * action 场景下,当平台选择“全部”或选择多个平台时,店铺字段会被禁用并改为非必填。
19
+ */
20
+ export type FormScene = "list" | "action";
21
+ type FieldComponentProps = Recordable | ((values: Recordable, actions: any, options: SelectOption[]) => Recordable);
22
+ type FieldSchemaConfig = Partial<TtFormSchema> | ((schema: TtFormSchema, dataType: DataType) => TtFormSchema);
23
+ /**
24
+ * 字段 onChange 回调上下文。
25
+ *
26
+ * 业务侧通过 field(dataType, { onChange }) 追加字段变更逻辑时,
27
+ * 可以从这里拿到当前表单值、表单操作对象、字段名、原始选项和当前选中项。
28
+ */
29
+ export interface FieldOnChangeContext {
30
+ /** 当前表单值对象 */
31
+ values: Recordable;
32
+ /** 表单渲染器透出的操作对象 */
33
+ actions: any;
34
+ /** 当前字段最终绑定的字段名,已合并 fieldName 自定义配置 */
35
+ fieldName: string;
36
+ /** 当前触发变更的数据类型 */
37
+ dataType: DataType;
38
+ /** 当前字段可选项 */
39
+ options: SelectOption[];
40
+ /** 当前选中项。多选时为数组,单选时为单个选项。 */
41
+ currentOption: SelectOption[] | SelectOption | undefined;
42
+ }
43
+ /**
44
+ * 单个联动字段的覆盖配置。
45
+ *
46
+ * 该配置通过 builder.field(dataType, config) 传入,用于覆盖默认字段名、标签、
47
+ * 组件 props、校验规则、依赖关系和追加 onChange 行为。
48
+ */
49
+ export interface UseFormSchemasLinkFieldConfig {
50
+ /** 业务中实际需要绑定的字段名称 */
51
+ fieldName?: string;
52
+ /** 业务中实际需要绑定的label名称 */
53
+ label?: string;
54
+ /** 是否多选 默认多选 */
55
+ multiple?: boolean;
56
+ /** 多选时是否折叠 tag,默认 true */
57
+ collapseTags?: boolean;
58
+ /** 透传给 ElSelectV2 的 props;传函数时会在渲染时接收表单值、操作对象和当前选项 */
59
+ componentProps?: FieldComponentProps;
60
+ /** 追加或覆盖 TtFormSchema.dependencies */
61
+ dependencies?: TtFormSchema["dependencies"];
62
+ /** 字段值变化后的追加回调。默认联动逻辑会先执行,再执行该回调。 */
63
+ onChange?: (values: unknown, context: FieldOnChangeContext) => void;
64
+ /** 字段校验规则 */
65
+ rules?: TtFormSchema["rules"];
66
+ /** 是否在当前字段选项前追加“全部”,默认 true */
67
+ showAll?: boolean;
68
+ }
69
+ /**
70
+ * useFormSchemasLink 的批量配置。
71
+ *
72
+ * 可以通过 fromOptions(options) 一次性传入,也可以使用 builder 链式方法逐项配置。
73
+ */
74
+ export interface UseFormSchemasLinkOptions {
75
+ /** 表单场景,默认 list */
76
+ scene?: FormScene;
77
+ /** 外部数据源。未传时会按 codes 调用 queryDataPermissionDetailDataTypeContext。 */
78
+ dataSource?: MaybeRef<IamAPI.DataPermissionDetailDTO[] | undefined>;
79
+ /** 字段级配置,key 为 DataType */
80
+ fieldConfigs?: Partial<Record<DataType, UseFormSchemasLinkFieldConfig>>;
81
+ /** Schema 级覆盖。传函数时可基于默认 schema 做增量修改。 */
82
+ schemas?: Partial<Record<DataType, FieldSchemaConfig>>;
83
+ }
84
+ /**
85
+ * ElSelectV2 消费的统一选项结构。
86
+ */
87
+ export type SelectOption = Recordable & {
88
+ /** 展示文案 */
89
+ label: string;
90
+ /** 选项值 */
91
+ value: string | number;
92
+ /** 店铺所属平台 id,用于平台和店铺联动过滤 */
93
+ platformId?: string | number;
94
+ };
95
+ /**
96
+ * 构建后的表单 schema 集合。
97
+ *
98
+ * 返回值会包含每个 DataType 对应的 TtFormSchema,以及当前已归一化的下拉数据源。
99
+ */
100
+ type UseFormSchemasLinkResult = Record<DataType, TtFormSchema> & {
101
+ dataSource: Ref<Record<DataType, SelectOption[]>>;
102
+ };
103
+ type FormSchemasLinkBuilder = {
104
+ /** 设置为查询筛选场景 */
105
+ list(): FormSchemasLinkBuilder;
106
+ /** 设置为新增、编辑等操作场景 */
107
+ action(): FormSchemasLinkBuilder;
108
+ /** 设置表单场景 */
109
+ scene(scene: FormScene): FormSchemasLinkBuilder;
110
+ /** 指定需要请求和构建的字段类型,默认包含全部 DataType */
111
+ codes(codes: DataType[]): FormSchemasLinkBuilder;
112
+ /** 使用外部数据源,跳过内部接口请求 */
113
+ dataSource(dataSource: MaybeRef<IamAPI.DataPermissionDetailDTO[] | undefined>): FormSchemasLinkBuilder;
114
+ /** 覆盖单个字段配置 */
115
+ field(dataType: DataType, config: UseFormSchemasLinkFieldConfig): FormSchemasLinkBuilder;
116
+ /** 覆盖单个字段的完整 schema 或基于默认 schema 做增量修改 */
117
+ schema(dataType: DataType, schema: FieldSchemaConfig): FormSchemasLinkBuilder;
118
+ /** 批量合并配置 */
119
+ fromOptions(options: UseFormSchemasLinkOptions): FormSchemasLinkBuilder;
120
+ /** 生成最终 schema 和数据源 */
121
+ build(): UseFormSchemasLinkResult;
122
+ };
123
+ /**
124
+ * 构建数据权限相关的表单联动 schema。
125
+ *
126
+ * 调用 build() 后会生成平台、店铺、采购地、
127
+ * 业务线、锁单人的默认 TtFormSchema,并自动处理以下逻辑:
128
+ * - 未传 dataSource 时按 codes 请求数据权限下拉数据
129
+ * - 以 route.meta.permissionOnlyCode 和 route.path 为 key 缓存数据源
130
+ * - 平台变更时清空店铺值,并按平台过滤店铺选项
131
+ * - 多选字段支持“全部”互斥选择逻辑
132
+ * - action 场景下平台为“全部”或多平台时禁用店铺并取消必填
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * const { platformId, shopId, businessType } = useFormSchemasLink()
137
+ * .list()
138
+ * .codes(["platformId", "shopId", "businessType"])
139
+ * .field("platformId", {
140
+ * fieldName: "platformIds",
141
+ * label: "平台",
142
+ * onChange(value, context) {
143
+ * console.log(value, context.currentOption);
144
+ * },
145
+ * })
146
+ * .build();
147
+ *
148
+ * const schemas = [platformId, shopId, businessType];
149
+ * ```
150
+ */
151
+ export declare function useFormSchemasLink(): FormSchemasLinkBuilder;
152
+ export {};
package/dist/index.d.ts CHANGED
@@ -21,6 +21,7 @@ export * from './components/tt-upload';
21
21
  export * from './components/tt-nav-anchor';
22
22
  export * from './components/tt-api-component';
23
23
  export * from './components/tt-log';
24
+ export { useFormSchemasLink } from './hooks/useFormSchemasLink';
24
25
  export { useFormat } from './hooks/useFormat';
25
26
  export { useLoading } from './hooks/useLoading';
26
27
  export { setXHR };