fix: bug

This commit is contained in:
杨航
2025-09-17 14:42:19 +08:00
parent fe7e4b6a1e
commit cbeab8a1f4
+75 -52
View File
@@ -424,35 +424,35 @@ const talkItemEvents = ({ type, data, id, info = {} }) => {
} else {
const base_url = get_base_url('/traask/traFilePreview/')
let fileUrl = base_url + '/traask/traFilePreview/' + info.docId
const localFilePath = '_doc/pdf_view/' + info.docName + '.pdf'
downloadAndSaveAvatar(fileUrl, localFilePath).then(res=>{
uni.openDocument({
filePath: res,
showMenu: true,
success: function () {
console.log('打开文档成功')
}
})
})
// uni.downloadFile({
// url: fileUrl,
// success: function (res) {
// uni.saveFile({
// tempFilePath: res.tempFilePath,
// success: function (resS) {
// var filePath = resS.savedFilePath
// uni.openDocument({
// filePath: filePath,
// showMenu: true,
// success: function () {
// console.log('打开文档成功')
// }
// })
// }
// })
// }
// })
const localFilePath = '_doc/pdf_view/' + info.docName + '.pdf'
downloadAndSaveAvatar(fileUrl, localFilePath).then(res => {
uni.openDocument({
filePath: res,
showMenu: true,
success: function () {
console.log('打开文档成功')
}
})
})
// uni.downloadFile({
// url: fileUrl,
// success: function (res) {
// uni.saveFile({
// tempFilePath: res.tempFilePath,
// success: function (resS) {
// var filePath = resS.savedFilePath
// uni.openDocument({
// filePath: filePath,
// showMenu: true,
// success: function () {
// console.log('打开文档成功')
// }
// })
// }
// })
// }
// })
}
break
case 'toCourse':
@@ -462,29 +462,39 @@ const talkItemEvents = ({ type, data, id, info = {} }) => {
break
}
}
const downloadAndSaveAvatar = async (fileUrl, localFilePath) => {
try {
return new Promise((resolve, reject) => {
console.log('开始下载:', fileUrl)
const dtask = plus.downloader.createDownload(fileUrl, {
filename: localFilePath
}, (d, status) => {
if (status === 200) {
console.log("保存路径:", d.filename)
resolve(d.filename)
} else {
console.error("文件下载失败:", status)
reject(new Error(`下载失败,状态码: ${status}`))
}
})
dtask.start()
})
} catch (error) {
console.error('创建目录失败:', error)
throw error
}
}
const downloadAndSaveAvatar = async (fileUrl, localFilePath) => {
try {
//#ifdef APP-PLUS
return new Promise((resolve, reject) => {
console.log('开始下载:', fileUrl)
const dtask = plus.downloader.createDownload(
fileUrl,
{
filename: localFilePath
},
(d, status) => {
if (status === 200) {
console.log('保存路径:', d.filename)
resolve(d.filename)
} else {
console.error('文件下载失败:', status)
reject(new Error(`下载失败,状态码: ${status}`))
}
}
)
dtask.start()
})
// #endif
//#ifdef H5
return new Promise((resolve, reject) => {
resolve()
})
// #endif
} catch (error) {
console.error('创建目录失败:', error)
throw error
}
}
const feedbackAnswer = params => {
talkingList.value.forEach(t => {
if (t.seqNo === params.askId) {
@@ -758,6 +768,18 @@ const changeAppHeightBottom = height => {
bottomHeight.value = systemInfo.screenHeight - systemInfo.safeArea.bottom + 'px'
// #endif
}
const deleteFolder = () => {
//#ifdef APP-PLUS
plus.io.resolveLocalFileSystemURL('_doc/pdf_view', function (entry) {
console.log('entry', entry)
entry.removeRecursively(function (res) {
console.log('删除成功')
})
})
// #endif
}
//#ifdef APP-PLUS
onHide(() => {
uni.offKeyboardHeightChange(setHeight)
@@ -768,6 +790,7 @@ onShow(() => {
// #endif
onUnload(() => {
watchFlag.value = 1
deleteFolder()
socketStore?.closeSocket()
// setupKeyboardHeightListener(changeAppHeightBottom)
})