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
sampleId
})
this.content = ""
if(typeof res == 'string') {
this.content = res
} else if(typeof res == 'object') {
this.$message.error(res.message)
}
} catch (error) {
console.error(error)
} finally {

View File

@ -18,11 +18,11 @@
<div class="config-user-library-btns">
<div>
<a-button type="primary">Default</a-button>
<a-button type="primary" @click="handleDefault">Default</a-button>
<a-button type="primary">Load</a-button>
</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>
</div>
</div>
@ -33,14 +33,17 @@
<script>
import ModalMixin from '@/mixins/ModalMixin'
import { getAction } from '@/api/manage'
import { getAction, postAction } from '@/api/manage'
import SampleDataMixin from '../../SampleDataMixin'
import { cloneDeep } from 'lodash'
export default {
mixins: [ModalMixin, SampleDataMixin],
data() {
return {
list: [],
targetKeys: []
targetKeys: [],
isSaving: false
}
},
methods: {
@ -66,6 +69,8 @@ export default {
}))
this.targetKeys = UserNuclides.map(item => item)
this.initialTargetKeys = cloneDeep(this.targetKeys)
} else {
this.$message.error(message)
}
@ -76,6 +81,32 @@ export default {
beforeModalOpen() {
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>
<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>
<a-select v-model="funcId" @change="recalculate">
@ -111,6 +111,7 @@ import { getAction, postAction } from '@/api/manage'
import { cloneDeep } from 'lodash'
import { buildLineSeries } from '@/utils/chartHelper'
import SampleDataMixin from '../../SampleDataMixin'
import { showSaveFileModal } from '@/utils/file'
const columns = [
{
@ -240,6 +241,8 @@ export default {
return {
isLoading: false,
isSaving: false,
equation: '',
dataSourceList: [],
list: [],
@ -264,11 +267,11 @@ export default {
const { success, result, message } = await getAction('/gamma/EfficiencyCalibration', {
sampleId,
fileName,
currentText
currentText,
width: 922
})
this.isLoading = false
if (success) {
console.log('%c [ ]-220', 'font-size:13px; background:pink; color:#bf2c9f;', result)
const { list_dataSource, ECutAnalysis_Low, G_energy_span } = result
this.dataSourceList = list_dataSource
if (!currentText) {
@ -450,7 +453,8 @@ export default {
m_vCurEffi: this.list.map(item => item.efficiency),
m_vCurUncert: this.uncert,
m_curParam: this.param,
funcId: this.funcId
funcId: this.funcId,
width: 922
})
if (success) {
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() {
try {

View File

@ -53,7 +53,7 @@
<div class="operators">
<div>
<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>
<a-button type="primary" @click="handleApply">Apply</a-button>
@ -106,6 +106,7 @@ import { getAction, postAction } from '@/api/manage'
import { cloneDeep } from 'lodash'
import { buildLineSeries } from '@/utils/chartHelper'
import SampleDataMixin from '../../SampleDataMixin'
import { showSaveFileModal } from '@/utils/file'
const columns = [
{
@ -202,6 +203,8 @@ export default {
this.columns = columns
return {
isLoading: false,
isSaving: false,
equation: '',
dataSourceList: [],
list: [],
@ -226,7 +229,8 @@ export default {
const { success, result, message } = await getAction('/gamma/energyCalibration', {
sampleId,
fileName,
currentText
currentText,
width: 922
})
this.isLoading = false
if (success) {
@ -409,7 +413,8 @@ export default {
m_vCurCentroid: this.list.map(item => item.channel),
m_vCurEnergy: this.list.map(item => item.energy),
m_vCurUncert: this.uncert,
m_curParam: this.param
m_curParam: this.param,
width: 922
})
if (success) {
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() {
try {

View File

@ -53,7 +53,7 @@
<div class="operators">
<div>
<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>
<a-button type="primary" @click="handleApply">Apply</a-button>
@ -106,6 +106,7 @@ import { getAction, postAction } from '@/api/manage'
import { cloneDeep } from 'lodash'
import { buildLineSeries } from '@/utils/chartHelper'
import SampleDataMixin from '../../SampleDataMixin'
import { showSaveFileModal } from '@/utils/file'
const columns = [
{
@ -202,6 +203,8 @@ export default {
this.columns = columns
return {
isLoading: false,
isSaving: false,
equation: '',
dataSourceList: [],
list: [],
@ -225,11 +228,11 @@ export default {
const { success, result, message } = await getAction('/gamma/resolutionCalibration', {
sampleId,
fileName,
currentText
currentText,
width: 922
})
this.isLoading = false
if (success) {
console.log('%c [ ]-220', 'font-size:13px; background:pink; color:#bf2c9f;', result)
const { list_dataSource, ECutAnalysis_Low, G_energy_span } = result
this.dataSourceList = list_dataSource
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() {
try {