From 718a13554dbb2f99e27adeb7b95edfc3096dacc5 Mon Sep 17 00:00:00 2001 From: 董国庆 <364620639@qq.com> Date: 星期四, 26 六月 2025 14:24:27 +0800 Subject: [PATCH] 删除打印和路由返回 --- laboratory/src/views/dataManagement/approvalPlan/addPlan.vue | 244 ++++++++++++++++++++++++++++-------------------- 1 files changed, 143 insertions(+), 101 deletions(-) diff --git a/laboratory/src/views/dataManagement/approvalPlan/addPlan.vue b/laboratory/src/views/dataManagement/approvalPlan/addPlan.vue index d78dce6..868c75e 100644 --- a/laboratory/src/views/dataManagement/approvalPlan/addPlan.vue +++ b/laboratory/src/views/dataManagement/approvalPlan/addPlan.vue @@ -126,7 +126,9 @@ placeholder="请输入注意事项..." /> <div class="add-project-footer"> - <el-button type="primary" class="save-btn" @click="handleSave">保存</el-button> + <el-button type="primary" class="save-btn" @click="handleSave" + >保存</el-button + > <el-button @click="handleSaveDraft">存草稿</el-button> </div> </template> @@ -135,44 +137,49 @@ </template> <script> -import AiEditor from '@/components/AiEditor' -import { addProposal, updateProposal, getDetailById } from './service' +import AiEditor from "@/components/AiEditor"; +import { addProposal, updateProposal, getDetailById } from "./service"; +import { mapState } from "vuex"; export default { name: "AddProject", components: { - AiEditor + AiEditor, }, data() { return { - id: '', // 用于编辑时存储id + id: "", // 用于编辑时存储id form: { - projectName: '', - projectStage: '', - projectCode: '', - experimentObjective: '', - experimentMaterial: '', - experimentDevice: '', - experimentTestMethod: '', - experimentProcedure: '', - dataAcquisition: '', - resultEvaluation: '', - precautions: '', + projectName: "", + projectStage: "", + projectCode: "", + experimentObjective: "", + experimentMaterial: "", + experimentDevice: "", + experimentTestMethod: "", + experimentProcedure: "", + dataAcquisition: "", + resultEvaluation: "", + precautions: "", auditStatus: 1, // 默认为审批中 }, editorContents: { - experimentObjective: '', - experimentMaterial: '', - experimentDevice: '', - experimentTestMethod: '', - experimentProcedure: '', - dataAcquisition: '', - resultEvaluation: '', - precautions: '' + experimentObjective: "", + experimentMaterial: "", + experimentDevice: "", + experimentTestMethod: "", + experimentProcedure: "", + dataAcquisition: "", + resultEvaluation: "", + precautions: "", }, rules: { projectName: [ - { required: true, message: "请输入项目课题方案名称", trigger: "blur" }, + { + required: true, + message: "请输入项目课题方案名称", + trigger: "blur", + }, ], projectStage: [ { required: true, message: "请选择项目阶段", trigger: "change" }, @@ -204,6 +211,9 @@ }, }; }, + computed: { + ...mapState(["tagList", "isFold"]), + }, methods: { // 获取所有编辑器的内容 getAllEditorContent() { @@ -215,123 +225,155 @@ experimentProcedure: this.$refs.stepsEditor.getContent(), dataAcquisition: this.$refs.dataAnalysisEditor.getContent(), resultEvaluation: this.$refs.evaluationEditor.getContent(), - precautions: this.$refs.notesEditor.getContent() - } + precautions: this.$refs.notesEditor.getContent(), + }; }, // 统一处理方法 handleSubmit(type) { this.$refs.form.validate((valid) => { if (valid) { // 获取所有编辑器内容 - const editorContents = this.getAllEditorContent() - + const editorContents = this.getAllEditorContent(); + // 检查编辑器内容是否为空 - const emptyFields = [] - console.log('editorContents', editorContents) - + const emptyFields = []; + console.log("editorContents", editorContents); + // 判断内容是否为空(排除<p></p>) const isEmptyContent = (content) => { - return !content || content === '<p></p>' || content.trim() === '<p></p>' - } + return ( + !content || content === "<p></p>" || content.trim() === "<p></p>" + ); + }; - if (isEmptyContent(editorContents.experimentObjective)) emptyFields.push('实验目的') - if (isEmptyContent(editorContents.experimentMaterial)) emptyFields.push('实验材料') - if (isEmptyContent(editorContents.experimentDevice)) emptyFields.push('实验设备') - if (isEmptyContent(editorContents.experimentTestMethod)) emptyFields.push('检测方法及开发') - if (isEmptyContent(editorContents.experimentProcedure)) emptyFields.push('实验步骤') - if (isEmptyContent(editorContents.dataAcquisition)) emptyFields.push('数据采集及分析') - if (isEmptyContent(editorContents.resultEvaluation)) emptyFields.push('结果评估') + if (isEmptyContent(editorContents.experimentObjective)) + emptyFields.push("实验目的"); + if (isEmptyContent(editorContents.experimentMaterial)) + emptyFields.push("实验材料"); + if (isEmptyContent(editorContents.experimentDevice)) + emptyFields.push("实验设备"); + if (isEmptyContent(editorContents.experimentTestMethod)) + emptyFields.push("检测方法及开发"); + if (isEmptyContent(editorContents.experimentProcedure)) + emptyFields.push("实验步骤"); + if (isEmptyContent(editorContents.dataAcquisition)) + emptyFields.push("数据采集及分析"); + if (isEmptyContent(editorContents.resultEvaluation)) + emptyFields.push("结果评估"); // if (isEmptyContent(editorContents.precautions)) emptyFields.push('注意事项') if (emptyFields.length > 0) { - this.$message.warning(`请填写${emptyFields.join('、')}`) - return false + this.$message.warning(`请填写${emptyFields.join("、")}`); + return false; } const formData = { ...this.form, ...editorContents, - auditStatus: type === 'draft' ? -1 : 1 // 草稿箱:-1, 审批中:1 - } - - const request = this.id ? updateProposal : addProposal + auditStatus: type === "draft" ? -1 : 1, // 草稿箱:-1, 审批中:1 + }; + + const request = this.id ? updateProposal : addProposal; if (this.id) { - formData.id = this.id + formData.id = this.id; } - console.log('请求参数:', { - formData - }) + console.log("请求参数:", { + formData, + }); - request(formData).then(res => { - console.log('接口返回:', res) - if (res.code === 200) { - const successMsg = type === 'draft' ? '草稿保存成功' : (this.id ? '更新成功' : '保存成功') - this.$message.success(successMsg) - this.$router.back() - } else { - const errorMsg = type === 'draft' ? '草稿保存失败' : (this.id ? '更新失败' : '保存失败') - this.$message.error(res.msg || errorMsg) - } - }).catch(err => { - console.error('接口错误:', err) - const errorMsg = type === 'draft' ? '草稿保存失败' : (this.id ? '更新失败' : '保存失败') - this.$message.error(errorMsg) - }) + request(formData) + .then((res) => { + console.log("接口返回:", res); + if (res.code === 200) { + const successMsg = + type === "draft" + ? "草稿保存成功" + : this.id + ? "更新成功" + : "保存成功"; + this.$message.success(successMsg); + this.$router.back(); + this.$store.commit( + "SET_TAGLIST", + this.tagList.filter((item) => item.path !== this.$route.path) + ); + } else { + const errorMsg = + type === "draft" + ? "草稿保存失败" + : this.id + ? "更新失败" + : "保存失败"; + this.$message.error(res.msg || errorMsg); + } + }) + .catch((err) => { + console.error("接口错误:", err); + const errorMsg = + type === "draft" + ? "草稿保存失败" + : this.id + ? "更新失败" + : "保存失败"; + this.$message.error(errorMsg); + }); } else { - this.$message.warning('请填写必填项') - return false + this.$message.warning("请填写必填项"); + return false; } - }) + }); }, // 保存 handleSave() { - this.handleSubmit('save') + this.handleSubmit("save"); }, // 保存草稿 handleSaveDraft() { - this.handleSubmit('draft') + this.handleSubmit("draft"); }, // 获取详情 getDetail() { if (this.id) { - console.log('获取详情参数:', { id: this.id }) - getDetailById({ id: this.id }).then(res => { - console.log('详情接口返回:', res) - if (res) { - const data = res - // 设置表单数据 - this.form = { - projectName: data.projectName, - projectStage: data.projectStage, - projectCode: data.projectCode, - auditStatus: data.auditStatus + console.log("获取详情参数:", { id: this.id }); + getDetailById({ id: this.id }) + .then((res) => { + console.log("详情接口返回:", res); + if (res) { + const data = res; + // 设置表单数据 + this.form = { + projectName: data.projectName, + projectStage: data.projectStage, + projectCode: data.projectCode, + auditStatus: data.auditStatus, + }; + // 设置编辑器内容 + this.editorContents = { + experimentObjective: data.experimentObjective, + experimentMaterial: data.experimentMaterial, + experimentDevice: data.experimentDevice, + experimentTestMethod: data.experimentTestMethod, + experimentProcedure: data.experimentProcedure, + dataAcquisition: data.dataAcquisition, + resultEvaluation: data.resultEvaluation, + precautions: data.precautions, + }; } - // 设置编辑器内容 - this.editorContents = { - experimentObjective: data.experimentObjective, - experimentMaterial: data.experimentMaterial, - experimentDevice: data.experimentDevice, - experimentTestMethod: data.experimentTestMethod, - experimentProcedure: data.experimentProcedure, - dataAcquisition: data.dataAcquisition, - resultEvaluation: data.resultEvaluation, - precautions: data.precautions - } - } - }).catch(err => { - console.error('获取详情失败:', err) - }) + }) + .catch((err) => { + console.error("获取详情失败:", err); + }); } - } + }, }, created() { // 从路由参数中获取id - this.id = this.$route.query.id + this.id = this.$route.query.id; if (this.id) { - this.getDetail() + this.getDetail(); } - } + }, }; </script> -- Gitblit v1.7.1