yanghao hace 1 día
padre
commit
0a934af56f
Se han modificado 2 ficheros con 52 adiciones y 0 borrados
  1. 4 0
      src/api/pms/qhse/index.ts
  2. 48 0
      src/views/pms/qhse/hazard/index.vue

+ 4 - 0
src/api/pms/qhse/index.ts

@@ -180,5 +180,9 @@ export const IotDangerApi = {
   // 修改危险源
   updateDanger: async (data) => {
     return await request.put({ url: `/rq/iot-danger-source/update`, data })
+  },
+  // 导出危险源 Excel
+  exportDanger: async (params) => {
+    return await request.download({ url: `/rq/iot-danger-source/export-excel`, params })
   }
 }

+ 48 - 0
src/views/pms/qhse/hazard/index.vue

@@ -297,6 +297,54 @@ const handleQuery = () => {
   loadTableData()
 }
 
+const downloadFile = (response) => {
+  // 创建 blob 对象
+  const blob = new Blob([response], {
+    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
+  })
+
+  // 获取文件名
+  let fileName = '危险源.xlsx'
+  const disposition = response.headers ? response.headers['content-disposition'] : ''
+  if (disposition) {
+    const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
+    const matches = filenameRegex.exec(disposition)
+    if (matches != null && matches[1]) {
+      fileName = matches[1].replace(/['"]/g, '')
+    }
+  }
+
+  // 创建下载链接
+  const url = window.URL.createObjectURL(blob)
+  const link = document.createElement('a')
+  link.href = url
+  link.setAttribute('download', fileName)
+
+  // 触发下载
+  document.body.appendChild(link)
+  link.click()
+
+  // 清理
+  document.body.removeChild(link)
+  window.URL.revokeObjectURL(url)
+}
+
+const handleExport = async () => {
+  try {
+    exportLoading.value = true
+    // 调用导出接口
+    const response = await IotDangerApi.exportDanger(queryParams)
+
+    // 下载文件
+    downloadFile(response)
+    exportLoading.value = false
+  } catch (error) {
+    ElMessage.error('导出失败,请重试')
+    console.error('导出错误:', error)
+  } finally {
+  }
+}
+
 // 重置查询
 const resetQuery = () => {
   queryParams.riskGrade = '' // 清空风险等级筛选