|
@@ -297,6 +297,54 @@ const handleQuery = () => {
|
|
|
loadTableData()
|
|
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 = () => {
|
|
const resetQuery = () => {
|
|
|
queryParams.riskGrade = '' // 清空风险等级筛选
|
|
queryParams.riskGrade = '' // 清空风险等级筛选
|