feat: 对接保存功能,修复部分BUG

This commit is contained in:
Xu Zhimeng 2023-09-20 18:58:35 +08:00
parent 81e5797c73
commit acb93dd817
6 changed files with 162 additions and 15 deletions

33
src/utils/file.js Normal file
View File

@ -0,0 +1,33 @@
import { Modal } from 'ant-design-vue'
import { saveAs } from 'file-saver'
/**
* 弹窗填入文件名保存文件
* @param {Blob} data 数据
* @param {string} ext 扩展名不带.
*/
export const showSaveFileModal = (data, ext) => {
let fileName = ''
const handleClick = event => {
fileName = event.target.value
}
Modal.confirm({
title: 'Please enter file name',
content: h => <a-input onChange={handleClick} />,
okText: 'Cancle',
cancelText: 'Save',
okButtonProps: { style: { backgroundColor: '#b98326', color: '#fff', borderColor: 'transparent' } },
cancelButtonProps: { style: { color: '#fff', backgroundColor: '#31aab0', borderColor: 'transparent' } },
onOk() {
console.log('Cancel')
},
onCancel() {
if (fileName) {
saveAs(data, `${fileName}.${ext}`)
} else {
throw new Error()
}
}
})
}

View File

@ -41,7 +41,11 @@ export default {
const res = await getAction(this.type == 1 ? '/gamma/viewAutomaticAnalysisLog' : '/gamma/viewAutomaticAnalysisLog', { // gammam,beta const res = await getAction(this.type == 1 ? '/gamma/viewAutomaticAnalysisLog' : '/gamma/viewAutomaticAnalysisLog', { // gammam,beta
sampleId sampleId
}) })
this.content = "" if(typeof res == 'string') {
this.content = res
} else if(typeof res == 'object') {
this.$message.error(res.message)
}
} catch (error) { } catch (error) {
console.error(error) console.error(error)
} finally { } finally {

View File

@ -18,11 +18,11 @@
<div class="config-user-library-btns"> <div class="config-user-library-btns">
<div> <div>
<a-button type="primary">Default</a-button> <a-button type="primary" @click="handleDefault">Default</a-button>
<a-button type="primary">Load</a-button> <a-button type="primary">Load</a-button>
</div> </div>
<div> <div>
<a-button type="primary">Save</a-button> <a-button type="primary" :loading="isSaving" @click="handleSave">Save</a-button>
<a-button type="primary">Apply</a-button> <a-button type="primary">Apply</a-button>
</div> </div>
</div> </div>
@ -33,14 +33,17 @@
<script> <script>
import ModalMixin from '@/mixins/ModalMixin' import ModalMixin from '@/mixins/ModalMixin'
import { getAction } from '@/api/manage' import { getAction, postAction } from '@/api/manage'
import SampleDataMixin from '../../SampleDataMixin' import SampleDataMixin from '../../SampleDataMixin'
import { cloneDeep } from 'lodash'
export default { export default {
mixins: [ModalMixin, SampleDataMixin], mixins: [ModalMixin, SampleDataMixin],
data() { data() {
return { return {
list: [], list: [],
targetKeys: [] targetKeys: [],
isSaving: false
} }
}, },
methods: { methods: {
@ -66,6 +69,8 @@ export default {
})) }))
this.targetKeys = UserNuclides.map(item => item) this.targetKeys = UserNuclides.map(item => item)
this.initialTargetKeys = cloneDeep(this.targetKeys)
} else { } else {
this.$message.error(message) this.$message.error(message)
} }
@ -76,6 +81,32 @@ export default {
beforeModalOpen() { beforeModalOpen() {
this.getInfo() this.getInfo()
},
//
handleDefault() {
this.targetKeys = cloneDeep(this.initialTargetKeys)
},
//
async handleSave() {
try {
this.isSaving = true
const { inputFileName: fileName } = this.sampleData
const { success, result, message } = await postAction('/gamma/saveUserLibrary', {
fileName,
userLibraryName: this.targetKeys
})
if (success) {
this.$message.success('Save Success')
} else {
this.$message.error(message)
}
} catch (error) {
console.error(error)
} finally {
this.isSaving = false
}
} }
} }
} }

