Merge branch 'feature-analysis-RLR-renpy' of http://git.hivekion.com:3000/xiaoguangbin/AnalysisSystemForRadionuclide_vue into master-dev
This commit is contained in:
commit
692cb33145
|
@ -37,6 +37,7 @@ export const showSaveFileModal = (data, ext) => {
|
|||
* 读文件
|
||||
* @param {File} file
|
||||
* @param { 'arrayBuffer' | 'text' | 'dataURL' | 'binaryString'} fileType
|
||||
* @returns {Promise<string | ArrayBuffer}
|
||||
*/
|
||||
export const readFile = (file, fileType = 'text') => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -66,8 +67,16 @@ export const readFile = (file, fileType = 'text') => {
|
|||
export const zipFile = async (fileList, zipName) => {
|
||||
const zip = new JSZip()
|
||||
const promises = []
|
||||
|
||||
const readFileWithName = async file => {
|
||||
const data = await readFile(file, 'arrayBuffer')
|
||||
return {
|
||||
fileName: file.name,
|
||||
data
|
||||
}
|
||||
}
|
||||
fileList.forEach(file => {
|
||||
promises.push(readFile(file, 'arrayBuffer'))
|
||||
promises.push(readFileWithName(file))
|
||||
})
|
||||
const result = await Promise.all(promises)
|
||||
result.forEach(res => {
|
||||
|
|
|
@ -1,4 +1,30 @@
|
|||
/**
|
||||
* PHD 类型
|
||||
*/
|
||||
export const PHD_DATA_TYPE = {
|
||||
QCPHD: 'QCPHD',
|
||||
DETBKPHD: 'DETBKPHD',
|
||||
SAMPLEPHD: 'SAMPLEPHD',
|
||||
GASBKPHD: 'GASBKPHD'
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是不是sample
|
||||
* @param {*} dataType
|
||||
* @returns
|
||||
*/
|
||||
export const isSample = dataType => {
|
||||
return ['SAMPLEPHD', 'SPHDP', 'SPHDF'].includes(dataType)
|
||||
}
|
||||
|
||||
export class PHDParser {
|
||||
/**
|
||||
* 根据Block解析出的结果集
|
||||
*/
|
||||
blocks = {
|
||||
baseInfo: []
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
*/
|
||||
|
@ -30,45 +56,95 @@ export class PHDParser {
|
|||
*/
|
||||
otherFilePrefixes = []
|
||||
|
||||
/**
|
||||
* 该文件是不是sample
|
||||
*/
|
||||
isSample = false
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param {string} text
|
||||
*/
|
||||
constructor(text) {
|
||||
const getLine = this.readTextLine(text)
|
||||
const dataTypeLine = getLine(4)
|
||||
const fileTypeLine = getLine(6)
|
||||
const fileNameLine = getLine(8)
|
||||
const liveTimeLine = getLine(18)
|
||||
this.splitByBlock(text)
|
||||
this.dataType = this.getBaseInfoByTag('DATA_TYPE')[0]
|
||||
this.isSample = isSample(this.dataType)
|
||||
|
||||
this.dataType = this.getOnymousData(dataTypeLine)[0]
|
||||
const fileType = this.splitLineText(fileTypeLine)
|
||||
this.fileType = fileType[2]
|
||||
this.qualify = fileType[4]
|
||||
const headerInfo = this.getBlockInfo('Header')
|
||||
const headerInfoLine1 = this.splitLineText(headerInfo[0])
|
||||
this.fileType = headerInfoLine1[2]
|
||||
this.qualify = headerInfoLine1[4]
|
||||
|
||||
const liveTime = parseFloat(this.splitLineText(liveTimeLine)[3]).toFixed(1)
|
||||
const liveTime = parseFloat(this.getBlockStr('Acquisition', 0, 3)).toFixed(1)
|
||||
this.liveTime = liveTime.indexOf('.0') == -1 ? liveTime : liveTime.slice(0, -2)
|
||||
|
||||
// 如果是 Beta 谱
|
||||
if (this.fileType == 'B') {
|
||||
// 如果解析的是sample 文件,则获取其他三个文件
|
||||
if (this.dataType == PHD_DATA_TYPE.SAMPLEPHD) {
|
||||
const filePrefixes = this.getFilePrefixes(fileNameLine)
|
||||
// 如果解析的是sample 文件,则解析相关联的文件
|
||||
if (this.isSample) {
|
||||
const filePrefixes = this.getFilePrefixes(headerInfo[2])
|
||||
this.sampleFilePrefix = filePrefixes.splice(0, 1)[0]
|
||||
this.otherFilePrefixes = filePrefixes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文本按行分割
|
||||
* 根据块类型分割
|
||||
* @param {string} text
|
||||
* @returns { (line: number) => string }
|
||||
*/
|
||||
readTextLine(text) {
|
||||
const splited = text.split('\n')
|
||||
return line => {
|
||||
return splited[line - 1]
|
||||
splitByBlock(text) {
|
||||
const lines = (text = text.replace(/\r{0,1}\n/g, '\n').split('\n'))
|
||||
let blockType = 'baseInfo'
|
||||
for (const line of lines) {
|
||||
// 如果以#开头
|
||||
if (line.startsWith('#')) {
|
||||
blockType = line.slice(1)
|
||||
if (blockType.startsWith('Header')) {
|
||||
blockType = 'Header'
|
||||
}
|
||||
this.blocks[blockType] = []
|
||||
continue
|
||||
}
|
||||
this.blocks[blockType].push(line.trim())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据块名拿到块内容
|
||||
* @param {string} blockName
|
||||
* @returns {Array<string>}
|
||||
*/
|
||||
getBlockInfo(blockName) {
|
||||
return this.blocks[blockName]
|
||||
}
|
||||
|
||||
/**
|
||||
* 在baseInfo中根据tag查找值
|
||||
* @param {*} tag
|
||||
* @returns {Array<string>}
|
||||
*/
|
||||
getBaseInfoByTag(tag) {
|
||||
const baseInfo = this.getBlockInfo('baseInfo')
|
||||
const map = new Map()
|
||||
baseInfo.forEach(line => {
|
||||
if (line.startsWith(tag)) {
|
||||
map.set(tag, this.getOnymousData(line))
|
||||
}
|
||||
})
|
||||
|
||||
return map.get(tag)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据行号和位置在block中查找字符
|
||||
* @param {string} blockName
|
||||
* @param {number} lineNum
|
||||
* @param {number} index
|
||||
* @returns {string}
|
||||
*/
|
||||
getBlockStr(blockName, lineNum, index) {
|
||||
const blockInfo = this.getBlockInfo(blockName)
|
||||
const lineText = blockInfo[lineNum]
|
||||
const splited = this.splitLineText(lineText)
|
||||
return splited[index]
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,19 +174,9 @@ export class PHDParser {
|
|||
const filePrefixes = unHandledfilePrefixes
|
||||
.filter(filePrefix => filePrefix)
|
||||
.map(filePrefix => {
|
||||
filePrefix = filePrefix.replace(/(\d{4})\/(\d{2})\/(\d{2})-(\d{2}):(\d{2})/, '$1$2$3_$4$5')
|
||||
filePrefix = filePrefix.replace(/(\d{4})\/(\d{2})\/(\d{2})-(\d{2}):(\d{2})(:\d{2}\.\d)?/, '$1$2$3_$4$5')
|
||||
return filePrefix + '_'
|
||||
})
|
||||
return filePrefixes
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHD 类型
|
||||
*/
|
||||
export const PHD_DATA_TYPE = {
|
||||
QCPHD: 'QCPHD',
|
||||
DETBKPHD: 'DETBKPHD',
|
||||
SAMPLEPHD: 'SAMPLEPHD',
|
||||
GASBKPHD: 'GASBKPHD'
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ export default {
|
|||
*/
|
||||
async handleLoad() {
|
||||
if (!this.selectedRowKeys.length) {
|
||||
this.$message.warn('Please Select Databases To Load')
|
||||
this.$message.warn('Please Select Sample To Load')
|
||||
return
|
||||
}
|
||||
this.selectedRowKeys = []
|
||||
|
|
|
@ -205,7 +205,7 @@
|
|||
import { getAction, postAction } from '../../../../api/manage'
|
||||
import { FilePicker } from '@/utils/FilePicker'
|
||||
import { readFile, zipFile } from '@/utils/file'
|
||||
import { PHDParser, PHD_DATA_TYPE } from '@/utils/phdHelper'
|
||||
import { isSample, PHDParser, PHD_DATA_TYPE } from '@/utils/phdHelper'
|
||||
import ModalMixin from '@/mixins/ModalMixin'
|
||||
|
||||
const columns = [
|
||||
|
@ -417,6 +417,8 @@ export default {
|
|||
fileName: `${sampleFilePrefix}S_${qualify}_${liveTime}.PHD`,
|
||||
}
|
||||
|
||||
// 如果是Beta Gamma,则查找其他的文件
|
||||
if (phdParser.fileType == 'B') {
|
||||
const iter = await this.directoryHanlder.values()
|
||||
const fileList = []
|
||||
|
||||
|
@ -468,6 +470,13 @@ export default {
|
|||
}
|
||||
}
|
||||
record.qcFileName = qcFileInfo
|
||||
} else {
|
||||
Object.assign(record, {
|
||||
gasFileName: undefined,
|
||||
detFileName: undefined,
|
||||
qcFileName: undefined,
|
||||
})
|
||||
}
|
||||
}
|
||||
// 非sample
|
||||
else {
|
||||
|
@ -491,8 +500,7 @@ export default {
|
|||
let currDataType = ''
|
||||
switch (column) {
|
||||
case 'sampleFileName':
|
||||
currDataType = PHD_DATA_TYPE.SAMPLEPHD
|
||||
break
|
||||
return isSample(dataType)
|
||||
case 'gasFileName':
|
||||
currDataType = PHD_DATA_TYPE.GASBKPHD
|
||||
break
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
<title-over-border title="Format">
|
||||
<a-radio-group v-model="saveFormat" class="format-radio-group">
|
||||
<a-radio value="txt">Save as Txt</a-radio>
|
||||
<a-radio value="excel">Save as Excel</a-radio>
|
||||
<a-radio value="xls">Save as Excel</a-radio>
|
||||
<a-radio value="html">Save as Html</a-radio>
|
||||
</a-radio-group>
|
||||
</title-over-border>
|
||||
</div>
|
||||
|
@ -19,7 +20,6 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { downloadFile } from '../../../../api/manage'
|
||||
import TitleOverBorder from '../TitleOverBorder.vue'
|
||||
export default {
|
||||
components: { TitleOverBorder },
|
||||
|
@ -41,8 +41,7 @@ export default {
|
|||
},
|
||||
|
||||
handleOk() {
|
||||
console.log('%c [ save ]-22', 'font-size:13px; background:pink; color:#bf2c9f;')
|
||||
downloadFile('', 'result.' + this.saveFormat, {})
|
||||
this.$emit('save', this.saveFormat)
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
@ -73,7 +72,7 @@ export default {
|
|||
}
|
||||
|
||||
.format-radio-group {
|
||||
.ant-radio-wrapper:first-child {
|
||||
.ant-radio-wrapper:not(:last-child) {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
<!-- Nuclide Activity and MDC 弹窗结束 -->
|
||||
|
||||
<!-- Save Setting 弹窗开始 -->
|
||||
<save-setting-modal v-model="saveSettingModalVisible" />
|
||||
<save-setting-modal v-model="saveSettingModalVisible" @save="handleSaveResultsToFile" />
|
||||
<!-- Save Setting 弹窗结束 -->
|
||||
|
||||
<!-- 分析-设置弹窗开始 -->
|
||||
|
@ -156,10 +156,7 @@
|
|||
<!-- Beta-Gamma 的Comments 结束 -->
|
||||
|
||||
<!-- Beta-Gamma 的Energy Calibration开始 -->
|
||||
<beta-gamma-energy-calibration-modal
|
||||
v-model="betaGammaEnergyCalibrationModalVisible"
|
||||
@sendInfo="getCheckFlag"
|
||||
/>
|
||||
<beta-gamma-energy-calibration-modal v-model="betaGammaEnergyCalibrationModalVisible" @sendInfo="getCheckFlag" />
|
||||
<!-- Beta-Gamma 的Energy Calibration结束 -->
|
||||
|
||||
<!-- Beta-Gamma 的 Extrapolation 弹窗开始 -->
|
||||
|
@ -191,7 +188,7 @@
|
|||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { postAction } from '@/api/manage'
|
||||
import { downloadFile, postAction } from '@/api/manage'
|
||||
import GammaAnalysis from './gamma-analysis.vue'
|
||||
import BetaGammaAnalysis from './beta-gamma-analysis.vue'
|
||||
import SpectraListInMenu from './components/SpectraListInMenu.vue'
|
||||
|
@ -460,8 +457,31 @@ export default {
|
|||
},
|
||||
|
||||
// 保存结果到文件, 服务端生成文件,前端下载
|
||||
handleSaveResultsToFile() {
|
||||
this.saveSettingModalVisible = true
|
||||
async handleSaveResultsToFile(saveFormat) {
|
||||
const url =
|
||||
saveFormat == 'xls'
|
||||
? '/spectrumAnalysis/saveToExcel'
|
||||
: saveFormat == 'txt'
|
||||
? '/spectrumAnalysis/saveToTxt'
|
||||
: saveFormat == 'html'
|
||||
? '/spectrumAnalysis/saveToHTML'
|
||||
: ''
|
||||
if (!this.resultDisplayFlag) {
|
||||
this.$message.warn('Please Analyse Spectrum First')
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
downloadFile(url, `result.${saveFormat}`, this.params_toDB, 'post')
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -478,7 +498,7 @@ export default {
|
|||
const hideLoading = this.$message.loading('Saving...', 0)
|
||||
try {
|
||||
const { success, message } = await getAction('/gamma/saveToDB', {
|
||||
fileName: this.sampleData.inputFileName
|
||||
fileName: this.sampleData.inputFileName,
|
||||
})
|
||||
if (success) {
|
||||
this.$message.success('Save Success')
|
||||
|
@ -727,7 +747,7 @@ export default {
|
|||
},
|
||||
on: {
|
||||
menuClick: () => {
|
||||
this.handleSaveResultsToFile()
|
||||
this.saveSettingModalVisible = true
|
||||
},
|
||||
submenuClick: ({ item, child }) => {
|
||||
if (item.title == 'Save Results to DB') {
|
||||
|
|
Loading…
Reference in New Issue
Block a user