diff --git a/src/components/custom/table-search-fields.vue b/src/components/custom/table-search-fields.vue index 5e98fdf..44b798d 100644 --- a/src/components/custom/table-search-fields.vue +++ b/src/components/custom/table-search-fields.vue @@ -22,6 +22,10 @@ export interface SearchField { dateType?: 'date' | 'month'; /** dateRange 字段的日期范围粒度 */ dateRangeType?: 'daterange' | 'monthrange'; + /** 日期面板展示格式 */ + format?: string; + /** 自定义范围分隔文案 */ + rangeSeparator?: string; /** 日期字段提交格式 */ valueFormat?: string; /** 占位列数,默认 1 */ @@ -36,6 +40,10 @@ export interface SearchField { placeholder?: string; /** select 类型的自定义选项渲染函数 */ renderOption?: (option: Option) => VNode | VNode[] | string; + /** 值写回模型前的转换函数 */ + transformValue?: (value: any) => any; + /** 从模型值解析展示值 */ + resolveValue?: (value: any) => any; } interface Props { @@ -60,6 +68,7 @@ const props = withDefaults(defineProps(), { }); interface Emits { + (e: 'update:modelValue', value: Record): void; (e: 'search'): void; (e: 'reset'): void; } @@ -122,6 +131,19 @@ function handleReset() { function handleSearch() { emit('search'); } + +function updateFieldValue(field: SearchField, value: any) { + const nextValue = field.transformValue ? field.transformValue(value) : value; + emit('update:modelValue', { + ...props.modelValue, + [field.key]: nextValue + }); +} + +function getFieldValue(field: SearchField) { + const value = props.modelValue[field.key]; + return field.resolveValue ? field.resolveValue(value) : value; +} @@ -139,19 +161,19 @@ function handleSearch() {