12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <template>
- <view>
- <view>
- <view @click="handleDownload">下载</view>
- <!-- <web-view v-if="pdfUrl" :src="pdfUrl" @message="getPostMessage"></web-view>-->
- <ssDownload ref="ssRef"></ssDownload>
- </view>
- </view>
- </template>
- <script setup>
- import {ref} from "vue"
- import {onLoad, onBackPress} from "@dcloudio/uni-app"
- import ssDownload from "./ssDownload.vue"
- import * as httpApi from "@/api/pdf.js"
- const pdfUrl = ref('');
- const httpUrl = ref('');
- const ssRef = ref(null)
- const banben1 =ref('');
- const nianji1 =ref('');
- function updatePdfUrl({banben,nianji}) {
- httpApi.getPDFUrl({
- banben,
- nianji,
- }).then(res => {
- httpUrl.value = res.data;
- pdfUrl.value = '/hybrid/html/web/viewer.html?file=' + encodeURIComponent(res.data);
- })
- }
- function handleDownload() {
- uni.downloadFile({
- url: httpUrl.value,
- success: function (res) {
- var filePath = res.tempFilePath;
- uni.openDocument({
- filePath: filePath,
- showMenu: true,
- success: function (res) {
- console.log('打开文档成功');
- }
- });
- }
- });
- /*ssRef.value.toDownload({
- type:2,
- src: httpUrl.value,
- })*/
- }
- function getPostMessage() {
- console.log('执行下载操作')
- ssRef.value.toDownload({
- type:2,
- src: httpUrl.value,
-
- })
- }
- onBackPress((d) => {
- console.log('地址:',`/pages/my/sxtkPage?banben=${banben1.value}&nianji=${nianji1.value}`)
- uni.redirectTo({
- url: `/pages/my/sxtkPage?banben=${banben1.value}&nianji=${nianji1.value}`
- })
- return true
- })
-
- onLoad(({banben, nianji}) => {
- nianji1.value = nianji;
- banben1.value = banben;
- updatePdfUrl({banben, nianji});
- })
-
- </script>
- <style>
- </style>
|