@aplus-frontend/ui
Version:
228 lines (227 loc) • 8.38 kB
TypeScript
import { InputProps, CheckboxGroupProps, DatePickerProps, InputNumberProps, RadioGroupProps, SwitchProps, TextAreaProps, SelectProps, PopconfirmProps, SliderProps, SegmentedProps, RateProps, TreeSelectProps } from '@aplus-frontend/antdv';
import { InputFocusOptions } from '@aplus-frontend/antdv/es/vc-input/utils/commonUtils';
import { ApFormatPresetType } from './date/interface';
import { RangeValue } from '@aplus-frontend/antdv/es/vc-picker/interface';
import { RangePickerProps } from '@aplus-frontend/antdv/es/date-picker/dayjs';
import { LiteralUnion, Recordable } from '../type';
import { InputPasswordProps } from './text/input-password-props';
import { ZoneAlias } from '@aplus-frontend/utils';
import { LegacyDataNode } from '@aplus-frontend/antdv/es/vc-tree-select/interface';
import { SharedTimeProps } from '@aplus-frontend/antdv/es/vc-picker/panels/TimePanel';
import { Dayjs } from 'dayjs';
export type FieldMode = 'read' | 'edit';
export type BasicApFieldProps<FieldPropsType = any> = {
mode?: FieldMode;
class?: unknown;
style?: unknown;
} & FieldPropsType;
export type ApFieldTextProps = BasicApFieldProps<InputProps> & {
emptyText?: string;
/**
* 输入生效前的事件,受控输入拦截
* @param nextVal
* @returns
*/
beforeInput?: (nextVal: string) => string;
};
export type ApFieldTextPasswordProps = BasicApFieldProps<InputPasswordProps> & {
emptyText?: string;
};
export type ApFieldTextPasswordExpose = {
focus: () => void;
blur: () => void;
};
export type ApFieldTextExpose = {
focus: (options?: InputFocusOptions) => void;
blur: () => void;
input: any;
setSelectionRange: (start: number, end: number, direction?: 'forward' | 'backward' | 'none') => void;
select: () => void;
};
export type ApFieldCheckboxProps = BasicApFieldProps<CheckboxGroupProps> & {
emptyText?: string;
request?: () => Promise<CheckboxGroupProps['options']>;
vertical?: boolean;
};
export type ApFieldDateProps = BasicApFieldProps<Omit<DatePickerProps, 'mode' | 'value' | 'defaultValue' | 'onChange' | 'onOk' | 'format' | 'onUpdate:value'>> & {
emptyText?: string;
value?: number | null;
defaultValue?: number;
'onUpdate:value'?: (ts: number | null) => void;
onChange?: (ts: number | null, dayStr: string) => void;
onOk?: (ts: number | null) => void;
format?: LiteralUnion<ApFormatPresetType, string>;
/**
* 只用于显示的自定义格式化
*/
shownFormat?: DatePickerProps['format'];
/**
* 格式化时间时是否以`format`的开始
* @default true
*/
formatBegins?: boolean;
/**
* 指定时区,指定后value会变为特定时区下的timestamp
*/
timezone?: ZoneAlias | {
label?: string;
value: ZoneAlias;
}[];
disabledTime?: SharedTimeProps<Dayjs>['disabledTime'];
};
export type ApFieldNumberProps = BasicApFieldProps<InputNumberProps> & {
emptyText?: string;
/**
* 是否展示千分位,只读模式可用
*/
thousands?: boolean;
/**
* 强制保留指定的小数位,只读模式可用,只有在设置了`precision`才生效
*/
limitDecimalsRetain?: boolean;
};
export type ApiFieldNumberExpose = {
focus: () => void;
blur: () => void;
};
export type ApFieldRadioProps = BasicApFieldProps<RadioGroupProps> & {
emptyText?: string;
request?: () => Promise<RadioGroupProps['options']>;
vertical?: boolean;
};
export type ApiFieldRadioExpose = {
focus: () => void;
blur: () => void;
};
export type ApFieldSwitchConfirmConfig = Pick<PopconfirmProps, 'title' | 'okText' | 'cancelText' | 'description' | 'showCancel' | 'icon' | 'okType' | 'onCancel' | 'okButtonProps' | 'cancelButtonProps'>;
export type ApFieldSwitchProps = BasicApFieldProps<Omit<SwitchProps, 'onClick'>> & {
emptyText?: string;
onAction?: (checked: string | boolean | number, e?: Event) => boolean | Promise<boolean>;
confirm?: ApFieldSwitchConfirmConfig | ((checked: string | number | boolean) => ApFieldSwitchConfirmConfig);
};
export type ApFieldTextAreaProps = BasicApFieldProps<Omit<TextAreaProps, 'autosize'>> & {
emptyText?: string;
/**
* 输入生效前的事件,受控输入拦截
* @param nextVal
* @returns
*/
beforeInput?: (nextVal: string) => string;
};
export type ApFieldTextAreaExpose = {
focus: (options?: InputFocusOptions) => void;
blur: () => void;
resizableTextArea: any;
};
export type ApFieldDateRangeProps = BasicApFieldProps<Omit<RangePickerProps, 'value' | 'onChange' | 'onPanelChange' | 'defaultValue' | 'onOk' | 'renderExtraFooter' | 'onUpdate:value' | 'mode' | 'format' | 'presets'>> & {
emptyText?: string;
value?: RangeValue<number> | null;
defaultValue?: RangeValue<number>;
'onUpdate:value'?: (ts: RangeValue<number> | null) => void;
onChange?: (ts: RangeValue<number> | null, dayStr: [string, string]) => void;
onOk?: (ts: RangeValue<number>) => void;
format?: LiteralUnion<ApFormatPresetType, string>;
/**
* 只用于显示的format
*/
shownFormat?: RangePickerProps['format'];
/**
* 指定时区,指定后value会变为特定时区下的timestamp
*/
timezone?: ZoneAlias | {
label?: string;
value: ZoneAlias;
}[];
/**
* 只读模式下的分隔符(比插槽优先级更高)
*/
readModeSeparator?: any;
presets?: RangePickerProps['presets'] | true;
};
export type ApFieldSelectProps = BasicApFieldProps<Omit<SelectProps, 'mode' | 'value' | 'onUpdate:value' | 'onSearch'>> & {
emptyText?: string;
request?: (value?: string, extraParams?: Recordable) => Promise<SelectProps['options']>;
multiple?: boolean;
value?: SelectProps['value'];
'onUpdate:value'?: SelectProps['onUpdate:value'];
/**
* 如果设置showSearch=true,此时设置searchMode=filter将进行前端筛选,设置searchMode=request将会走后端筛选
*/
searchMode?: 'filter' | 'request';
/**
* 是否在Select框聚焦时再次触发选项请求
*/
refetchOnFocus?: boolean;
/**
* 是否延迟请求选项列表
*/
lazy?: boolean;
/**
* 添加一个名为全部的节点(只在多选的情况下有效)
*/
addAll?: boolean | number;
/**
* 发起request额外的请求,变更后会自动重新发器请求
*/
params?: Recordable;
/**
* 发起搜索的时间间隔默认300ms
*/
searchDelay?: number;
};
export type ApFieldTreeSelectProps = BasicApFieldProps<Omit<TreeSelectProps, 'loadData'>> & {
emptyText?: string;
/**
* 用于请求treeNode
* @param currentNode 异步加载时表示当前节点,非异步请求时为undefined
* @param extraParams 额外的响应式参数
* @returns
*/
request?: (currentNode?: LegacyDataNode, extraParams?: Recordable) => Promise<TreeSelectProps['treeData']>;
/**
* 是否跳过首次加载数据
*/
lazy?: boolean;
/**
* 发起request额外的请求,变更后会自动重新发器请求
*/
params?: Recordable;
/**
* 是否懒加载子树
*/
loadData?: boolean;
};
export type ApFieldSelectExpose = {
focus: () => void;
blur: () => void;
request: (clear?: boolean) => Promise<void>;
};
export type ApFieldTreeSelectExpose = Omit<ApFieldSelectExpose, 'request'> & {
/**
* 手动请求treeData
* @param currentNode 当前树节点(用于请求子树,如果不需要请求子树传入undefined)
* @param clear 请求数据前是否清空treeData
* @returns
*/
request: (currentNode?: LegacyDataNode, clear?: boolean) => Promise<void>;
};
export type ApFieldSliderProps = BasicApFieldProps<SliderProps> & {
emptyText?: string;
defaultValue?: number | [number, number];
};
export type ApFieldSliderExpose = {
focus: () => void;
blur: () => void;
};
export type ApFieldSegmentedProps = BasicApFieldProps<SegmentedProps> & {
emptyText?: string;
defaultValue?: string | number;
request?: () => Promise<SegmentedProps['options']>;
};
export type ApFieldRateProps = BasicApFieldProps<RateProps> & {
defaultValue?: number;
};
export type ApFieldRateExpose = {
focus: () => void;
blur: () => void;
};