From 219c7307510f24c2ab4aa0b113511a4fc49c8662 Mon Sep 17 00:00:00 2001 From: weiwei Date: Thu, 17 Apr 2025 12:33:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E9=A2=84=E8=A7=88=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E8=B7=AF=E5=BE=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PreviewImage/index.vue | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/components/PreviewImage/index.vue b/src/components/PreviewImage/index.vue index 5b8a0b5..0ae388f 100644 --- a/src/components/PreviewImage/index.vue +++ b/src/components/PreviewImage/index.vue @@ -18,14 +18,36 @@ const props = withDefaults(defineProps(), { downloadName: "下载", }) +const formatSrc = (src: string, type: "string" | "array" = "string"): string | string[] => { + switch (type) { + case "string": + if (!src.match(/x-oss-process/g)) { + return src.split(",")[0] + } else { + return src.split("?")[0] + } + case "array": + if (!src.match(/x-oss-process/g)) { + return src.split(",") + } else { + return src + .split("?") + .filter( + (item) => + item.endsWith(".jpg") || item.endsWith(".png") || item.endsWith(".gif") || item.endsWith(".jpeg") || item.endsWith(".webp"), + ) + } + } +} + const realSrc = computed(() => { if (!props.src) return "" - let real_src = props.src.split(",")[0] + let real_src: string = formatSrc(props.src, "string") as string return dispatchUrl(real_src) ?? "" }) const realSrcList = computed(() => { if (!props.src) return "" - let real_src = props.src.split(",")?.map((v) => dispatchUrl(v)) + let real_src = (formatSrc(props.src, "array") as string[]).map((v) => dispatchUrl(v)) return real_src ?? [] }) const realWidth = computed(() => (typeof props.width == "string" ? props.width : `${props.width}px`))