Skip to content

Commit 628d064

Browse files
authored
Merge pull request #5 from NCTUCSUnion/dev
Dev
2 parents 040faba + f448deb commit 628d064

4 files changed

Lines changed: 268 additions & 25 deletions

File tree

frontend/package-lock.json

Lines changed: 210 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"primevue": "^4.3.5",
2323
"tailwindcss": "^4.1.8",
2424
"vue": "^3.5.13",
25+
"vue-pdf-embed": "^2.1.3",
2526
"vue-router": "^4.5.1"
2627
},
2728
"devDependencies": {

frontend/src/components/PdfPreviewModal.vue

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,28 @@
2020
</template>
2121

2222
<div class="w-full h-full flex flex-column">
23-
<div v-if="loading" class="flex-1 flex align-items-center justify-content-center">
23+
<div
24+
v-if="loading || pdfLoading"
25+
class="flex-1 flex align-items-center justify-content-center"
26+
>
2427
<ProgressSpinner strokeWidth="4" />
2528
</div>
2629

2730
<div
28-
v-else-if="error"
31+
v-else-if="error || pdfError"
2932
class="flex-1 flex flex-column align-items-center justify-content-center gap-4"
3033
>
3134
<i class="pi pi-exclamation-circle text-6xl text-red-500" />
3235
<div class="text-xl">無法載入預覽</div>
3336
<div class="text-sm text-gray-600">請嘗試下載檔案查看</div>
3437
</div>
3538

36-
<div v-else-if="previewUrl" class="flex-1 relative">
37-
<iframe
38-
:src="previewUrl"
39-
class="absolute top-0 left-0 w-full h-full"
40-
type="application/pdf"
41-
frameborder="0"
42-
@load="handleLoad"
43-
@error="handleError"
44-
allow="fullscreen"
45-
referrerpolicy="no-referrer"
39+
<div v-else-if="previewUrl" class="flex-1 pdf-container">
40+
<VuePdfEmbed
41+
:source="previewUrl"
42+
class="pdf-viewer"
43+
@loaded="handlePdfLoaded"
44+
@loading-failed="handlePdfError"
4645
/>
4746
</div>
4847
</div>
@@ -62,6 +61,7 @@
6261

6362
<script setup>
6463
import { computed, ref } from 'vue'
64+
import VuePdfEmbed from 'vue-pdf-embed'
6565
6666
const props = defineProps({
6767
visible: {
@@ -98,16 +98,26 @@ const localVisible = computed({
9898
})
9999
100100
const downloading = ref(false)
101+
const pdfLoading = ref(false)
102+
const pdfError = ref(false)
101103
102104
function onHide() {
105+
// Reset PDF states when modal is hidden
106+
pdfLoading.value = false
107+
pdfError.value = false
103108
emit('hide')
104109
}
105110
106-
function handleLoad() {
111+
function handlePdfLoaded() {
112+
pdfLoading.value = false
113+
pdfError.value = false
107114
emit('load')
108115
}
109116
110-
function handleError() {
117+
function handlePdfError(error) {
118+
console.error('PDF loading failed:', error)
119+
pdfLoading.value = false
120+
pdfError.value = true
111121
emit('error')
112122
}
113123
@@ -120,14 +130,32 @@ function handleDownload() {
120130
</script>
121131

122132
<style scoped>
123-
.pdf-viewer {
133+
.pdf-container {
124134
width: 100%;
125-
height: 80vh;
135+
height: 100%;
136+
overflow: auto;
126137
display: flex;
127138
justify-content: center;
139+
background-color: #525659;
140+
}
141+
142+
.pdf-viewer {
143+
width: 100%;
144+
height: 100%;
145+
display: flex;
146+
flex-direction: column;
128147
align-items: center;
129148
}
130149
150+
:deep(.vue-pdf-embed) {
151+
width: 100%;
152+
}
153+
154+
:deep(.vue-pdf-embed > div) {
155+
margin-bottom: 10px;
156+
box-shadow: 0 2px 8px 4px rgba(0, 0, 0, 0.1);
157+
}
158+
131159
/* Mobile responsive adjustments */
132160
@media (max-width: 768px) {
133161
:deep(.p-dialog .p-dialog-header) {
@@ -138,9 +166,5 @@ function handleDownload() {
138166
font-size: 0.875rem;
139167
padding: 0.5rem 0.75rem;
140168
}
141-
142-
.pdf-viewer {
143-
height: 70vh;
144-
}
145169
}
146170
</style>

0 commit comments

Comments
 (0)