下载文件添加自定义文件名称的逻辑

实现beta的弹窗文件下载功能
This commit is contained in:
renpy 2023-09-06 15:12:15 +08:00
parent 301a42b93e
commit c0139480f5
7 changed files with 176 additions and 21 deletions

View File

@ -33,7 +33,8 @@ export default {
data() { data() {
return { return {
content: '', content: '',
isLoading: true isLoading: true,
fileName: ''
} }
}, },
methods: { methods: {
@ -80,7 +81,27 @@ export default {
}, },
handleOk() { handleOk() {
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, `${this.type == 1 || this.type == 3 ? 'ARR' : 'RRR'}.txt`) // if (this.type == 1 || this.type == 3) {
// saveAs(strData, `${this.type == 1 ?'Gamma-':'Beta-'} ARR.txt`)
// } else {
// saveAs(strData, `${this.type == 2 ?'Gamma-':'Beta-'} RRR.txt`)
// }
let _this = this
this.$confirm({
title: 'Please enter file name',
content: h => <a-input v-model={_this.fileName} />,
okText: 'Save',
cancelText: 'Cancle',
onOk() {
if (_this.fileName) {
_this.visible = false
saveAs(strData, `${_this.fileName}.txt`)
}
},
onCancel() {
console.log('Cancel');
},
});
} }
} }
} }

View File

@ -1,10 +1,16 @@
<template> <template>
<custom-modal v-model="visible" :width="1000" title="Auto Process Log Viewer" :okHandler="handleOk"> <custom-modal v-model="visible" :width="1000" title="Auto Process Log Viewer">
<a-spin :spinning="isLoading"> <a-spin :spinning="isLoading">
<pre> <pre>
{{ content }} {{ content }}
</pre> </pre>
</a-spin> </a-spin>
<div slot="custom-footer" style="text-align: center;">
<a-space :size="20">
<a-button type="primary" @click="handleOk">Save</a-button>
<a-button @click="visible = false">Cancel</a-button>
</a-space>
</div>
</custom-modal> </custom-modal>
</template> </template>
@ -23,7 +29,8 @@ export default {
}, },
data() { data() {
return { return {
content: '' content: '',
fileName: ''
} }
}, },
methods: { methods: {
@ -31,7 +38,7 @@ export default {
try { try {
this.isLoading = true this.isLoading = true
const { sampleId } = this.sampleData const { sampleId } = this.sampleData
const res = await getAction(this.type == 1 ? '/gamma/viewAutomaticAnalysisLog' : '', { const res = await getAction(this.type == 1 ? '/gamma/viewAutomaticAnalysisLog' : '/gamma/viewAutomaticAnalysisLog', { // gammam,beta
sampleId sampleId
}) })
this.content = res this.content = res
@ -47,8 +54,24 @@ export default {
}, },
handleOk() { handleOk() {
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' });
saveAs(strData, `Automatic Analysis Log.txt`) // saveAs(strData, `${this.type == 1 ?'Gamma-':'Beta-'}Automatic Analysis Log.txt`)
this.$confirm({
title: 'Please enter file name',
content: h => <a-input v-model={_this.fileName} />,
okText: 'Save',
cancelText: 'Cancle',
onOk() {
if (_this.fileName) {
_this.visible = false
saveAs(strData, `${_this.fileName}.txt`)
}
},
onCancel() {
console.log('Cancel');
},
});
} }
} }
} }

View File

@ -2,7 +2,7 @@
<custom-modal v-model="visible" :width="750" title="QC Result"> <custom-modal v-model="visible" :width="750" title="QC Result">
<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">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">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>
@ -57,7 +57,9 @@ export default {
this.columns = columns this.columns = columns
return { return {
list: [], list: [],
isLoading: false isLoading: false,
text: '',
fileName: ''
} }
}, },
methods: { methods: {
@ -124,6 +126,34 @@ export default {
beforeModalOpen() { beforeModalOpen() {
this.list = [] this.list = []
this.getData() this.getData()
},
SaveText() {
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 => {
let str = ""
str += `${item.qcFlags} `
str += `${item.evaluationMetrics} `
str += `${item.value} `
str += `${item.status} \n`
this.text+=str
})
let strData = new Blob([this.text], { type: 'text/plain;charset=utf-8' });
let _this = this
this.$confirm({
title: 'Please enter file name',
content: h => <a-input v-model={_this.fileName} />,
okText: 'Save',
cancelText: 'Cancle',
onOk() {
if (_this.fileName) {
_this.visible = false
saveAs(strData, `${_this.fileName}.txt`)
}
},
onCancel() {
console.log('Cancel');
},
});
} }
} }
} }

View File

