@ebiz/designer-components 0.1.36 → 0.1.37

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": "@ebiz/designer-components",
3
- "version": "0.1.36",
3
+ "version": "0.1.37",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -19,6 +19,7 @@
19
19
  "dependencies": {
20
20
  "axios": "^1.8.1",
21
21
  "echarts": "^5.6.0",
22
+ "pdfjs-dist": "^3.11.174",
22
23
  "vxe-table": "^4.13.31",
23
24
  "tdesign-vue-next": "^1.12.0",
24
25
  "unplugin-auto-import": "^19.0.0",
@@ -385,7 +385,7 @@ const fetchOrganizationData = async () => {
385
385
  }, "/process/deptList"
386
386
  );
387
387
  organizationData.value = response;
388
- handleActive(response[0].id, 'organization')
388
+ handleActive(null, 'organization')
389
389
  // organizationData.value = processOrgData(response.data || []);
390
390
  } catch (error) {
391
391
  MessagePlugin.error({
@@ -589,6 +589,7 @@ const fetchEmployeesByIds = async (ids) => {
589
589
 
590
590
  // 处理节点激活
591
591
  const handleActive = (value, context) => {
592
+ console.log("value", value)
592
593
  currentActive.value = [value];
593
594
  currentNodeName.value = context.node?.label || '';
594
595
 
@@ -604,14 +605,26 @@ const selectDepartment = (department) => {
604
605
 
605
606
  // 处理全选
606
607
  const handleSelectAll = (checked) => {
607
- employeeList.value.forEach(item => {
608
+ if (!checked) {
609
+ // 移除当前页的选择
610
+ employeeList.value.forEach(item => {
611
+ console.log("item", item, (tempSelectedEmployees.value.indexOf(item.id) !== -1))
612
+ if (tempSelectedEmployeeIds.value.indexOf(item.id) !== -1) {
613
+ tempSelectedEmployeeIds.value.splice(tempSelectedEmployeeIds.value.indexOf(item.id), 1);
614
+ }
615
+ });
616
+ handleCheckChange()
617
+ } else {
618
+ employeeList.value.forEach(item => {
619
+
620
+ // 如果选中,确保添加到临时选中列表
621
+ if (!tempSelectedEmployees.value.some(emp => emp.id === item.id)) {
622
+ tempSelectedEmployees.value.push(item);
623
+ tempSelectedEmployeeIds.value.push(item.id);
624
+ }
625
+ });
626
+ }
608
627
 
609
- // 如果选中,确保添加到临时选中列表
610
- if (!tempSelectedEmployees.value.some(emp => emp.id === item.id)) {
611
- tempSelectedEmployees.value.push(item);
612
- tempSelectedEmployeeIds.value.push(item.id);
613
- }
614
- });
615
628
  };
616
629
 
617
630
  // 处理选中状态变更
@@ -0,0 +1,541 @@
1
+ <template>
2
+ <div class="ebiz-pdf-viewer" :style="{ width: width, height: height }">
3
+ <!-- 工具栏 -->
4
+ <div v-if="showToolbar" class="pdf-toolbar">
5
+ <div class="toolbar-left">
6
+ <button
7
+ @click="previousPage"
8
+ :disabled="currentPage <= 1"
9
+ class="toolbar-btn"
10
+ title="上一页"
11
+ >
12
+
13
+ </button>
14
+ <span class="page-info">
15
+ {{ currentPage }} / {{ totalPages }}
16
+ </span>
17
+ <button
18
+ @click="nextPage"
19
+ :disabled="currentPage >= totalPages"
20
+ class="toolbar-btn"
21
+ title="下一页"
22
+ >
23
+
24
+ </button>
25
+ </div>
26
+ <div class="toolbar-center">
27
+ <button @click="zoomOut" class="toolbar-btn" title="缩小">-</button>
28
+ <span class="zoom-info">{{ Math.round(scale * 100) }}%</span>
29
+ <button @click="zoomIn" class="toolbar-btn" title="放大">+</button>
30
+ <button @click="resetZoom" class="toolbar-btn" title="重置缩放">⟲</button>
31
+ </div>
32
+ <div class="toolbar-right">
33
+ <button @click="rotatePage" class="toolbar-btn" title="旋转">↻</button>
34
+ <button @click="downloadPdf" class="toolbar-btn" title="下载">⬇</button>
35
+ </div>
36
+ </div>
37
+
38
+ <!-- PDF 内容区域 -->
39
+ <div class="pdf-container" ref="containerRef">
40
+ <div v-if="loading" class="pdf-loading">
41
+ <div class="loading-spinner"></div>
42
+ <span>加载中...</span>
43
+ </div>
44
+ <div v-else-if="error" class="pdf-error">
45
+ <span>{{ error }}</span>
46
+ </div>
47
+ <div v-else class="pdf-content">
48
+ <canvas
49
+ ref="canvasRef"
50
+ :style="{
51
+ transform: `rotate(${rotation}deg)`,
52
+ transformOrigin: 'center center'
53
+ }"
54
+ ></canvas>
55
+ </div>
56
+ </div>
57
+ </div>
58
+ </template>
59
+
60
+ <script>
61
+ export default {
62
+ name: "EbizPdfViewer"
63
+ }
64
+ </script>
65
+
66
+ <script setup>
67
+ import { ref, onMounted, onUnmounted, watch, nextTick } from 'vue';
68
+
69
+ const props = defineProps({
70
+ // PDF文件URL或base64数据
71
+ src: {
72
+ type: String,
73
+ required: true
74
+ },
75
+ // 组件宽度
76
+ width: {
77
+ type: String,
78
+ default: '100%'
79
+ },
80
+ // 组件高度
81
+ height: {
82
+ type: String,
83
+ default: '600px'
84
+ },
85
+ // 是否显示工具栏
86
+ showToolbar: {
87
+ type: Boolean,
88
+ default: true
89
+ },
90
+ // 初始页码
91
+ page: {
92
+ type: Number,
93
+ default: 1
94
+ },
95
+ // 初始缩放比例
96
+ zoom: {
97
+ type: Number,
98
+ default: 1
99
+ },
100
+ // 是否允许下载
101
+ downloadable: {
102
+ type: Boolean,
103
+ default: true
104
+ },
105
+ // PDF密码
106
+ password: {
107
+ type: String,
108
+ default: ''
109
+ }
110
+ });
111
+
112
+ const emit = defineEmits([
113
+ 'load',
114
+ 'error',
115
+ 'page-change',
116
+ 'zoom-change',
117
+ 'download'
118
+ ]);
119
+
120
+ // 响应式状态
121
+ const loading = ref(false);
122
+ const error = ref('');
123
+ const currentPage = ref(props.page);
124
+ const totalPages = ref(0);
125
+ const scale = ref(props.zoom);
126
+ const rotation = ref(0);
127
+
128
+ // DOM引用
129
+ const containerRef = ref(null);
130
+ const canvasRef = ref(null);
131
+
132
+ // PDF相关变量
133
+ let pdfDoc = null;
134
+ let pdfLib = null;
135
+ let renderRetryCount = 0;
136
+ const MAX_RETRY_COUNT = 3;
137
+ let resizeObserver = null;
138
+
139
+ // 初始化PDF.js
140
+ const initPdfJs = async () => {
141
+ try {
142
+ // 动态导入pdfjs-dist
143
+ pdfLib = await import('pdfjs-dist');
144
+
145
+ // 设置worker路径
146
+ pdfLib.GlobalWorkerOptions.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js`;
147
+
148
+ return true;
149
+ } catch (err) {
150
+ console.error('Failed to initialize PDF.js:', err);
151
+ error.value = '初始化PDF.js失败';
152
+ return false;
153
+ }
154
+ };
155
+
156
+ // 加载PDF文档
157
+ const loadPdf = async () => {
158
+ if (!props.src) return;
159
+
160
+ loading.value = true;
161
+ error.value = '';
162
+
163
+ try {
164
+ if (!pdfLib) {
165
+ const success = await initPdfJs();
166
+ if (!success) return;
167
+ }
168
+
169
+ const loadingTask = pdfLib.getDocument({
170
+ url: props.src,
171
+ password: props.password
172
+ });
173
+
174
+ pdfDoc = await loadingTask.promise;
175
+ totalPages.value = pdfDoc.numPages;
176
+
177
+ // 确保当前页在有效范围内
178
+ if (currentPage.value > totalPages.value) {
179
+ currentPage.value = totalPages.value;
180
+ }
181
+ if (currentPage.value < 1) {
182
+ currentPage.value = 1;
183
+ }
184
+
185
+ // 延迟渲染确保DOM完全准备
186
+ await nextTick();
187
+ setTimeout(async () => {
188
+ await renderPage();
189
+ }, 50);
190
+
191
+ emit('load', {
192
+ totalPages: totalPages.value,
193
+ currentPage: currentPage.value
194
+ });
195
+
196
+ } catch (err) {
197
+ console.error('PDF loading error:', err);
198
+ error.value = err.message || 'PDF加载失败';
199
+ emit('error', err);
200
+ } finally {
201
+ loading.value = false;
202
+ }
203
+ };
204
+
205
+ // 渲染当前页面
206
+ const renderPage = async () => {
207
+ if (!pdfDoc || !canvasRef.value) return;
208
+
209
+ try {
210
+ // 确保canvas元素已经完全渲染到DOM中
211
+ await nextTick();
212
+
213
+ const page = await pdfDoc.getPage(currentPage.value);
214
+ const canvas = canvasRef.value;
215
+
216
+ // 再次检查canvas是否存在
217
+ if (!canvas) {
218
+ if (renderRetryCount < MAX_RETRY_COUNT) {
219
+ renderRetryCount++;
220
+ console.warn(`Canvas element not found, retrying... (${renderRetryCount}/${MAX_RETRY_COUNT})`);
221
+ setTimeout(renderPage, 100);
222
+ return;
223
+ } else {
224
+ console.error('Canvas element not found after multiple retries');
225
+ error.value = 'Canvas元素未找到';
226
+ return;
227
+ }
228
+ }
229
+
230
+ // 重置重试计数
231
+ renderRetryCount = 0;
232
+
233
+ const context = canvas.getContext('2d');
234
+
235
+ // 获取页面尺寸
236
+ const viewport = page.getViewport({ scale: scale.value });
237
+
238
+ // 获取容器可用宽度
239
+ const containerWidth = containerRef.value?.clientWidth || 800;
240
+ const maxWidth = containerWidth - 40; // 减去padding
241
+
242
+ // 如果PDF宽度超过容器宽度,自动缩放
243
+ let finalScale = scale.value;
244
+ if (viewport.width > maxWidth) {
245
+ finalScale = (maxWidth / viewport.width) * scale.value;
246
+ const adjustedViewport = page.getViewport({ scale: finalScale });
247
+ canvas.height = adjustedViewport.height;
248
+ canvas.width = adjustedViewport.width;
249
+ } else {
250
+ canvas.height = viewport.height;
251
+ canvas.width = viewport.width;
252
+ }
253
+
254
+ // 清空canvas
255
+ context.clearRect(0, 0, canvas.width, canvas.height);
256
+
257
+ // 渲染页面 - 使用最终的viewport
258
+ const finalViewport = finalScale !== scale.value ?
259
+ page.getViewport({ scale: finalScale }) : viewport;
260
+
261
+ const renderContext = {
262
+ canvasContext: context,
263
+ viewport: finalViewport
264
+ };
265
+
266
+ await page.render(renderContext).promise;
267
+
268
+ } catch (err) {
269
+ console.error('Page rendering error:', err);
270
+ error.value = '页面渲染失败';
271
+ }
272
+ };
273
+
274
+ // 翻页方法
275
+ const previousPage = () => {
276
+ if (currentPage.value > 1) {
277
+ currentPage.value--;
278
+ renderPage();
279
+ emit('page-change', currentPage.value);
280
+ }
281
+ };
282
+
283
+ const nextPage = () => {
284
+ if (currentPage.value < totalPages.value) {
285
+ currentPage.value++;
286
+ renderPage();
287
+ emit('page-change', currentPage.value);
288
+ }
289
+ };
290
+
291
+ // 缩放方法
292
+ const zoomIn = () => {
293
+ scale.value = Math.min(scale.value * 1.2, 3);
294
+ renderPage();
295
+ emit('zoom-change', scale.value);
296
+ };
297
+
298
+ const zoomOut = () => {
299
+ scale.value = Math.max(scale.value / 1.2, 0.1);
300
+ renderPage();
301
+ emit('zoom-change', scale.value);
302
+ };
303
+
304
+ const resetZoom = () => {
305
+ scale.value = 1;
306
+ renderPage();
307
+ emit('zoom-change', scale.value);
308
+ };
309
+
310
+ // 旋转页面
311
+ const rotatePage = () => {
312
+ rotation.value = (rotation.value + 90) % 360;
313
+ };
314
+
315
+ // 下载PDF
316
+ const downloadPdf = () => {
317
+ if (!props.downloadable) return;
318
+
319
+ try {
320
+ const link = document.createElement('a');
321
+ link.href = props.src;
322
+ link.download = 'document.pdf';
323
+ document.body.appendChild(link);
324
+ link.click();
325
+ document.body.removeChild(link);
326
+
327
+ emit('download', props.src);
328
+ } catch (err) {
329
+ console.error('Download error:', err);
330
+ }
331
+ };
332
+
333
+ // 监听属性变化
334
+ watch(() => props.src, () => {
335
+ loadPdf();
336
+ });
337
+
338
+ watch(() => props.page, (newPage) => {
339
+ if (newPage !== currentPage.value && newPage >= 1 && newPage <= totalPages.value) {
340
+ currentPage.value = newPage;
341
+ renderPage();
342
+ }
343
+ });
344
+
345
+ watch(() => props.zoom, (newZoom) => {
346
+ if (newZoom !== scale.value) {
347
+ scale.value = newZoom;
348
+ renderPage();
349
+ }
350
+ });
351
+
352
+ // 强制刷新渲染
353
+ const forceRender = async () => {
354
+ if (pdfDoc && canvasRef.value) {
355
+ await nextTick();
356
+ await renderPage();
357
+ }
358
+ };
359
+
360
+ // 组件挂载时加载PDF
361
+ onMounted(() => {
362
+ nextTick(() => {
363
+ loadPdf();
364
+
365
+ // 监听容器大小变化
366
+ if (containerRef.value && window.ResizeObserver) {
367
+ resizeObserver = new ResizeObserver(() => {
368
+ if (pdfDoc && canvasRef.value) {
369
+ // 延迟渲染以避免频繁触发
370
+ setTimeout(() => {
371
+ renderPage();
372
+ }, 100);
373
+ }
374
+ });
375
+ resizeObserver.observe(containerRef.value);
376
+ }
377
+ });
378
+ });
379
+
380
+ // 组件卸载时清理
381
+ onUnmounted(() => {
382
+ if (resizeObserver) {
383
+ resizeObserver.disconnect();
384
+ resizeObserver = null;
385
+ }
386
+ });
387
+
388
+ // 暴露强制刷新方法
389
+ defineExpose({
390
+ forceRender
391
+ });
392
+ </script>
393
+
394
+ <style lang="less" scoped>
395
+ .ebiz-pdf-viewer {
396
+ display: flex;
397
+ flex-direction: column;
398
+ border: 1px solid #e1e1e1;
399
+ border-radius: 4px;
400
+ overflow: hidden;
401
+ background: #f5f5f5;
402
+ }
403
+
404
+ .pdf-toolbar {
405
+ display: flex;
406
+ justify-content: space-between;
407
+ align-items: center;
408
+ padding: 8px 12px;
409
+ background: #fff;
410
+ border-bottom: 1px solid #e1e1e1;
411
+
412
+ .toolbar-left,
413
+ .toolbar-center,
414
+ .toolbar-right {
415
+ display: flex;
416
+ align-items: center;
417
+ gap: 8px;
418
+ }
419
+
420
+ .toolbar-btn {
421
+ padding: 4px 8px;
422
+ border: 1px solid #d1d1d1;
423
+ background: #fff;
424
+ border-radius: 2px;
425
+ cursor: pointer;
426
+ font-size: 12px;
427
+
428
+ &:hover:not(:disabled) {
429
+ background: #f0f0f0;
430
+ }
431
+
432
+ &:disabled {
433
+ opacity: 0.5;
434
+ cursor: not-allowed;
435
+ }
436
+ }
437
+
438
+ .page-info,
439
+ .zoom-info {
440
+ font-size: 12px;
441
+ color: #666;
442
+ min-width: 60px;
443
+ text-align: center;
444
+ }
445
+ }
446
+
447
+ .pdf-container {
448
+ flex: 1;
449
+ display: flex;
450
+ justify-content: center;
451
+ align-items: flex-start;
452
+ overflow: auto;
453
+ padding: 10px;
454
+ box-sizing: border-box;
455
+ }
456
+
457
+ .pdf-loading {
458
+ display: flex;
459
+ flex-direction: column;
460
+ align-items: center;
461
+ justify-content: center;
462
+ gap: 12px;
463
+ color: #666;
464
+ min-height: 200px;
465
+ width: 100%;
466
+
467
+ .loading-spinner {
468
+ width: 24px;
469
+ height: 24px;
470
+ border: 2px solid #f3f3f3;
471
+ border-top: 2px solid #0052d9;
472
+ border-radius: 50%;
473
+ animation: spin 1s linear infinite;
474
+ }
475
+ }
476
+
477
+ .pdf-error {
478
+ color: #e34d59;
479
+ text-align: center;
480
+ padding: 20px;
481
+ min-height: 200px;
482
+ width: 100%;
483
+ display: flex;
484
+ align-items: center;
485
+ justify-content: center;
486
+ }
487
+
488
+ .pdf-content {
489
+ display: flex;
490
+ justify-content: center;
491
+ align-items: flex-start;
492
+ min-height: 100%;
493
+ width: 100%;
494
+ padding-top: 10px;
495
+
496
+ canvas {
497
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
498
+ background: white;
499
+ transition: transform 0.3s ease;
500
+ display: block;
501
+ max-width: calc(100% - 20px);
502
+ height: auto;
503
+ margin: 0 auto;
504
+ }
505
+ }
506
+
507
+ @keyframes spin {
508
+ 0% { transform: rotate(0deg); }
509
+ 100% { transform: rotate(360deg); }
510
+ }
511
+
512
+ /* 响应式适配 */
513
+ @media (max-width: 768px) {
514
+ .pdf-container {
515
+ padding: 5px;
516
+ }
517
+
518
+ .pdf-content {
519
+ padding-top: 5px;
520
+
521
+ canvas {
522
+ max-width: calc(100% - 10px);
523
+ }
524
+ }
525
+
526
+ .pdf-toolbar {
527
+ padding: 6px 8px;
528
+
529
+ .toolbar-btn {
530
+ padding: 3px 6px;
531
+ font-size: 11px;
532
+ }
533
+
534
+ .page-info,
535
+ .zoom-info {
536
+ font-size: 11px;
537
+ min-width: 50px;
538
+ }
539
+ }
540
+ }
541
+ </style>
package/src/index.js CHANGED
@@ -99,6 +99,7 @@ import EbizDropdownItem from './components/EbizDropdownItem.vue'
99
99
  import EbizFileList from './components/EbizFileList.vue'
100
100
  import EbizDetailView from './components/EbizDetailView.vue'
101
101
  import EbizDetailItem from './components/EbizDetailItem.vue'
102
+ import EbizPdfViewer from './components/EbizPdfViewer.vue'
102
103
 
103
104
  // 导出组件
104
105
  export {
@@ -239,5 +240,7 @@ export {
239
240
  EbizSApprovalProcess,
240
241
  // 详情页组件
241
242
  EbizDetailView,
242
- EbizDetailItem
243
+ EbizDetailItem,
244
+ // PDF预览组件
245
+ EbizPdfViewer
243
246
  }
@@ -394,6 +394,12 @@ const routes = [
394
394
  name: 'DetailViewDemo',
395
395
  component: () => import('../views/EbizDetailViewDemo.vue'),
396
396
  meta: { title: 'Ebiz详情页组件示例' }
397
+ },
398
+ {
399
+ path: '/pdf-viewer-demo',
400
+ name: 'PdfViewerDemo',
401
+ component: () => import('../views/PdfViewerDemo.vue'),
402
+ meta: { title: 'EbizPdfViewer PDF预览器示例' }
397
403
  }
398
404
  ]
399
405
 
@@ -97,7 +97,8 @@ export default {
97
97
  { path: '/meeting-room-selector', title: 'Ebiz会议室选择器组件示例' },
98
98
  { path: '/mobile-meeting-room-selector', title: 'Ebiz移动端会议室选择器组件示例' },
99
99
  { path: '/file-list-demo', title: '文件列表demo' },
100
- { path: '/detail-view-demo', title: 'Ebiz详情页组件示例' }
100
+ { path: '/detail-view-demo', title: 'Ebiz详情页组件示例' },
101
+ { path: '/pdf-viewer-demo', title: 'EbizPdfViewer PDF预览器示例' }
101
102
  ]
102
103
 
103
104
  return {