smart_archives_web/src/views/archivesManagement/fileManager/components/addTableData.vue

427 lines
16 KiB
Vue
Raw Normal View History

2025-09-16 14:37:37 +08:00
<template>
<!-- 小型弹窗用于完成删除保存等操作 -->
<el-dialog class="l-dialog" :class="lDialog" :title="title" :visible.sync="dialogVisible" :showClose="true"
:closeOnClickModal="false" @close="handleClose" :append-to-body="true">
<div>
<el-form :model="form" :rules="rules" ref="ruleForm" label-width="110px">
<el-form-item label="所属案卷">
<el-input type="textarea" class="form-item" :value="belongName" :disabled="true"></el-input>
</el-form-item>
2025-09-17 17:07:50 +08:00
<el-form-item label="档案名称" prop="contentName">
2025-09-16 14:37:37 +08:00
<el-input type="textarea" class="form-item" v-model="form.contentName" clearable show-word-limit
2025-09-17 17:07:50 +08:00
placeholder="请输入档案名称" maxlength="64" :disabled="detailStatus"></el-input>
2025-09-16 14:37:37 +08:00
</el-form-item>
<el-form-item label="案卷期限" prop="term">
2025-09-17 11:30:01 +08:00
<el-input class="form-item" v-model="form.term" clearable show-word-limit placeholder="请输入案卷期限"
maxlength="32" :disabled="detailStatus"></el-input>
2025-09-16 14:37:37 +08:00
</el-form-item>
<el-form-item label="归档责任单位" prop="unitName">
<el-input class="form-item" v-model="form.unitName" clearable show-word-limit
placeholder="请输入归档责任单位" maxlength="32" :disabled="detailStatus"></el-input>
</el-form-item>
<el-form-item label="所属专业" prop="major">
2025-09-17 11:30:01 +08:00
<el-input class="form-item" v-model="form.major" clearable show-word-limit placeholder="请输入所属专业"
maxlength="32" :disabled="detailStatus"></el-input>
2025-09-16 14:37:37 +08:00
</el-form-item>
<el-form-item label="档案标识代码" prop="markCode">
<el-select class="form-item" v-model="form.markCode" :disabled="detailStatus" filterable clearable
placeholder="请选择档案标识代码">
<el-option v-for="item in dict.type.mark_code" :key="item.value" :label="item.label"
:value="item.label"></el-option>
</el-select>
</el-form-item>
<el-form-item label="文件分类标记" prop="classifyMark">
2025-09-17 11:30:01 +08:00
<el-select class="form-item" v-model="form.classifyMark" :disabled="detailStatus" filterable
clearable>
<el-option v-for="item in classifyMarkList" :key="item.id" :label="item.name"
:value="item.id"></el-option>
2025-09-16 14:37:37 +08:00
</el-select>
</el-form-item>
2025-09-17 15:30:46 +08:00
<el-form-item label="附件上传" v-if="!detailStatus" prop="fileList">
2025-09-17 11:30:01 +08:00
<el-upload
ref="upload"
2025-09-17 15:30:46 +08:00
action="#"
2025-09-17 11:30:01 +08:00
:file-list="fileList"
:on-remove="handleRemove"
2025-09-17 15:30:46 +08:00
:on-change="handleFileChange"
:before-upload="beforeUpload"
2025-09-17 11:30:01 +08:00
:auto-upload="false"
:limit="1"
2025-09-18 09:42:48 +08:00
accept=".pdf,.jpg,.jpeg,.png">
2025-09-17 15:30:46 +08:00
<el-button size="small" type="primary" icon="el-icon-upload" :disabled="fileList.length > 0">选择文件</el-button>
2025-09-17 11:30:01 +08:00
<div slot="tip" class="el-upload__tip">
2025-09-17 17:07:50 +08:00
<span style="color: #f00;">
2025-09-17 15:30:46 +08:00
只能上传PDF和图片文件且不超过{{maxFileTips}}
</span>
2025-09-17 11:30:01 +08:00
</div>
</el-upload>
</el-form-item>
2025-09-16 14:37:37 +08:00
</el-form>
</div>
<span slot="footer" class="dialog-footer">
<el-button class="clear-btn" @click="handleClose" :disabled="disabled">取消</el-button>
<el-button type="primary" class="search-btn" :disabled="disabled" v-if="!detailStatus"
@click="submitForm('ruleForm')">确认</el-button>
</span>
</el-dialog>
</template>
<script>
import _ from 'lodash'
import {
2025-09-17 15:30:46 +08:00
addFileManageRightApi,
updateFileManageRightApi,
2025-09-17 18:11:19 +08:00
getFileManageByIdApi
2025-09-17 15:30:46 +08:00
} from '@/api/archivesManagement/fileManager/fileManager.js'
2025-09-17 11:30:01 +08:00
import { getClassifyMarkSelApi } from '@/api/select.js'
2025-09-16 14:37:37 +08:00
export default {
name: "FileAddTableData",
2025-09-17 11:30:01 +08:00
props: ["width", "dataForm", "title", "disabled", "isAdd", "rowData", "projectId"],
dicts: ['mark_code','file_size_limit'],
2025-09-16 14:37:37 +08:00
data() {
return {
lDialog: this.width > 500 ? "w700" : "w500",
dialogVisible: true,
isDisabled: true,
getClassifyMarkSelApi,
2025-09-17 11:30:01 +08:00
classifyMarkList: [],
2025-09-16 14:37:37 +08:00
form: {
contentName: null,
term: null,
unitName: null,
major: null,
markCode: null,
classifyMark: null,
},
2025-09-17 11:30:01 +08:00
belongName: '',
2025-09-16 14:37:37 +08:00
loading: null,
2025-09-17 11:30:01 +08:00
detailStatus: false,
// 文件上传相关
fileList: [],
maxFileSize: 10 * 1024 * 1024, // 默认10MB
2025-09-17 15:30:46 +08:00
maxFileTips: '10MB',
2025-09-16 14:37:37 +08:00
rules: {
contentName: [
2025-09-17 17:07:50 +08:00
{ required: true, message: '档案名称不能为空', trigger: 'blur' }
2025-09-16 14:37:37 +08:00
],
2025-09-17 15:30:46 +08:00
fileList: [
{ validator: (rule, value, callback) => {
if (!Array.isArray(this.fileList) || this.fileList.length === 0) {
callback(new Error('请上传附件文件'))
} else {
callback()
}
}, trigger: 'change' }
],
2025-09-16 14:37:37 +08:00
term: [
{ required: true, message: '案卷期限不能为空', trigger: 'blur' }
],
unitName: [
{ required: true, message: '归档责任单位不能为空', trigger: 'blur' }
],
major: [
{ required: true, message: '所属专业不能为空', trigger: 'blur' }
],
markCode: [
{ required: true, message: '请选择档案标识代码', trigger: 'change' }
],
classifyMark: [
{ required: true, message: '请选择文件分类标记', trigger: 'change' }
],
},
};
},
created() {
2025-09-17 15:30:46 +08:00
this.initUploadLimit();
2025-09-16 14:37:37 +08:00
this.initFormData();
},
2025-09-17 11:30:01 +08:00
mounted() {
// 在mounted生命周期中再次尝试获取字典数据
this.$nextTick(() => {
2025-09-17 15:30:46 +08:00
this.updateFileSizeLimit();
});
},
watch: {
// 监听字典数据变化
'dict.type.file_size_limit': {
handler(newVal) {
if (newVal && Array.isArray(newVal) && newVal.length > 0) {
this.updateFileSizeLimit();
}
},
immediate: true,
deep: true
}
},
methods: {
async initUploadLimit(){
// 加载文件上传限制
await this.$nextTick();
this.updateFileSizeLimit();
},
// 更新文件大小限制
updateFileSizeLimit() {
2025-09-17 11:30:01 +08:00
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)) {
2025-09-17 15:30:46 +08:00
this.maxFileSize = parseInt(firstValue) * 1024 * 1024;
this.maxFileTips = firstValue + 'MB';
2025-09-17 11:30:01 +08:00
}
}
}
2025-09-17 15:30:46 +08:00
},
2025-09-16 14:37:37 +08:00
/** 初始化表单数据 */
2025-09-17 11:30:01 +08:00
async initFormData() {
const res = await getClassifyMarkSelApi();
this.classifyMarkList = res.data;
this.belongName = this.rowData.belongName;
this.detailStatus = this.rowData.detailStatus;
2025-09-16 14:37:37 +08:00
if ((this.isAdd === 'edit' || this.isAdd === 'detail') && this.rowData) {
2025-09-17 18:18:58 +08:00
2025-09-25 15:41:15 +08:00
const res2 = await getFileManageByIdApi({id:this.rowData.id,proId:this.projectId});
2025-09-17 18:18:58 +08:00
const obj =res2.data;
2025-09-18 09:42:48 +08:00
2025-09-16 14:37:37 +08:00
// 编辑模式:填充表单数据
this.form = {
2025-09-17 18:18:58 +08:00
id: obj.id,
contentName: obj.contentName || null,
term: obj.term || null,
major: obj.major || null,
unitName: obj.unitName || null,
markCode: obj.markCode || null,
classifyMark: obj.classifyMark || null,
2025-09-17 11:30:01 +08:00
parentId: this.rowData.parentId || null,
2025-09-17 17:07:50 +08:00
level: 5,
proId:this.projectId
2025-09-16 14:37:37 +08:00
};
2025-09-18 09:42:48 +08:00
const fileList = [{name:obj.fileName,businessId:obj.businessId}];
this.fileList = fileList;
2025-09-16 14:37:37 +08:00
} else {
2025-09-25 15:41:15 +08:00
const id = this.rowData.id;
const proId = this.projectId;
const res = await getFileManageByIdApi({id,proId});
2025-09-17 18:11:19 +08:00
const obj =res.data;
2025-09-16 14:37:37 +08:00
// 新增模式:重置表单
this.form = {
contentName: null,
2025-09-17 18:11:19 +08:00
term: obj.term || null,
unitName: obj.unitName || null,
major: obj.major || null,
markCode: obj.markCode || null,
classifyMark: obj.classifyMark || null,
2025-09-17 11:30:01 +08:00
parentId: this.rowData.id || null,
2025-09-17 17:07:50 +08:00
level: 5,
proId:this.projectId
2025-09-16 14:37:37 +08:00
};
}
},
/*关闭弹窗 */
handleClose() {
this.dialogVisible = false;
this.$emit("closeDialog");
2025-09-29 14:18:40 +08:00
/* setTimeout(() => {
2025-09-16 14:37:37 +08:00
this.dialogVisible = true;
2025-09-29 14:18:40 +08:00
}); */
2025-09-16 14:37:37 +08:00
},
/**确认弹窗 */
sureBtnClick() {
this.dialogVisible = false;
this.$emit("closeDialog");
2025-09-29 14:18:40 +08:00
/* setTimeout(() => {
2025-09-16 14:37:37 +08:00
this.dialogVisible = true;
2025-09-29 14:18:40 +08:00
}); */
2025-09-16 14:37:37 +08:00
},
/**重置表单*/
reset() {
this.form = {
contentName: null,
term: null,
unitName: null,
major: null,
markCode: null,
classifyMark: null,
2025-09-17 11:30:01 +08:00
parentId: null,
2025-09-17 15:30:46 +08:00
level: 5
2025-09-16 14:37:37 +08:00
};
2025-09-17 11:30:01 +08:00
this.fileList = [];
2025-09-17 15:30:46 +08:00
this.$nextTick(() => {
this.$refs.upload && this.$refs.upload.clearFiles();
});
2025-09-16 14:37:37 +08:00
this.resetForm("ruleForm");
},
handleReuslt(res) {
this.$modal.msgSuccess(res.msg);
this.reset();
this.$emit('handleQuery');
this.handleClose();
},
2025-09-17 15:30:46 +08:00
// 上传前对文件进行验证
2025-09-17 11:30:01 +08:00
beforeUpload(file) {
2025-09-18 11:58:21 +08:00
if(!(file.raw instanceof File)){
2025-09-18 09:42:48 +08:00
return true;
}
2025-09-17 11:30:01 +08:00
const isValidType = this.checkFileType(file)
const isValidSize = this.checkFileSize(file)
if (!isValidType) {
this.$message.error('只能上传PDF和图片文件')
return false
}
if (!isValidSize) {
2025-09-17 17:44:11 +08:00
this.$message.error('文件大小不能超过`${this.maxFileTips}`')
2025-09-17 11:30:01 +08:00
return false
}
// 检查是否已有文件
if (this.fileList.length >= 1) {
this.$message.warning('只能上传一个文件,请先删除现有文件!')
return false
}
return true
},
// 检查文件类型
checkFileType(file) {
const allowedTypes = [
'application/pdf',
'image/jpeg',
'image/jpg',
'image/png',
]
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) {
2025-09-18 09:42:48 +08:00
if(!(file instanceof File)){
this.form.businessId = file.businessId;
}
2025-09-17 11:30:01 +08:00
this.fileList = fileList
},
2025-09-17 15:30:46 +08:00
// 文件状态改变
handleFileChange(file, fileList) {
this.fileList = fileList
// 主动触发校验
if (this.$refs.ruleForm) {
this.$refs.ruleForm.validateField('fileList')
}
2025-09-29 15:12:56 +08:00
// console.log('文件列表更新:', fileList.length, '个文件')
2025-09-17 15:30:46 +08:00
},
2025-09-18 09:42:48 +08:00
2025-09-16 14:37:37 +08:00
/**验证 */
submitForm(formName) {
this.$refs[formName].validate(valid => {
if (valid) {
2025-09-17 11:30:01 +08:00
// 如果有文件需要上传,先上传文件
if (this.fileList.length > 0) {
2025-09-17 15:30:46 +08:00
this.submitFormData();
2025-09-16 14:37:37 +08:00
} else {
2025-09-17 11:30:01 +08:00
this.submitFormData();
2025-09-16 14:37:37 +08:00
}
}
});
2025-09-17 11:30:01 +08:00
},
// 提交表单数据
submitFormData() {
// 显示遮罩层
this.loading = this.$loading({
lock: true,
text: "数据提交中,请稍候...",
background: 'rgba(0,0,0,0.5)',
target: this.$el.querySelector('.el-dialog') || document.body
})
2025-09-17 15:30:46 +08:00
let formData = new FormData();
2025-09-17 11:30:01 +08:00
let params = _.cloneDeep(this.form);
2025-09-17 15:30:46 +08:00
if(this.fileList.length > 0){
this.fileList.map(file => {
2025-09-18 11:58:21 +08:00
if(file.raw instanceof File){
2025-09-18 09:42:48 +08:00
formData.append('file', file.raw);
}
2025-09-17 15:30:46 +08:00
})
}
2025-09-17 11:30:01 +08:00
if (this.isAdd === 'add') {
2025-09-17 15:30:46 +08:00
formData.append('params', JSON.stringify(params));
2025-09-29 15:12:56 +08:00
// console.log(params);
2025-09-17 15:30:46 +08:00
addFileManageRightApi(formData).then(res => {
2025-09-17 11:30:01 +08:00
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 {
2025-09-18 09:42:48 +08:00
formData.append('params', JSON.stringify(params));
2025-09-29 15:12:56 +08:00
// console.log(params);
2025-09-17 15:30:46 +08:00
updateFileManageRightApi(formData).then(res => {
2025-09-17 11:30:01 +08:00
this.loading.close();
if (res.code === 200) {
this.handleReuslt(res);
} else {
this.$modal.msgError(res.msg);
}
}).catch(error => {
this.loading.close();
// this.$modal.msgError('提交失败,请重试');
});
}
2025-09-16 14:37:37 +08:00
}
}
};
</script>
2025-09-22 10:50:09 +08:00
<style lang="scss" scoped>
2025-09-22 11:13:52 +08:00
.w700 ::v-deep .el-dialog {
2025-09-16 14:37:37 +08:00
width: 700px;
}
2025-09-22 11:13:52 +08:00
.w500 ::v-deep .el-dialog {
2025-09-16 14:37:37 +08:00
width: 500px;
}
2025-09-22 11:13:52 +08:00
.w500 ::v-deep .el-dialog__header,
.w700 ::v-deep .el-dialog__header {
2025-09-16 14:37:37 +08:00
// background: #eeeeee;
.el-dialog__title {
font-size: 16px;
}
}
.yxq .el-range-separator {
margin-right: 7px !important;
}
.el-date-editor--daterange.el-input__inner {
width: 260px;
}
.form-item {
width: 100%;
}
.select-style {
display: flex;
justify-content: space-between;
}
</style>