feat(Pdf预览): 添加PDF加载状态处理和加载指示器
在PdfPreview组件中添加加载状态处理和加载指示器,通过@onLoad事件通知父组件加载状态
Showing
2 changed files
with
21 additions
and
3 deletions
| ... | @@ -7,6 +7,11 @@ | ... | @@ -7,6 +7,11 @@ |
| 7 | :style="{ height: '100%', width: '100%' }"> | 7 | :style="{ height: '100%', width: '100%' }"> |
| 8 | <div id="pdf-container"></div> | 8 | <div id="pdf-container"></div> |
| 9 | <van-button class="close-btn" type="default" icon="cross" round @click="emit('update:show', false)" /> | 9 | <van-button class="close-btn" type="default" icon="cross" round @click="emit('update:show', false)" /> |
| 10 | + <van-overlay :show="loading"> | ||
| 11 | + <div class="wrapper" @click.stop> | ||
| 12 | + <van-loading vertical color="#FFFFFF">加载中...</van-loading> | ||
| 13 | + </div> | ||
| 14 | + </van-overlay> | ||
| 10 | </van-popup> | 15 | </van-popup> |
| 11 | </template> | 16 | </template> |
| 12 | 17 | ||
| ... | @@ -30,15 +35,16 @@ const props = defineProps({ | ... | @@ -30,15 +35,16 @@ const props = defineProps({ |
| 30 | } | 35 | } |
| 31 | }); | 36 | }); |
| 32 | 37 | ||
| 33 | -const emit = defineEmits(['update:show']); | 38 | +const emit = defineEmits(['update:show', 'onLoad']); |
| 34 | 39 | ||
| 35 | // PDF Worker路径 | 40 | // PDF Worker路径 |
| 36 | -const loading = ref(false); | 41 | +const loading = ref(true); |
| 37 | const pdfPath = new URL("@sunsetglow/vue-pdf-viewer/dist/libs/pdf.worker.min.js", import.meta.url).href; | 42 | const pdfPath = new URL("@sunsetglow/vue-pdf-viewer/dist/libs/pdf.worker.min.js", import.meta.url).href; |
| 38 | 43 | ||
| 39 | // 监听show属性变化 | 44 | // 监听show属性变化 |
| 40 | watch(() => props.show, (newVal) => { | 45 | watch(() => props.show, (newVal) => { |
| 41 | if (newVal && props.url) { | 46 | if (newVal && props.url) { |
| 47 | + loading.value = true; | ||
| 42 | initPdfViewer(); | 48 | initPdfViewer(); |
| 43 | } | 49 | } |
| 44 | }); | 50 | }); |
| ... | @@ -52,6 +58,7 @@ const initPdfViewer = () => { | ... | @@ -52,6 +58,7 @@ const initPdfViewer = () => { |
| 52 | pdfPath: pdfPath, | 58 | pdfPath: pdfPath, |
| 53 | loading: (load, fileInfo) => { | 59 | loading: (load, fileInfo) => { |
| 54 | loading.value = load; | 60 | loading.value = load; |
| 61 | + emit('onLoad', false); | ||
| 55 | }, | 62 | }, |
| 56 | pdfOption: { | 63 | pdfOption: { |
| 57 | search: false, | 64 | search: false, |
| ... | @@ -98,4 +105,11 @@ const initPdfViewer = () => { | ... | @@ -98,4 +105,11 @@ const initPdfViewer = () => { |
| 98 | background: rgba(0, 0, 0, 0.6); | 105 | background: rgba(0, 0, 0, 0.6); |
| 99 | color: #fff; | 106 | color: #fff; |
| 100 | } | 107 | } |
| 108 | + | ||
| 109 | +.wrapper { | ||
| 110 | + display: flex; | ||
| 111 | + align-items: center; | ||
| 112 | + justify-content: center; | ||
| 113 | + height: 100%; | ||
| 114 | +} | ||
| 101 | </style> | 115 | </style> | ... | ... |
| ... | @@ -238,7 +238,7 @@ | ... | @@ -238,7 +238,7 @@ |
| 238 | </van-popup> | 238 | </van-popup> |
| 239 | 239 | ||
| 240 | <!-- PDF预览 --> | 240 | <!-- PDF预览 --> |
| 241 | - <PdfPreview v-model:show="pdfShow" :url="pdfUrl" :title="pdfTitle" /> | 241 | + <PdfPreview v-model:show="pdfShow" :url="pdfUrl" :title="pdfTitle" @onLoad="onPdfLoad" /> |
| 242 | </div> | 242 | </div> |
| 243 | </template> | 243 | </template> |
| 244 | 244 | ||
| ... | @@ -416,6 +416,10 @@ const showPdf = ({ title, url, meta_id }) => { | ... | @@ -416,6 +416,10 @@ const showPdf = ({ title, url, meta_id }) => { |
| 416 | addRecord(paramsObj); | 416 | addRecord(paramsObj); |
| 417 | }; | 417 | }; |
| 418 | 418 | ||
| 419 | +const onPdfLoad = (load) => { | ||
| 420 | + // console.warn('pdf加载状态', load); | ||
| 421 | +}; | ||
| 422 | + | ||
| 419 | const courseId = computed(() => { | 423 | const courseId = computed(() => { |
| 420 | return route.params.id || ''; | 424 | return route.params.id || ''; |
| 421 | }); | 425 | }); | ... | ... |
-
Please register or login to post a comment