文件服务下载修改

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) { export function reStartDevice(data) {
return createAxios({ return createAxios({

View File

@@ -1,20 +1,20 @@
import createAxios from '@/utils/request' import createAxios from '@/utils/request'
// 更新问题状态 // 更新问题状态
export function auditFeedBack(data:any) { export function auditFeedBack(data: any) {
return createAxios({ return createAxios({
url: '/cs-system-boot/feedback/auditFeedBack', url: '/cs-system-boot/feedback/auditFeedBack',
method: 'post', method: 'post',
params:data params: data
}) })
} }
//下载文件 //下载文件
export function downLoadFile(filePath:any){ export function downLoadFile(filePath: any) {
return createAxios({ return createAxios({
url: '/system-boot/file/download', url: '/system-boot/file/download',
method: 'get', method: 'get',
responseType: 'blob', responseType: 'blob',
params:{filePath:filePath} params: { filePath: filePath }
}) })
} }

View File

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

View File

@@ -2,38 +2,44 @@
<template> <template>
<div :class="downLoading ? 'all_disabled' : ''"> <div :class="downLoading ? 'all_disabled' : ''">
<el-dialog v-model="dialogVisible" title="文件信息" width="50%" @closed="handleClose"> <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="progress_left"> <div
正在下载 class="download_progress"
{{ v-if="mqttFileName.includes(fileNameInfoMation) && status != 0 && status != 100"
// fileData?.prjDataPath >
// ? fileData?.prjDataPath.split('/')[fileData?.prjDataPath.split('/').length - 1] <div class="progress_left">
// : '/' 正在下载
fileName {{
}} // fileData?.prjDataPath
</div> // ? fileData?.prjDataPath.split('/')[fileData?.prjDataPath.split('/').length - 1]
<div class="progress_right"> // : '/'
<el-progress :percentage="status" /> mqttFileName
}}
</div>
<div class="progress_right">
<el-progress :percentage="status" />
</div>
</div> </div>
<el-descriptions title="" style="margin: 10px 0" :column="2" :border="true">
<el-descriptions-item label="文件名称">
{{
fileData?.prjDataPath
? fileData?.prjDataPath.split('/')[fileData?.prjDataPath.split('/').length - 1]
: '/'
}}
</el-descriptions-item>
<el-descriptions-item label="文件大小">
{{ fileData?.size ? fileData?.size + '字节' : '/' }}
</el-descriptions-item>
<el-descriptions-item label="文件时间">
{{ fileData?.startTime ? fileData?.startTime : '/' }}
</el-descriptions-item>
<el-descriptions-item label="文件校验码">
{{ fileData?.fileCheck ? fileData?.fileCheck : '/' }}
</el-descriptions-item>
</el-descriptions>
</div> </div>
<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]
: '/'
}}
</el-descriptions-item>
<el-descriptions-item label="文件大小">
{{ fileData?.size ? fileData?.size + '字节' : '/' }}
</el-descriptions-item>
<el-descriptions-item label="文件时间">
{{ fileData?.startTime ? fileData?.startTime : '/' }}
</el-descriptions-item>
<el-descriptions-item label="文件校验码">
{{ fileData?.fileCheck ? fileData?.fileCheck : '/' }}
</el-descriptions-item>
</el-descriptions>
<template #footer> <template #footer>
<div class="dialog-footer download_status"> <div class="dialog-footer download_status">
<el-button @click="handleClose">取消</el-button> <el-button @click="handleClose">取消</el-button>
@@ -47,7 +53,11 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, onMounted, defineExpose, defineProps, onBeforeUnmount, onUnmounted, defineEmits, watch } from 'vue' 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 { ElMessage } from 'element-plus'
import { downLoadFile } from '@/api/cs-system-boot/manage.ts' import { downLoadFile } from '@/api/cs-system-boot/manage.ts'
const dialogVisible = ref(false) const dialogVisible = ref(false)
@@ -55,10 +65,15 @@ const loading = ref(false)
const downLoading = ref(false) const downLoading = ref(false)
const emit = defineEmits(['downLoadFile']) const emit = defineEmits(['downLoadFile'])
const handleClose = () => { const handleClose = () => {
status.value = 0
mqttFileName.value = ''
downLoading.value = false
dialogVisible.value = false dialogVisible.value = false
} }
//文件信息 //文件信息
const fileData: any = ref({}) const fileData: any = ref({})
//文件名称信息
const fileNameInfoMation = ref<any>('')
const open = async (row: any, id: any) => { const open = async (row: any, id: any) => {
status.value = 0 status.value = 0
fileData.value = {} fileData.value = {}
@@ -69,11 +84,17 @@ const open = async (row: any, id: any) => {
name: row.prjDataPath, name: row.prjDataPath,
type: row.type type: row.type
} }
await getFileServiceFileOrDir(obj).then(res => { await getFileServiceFileOrDir(obj).then((res: any) => {
if (res.code == 'A0000') { if (res.code == 'A0000') {
if (res.data && res.data.length != 0) { if (res.data && res.data.length != 0) {
fileData.value = res.data[0] fileData.value = res.data[0]
fileData.value.nDid = id 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 loading.value = false
} }
@@ -90,7 +111,55 @@ const handleDownLoad = () => {
downLoadDeviceFile(obj) downLoadDeviceFile(obj)
.then((res: any) => { .then((res: any) => {
if (res.code == 'A0000') { 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') { if (resp.type != 'application/json') {
// 'application/vnd.ms-excel' // 'application/vnd.ms-excel'
let blob = new Blob([resp], { type: resp.type }) let blob = new Blob([resp], { type: resp.type })
@@ -109,7 +178,7 @@ const handleDownLoad = () => {
handleClose() handleClose()
} else { } else {
if (resp.code == 'A0000') { if (resp.code == 'A0000') {
window.open(res.data, '_blank') window.open(ress.data, '_blank')
downLoading.value = false downLoading.value = false
ElMessage.success(resp.message) ElMessage.success(resp.message)
handleClose() 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 }) defineExpose({ open, setStatus })
</script> </script>