tachybase_todo/docs/components/collection-fields/attachment.md

59 lines
1.2 KiB
Markdown
Raw Normal View History

---
group:
title: Collection Fields
path: /components/collection-fields
order: 3
2021-10-31 11:35:11 +08:00
---
# Attachment - 附件
## Interface
```ts
export const attachment: FieldOptions = {
name: 'attachment',
type: 'object',
group: 'media',
title: '附件',
isAssociation: true,
default: {
dataType: 'belongsToMany',
target: 'attachments',
// name,
uiSchema: {
type: 'array',
// title,
'x-component': 'Upload.Attachment',
'x-decorator': 'FormItem',
'x-designable-bar': 'Upload.DesignableBar',
},
},
initialize: (values: any) => {
if (!values.through) {
values.through = `t_${uid()}`;
}
if (!values.foreignKey) {
values.foreignKey = `f_${uid()}`;
}
if (!values.otherKey) {
values.otherKey = `f_${uid()}`;
}
if (!values.sourceKey) {
values.sourceKey = 'id';
}
if (!values.targetKey) {
values.targetKey = 'id';
}
},
properties: {
...defaultProps,
'uiSchema.x-component-props.multiple': {
type: 'boolean',
'x-content': '允许上传多个文件',
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
default: true,
},
},
};
```