add Export2Zip vendor

This commit is contained in:
spiritree 2017-09-25 16:43:56 +08:00 committed by 花裤衩
parent fcf7c0ba50
commit 3cf048e80b
2 changed files with 24 additions and 1 deletions

View file

@ -35,7 +35,8 @@
"vue-splitpane": "^1.0.0", "vue-splitpane": "^1.0.0",
"vuedraggable": "2.14.1", "vuedraggable": "2.14.1",
"vuex": "2.3.1", "vuex": "2.3.1",
"xlsx": "^0.10.8" "xlsx": "^0.10.8",
"jszip": "^3.1.4"
}, },
"devDependencies": { "devDependencies": {
"autoprefixer": "7.1.1", "autoprefixer": "7.1.1",

22
src/vendor/Export2Zip.js vendored Normal file
View file

@ -0,0 +1,22 @@
/* 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('导出失败')
})
}