feat: 支持设置显示附件数量 (#753)

Co-authored-by: sealday <sealday@gmail.com>
Reviewed-on: daoyoucloud/tachycode#753
Co-authored-by: bai.zixv <bai.zixv@foxmail.com>
Co-committed-by: bai.zixv <bai.zixv@foxmail.com>
This commit is contained in:
bai.zixv 2024-04-18 00:03:32 +08:00 committed by sealday
parent 2dd8e25616
commit 8da9c47a7e
6 changed files with 53 additions and 4 deletions

View File

@ -45,5 +45,47 @@ export const uploadAttachmentComponentFieldSettings = new SchemaSettings({
}; };
}, },
}, },
{
name: 'showCount',
type: 'modal',
useComponentProps() {
const field: any = useField();
const { t } = useTranslation();
const showCountSchema = useFieldSchema();
const { dn } = useDesignable();
return {
title: t('Show Count'),
schema: {
type: 'object',
title: t('Show Count'),
properties: {
showCount: {
default: showCountSchema?.['x-component-props']?.['showCount'] || 1,
'x-decorator': 'FormItem',
'x-component': 'InputNumber',
'x-component-props': {
min: 0,
max: 5,
},
},
},
},
onSubmit: ({ showCount }) => {
const props = showCountSchema['x-component-props'] || {};
props.showCount = showCount;
field.componentProps.showCount = showCount;
const schema = {
['x-uid']: showCountSchema['x-uid'],
['x-component-props']: props,
};
dn.emit('patch', {
schema,
});
dn.refresh();
},
};
},
},
], ],
}); });

View File

@ -22,15 +22,16 @@ type Composed = React.FC<UploadProps> & {
export const ReadPretty: Composed = () => null; export const ReadPretty: Composed = () => null;
ReadPretty.File = function File(props: UploadProps) { ReadPretty.File = function File(props: UploadProps) {
const { size, showCount = 0 } = props;
const { t } = useTranslation(); const { t } = useTranslation();
const record = useRecord(); const record = useRecord();
const field = useField<Field>(); const field = useField<Field>();
const value = isString(field.value) ? record : field.value; const value = isString(field.value) ? record : field.value;
const images = toImages(toArr(value));
const images = toImages(showCount === 0 ? toArr(value) : toArr(value).slice(0, showCount));
const [fileIndex, setFileIndex] = useState(0); const [fileIndex, setFileIndex] = useState(0);
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [fileType, setFileType] = useState<'image' | 'pdf'>(); const [fileType, setFileType] = useState<'image' | 'pdf'>();
const { size } = props;
const { wrapSSR, hashId, componentCls: prefixCls } = useStyles(); const { wrapSSR, hashId, componentCls: prefixCls } = useStyles();
const useUploadStyleVal = (useUploadStyle as any).default ? (useUploadStyle as any).default : useUploadStyle; const useUploadStyleVal = (useUploadStyle as any).default ? (useUploadStyle as any).default : useUploadStyle;
// 加载 antd 的样式 // 加载 antd 的样式

View File

@ -7,6 +7,7 @@ export type UploadProps = Omit<AntdUploadProps, 'onChange'> & {
serviceErrorMessage?: string; serviceErrorMessage?: string;
value?: any; value?: any;
size?: string; size?: string;
showCount?: number;
}; };
export type DraggerProps = Omit<AntdDraggerProps, 'onChange'> & { export type DraggerProps = Omit<AntdDraggerProps, 'onChange'> & {

View File

@ -10,5 +10,6 @@
"Configure field": "Configure field", "Configure field": "Configure field",
"Configure fields": "Configure fields", "Configure fields": "Configure fields",
"Configure columns": "Configure columns", "Configure columns": "Configure columns",
"Add block": "Add block" "Add block": "Add block",
"all": "all"
} }

View File

@ -10,5 +10,6 @@
"Configure field": "配置字段", "Configure field": "配置字段",
"Configure fields": "配置字段", "Configure fields": "配置字段",
"Configure columns": "配置字段", "Configure columns": "配置字段",
"Add block": "创建区块" "Add block": "创建区块",
"all": "全部"
} }

View File

@ -25,6 +25,9 @@ export class AttachmentFieldInterface extends CollectionFieldInterface {
if (['Table', 'Kanban'].includes(block)) { if (['Table', 'Kanban'].includes(block)) {
schema['x-component-props'] = schema['x-component-props'] || {}; schema['x-component-props'] = schema['x-component-props'] || {};
schema['x-component-props']['size'] = 'small'; schema['x-component-props']['size'] = 'small';
// TODO: 此处修改是个临时方案, 找不到具体上下文丢失的原因. 仿照之前size的处理办法.
// 影响: table的附件设置,在根源schema处的设置值无法传递下去. 只能在这里手动赋值.
schema['x-component-props']['showCount'] = 1;
} }
if (!schema['x-component-props']) { if (!schema['x-component-props']) {