fix(antd Upload onChange Event): rewrite onChange event to handle upl… (#7098)

* fix(antd Upload onChange Event): rewrite onChange event to handle upload success or error messages

* fix(antd Upload onChange Event): rewrite onChange event to handle upload success or error messages

* fix(antd Upload onChange Event): rewrite onChange event to handle upload success or error messages
pull/324/head
JyQAQ 2026-01-14 15:38:21 +08:00 committed by GitHub
parent 67da9417a8
commit 174c4ae749
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 2 deletions

View File

@ -424,7 +424,16 @@ const withPreviewUpload = () => {
return attrs.beforeUpload?.(file) ?? true;
};
const handleChange = async (event: UploadChangeParam) => {
const handleChange = (event: UploadChangeParam) => {
try {
// 行内写法 handleChange: (event) => {}
attrs.handleChange?.(event);
// template写法 @handle-change="(event) => {}"
attrs.onHandleChange?.(event);
} catch (error) {
// Avoid breaking internal v-model sync on user handler errors
console.error(error);
}
fileList.value = event.fileList.filter(
(file) => file.status !== 'removed',
);

View File

@ -424,7 +424,16 @@ const withPreviewUpload = () => {
return attrs.beforeUpload?.(file) ?? true;
};
const handleChange = async (event: UploadChangeParam) => {
const handleChange = (event: UploadChangeParam) => {
try {
// 行内写法 handleChange: (event) => {}
attrs.handleChange?.(event);
// template写法 @handle-change="(event) => {}"
attrs.onHandleChange?.(event);
} catch (error) {
// Avoid breaking internal v-model sync on user handler errors
console.error(error);
}
fileList.value = event.fileList.filter(
(file) => file.status !== 'removed',
);

View File

@ -348,6 +348,15 @@ const [BaseForm, baseFormApi] = useVbenForm({
showUploadList: true,
// text, picture, picture-card picture-circle
listType: 'picture-card',
// onChange
handleChange: ({ file }: { file: UploadFile }) => {
const { name, status } = file;
if (status === 'done') {
message.success(`${name} ${$t('examples.form.upload-success')}`);
} else if (status === 'error') {
message.error(`${name} ${$t('examples.form.upload-fail')}`);
}
},
},
fieldName: 'files',
label: $t('examples.form.file'),