You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
2.3 KiB
Vue
105 lines
2.3 KiB
Vue
<template>
|
|
<view>
|
|
<view v-if="downLoadOk==false" class="loading">正在加载请稍后...</view>
|
|
<view v-else class="tishi">
|
|
<view class="tishi2">
|
|
<view style=" transform: rotate(125deg) scaleX(2) scaleY(1);margin-bottom: 30%;margin-left: 30%; " ><uni-icons type="undo" size="100"></uni-icons></view>
|
|
<view>文档打开后</view>
|
|
<view>点击右上角按钮,可下载或转发保存</view>
|
|
</view>
|
|
<view class="ok" @click="openfile()">
|
|
我知道了,打开文档
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import {
|
|
ref
|
|
} from 'vue'
|
|
|
|
import {
|
|
onLoad
|
|
} from '@dcloudio/uni-app'
|
|
|
|
let downLoadOk = ref(false);
|
|
onLoad((e) => {
|
|
console.log(e)
|
|
tiao(e)
|
|
})
|
|
let filePath = ref('');
|
|
const tiao = (e) => {
|
|
console.log("开始下载")
|
|
uni.downloadFile({
|
|
url: e.url,
|
|
success: function(res) {
|
|
downLoadOk.value = true
|
|
filePath.value = res.tempFilePath;
|
|
const newFilePath = `${wx.env.USER_DATA_PATH}/${e.url.split('/').pop()}`;
|
|
uni.saveFile({
|
|
tempFilePath:res.tempFilePath, // 临时文件路径
|
|
filePath: newFilePath, // 新的文件路径
|
|
success: (saveResult) => {
|
|
console.log("文件保存成功,新路径为:", saveResult.savedFilePath);
|
|
filePath.value= saveResult.savedFilePath
|
|
},
|
|
fail: (saveErr) => {
|
|
console.error("文件保存失败:", saveErr);
|
|
reject(saveErr);
|
|
}
|
|
});
|
|
|
|
},
|
|
});
|
|
|
|
}
|
|
const openfile = () => {
|
|
uni.openDocument({
|
|
filePath: filePath.value,
|
|
showMenu: true,
|
|
fileType:"pdf",
|
|
success: function(res) {
|
|
console.log("打开文档成功");
|
|
// wx.navigateBack({
|
|
// delta: 1
|
|
// })
|
|
},
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.loading {
|
|
margin-top: 200rpx;
|
|
width: 100%;
|
|
text-align: center;
|
|
}
|
|
|
|
.tishi {
|
|
width: 100%;
|
|
height: calc(100vh - 200rpx);
|
|
background-color: black;
|
|
opacity: 0.5;
|
|
color: #fff;
|
|
padding-top: 200rpx;
|
|
}
|
|
|
|
.tishi2 {
|
|
width: 50%;
|
|
margin-left: auto;
|
|
margin-right: auto;
|
|
text-align: center;
|
|
}
|
|
|
|
.ok {
|
|
width: 50%;
|
|
margin-left: auto;
|
|
margin-right: auto;
|
|
text-align: center;
|
|
border: 1px solid #fff;
|
|
margin-top: 70%;
|
|
padding: 20rpx;
|
|
border-radius: 20rpx;
|
|
}
|
|
</style> |