123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <template>
- <view>
- <web-view v-if="pdfUrl" :src="pdfUrl" @message="getPostMessage"></web-view>
-
- <ssDownload ref="ssRef"></ssDownload>
- </view>
- </template>
- <script setup>
- import {ref} from "vue"
- import {onLoad} from "@dcloudio/uni-app"
- import ssDownload from "./ssDownload.vue"
-
-
- const pdfUrl = ref('');
- const httpUrl = ref('');
- const ssRef = ref(null)
-
- function updatePdfUrl(url) {
- httpUrl.value = url;
- pdfUrl.value = '/hybrid/html/web/viewer.html?file=' + encodeURIComponent(url);
- }
-
- function getPostMessage() {
- // console.log('执行下载操作')
- ssRef.value.toDownload({
- type:2,
- src: httpUrl.value
- })
- }
-
-
- onLoad(({url}) => {
- const mockUrl = "https://501351981.github.io/vue-office/examples/dist/static/test-files/test.pdf"
- updatePdfUrl(url||mockUrl);
- })
-
- </script>
- <style>
- </style>
|