fe-drone-ci/src/vendor/Export2Zip.js

23 lines
613 B
JavaScript
Raw Normal View History

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()
const txt_name = txtName || '文本'
const zip_name = zipName || '压缩包'
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)
zip.generateAsync({type:"blob"}).then(function (blob) {
saveAs(blob, `${zip_name}.zip`)
}, function (err) {
alert('导出失败')
})
}