From d31a12b8e4ca9e5529002f615d9129af3e5b7402 Mon Sep 17 00:00:00 2001 From: Xu Zhimeng Date: Fri, 10 Nov 2023 18:12:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DPHDParser=20=E5=AF=B9?= =?UTF-8?q?=E5=BC=82=E5=BD=A2=E6=96=87=E4=BB=B6=E5=90=8D=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/phdHelper.js | 22 +++++++++++++-- src/views/spectrumAnalysis/gamma-analysis.vue | 28 +++++++++++++++---- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/utils/phdHelper.js b/src/utils/phdHelper.js index 3bd4949..df5a33e 100644 --- a/src/utils/phdHelper.js +++ b/src/utils/phdHelper.js @@ -17,6 +17,21 @@ export const isSample = dataType => { return ['SAMPLEPHD', 'SPHDP', 'SPHDF'].includes(dataType) } +export const getSampleTypeIdentify = dataType => { + if(isSample(dataType)) { + return 'S' + } else { + switch (dataType) { + case PHD_DATA_TYPE.QCPHD: + return 'Q' + case PHD_DATA_TYPE.DETBKPHD: + return 'D' + case PHD_DATA_TYPE.GASBKPHD: + return 'G' + } + } +} + export class PHDParser { /** * 根据Block解析出的结果集 @@ -75,8 +90,8 @@ export class PHDParser { this.fileType = headerInfoLine1[2] this.qualify = headerInfoLine1[4] - const liveTime = parseFloat(this.getBlockStr('Acquisition', 0, 3)).toFixed(1) - this.liveTime = liveTime.indexOf('.0') == -1 ? liveTime : liveTime.slice(0, -2) + const liveTime = parseFloat(this.getBlockStr('Acquisition', 0, 3)) + this.liveTime = parseFloat(liveTime.toPrecision(6)) // 如果解析的是sample 文件,则解析相关联的文件 if (this.isSample) { @@ -87,6 +102,9 @@ export class PHDParser { } else { this.sampleFilePrefix = this.getGammaFilePrefix(headerInfo[2]) } + } else { + const filePrefixes = this.getFilePrefixes(headerInfo[2]) + this.sampleFilePrefix = filePrefixes.splice(0, 1)[0] } } diff --git a/src/views/spectrumAnalysis/gamma-analysis.vue b/src/views/spectrumAnalysis/gamma-analysis.vue index 85d45a8..d632d2f 100644 --- a/src/views/spectrumAnalysis/gamma-analysis.vue +++ b/src/views/spectrumAnalysis/gamma-analysis.vue @@ -139,9 +139,10 @@ import Vue from 'vue' import { ACCESS_TOKEN } from '@/store/mutation-types' import StripModal from './components/Modals/StripModal.vue' import { FilePicker } from '@/utils/FilePicker' -import { zipFile } from '@/utils/file' +import { readFile, zipFile } from '@/utils/file' import { findNearPeak } from '@/utils/sampleHelper' import { add, subtract } from 'xe-utils/methods' +import { PHDParser, isSample, getSampleTypeIdentify } from '@/utils/phdHelper' export default { props: { @@ -1372,7 +1373,7 @@ export default { DetailedInformation: this.detailedInfomation, QCFlag: this.qcFlags, BaseCtrls: this.baseCtrls, - bAnalyed: this.bAnalyed + bAnalyed: this.bAnalyed, }) this.clearCompareLine() @@ -1382,7 +1383,16 @@ export default { // 分析工具Accept时刷新部分数据 handleAccept(data) { - const { allData, peak, shadowChannelChart, shadowEnergyChart, shapeChannelData, shapeEnergyData, barChart, BaseCtrls } = data + const { + allData, + peak, + shadowChannelChart, + shadowEnergyChart, + shapeChannelData, + shapeEnergyData, + barChart, + BaseCtrls, + } = data const result = { DetailedInformation: this.detailedInfomation, @@ -1395,7 +1405,7 @@ export default { peak, BaseCtrls, bAnalyed: this.bAnalyed, - barChart + barChart, } this.clearCompareLine() this.redrawPeakLine() @@ -1423,18 +1433,26 @@ export default { try { const [fileHandle] = await FilePicker.chooseFile(false, [{ accept: { 'text/phd': ['.phd'] } }]) const file = await fileHandle.getFile() + const text = await readFile(file) + const parser = new PHDParser(text) + const { sampleFilePrefix, qualify, dataType, liveTime } = parser + + const hide = this.$message.loading('Uploading...', 0) + const zipedFiles = await zipFile([file], 'test.zip') try { const formData = new FormData() formData.append('file', zipedFiles) const { success, message } = await postAction('/spectrumFile/upload', formData) if (success) { - this.handleFileSelect(file.name) + this.handleFileSelect(`${sampleFilePrefix}${getSampleTypeIdentify(dataType)}_${qualify}_${liveTime}.PHD`) } else { this.$message.error(message) } } catch (error) { console.error(error) + } finally { + hide() } } catch (error) { console.error(error)