123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <template>
- <view>
- <button @click="previewFile">预览文件</button>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- }
- },
- methods: {
- previewFile() {
- uni.showLoading({
- title: '加载中'
- })
- uni.downloadFile({
- url: "http://114.115.142.166:8087/down/0OR9jtcjJHMj.xlsx", //后端返回的文件地址
- filePath: wx.env.USER_DATA_PATH + '/gwy.xls',
- // filePath: wx.env.USER_DATA_PATH + '/' + item.name + '.' + item.value.split('.')[item.value.split('.').length - 1],
- success: function(res) {
- if (res.statusCode === 200) {
- uni.openDocument({
- showMenu: true,
- filePath: res.filePath,
- success: function(res) {
- console.log(res, '打开文件成功')
- },
- fail: (err) => {
- uni.showToast({
- title: '打开文件失败请重试',
- icon: 'none'
- })
- }
- })
- } else {
- uni.showToast({
- title: '打开文件失败请重试',
- icon: 'none'
- })
- }
- uni.hideLoading()
- },
- fail: (err) => {
- uni.hideLoading()
- uni.showToast({
- title: '加载失败请重试',
- icon: "none"
- })
- }
- })
- }
- }
- }
- </script>
- <style>
- </style>
|