web 模块 页面详情种的zip下载功能对接

This commit is contained in:
任珮宇 2023-11-14 18:16:11 +08:00
parent 0423207abf
commit e8ffe4b686

View File

@ -270,9 +270,10 @@
<script>
import { saveAs } from 'file-saver'
import JSZip from 'jszip'
import { getAction } from '../../api/manage'
import { getAction, getFileAction } from '../../api/manage'
const colorList = ['#0D5fff', '#287D3C', '#DF1512', '#F3BF24', '#D3D4DE', '#000000']
import * as echarts from 'echarts'
import { fetchAndDownload } from '@/utils/file'
export default {
props: {
allData: {
@ -628,27 +629,15 @@ export default {
this.$message.warning('This operation fails. Contact your system administrator')
}
},
downloadZip() {
let fileName = this.currName.replace('.PHD', '')
console.log('fileName', fileName)
getAction('/webStatistics/radionuclideFile', {
sampleId: this.sampleId,
}).then(async (res) => {
if (res.code && res.code == 500) {
this.$message.warning('This operation fails. Contact your system administrator')
} else {
const arrayBufferView = new Uint8Array(res)
const zip = new JSZip()
const blob = new Blob([res], { type: 'text/plain' })
// saveAs(blob, 'files.txt');
// ZIP
zip.file(`${fileName}.txt`, blob, { binary: true })
// ZIP
const zipContent = await zip.generateAsync({ type: 'blob' })
// ZIP
saveAs(zipContent, fileName)
}
})
async downloadZip() {
let url = '/webStatistics/downloadFile'
// let params = { sampleId: this.sampleId }
let params = { sampleId: 7480344 }
try {
await fetchAndDownload(url, params, 'get')
} catch (error) {
console.error(error)
}
},
viewFile() {
if (this.fileSrc) {