From 0eef1888d7d930f78fb546c765b60ee8d344adae Mon Sep 17 00:00:00 2001 From: cwchen <1048842385@qq.com> Date: Mon, 27 Oct 2025 16:41:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 14 + src/views/common/UploadFile.vue | 42 ++- .../components/EnterpriseKnowledge.vue | 2 +- .../technical/components/RightTable.vue | 2 +- .../technical/components/TypeForm.vue | 43 +++- .../enterpriseLibrary/technical/index.vue | 46 +++- .../tool/components/ToolForm.vue | 242 ++++++++++++++++++ src/views/enterpriseLibrary/tool/config.js | 18 ++ src/views/enterpriseLibrary/tool/index.vue | 212 +++++++++++++++ 9 files changed, 608 insertions(+), 13 deletions(-) create mode 100644 src/views/enterpriseLibrary/tool/components/ToolForm.vue create mode 100644 src/views/enterpriseLibrary/tool/config.js create mode 100644 src/views/enterpriseLibrary/tool/index.vue diff --git a/src/router/index.js b/src/router/index.js index bbfb0d0..37e31e4 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -303,6 +303,20 @@ export const dynamicRoutes = [ } ] }, + { + path: '/tool', + component: Layout, + hidden: true, + permissions: ['enterpriseLibrary:tool:list'], + children: [ + { + path: 'index', + component: () => import('@/views/enterpriseLibrary/tool/index'), + name: 'Tool', + meta: { title: '工器具库', activeMenu: '/enterpriseLibrary/tool', noCache: true } + } + ] + }, ] // 防止连续点击多次路由报错 diff --git a/src/views/common/UploadFile.vue b/src/views/common/UploadFile.vue index 095e2e1..603b87d 100644 --- a/src/views/common/UploadFile.vue +++ b/src/views/common/UploadFile.vue @@ -85,12 +85,14 @@ export default { previewFileType: '', isUploading: false, // 添加上传状态标识 defaultFileSize: 1024 * 1024 * 5, // 默认文件大小5MB 超过5MB算大文件上传 + fileValidationMap: new Map(), // 存储文件验证结果 } }, methods: { beforeUpload(file) { // 如果正在上传中,阻止新的上传 if (this.isUploading) { + this.fileValidationMap.set(file.uid, false); return false; } @@ -103,16 +105,23 @@ export default { // 验证文件大小 const isLtMaxSize = file.size / 1024 / 1024 < this.maxSizeMB; + + let isValid = true; + if (!isAllowedType || !isAllowedMimeType) { this.$message.error(`只能上传 ${this.uploadType} 格式的文件!`); - return false; + isValid = false; } if (!isLtMaxSize) { this.$message.error(`文件大小不能超过 ${this.maxFileTips}!`); - return false; + isValid = false; } + // 存储验证结果 + this.fileValidationMap.set(file.uid, isValid); + + // 返回 false 阻止自动上传,我们将手动控制上传流程 return false; }, // 文件状态改变 @@ -122,7 +131,20 @@ export default { return; } - // 不使用深拷贝,直接使用 fileList,但确保 files 是响应式的 + // 检查文件验证结果 + const isValid = this.fileValidationMap.get(file.uid); + if (isValid === false) { + // 验证失败,从文件列表中移除该文件 + const fileIndex = fileList.findIndex(item => item.uid === file.uid); + if (fileIndex !== -1) { + fileList.splice(fileIndex, 1); + } + this.fileValidationMap.delete(file.uid); + this.files = this.formatFileList(fileList); + return; + } + + // 验证通过,继续处理 this.files = this.formatFileList(fileList); // 生成预览 @@ -140,8 +162,7 @@ export default { } // 如果启用自动上传且文件验证通过,触发上传 - if (this.autoUpload && file.status === 'ready' && !this.isUploading) { - alert(this.fileUploadRule.fields_json); + if (this.autoUpload && file.status === 'ready' && !this.isUploading && isValid !== false) { if (this.fileUploadRule.fields_json) { // 文件需要ocr识别 this.uploadFile(file, '识别中'); @@ -150,6 +171,9 @@ export default { this.uploadFile(file, '上传中'); } } + + // 清理验证结果 + this.fileValidationMap.delete(file.uid); }, // 格式化文件列表,确保数据结构正确 @@ -336,7 +360,13 @@ export default { // 手动触发新文件的上传流程 const newFile = files[0]; - this.beforeUpload(newFile); // 先进行验证 + + // 先进行验证 + const isValid = this.beforeUpload(newFile); + + if (!isValid) { + return; + } // 创建新的文件对象,确保包含 percentage const newFileObj = { diff --git a/src/views/enterpriseLibrary/enterprise/components/EnterpriseKnowledge.vue b/src/views/enterpriseLibrary/enterprise/components/EnterpriseKnowledge.vue index 3b79d17..31e498e 100644 --- a/src/views/enterpriseLibrary/enterprise/components/EnterpriseKnowledge.vue +++ b/src/views/enterpriseLibrary/enterprise/components/EnterpriseKnowledge.vue @@ -76,7 +76,7 @@ export default { description: '工器具库主要用于登记工器具资料信息, 统一管理工器具清单等', icon: enterpriseKnowledgeIcon, path: '/enterpriseLibrary/enterprise/tools', - name: 'Tools' + name: 'Tool' }, { type: 'financial', diff --git a/src/views/enterpriseLibrary/technical/components/RightTable.vue b/src/views/enterpriseLibrary/technical/components/RightTable.vue index ac44025..6950360 100644 --- a/src/views/enterpriseLibrary/technical/components/RightTable.vue +++ b/src/views/enterpriseLibrary/technical/components/RightTable.vue @@ -1,5 +1,5 @@ @@ -165,4 +164,42 @@ export default { display: flex; justify-content: space-between; } + +.confirm-btn { + width: 98px; + height: 36px; + background: #1F72EA; + box-shadow: 0px 4px 8px 0px rgba(51, 135, 255, 0.5); + border-radius: 4px 4px 4px 4px; + color: #fff; + border: none; + font-size: 14px; + transition: all 0.3s; + + &:hover { + background: #4A8BFF; + box-shadow: 0px 6px 12px 0px rgba(51, 135, 255, 0.6); + } +} + +.cancel-btn { + width: 98px; + height: 36px; + background: #E5E5E5; + box-shadow: 0px 4px 8px 0px rgba(76, 76, 76, 0.2); + border-radius: 4px 4px 4px 4px; + color: #333; + border: none; + font-size: 14px; + transition: all 0.3s; + + &:hover { + background: #d0d0d0; + box-shadow: 0px 6px 12px 0px rgba(76, 76, 76, 0.3); + } +} + +::v-deep .el-dialog__footer { + text-align: center; +} \ No newline at end of file diff --git a/src/views/enterpriseLibrary/technical/index.vue b/src/views/enterpriseLibrary/technical/index.vue index bffcb1d..fc725a7 100644 --- a/src/views/enterpriseLibrary/technical/index.vue +++ b/src/views/enterpriseLibrary/technical/index.vue @@ -1,5 +1,11 @@