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:
		
							parent
							
								
									2dd8e25616
								
							
						
					
					
						commit
						8da9c47a7e
					
				@ -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();
 | 
			
		||||
          },
 | 
			
		||||
        };
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
  ],
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -22,15 +22,16 @@ type Composed = React.FC<UploadProps> & {
 | 
			
		||||
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<Field>();
 | 
			
		||||
  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 的样式
 | 
			
		||||
 | 
			
		||||
@ -7,6 +7,7 @@ export type UploadProps = Omit<AntdUploadProps, 'onChange'> & {
 | 
			
		||||
  serviceErrorMessage?: string;
 | 
			
		||||
  value?: any;
 | 
			
		||||
  size?: string;
 | 
			
		||||
  showCount?: number;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export type DraggerProps = Omit<AntdDraggerProps, 'onChange'> & {
 | 
			
		||||
 | 
			
		||||
@ -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"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -10,5 +10,6 @@
 | 
			
		||||
  "Configure field": "配置字段",
 | 
			
		||||
  "Configure fields": "配置字段",
 | 
			
		||||
  "Configure columns": "配置字段",
 | 
			
		||||
  "Add block": "创建区块"
 | 
			
		||||
  "Add block": "创建区块",
 | 
			
		||||
  "all": "全部"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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']) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user