fix: 修改Save to Txt调的接口

This commit is contained in:
Xu Zhimeng 2023-11-10 16:41:35 +08:00
parent 8459081c5c
commit 88348f4f78

View File

@ -255,6 +255,8 @@ import { clearSampleCache } from './clearSampleCache'
import { fetchAndDownload } from '@/utils/file'
import BGLogViewer from './components/Modals/BetaGammaModals/BGLogViewer.vue'
import { saveAs } from 'file-saver'
//
const ANALYZE_TYPE = {
GAMMA: 'gammaAnalysis',
@ -586,34 +588,81 @@ export default {
}
}
if (this.isBetaGamma) {
const url =
saveFormat == 'xls'
? '/spectrumAnalysis/saveToExcel'
: saveFormat == 'txt'
? '/spectrumAnalysis/saveToTxt'
: saveFormat == 'html'
? '/spectrumAnalysis/saveToHTML'
: ''
if (!this.resultDisplayFlag) {
this.$message.warn('Please Analyse Spectrum First')
if(!this.isReAnalyed_beta) {
this.$message.warning('Please analyze the spectrum first!')
this.isSaving = false
return
}
if (saveFormat == 'txt') {
try {
const {
sampleId,
inputFileName: fileName,
dbName,
detFileName,
gasFileName,
qcFileName,
} = this.newSampleData
this.resultDisplayFlag.forEach((item) => {
this.params_toDB[`${item.nuclideName.toLowerCase()}Flag`] = item.nidFlag
})
const params = {
dbName,
sampleId,
sampleData: false,
gasBgData: false,
detBgData: false,
qcData: false,
sampleFileName: fileName,
gasFileName,
detFileName,
qcFileName,
}
const txtFileName = `${fileName.split('.')[0]}.txt`
const res = await postAction('/spectrumAnalysis/viewRRR', params)
if (typeof res == 'string') {
const data = new Blob([res], { type: 'text/plain;charset=utf-8' })
saveAs(data, txtFileName)
} else {
const { success, result, message } = res
if (success) {
const data = new Blob([result], { type: 'text/plain;charset=utf-8' })
saveAs(data, txtFileName)
} else {
this.$message.error(message)
}
}
} catch (error) {
console.error(error)
} finally {
this.isSaving = false
}
} else {
const url =
saveFormat == 'xls'
? '/spectrumAnalysis/saveToExcel'
: saveFormat == 'html'
? '/spectrumAnalysis/saveToHTML'
: ''
if (!this.resultDisplayFlag) {
this.$message.warn('Please Analyse Spectrum First')
return
}
this.params_toDB.sampleFileName = this.newSampleData.inputFileName
this.params_toDB.gasFileName = this.newSampleData.gasFileName
this.params_toDB.detFileName = this.newSampleData.detFileName
this.params_toDB.qcFileName = this.newSampleData.qcFileName
this.params_toDB.dbName = this.newSampleData.dbName
try {
await fetchAndDownload(url, this.params_toDB)
} catch (error) {
console.error(error)
} finally {
this.isSaving = false
this.resultDisplayFlag.forEach((item) => {
this.params_toDB[`${item.nuclideName.toLowerCase()}Flag`] = item.nidFlag
})
this.params_toDB.sampleFileName = this.newSampleData.inputFileName
this.params_toDB.gasFileName = this.newSampleData.gasFileName
this.params_toDB.detFileName = this.newSampleData.detFileName
this.params_toDB.qcFileName = this.newSampleData.qcFileName
this.params_toDB.dbName = this.newSampleData.dbName
try {
await fetchAndDownload(url, this.params_toDB)
} catch (error) {
console.error(error)
} finally {
this.isSaving = false
}
}
}
},