fix
This commit is contained in:
@@ -7,10 +7,9 @@ import {
|
||||
type PDFDocumentProxy,
|
||||
type RenderTask,
|
||||
} from "pdfjs-dist";
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue";
|
||||
import { computed, nextTick, onBeforeUnmount, ref, shallowRef, watch } from "vue";
|
||||
|
||||
const props = defineProps<{
|
||||
localPath: string;
|
||||
scanUrl: string;
|
||||
title: string;
|
||||
}>();
|
||||
@@ -23,7 +22,7 @@ GlobalWorkerOptions.workerSrc = new URL(
|
||||
).toString();
|
||||
|
||||
const canvasRef = ref<HTMLCanvasElement | null>(null);
|
||||
const pdfDocument = ref<PDFDocumentProxy | null>(null);
|
||||
const pdfDocument = shallowRef<PDFDocumentProxy | null>(null);
|
||||
const loading = ref(false);
|
||||
const error = ref("");
|
||||
const pageNumber = ref(1);
|
||||
@@ -41,19 +40,17 @@ async function loadDocument() {
|
||||
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
let task: PDFDocumentLoadingTask | null = null;
|
||||
|
||||
try {
|
||||
const bytes = await invoke<number[]>("load_application_file", {
|
||||
localPath: props.localPath,
|
||||
scanUrl: props.scanUrl,
|
||||
const bytes = await invoke<number[]>("load_remote_file", {
|
||||
url: props.scanUrl,
|
||||
});
|
||||
|
||||
if (!bytes.length) {
|
||||
throw new Error("Файл пустой");
|
||||
}
|
||||
|
||||
task = getDocument({ data: new Uint8Array(bytes) });
|
||||
const task = getDocument({ data: new Uint8Array(bytes) });
|
||||
loadingTask = task;
|
||||
|
||||
const document = await task.promise;
|
||||
@@ -66,12 +63,13 @@ async function loadDocument() {
|
||||
pageCount.value = document.numPages;
|
||||
pageNumber.value = 1;
|
||||
scale.value = 1.1;
|
||||
loading.value = false;
|
||||
await nextTick();
|
||||
await renderPage();
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : "Не удалось открыть PDF";
|
||||
} finally {
|
||||
loading.value = false;
|
||||
if (task && loadingTask === task) {
|
||||
if (loadingTask) {
|
||||
loadingTask = null;
|
||||
}
|
||||
}
|
||||
@@ -156,7 +154,7 @@ async function zoomOut() {
|
||||
await renderPage();
|
||||
}
|
||||
|
||||
watch([show, () => props.localPath, () => props.scanUrl], async ([visible]) => {
|
||||
watch([show, () => props.scanUrl], async ([visible]) => {
|
||||
if (visible) {
|
||||
await nextTick();
|
||||
await loadDocument();
|
||||
|
||||
Reference in New Issue
Block a user