Files
admin-govern/src/views/govern/device/fileService/popup.vue

213 lines
8.1 KiB
Vue
Raw Normal View History

2024-08-30 16:34:06 +08:00
<!-- 设备文件下载 -->
<template>
<div :class="downLoading ? 'all_disabled' : ''">
2024-12-25 10:53:07 +08:00
<el-dialog v-model.trim="dialogVisible" title="文件信息" width="50%" @closed="handleClose">
2024-10-25 16:03:44 +08:00
<div v-loading="loading">
2024-11-08 14:02:27 +08:00
<div class="download_progress"
v-if="mqttFileName.includes(fileNameInfoMation) && status != 0 && status != 100">
2024-10-25 16:03:44 +08:00
<div class="progress_left">
正在下载
{{
// fileData?.prjDataPath
2024-11-08 14:02:27 +08:00
// ? fileData?.prjDataPath.split('/')[fileData?.prjDataPath.split('/').length - 1]
// : '/'
2024-10-25 16:03:44 +08:00
mqttFileName
}}
</div>
<div class="progress_right">
<el-progress :percentage="status" />
</div>
2024-09-20 10:40:35 +08:00
</div>
2024-10-25 16:03:44 +08:00
<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>
2024-09-20 10:40:35 +08:00
</div>
2024-10-25 16:03:44 +08:00
2024-08-30 16:34:06 +08:00
<template #footer>
2024-09-20 10:40:35 +08:00
<div class="dialog-footer download_status">
2024-08-30 16:34:06 +08:00
<el-button @click="handleClose">取消</el-button>
2024-09-12 11:35:26 +08:00
<el-button type="primary" @click="handleDownLoad" :disabled="loading" :loading="downLoading">
2024-08-30 16:34:06 +08:00
{{ downLoading ? '下载中...' : '下载' }}
</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script lang="ts" setup>
2024-10-30 15:02:25 +08:00
import { ref, onMounted, defineExpose, onUnmounted, defineEmits } from 'vue'
2024-10-25 16:03:44 +08:00
import {
getFileServiceFileOrDir,
downLoadDeviceFile,
downLoadDeviceFilePath
} from '@/api/cs-device-boot/fileService.ts'
import { ElMessage } from 'element-plus'
2024-11-08 14:02:27 +08:00
import { useAdminInfo } from '@/stores/adminInfo'
import { downLoadFile } from '@/api/cs-system-boot/manage.ts'
2024-08-30 16:34:06 +08:00
const dialogVisible = ref(false)
const loading = ref(false)
2024-11-08 14:02:27 +08:00
const adminInfo = useAdminInfo()
2024-08-30 16:34:06 +08:00
const downLoading = ref(false)
const emit = defineEmits(['downLoadFile'])
const handleClose = () => {
2024-10-25 16:03:44 +08:00
status.value = 0
mqttFileName.value = ''
downLoading.value = false
2024-08-30 16:34:06 +08:00
dialogVisible.value = false
}
//文件信息
const fileData: any = ref({})
2024-10-25 16:03:44 +08:00
//文件名称信息
const fileNameInfoMation = ref<any>('')
2024-09-02 18:19:47 +08:00
const open = async (row: any, id: any) => {
2024-10-14 15:09:58 +08:00
status.value = 0
fileData.value = {}
2024-08-30 16:34:06 +08:00
dialogVisible.value = true
2024-09-02 18:19:47 +08:00
loading.value = true
2024-08-30 16:34:06 +08:00
const obj = {
nDid: id,
name: row.prjDataPath,
type: row.type
}
2024-10-25 16:03:44 +08:00
await getFileServiceFileOrDir(obj).then((res: any) => {
2024-08-30 16:34:06 +08:00
if (res.code == 'A0000') {
if (res.data && res.data.length != 0) {
fileData.value = res.data[0]
fileData.value.nDid = id
2024-10-25 16:03:44 +08:00
if (fileData.value && fileData.value.prjDataPath) {
fileNameInfoMation.value =
fileData.value.prjDataPath.split('/')[fileData.value.prjDataPath.split('/').length - 1]
} else {
fileNameInfoMation.value = '/'
}
}
2024-08-30 16:34:06 +08:00
loading.value = false
}
})
}
const handleDownLoad = () => {
const obj = {
nDid: fileData.value.nDid,
name: fileData.value.prjDataPath,
size: fileData.value.size,
fileCheck: fileData.value.fileCheck
}
downLoading.value = true
2024-09-02 18:19:47 +08:00
downLoadDeviceFile(obj)
.then((res: any) => {
2024-09-02 18:19:47 +08:00
if (res.code == 'A0000') {
2024-10-25 16:03:44 +08:00
// 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
}
})
}
2024-11-08 14:02:27 +08:00
onMounted(() => { })
onUnmounted(() => { })
2024-10-25 16:03:44 +08:00
const status = ref(0)
const mqttFileName = ref('')
const setStatus = (val: any) => {
2024-11-08 14:02:27 +08:00
status.value = parseInt(Number((val.nowStep / val.allStep) * 100)) || 0
2024-10-25 16:03:44 +08:00
mqttFileName.value = val.fileName
2024-11-08 14:02:27 +08:00
if (adminInfo.userIndex != val.userId) return
downLoading.value = true
2024-10-25 16:03:44 +08:00
if (status.value == 100) {
downLoadDeviceFilePath({ nDid: fileData.value.nDid, name: fileData.value.prjDataPath }).then((ress: any) => {
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 })
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)
2024-09-11 20:17:38 +08:00
downLoading.value = false
link.click()
2024-09-20 10:40:35 +08:00
status.value = 100
2024-09-11 20:17:38 +08:00
ElMessage.success('文件下载成功')
link.remove()
2024-09-12 10:03:12 +08:00
handleClose()
} else {
if (resp.code == 'A0000') {
2024-10-25 16:03:44 +08:00
window.open(ress.data, '_blank')
downLoading.value = false
ElMessage.success(resp.message)
handleClose()
}
}
})
2024-09-02 18:19:47 +08:00
}
})
2024-10-25 16:03:44 +08:00
}
2024-09-20 10:40:35 +08:00
}
defineExpose({ open, setStatus })
2024-08-30 16:34:06 +08:00
</script>
<style lang="scss" scoped>
2024-09-20 10:40:35 +08:00
.download_progress {
display: flex;
width: 100%;
margin: 10px 0;
align-items: center;
justify-content: space-between;
2024-11-08 14:02:27 +08:00
2024-10-14 15:09:58 +08:00
.progress_left {
2024-09-20 10:40:35 +08:00
width: auto;
}
2024-11-08 14:02:27 +08:00
2024-10-14 15:09:58 +08:00
.progress_right {
flex: 1;
2024-09-20 10:40:35 +08:00
padding-left: 10px;
box-sizing: border-box;
}
2024-08-30 16:34:06 +08:00
}
</style>