Bläddra i källkod

fix: 演出安排只能上传图片

sgc 3 veckor sedan
förälder
incheckning
f6253970d8
1 ändrade filer med 33 tillägg och 3 borttagningar
  1. 33 3
      src/views/performance/edit.vue

+ 33 - 3
src/views/performance/edit.vue

@@ -44,7 +44,8 @@
               <div class="upload-wrap">
                 <UploadImgs
                   v-model:file-list="posterFileList"
-                  :api="uploadImgStore"
+                  :api="handlePerformanceImageUpload"
+                  :file-type="PERFORMANCE_IMAGE_FILE_TYPES"
                   :limit="1"
                   :file-size="20"
                   :disabled="viewMode"
@@ -194,7 +195,8 @@
               <div class="upload-wrap">
                 <UploadImgs
                   v-model:file-list="detailImageFileList"
-                  :api="uploadImgStore"
+                  :api="handlePerformanceImageUpload"
+                  :file-type="PERFORMANCE_IMAGE_FILE_TYPES"
                   :limit="9"
                   :file-size="20"
                   :disabled="viewMode"
@@ -294,7 +296,10 @@ import { ElMessage } from "element-plus";
 import { User, Close, ArrowLeft } from "@element-plus/icons-vue";
 import type { FormInstance, FormRules, UploadUserFile } from "element-plus";
 import UploadImgs from "@/components/Upload/Imgs.vue";
-import { uploadImgStore } from "@/api/modules/upload";
+import { uploadFilesToOss } from "@/api/upload.js";
+
+/** 演出编辑仅图片(UploadImgs 默认 fileType 含 video/*) */
+const PERFORMANCE_IMAGE_FILE_TYPES = ["image/jpeg", "image/png", "image/gif", "image/webp", "image/heic", "image/heif"];
 import {
   getPerformanceDetail,
   saveOrUpdatePerformance,
@@ -477,6 +482,31 @@ async function loadDetail() {
   } catch (e) {}
 }
 
+/** OSS 直传,仅图片(UploadImgs 读取 response.fileUrl) */
+const handlePerformanceImageUpload = async (formData: FormData, options?: Record<string, unknown>): Promise<any> => {
+  const raw = formData.get("file");
+  const file = raw instanceof File ? raw : null;
+  if (!file) {
+    throw new Error("请选择文件");
+  }
+  const mime = typeof file.type === "string" ? file.type : "";
+  if (mime.startsWith("video/") || /\.(mp4|m4v|webm|ogg|mov|avi)(\?.*)?$/i.test(file.name || "")) {
+    throw new Error("仅支持上传图片");
+  }
+  const urls = await uploadFilesToOss(file, "image", options ?? {});
+  const fileUrl = urls[0];
+  if (!fileUrl) {
+    throw new Error("上传失败,未返回地址");
+  }
+  return {
+    fileUrl,
+    data: { fileUrl },
+    code: 200,
+    success: true,
+    msg: "操作成功"
+  };
+};
+
 function syncPosterAndDetailFiles() {
   const poster = form.value.posterUrls?.[0] ?? form.value.imgUrl;
   posterFileList.value = poster ? ([{ name: "poster", url: poster }] as UploadUserFile[]) : [];