2024-07-22 10:35:01 +08:00
|
|
|
|
<!-- 离线数据导入 -->
|
|
|
|
|
|
<template>
|
2024-10-30 16:49:08 +08:00
|
|
|
|
<el-dialog v-model="dialogVisible" title="文件列表" width="70%" :destroy-on-close="true" draggable @closed="close">
|
2024-07-22 10:35:01 +08:00
|
|
|
|
<!-- 上传文件列表 -->
|
|
|
|
|
|
<div class="offline_data">
|
|
|
|
|
|
<div class="offline_data_btn">
|
2024-11-01 13:55:45 +08:00
|
|
|
|
<el-button :loading="loading" style="margin-left: 10px" type="primary" @click="submitUpload">
|
2024-11-01 11:21:12 +08:00
|
|
|
|
上传离线数据
|
|
|
|
|
|
</el-button>
|
2024-11-19 10:39:46 +08:00
|
|
|
|
<el-button type="primary" @click="handleUpload" :loading="loading"
|
|
|
|
|
|
:disabled="offLineFileList.length == 0 || disableHandleUpload">
|
2024-07-22 13:16:14 +08:00
|
|
|
|
开始上传
|
|
|
|
|
|
</el-button>
|
2024-11-19 10:39:46 +08:00
|
|
|
|
<el-button type="primary" @click="removeAllFile" :loading="loading"
|
|
|
|
|
|
:disabled="offLineFileList.length == 0">
|
|
|
|
|
|
重置上传文件
|
2024-07-22 13:16:14 +08:00
|
|
|
|
</el-button>
|
2024-07-22 10:35:01 +08:00
|
|
|
|
</div>
|
2024-11-01 13:55:45 +08:00
|
|
|
|
<div :style="tableHeight">
|
2024-11-19 10:39:46 +08:00
|
|
|
|
<vxe-table border auto-resize height="auto" :data="offLineFileList" v-bind="defaultAttribute"
|
|
|
|
|
|
:key="updateKey">
|
2024-11-01 13:55:45 +08:00
|
|
|
|
<vxe-column field="name" align="center" title="文件名"></vxe-column>
|
|
|
|
|
|
<vxe-column field="webkitRelativePath" align="center" title="文件地址"></vxe-column>
|
|
|
|
|
|
<vxe-column field="status" align="center" title="状态" width="250">
|
|
|
|
|
|
<template v-slot:default="scoped">
|
|
|
|
|
|
<el-progress v-if="scoped.row.status == 0" :percentage="0">
|
|
|
|
|
|
<el-button text>等待上传</el-button>
|
|
|
|
|
|
</el-progress>
|
|
|
|
|
|
<el-progress v-if="scoped.row.status == -1" :percentage="30" :indeterminate="true">
|
|
|
|
|
|
<el-button text>上传中...</el-button>
|
|
|
|
|
|
</el-progress>
|
|
|
|
|
|
<el-progress v-if="scoped.row.status == 1" status="success" :percentage="100">
|
|
|
|
|
|
<el-button text>上传成功</el-button>
|
|
|
|
|
|
</el-progress>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</vxe-column>
|
|
|
|
|
|
<vxe-column title="操作" width="200px">
|
|
|
|
|
|
<template v-slot:default="scoped">
|
|
|
|
|
|
<el-button link type="danger" @click="removeFile(scoped.row)">移除</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</vxe-column>
|
|
|
|
|
|
</vxe-table>
|
2024-07-22 10:35:01 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
<div class="dialog-footer">
|
2024-11-01 11:21:12 +08:00
|
|
|
|
<!-- <el-button @click="close">取消</el-button> -->
|
|
|
|
|
|
<el-button type="primary" @click="close">确定</el-button>
|
2024-07-22 10:35:01 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-10-30 16:49:08 +08:00
|
|
|
|
import { ref } from 'vue'
|
2024-07-22 13:16:14 +08:00
|
|
|
|
import { uploadOffLineDataFile } from '@/api/cs-device-boot/EquipmentDelivery.ts'
|
2024-10-30 16:49:08 +08:00
|
|
|
|
import { defaultAttribute } from '@/components/table/defaultAttribute'
|
|
|
|
|
|
import { mainHeight } from '@/utils/layout'
|
2024-07-22 10:35:01 +08:00
|
|
|
|
const dialogVisible = ref(false)
|
|
|
|
|
|
const loading = ref(false)
|
2024-07-22 13:16:14 +08:00
|
|
|
|
const offLineFileList: any = ref([])
|
2024-07-24 14:42:45 +08:00
|
|
|
|
const disableHandleUpload = ref(true)
|
2024-10-30 16:49:08 +08:00
|
|
|
|
const tableHeight = mainHeight(550)
|
2024-07-24 14:42:45 +08:00
|
|
|
|
//上传离线数据
|
2024-10-30 16:49:08 +08:00
|
|
|
|
const submitUpload = (e: any) => {
|
2024-07-22 10:35:01 +08:00
|
|
|
|
const input = document.createElement('input')
|
|
|
|
|
|
input.type = 'file'
|
|
|
|
|
|
input.setAttribute('allowdirs', 'true')
|
|
|
|
|
|
input.setAttribute('directory', 'true')
|
|
|
|
|
|
input.setAttribute('webkitdirectory', 'true')
|
|
|
|
|
|
input.multiple = true
|
|
|
|
|
|
document.querySelector('body').appendChild(input)
|
|
|
|
|
|
// todo 这里增加了input标签,可以给它删掉
|
|
|
|
|
|
input.click()
|
2024-07-23 17:28:31 +08:00
|
|
|
|
input.onchange = function (e) {
|
2024-07-22 10:35:01 +08:00
|
|
|
|
const formData = new FormData()
|
|
|
|
|
|
const file = e.target['files']
|
|
|
|
|
|
for (let i = 0; i < file.length; i++) {
|
|
|
|
|
|
formData.append('files', file[i])
|
|
|
|
|
|
}
|
2024-07-22 13:16:14 +08:00
|
|
|
|
offLineFileList.value = formData.getAll('files')
|
|
|
|
|
|
offLineFileList.value.map((item: any) => {
|
|
|
|
|
|
item.status = 0
|
|
|
|
|
|
})
|
2024-07-24 14:51:51 +08:00
|
|
|
|
disableHandleUpload.value = false
|
2024-07-22 10:35:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-22 13:16:14 +08:00
|
|
|
|
//清空文件
|
|
|
|
|
|
const removeAllFile = () => {
|
|
|
|
|
|
offLineFileList.value = []
|
|
|
|
|
|
}
|
2024-07-22 10:35:01 +08:00
|
|
|
|
//移除文件
|
|
|
|
|
|
const removeFile = async (file: any) => {
|
2024-07-22 13:16:14 +08:00
|
|
|
|
const delIndex = offLineFileList.value.findIndex((item: any) => {
|
|
|
|
|
|
return item.webkitRelativePath == file.webkitRelativePath && item.name == file.name
|
|
|
|
|
|
})
|
|
|
|
|
|
offLineFileList.value.splice(delIndex, 1)
|
|
|
|
|
|
return
|
2024-07-22 10:35:01 +08:00
|
|
|
|
}
|
2024-07-22 13:16:14 +08:00
|
|
|
|
//开始上传
|
2024-07-24 14:42:45 +08:00
|
|
|
|
const updateKey = ref(0)
|
|
|
|
|
|
const handleUpload = () => {
|
|
|
|
|
|
loading.value = true
|
2024-07-23 17:28:31 +08:00
|
|
|
|
const subForm = new FormData()
|
|
|
|
|
|
subForm.append('devId', deviceId.value)
|
|
|
|
|
|
subForm.append('lineId', lineId.value)
|
|
|
|
|
|
let webkitRelativePathList: any = []
|
|
|
|
|
|
offLineFileList.value.map((item: any, index: any) => {
|
|
|
|
|
|
subForm.append(`files[${index}]`, item)
|
|
|
|
|
|
webkitRelativePathList.push(item.webkitRelativePath)
|
|
|
|
|
|
})
|
|
|
|
|
|
subForm.append('paths', webkitRelativePathList.join(','))
|
2024-07-24 14:42:45 +08:00
|
|
|
|
offLineFileList.value.map((item: any) => {
|
|
|
|
|
|
item.status = -1
|
|
|
|
|
|
})
|
|
|
|
|
|
// 操作数据后更新视图
|
|
|
|
|
|
updateKey.value += 1
|
2024-07-24 14:51:51 +08:00
|
|
|
|
disableHandleUpload.value = true
|
2024-07-24 14:42:45 +08:00
|
|
|
|
uploadOffLineDataFile(subForm).then(res => {
|
2024-07-23 17:28:31 +08:00
|
|
|
|
if (res.code == 'A0000') {
|
2024-07-24 14:42:45 +08:00
|
|
|
|
offLineFileList.value.map((item: any) => {
|
|
|
|
|
|
item.status = 1
|
|
|
|
|
|
})
|
|
|
|
|
|
// 操作数据后更新视图
|
|
|
|
|
|
updateKey.value += 1
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
disableHandleUpload.value = true
|
2024-07-22 13:16:14 +08:00
|
|
|
|
}
|
2024-11-19 10:39:46 +08:00
|
|
|
|
}).catch(()=>{
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
disableHandleUpload.value = false
|
|
|
|
|
|
offLineFileList.value.map((item: any) => {
|
|
|
|
|
|
item.status = 0
|
|
|
|
|
|
})
|
|
|
|
|
|
updateKey.value += 1
|
2024-07-22 13:16:14 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-07-23 17:28:31 +08:00
|
|
|
|
const deviceId: any = ref()
|
|
|
|
|
|
const lineId: any = ref()
|
|
|
|
|
|
const open = (devId: any, lineIds: any) => {
|
|
|
|
|
|
deviceId.value = devId
|
|
|
|
|
|
lineId.value = lineIds
|
2024-07-22 10:35:01 +08:00
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
const close = () => {
|
2024-10-30 16:49:08 +08:00
|
|
|
|
offLineFileList.value = []
|
2024-07-22 10:35:01 +08:00
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
defineExpose({ open })
|
|
|
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
.offline_data {
|
|
|
|
|
|
width: 100%;
|
2024-11-19 10:39:46 +08:00
|
|
|
|
|
2024-07-22 10:35:01 +08:00
|
|
|
|
.offline_data_btn {
|
|
|
|
|
|
width: 100%;
|
2024-11-01 13:58:45 +08:00
|
|
|
|
height: 60px;
|
2024-07-22 10:35:01 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|