修改附件

main
ihzero 2024-05-15 23:32:10 +08:00
parent 5f7f73970a
commit 0364e37009
2 changed files with 34 additions and 49 deletions

View File

@ -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 }}/{{

View File

@ -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>