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 >
6261
6362<script setup>
6463import { computed , ref } from ' vue'
64+ import VuePdfEmbed from ' vue-pdf-embed'
6565
6666const props = defineProps ({
6767 visible: {
@@ -98,16 +98,26 @@ const localVisible = computed({
9898})
9999
100100const downloading = ref (false )
101+ const pdfLoading = ref (false )
102+ const pdfError = ref (false )
101103
102104function 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