diff --git a/packages/core/client/src/modules/fields/component/FileManager/uploadAttachmentComponentFieldSettings.tsx b/packages/core/client/src/modules/fields/component/FileManager/uploadAttachmentComponentFieldSettings.tsx index ec4b239e3..a92a907a6 100644 --- a/packages/core/client/src/modules/fields/component/FileManager/uploadAttachmentComponentFieldSettings.tsx +++ b/packages/core/client/src/modules/fields/component/FileManager/uploadAttachmentComponentFieldSettings.tsx @@ -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(); + }, + }; + }, + }, ], }); diff --git a/packages/core/client/src/schema-component/antd/upload/ReadPretty.tsx b/packages/core/client/src/schema-component/antd/upload/ReadPretty.tsx index 678540e18..8cbf568a8 100644 --- a/packages/core/client/src/schema-component/antd/upload/ReadPretty.tsx +++ b/packages/core/client/src/schema-component/antd/upload/ReadPretty.tsx @@ -22,15 +22,16 @@ type Composed = React.FC & { export const ReadPretty: Composed = () => null; ReadPretty.File = function File(props: UploadProps) { + const { size, showCount = 0 } = props; const { t } = useTranslation(); const record = useRecord(); const field = useField(); 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 [visible, setVisible] = useState(false); const [fileType, setFileType] = useState<'image' | 'pdf'>(); - const { size } = props; const { wrapSSR, hashId, componentCls: prefixCls } = useStyles(); const useUploadStyleVal = (useUploadStyle as any).default ? (useUploadStyle as any).default : useUploadStyle; // 加载 antd 的样式 diff --git a/packages/core/client/src/schema-component/antd/upload/type.d.ts b/packages/core/client/src/schema-component/antd/upload/type.d.ts index ba7c9c05c..49eeac02a 100644 --- a/packages/core/client/src/schema-component/antd/upload/type.d.ts +++ b/packages/core/client/src/schema-component/antd/upload/type.d.ts @@ -7,6 +7,7 @@ export type UploadProps = Omit & { serviceErrorMessage?: string; value?: any; size?: string; + showCount?: number; }; export type DraggerProps = Omit & { diff --git a/packages/plugins/@hera/plugin-mobile/src/locale/en-US.json b/packages/plugins/@hera/plugin-mobile/src/locale/en-US.json index 05b770a8b..3f5c86d55 100644 --- a/packages/plugins/@hera/plugin-mobile/src/locale/en-US.json +++ b/packages/plugins/@hera/plugin-mobile/src/locale/en-US.json @@ -10,5 +10,6 @@ "Configure field": "Configure field", "Configure fields": "Configure fields", "Configure columns": "Configure columns", - "Add block": "Add block" + "Add block": "Add block", + "all": "all" } diff --git a/packages/plugins/@hera/plugin-mobile/src/locale/zh-CN.json b/packages/plugins/@hera/plugin-mobile/src/locale/zh-CN.json index cac01aac6..ab456be10 100644 --- a/packages/plugins/@hera/plugin-mobile/src/locale/zh-CN.json +++ b/packages/plugins/@hera/plugin-mobile/src/locale/zh-CN.json @@ -10,5 +10,6 @@ "Configure field": "配置字段", "Configure fields": "配置字段", "Configure columns": "配置字段", - "Add block": "创建区块" + "Add block": "创建区块", + "all": "全部" } diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/client/interfaces/attachment.ts b/packages/plugins/@nocobase/plugin-file-manager/src/client/interfaces/attachment.ts index 187ae558b..c4c96af92 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/client/interfaces/attachment.ts +++ b/packages/plugins/@nocobase/plugin-file-manager/src/client/interfaces/attachment.ts @@ -25,6 +25,9 @@ export class AttachmentFieldInterface extends CollectionFieldInterface { if (['Table', 'Kanban'].includes(block)) { schema['x-component-props'] = schema['x-component-props'] || {}; schema['x-component-props']['size'] = 'small'; + // TODO: 此处修改是个临时方案, 找不到具体上下文丢失的原因. 仿照之前size的处理办法. + // 影响: table的附件设置,在根源schema处的设置值无法传递下去. 只能在这里手动赋值. + schema['x-component-props']['showCount'] = 1; } if (!schema['x-component-props']) {