23120e5a84bd5a39c219967defb54d88ee54530f.svn-base 627 B

123456789101112131415161718192021222324
  1. /* eslint-disable */
  2. require('script-loader!file-saver');
  3. import JSZip from 'jszip'
  4. export function export_txt_to_zip(th, jsonData, txtName, zipName) {
  5. const zip = new JSZip()
  6. const txt_name = txtName || 'file'
  7. const zip_name = zipName || 'file'
  8. const data = jsonData
  9. let txtData = `${th}\r\n`
  10. data.forEach((row) => {
  11. let tempStr = ''
  12. tempStr = row.toString()
  13. txtData += `${tempStr}\r\n`
  14. })
  15. zip.file(`${txt_name}.txt`, txtData)
  16. zip.generateAsync({
  17. type: "blob"
  18. }).then((blob) => {
  19. saveAs(blob, `${zip_name}.zip`)
  20. }, (err) => {
  21. alert('导出失败')
  22. })
  23. }