puzhibing
6 天以前 0db8c9b94a9ac655549d5eba5c2a6c92ac386c06
culture/src/views/strainReportLibrary/reportLibraryOneTWO/add.vue
@@ -159,7 +159,7 @@
<script>
import AiEditor from '@/components/AiEditor'
import ChooseProject from '@/components/chooseProject/index.vue'
import {customUploadRequest, downloadFileByUrl, getAllocateIp, getFullUrl, isImageFile} from "@/utils/utils";
import { customUploadRequest, downloadFileByUrl, getAllocateIp, getFullUrl, getUploadedFilePath, isImageFile, normalizeFileList } from "@/utils/utils";
import SelectMember from '@/components/SelectMember'
import {add, getDetail, update} from './service'
@@ -244,6 +244,9 @@
    },
  // 👇 添加这两个钩子
  activated() {
    if (!["/strainReportLibrary/addTwo", "/strainReportLibrary/detailTwo"].includes(this.$route.path)) {
      return;
    }
    if (this.cacheData) {
      // 恢复表单数据
      this.form = JSON.parse(JSON.stringify(this.cacheData.form));
@@ -285,45 +288,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.selectedMember = [{
                    nickName: data.experimentName,
                    userId: data.experimentId
                }]
                this.fileList = (data.enclosureUrl ? JSON.parse(data.enclosureUrl) : [])
              this.assessmentTable = this.assessmentTable.map((item, index) => {
                item.selectedScore = Number(arr[index] ?? 0);
                return item;
              });
                this.projectData = data.projectTeam ?
                    [{ ...data.projectTeam, staffName: data.projectTeam.staff || '' }] :
                    [];
            }).catch(err => {
              console.log(err)
                this.$message.error('获取详情失败');
            });
        }
    },
    methods: {
      // 👇 添加这个方法
@@ -348,7 +312,7 @@
            nickName: data.experimentName,
            userId: data.experimentId
          }];
          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);
@@ -377,11 +341,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 {
          // 非图片文件:使用下载方式
@@ -427,11 +389,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,
@@ -440,14 +403,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) => {
@@ -461,7 +425,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);
            }
        },
@@ -497,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,
@@ -512,8 +475,8 @@
                        this.loading = false;
                        if (res.code == 200) {
                            this.$message.success('编辑成功');
                            this.$router.back()
                          this.cacheData = null;
                            this.cacheData = null;
                            this.$closeCurrentView('/strainReportLibrary/reportLibraryTwo')
                        } else {
                            this.$message.error(res.message || '编辑失败');
                        }
@@ -528,8 +491,8 @@
                    this.loading = false;
                    if (res.code == 200) {
                        this.$message.success('发送成功');
                        this.$router.back()
                      this.cacheData = null;
                        this.cacheData = null;
                        this.$closeCurrentView('/strainReportLibrary/reportLibraryTwo')
                    } else {
                        this.$message.error(res.message || '发送失败');
                    }
@@ -557,7 +520,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,
@@ -571,7 +534,8 @@
                            this.loading = false;
                            if (res.code == 200) {
                                this.$message.success('编辑成功');
                                this.$router.back()
                                this.cacheData = null;
                                this.$closeCurrentView('/strainReportLibrary/reportLibraryTwo')
                            } else {
                                this.$message.error(res.message || '编辑失败');
                            }
@@ -586,7 +550,8 @@
                        this.loading = false;
                        if (res.code == 200) {
                            this.$message.success('保存成功');
                            this.$router.back()
                            this.cacheData = null;
                            this.$closeCurrentView('/strainReportLibrary/reportLibraryTwo')
                        } else {
                            this.$message.error(res.message || '保存失败');
                        }