From 06d52deb60040d968c3f69d625f9cd52ecbdac4c Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期二, 22 四月 2025 11:48:56 +0800 Subject: [PATCH] 优化代码 --- src/components/ImageUpload/index.vue | 23 ++++++++++++++++++----- 1 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/components/ImageUpload/index.vue b/src/components/ImageUpload/index.vue index 149524b..2bedc33 100644 --- a/src/components/ImageUpload/index.vue +++ b/src/components/ImageUpload/index.vue @@ -6,6 +6,7 @@ list-type="picture-card" :on-success="handleUploadSuccess" :before-upload="handleBeforeUpload" + :data="data" :limit="limit" :on-error="handleUploadError" :on-exceed="handleExceed" @@ -47,9 +48,19 @@ <script setup> import { getToken } from "@/utils/auth"; +import { isExternal } from "@/utils/validate"; const props = defineProps({ modelValue: [String, Object, Array], + // 涓婁紶鎺ュ彛鍦板潃 + action: { + type: String, + default: "/common/upload" + }, + // 涓婁紶鎼哄甫鐨勫弬鏁� + data: { + type: Object + }, // 鍥剧墖鏁伴噺闄愬埗 limit: { type: Number, @@ -79,7 +90,7 @@ const dialogImageUrl = ref(""); const dialogVisible = ref(false); const baseUrl = import.meta.env.VITE_APP_BASE_API; -const uploadImgUrl = ref(import.meta.env.VITE_APP_BASE_API + "/common/upload"); // 涓婁紶鐨勫浘鐗囨湇鍔″櫒鍦板潃 +const uploadImgUrl = ref(import.meta.env.VITE_APP_BASE_API + props.action); // 涓婁紶鐨勫浘鐗囨湇鍔″櫒鍦板潃 const headers = ref({ Authorization: "Bearer " + getToken() }); const fileList = ref([]); const showTip = computed( @@ -93,7 +104,7 @@ // 鐒跺悗灏嗘暟缁勮浆涓哄璞℃暟缁� fileList.value = list.map(item => { if (typeof item === "string") { - if (item.indexOf(baseUrl) === -1) { + if (item.indexOf(baseUrl) === -1 && !isExternal(item)) { item = { name: baseUrl + item, url: baseUrl + item }; } else { item = { name: item, url: item }; @@ -124,9 +135,11 @@ isImg = file.type.indexOf("image") > -1; } if (!isImg) { - proxy.$modal.msgError( - `鏂囦欢鏍煎紡涓嶆纭�, 璇蜂笂浼�${props.fileType.join("/")}鍥剧墖鏍煎紡鏂囦欢!` - ); + proxy.$modal.msgError(`鏂囦欢鏍煎紡涓嶆纭紝璇蜂笂浼�${props.fileType.join("/")}鍥剧墖鏍煎紡鏂囦欢!`); + return false; + } + if (file.name.includes(',')) { + proxy.$modal.msgError('鏂囦欢鍚嶄笉姝g‘锛屼笉鑳藉寘鍚嫳鏂囬�楀彿!'); return false; } if (props.fileSize) { -- Gitblit v1.9.3