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`))