@koi-br/ocr-web-sdk 1.0.25 → 1.0.27

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/preview/index.vue CHANGED
@@ -42,13 +42,17 @@
42
42
  <ImagePreview
43
43
  v-else-if="fileType === 'image'"
44
44
  ref="imagePreviewRef"
45
- :url="fileUrl"
45
+ :url="imagePreviewUrl"
46
46
  :original-id="originalId"
47
47
  :is-download="props.isDownload"
48
48
  v-bind="props.imageProps || {}"
49
49
  @original="handleOriginal"
50
50
  @download="handleDownload"
51
51
  @load="handleFileLoaded"
52
+ @page-change="handleImagePageChange"
53
+ @annotation-add="handleAnnotationAdd"
54
+ @annotation-update="handleAnnotationUpdate"
55
+ @annotation-delete="handleAnnotationDelete"
52
56
  >
53
57
  <template #left-top>
54
58
  <slot name="left-top"></slot>
@@ -127,7 +131,7 @@
127
131
  </template>
128
132
 
129
133
  <script setup>
130
- import { ref, onBeforeUnmount } from 'vue';
134
+ import { ref, onBeforeUnmount, computed, watch } from 'vue';
131
135
  import { Message, Button as AButton } from '@arco-design/web-vue';
132
136
  import ImagePreview from './ImagePreview.vue';
133
137
  import PdfPreview from './PdfPreview.vue';
@@ -137,7 +141,7 @@ import DocxPreview from './docxPreview.vue';
137
141
  import XLSXPreview from './xlsxPreview.vue';
138
142
 
139
143
  // 定义 emits
140
- const emit = defineEmits(['load']);
144
+ const emit = defineEmits(['load', 'annotation-add', 'annotation-update', 'annotation-delete']);
141
145
 
142
146
  // 定义 props
143
147
  const props = defineProps({
@@ -193,6 +197,35 @@ const xlsxPreviewRef = ref(null);
193
197
 
194
198
  const originalId = ref('');
195
199
 
200
+ // 计算图片预览的URL(支持单个URL或URL数组)
201
+ const imagePreviewUrl = computed(() => {
202
+ // 如果imageProps中指定了url或urls,优先使用
203
+ if (props.imageProps) {
204
+ if (Array.isArray(props.imageProps.urls)) {
205
+ return props.imageProps.urls;
206
+ }
207
+ if (typeof props.imageProps.url === 'string' || Array.isArray(props.imageProps.url)) {
208
+ return props.imageProps.url;
209
+ }
210
+ }
211
+ // 否则使用fileUrl(向后兼容)
212
+ return fileUrl.value;
213
+ });
214
+
215
+ // 监听 imageProps 的变化,自动设置 fileType
216
+ watch(
217
+ () => props.imageProps?.url || props.imageProps?.urls,
218
+ (newUrl) => {
219
+ if (newUrl) {
220
+ // 如果传入了图片URL,自动设置fileType为image
221
+ if (fileType.value !== 'image') {
222
+ fileType.value = 'image';
223
+ }
224
+ }
225
+ },
226
+ { immediate: true }
227
+ );
228
+
196
229
  // 添加 AbortController 的引用
197
230
  const abortController = ref(null);
198
231
 
@@ -394,6 +427,27 @@ const handleFileLoaded = (data) => {
394
427
  emit('load', fileInfo);
395
428
  };
396
429
 
430
+ // 处理图片页码变化事件
431
+ const handleImagePageChange = (page, totalPages) => {
432
+ // 可以在这里处理页码变化,例如更新文件名显示等
433
+ console.log(`图片页码变化: ${page}/${totalPages}`);
434
+ };
435
+
436
+ // 处理批注添加事件
437
+ const handleAnnotationAdd = (annotation) => {
438
+ emit('annotation-add', annotation);
439
+ };
440
+
441
+ // 处理批注更新事件
442
+ const handleAnnotationUpdate = (annotation) => {
443
+ emit('annotation-update', annotation);
444
+ };
445
+
446
+ // 处理批注删除事件
447
+ const handleAnnotationDelete = (annotationId) => {
448
+ emit('annotation-delete', annotationId);
449
+ };
450
+
397
451
  // 获取当前活动的预览组件引用
398
452
  const getCurrentPreviewRef = () => {
399
453
  switch (fileType.value) {