@ -6,7 +6,7 @@
<div slot="custom-footer"> <div slot="custom-footer">
<a-space :size="20"> <a-space :size="20">
<a-button type="primary">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">Save Excel</a-button>
<a-button @click="visible = false">Cancel</a-button> <a-button @click="visible = false">Cancel</a-button>
</a-space> </a-space>
@ -17,6 +17,7 @@
<script> <script>
import { getAction } from '@/api/manage' import { getAction } from '@/api/manage'
import ModalMixin from '@/mixins/ModalMixin' import ModalMixin from '@/mixins/ModalMixin'
import { saveAs } from 'file-saver';
export default { export default {
mixins: [ModalMixin], mixins: [ModalMixin],
props: { props: {
@ -27,7 +28,8 @@ export default {
data() { data() {
return { return {
content: '', content: '',
isLoading: true isLoading: true,
fileName: ''
} }
}, },
methods: { methods: {
@ -55,6 +57,26 @@ export default {
if (this.sampleId) { if (this.sampleId) {
this.getContent() this.getContent()
} }
},
saveText() {
let strData = new Blob([this.content], { type: 'text/plain;charset=utf-8' });
// saveAs(strData, `Beta-View Sample Infomation.txt`)
let _this = this
this.$confirm({
title: 'Please enter file name',
content: h => <a-input v-model={_this.fileName} />,
okText: 'Save',
cancelText: 'Cancle',
onOk() {
if (_this.fileName) {
_this.visible = false
saveAs(strData, `${_this.fileName}.txt`)
}
},
onCancel() {
console.log('Cancel');
},
});
} }
} }
} }

View File

@ -1,7 +1,7 @@
<template> <template>
<custom-modal v-model="visible" :width="1000" title="View Spectrum" :footer="null" destroyOnClose> <custom-modal v-model="visible" :width="1000" title="View Spectrum" destroyOnClose>
<a-spin :spinning="isLoading"> <a-spin :spinning="isLoading">
<a-tabs :animated="false"> <a-tabs :animated="false" @change="handleTabChange">
<a-tab-pane tab="Sample Spectrum" :key="1"> <a-tab-pane tab="Sample Spectrum" :key="1">
<pre>{{ content.sample.join('\n') }}</pre> <pre>{{ content.sample.join('\n') }}</pre>
</a-tab-pane> </a-tab-pane>
@ -16,6 +16,12 @@
</a-tab-pane> </a-tab-pane>
</a-tabs> </a-tabs>
</a-spin> </a-spin>
<div slot="custom-footer">
<a-space :size="20">
<a-button type="primary" @click="handleOk">Save Text</a-button>
<a-button @click="visible = false">Cancel</a-button>
</a-space>
</div>
</custom-modal> </custom-modal>
</template> </template>
@ -37,7 +43,9 @@ export default {
qc: [], qc: [],
sample: [] sample: []
}, },
isLoading: true isLoading: true,
fileName: '',
currTab: 1
} }
}, },
methods: { methods: {
@ -63,6 +71,40 @@ export default {
if (this.sampleId) { if (this.sampleId) {
this.getContent() this.getContent()
} }
},
handleTabChange(key) {
this.currTab = key
},
handleOk() {
let text = ""
if (this.currTab==1) {
text=this.content.sample.join('\n')
} else if (this.currTab == 2) {
text=this.content.gasBg.join('\n')
}else if (this.currTab == 3) {
text=this.content.detBg.join('\n')
}else if (this.currTab == 4) {
text=this.content.qc.join('\n')
}
console.log(text);
let strData = new Blob([text], { type: 'text/plain;charset=utf-8' });
// saveAs(strData, `GammaViewer Log.txt`)
let _this = this
this.$confirm({
title: 'Please enter file name',
content: h => <a-input v-model={_this.fileName} />,
okText: 'Save',
cancelText: 'Cancle',
onOk() {
if (_this.fileName) {
// _this.visible = false
saveAs(strData, `${_this.fileName}.txt`)
}
},
onCancel() {
console.log('Cancel');
},
});
} }
} }
} }

View File

@ -27,6 +27,7 @@ export default {
return { return {
text: "", text: "",
isLoading: false, isLoading: false,
fileName: ''
} }
}, },
methods: { methods: {
@ -50,7 +51,23 @@ export default {
}, },
handleOk() { handleOk() {
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`)
let _this = this
this.$confirm({
title: 'Please enter file name',
content: h => <a-input v-model={_this.fileName} />,
okText: 'Save',
cancelText: 'Cancle',
onOk() {
if (_this.fileName) {
_this.visible = false
saveAs(strData, `${_this.fileName}.txt`)
}
},
onCancel() {
console.log('Cancel');
},
});
} }
}, },
} }

View File

@ -897,7 +897,7 @@ export default {
type: 'a-menu-item', type: 'a-menu-item',
title: 'Automatic Analysis Log', title: 'Automatic Analysis Log',
handler: () => { handler: () => {
this.autoAnalysisMogModalType = 1 this.autoAnalysisMogModalType = this.isGamma?1:this.isBetaGamma?2:1
this.autoAnalysisMogModalVisible = true this.autoAnalysisMogModalVisible = true
} }
}, },