fix: 修复PHDParser 对异形文件名解析问题
This commit is contained in:
		
							parent
							
								
									88348f4f78
								
							
						
					
					
						commit
						d31a12b8e4
					
				|  | @ -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] | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user