From a7f48e12bb87f9e7701f65a75caf89dee8141cd7 Mon Sep 17 00:00:00 2001 From: qiankanghui Date: Fri, 10 Jul 2026 10:00:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(eam):=20=E6=B7=BB=E5=8A=A0=E7=82=B9?= =?UTF-8?q?=E6=A3=80=E9=A1=B9=E7=9B=AE=E6=B8=85=E5=8D=95=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在API中新增uploadEamPropertiesItemDetailExcel和downloadEamPropertiesItemDetailTemplate方法 - 在点检模板页面添加导入点检项目按钮和相应的对话框组件 - 实现点检项目文件上传、模板下载和导入确认逻辑 - 添加点检项目导入相关的数据属性和方法 - 实现点检项目模板下载功能和对话框关闭清理逻辑 --- src/api/eam/eam.js | 2 + src/views/modules/eam/eamPropertiesModel.vue | 195 +++++++++++++++++-- 2 files changed, 186 insertions(+), 11 deletions(-) diff --git a/src/api/eam/eam.js b/src/api/eam/eam.js index c8d8db0..582a53d 100644 --- a/src/api/eam/eam.js +++ b/src/api/eam/eam.js @@ -77,6 +77,8 @@ export const deleteItemAvailable = data => createAPI(`/pms/eam/deleteItemAvailab export const deleteModalDetail = data => createAPI(`/pms/eam/deleteModalDetail`,'post',data) export const uploadEamPropertiesItemExcel = data => createAPI(`/pms/eam/uploadEamPropertiesItemExcel`,'post',data) export const downloadEamPropertiesItemTemplate = () => createAPI(`/pms/eam/downloadEamPropertiesItemTemplate`,'get',{},'download') +export const uploadEamPropertiesItemDetailExcel = data => createAPI(`/pms/eam/uploadEamPropertiesItemDetailExcel`,'post',data) +export const downloadEamPropertiesItemDetailTemplate = () => createAPI(`/pms/eam/downloadEamPropertiesItemDetailTemplate`,'get',{},'download') //---------------维保项目------------------------ export const uploadEamMaintenanceItemExcel = data => createAPI(`/pms/eam/uploadEamMaintenanceItemExcel`,'post',data) diff --git a/src/views/modules/eam/eamPropertiesModel.vue b/src/views/modules/eam/eamPropertiesModel.vue index a1ebe67..103efe2 100644 --- a/src/views/modules/eam/eamPropertiesModel.vue +++ b/src/views/modules/eam/eamPropertiesModel.vue @@ -42,6 +42,7 @@ 查询 新增 导入 + 导入点检项目 {{'导出'}} {{'导出明细'}} @@ -411,6 +412,48 @@ + + + @@ -433,7 +476,9 @@ goDownItemEam, uploadEamPropertiesModelExcel, // 导入点检模板Excel downloadEamPropertiesModelTemplate, // 下载点检模板导入模板 - } from "@/api/eam/eam.js" + uploadEamPropertiesItemDetailExcel, // 导入点检项目清单Excel + downloadEamPropertiesItemDetailTemplate // 下载点检项目清单导入模板 + } from '@/api/eam/eam.js' import {getTableDefaultListLanguage, getTableUserListLanguage} from "@/api/table.js" import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js' import Chooselist from '@/views/modules/common/Chooselist_eam' @@ -1228,6 +1273,11 @@ uploadFileName: '', uploadFile: null, uploadBu: '', // 上传时选择的BU + // 导入点检项目相关 + uploadItemDialogVisible: false, + uploadItemFileName: '', + uploadItemFile: null, + uploadItemBu: '', // 导入点检项目时选择的BU } }, @@ -1861,6 +1911,56 @@ }) }, + // 导入点检项目 + importItemExcel () { + this.uploadItemDialogVisible = true + this.uploadItemFileName = '' + this.uploadItemFile = null + // 清空el-upload组件的文件列表 + if (this.$refs.uploadItemFile) { + this.$refs.uploadItemFile.clearFiles() + } + }, + + // 点检项目文件选择变化 + handleItemFileChange (file) { + this.uploadItemFile = file.raw + this.uploadItemFileName = file.name + }, + + // 确认导入点检项目 + confirmItemUpload () { + if (!this.uploadItemFile) { + this.$message.warning('请先选择文件') + return + } + + const formData = new FormData() + formData.append('file', this.uploadItemFile) + formData.append('userId', this.$store.state.user.name) + + // 调用后端导入接口 + uploadEamPropertiesItemDetailExcel(formData).then(({data}) => { + if (data.code === 0) { + this.$message.success(data.msg || '导入成功') + this.uploadItemDialogVisible = false + // 清空文件信息 + this.uploadItemFileName = '' + this.uploadItemFile = null + if (this.$refs.uploadItemFile) { + this.$refs.uploadItemFile.clearFiles() + } + this.getDataList() + } else { + this.$message.error(data.msg || '导入失败') + } + }).catch((error) => { + console.error('导入失败:', error) + const errorMsg = (error.response && error.response.data && error.response.data.msg) || error.message || '未知错误' + this.$message.error('导入失败: ' + errorMsg) + }) + }, + // 下载模板 downloadTemplate () { const loading = this.$loading({ @@ -1874,54 +1974,118 @@ const xhr = new XMLHttpRequest() xhr.open('GET', this.$http.adornUrl('/pms/eam/downloadEamPropertiesModelTemplate'), true) xhr.responseType = 'blob' - + // 添加token const token = this.$cookie.get('token') if (token) { xhr.setRequestHeader('token', token) } - + xhr.onload = () => { loading.close() - + if (xhr.status === 200) { const blob = xhr.response - + // 验证Blob大小 if (blob.size === 0) { this.$message.error('模板文件为空,请联系管理员') return } - + // 创建下载链接 const url = window.URL.createObjectURL(blob) const link = document.createElement('a') link.href = url link.download = '点检模板导入模板.xlsx' link.style.display = 'none' - + + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + + // 释放URL对象 + setTimeout(() => { + window.URL.revokeObjectURL(url) + }, 100) + + this.$message.success('模板下载成功') + } else { + console.error('模板下载失败,状态码:', xhr.status) + this.$message.error('模板下载失败:服务器错误') + } + } + + xhr.onerror = () => { + loading.close() + console.error('网络错误') + this.$message.error('模板下载失败:网络错误') + } + + xhr.send() + }, + + // 下载点检项目模板 + downloadItemTemplate () { + const loading = this.$loading({ + lock: true, + text: '正在下载模板...', + spinner: 'el-icon-loading', + background: 'rgba(0, 0, 0, 0.7)' + }) + + // 使用原生XMLHttpRequest处理文件下载,避免axios拦截器干扰 + const xhr = new XMLHttpRequest() + xhr.open('GET', this.$http.adornUrl('/pms/eam/downloadEamPropertiesItemDetailTemplate'), true) + xhr.responseType = 'blob' + + // 添加token + const token = this.$cookie.get('token') + if (token) { + xhr.setRequestHeader('token', token) + } + + xhr.onload = () => { + loading.close() + + if (xhr.status === 200) { + const blob = xhr.response + + // 验证Blob大小 + if (blob.size === 0) { + this.$message.error('模板文件为空,请联系管理员') + return + } + + // 创建下载链接 + const url = window.URL.createObjectURL(blob) + const link = document.createElement('a') + link.href = url + link.download = '点检项目清单导入模板.xlsx' + link.style.display = 'none' + document.body.appendChild(link) link.click() document.body.removeChild(link) - + // 释放URL对象 setTimeout(() => { window.URL.revokeObjectURL(url) }, 100) - + this.$message.success('模板下载成功') } else { console.error('模板下载失败,状态码:', xhr.status) this.$message.error('模板下载失败:服务器错误') } } - + xhr.onerror = () => { loading.close() console.error('网络错误') this.$message.error('模板下载失败:网络错误') } - + xhr.send() }, @@ -1934,6 +2098,15 @@ this.$refs.uploadFile.clearFiles() } }, + + // 关闭点检项目上传对话框时清空文件 + handleUploadItemDialogClose () { + this.uploadItemFileName = '' + this.uploadItemFile = null + if (this.$refs.uploadItemFile) { + this.$refs.uploadItemFile.clearFiles() + } + } } }