puzhibing
6 天以前 0db8c9b94a9ac655549d5eba5c2a6c92ac386c06
culture/src/views/strainReportLibrary/reportLibraryOneFour/add.vue
@@ -160,7 +160,7 @@
import { Card } from 'element-ui';
import AiEditor from '@/components/AiEditor'
import ChooseProject from '@/components/chooseProject/index.vue'
import { customUploadRequest, getFullUrl ,downloadFileByUrl,getAllocateIp,isImageFile} from "@/utils/utils";
import { customUploadRequest, getFullUrl, downloadFileByUrl, getAllocateIp, getUploadedFilePath, isImageFile, normalizeFileList } from "@/utils/utils";
import SelectMember from '@/components/SelectMember'
import { add, getDetail, update } from './service'
@@ -246,6 +246,9 @@
    },
  // 👇 添加这两个钩子
  activated() {
    if (!["/strainReportLibrary/addFour", "/strainReportLibrary/detailFour"].includes(this.$route.path)) {
      return;
    }
    if (this.cacheData) {
      // 恢复表单数据
      this.form = JSON.parse(JSON.stringify(this.cacheData.form));
@@ -288,44 +291,6 @@
        this.$nextTick(() => {
            window.scrollTo(0, 0);
        });
      if (this.$route.query.id && !this.cacheData) {
            getDetail(this.$route.query.id).then(res => {
                const data = res.data || res;
                this.form = {
                    ...this.form,
                    ...data,
                    processData: []
                };
              // 添加空值判断
              let arr = [];
              if (data.evaluate) {
                arr = data.evaluate.split(',');
              } else {
                // 如果 evaluate 为空,使用默认值(根据你的 assessmentTable 长度)
                arr = this.assessmentTable.map(() => 0);
              }
                this.fileList = (data.enclosureUrl ? JSON.parse(data.enclosureUrl) : [])
                this.assessmentTable = this.assessmentTable.map((item, index) => {
                  item.selectedScore = Number(arr[index] ?? 0);
                    return item
                })
                this.selectedMember = [{
                    nickName: data.experimentName,
                    userId: data.experimentId
                }]
                this.projectData = data.projectTeam ?
                    [{ ...data.projectTeam, staffName: data.projectTeam.staff || '' }] :
                    [];
            }).catch(err => {
                this.$message.error('获取详情失败');
            });
        }
    },
    methods: {
      // 👇 添加这个方法
@@ -345,7 +310,7 @@
            arr = this.assessmentTable.map(() => 0);
          }
          this.fileList = (data.enclosureUrl ? JSON.parse(data.enclosureUrl) : []);
          this.fileList = normalizeFileList(data.enclosureUrl);
          this.assessmentTable = this.assessmentTable.map((item, index) => {
            item.selectedScore = Number(arr[index] ?? 0);
@@ -378,11 +343,9 @@
                    // 图片文件:使用 window.open 预览
                    if (file.url && file.url.startsWith('http')) {
                        console.log('图片链接', file.url)
                        window.open(file.url, '_blank');
                        window.open(getFullUrl(file.url), '_blank');
                    } else {
                        let newUrl = getAllocateIp() + file.url;
                        console.log('图片链接', newUrl)
                        window.open(newUrl, '_blank');
                        window.open(getFullUrl(file.url), '_blank');
                    }
                } else {
                    // 非图片文件:使用下载方式
@@ -429,11 +392,12 @@
            customUploadRequest({
                file,
                onSuccess: (res) => {
                    if (res.code === 200) {
                    const uploadedPath = getUploadedFilePath(res)
                    if (uploadedPath) {
                        const fileObj = {
                            id: new Date().getTime(),
                            reportId: this.$route.query.id ? this.$route.query.id : "",
                            fileUrl: res.msg || res.data || "",
                            fileUrl: uploadedPath,
                            reportType: 2, // 报告类型
                            fileName: file.name,
                            fileSize: file.size,
@@ -442,14 +406,15 @@
                        // 添加到文件列表显示
                        this.fileList.push({
                            name: file.name,
                            url: getFullUrl(fileObj.fileUrl),
                            url: fileObj.fileUrl,
                            uid: fileObj.id,
                        });
                        // 添加到表单数据
                        this.form.feasibilityReportFiles.push(fileObj);
                        this.$message.success("文件上传成功");
                        onSuccess(res);
                    } else {
                        this.$message.error(res && res.msg ? res.msg : "上传接口未返回文件地址");
                        onError(new Error('missing uploaded file path'));
                    }
                },
                onError: (err) => {
@@ -463,7 +428,6 @@
            const index = this.fileList.findIndex((item) => item.name === file.name);
            if (index !== -1) {
                this.fileList.splice(index, 1);
                this.form.feasibilityReportFiles.splice(index, 1);
            }
        },
        async addData() {
@@ -496,7 +460,7 @@
                        isDraft: 0,
                        projectId: this.projectData[0].id,
                        // experimentId: this.selectedMember[0].userId,
                        enclosureUrl: this.fileList.length && JSON.stringify(this.fileList),
                        enclosureUrl: JSON.stringify(this.fileList),
                        // reportCode: this.form.reportCode,
                        reportContent: this.$refs.materialEditor.getContent(),
                        reportName: this.form.reportName,
@@ -511,7 +475,7 @@
                            if (res.code == 200) {
                                this.$message.success('编辑成功');
                              this.cacheData = null;  // 👈 添加这一行
                                this.$router.back()
                                this.$closeCurrentView('/strainReportLibrary/reportLibraryFour')
                            }
                        }).catch(() => {
                            this.submitLoading = false;
@@ -523,7 +487,7 @@
                        if (res.code == 200) {
                            this.$message.success('发送成功');
                          this.cacheData = null;  // 👈 添加这一行
                            this.$router.push('/strainReportLibrary/reportLibraryFour');
                            this.$closeCurrentView('/strainReportLibrary/reportLibraryFour');
                        }
                    }).catch(() => {
                        this.submitLoading = false;
@@ -548,7 +512,7 @@
                            isDraft: 1,
                            projectId: this.projectData[0].id,
                            // experimentId: this.selectedMember[0].userId,
                            enclosureUrl: this.fileList.length && JSON.stringify(this.fileList),
                            enclosureUrl: JSON.stringify(this.fileList),
                            // reportCode: this.form.reportCode,
                            reportContent: this.$refs.materialEditor.getContent(),
                            reportName: this.form.reportName,
@@ -563,7 +527,7 @@
                                if (res.code == 200) {
                                    this.$message.success('编辑成功');
                                  this.cacheData = null;  // 👈 添加这一行
                                    this.$router.back()
                                    this.$closeCurrentView('/strainReportLibrary/reportLibraryFour')
                                }
                            }).catch(() => {
                                this.submitLoading = false;
@@ -575,7 +539,7 @@
                            if (res.code == 200) {
                                this.$message.success('保存成功');
                              this.cacheData = null;  // 👈 添加这一行
                                this.$router.push('/strainReportLibrary/reportLibraryFour');
                                this.$closeCurrentView('/strainReportLibrary/reportLibraryFour');
                            }
                        }).catch(() => {
                            this.draftLoading = false;