| | |
| | | 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' |
| | | |
| | |
| | | }, |
| | | // 👇 添加这两个钩子 |
| | | activated() { |
| | | if (!["/strainReportLibrary/addFour", "/strainReportLibrary/detailFour"].includes(this.$route.path)) { |
| | | return; |
| | | } |
| | | if (this.cacheData) { |
| | | // 恢复表单数据 |
| | | this.form = JSON.parse(JSON.stringify(this.cacheData.form)); |
| | |
| | | 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: { |
| | | // 👇 添加这个方法 |
| | |
| | | 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); |
| | |
| | | // 图片文件:使用 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 { |
| | | // 非图片文件:使用下载方式 |
| | |
| | | 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, |
| | |
| | | // 添加到文件列表显示 |
| | | 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) => { |
| | |
| | | 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() { |
| | |
| | | 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, |
| | |
| | | if (res.code == 200) { |
| | | this.$message.success('编辑成功'); |
| | | this.cacheData = null; // 👈 添加这一行 |
| | | this.$router.back() |
| | | this.$closeCurrentView('/strainReportLibrary/reportLibraryFour') |
| | | } |
| | | }).catch(() => { |
| | | this.submitLoading = false; |
| | |
| | | if (res.code == 200) { |
| | | this.$message.success('发送成功'); |
| | | this.cacheData = null; // 👈 添加这一行 |
| | | this.$router.push('/strainReportLibrary/reportLibraryFour'); |
| | | this.$closeCurrentView('/strainReportLibrary/reportLibraryFour'); |
| | | } |
| | | }).catch(() => { |
| | | this.submitLoading = false; |
| | |
| | | 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, |
| | |
| | | if (res.code == 200) { |
| | | this.$message.success('编辑成功'); |
| | | this.cacheData = null; // 👈 添加这一行 |
| | | this.$router.back() |
| | | this.$closeCurrentView('/strainReportLibrary/reportLibraryFour') |
| | | } |
| | | }).catch(() => { |
| | | this.submitLoading = false; |
| | |
| | | if (res.code == 200) { |
| | | this.$message.success('保存成功'); |
| | | this.cacheData = null; // 👈 添加这一行 |
| | | this.$router.push('/strainReportLibrary/reportLibraryFour'); |
| | | this.$closeCurrentView('/strainReportLibrary/reportLibraryFour'); |
| | | } |
| | | }).catch(() => { |
| | | this.draftLoading = false; |