|
@ -6,8 +6,22 @@ const moment = require('moment') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function (app, opts) { |
|
|
module.exports = function (app, opts) { |
|
|
|
|
|
|
|
|
|
|
|
//递归创建目录 同步方法
|
|
|
|
|
|
async function makeDir (dir) { |
|
|
|
|
|
if (!fs.existsSync(dir)) { |
|
|
|
|
|
this.makeDir(path.dirname(dir)) |
|
|
|
|
|
fs.mkdirSync(dir, function (err) { |
|
|
|
|
|
if (err) { |
|
|
|
|
|
throw err |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
async function simpleExcelDown ({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss') } = {}) { |
|
|
async function simpleExcelDown ({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss') } = {}) { |
|
|
const fileDirPath = path.join(__dirname, `../../downloadFiles`) |
|
|
const fileDirPath = path.join(__dirname, `../../downloadFiles`) |
|
|
|
|
|
makeDir(fileDirPath) |
|
|
const file = new xlsx.File(); |
|
|
const file = new xlsx.File(); |
|
|
const sheet_1 = file.addSheet('sheet_1'); |
|
|
const sheet_1 = file.addSheet('sheet_1'); |
|
|
|
|
|
|
|
@ -62,6 +76,7 @@ module.exports = function (app, opts) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
simpleExcelDown |
|
|
simpleExcelDown, |
|
|
|
|
|
makeDir |
|
|
} |
|
|
} |
|
|
} |
|
|
} |