From 9876e6c542baf9a8302b689f0f80c7aba05c4100 Mon Sep 17 00:00:00 2001 From: cwchen <1048842385@qq.com> Date: Wed, 17 Sep 2025 11:30:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=A3=E6=A1=88=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../archCatalogue/components/addTreeData.vue | 4 +- .../archCatalogue/components/leftTree.vue | 7 +- .../fileManager/components/addTableData.vue | 271 ++++++++++++++---- .../fileManager/components/addTreeData.vue | 16 +- .../fileManager/components/leftTree.vue | 15 +- .../fileManager/components/rightTable.vue | 2 + 6 files changed, 242 insertions(+), 73 deletions(-) diff --git a/src/views/archivesManagement/archClass/archCatalogue/components/addTreeData.vue b/src/views/archivesManagement/archClass/archCatalogue/components/addTreeData.vue index d6f3742..fbe24a2 100644 --- a/src/views/archivesManagement/archClass/archCatalogue/components/addTreeData.vue +++ b/src/views/archivesManagement/archClass/archCatalogue/components/addTreeData.vue @@ -174,10 +174,10 @@ export default { } else { // 新增模式:重置表单 this.form = { - parentId: this.rowData.id, + parentId: this.rowData && this.rowData.id ? this.rowData.id : undefined, contentName: null, sort: 0, - level:this.rowData.level + level:this.rowData && this.rowData.level ? this.rowData.level : undefined }; value = this.rowData.id; } diff --git a/src/views/archivesManagement/archClass/archCatalogue/components/leftTree.vue b/src/views/archivesManagement/archClass/archCatalogue/components/leftTree.vue index f6f95ea..9f97e72 100644 --- a/src/views/archivesManagement/archClass/archCatalogue/components/leftTree.vue +++ b/src/views/archivesManagement/archClass/archCatalogue/components/leftTree.vue @@ -65,6 +65,7 @@ export default { originalTreeData: [], // 保存原始数据, isflag: false, isAdd: '', + title:'', row: {}, selectedNodeId: null, // 保存当前选中的节点ID delArchiveApi @@ -111,8 +112,10 @@ export default { this.title = "新增"; this.isAdd = 'add'; this.isflag = true; - this.row = data; - this.row.level = Number(data.level) + 1 + if(data){ + this.row = data; + this.row.level = Number(data.level) + 1 + } }, /* 修改树节点 */ editTree(row, data) { diff --git a/src/views/archivesManagement/fileManager/components/addTableData.vue b/src/views/archivesManagement/fileManager/components/addTableData.vue index fd33e27..5cec8c3 100644 --- a/src/views/archivesManagement/fileManager/components/addTableData.vue +++ b/src/views/archivesManagement/fileManager/components/addTableData.vue @@ -12,16 +12,16 @@ placeholder="请输入文件题名" maxlength="64" :disabled="detailStatus"> - + - + - - + + + + + 选择文件 + + 只能上传PDF和图片文件,且不超过10MB + + + @@ -50,18 +72,19 @@ import { addArchiveRightApi, editArchiveRightApi, } from '@/api/archivesManagement/index.js' -import {getClassifyMarkSelApi} from '@/api/select.js' +import { getClassifyMarkSelApi } from '@/api/select.js' +import { getToken } from '@/utils/auth' export default { name: "FileAddTableData", - props: ["width", "dataForm", "title", "disabled", "isAdd", "rowData","projectId"], - dicts: ['mark_code'], + props: ["width", "dataForm", "title", "disabled", "isAdd", "rowData", "projectId"], + dicts: ['mark_code','file_size_limit'], data() { return { lDialog: this.width > 500 ? "w700" : "w500", dialogVisible: true, isDisabled: true, getClassifyMarkSelApi, - classifyMarkList : [], + classifyMarkList: [], form: { contentName: null, term: null, @@ -70,9 +93,17 @@ export default { markCode: null, classifyMark: null, }, - belongName:'', + belongName: '', loading: null, - detailStatus:false, + detailStatus: false, + // 文件上传相关 + fileList: [], + uploadUrl: process.env.VUE_APP_BASE_API + '/smartArchives/file/upload', + uploadHeaders: { + 'Authorization': 'Bearer ' + getToken() + }, + uploadData: {}, + maxFileSize: 10 * 1024 * 1024, // 默认10MB rules: { contentName: [ { required: true, message: '文件题名不能为空', trigger: 'blur' } @@ -98,13 +129,32 @@ export default { created() { this.initFormData(); }, + mounted() { + // 在mounted生命周期中再次尝试获取字典数据 + this.$nextTick(() => { + if (this.dict && this.dict.type && this.dict.type.file_size_limit) { + const fileSizeLimit = this.dict.type.file_size_limit; + if (Array.isArray(fileSizeLimit) && fileSizeLimit.length > 0) { + const firstValue = fileSizeLimit[0].value; + // 更新最大文件大小限制 + if (firstValue && !isNaN(firstValue)) { + this.maxFileSize = parseInt(firstValue); + } + } + } + }); + }, methods: { /** 初始化表单数据 */ - async initFormData() { - const res = await getClassifyMarkSelApi(); - this.classifyMarkList = res.data; - this.belongName = this.rowData.belongName; - this.detailStatus = this.rowData.detailStatus; + async initFormData() { + // 等待字典数据加载完成 + await this.$nextTick(); + const fileSizeLimit = this.dict.type.file_size_limit; + const firstFileSizeLimit = fileSizeLimit && Array.isArray(fileSizeLimit) && fileSizeLimit.length > 0 ? fileSizeLimit[0].value : null; + const res = await getClassifyMarkSelApi(); + this.classifyMarkList = res.data; + this.belongName = this.rowData.belongName; + this.detailStatus = this.rowData.detailStatus; if ((this.isAdd === 'edit' || this.isAdd === 'detail') && this.rowData) { // 编辑模式:填充表单数据 this.form = { @@ -115,8 +165,8 @@ export default { unitName: this.rowData.unitName || null, markCode: this.rowData.markCode || null, classifyMark: this.rowData.classifyMark || null, - parentId:this.rowData.parentId || null, - level:4 + parentId: this.rowData.parentId || null, + level: 4 }; } else { // 新增模式:重置表单 @@ -127,8 +177,8 @@ export default { major: null, markCode: null, classifyMark: null, - parentId:this.rowData.id || null, - level:4 + parentId: this.rowData.id || null, + level: 4 }; } }, @@ -157,9 +207,11 @@ export default { major: null, markCode: null, classifyMark: null, - parentId:null, - level:4 + parentId: null, + level: 4 }; + this.fileList = []; + this.$refs.upload && this.$refs.upload.clearFiles(); this.resetForm("ruleForm"); }, handleReuslt(res) { @@ -168,46 +220,159 @@ export default { this.$emit('handleQuery'); this.handleClose(); }, + // 上传前验证 + beforeUpload(file) { + const isValidType = this.checkFileType(file) + const isValidSize = this.checkFileSize(file) + + if (!isValidType) { + this.$message.error('只能上传PDF和图片文件!') + return false + } + if (!isValidSize) { + this.$message.error('文件大小不能超过10MB!') + return false + } + + // 检查是否已有文件 + if (this.fileList.length >= 1) { + this.$message.warning('只能上传一个文件,请先删除现有文件!') + return false + } + + // 设置上传数据 + this.uploadData = { + projectId: this.projectId, + categoryId: this.form.parentId || 0, + description: this.form.contentName || '' + } + + return true + }, + // 检查文件类型 + checkFileType(file) { + const allowedTypes = [ + 'application/pdf', + 'image/jpeg', + 'image/jpg', + 'image/png', + 'image/gif', + 'image/bmp' + ] + return allowedTypes.includes(file.type) + }, + // 检查文件大小 + checkFileSize(file) { + const maxSize = this.maxFileSize || (10 * 1024 * 1024) // 使用动态配置或默认10MB + return file.size <= maxSize + }, + // 上传成功 + handleUploadSuccess(response, file, fileList) { + if (response.code === 200) { + this.$message.success('文件上传成功!') + } else { + this.$message.error(response.msg || '上传失败') + } + }, + // 上传失败 + handleUploadError(error, file, fileList) { + this.$message.error('文件上传失败,请重试') + console.error('Upload error:', error) + }, + // 移除文件 + handleRemove(file, fileList) { + this.fileList = fileList + }, + // 上传文件 + uploadFiles() { + return new Promise((resolve, reject) => { + if (this.fileList.length === 0) { + resolve(); + return; + } + + let uploadPromises = this.fileList.map(file => { + return new Promise((fileResolve, fileReject) => { + const formData = new FormData(); + formData.append('file', file.raw); + formData.append('projectId', this.projectId); + formData.append('categoryId', this.form.parentId || 0); + formData.append('description', this.form.contentName || ''); + + this.$http.post(this.uploadUrl, formData, { + headers: this.uploadHeaders + }).then(response => { + if (response.data.code === 200) { + fileResolve(response.data); + } else { + fileReject(new Error(response.data.msg || '上传失败')); + } + }).catch(error => { + fileReject(error); + }); + }); + }); + + Promise.all(uploadPromises).then(() => { + resolve(); + }).catch(error => { + reject(error); + }); + }); + }, /**验证 */ submitForm(formName) { this.$refs[formName].validate(valid => { if (valid) { - // 显示遮罩层 - this.loading = this.$loading({ - lock: true, - text: "数据提交中,请稍候...", - background: 'rgba(0,0,0,0.5)', - target: this.$el.querySelector('.el-dialog') || document.body - }) - let params = _.cloneDeep(this.form); - - if (this.isAdd === 'add') { - addArchiveRightApi(params).then(res => { - this.loading.close(); - if (res.code === 200) { - this.handleReuslt(res); - } else { - this.$modal.msgError(res.msg); - } + // 如果有文件需要上传,先上传文件 + if (this.fileList.length > 0) { + this.uploadFiles().then(() => { + this.submitFormData(); }).catch(error => { - this.loading.close(); - // this.$modal.msgError('提交失败,请重试'); + this.$message.error('文件上传失败,请重试'); }); } else { - editArchiveRightApi(params).then(res => { - this.loading.close(); - if (res.code === 200) { - this.handleReuslt(res); - } else { - this.$modal.msgError(res.msg); - } - }).catch(error => { - this.loading.close(); - // this.$modal.msgError('提交失败,请重试'); - }); + this.submitFormData(); } } }); + }, + // 提交表单数据 + submitFormData() { + // 显示遮罩层 + this.loading = this.$loading({ + lock: true, + text: "数据提交中,请稍候...", + background: 'rgba(0,0,0,0.5)', + target: this.$el.querySelector('.el-dialog') || document.body + }) + let params = _.cloneDeep(this.form); + + if (this.isAdd === 'add') { + addArchiveRightApi(params).then(res => { + this.loading.close(); + if (res.code === 200) { + this.handleReuslt(res); + } else { + this.$modal.msgError(res.msg); + } + }).catch(error => { + this.loading.close(); + // this.$modal.msgError('提交失败,请重试'); + }); + } else { + editArchiveRightApi(params).then(res => { + this.loading.close(); + if (res.code === 200) { + this.handleReuslt(res); + } else { + this.$modal.msgError(res.msg); + } + }).catch(error => { + this.loading.close(); + // this.$modal.msgError('提交失败,请重试'); + }); + } } } }; diff --git a/src/views/archivesManagement/fileManager/components/addTreeData.vue b/src/views/archivesManagement/fileManager/components/addTreeData.vue index dc6432e..3e9dcae 100644 --- a/src/views/archivesManagement/fileManager/components/addTreeData.vue +++ b/src/views/archivesManagement/fileManager/components/addTreeData.vue @@ -34,19 +34,17 @@ import _ from 'lodash' import Treeselect from "@riophae/vue-treeselect"; import "@riophae/vue-treeselect/dist/vue-treeselect.css"; import { getFileManageTreeByAddOrUpdateApi, addFileManageLeftApi, updateFileManageLeftApi,geMaxSortApi } from '@/api/archivesManagement/fileManager/fileManager.js' -import { Alert } from 'element-ui'; export default { name: "FileAddTreeData", - props: ["width", "dataForm", "title", "disabled", "isAdd", "rowData"], + props: ["width", "dataForm", "title", "disabled", "isAdd", "rowData","projectId"], components: { Treeselect }, - props: ["projectId"], data() { return { lDialog: this.width > 500 ? "w700" : "w500", dialogVisible: true, isDisabled: true, form: { - parentId: '', + parentId: undefined, contentName: '', sort: 1, }, @@ -168,7 +166,7 @@ export default { // 编辑模式:填充表单数据 this.form = { id: this.rowData.id, - parentId: this.rowData.parentId || 0, + parentId: this.rowData.parentId || undefined, contentName: this.rowData.label || null, sort: this.rowData.sort || 0, level:this.rowData.level, @@ -178,10 +176,10 @@ export default { } else { // 新增模式:重置表单 this.form = { - parentId: this.rowData.id, + parentId: this.rowData && this.rowData.id ? this.rowData.id : undefined, contentName: null, sort: 0, - level:this.rowData.level, + level:this.rowData && this.rowData.level ? this.rowData.level : undefined, proId:this.projectId }; value = this.rowData.id; @@ -203,8 +201,8 @@ export default { } return data.map(item => { - // 如果当前节点层级为3,则跳过 - if (item.level === 3) { + // 如果当前节点层级为4,则跳过 + if (item.level === 4) { return null; } diff --git a/src/views/archivesManagement/fileManager/components/leftTree.vue b/src/views/archivesManagement/fileManager/components/leftTree.vue index a8c46ce..bc41c16 100644 --- a/src/views/archivesManagement/fileManager/components/leftTree.vue +++ b/src/views/archivesManagement/fileManager/components/leftTree.vue @@ -47,7 +47,7 @@ - @@ -55,10 +55,10 @@