hookehuyr

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

...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
47 * @param image_type[Array] 图片上传类型 47 * @param image_type[Array] 图片上传类型
48 * @param multiple[Boolean] 图片多选 48 * @param multiple[Boolean] 图片多选
49 */ 49 */
50 -import { showSuccessToast, showFailToast } from "vant"; 50 +import { showSuccessToast, showFailToast, showToast } from "vant";
51 import _ from "lodash"; 51 import _ from "lodash";
52 import { v4 as uuidv4 } from "uuid"; 52 import { v4 as uuidv4 } from "uuid";
53 import { qiniuTokenAPI, qiniuUploadAPI, saveFileAPI } from "@/api/common"; 53 import { qiniuTokenAPI, qiniuUploadAPI, saveFileAPI } from "@/api/common";
...@@ -96,11 +96,30 @@ const beforeRead = (file) => { ...@@ -96,11 +96,30 @@ const beforeRead = (file) => {
96 flag = false; 96 flag = false;
97 showFailToast("请上传指定格式图片"); 97 showFailToast("请上传指定格式图片");
98 } 98 }
99 + if (fileList.value.length + file.length > props.item.component_props.max_count) {
100 + // 数量限制
101 + flag = false;
102 + showToast(`最大上传数量为${props.item.component_props.max_count}个`);
103 + }
99 } else { 104 } else {
100 if (!_.includes(image_types, file.type)) { 105 if (!_.includes(image_types, file.type)) {
101 showFailToast("请上传指定格式图片"); 106 showFailToast("请上传指定格式图片");
102 flag = false; 107 flag = false;
103 } 108 }
109 + if (fileList.value.length + 1 > props.item.component_props.max_count) {
110 + // 数量限制
111 + flag = false;
112 + showToast(`最大上传数量为${props.item.component_props.max_count}个`);
113 + }
114 + if (file.size > props.item.component_props.max_size) {
115 + // 体积限制
116 + flag = false;
117 + showToast(
118 + `最大文件体积为${(props.item.component_props.max_size / 1024 / 1024).toFixed(
119 + 2
120 + )}MB`
121 + );
122 + }
104 } 123 }
105 return flag; 124 return flag;
106 }; 125 };
......