Browse Source

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/7108/head
JyQAQ 3 weeks ago
committed by GitHub
parent
commit
174c4ae749
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 11
      apps/web-antd/src/adapter/component/index.ts
  2. 11
      playground/src/adapter/component/index.ts
  3. 9
      playground/src/views/examples/form/basic.vue

11
apps/web-antd/src/adapter/component/index.ts

@ -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',
);

11
playground/src/adapter/component/index.ts

@ -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',
);

9
playground/src/views/examples/form/basic.vue

@ -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'),

Loading…
Cancel
Save