mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
* feat: support to add File collection * feat: support to upload files * refactor: rename 'ReadPretty.Attachment' to 'ReadPretty.File' * feat: support to associate the File collection * refactor: add Preview and replace Upload.Selector * fix(Preview): fix some problems in ReadPretty mode * feat: use 'preview' as a default title field * feat: support only local storage now * fix: should not show 'Add new' button * chore: add default value for file storage * fix: fix preview field of file collection cannot be displayed normally * fix: only Table and Details can display File collection * chore: translate * refactor: migration to plugin from core * refactor: change 'preview' to 'url' * fix: only 'belongsTo' and 'belongsToMany' can linked file collection * fix: fix storage and add a field called storage in file collection * feat: add 'deletable' to configure the visibility of the delete button * fix: fix can't upload attachment problem * fix: remove more option * fix: can't use preview to filter * fix: remove Import action option * refactor: remove useless code * chore: optimize condition * chore: remove comment * test: windows compatible * refactor: optimize upload * fix: upload action * fix: createAction * fix: uploads * fix: file collection cannot be inherited by other collections * fix: url should be editable * fix: url is filterable * fix: use input interface for url field * fix: fix error * fix: remove subform * Revert "chore: translate" This reverts commit 53cd346dab8cbee0c52a9da3cf83a99dff2def34. * refactor: move translation to plugin * fix: title is editable * fix: collection?.template === 'file' * fix: fix order of URL * fix(collection-manager): allow collectionCategories:list * chore: add translation * fix(upload): should enable to use drawer * refactor: move code to plugin --------- Co-authored-by: chenos <chenlinxh@gmail.com>
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { useBlockRequestContext } from '@nocobase/client';
|
|
import { notification } from 'antd';
|
|
import { useFmTranslation } from '../locale';
|
|
|
|
// 限制上传文件大小为 10M
|
|
export const FILE_LIMIT_SIZE = 10 * 1024 * 1024;
|
|
|
|
export const useUploadFiles = () => {
|
|
const { service } = useBlockRequestContext();
|
|
const { t } = useFmTranslation();
|
|
const uploadingFiles = {};
|
|
|
|
let pendingNumber = 0;
|
|
|
|
return {
|
|
/**
|
|
* 返回 false 会阻止上传,返回 true 会继续上传
|
|
*/
|
|
beforeUpload(file) {
|
|
if (file.size > FILE_LIMIT_SIZE) {
|
|
notification.error({
|
|
message: `${t('File size cannot exceed')} ${FILE_LIMIT_SIZE / 1024 / 1024}M`,
|
|
});
|
|
file.status = 'error';
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
onChange(fileList) {
|
|
fileList.forEach((file) => {
|
|
if (file.status === 'uploading' && !uploadingFiles[file.uid]) {
|
|
pendingNumber++;
|
|
uploadingFiles[file.uid] = true;
|
|
}
|
|
if (file.status === 'done' && uploadingFiles[file.uid]) {
|
|
delete uploadingFiles[file.uid];
|
|
if (--pendingNumber === 0) {
|
|
service?.refresh?.();
|
|
}
|
|
}
|
|
});
|
|
},
|
|
};
|
|
};
|