吉安感知网项目-前端
张含笑
2026-01-28 6b4d23b2f62d5685b7909a301db6f4c7ecf52a30
applications/task-work-order/src/views/orderView/orderManage/inspectionReport/index.vue
@@ -47,7 +47,11 @@
               <el-table-column type="selection" width="46" />
               <el-table-column type="index" width="64" label="序号" />
               <el-table-column prop="nickName" show-overflow-tooltip label="文档名称" />
               <el-table-column prop="attachSize" show-overflow-tooltip label="文档大小" />
               <el-table-column prop="attachSize" show-overflow-tooltip label="文档大小">
                  <template v-slot="{ row }">
                  {{ formatFileSize(row.attachSize) }}
                  </template>
               </el-table-column>
               <el-table-column prop="deptName" show-overflow-tooltip label="文档归属" />
               <!-- <el-table-column prop="resultType" show-overflow-tooltip label="文档类型" /> -->
               <el-table-column prop="resultType" show-overflow-tooltip label="文档类型">
@@ -138,10 +142,10 @@
</template>
<script setup>
import { Search, RefreshRight, Download, Upload, Delete } from '@element-plus/icons-vue'
import { fjPageApi, fjSubmitApi, fjRemoveApi, fjDetailApi, fjUploadApi } from './inspectionRequestApi'
import { fjPageApi, fjSubmitApi, fjRemoveApi, fjDetailApi, fjUploadApi,fjDownloadByByteApi } from './inspectionRequestApi'
import { useStore } from 'vuex'
import { ref, computed, inject, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ElMessage, ElMessageBox, ElLoading } from 'element-plus'
import { getDictLabel } from '@ztzf/utils'
import PreviewFiles from '@/components/PreviewFiles/PreviewFiles.vue'
import { getDictionaryByCode } from '@/api/system/dictbiz'
@@ -203,6 +207,15 @@
   })
}
// 将字节大小转换为可读格式的函数
const formatFileSize = (bytes) => {
  if (bytes === 0 || bytes === null) return '0 B'
  const k = 1024
  const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
  const i = Math.floor(Math.log(bytes) / Math.log(k))
  return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
}
// 获取列表
async function getList() {
   loading.value = true
@@ -261,9 +274,9 @@
   const fileType = row?.link?.split('.').pop() || ''
   if (!row.link) {
      ElMessage.warning('文件链接不存在')
   }else if (allSupportedExtensions.includes(fileType)){
   } else if (allSupportedExtensions.includes(fileType)){
      window.open(`${VITE_APP_PREVIEW_URL}/onlinePreview?url=`+encodeURIComponent(Base64.encode(row.link)));
   }else {
   } else {
      ElMessage.warning(`${fileType}文件格式,可以下载再查看`)
   }
}
@@ -289,7 +302,7 @@
   selectedFiles.value = rows
   selectedIds.value = rows.map(item => item.id)
}
let loadingData
// 文档下载
async function handleDownload() {
   // 如果是勾选一个可以直接下载,超过一个打包下载
@@ -298,8 +311,9 @@
      ElMessage.warning('请选择要下载的文件')
      return
   }
   selectedFiles.value.forEach((file, index) => {
      setTimeout(() => {
   if (selectedFiles.value.length === 1) {
      selectedFiles.value.forEach((file, index) => {
         // setTimeout(() => {
         if (file.link) {
            const a = document.createElement('a')
            a.href = file.link
@@ -308,8 +322,32 @@
            a.click()
            document.body.removeChild(a)
         }
      }, index * 300) // 300ms delay between downloads
   })
         // }, index * 300) // 300ms delay between downloads
      })
   } else {
      // 批量下载
      try {
         console.log(selectedFiles.value, '9999')
         loadingData = ElLoading.service({ background: 'rgba(0, 0, 0, 0.5)', text: '打包中,请稍等...' })
         const fileIds = selectedFiles.value.map(i => i.id)
         // const res = await getDownloadStatusApi({ type: 'dpsjzx' })
         // if (!['CANCELLED', 'COMPLETED'].includes(res.data.data?.status || 'COMPLETED')) {
         //    return ElMessage.warning('还有正在处理的')
         // }
         console.log(fileIds, '7777')
         await fjDownloadByByteApi({ attachIds: fileIds }).then(res => {
            if (res.data.code === 200) {
               ElMessage.success('下载成功')
            } else {
               ElMessage.error(res.msg || '下载失败')
            }
         })
      } catch (e) {
      } finally {
         loadingData.close()
      }
   }
}
// 文档上传
@@ -322,6 +360,8 @@
function onUploadFileBefore(file) {
   // 执行文件上传
   let data = new FormData()
   // 获取文件扩展名
  const fileExtension = file.name.split('.').pop().toLowerCase();
   data.append('file', file)
   fjUploadApi(data).then(res => {
@@ -330,6 +370,11 @@
         // 保存文件URL到表单
         uploadName.value = res.data.data.originalName
         editParams.value.link = res.data.data.link
         editParams.value.name = res.data.data.name
         editParams.value.originalName = res.data.data.originalName
         editParams.value.attachSize = file.size;
         editParams.value.extension = fileExtension
         editParams.value.domainUrl = res.data.data.link.replace(res.data.data.name, '')
      } else {
         ElMessage.error(res.msg || '上传失败')
      }