@koi-br/ocr-web-sdk 1.0.9 → 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 CHANGED
@@ -81,7 +81,19 @@ pnpm add @koi-br/ocr-web-sdk
81
81
  ```vue
82
82
  <template>
83
83
  <div>
84
- <FilePreview ref="previewRef" :is-download="true" />
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,6 +302,64 @@ previewRef.value.preview(url, 'file.pdf', {
281
302
  previewRef.value.clearPreview();
282
303
  ```
283
304
 
305
+ #### 向子组件传递 Props
306
+
307
+ `FilePreview` 支持通过 `*Props` 属性向对应的子组件传递配置。例如,向 PDF 预览组件传递 `blocksData` 和 `showTocSidebar`:
308
+
309
+ **示例:**
310
+ ```vue
311
+ <template>
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
+ />
331
+ </template>
332
+
333
+ <script setup>
334
+ import { ref } from 'vue';
335
+ import { FilePreview } from '@koi-br/ocr-web-sdk';
336
+
337
+ const previewRef = ref(null);
338
+ const pdfBlocksData = ref([
339
+ {
340
+ blockLabel: '标题',
341
+ blockContent: '第一章',
342
+ blockBbox: [100, 100, 200, 150],
343
+ blockPage: 1
344
+ }
345
+ ]);
346
+
347
+ // 预览文件
348
+ previewRef.value.preview('https://example.com/file.pdf', 'file.pdf');
349
+ </script>
350
+ ```
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
+
284
363
  ---
285
364
 
286
365
  ### PdfPreview 组件
@@ -321,8 +400,6 @@ interface BlockInfo {
321
400
  |--------|------|--------|------|
322
401
  | `goToPage` | `pageNum: number` | - | 跳转到指定页码(从1开始) |
323
402
  | `jumpToPosition` | `pageNum: number, bbox: [number, number, number, number], emitEvent?: boolean` | - | 跳转到指定位置并高亮(统一接口,**自动识别类型**,无需传入类型参数) |
324
- | `jumpToBlockPosition` | `pageNum: number, bbox: [number, number, number, number], emitEvent?: boolean` | - | 跳转到指定文本块位置并高亮(向后兼容的别名,内部调用统一接口) |
325
- | `jumpToSealPosition` | `pageNum: number, bbox: [number, number, number, number], emitEvent?: boolean` | - | 跳转到指定印章位置并高亮(向后兼容的别名,内部调用统一接口) |
326
403
  | `getCurrentPage` | - | `number` | 获取当前页码 |
327
404
  | `getTotalPages` | - | `number` | 获取总页数 |
328
405
  | `reset` | - | - | 重置预览状态 |
@@ -721,10 +798,6 @@ const handleFileChange = (event) => {
721
798
  ```javascript
722
799
  // 自动识别类型(推荐)
723
800
  pdfRef.value?.jumpToPosition(pageNum, bbox);
724
-
725
- // 向后兼容的别名方法
726
- pdfRef.value?.jumpToBlockPosition(pageNum, bbox);
727
- pdfRef.value?.jumpToSealPosition(pageNum, bbox);
728
801
  ```
729
802
 
730
803
  ### 6. 资源清理