Просмотр исходного кода

fix: 预定服务上传图片没限制住

sgc 3 дней назад
Родитель
Сommit
1bfbb25447
1 измененных файлов с 18 добавлено и 0 удалено
  1. 18 0
      src/views/appoinmentManagement/classifyManagement.vue

+ 18 - 0
src/views/appoinmentManagement/classifyManagement.vue

@@ -55,6 +55,7 @@
               v-model:file-list="form.planeImageFileList"
               list-type="picture-card"
               :limit="9"
+              :before-upload="beforePlaneImageUpload"
               :http-request="handlePlaneImageUpload"
               :on-remove="onPlaneImageRemove"
               :on-preview="onPlaneImagePreview"
@@ -122,6 +123,23 @@ import {
 import { uploadFileToOss } from "@/api/upload.js";
 import { localGet } from "@/utils";
 
+/** 平面图单张上限(与商户端 / 动态发布一致) */
+const PLANE_IMAGE_MAX_MB = 20;
+const UPLOAD_TIP_IMAGE = "图片建议不超过 20MB";
+
+const beforePlaneImageUpload = (rawFile: File) => {
+  const mime = String(rawFile?.type || "");
+  if (!mime.startsWith("image/")) {
+    ElMessage.warning("只能上传图片格式");
+    return false;
+  }
+  if (rawFile.size > PLANE_IMAGE_MAX_MB * 1024 * 1024) {
+    ElMessage.warning(UPLOAD_TIP_IMAGE);
+    return false;
+  }
+  return true;
+};
+
 export interface CategoryRow {
   id: number | string;
   _seq?: number;