文件服务下载改为数据流

新建文件夹&删除文件夹
This commit is contained in:
zhujiyan
2024-09-11 19:39:55 +08:00
parent 6af2bc8397
commit 79cb8a9897
4 changed files with 168 additions and 11 deletions

View File

@@ -4,7 +4,11 @@
<el-dialog v-model="dialogVisible" title="文件信息" width="50%" @closed="handleClose">
<el-descriptions title="" style="margin: 10px 0" :column="2" :border="true" v-loading="loading">
<el-descriptions-item label="文件名称">
{{ fileData?.prjDataPath ? fileData?.prjDataPath.split("/")[fileData?.prjDataPath.split("/").length-1]: '/' }}
{{
fileData?.prjDataPath
? fileData?.prjDataPath.split('/')[fileData?.prjDataPath.split('/').length - 1]
: '/'
}}
</el-descriptions-item>
<el-descriptions-item label="文件大小">
{{ fileData?.size ? fileData?.size + '字节' : '/' }}
@@ -31,6 +35,7 @@
import { ref, onMounted, defineExpose, onBeforeUnmount, onUnmounted, defineEmits } from 'vue'
import { getFileServiceFileOrDir, downLoadDeviceFile } from '@/api/cs-device-boot/fileService.ts'
import { ElMessage } from 'element-plus'
import { downLoadFile } from '@/api/cs-system-boot/manage.ts'
const dialogVisible = ref(false)
const loading = ref(false)
const downLoading = ref(false)
@@ -68,12 +73,32 @@ const handleDownLoad = () => {
}
downLoading.value = true
downLoadDeviceFile(obj)
.then(res => {
.then((res: any) => {
if (res.code == 'A0000') {
window.open(res.data, '_blank')
downLoading.value = false
ElMessage.success(res.message)
handleClose()
downLoadFile(res.data).then((resp: any) => {
console.log(resp, '999999999999')
if (resp.type != 'application/json') {
// 'application/vnd.ms-excel'
let blob = new Blob([resp], { type: resp.type })
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = fileData.value?.prjDataPath
? fileData.value?.prjDataPath.split('/')[fileData.value?.prjDataPath.split('/').length - 1]
: '/'
document.body.appendChild(link)
link.click()
link.remove()
} else {
console.log(6666)
if (resp.code == 'A0000') {
window.open(res.data, '_blank')
downLoading.value = false
ElMessage.success(resp.message)
handleClose()
}
}
})
}
})
.catch(e => {