This commit is contained in:
che
2026-07-27 10:51:18 +05:00
parent 560b3fe44e
commit c1b24206b9
13 changed files with 405 additions and 226 deletions
+9 -11
View File
@@ -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();