Browse Source

导出通用接口 30%

release_0.0.2
yuan_yi 3 years ago
parent
commit
6dbcca3fa9
  1. 5
      code/VideoAccess-VCMP/api/app/lib/routes/nvr/index.js
  2. 2
      code/VideoAccess-VCMP/api/app/lib/utils/index.js
  3. 39
      code/VideoAccess-VCMP/api/app/lib/utils/xlsxDownload.js
  4. 1
      code/VideoAccess-VCMP/api/package.json

5
code/VideoAccess-VCMP/api/app/lib/routes/nvr/index.js

@ -12,6 +12,9 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/nvr/detail/:nvrId'] = { content: '获取nvr详情', visible: false };
router.get('/nvr/detail/:nvrId', nvr.detail);
app.fs.api.logAttr['DEL/nvr'] = { content: '删除nvr', visible: false };
app.fs.api.logAttr['DEL/nvr/:nvrId'] = { content: '删除nvr', visible: false };
router.del('/nvr/:nvrId', nvr.del);
app.fs.api.logAttr['GET/nvr/export'] = { content: '删除nvr', visible: false };
router.get('/nvr/export', nvr.nvrExport);
};

2
code/VideoAccess-VCMP/api/app/lib/utils/index.js

@ -5,7 +5,7 @@ const fs = require('fs');
module.exports = async function (app, opts) {
fs.readdirSync(__dirname).forEach((filename) => {
if (filename != 'index.js') {
if (!['index.js'].some(f => filename != f)) {
const utils = require(`./${filename}`)(app, opts)
app.fs.utils = {
...app.fs.utils,

39
code/VideoAccess-VCMP/api/app/lib/utils/xlsxDownload.js

@ -0,0 +1,39 @@
'use strict';
const xlsx = require('better-xlsx');
const path = require('path')
const moment = require('moment')
module.exports = function (app, opts) {
async function simpleExcelDown ({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss') } = {}) {
const fileDirPath = path.join(__dirname, `../../downloadFiles`)
const file = new xlsx.File();
const sheet_1 = file.addSheet('sheet_1');
// header
const headerRow = sheet.addRow();
for (let h of header) {
const cell = headerRow.addCell();
cell.value = h.title;
//设置文本在单元格内水平垂直居中
cell.style.align.h = 'center';
cell.style.align.v = 'center';
// border(cell, 0, 0, 1, 0)
}
const savePath = path.join(fileDirPath, fileName + '.xlsx')
await new Promise(function (resolve, reject) {
file.saveAs()
.pipe(fs.createWriteStream(savePath))
.on('finish', () => {
resolve()
});
})
return savePath
}
return {
simpleExcelDown
}
}

1
code/VideoAccess-VCMP/api/package.json

@ -15,6 +15,7 @@
"dependencies": {
"@fs/attachment": "^1.0.0",
"args": "^3.0.7",
"better-xlsx": "^0.7.6",
"crypto-js": "^4.0.0",
"file-saver": "^2.0.2",
"fs-web-server-scaffold": "^2.0.2",

Loading…
Cancel
Save