|
@@ -45,11 +45,15 @@ const loading = ref(true);
|
|
|
const error = ref(null);
|
|
const error = ref(null);
|
|
|
const progress = ref(0);
|
|
const progress = ref(0);
|
|
|
const pdfContainer = ref(null);
|
|
const pdfContainer = ref(null);
|
|
|
|
|
+const currentUrl = ref('');
|
|
|
let pdfDoc = null;
|
|
let pdfDoc = null;
|
|
|
|
|
|
|
|
const loadPdf = async () => {
|
|
const loadPdf = async () => {
|
|
|
if (!props.url) return;
|
|
if (!props.url) return;
|
|
|
|
|
+ // 如果正在加载当前URL,或者是已加载完成的URL,则跳过
|
|
|
|
|
+ if (loading.value && props.url === currentUrl.value) return;
|
|
|
|
|
|
|
|
|
|
+ currentUrl.value = props.url;
|
|
|
loading.value = true;
|
|
loading.value = true;
|
|
|
error.value = null;
|
|
error.value = null;
|
|
|
progress.value = 0;
|
|
progress.value = 0;
|
|
@@ -79,12 +83,14 @@ const loadPdf = async () => {
|
|
|
loading.value = false;
|
|
loading.value = false;
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
console.error('PDF 加载失败:', err);
|
|
console.error('PDF 加载失败:', err);
|
|
|
- error.value = '文档加载失败,请稍后重试或尝试下载查看';
|
|
|
|
|
|
|
+ error.value = '文档加载失败,请稍后重试';
|
|
|
loading.value = false;
|
|
loading.value = false;
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const renderPage = async (pageNum) => {
|
|
const renderPage = async (pageNum) => {
|
|
|
|
|
+ if (!pdfDoc) return; // 确保文档存在
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
const page = await pdfDoc.getPage(pageNum);
|
|
const page = await pdfDoc.getPage(pageNum);
|
|
|
|
|
|
|
@@ -124,14 +130,18 @@ const renderPage = async (pageNum) => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-watch(() => props.url, () => {
|
|
|
|
|
- loadPdf();
|
|
|
|
|
|
|
+watch(() => props.url, (newUrl, oldUrl) => {
|
|
|
|
|
+ if (newUrl !== oldUrl) {
|
|
|
|
|
+ loadPdf();
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
// 稍微延迟加载,确保容器已准备好
|
|
// 稍微延迟加载,确保容器已准备好
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
- loadPdf();
|
|
|
|
|
|
|
+ if (props.url) {
|
|
|
|
|
+ loadPdf();
|
|
|
|
|
+ }
|
|
|
}, 100);
|
|
}, 100);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -153,28 +163,44 @@ onUnmounted(() => {
|
|
|
overflow: hidden;
|
|
overflow: hidden;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-.loading-container, .error-container {
|
|
|
|
|
|
|
+.loading-container {
|
|
|
|
|
+ position: absolute;
|
|
|
|
|
+ top: 50%;
|
|
|
|
|
+ left: 50%;
|
|
|
|
|
+ transform: translate(-50%, -50%);
|
|
|
display: flex;
|
|
display: flex;
|
|
|
flex-direction: column;
|
|
flex-direction: column;
|
|
|
align-items: center;
|
|
align-items: center;
|
|
|
justify-content: center;
|
|
justify-content: center;
|
|
|
- padding: 40px 20px;
|
|
|
|
|
- text-align: center;
|
|
|
|
|
|
|
+ z-index: 10;
|
|
|
|
|
+ background: rgba(255, 255, 255, 0.8);
|
|
|
|
|
+ padding: 20px;
|
|
|
|
|
+ border-radius: 12px;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
.loading-spinner {
|
|
.loading-spinner {
|
|
|
- width: 40px;
|
|
|
|
|
- height: 40px;
|
|
|
|
|
- border: 4px solid #e5e7eb;
|
|
|
|
|
- border-top: 4px solid #3b82f6;
|
|
|
|
|
|
|
+ width: 30px;
|
|
|
|
|
+ height: 30px;
|
|
|
|
|
+ border: 3px solid #e5e7eb;
|
|
|
|
|
+ border-top: 3px solid #3b82f6;
|
|
|
border-radius: 50%;
|
|
border-radius: 50%;
|
|
|
animation: spin 1s linear infinite;
|
|
animation: spin 1s linear infinite;
|
|
|
- margin-bottom: 16px;
|
|
|
|
|
|
|
+ margin-bottom: 8px;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
.loading-text {
|
|
.loading-text {
|
|
|
color: #6b7280;
|
|
color: #6b7280;
|
|
|
- font-size: 14px;
|
|
|
|
|
|
|
+ font-size: 12px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.error-container {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ flex-direction: column;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ justify-content: center;
|
|
|
|
|
+ padding: 40px 20px;
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ height: 100%;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
.error-icon {
|
|
.error-icon {
|