Skip to content

Commit 9664be1

Browse files
committed
feat: 增加通过 Url 打开文档功能
1 parent a1b726b commit 9664be1

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/components/BootstrapBlazor.EmbedPDF/EmbedPDF.razor.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Data from '../BootstrapBlazor/modules/data.js';
1+
import Data from '../BootstrapBlazor/modules/data.js'
22
import EventHandler from "../BootstrapBlazor/modules/event-handler.js"
3-
import { default as EmbedPDF, UIPlugin } from './embedpdf.js';
3+
import { default as EmbedPDF, DocumentManagerPlugin } from './embedpdf.js'
44
import { getTheme, registerBootstrapBlazorModule } from '../BootstrapBlazor/modules/utility.js'
55

66
export function init(id, invoke, options) {
@@ -37,8 +37,21 @@ export function init(id, invoke, options) {
3737
Data.set(id, { el, invoke, options, viewer });
3838
}
3939

40-
export function setUrl(id, url) {
40+
export async function setUrl(id, url) {
41+
if (url) {
42+
const pdf = Data.get(id);
43+
const { viewer } = pdf;
4144

45+
if (viewer) {
46+
const registry = await viewer.registry;
47+
const docManager = registry.getPlugin('document-manager').provides();
48+
docManager.openDocumentUrl({
49+
url,
50+
documentId: getFileName(url),
51+
autoActivate: true
52+
});
53+
}
54+
}
4255
}
4356

4457
export function setTheme(id, theme) {
@@ -77,3 +90,11 @@ const updateTheme = e => {
7790
}
7891
});
7992
}
93+
94+
function getFileName(filePath) {
95+
const lastSeparatorIndex = Math.max(
96+
filePath.lastIndexOf('/'),
97+
filePath.lastIndexOf('\\')
98+
);
99+
return filePath.substring(lastSeparatorIndex + 1);
100+
}

0 commit comments

Comments
 (0)