View File

@ -53,7 +53,7 @@
<div class="operators"> <div class="operators">
<div> <div>
<a-button type="primary">Call</a-button> <a-button type="primary">Call</a-button>
<a-button type="primary">Save</a-button> <a-button type="primary" :loading="isSaving" @click="handleSave">Save</a-button>
</div> </div>
<div> <div>
<a-select v-model="funcId" @change="recalculate"> <a-select v-model="funcId" @change="recalculate">
@ -111,6 +111,7 @@ import { getAction, postAction } from '@/api/manage'
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
import { buildLineSeries } from '@/utils/chartHelper' import { buildLineSeries } from '@/utils/chartHelper'
import SampleDataMixin from '../../SampleDataMixin' import SampleDataMixin from '../../SampleDataMixin'
import { showSaveFileModal } from '@/utils/file'
const columns = [ const columns = [
{ {
@ -240,6 +241,8 @@ export default {
return { return {
isLoading: false, isLoading: false,
isSaving: false,
equation: '', equation: '',
dataSourceList: [], dataSourceList: [],
list: [], list: [],
@ -264,11 +267,11 @@ export default {
const { success, result, message } = await getAction('/gamma/EfficiencyCalibration', { const { success, result, message } = await getAction('/gamma/EfficiencyCalibration', {
sampleId, sampleId,
fileName, fileName,
currentText currentText,
width: 922
}) })
this.isLoading = false this.isLoading = false
if (success) { if (success) {
console.log('%c [ ]-220', 'font-size:13px; background:pink; color:#bf2c9f;', result)
const { list_dataSource, ECutAnalysis_Low, G_energy_span } = result const { list_dataSource, ECutAnalysis_Low, G_energy_span } = result
this.dataSourceList = list_dataSource this.dataSourceList = list_dataSource
if (!currentText) { if (!currentText) {
@ -450,7 +453,8 @@ export default {
m_vCurEffi: this.list.map(item => item.efficiency), m_vCurEffi: this.list.map(item => item.efficiency),
m_vCurUncert: this.uncert, m_vCurUncert: this.uncert,
m_curParam: this.param, m_curParam: this.param,
funcId: this.funcId funcId: this.funcId,
width: 922
}) })
if (success) { if (success) {
this.handleResult(result) this.handleResult(result)
@ -464,6 +468,29 @@ export default {
} }
}, },
//
async handleSave() {
try {
this.isSaving = true
const res = await postAction('/gamma/saveDataEfficiency', {
m_vCurEnergy: this.list.map(item => item.energy),
m_vCurEffi: this.list.map(item => item.efficiency),
m_vCurUncert: this.uncert,
funcId: this.funcId
})
if (typeof res == 'string') {
const blob = new Blob([res], { type: 'text/plain' })
showSaveFileModal(blob, 'ent')
} else if (typeof res == 'object') {
this.$message.error(res.message)
}
} catch (error) {
console.error(error)
} finally {
this.isSaving = false
}
},
// //
async handleApply() { async handleApply() {
try { try {

View File

@ -53,7 +53,7 @@
<div class="operators"> <div class="operators">
<div> <div>
<a-button type="primary">Call</a-button> <a-button type="primary">Call</a-button>
<a-button type="primary">Save</a-button> <a-button type="primary" :loading="isSaving" @click="handleSave">Save</a-button>
</div> </div>
<div> <div>
<a-button type="primary" @click="handleApply">Apply</a-button> <a-button type="primary" @click="handleApply">Apply</a-button>
@ -106,6 +106,7 @@ import { getAction, postAction } from '@/api/manage'
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
import { buildLineSeries } from '@/utils/chartHelper' import { buildLineSeries } from '@/utils/chartHelper'
import SampleDataMixin from '../../SampleDataMixin' import SampleDataMixin from '../../SampleDataMixin'
import { showSaveFileModal } from '@/utils/file'
const columns = [ const columns = [
{ {
@ -202,6 +203,8 @@ export default {
this.columns = columns this.columns = columns
return { return {
isLoading: false, isLoading: false,
isSaving: false,
equation: '', equation: '',
dataSourceList: [], dataSourceList: [],
list: [], list: [],
@ -226,7 +229,8 @@ export default {
const { success, result, message } = await getAction('/gamma/energyCalibration', { const { success, result, message } = await getAction('/gamma/energyCalibration', {
sampleId, sampleId,
fileName, fileName,
currentText currentText,
width: 922
}) })
this.isLoading = false this.isLoading = false
if (success) { if (success) {
@ -409,7 +413,8 @@ export default {
m_vCurCentroid: this.list.map(item => item.channel), m_vCurCentroid: this.list.map(item => item.channel),
m_vCurEnergy: this.list.map(item => item.energy), m_vCurEnergy: this.list.map(item => item.energy),
m_vCurUncert: this.uncert, m_vCurUncert: this.uncert,
m_curParam: this.param m_curParam: this.param,
width: 922
}) })
if (success) { if (success) {
this.handleResult(result) this.handleResult(result)
@ -423,6 +428,28 @@ export default {
} }
}, },
//
async handleSave() {
try {
this.isSaving = true
const res = await postAction('/gamma/saveDataEnergy', {
m_vCurCentroid: this.list.map(item => item.channel),
m_vCurEnergy: this.list.map(item => item.energy),
m_vCurUncert: this.uncert
})
if (typeof res == 'string') {
const blob = new Blob([res], { type: 'text/plain' })
showSaveFileModal(blob, 'ent')
} else if (typeof res == 'object') {
this.$message.error(res.message)
}
} catch (error) {
console.error(error)
} finally {
this.isSaving = false
}
},
// //
async handleApply() { async handleApply() {
try { try {

View File

@ -53,7 +53,7 @@
<div class="operators"> <div class="operators">
<div> <div>
<a-button type="primary">Call</a-button> <a-button type="primary">Call</a-button>
<a-button type="primary">Save</a-button> <a-button type="primary" :loading="isSaving" @click="handleSave">Save</a-button>
</div> </div>
<div> <div>
<a-button type="primary" @click="handleApply">Apply</a-button> <a-button type="primary" @click="handleApply">Apply</a-button>
@ -106,6 +106,7 @@ import { getAction, postAction } from '@/api/manage'
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
import { buildLineSeries } from '@/utils/chartHelper' import { buildLineSeries } from '@/utils/chartHelper'
import SampleDataMixin from '../../SampleDataMixin' import SampleDataMixin from '../../SampleDataMixin'
import { showSaveFileModal } from '@/utils/file'
const columns = [ const columns = [
{ {
@ -202,6 +203,8 @@ export default {
this.columns = columns this.columns = columns
return { return {
isLoading: false, isLoading: false,
isSaving: false,
equation: '', equation: '',
dataSourceList: [], dataSourceList: [],
list: [], list: [],
@ -225,11 +228,11 @@ export default {
const { success, result, message } = await getAction('/gamma/resolutionCalibration', { const { success, result, message } = await getAction('/gamma/resolutionCalibration', {
sampleId, sampleId,
fileName, fileName,
currentText currentText,
width: 922
}) })
this.isLoading = false this.isLoading = false
if (success) { if (success) {
console.log('%c [ ]-220', 'font-size:13px; background:pink; color:#bf2c9f;', result)
const { list_dataSource, ECutAnalysis_Low, G_energy_span } = result const { list_dataSource, ECutAnalysis_Low, G_energy_span } = result
this.dataSourceList = list_dataSource this.dataSourceList = list_dataSource
if (!currentText) { if (!currentText) {
@ -423,6 +426,28 @@ export default {
} }
}, },
//
async handleSave() {
try {
this.isSaving = true
const res = await postAction('/gamma/saveDataResolution', {
m_vCurEnergy: this.list.map(item => item.energy),
m_vCurReso: this.list.map(item => item.fwhm),
m_vCurUncert: this.uncert
})
if (typeof res == 'string') {
const blob = new Blob([res], { type: 'text/plain' })
showSaveFileModal(blob, 'ent')
} else if (typeof res == 'object') {
this.$message.error(res.message)
}
} catch (error) {
console.error(error)
} finally {
this.isSaving = false
}
},
// //
async handleApply() { async handleApply() {
try { try {