adtec-core-package 3.2.1 → 3.2.2
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,15 +1,15 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div ref="scrollRef" class="docx-js-viewer">
|
|
3
|
-
<div
|
|
4
|
-
<div v-else-if="loadError" class="docx-error-tip">
|
|
5
|
-
<el-empty :description="loadError" />
|
|
6
|
-
</div>
|
|
7
|
-
<div v-else class="docx-body">
|
|
3
|
+
<div class="docx-body">
|
|
8
4
|
<div ref="styleHostRef" class="docx-style-host" />
|
|
9
5
|
<div class="docx-scale-host" :style="scaleHostStyle">
|
|
10
6
|
<div ref="bodyHostRef" class="docx-render-host" :style="renderStyle" />
|
|
11
7
|
</div>
|
|
12
8
|
</div>
|
|
9
|
+
<div v-if="loading" class="docx-overlay docx-loading">正在解析 Word 文档…</div>
|
|
10
|
+
<div v-else-if="loadError" class="docx-overlay docx-error-tip">
|
|
11
|
+
<el-empty :description="loadError" />
|
|
12
|
+
</div>
|
|
13
13
|
</div>
|
|
14
14
|
</template>
|
|
15
15
|
|
|
@@ -98,16 +98,23 @@ const collectPageSections = () => {
|
|
|
98
98
|
emit('page-change', 1)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
let loadToken = 0
|
|
102
|
+
|
|
101
103
|
const loadDocument = async (src: Blob | ArrayBuffer) => {
|
|
104
|
+
const token = ++loadToken
|
|
102
105
|
loading.value = true
|
|
103
|
-
|
|
106
|
+
loadError.value = ''
|
|
104
107
|
try {
|
|
105
108
|
const buffer = src instanceof Blob ? await src.arrayBuffer() : src
|
|
109
|
+
if (token !== loadToken) return
|
|
110
|
+
|
|
111
|
+
await nextTick()
|
|
106
112
|
const bodyHost = bodyHostRef.value
|
|
107
113
|
const styleHost = styleHostRef.value
|
|
108
114
|
if (!bodyHost || !styleHost) {
|
|
109
115
|
throw new Error('预览容器未就绪')
|
|
110
116
|
}
|
|
117
|
+
resetViewer()
|
|
111
118
|
await renderAsync(buffer, bodyHost, styleHost, {
|
|
112
119
|
className: 'docx',
|
|
113
120
|
inWrapper: true,
|
|
@@ -119,14 +126,18 @@ const loadDocument = async (src: Blob | ArrayBuffer) => {
|
|
|
119
126
|
renderFootnotes: true,
|
|
120
127
|
renderEndnotes: true,
|
|
121
128
|
})
|
|
129
|
+
if (token !== loadToken) return
|
|
122
130
|
await nextTick()
|
|
123
131
|
collectPageSections()
|
|
124
132
|
emit('loaded')
|
|
125
133
|
} catch (err) {
|
|
134
|
+
if (token !== loadToken) return
|
|
126
135
|
loadError.value = 'Word 文档解析失败,请下载后查看'
|
|
127
136
|
emit('error', err)
|
|
128
137
|
} finally {
|
|
129
|
-
|
|
138
|
+
if (token === loadToken) {
|
|
139
|
+
loading.value = false
|
|
140
|
+
}
|
|
130
141
|
}
|
|
131
142
|
}
|
|
132
143
|
|
|
@@ -196,7 +207,11 @@ watch(
|
|
|
196
207
|
() => props.src,
|
|
197
208
|
(src) => {
|
|
198
209
|
if (src) void loadDocument(src)
|
|
199
|
-
else
|
|
210
|
+
else {
|
|
211
|
+
++loadToken
|
|
212
|
+
loading.value = false
|
|
213
|
+
resetViewer()
|
|
214
|
+
}
|
|
200
215
|
},
|
|
201
216
|
{ immediate: true },
|
|
202
217
|
)
|
|
@@ -213,6 +228,7 @@ defineExpose({
|
|
|
213
228
|
|
|
214
229
|
<style scoped lang="scss">
|
|
215
230
|
.docx-js-viewer {
|
|
231
|
+
position: relative;
|
|
216
232
|
flex: 1;
|
|
217
233
|
width: 100%;
|
|
218
234
|
min-height: 0;
|
|
@@ -220,6 +236,16 @@ defineExpose({
|
|
|
220
236
|
background: #e5e7eb;
|
|
221
237
|
}
|
|
222
238
|
|
|
239
|
+
.docx-overlay {
|
|
240
|
+
position: absolute;
|
|
241
|
+
inset: 0;
|
|
242
|
+
z-index: 2;
|
|
243
|
+
display: flex;
|
|
244
|
+
align-items: center;
|
|
245
|
+
justify-content: center;
|
|
246
|
+
background: #e5e7eb;
|
|
247
|
+
}
|
|
248
|
+
|
|
223
249
|
.docx-body {
|
|
224
250
|
min-height: 100%;
|
|
225
251
|
padding: 12px;
|
|
@@ -238,12 +264,7 @@ defineExpose({
|
|
|
238
264
|
background: transparent;
|
|
239
265
|
}
|
|
240
266
|
|
|
241
|
-
.docx-loading
|
|
242
|
-
.docx-error-tip {
|
|
243
|
-
display: flex;
|
|
244
|
-
align-items: center;
|
|
245
|
-
justify-content: center;
|
|
246
|
-
min-height: 240px;
|
|
267
|
+
.docx-loading {
|
|
247
268
|
color: #6b7280;
|
|
248
269
|
font-size: 14px;
|
|
249
270
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
v-loading="showOverlayLoading"
|
|
9
9
|
element-loading-text="加载中,请稍后。。。"
|
|
10
10
|
class="file-view-overlay"
|
|
11
|
+
:class="{ 'is-preview-fullscreen': isFullscreen }"
|
|
11
12
|
>
|
|
12
13
|
<office-preview-toolbar
|
|
13
14
|
v-if="!isHeaderPreview"
|
|
@@ -15,13 +16,23 @@
|
|
|
15
16
|
:zoom="previewScale"
|
|
16
17
|
:show-zoom="false"
|
|
17
18
|
:show-download="!!url"
|
|
19
|
+
:show-fullscreen="true"
|
|
18
20
|
:show-close="true"
|
|
21
|
+
:fullscreen="isFullscreen"
|
|
19
22
|
:download-loading="loading"
|
|
20
23
|
@download="download"
|
|
21
|
-
@
|
|
24
|
+
@toggle-fullscreen="toggleFullscreen"
|
|
25
|
+
@close="closePreview"
|
|
22
26
|
/>
|
|
23
27
|
|
|
24
|
-
<div
|
|
28
|
+
<div
|
|
29
|
+
ref="previewContainerRef"
|
|
30
|
+
class="office-preview"
|
|
31
|
+
:class="{
|
|
32
|
+
'has-rich-header': isHeaderPreview,
|
|
33
|
+
'fullscreen-mode': isFullscreen,
|
|
34
|
+
}"
|
|
35
|
+
>
|
|
25
36
|
<office-preview
|
|
26
37
|
v-if="url"
|
|
27
38
|
v-model:scale="previewScale"
|
|
@@ -30,19 +41,22 @@
|
|
|
30
41
|
:file-name="title"
|
|
31
42
|
:show-header="isHeaderPreview"
|
|
32
43
|
:show-download="!!url"
|
|
44
|
+
:show-fullscreen="isHeaderPreview"
|
|
33
45
|
:show-close="isHeaderPreview"
|
|
46
|
+
:fullscreen="isFullscreen"
|
|
34
47
|
:download-loading="loading"
|
|
35
48
|
@loaded="loading = false"
|
|
36
49
|
@error="loading = false"
|
|
37
50
|
@download="download"
|
|
38
|
-
@
|
|
51
|
+
@toggle-fullscreen="toggleFullscreen"
|
|
52
|
+
@close="closePreview"
|
|
39
53
|
/>
|
|
40
54
|
</div>
|
|
41
55
|
</div>
|
|
42
56
|
</Teleport>
|
|
43
57
|
</template>
|
|
44
58
|
<script setup lang="ts">
|
|
45
|
-
import { computed, ref, watch } from 'vue'
|
|
59
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
46
60
|
import { useVModel } from '@vueuse/core'
|
|
47
61
|
import framework from '../../api/framework'
|
|
48
62
|
import frameworkUtils from '../../utils/FrameworkUtils'
|
|
@@ -58,6 +72,8 @@ import {
|
|
|
58
72
|
const model = defineModel()
|
|
59
73
|
const loading = ref(false)
|
|
60
74
|
const previewScale = ref(1)
|
|
75
|
+
const previewContainerRef = ref<HTMLElement | null>(null)
|
|
76
|
+
const isFullscreen = ref(false)
|
|
61
77
|
|
|
62
78
|
const props = defineProps({
|
|
63
79
|
title: {
|
|
@@ -89,6 +105,46 @@ const isHeaderPreview = computed(() =>
|
|
|
89
105
|
/** 富文本预览由 OfficePreview 自带 loading,避免与 v-loading 双层转圈 */
|
|
90
106
|
const showOverlayLoading = computed(() => loading.value && !isHeaderPreview.value)
|
|
91
107
|
|
|
108
|
+
const getContainerEl = () => previewContainerRef.value
|
|
109
|
+
|
|
110
|
+
const syncFullscreenState = () => {
|
|
111
|
+
const el = getContainerEl()
|
|
112
|
+
isFullscreen.value = !!el && document.fullscreenElement === el
|
|
113
|
+
document.body.style.overflow = isFullscreen.value ? 'hidden' : ''
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const exitFullscreen = async () => {
|
|
117
|
+
try {
|
|
118
|
+
if (document.fullscreenElement === getContainerEl()) {
|
|
119
|
+
await document.exitFullscreen()
|
|
120
|
+
}
|
|
121
|
+
} catch {
|
|
122
|
+
// ignore
|
|
123
|
+
}
|
|
124
|
+
isFullscreen.value = false
|
|
125
|
+
document.body.style.overflow = ''
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const toggleFullscreen = async () => {
|
|
129
|
+
const el = getContainerEl()
|
|
130
|
+
if (!el) return
|
|
131
|
+
try {
|
|
132
|
+
if (document.fullscreenElement === el) {
|
|
133
|
+
await document.exitFullscreen()
|
|
134
|
+
} else {
|
|
135
|
+
await el.requestFullscreen()
|
|
136
|
+
}
|
|
137
|
+
} catch {
|
|
138
|
+
isFullscreen.value = !isFullscreen.value
|
|
139
|
+
document.body.style.overflow = isFullscreen.value ? 'hidden' : ''
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const closePreview = async () => {
|
|
144
|
+
await exitFullscreen()
|
|
145
|
+
model.value = false
|
|
146
|
+
}
|
|
147
|
+
|
|
92
148
|
watch(
|
|
93
149
|
[model, url],
|
|
94
150
|
([visible, fileUrl]) => {
|
|
@@ -100,11 +156,21 @@ watch(
|
|
|
100
156
|
} else if (!visible) {
|
|
101
157
|
loading.value = false
|
|
102
158
|
previewScale.value = 1
|
|
159
|
+
void exitFullscreen()
|
|
103
160
|
}
|
|
104
161
|
},
|
|
105
162
|
{ immediate: true },
|
|
106
163
|
)
|
|
107
164
|
|
|
165
|
+
onMounted(() => {
|
|
166
|
+
document.addEventListener('fullscreenchange', syncFullscreenState)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
onBeforeUnmount(() => {
|
|
170
|
+
document.removeEventListener('fullscreenchange', syncFullscreenState)
|
|
171
|
+
void exitFullscreen()
|
|
172
|
+
})
|
|
173
|
+
|
|
108
174
|
const getFileType = () => resolveOfficeFileExt(undefined, title.value, url.value)
|
|
109
175
|
|
|
110
176
|
const download = async () => {
|
|
@@ -143,6 +209,10 @@ const download = async () => {
|
|
|
143
209
|
display: flex;
|
|
144
210
|
align-items: center;
|
|
145
211
|
justify-content: center;
|
|
212
|
+
|
|
213
|
+
&.is-preview-fullscreen {
|
|
214
|
+
background: transparent;
|
|
215
|
+
}
|
|
146
216
|
}
|
|
147
217
|
|
|
148
218
|
.file-view-toolbar {
|
|
@@ -163,5 +233,41 @@ const download = async () => {
|
|
|
163
233
|
display: flex;
|
|
164
234
|
flex-direction: column;
|
|
165
235
|
}
|
|
236
|
+
|
|
237
|
+
&:fullscreen {
|
|
238
|
+
display: flex;
|
|
239
|
+
flex-direction: column;
|
|
240
|
+
width: 100% !important;
|
|
241
|
+
height: 100% !important;
|
|
242
|
+
border-radius: 0;
|
|
243
|
+
background: #f5f5f5 !important;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
&.fullscreen-mode {
|
|
247
|
+
position: fixed !important;
|
|
248
|
+
inset: 0 !important;
|
|
249
|
+
z-index: 10000;
|
|
250
|
+
display: flex;
|
|
251
|
+
flex-direction: column;
|
|
252
|
+
width: 100vw !important;
|
|
253
|
+
height: 100vh !important;
|
|
254
|
+
border-radius: 0;
|
|
255
|
+
background: #f5f5f5 !important;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
&:fullscreen,
|
|
259
|
+
&.fullscreen-mode {
|
|
260
|
+
:deep(.office-preview-root) {
|
|
261
|
+
flex: 1;
|
|
262
|
+
min-height: 0;
|
|
263
|
+
height: 100%;
|
|
264
|
+
background: #f5f5f5 !important;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
:deep(.office-rich-wrap),
|
|
268
|
+
:deep(.pdf-js-viewer) {
|
|
269
|
+
background: #f5f5f5;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
166
272
|
}
|
|
167
273
|
</style>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="office-preview-root" :class="{ 'is-rich-preview': isRichPreview }">
|
|
2
|
+
<div class="office-preview-root" :class="{ 'is-rich-preview': isRichPreview, 'is-fullscreen': fullscreen }">
|
|
3
3
|
<template v-if="isRichPreview">
|
|
4
4
|
<office-preview-header-bar
|
|
5
5
|
v-if="showHeader"
|
|
@@ -386,6 +386,19 @@ defineExpose({
|
|
|
386
386
|
flex-direction: column;
|
|
387
387
|
overflow: hidden;
|
|
388
388
|
}
|
|
389
|
+
|
|
390
|
+
&.is-fullscreen {
|
|
391
|
+
height: 100%;
|
|
392
|
+
background: #f5f5f5 !important;
|
|
393
|
+
|
|
394
|
+
&.is-rich-preview {
|
|
395
|
+
.office-rich-wrap {
|
|
396
|
+
flex: 1;
|
|
397
|
+
min-height: 0;
|
|
398
|
+
background: #f5f5f5;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
389
402
|
}
|
|
390
403
|
|
|
391
404
|
.office-rich-viewer {
|
|
@@ -104,7 +104,7 @@ const showPlaceholder = computed(
|
|
|
104
104
|
const placeholderText = computed(() => {
|
|
105
105
|
if (isPending.value) return '等待预览区域就绪…'
|
|
106
106
|
if (totalPages.value > 0) return '正在渲染页面…'
|
|
107
|
-
return '
|
|
107
|
+
return '正在解析文档…'
|
|
108
108
|
})
|
|
109
109
|
|
|
110
110
|
const setPageRef = (pageNum: number, el: HTMLElement | null) => {
|