图片预览图片路径处理

This commit is contained in:
weiwei committed 2025-04-17 12:33:16 +08:00
1 parent c5f5bb0649
commit 219c730751
1 file changed
+24 -2
+24 -2
View File
@@ -18,14 +18,36 @@ const props = withDefaults(defineProps<Props>(), {
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`))