<template>
<view class="content">
<l-file ref="lFile" :logo="logo" @up-success="onSuccess"></l-file>
<uni-table border stripe emptyText="暂无更多数据">
<!-- 表头行 -->
<uni-tr>
<uni-th align="center">文件名称</uni-th>
<uni-th align="center">操作</uni-th>
</uni-tr>
<!-- 表格数据行 -->
<uni-tr v-model="downTable" v-for="(item,index) in downTable" :key="item.id">
<uni-td>{{item.file_name}}</uni-td>
<!-- 点击预览-->
<uni-td>
<button style="width: 100rpx;font-size: 24rpx;" type="primary" @click="handleDownload(index)">预览</button>
</uni-td>
</uni-tr>
</uni-table>
</view>`
</template>
export default{
data(){
return{
downTable:[],
mis_id:"",
file_url:"",//路径
localPath: '',
}
},
onLoad(options) {
this.mis_id = options.mis_id;
this.getDown();
},
methods:{
//获取文件数据
getDown(){
uni.request({
url:"https://xxxxxxxxxxxx",
method:"POST",
data:{
mis_id: this.mis_id
},success:(res)=>{
this.downTable = res.data.data;
}
})
},
//点击预览
handleDownload(index){
//wx.downloadFile详情查看微信小程序官方文档
wx.downloadFile({
url:this.downTable[index].file_url,
success:(res=>{
const fileManager = wx.getFileSystemManager()
//下面这个一定要记得添加,不然真机测试!
const filePath = wx.env.USER_DATA_PATH +'/'+this.downTable[index].file_name
fileManager.saveFile({
tempFilePath: res.tempFilePath,
filePath:filePath,
success:()=>{
//预览打开文档,没问题的话在手机上测试,点击右上角的分享给微信好友和朋友圈应该都没有问题
wx.openDocument({
filePath: filePath,
showMenu: true,
})
}
})
})
})
},
}
}