hookehuyr

图片上传控件新增最大数量和最大体积控制

......@@ -47,7 +47,7 @@
* @param image_type[Array] 图片上传类型
* @param multiple[Boolean] 图片多选
*/
import { showSuccessToast, showFailToast } from "vant";
import { showSuccessToast, showFailToast, showToast } from "vant";
import _ from "lodash";
import { v4 as uuidv4 } from "uuid";
import { qiniuTokenAPI, qiniuUploadAPI, saveFileAPI } from "@/api/common";
......@@ -96,11 +96,30 @@ const beforeRead = (file) => {
flag = false;
showFailToast("请上传指定格式图片");
}
if (fileList.value.length + file.length > props.item.component_props.max_count) {
// 数量限制
flag = false;
showToast(`最大上传数量为${props.item.component_props.max_count}个`);
}
} else {
if (!_.includes(image_types, file.type)) {
showFailToast("请上传指定格式图片");
flag = false;
}
if (fileList.value.length + 1 > props.item.component_props.max_count) {
// 数量限制
flag = false;
showToast(`最大上传数量为${props.item.component_props.max_count}个`);
}
if (file.size > props.item.component_props.max_size) {
// 体积限制
flag = false;
showToast(
`最大文件体积为${(props.item.component_props.max_size / 1024 / 1024).toFixed(
2
)}MB`
);
}
}
return flag;
};
......