2017-09-25 08:43:56 +00:00
|
|
|
/* eslint-disable */
|
|
|
|
require('script-loader!file-saver');
|
|
|
|
import JSZip from 'jszip'
|
|
|
|
|
|
|
|
export function export_txt_to_zip(th, jsonData, txtName, zipName) {
|
|
|
|
const zip = new JSZip()
|
2017-11-02 09:58:35 +00:00
|
|
|
const txt_name = txtName || 'file'
|
|
|
|
const zip_name = zipName || 'file'
|
2017-09-25 08:43:56 +00:00
|
|
|
const data = jsonData
|
|
|
|
let txtData = `${th}\r\n`
|
|
|
|
data.forEach((row) => {
|
|
|
|
let tempStr = ''
|
|
|
|
tempStr = row.toString()
|
|
|
|
txtData += `${tempStr}\r\n`
|
|
|
|
})
|
|
|
|
zip.file(`${txt_name}.txt`, txtData)
|
2017-10-12 05:59:01 +00:00
|
|
|
zip.generateAsync({type:"blob"}).then((blob) => {
|
2017-09-25 08:43:56 +00:00
|
|
|
saveAs(blob, `${zip_name}.zip`)
|
2017-10-12 05:59:01 +00:00
|
|
|
}, (err) => {
|
2017-09-25 08:43:56 +00:00
|
|
|
alert('导出失败')
|
|
|
|
})
|
|
|
|
}
|