文件服务下载修改

This commit is contained in:
zhujiyan
2024-10-25 16:03:44 +08:00
parent 63937a0742
commit 21af539824
4 changed files with 127 additions and 56 deletions

View File

@@ -24,6 +24,20 @@ export function downLoadDeviceFile(data) {
})
}
//获取下载文件的文件路径地址
export function downLoadDeviceFilePath(obj) {
let form = new FormData()
form.append('name', obj.name)
form.append('nDid', obj.nDid)
return createAxios({
url: `/cs-device-boot/deviceFile/getDownloadFilePath`,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: form
})
}
//装置重启
export function reStartDevice(data) {
return createAxios({

View File

@@ -101,9 +101,9 @@
{{ row.type == 'dir' ? '文件夹' : row.type == 'file' ? '文件' : '/' }}
</span>
</vxe-column>
<!-- <vxe-column field="startTime" align="center" title="文件时间" width="120" #default="{ row }">
<vxe-column field="startTime" align="center" title="文件时间" width="120" #default="{ row }">
{{ row.startTime ? row.startTime : '/' }}
</vxe-column> -->
</vxe-column>
<!--<vxe-column field="fileCheck" align="center" title="文件校验码" width="100" #default="{ row }">
{{ row.fileCheck ? row.fileCheck : '/' }}
</vxe-column> -->
@@ -243,7 +243,7 @@ const isRoot = ref<boolean>(true)
//储存所有点击过的目录
const activePathList: any = ref([])
const nodeClick = (e: any) => {
console.log(e,"------");
console.log(e, '------')
if (e && (e.level == 2 || e.type == 'device')) {
loading.value = true
nDid.value = e.ndid

View File

@@ -2,21 +2,25 @@
<template>
<div :class="downLoading ? 'all_disabled' : ''">
<el-dialog v-model="dialogVisible" title="文件信息" width="50%" @closed="handleClose">
<div class="download_progress" v-if="status != 0 && status != 100">
<div v-loading="loading">
<div
class="download_progress"
v-if="mqttFileName.includes(fileNameInfoMation) && status != 0 && status != 100"
>
<div class="progress_left">
正在下载
{{
// fileData?.prjDataPath
// ? fileData?.prjDataPath.split('/')[fileData?.prjDataPath.split('/').length - 1]
// : '/'
fileName
mqttFileName
}}
</div>
<div class="progress_right">
<el-progress :percentage="status" />
</div>
</div>
<el-descriptions title="" style="margin: 10px 0" :column="2" :border="true" v-loading="loading">
<el-descriptions title="" style="margin: 10px 0" :column="2" :border="true">
<el-descriptions-item label="文件名称">
{{
fileData?.prjDataPath
@@ -34,6 +38,8 @@
{{ fileData?.fileCheck ? fileData?.fileCheck : '/' }}
</el-descriptions-item>
</el-descriptions>
</div>
<template #footer>
<div class="dialog-footer download_status">
<el-button @click="handleClose">取消</el-button>
@@ -47,7 +53,11 @@
</template>
<script lang="ts" setup>
import { ref, onMounted, defineExpose, defineProps, onBeforeUnmount, onUnmounted, defineEmits, watch } from 'vue'
import { getFileServiceFileOrDir, downLoadDeviceFile } from '@/api/cs-device-boot/fileService.ts'
import {
getFileServiceFileOrDir,
downLoadDeviceFile,
downLoadDeviceFilePath
} 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)
@@ -55,10 +65,15 @@ const loading = ref(false)
const downLoading = ref(false)
const emit = defineEmits(['downLoadFile'])
const handleClose = () => {
status.value = 0
mqttFileName.value = ''
downLoading.value = false
dialogVisible.value = false
}
//文件信息
const fileData: any = ref({})
//文件名称信息
const fileNameInfoMation = ref<any>('')
const open = async (row: any, id: any) => {
status.value = 0
fileData.value = {}
@@ -69,11 +84,17 @@ const open = async (row: any, id: any) => {
name: row.prjDataPath,
type: row.type
}
await getFileServiceFileOrDir(obj).then(res => {
await getFileServiceFileOrDir(obj).then((res: any) => {
if (res.code == 'A0000') {
if (res.data && res.data.length != 0) {
fileData.value = res.data[0]
fileData.value.nDid = id
if (fileData.value && fileData.value.prjDataPath) {
fileNameInfoMation.value =
fileData.value.prjDataPath.split('/')[fileData.value.prjDataPath.split('/').length - 1]
} else {
fileNameInfoMation.value = '/'
}
}
loading.value = false
}
@@ -90,7 +111,55 @@ const handleDownLoad = () => {
downLoadDeviceFile(obj)
.then((res: any) => {
if (res.code == 'A0000') {
downLoadFile(res.data).then((resp: any) => {
console.log(res, '00000')
// downLoadFile(res.data).then((resp: any) => {
// 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)
// downLoading.value = false
// link.click()
// status.value = 100
// ElMessage.success('文件下载成功')
// link.remove()
// handleClose()
// } else {
// if (resp.code == 'A0000') {
// window.open(res.data, '_blank')
// downLoading.value = false
// ElMessage.success(resp.message)
// handleClose()
// }
// }
// })
}
})
.catch(e => {
console.log(e, '0000000')
if (e) {
downLoading.value = false
}
})
}
onMounted(() => {})
onUnmounted(() => {})
const status = ref(0)
const mqttFileName = ref('')
const setStatus = (val: any) => {
status.value = parseInt(Number((val.nowStep / val.allStep) * 100))
mqttFileName.value = val.fileName
if (status.value == 100) {
downLoadDeviceFilePath({ nDid: fileData.value.nDid, name: fileData.value.prjDataPath }).then((ress: any) => {
console.log(ress, 'a7778888881111')
if (ress.code == 'A0000') {
downLoadFile(ress.data).then((resp: any) => {
if (resp.type != 'application/json') {
// 'application/vnd.ms-excel'
let blob = new Blob([resp], { type: resp.type })
@@ -109,7 +178,7 @@ const handleDownLoad = () => {
handleClose()
} else {
if (resp.code == 'A0000') {
window.open(res.data, '_blank')
window.open(ress.data, '_blank')
downLoading.value = false
ElMessage.success(resp.message)
handleClose()
@@ -118,19 +187,7 @@ const handleDownLoad = () => {
})
}
})
.catch(e => {
if (e) {
downLoading.value = false
}
})
}
onMounted(() => {})
onUnmounted(() => {})
const status = ref(0)
const fileName = ref('')
const setStatus = (val: any) => {
status.value = parseInt(Number((val.nowStep / val.allStep) * 100))
fileName.value = val.fileName
}
defineExpose({ open, setStatus })
</script>