UNPKG

@aplus-frontend/ui

Version:

62 lines (61 loc) 2.57 kB
import { DescriptionsProps } from '@aplus-frontend/antdv'; import { CSSProperties, StyleValue, VNode, VNodeChild } from 'vue'; import { formatterMap } from './formatter'; /** 字段路径 */ export type FieldPath = string | string[]; type FormatterMapType = typeof formatterMap; export type FormatterValueType = keyof typeof formatterMap; /** 提取某个对象类型的某个key和key的类型 */ type MixObjectPropertyType<O, key extends keyof O> = key extends keyof O ? { valueType: key; extraProps?: O[key] extends (a: infer _, b: infer B) => unknown ? B : O[key]; } : never; export type TransformOptionType = MixObjectPropertyType<FormatterMapType, FormatterValueType>; type Recordable = Record<string, any>; type AllKeys<T, P extends string = '', Level extends unknown[] = []> = Level['length'] extends 5 ? never : T extends object ? { [K in keyof T]: `${P}${K extends string ? K : never}` | (T[K] extends object ? AllKeys<T[K], `${P}${K extends string ? K : never}.`, [ ...Level, unknown ]> : never); }[keyof T] : never; /** 基本描述类型 */ export interface ItemSchema<T extends Recordable = Recordable> { label: VNodeChild | VNode; field: Extract<AllKeys<T>, string> | (string & {}) | string[]; span?: number; prefix?: VNodeChild | VNode; suffix?: VNodeChild | VNode; contentStyle?: CSSProperties; labelStyle?: CSSProperties; customRender?: (record?: T) => VNodeChild | VNode; contentSlotName?: string; helpMessage?: any; visible?: boolean | ((config: { record: T; schema: DescriptionsItemSchema; }) => boolean); isShowEmptyPlaceholder?: boolean; format?: (text: string, record: T) => string | number; } /** 空的类型描述类型 */ export type EmptyItemSchema = { valueType: 'empty'; } & Partial<ItemSchema>; /** 混合处理函数类型的描述类型 */ export type MixSchemaAndOptionType<T extends Recordable = Recordable, Y extends TransformOptionType = TransformOptionType> = TransformOptionType extends TransformOptionType ? ItemSchema<T> & Y : ItemSchema<T>; /** 所有的描述类型 */ export type DescriptionsItemSchema<T extends Recordable = any> = MixSchemaAndOptionType<T> | EmptyItemSchema; /** descriptions的props类型 */ export interface DisplayInfoProps { descriptionsProps?: DescriptionsProps; schemas?: DescriptionsItemSchema[]; dataSource?: Recordable; style?: StyleValue; className?: string; } /** 传给转换函数 */ export interface FormatOptions { value: any; record: any; } export {};