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

154 lines
5.7 KiB
Vue
Raw Normal View History

2024-08-30 16:34:06 +08:00
<!-- 设备文件下载 -->
<template>
<div :class="downLoading ? 'all_disabled' : ''">
<el-dialog v-model="dialogVisible" title="文件信息" width="50%" @closed="handleClose">
2024-09-20 10:40:35 +08:00
<div class="download_progress" v-if="status != 0 && status != 100">
<div class="progress_left">
正在下载
{{
2024-10-11 09:25:36 +08:00
// fileData?.prjDataPath
// ? fileData?.prjDataPath.split('/')[fileData?.prjDataPath.split('/').length - 1]
// : '/'
fileName
2024-09-20 10:40:35 +08:00
}}
</div>
<div class="progress_right">
<el-progress :percentage="status" />
</div>
</div>
2024-08-30 16:34:06 +08:00
<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]
: '/'
}}
2024-08-30 16:34:06 +08:00
</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>
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-09-20 10:40:35 +08:00
import { ref, onMounted, defineExpose, defineProps, onBeforeUnmount, onUnmounted, defineEmits, watch } from 'vue'
2024-08-30 16:34:06 +08:00
import { getFileServiceFileOrDir, downLoadDeviceFile } from '@/api/cs-device-boot/fileService.ts'
import { ElMessage } from 'element-plus'
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)
const downLoading = ref(false)
const emit = defineEmits(['downLoadFile'])
const handleClose = () => {
dialogVisible.value = false
}
//文件信息
const fileData: any = ref({})
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-09-02 18:19:47 +08:00
await getFileServiceFileOrDir(obj).then(res => {
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-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') {
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)
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') {
window.open(res.data, '_blank')
downLoading.value = false
ElMessage.success(resp.message)
handleClose()
}
}
})
2024-09-02 18:19:47 +08:00
}
})
.catch(e => {
if (e) {
downLoading.value = false
}
})
2024-08-30 16:34:06 +08:00
}
onMounted(() => {})
onUnmounted(() => {})
2024-09-20 10:40:35 +08:00
const status = ref(0)
2024-10-14 15:09:58 +08:00
const fileName = ref('')
2024-09-20 10:40:35 +08:00
const setStatus = (val: any) => {
2024-10-11 09:25:36 +08:00
status.value = parseInt(Number((val.nowStep / val.allStep) * 100))
fileName.value = val.fileName
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-10-14 15:09:58 +08:00
.progress_left {
2024-09-20 10:40:35 +08:00
width: auto;
}
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>