From 4de05c1c4c5d4af286f0658aa52c3bd1028c5b76 Mon Sep 17 00:00:00 2001 From: xuhuajiao <13476289682@163.com> Date: Thu, 28 May 2026 10:25:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=80=BC=E4=B8=8D=E5=8F=AF=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/collectHeader.vue | 11 +- src/views/components/category/PreviewForm.vue | 149 ++++++++++++++---- src/views/prearchiveLibrary/index.vue | 2 + 3 files changed, 126 insertions(+), 36 deletions(-) diff --git a/src/views/collectReorganizi/collectionLibrary/module/collectHeader.vue b/src/views/collectReorganizi/collectionLibrary/module/collectHeader.vue index 3a306b5..cbf24ee 100644 --- a/src/views/collectReorganizi/collectionLibrary/module/collectHeader.vue +++ b/src/views/collectReorganizi/collectionLibrary/module/collectHeader.vue @@ -826,16 +826,11 @@ export default { console.log('data.echo', data.echo) const archivesNo = data.echo.archive_no if (archivesNo) { - let categoryId - if (this.isDesFormType !== 'mergeFile' && this.isDesFormType !== 'arcives' && this.isDesFormType !== 'manageArcives') { - categoryId = this.selectedCategory.pid - } else { - categoryId = this.selectedCategory.id - } + const categoryId = this.selectedCategory.id this.$refs.previewForm.FetchNoFormatField(categoryId).then(() => { FetchMaxItemNoByArchivesNo({ archivesNo, categoryId, categoryLevel: this.collectLevel }).then(res => { if (res) { - const newItemNo = (parseInt(res) + 1).toString() + const newItemNo = (parseInt(res)).toString() const field = this.formPreviewData.find(item => item.fieldName === 'item_no') if (field && field.isFilling) { const fillingDigit = field.fillingDigit @@ -843,7 +838,9 @@ export default { } else { this.$set(this.$refs.previewForm.addOrUpdateForm, 'item_no', newItemNo) } + this.$refs.previewForm.maxItemNo = newItemNo this.$refs.previewForm.handleAuto() + this.arcId = null } }) }) diff --git a/src/views/components/category/PreviewForm.vue b/src/views/components/category/PreviewForm.vue index 5101872..290c032 100644 --- a/src/views/components/category/PreviewForm.vue +++ b/src/views/components/category/PreviewForm.vue @@ -1193,21 +1193,56 @@ export default { }) }, 100) }, - // 判断重复api + // 判断重复api - 表单验证方式 handlerIsRepeat(params, item) { - if (this.isDesFormType !== 'prearchiveLibrary') { - FetchIsRepeatByField(params).then(res => { - if (res) { - this.$message({ message: item.fieldCnName + '不可重复', type: 'error', offset: 8 }) + const validateRepeat = async(value) => { + if (!value) { + return null + } + try { + const fieldValue = this.addOrUpdateForm[item.fieldName] + let response + if (this.isDesFormType !== 'prearchiveLibrary') { + // 非预归档库场景 + const requestParams = { + 'categoryId': this.selectedCategory.id, + 'archivesId': this.arcId, + 'categoryLevel': this.collectLevel, + 'fieldName': item.fieldName, + 'fieldValue': fieldValue + } + response = await FetchIsRepeatByField(requestParams) + } else { + // 预归档库场景 + const requestParams = { + 'documentId': this.selectedCategory.id, + 'archivesId': this.arcId, + 'fieldName': item.fieldName, + 'value': fieldValue + } + response = await FetchReDoeditIsRepeat(requestParams) } - }) - } else { - FetchReDoeditIsRepeat(params).then(res => { - if (res) { - this.$message({ message: item.fieldCnName + '不可重复', type: 'error', offset: 8 }) + if (response) { + return `${item.fieldCnName}不可重复` } - }) + return null + } catch (error) { + console.error('重复检查失败:', error) + return '验证重复时发生错误,请稍后再试' + } } + + this.$set(this.rules, item.fieldName, [{ + validator: async(rule, value, callback) => { + const errorMessage = await validateRepeat(value) + if (errorMessage) { + callback(new Error(errorMessage)) + } else { + callback() + } + }, + trigger: 'blur' + }]) }, async isRepeatHandle(item) { // 记录最后修改的字段名 @@ -1218,14 +1253,14 @@ export default { const params = this.isDesFormType !== 'prearchiveLibrary' ? { 'categoryId': this.selectedCategory.id, - // 'archivesId': this.arcId, + 'archivesId': this.arcId, 'categoryLevel': this.collectLevel, 'fieldName': item.fieldName, 'fieldValue': this.addOrUpdateForm[item.fieldName] } : { 'documentId': this.selectedCategory.id, - 'archivesId': null, + 'archivesId': this.arcId, 'fieldName': item.fieldName, 'value': this.addOrUpdateForm[item.fieldName] } @@ -1278,14 +1313,14 @@ export default { const params = this.isDesFormType !== 'prearchiveLibrary' && this.isDesFormType !== 'mergeFile' ? { 'categoryId': this.selectedCategory.id, - // 'archivesId': this.arcId, + 'archivesId': this.arcId, 'categoryLevel': this.collectLevel, 'fieldName': this.treeCurrentFiled.fieldName, 'fieldValue': val.dictionaryName } : { 'documentId': this.selectedCategory.id, - 'archivesId': null, + 'archivesId': this.arcId, 'fieldName': this.treeCurrentFiled.fieldName, 'value': val.dictionaryName } @@ -1569,24 +1604,80 @@ export default { this.formPreviewData[newIndex] = index } }, - submitForm(formName, categoryId, quickPaperArcId, arcAddType) { - // 时间格式化 - // this.formPreviewData.map(item => { - // if (item.isInputClass === 'date') { - // if (this.addOrUpdateForm[item.fieldName] !== '') { - // this.$set(this.addOrUpdateForm, item.fieldName, parseTime(this.addOrUpdateForm[item.fieldName]).split(' ')[0]) - // } - // } - // }) + async validateRepeatFieldsBeforeSubmit(formName) { + let hasError = false + const repeatFields = this.formPreviewData.filter(item => item.isRepeat) + for (const item of repeatFields) { + const fieldValue = this.addOrUpdateForm[item.fieldName] + if (!fieldValue) continue + + let response + try { + if (this.isDesFormType !== 'prearchiveLibrary') { + const requestParams = { + 'categoryId': this.selectedCategory.id, + 'archivesId': this.arcId, + 'categoryLevel': this.collectLevel, + 'fieldName': item.fieldName, + 'fieldValue': fieldValue + } + response = await FetchIsRepeatByField(requestParams) + } else { + const requestParams = { + 'documentId': this.selectedCategory.id, + 'archivesId': this.arcId, + 'fieldName': item.fieldName, + 'value': fieldValue + } + response = await FetchReDoeditIsRepeat(requestParams) + } + if (response) { + const errorMsg = `${item.fieldCnName}不可重复` + + if (this.$refs[formName]) { + // 方式1:动态添加验证规则并触发验证 + const repeatRule = { + validator: (rule, value, callback) => { + callback(new Error(errorMsg)) + }, + trigger: 'blur' + } + + // 获取当前字段的验证规则 + let fieldRules = this.rules[item.fieldName] || [] + // 添加重复验证规则 + fieldRules = [repeatRule, ...fieldRules.filter(r => r.validator && typeof r.validator === 'function')] + this.$set(this.rules, item.fieldName, fieldRules) + + // 触发该字段的验证 + this.$refs[formName].validateField(item.fieldName) + } + + hasError = true + } + } catch (error) { + console.error('重复检查失败:', error) + } + } + return !hasError + }, + async submitForm(formName, categoryId, quickPaperArcId, arcAddType) { if (this.archivesType === 'add' || this.archivesType === 'copy') { this.addOrUpdateForm.fonds_affiliation = this.selectedCategory.fondsId } const originalArchiveNo = this.addOrUpdateForm.archive_no console.log('this.addOrUpdateForm', this.addOrUpdateForm) - this.$nextTick(() => { - console.log('this.addOrUpdateForm.archive_no', this.addOrUpdateForm.archive_no) + // 先验证重复字段 + // if (this.archivesType !== 'edit') { + const isRepeatValid = await this.validateRepeatFieldsBeforeSubmit(formName) + if (!isRepeatValid) { + return false + } + // } + + this.$nextTick(() => { this.$refs[formName].validate((valid, fields) => { if (valid) { this.addOrUpdateForm.archive_no = originalArchiveNo @@ -1724,7 +1815,7 @@ export default { console.log(params) if (this.archivesType === 'add' || this.archivesType === 'copy') { collectAdd(params).then(res => { - console.log('res', res) + console.log('collectAdd-res', res) if (res.code !== 500) { this.$message({ message: res, type: 'success', offset: 8 }) this.$emit('close-dialog', parentsId) @@ -1737,7 +1828,7 @@ export default { localStorage.removeItem('savePrevFromData') } } else { - this.$message({ message: res.message, type: 'error', offset: 8 }) + this.$message({ message: res.message + ',新增失败', type: 'error', offset: 8 }) this.$emit('close-dialog', parentsId) } this.$emit('formLoadingShow', false) @@ -1749,7 +1840,7 @@ export default { this.$message({ message: res, type: 'success', offset: 8 }) this.$emit('close-dialog', parentsId) } else { - this.$message({ message: res.message, type: 'error', offset: 8 }) + this.$message({ message: res.message + ',编辑失败', type: 'error', offset: 8 }) this.$emit('close-dialog', parentsId) } this.$emit('formLoadingShow', false) diff --git a/src/views/prearchiveLibrary/index.vue b/src/views/prearchiveLibrary/index.vue index c4c9e7a..94a6596 100644 --- a/src/views/prearchiveLibrary/index.vue +++ b/src/views/prearchiveLibrary/index.vue @@ -418,8 +418,10 @@ export default { this.$refs.previewForm.addOrUpdateForm = data.echo this.$refs.previewForm.fileOriginal = '' this.$refs.previewForm.fileJsonString = '' + this.arcId = null } else { this.$refs.previewForm.archivesType = 'add' + this.arcId = null } }) })