From 9edb9611886b814a6dcac3b23da1a38d24ad3c21 Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Sun, 15 Mar 2026 14:08:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20#5737?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/web/src/components/ChapterContent.vue | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/modules/web/src/components/ChapterContent.vue b/modules/web/src/components/ChapterContent.vue index 405a4f368..8c41941b7 100644 --- a/modules/web/src/components/ChapterContent.vue +++ b/modules/web/src/components/ChapterContent.vue @@ -13,7 +13,7 @@ @error.once="proxyImage" loading="lazy" /> -

+

@@ -25,6 +25,7 @@ import type { webReadConfig } from '@/web' const store = useBookStore() const readWidth = computed(() => store.config.readWidth) +const fontSize = computed(() => store.config.fontSize) const bookUrl = computed(() => store.readingBook.bookUrl) const props = defineProps<{ @@ -36,14 +37,29 @@ const props = defineProps<{ fontSize: string }>() +const imgPattern = /]*src=['"]([^'"]*(?:['"][^>]+\})?)['"][^>]*>/g + +const replaceImage = (content: string) => { + return content.replace(imgPattern, (match, src) => { + if (isLegadoUrl(src)) { + const proxySrc = API.getProxyImageUrl( + bookUrl.value, + src, + fontSize.value, + ) + return match.replace(src, proxySrc) + } + return match + }) +} + const getImageSrc = (content: string) => { - const imgPattern = /]*src="([^"]*(?:"[^>]+\})?)"[^>]*>/ const src = content.match(imgPattern)![1] //reg tested in template if (isLegadoUrl(src)) return API.getProxyImageUrl( bookUrl.value, src, - useBookStore().config.readWidth, + readWidth.value, ) return src } @@ -82,7 +98,6 @@ const handleImgLoadError = (event: Event) => { } const calculateWordCount = (paragraph: string) => { - const imgPattern = /]*src="[^"]*(?:"[^>]+\})?"[^>]*>/g //内嵌图片文字为1 const imagePlaceHolder = ' ' return paragraph.replace(imgPattern, imagePlaceHolder).length