mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-15 12:12:02 +08:00
feat(upload prop:crop,aspectRatio): from Upload component accept prop… (#7095)
* feat(upload prop:crop,aspectRatio): from Upload component accept prop crop,aspectRatio * feat(upload prop:crop,aspectRatio): from Upload component accept prop crop,aspectRatio * feat(upload prop:crop,aspectRatio): from Upload component accept prop crop,aspectRatio * feat(upload prop:crop,aspectRatio): from Upload component accept prop crop,aspectRatio
This commit is contained in:
@@ -358,6 +358,28 @@ const [BaseForm, baseFormApi] = useVbenForm({
|
||||
},
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
{
|
||||
component: 'Upload',
|
||||
componentProps: {
|
||||
accept: '.png,.jpg,.jpeg',
|
||||
customRequest: upload_file,
|
||||
maxCount: 1,
|
||||
maxSize: 2,
|
||||
listType: 'picture-card',
|
||||
// 是否启用图片裁剪(多选或者非图片不唤起裁剪框)
|
||||
crop: true,
|
||||
// 裁剪比例
|
||||
aspectRatio: '1:1',
|
||||
},
|
||||
fieldName: 'cropImage',
|
||||
label: $t('examples.form.crop-image'),
|
||||
renderComponentContent: () => {
|
||||
return {
|
||||
default: () => $t('examples.form.upload-image'),
|
||||
};
|
||||
},
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
],
|
||||
// 大屏一行显示3个,中屏一行显示2个,小屏一行显示1个
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
|
||||
@@ -365,13 +387,20 @@ const [BaseForm, baseFormApi] = useVbenForm({
|
||||
|
||||
function onSubmit(values: Record<string, any>) {
|
||||
const files = toRaw(values.files) as UploadFile[];
|
||||
const cropImage = (toRaw(values.cropImage) ?? []) as UploadFile[];
|
||||
const doneFiles = files.filter((file) => file.status === 'done');
|
||||
const failedFiles = files.filter((file) => file.status !== 'done');
|
||||
const doneCrop = cropImage.filter((file) => file.status === 'done');
|
||||
const failedCrop = cropImage.filter((file) => file.status !== 'done');
|
||||
|
||||
const msg = [
|
||||
...doneFiles.map((file) => file.response?.url || file.url),
|
||||
...failedFiles.map((file) => file.name),
|
||||
].join(', ');
|
||||
const msgCrop = [
|
||||
...doneCrop.map((file) => file.response?.url || file.url),
|
||||
...failedCrop.map((file) => file.name),
|
||||
].join(', ');
|
||||
|
||||
if (failedFiles.length === 0) {
|
||||
message.success({
|
||||
@@ -383,8 +412,19 @@ function onSubmit(values: Record<string, any>) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (doneCrop.length > 0 && failedCrop.length === 0) {
|
||||
message.success({
|
||||
content: `${$t('examples.form.upload-urls')}: ${msgCrop}`,
|
||||
});
|
||||
} else if (failedCrop.length > 0) {
|
||||
message.error({
|
||||
content: `${$t('examples.form.upload-error')}: ${msgCrop}`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 如果需要可提交前替换为需要的urls
|
||||
values.files = doneFiles.map((file) => file.response?.url || file.url);
|
||||
values.cropImage = doneCrop.map((file) => file.response?.url || file.url);
|
||||
message.success({
|
||||
content: `form values: ${JSON.stringify(values)}`,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user