|
@ -8,7 +8,7 @@ const moment = require('moment') |
|
|
module.exports = function (app, opts) { |
|
|
module.exports = function (app, opts) { |
|
|
|
|
|
|
|
|
//递归创建目录 同步方法
|
|
|
//递归创建目录 同步方法
|
|
|
async function makeDir (dir) { |
|
|
async function makeDir(dir) { |
|
|
if (!fs.existsSync(dir)) { |
|
|
if (!fs.existsSync(dir)) { |
|
|
makeDir(path.dirname(dir)) |
|
|
makeDir(path.dirname(dir)) |
|
|
fs.mkdirSync(dir, function (err) { |
|
|
fs.mkdirSync(dir, function (err) { |
|
@ -19,7 +19,7 @@ module.exports = function (app, opts) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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) |
|
|
makeDir(fileDirPath) |
|
|
const file = new xlsx.File(); |
|
|
const file = new xlsx.File(); |
|
@ -59,7 +59,7 @@ module.exports = function (app, opts) { |
|
|
indexCell.style = headerStyle |
|
|
indexCell.style = headerStyle |
|
|
for (let h of header) { |
|
|
for (let h of header) { |
|
|
const cell = row.addCell(); |
|
|
const cell = row.addCell(); |
|
|
cell.value = data[i][h.key] || h.defaultValue || ''; |
|
|
cell.value = data[i][h.key] || h.defaultValue || '-'; |
|
|
cell.style = style |
|
|
cell.style = style |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|