优化 #5737
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
@error.once="proxyImage"
|
@error.once="proxyImage"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
/>
|
/>
|
||||||
<p v-else :style="{ fontFamily, fontSize }" v-html="para" @error.capture="handleImgLoadError" />
|
<p v-else :style="{ fontFamily, fontSize }" v-html="replaceImage(para)" @error.capture="handleImgLoadError" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ import type { webReadConfig } from '@/web'
|
|||||||
|
|
||||||
const store = useBookStore()
|
const store = useBookStore()
|
||||||
const readWidth = computed(() => store.config.readWidth)
|
const readWidth = computed(() => store.config.readWidth)
|
||||||
|
const fontSize = computed(() => store.config.fontSize)
|
||||||
const bookUrl = computed(() => store.readingBook.bookUrl)
|
const bookUrl = computed(() => store.readingBook.bookUrl)
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -36,14 +37,29 @@ const props = defineProps<{
|
|||||||
fontSize: string
|
fontSize: string
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
const imgPattern = /<img[^>]*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 getImageSrc = (content: string) => {
|
||||||
const imgPattern = /<img[^>]*src="([^"]*(?:"[^>]+\})?)"[^>]*>/
|
|
||||||
const src = content.match(imgPattern)![1] //reg tested in template
|
const src = content.match(imgPattern)![1] //reg tested in template
|
||||||
if (isLegadoUrl(src))
|
if (isLegadoUrl(src))
|
||||||
return API.getProxyImageUrl(
|
return API.getProxyImageUrl(
|
||||||
bookUrl.value,
|
bookUrl.value,
|
||||||
src,
|
src,
|
||||||
useBookStore().config.readWidth,
|
readWidth.value,
|
||||||
)
|
)
|
||||||
return src
|
return src
|
||||||
}
|
}
|
||||||
@@ -82,7 +98,6 @@ const handleImgLoadError = (event: Event) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const calculateWordCount = (paragraph: string) => {
|
const calculateWordCount = (paragraph: string) => {
|
||||||
const imgPattern = /<img[^>]*src="[^"]*(?:"[^>]+\})?"[^>]*>/g
|
|
||||||
//内嵌图片文字为1
|
//内嵌图片文字为1
|
||||||
const imagePlaceHolder = ' '
|
const imagePlaceHolder = ' '
|
||||||
return paragraph.replace(imgPattern, imagePlaceHolder).length
|
return paragraph.replace(imgPattern, imagePlaceHolder).length
|
||||||
|
|||||||
Reference in New Issue
Block a user