修改附件
parent
5f7f73970a
commit
0364e37009
|
|
@ -38,7 +38,7 @@
|
|||
<view v-for="(item, i) in ob" :key="i">
|
||||
<view class="flex items-center h-84rpx">
|
||||
<view class="w-110rpx text-primary"
|
||||
>{{ timeFormat(item.month, 'mm') }}月</view
|
||||
>{{ timeFormat(`${item.month}-01`, 'mm') }}月</view
|
||||
>
|
||||
<view class="flex-1"
|
||||
>{{ item.actual_performance }}/{{
|
||||
|
|
|
|||
|
|
@ -43,6 +43,15 @@
|
|||
<uv-parse :content="info.content"></uv-parse>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<uv-modal
|
||||
ref="modalRef"
|
||||
title="下载成功"
|
||||
content="下载成功!是否打开"
|
||||
showCancelButton
|
||||
@confirm="confirm"
|
||||
>
|
||||
</uv-modal>
|
||||
</view>
|
||||
</template>
|
||||
<script setup>
|
||||
|
|
@ -52,8 +61,10 @@ import { onLoad } from '@dcloudio/uni-app'
|
|||
import { ref } from 'vue'
|
||||
import { timeFormat } from '@climblee/uv-ui/libs/function'
|
||||
|
||||
const modalRef = ref(null)
|
||||
const id = ref('')
|
||||
const info = ref({})
|
||||
const tempFile = ref(null)
|
||||
onLoad((options) => {
|
||||
id.value = options.id
|
||||
http.get(`/train/books/${id.value}`).then((res) => {
|
||||
|
|
@ -62,59 +73,33 @@ onLoad((options) => {
|
|||
})
|
||||
|
||||
const downloadFile = (url) => {
|
||||
// #ifdef H5
|
||||
const filetype = url.substring(url.lastIndexOf('.') + 1)
|
||||
const whiteFile = ['doc', 'xls', 'ppt', 'pdf', 'docx', 'xlsx', 'pptx']
|
||||
uni.downloadFile({
|
||||
url: url, // 文件的URL
|
||||
success: function (res) {
|
||||
console.log('下载成功', res)
|
||||
// 在这里可以处理文件下载后的操作,比如保存到本地、读取文件内容等
|
||||
},
|
||||
fail: function (err) {
|
||||
console.log('下载失败', err)
|
||||
// 在这里可以处理文件下载失败的情况,比如重新下载、提示用户等
|
||||
url: url,
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
tempFile.value = res
|
||||
|
||||
if (whiteFile.includes(filetype)) {
|
||||
modalRef.value.open()
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '下载成功',
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
let dtask = plus.downloader.createDownload(
|
||||
url,
|
||||
{
|
||||
filename: 'file://storage/emulated/0/Download/',
|
||||
},
|
||||
(d, status) => {
|
||||
if (status == 200) {
|
||||
let fileSaveUrl = plus.io.convertLocalFileSystemURL(d.filename)
|
||||
// saveFile(fileSaveUrl)
|
||||
uni.showToast({
|
||||
title: '下载成功',
|
||||
icon: 'none',
|
||||
})
|
||||
} else {
|
||||
//下载失败
|
||||
uni.showToast({
|
||||
title: '下载失败',
|
||||
})
|
||||
plus.downloader.clear() //清除下载任务
|
||||
}
|
||||
console.log(d)
|
||||
}
|
||||
)
|
||||
dtask.start()
|
||||
// #endif
|
||||
}
|
||||
|
||||
const saveFile = (filePath) => {
|
||||
uni.saveFile({
|
||||
tempFilePath: filePath,
|
||||
success: (res) => {
|
||||
uni.showToast({
|
||||
title: '文件保存成功',
|
||||
})
|
||||
console.log('文件保存成功,路径为:' + res.savedFilePath)
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log('文件保存失败:' + err)
|
||||
},
|
||||
const confirm = () => {
|
||||
var filePath = encodeURI(tempFile.value.tempFilePath)
|
||||
uni.openDocument({
|
||||
filePath: encodeURI(filePath),
|
||||
// fileType: filetype,
|
||||
showMenu: true,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue