@koi-br/ocr-web-sdk 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -86
- package/dist/index.cjs.js +32 -32
- package/dist/index.esm.js +4885 -4859
- package/package.json +1 -1
- package/preview/PdfPreview.vue +1 -1
- package/preview/index.vue +36 -0
package/README.md
CHANGED
|
@@ -81,7 +81,19 @@ pnpm add @koi-br/ocr-web-sdk
|
|
|
81
81
|
```vue
|
|
82
82
|
<template>
|
|
83
83
|
<div>
|
|
84
|
-
<FilePreview
|
|
84
|
+
<FilePreview
|
|
85
|
+
ref="previewRef"
|
|
86
|
+
:is-download="true"
|
|
87
|
+
:pdf-props="{
|
|
88
|
+
showTocSidebar: true,
|
|
89
|
+
blocksData: blocksData
|
|
90
|
+
}"
|
|
91
|
+
:image-props="{
|
|
92
|
+
minScale: 0.1,
|
|
93
|
+
maxScale: 5,
|
|
94
|
+
clickStep: 0.25
|
|
95
|
+
}"
|
|
96
|
+
/>
|
|
85
97
|
<button @click="previewFile">预览文件</button>
|
|
86
98
|
</div>
|
|
87
99
|
</template>
|
|
@@ -91,6 +103,7 @@ import { ref } from 'vue';
|
|
|
91
103
|
import { FilePreview } from '@koi-br/ocr-web-sdk';
|
|
92
104
|
|
|
93
105
|
const previewRef = ref(null);
|
|
106
|
+
const blocksData = ref([]); // PDF 分块数据
|
|
94
107
|
|
|
95
108
|
// 预览文件 URL
|
|
96
109
|
const previewFile = () => {
|
|
@@ -237,7 +250,15 @@ const handleDownload = () => {
|
|
|
237
250
|
|
|
238
251
|
| 参数 | 类型 | 默认值 | 说明 |
|
|
239
252
|
|------|------|--------|------|
|
|
240
|
-
| `isDownload` | `boolean` | `false` |
|
|
253
|
+
| `isDownload` | `boolean` | `false` | 是否显示下载按钮(会传递给所有子组件) |
|
|
254
|
+
| `pdfProps` | `object` | `{}` | 传递给 PDF 预览组件的 props(见 [PdfPreview Props](#pdfpreview-组件)) |
|
|
255
|
+
| `imageProps` | `object` | `{}` | 传递给图片预览组件的 props(见 [ImagePreview Props](#imagepreview-组件)) |
|
|
256
|
+
| `tifProps` | `object` | `{}` | 传递给 TIF 预览组件的 props(见 [TifPreview Props](#tifpreview-组件)) |
|
|
257
|
+
| `docxProps` | `object` | `{}` | 传递给 Word 预览组件的 props(见 [DocxPreview Props](#docxpreview-组件)) |
|
|
258
|
+
| `ofdProps` | `object` | `{}` | 传递给 OFD 预览组件的 props(见 [OfdPreview Props](#ofdpreview-组件)) |
|
|
259
|
+
| `xlsxProps` | `object` | `{}` | 传递给 Excel 预览组件的 props(见 [XlsxPreview Props](#xlsxpreview-组件)) |
|
|
260
|
+
|
|
261
|
+
**注意:** `isDownload` 会单独传递给子组件,不会包含在对应的 `*Props` 对象中。如果需要为不同文件类型设置不同的下载按钮显示状态,可以在对应的 `*Props` 中设置 `isDownload`(优先级更高)。
|
|
241
262
|
|
|
242
263
|
#### Methods
|
|
243
264
|
|
|
@@ -281,67 +302,32 @@ previewRef.value.preview(url, 'file.pdf', {
|
|
|
281
302
|
previewRef.value.clearPreview();
|
|
282
303
|
```
|
|
283
304
|
|
|
284
|
-
####
|
|
285
|
-
|
|
286
|
-
`FilePreview` 提供了多种方式访问子组件的方法:
|
|
287
|
-
|
|
288
|
-
##### 方式一:使用代理方法(推荐)
|
|
289
|
-
|
|
290
|
-
`FilePreview` 提供了常用方法的代理,可以直接调用:
|
|
291
|
-
|
|
292
|
-
```javascript
|
|
293
|
-
// PDF 预览相关方法
|
|
294
|
-
previewRef.value.goToPage(5); // 跳转到第5页
|
|
295
|
-
previewRef.value.jumpToPosition(1, [100, 100, 200, 200]); // 跳转到指定位置
|
|
296
|
-
const currentPage = previewRef.value.getCurrentPage(); // 获取当前页码
|
|
297
|
-
const totalPages = previewRef.value.getTotalPages(); // 获取总页数
|
|
298
|
-
|
|
299
|
-
// 图片预览相关方法
|
|
300
|
-
previewRef.value.resetImage(); // 重置图片预览
|
|
301
|
-
previewRef.value.resetTif(); // 重置 TIF 预览
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
##### 方式二:获取子组件引用
|
|
305
|
-
|
|
306
|
-
如果需要访问子组件的所有方法,可以获取子组件的引用:
|
|
305
|
+
#### 向子组件传递 Props
|
|
307
306
|
|
|
308
|
-
|
|
309
|
-
// 获取 PDF 预览组件引用
|
|
310
|
-
const pdfPreview = previewRef.value.getPdfPreview();
|
|
311
|
-
if (pdfPreview) {
|
|
312
|
-
pdfPreview.jumpToPosition(1, [100, 100, 200, 200]);
|
|
313
|
-
pdfPreview.goToPage(5);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// 获取图片预览组件引用
|
|
317
|
-
const imagePreview = previewRef.value.getImagePreview();
|
|
318
|
-
if (imagePreview) {
|
|
319
|
-
imagePreview.reset();
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// 获取当前活动的预览组件(根据文件类型自动返回)
|
|
323
|
-
const currentPreview = previewRef.value.getCurrentPreview();
|
|
324
|
-
if (currentPreview) {
|
|
325
|
-
// 如果是 PDF 预览,可以调用 PDF 相关方法
|
|
326
|
-
if (currentPreview.jumpToPosition) {
|
|
327
|
-
currentPreview.jumpToPosition(1, [100, 100, 200, 200]);
|
|
328
|
-
}
|
|
329
|
-
// 如果是图片预览,可以调用图片相关方法
|
|
330
|
-
if (currentPreview.reset) {
|
|
331
|
-
currentPreview.reset();
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
```
|
|
307
|
+
`FilePreview` 支持通过 `*Props` 属性向对应的子组件传递配置。例如,向 PDF 预览组件传递 `blocksData` 和 `showTocSidebar`:
|
|
335
308
|
|
|
336
|
-
|
|
309
|
+
**示例:**
|
|
337
310
|
```vue
|
|
338
311
|
<template>
|
|
339
|
-
<
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
312
|
+
<FilePreview
|
|
313
|
+
ref="previewRef"
|
|
314
|
+
:is-download="true"
|
|
315
|
+
:pdf-props="{
|
|
316
|
+
showTocSidebar: true,
|
|
317
|
+
blocksData: pdfBlocksData
|
|
318
|
+
}"
|
|
319
|
+
:image-props="{
|
|
320
|
+
minScale: 0.1,
|
|
321
|
+
maxScale: 5,
|
|
322
|
+
clickStep: 0.25,
|
|
323
|
+
wheelStep: 0.1
|
|
324
|
+
}"
|
|
325
|
+
:docx-props="{
|
|
326
|
+
docName: '我的文档',
|
|
327
|
+
minScale: 0.1,
|
|
328
|
+
maxScale: 3
|
|
329
|
+
}"
|
|
330
|
+
/>
|
|
345
331
|
</template>
|
|
346
332
|
|
|
347
333
|
<script setup>
|
|
@@ -349,38 +335,31 @@ import { ref } from 'vue';
|
|
|
349
335
|
import { FilePreview } from '@koi-br/ocr-web-sdk';
|
|
350
336
|
|
|
351
337
|
const previewRef = ref(null);
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
// 方式一:使用代理方法(推荐)
|
|
359
|
-
previewRef.value.goToPage(5);
|
|
360
|
-
|
|
361
|
-
// 方式二:获取 PDF 预览组件引用
|
|
362
|
-
const pdfPreview = previewRef.value.getPdfPreview();
|
|
363
|
-
if (pdfPreview) {
|
|
364
|
-
pdfPreview.goToPage(5);
|
|
338
|
+
const pdfBlocksData = ref([
|
|
339
|
+
{
|
|
340
|
+
blockLabel: '标题',
|
|
341
|
+
blockContent: '第一章',
|
|
342
|
+
blockBbox: [100, 100, 200, 150],
|
|
343
|
+
blockPage: 1
|
|
365
344
|
}
|
|
366
|
-
|
|
345
|
+
]);
|
|
367
346
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const bbox = [100, 100, 200, 200];
|
|
371
|
-
|
|
372
|
-
// 方式一:使用代理方法(推荐)
|
|
373
|
-
previewRef.value.jumpToPosition(1, bbox);
|
|
374
|
-
|
|
375
|
-
// 方式二:获取 PDF 预览组件引用
|
|
376
|
-
const pdfPreview = previewRef.value.getPdfPreview();
|
|
377
|
-
if (pdfPreview) {
|
|
378
|
-
pdfPreview.jumpToPosition(1, bbox);
|
|
379
|
-
}
|
|
380
|
-
};
|
|
347
|
+
// 预览文件
|
|
348
|
+
previewRef.value.preview('https://example.com/file.pdf', 'file.pdf');
|
|
381
349
|
</script>
|
|
382
350
|
```
|
|
383
351
|
|
|
352
|
+
**各子组件支持的 Props:**
|
|
353
|
+
|
|
354
|
+
- **PDF (`pdfProps`)**: `showTocSidebar`, `blocksData`(详见 [PdfPreview Props](#pdfpreview-组件))
|
|
355
|
+
- **图片 (`imageProps`)**: `minScale`, `maxScale`, `clickStep`, `wheelStep`, `originalId`(详见 [ImagePreview Props](#imagepreview-组件))
|
|
356
|
+
- **TIF (`tifProps`)**: `minScale`, `maxScale`, `clickStep`, `wheelStep`, `originalId`(详见 [TifPreview Props](#tifpreview-组件))
|
|
357
|
+
- **Word (`docxProps`)**: `docName`, `docData`, `minScale`, `maxScale`, `clickStep`, `wheelStep`(详见 [DocxPreview Props](#docxpreview-组件))
|
|
358
|
+
- **OFD (`ofdProps`)**: 无额外 props(详见 [OfdPreview Props](#ofdpreview-组件))
|
|
359
|
+
- **Excel (`xlsxProps`)**: 无额外 props(详见 [XlsxPreview Props](#xlsxpreview-组件))
|
|
360
|
+
|
|
361
|
+
**注意:** `isDownload` 会单独传递给所有子组件。如果需要在 `*Props` 中覆盖 `isDownload`,子组件会优先使用 `*Props` 中的值。
|
|
362
|
+
|
|
384
363
|
---
|
|
385
364
|
|
|
386
365
|
### PdfPreview 组件
|