fix: web书籍部分图片加载失败

This commit is contained in:
Xwite
2023-04-16 20:13:45 +08:00
parent 97d75c1484
commit 9ee0c363e6
12 changed files with 61 additions and 63 deletions
+13 -5
View File
@@ -1,9 +1,10 @@
<template>
<div v-for="(para, index) in props.carray" :key="index">
<div v-for="(para, index) in carray" :key="index">
<img
class="full"
v-if="/^\s*<img[^>]*src[^>]+>$/.test(para)"
:src="getImageSrc(para)"
@error.once="proxyImage"
loading="lazy"
/>
<p v-else :style="style" v-html="para" />
@@ -12,8 +13,10 @@
<script setup>
import config from "../plugins/config";
import { getImageFromLegado, isLegadoUrl } from "../plugins/utils";
const store = useBookStore();
const props = defineProps(["carray"]);
defineProps(["carray"]);
const fontFamily = computed(() => {
if (store.config.font >= 0) {
@@ -30,10 +33,15 @@ const style = computed(() => {
return style;
});
function getImageSrc(content) {
const getImageSrc = (content) => {
const imgPattern = /<img[^>]*src="([^"]*(?:"[^>]+\})?)"[^>]*>/;
return content.match(imgPattern)[1];
}
const src = content.match(imgPattern)[1];
if (isLegadoUrl(src)) return getImageFromLegado(src);
return src;
};
const proxyImage = (event) => {
event.target.src = getImageFromLegado(event.target.src);
};
watch(fontSize, () => {
store.setShowContent(false);