完成beta 中excel 的导出功能

This commit is contained in:
renpy 2023-09-07 18:17:24 +08:00
parent 3b516367d3
commit 1c27c14564
10 changed files with 103 additions and 14 deletions

View File

@ -80,6 +80,7 @@ export default {
} }
}, },
handleOk() { handleOk() {
this.fileName=""
if (this.content) { if (this.content) {
let strData = new Blob([this.content], { type: 'text/plain;charset=utf-8' }); let strData = new Blob([this.content], { type: 'text/plain;charset=utf-8' });
// if (this.type == 1 || this.type == 3) { // if (this.type == 1 || this.type == 3) {

View File

@ -54,6 +54,7 @@ export default {
}, },
handleOk() { handleOk() {
this.fileName=""
if (this.content) { if (this.content) {
let _this = this let _this = this
let strData = new Blob([this.content], { type: 'text/plain;charset=utf-8' }); let strData = new Blob([this.content], { type: 'text/plain;charset=utf-8' });

View File

@ -3,15 +3,17 @@
<a-table :loading="isLoading" :columns="columns" :dataSource="list" :pagination="false"> </a-table> <a-table :loading="isLoading" :columns="columns" :dataSource="list" :pagination="false"> </a-table>
<a-space slot="custom-footer" :size="20"> <a-space slot="custom-footer" :size="20">
<a-button type="primary" @click="SaveText">Save Text</a-button> <a-button type="primary" @click="SaveText">Save Text</a-button>
<a-button type="primary">Save Excel</a-button> <a-button type="primary" @click="handleExportToExcel">Save Excel</a-button>
<a-button type="primary" @click="visible = false">Cancel</a-button> <a-button type="primary" @click="visible = false">Cancel</a-button>
</a-space> </a-space>
</custom-modal> </custom-modal>
</template> </template>
<script> <script>
import { getAction } from '@/api/manage' import { getAction, getFileAction } from '@/api/manage'
import ModalMixin from '@/mixins/ModalMixin' import ModalMixin from '@/mixins/ModalMixin'
import { saveAs } from 'file-saver';
import SampleDataMixin from '@/views/spectrumAnalysis/SampleDataMixin'
const columns = [ const columns = [
{ {
@ -47,7 +49,7 @@ const columns = [
] ]
export default { export default {
mixins: [ModalMixin], mixins: [ModalMixin, SampleDataMixin],
props: { props: {
sampleId: { sampleId: {
type: Number type: Number
@ -59,7 +61,8 @@ export default {
list: [], list: [],
isLoading: false, isLoading: false,
text: '', text: '',
fileName: '' fileName: '',
fileName_excel: ''
} }
}, },
methods: { methods: {
@ -128,6 +131,7 @@ export default {
this.getData() this.getData()
}, },
SaveText() { SaveText() {
this.fileName=""
this.text = `#QC RESULT\n${this.columns[0].title} ${this.columns[1].title} ${this.columns[2].title} ${this.columns[3].title}\n` this.text = `#QC RESULT\n${this.columns[0].title} ${this.columns[1].title} ${this.columns[2].title} ${this.columns[3].title}\n`
this.list.forEach(item => { this.list.forEach(item => {
let str = "" let str = ""
@ -156,6 +160,43 @@ export default {
} }
}, },
}); });
},
// Excel
handleExportToExcel() {
this.fileName_excel=""
if (this.list.length>0) {
let _this = this
this.$confirm({
title: 'Please enter file name',
content: h => <a-input v-model={_this.fileName_excel} />,
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 (_this.fileName_excel) {
_this.visible = false
let params = {
sampleId: _this.sampleData.sampleId||"",
fileName: _this.sampleData.fileName
}
getFileAction('/spectrumAnalysis/exportQCResult', params).then(res => {
if (res.code && res.code == 500) {
this.$message.warning("This operation fails. Contact your system administrator")
} else {
const blob = new Blob([res], { type: "application/vnd.ms-excel" })
saveAs(blob, `${_this.fileName_excel}`)
}
})
}
},
});
} else {
this.$message.warning("No downloadable data")
}
} }
} }
} }

View File

@ -7,7 +7,7 @@
<div slot="custom-footer"> <div slot="custom-footer">
<a-space :size="20"> <a-space :size="20">
<a-button type="primary" @click="saveText">Save Text</a-button> <a-button type="primary" @click="saveText">Save Text</a-button>
<a-button type="primary">Save Excel</a-button> <a-button type="primary" @click="handleExportToExcel">Save Excel</a-button>
<a-button @click="visible = false">Cancel</a-button> <a-button @click="visible = false">Cancel</a-button>
</a-space> </a-space>
</div> </div>
@ -15,11 +15,12 @@
</template> </template>
<script> <script>
import { getAction } from '@/api/manage' import { getAction, getFileAction } from '@/api/manage'
import ModalMixin from '@/mixins/ModalMixin' import ModalMixin from '@/mixins/ModalMixin'
import { saveAs } from 'file-saver'; import { saveAs } from 'file-saver';
import SampleDataMixin from '@/views/spectrumAnalysis/SampleDataMixin'
export default { export default {
mixins: [ModalMixin], mixins: [ModalMixin, SampleDataMixin],
props: { props: {
sampleId: { sampleId: {
type: Number type: Number
@ -29,7 +30,8 @@ export default {
return { return {
content: '', content: '',
isLoading: true, isLoading: true,
fileName: '' fileName: '',
fileName_excel: ''
} }
}, },
methods: { methods: {
@ -60,6 +62,7 @@ export default {
} }
}, },
saveText() { saveText() {
this.fileName=""
if (this.content) { if (this.content) {
let strData = new Blob([this.content], { type: 'text/plain;charset=utf-8' }); let strData = new Blob([this.content], { type: 'text/plain;charset=utf-8' });
// saveAs(strData, `Beta-View Sample Infomation.txt`) // saveAs(strData, `Beta-View Sample Infomation.txt`)
@ -84,6 +87,43 @@ export default {
} else { } else {
this.$message.warning("No data can be saved!") this.$message.warning("No data can be saved!")
} }
},
// Excel
handleExportToExcel() {
this.fileName_excel=""
if (this.content) {
let _this = this
this.$confirm({
title: 'Please enter file name',
content: h => <a-input v-model={_this.fileName_excel} />,
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 (_this.fileName_excel) {
_this.visible = false
let params = {
sampleId: _this.sampleData.sampleId||"",
fileName: _this.sampleData.fileName
}
getFileAction('/spectrumAnalysis/exportSampleInformation', params).then(res => {
if (res.code && res.code == 500) {
this.$message.warning("This operation fails. Contact your system administrator")
} else {
const blob = new Blob([res], { type: "application/vnd.ms-excel" })
saveAs(blob, `${_this.fileName_excel}`)
}
})
}
},
});
} else {
this.$message.warning("No downloadable data")
}
} }
} }
} }

View File

@ -76,6 +76,7 @@ export default {
this.currTab = key this.currTab = key
}, },
handleOk() { handleOk() {
this.fileName=""
let text = "" let text = ""
if (this.currTab == 1) { if (this.currTab == 1) {
text=this.content.sample.join('\n') text=this.content.sample.join('\n')

View File

@ -52,6 +52,7 @@ export default {
}) })
}, },
handleOk() { handleOk() {
this.fileName=""
if (this.text) { if (this.text) {
let strData = new Blob([this.text], { type: 'text/plain;charset=utf-8' }); let strData = new Blob([this.text], { type: 'text/plain;charset=utf-8' });
// saveAs(strData, `GammaViewer Log.txt`) // saveAs(strData, `GammaViewer Log.txt`)

View File

@ -170,6 +170,7 @@ export default {
// Excel // Excel
handleExportToExcel() { handleExportToExcel() {
this.fileName=""
if (this.list.length > 0) { if (this.list.length > 0) {
let _this = this let _this = this
this.$confirm({ this.$confirm({
@ -188,8 +189,8 @@ export default {
let params = { let params = {
// sampleId: "426530", // sampleId: "426530",
// fileName: "CAX05_001-20230731_1528_S_FULL_37563.6.PHD" // fileName: "CAX05_001-20230731_1528_S_FULL_37563.6.PHD"
sampleId: this.sampleId, sampleId: _this.sampleId,
fileName: this.sampleData.fileName fileName: _this.sampleData.fileName
} }
getFileAction('/gamma/exportRadionuclideActivity', params).then(res => { getFileAction('/gamma/exportRadionuclideActivity', params).then(res => {
if (res.code && res.code == 500) { if (res.code && res.code == 500) {

View File

@ -98,6 +98,7 @@ export default {
}, },
// Excel // Excel
handleExportToExcel() { handleExportToExcel() {
this.fileName=""
if (this.list.length > 0) { if (this.list.length > 0) {
let _this = this let _this = this
this.$confirm({ this.$confirm({
@ -116,8 +117,8 @@ export default {
let params = { let params = {
// sampleId: "426530", // sampleId: "426530",
// fileName: "CAX05_001-20230731_1528_S_FULL_37563.6.PHD" // fileName: "CAX05_001-20230731_1528_S_FULL_37563.6.PHD"
sampleId: this.sampleId, sampleId: _this.sampleId,
fileName: this.sampleData.fileName fileName: _this.sampleData.fileName
} }
getFileAction('/gamma/exportQCResult', params).then(res => { getFileAction('/gamma/exportQCResult', params).then(res => {
if (res.code && res.code == 500) { if (res.code && res.code == 500) {

View File

@ -127,6 +127,7 @@ export default {
}, },
// Excel // Excel
handleExportToExcel() { handleExportToExcel() {
this.fileName=""
if (Object.keys(this.data).length > 0) { if (Object.keys(this.data).length > 0) {
let _this = this let _this = this
this.$confirm({ this.$confirm({

View File

@ -129,6 +129,7 @@ export default {
// Excel // Excel
handleExportToExcel() { handleExportToExcel() {
this.fileName=""
if (this.list.length > 0) { if (this.list.length > 0) {
let _this = this let _this = this
this.$confirm({ this.$confirm({
@ -147,8 +148,8 @@ export default {
let params = { let params = {
// sampleId: "426530", // sampleId: "426530",
// fileName: "CAX05_001-20230731_1528_S_FULL_37563.6.PHD" // fileName: "CAX05_001-20230731_1528_S_FULL_37563.6.PHD"
sampleId: this.sampleId, sampleId: _this.sampleId,
fileName: this.sampleData.fileName fileName: _this.sampleData.fileName
} }
getFileAction('/gamma/exportPeakInformation', params).then(res => { getFileAction('/gamma/exportPeakInformation', params).then(res => {
if (res.code && res.code == 500) { if (res.code && res.code == 500) {