@koi-br/ocr-web-sdk 1.0.15 → 1.0.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koi-br/ocr-web-sdk",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "一个支持多种Office文件格式预览的Vue3组件SDK,包括PDF、Word、Excel、图片、OFD、TIF等格式",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -4,7 +4,10 @@
4
4
  @wheel.prevent="handleWheel"
5
5
  >
6
6
  <!-- 工具栏 -->
7
- <div class="preview-toolbar preview-toolbar-right">
7
+ <div class="preview-toolbar preview-toolbar-between">
8
+ <div class="toolbar-group">
9
+ <slot name="left-top"></slot>
10
+ </div>
8
11
  <div class="toolbar-group">
9
12
  <span class="scale-text">
10
13
  {{ Math.round(scale * 100) }}%
@@ -4,6 +4,9 @@
4
4
  <div class="preview-toolbar preview-toolbar-between">
5
5
  <!-- 左侧: 翻页控制 -->
6
6
  <div class="toolbar-group">
7
+ <!-- 左上角自定义按钮插槽 -->
8
+ <slot name="left-top"></slot>
9
+
7
10
  <!-- 目录和印章列表切换按钮 -->
8
11
  <ATooltip
9
12
  v-if="props.showTocSidebar !== false"
@@ -2420,6 +2423,20 @@ onBeforeUnmount(() => {
2420
2423
 
2421
2424
  &.toc-sidebar-show {
2422
2425
  width: 180px;
2426
+
2427
+ .toc-tab-switcher {
2428
+ opacity: 1; // 展开时显示Tab切换器
2429
+ visibility: visible; // 展开时可见
2430
+ pointer-events: auto; // 展开时允许交互
2431
+ transition: opacity 0.2s ease 0.4s, visibility 0s linear 0.4s; // 延迟显示,确保宽度变化完成后再显示(0.3s宽度 + 0.1s缓冲)
2432
+ }
2433
+
2434
+ .toc-sidebar-content {
2435
+ opacity: 1; // 展开时显示内容区域
2436
+ visibility: visible; // 展开时可见
2437
+ pointer-events: auto; // 展开时允许交互
2438
+ transition: opacity 0.2s ease 0.4s, visibility 0s linear 0.4s; // 延迟显示,确保宽度变化完成后再显示(0.3s宽度 + 0.1s缓冲)
2439
+ }
2423
2440
  }
2424
2441
 
2425
2442
  .toc-tab-switcher {
@@ -2434,6 +2451,10 @@ onBeforeUnmount(() => {
2434
2451
  border: 0.5px solid rgb(0 0 0 / 8%);
2435
2452
  border: 0.5px solid var(--s-color-border-tertiary, rgb(0 0 0 / 8%));
2436
2453
  border-radius: 10px;
2454
+ opacity: 0; // 默认隐藏
2455
+ visibility: hidden; // 完全隐藏,防止在宽度变化时可见
2456
+ pointer-events: none; // 收起时禁止交互,防止内容可见
2457
+ transition: opacity 0.15s ease 0s, visibility 0s linear 0s; // 收起时立即隐藏
2437
2458
 
2438
2459
  .toc-tab-item {
2439
2460
  display: flex;
@@ -2463,6 +2484,10 @@ onBeforeUnmount(() => {
2463
2484
  flex: 1;
2464
2485
  padding: 8px 0;
2465
2486
  overflow: hidden auto;
2487
+ opacity: 0; // 默认隐藏
2488
+ visibility: hidden; // 完全隐藏,防止在宽度变化时可见
2489
+ pointer-events: none; // 收起时禁止交互,防止内容可见
2490
+ transition: opacity 0.15s ease 0s, visibility 0s linear 0s; // 收起时立即隐藏
2466
2491
 
2467
2492
  // 自定义滚动条样式
2468
2493
  &::-webkit-scrollbar {
@@ -8,7 +8,10 @@
8
8
  <p class="preview-loading-title">正在加载文档...</p>
9
9
  </div>
10
10
  <!-- 工具栏 -->
11
- <div class="preview-toolbar preview-toolbar-right" v-if="isDownload">
11
+ <div class="preview-toolbar preview-toolbar-between" v-if="isDownload || slots['left-top']">
12
+ <div class="toolbar-group">
13
+ <slot name="left-top"></slot>
14
+ </div>
12
15
  <div class="toolbar-group">
13
16
  <ATooltip
14
17
  mini
@@ -33,10 +36,12 @@
33
36
 
34
37
  <script setup>
35
38
  import { renderAsync } from 'docx-preview';
36
- import { ref, watch, onMounted, onBeforeUnmount, nextTick } from 'vue';
39
+ import { ref, watch, onMounted, nextTick, useSlots } from 'vue';
37
40
  import { Download } from 'lucide-vue-next';
38
41
  import { Button as AButton, Tooltip as ATooltip, Spin as ASpin } from '@arco-design/web-vue';
39
42
 
43
+ const slots = useSlots();
44
+
40
45
  // 定义 props
41
46
  const props = defineProps({
42
47
  // 文档 URL 地址
package/preview/index.vue CHANGED
@@ -30,7 +30,12 @@
30
30
  :is-download="props.isDownload"
31
31
  v-bind="props.pdfProps || {}"
32
32
  @download="handleDownload"
33
- />
33
+ >
34
+ <!-- 透传 left-top 插槽给 PdfPreview -->
35
+ <template #left-top>
36
+ <slot name="left-top"></slot>
37
+ </template>
38
+ </PdfPreview>
34
39
 
35
40
  <!-- 图片预览 -->
36
41
  <ImagePreview
@@ -42,7 +47,11 @@
42
47
  v-bind="props.imageProps || {}"
43
48
  @original="handleOriginal"
44
49
  @download="handleDownload"
45
- />
50
+ >
51
+ <template #left-top>
52
+ <slot name="left-top"></slot>
53
+ </template>
54
+ </ImagePreview>
46
55
 
47
56
  <!-- ttf预览 -->
48
57
  <TifPreview
@@ -52,7 +61,11 @@
52
61
  :is-download="props.isDownload"
53
62
  v-bind="props.tifProps || {}"
54
63
  @download="handleDownload"
55
- />
64
+ >
65
+ <template #left-top>
66
+ <slot name="left-top"></slot>
67
+ </template>
68
+ </TifPreview>
56
69
 
57
70
  <!-- docx预览 -->
58
71
  <DocxPreview
@@ -62,7 +75,11 @@
62
75
  :is-download="props.isDownload"
63
76
  v-bind="props.docxProps || {}"
64
77
  @download="handleDownload"
65
- />
78
+ >
79
+ <template #left-top>
80
+ <slot name="left-top"></slot>
81
+ </template>
82
+ </DocxPreview>
66
83
 
67
84
  <!-- OFD预览 -->
68
85
  <OfdPreview
@@ -72,7 +89,8 @@
72
89
  :is-download="props.isDownload"
73
90
  v-bind="props.ofdProps || {}"
74
91
  @download="handleDownload"
75
- />
92
+ >
93
+ </OfdPreview>
76
94
 
77
95
  <!-- xlsx预览 -->
78
96
  <XLSXPreview
@@ -82,7 +100,11 @@
82
100
  :is-download="props.isDownload"
83
101
  v-bind="props.xlsxProps || {}"
84
102
  @download="handleDownload"
85
- />
103
+ >
104
+ <template #left-top>
105
+ <slot name="left-top"></slot>
106
+ </template>
107
+ </XLSXPreview>
86
108
 
87
109
  <!-- 不支持的文件类型 -->
88
110
  <div v-else class="preview-empty-container">
@@ -1,6 +1,5 @@
1
1
  <template>
2
2
  <div class="preview-container">
3
- <!-- 工具栏 -->
4
3
  <OfdView
5
4
  :show-open-file-button="false"
6
5
  :ofd-link="props.url"
@@ -14,12 +13,17 @@
14
13
  import { ref, watch, onMounted } from 'vue';
15
14
  import { OfdView } from 'bestofdview';
16
15
  import 'bestofdview/dist/style.css';
17
- import { Message } from '@arco-design/web-vue';
16
+ import { Message, Button as AButton, Tooltip as ATooltip } from '@arco-design/web-vue';
17
+ import { Download } from 'lucide-vue-next';
18
18
 
19
19
  const props = defineProps({
20
20
  url: {
21
21
  type: String,
22
22
  required: true
23
+ },
24
+ isDownload: {
25
+ type: Boolean,
26
+ default: false
23
27
  }
24
28
  });
25
29
 
@@ -80,3 +84,6 @@ defineExpose({
80
84
  });
81
85
  </script>
82
86
 
87
+ <style lang="less" scoped>
88
+ // 样式已统一到公共样式文件,这里只保留组件特定样式
89
+ </style>
@@ -8,7 +8,12 @@
8
8
  </div>
9
9
  <div v-else class="img-container">
10
10
  <!-- 工具栏 -->
11
- <div class="preview-toolbar preview-toolbar-right">
11
+ <div class="preview-toolbar preview-toolbar-between">
12
+ <!-- 左侧: 自定义按钮插槽 -->
13
+ <div class="toolbar-group">
14
+ <slot name="left-top"></slot>
15
+ </div>
16
+ <!-- 右侧: 缩放和控制按钮 -->
12
17
  <div class="toolbar-group">
13
18
  <span class="scale-text">
14
19
  {{ Math.round(scale * 100) }}%
@@ -1,168 +1,171 @@
1
- <template>
2
- <div class="preview-container">
3
- <!-- 工具栏 -->
4
- <div class="preview-toolbar preview-toolbar-right">
5
- <div class="toolbar-group">
6
- <span class="scale-text">
7
- {{ Math.round(scale * 100) }}%
8
- </span>
9
- <div class="toolbar-divider"></div>
10
- <ATooltip mini position="bottom" content="重置">
11
- <AButton
12
- size="small"
13
- type="outline"
14
- @click="reset"
15
- >
16
- <RefreshCcw :size="16" />
17
- </AButton>
18
- </ATooltip>
19
- <ATooltip mini position="bottom" content="缩小">
20
- <AButton
21
- size="small"
22
- type="outline"
23
- :disabled="scale <= 0.5"
24
- @click="zoom(-0.1)"
25
- >
26
- <ZoomOut :size="16" />
27
- </AButton>
28
- </ATooltip>
29
- <ATooltip mini position="bottom" content="放大">
30
- <AButton
31
- size="small"
32
- type="outline"
33
- :disabled="scale >= 2"
34
- @click="zoom(0.1)"
35
- >
36
- <ZoomIn :size="16" />
37
- </AButton>
38
- </ATooltip>
39
- <ATooltip
40
- v-if="isDownload"
41
- mini
42
- position="bottom"
43
- content="下载"
44
- >
45
- <AButton
46
- size="small"
47
- type="outline"
48
- @click="emit('download')"
49
- >
50
- <Download :size="16" />
51
- </AButton>
52
- </ATooltip>
53
- </div>
54
- </div>
55
- <div
56
- class="excel-wrapper"
57
- :style="{ transform: `scale(${scale})`, transformOrigin: 'top left' }"
58
- >
59
- <VueOfficeExcel
60
- v-if="excel"
61
- :src="excel"
62
- style="width: 100%; height: 75vh"
63
- @rendered="onRendered"
64
- @error="onError"
65
- />
66
- </div>
67
- </div>
68
- </template>
69
-
70
- <script setup>
71
- import { ref, watch } from 'vue';
72
- import { Message, Button as AButton, Tooltip as ATooltip } from '@arco-design/web-vue';
73
- import { ZoomIn, ZoomOut, RefreshCcw, Download } from 'lucide-vue-next';
74
- import VueOfficeExcel from '@vue-office/excel/lib/v3/index';
75
- import '@vue-office/excel/lib/v3/index.css';
76
-
77
- const props = defineProps({
78
- url: {
79
- type: String,
80
- required: true
81
- },
82
- isDownload: {
83
- type: Boolean,
84
- default: false
85
- }
86
- });
87
-
88
- const emit = defineEmits(['download']);
89
-
90
- const excel = ref('');
91
- const loading = ref(false);
92
- const scale = ref(1);
93
-
94
- // 缩放方法
95
- const zoom = delta => {
96
- const newScale = scale.value + delta;
97
- if (newScale >= 0.5 && newScale <= 2) {
98
- scale.value = newScale;
99
- }
100
- };
101
-
102
- // 重置方法
103
- const reset = () => {
104
- scale.value = 1;
105
- };
106
-
107
- // 放大
108
- const zoomIn = () => {
109
- zoom(0.1);
110
- };
111
-
112
- // 缩小
113
- const zoomOut = () => {
114
- zoom(-0.1);
115
- };
116
-
117
- // 重置缩放
118
- const resetZoom = () => {
119
- reset();
120
- };
121
-
122
- // 文件加载成功
123
- const onRendered = () => {
124
- loading.value = false;
125
- };
126
-
127
- // 文件加载失败
128
- const onError = error => {
129
- loading.value = false;
130
- Message.error('Excel文件加载失败');
131
- console.error('Excel文件加载失败:', error);
132
- };
133
-
134
- // 监听URL变化
135
- watch(
136
- () => props.url,
137
- newUrl => {
138
- if (newUrl) {
139
- loading.value = true;
140
- excel.value = newUrl;
141
- }
142
- },
143
- { immediate: true }
144
- );
145
-
146
- // 清理函数
147
- const cleanup = () => {
148
- loading.value = false;
149
- excel.value = '';
150
- scale.value = 1;
151
- };
152
-
153
- // 暴露清理方法给父组件
154
- defineExpose({
155
- cleanup
156
- });
157
- </script>
158
-
159
- <style lang="less" scoped>
160
- // 样式已统一到公共样式文件,这里只保留组件特定样式
161
- .excel-wrapper {
162
- flex: 1;
163
- display: inline-block;
164
- min-width: 100%;
165
- overflow: auto;
166
- transition: transform 0.2s ease;
167
- }
168
- </style>
1
+ <template>
2
+ <div class="preview-container">
3
+ <!-- 工具栏 -->
4
+ <div class="preview-toolbar preview-toolbar-between">
5
+ <div class="toolbar-group">
6
+ <slot name="left-top"></slot>
7
+ </div>
8
+ <div class="toolbar-group">
9
+ <span class="scale-text">
10
+ {{ Math.round(scale * 100) }}%
11
+ </span>
12
+ <div class="toolbar-divider"></div>
13
+ <ATooltip mini position="bottom" content="重置">
14
+ <AButton
15
+ size="small"
16
+ type="outline"
17
+ @click="reset"
18
+ >
19
+ <RefreshCcw :size="16" />
20
+ </AButton>
21
+ </ATooltip>
22
+ <ATooltip mini position="bottom" content="缩小">
23
+ <AButton
24
+ size="small"
25
+ type="outline"
26
+ :disabled="scale <= 0.5"
27
+ @click="zoom(-0.1)"
28
+ >
29
+ <ZoomOut :size="16" />
30
+ </AButton>
31
+ </ATooltip>
32
+ <ATooltip mini position="bottom" content="放大">
33
+ <AButton
34
+ size="small"
35
+ type="outline"
36
+ :disabled="scale >= 2"
37
+ @click="zoom(0.1)"
38
+ >
39
+ <ZoomIn :size="16" />
40
+ </AButton>
41
+ </ATooltip>
42
+ <ATooltip
43
+ v-if="isDownload"
44
+ mini
45
+ position="bottom"
46
+ content="下载"
47
+ >
48
+ <AButton
49
+ size="small"
50
+ type="outline"
51
+ @click="emit('download')"
52
+ >
53
+ <Download :size="16" />
54
+ </AButton>
55
+ </ATooltip>
56
+ </div>
57
+ </div>
58
+ <div
59
+ class="excel-wrapper"
60
+ :style="{ transform: `scale(${scale})`, transformOrigin: 'top left' }"
61
+ >
62
+ <VueOfficeExcel
63
+ v-if="excel"
64
+ :src="excel"
65
+ style="width: 100%; height: 75vh"
66
+ @rendered="onRendered"
67
+ @error="onError"
68
+ />
69
+ </div>
70
+ </div>
71
+ </template>
72
+
73
+ <script setup>
74
+ import { ref, watch } from 'vue';
75
+ import { Message, Button as AButton, Tooltip as ATooltip } from '@arco-design/web-vue';
76
+ import { ZoomIn, ZoomOut, RefreshCcw, Download } from 'lucide-vue-next';
77
+ import VueOfficeExcel from '@vue-office/excel/lib/v3/index';
78
+ import '@vue-office/excel/lib/v3/index.css';
79
+
80
+ const props = defineProps({
81
+ url: {
82
+ type: String,
83
+ required: true
84
+ },
85
+ isDownload: {
86
+ type: Boolean,
87
+ default: false
88
+ }
89
+ });
90
+
91
+ const emit = defineEmits(['download']);
92
+
93
+ const excel = ref('');
94
+ const loading = ref(false);
95
+ const scale = ref(1);
96
+
97
+ // 缩放方法
98
+ const zoom = delta => {
99
+ const newScale = scale.value + delta;
100
+ if (newScale >= 0.5 && newScale <= 2) {
101
+ scale.value = newScale;
102
+ }
103
+ };
104
+
105
+ // 重置方法
106
+ const reset = () => {
107
+ scale.value = 1;
108
+ };
109
+
110
+ // 放大
111
+ const zoomIn = () => {
112
+ zoom(0.1);
113
+ };
114
+
115
+ // 缩小
116
+ const zoomOut = () => {
117
+ zoom(-0.1);
118
+ };
119
+
120
+ // 重置缩放
121
+ const resetZoom = () => {
122
+ reset();
123
+ };
124
+
125
+ // 文件加载成功
126
+ const onRendered = () => {
127
+ loading.value = false;
128
+ };
129
+
130
+ // 文件加载失败
131
+ const onError = error => {
132
+ loading.value = false;
133
+ Message.error('Excel文件加载失败');
134
+ console.error('Excel文件加载失败:', error);
135
+ };
136
+
137
+ // 监听URL变化
138
+ watch(
139
+ () => props.url,
140
+ newUrl => {
141
+ if (newUrl) {
142
+ loading.value = true;
143
+ excel.value = newUrl;
144
+ }
145
+ },
146
+ { immediate: true }
147
+ );
148
+
149
+ // 清理函数
150
+ const cleanup = () => {
151
+ loading.value = false;
152
+ excel.value = '';
153
+ scale.value = 1;
154
+ };
155
+
156
+ // 暴露清理方法给父组件
157
+ defineExpose({
158
+ cleanup
159
+ });
160
+ </script>
161
+
162
+ <style lang="less" scoped>
163
+ // 样式已统一到公共样式文件,这里只保留组件特定样式
164
+ .excel-wrapper {
165
+ flex: 1;
166
+ display: inline-block;
167
+ min-width: 100%;
168
+ overflow: auto;
169
+ transition: transform 0.2s ease;
170
+ }
171
+ </style>