Browse Source

nvr 信息导出

release_0.0.2
yuan_yi 2 years ago
parent
commit
44606dfd4c
  1. 1
      .gitignore
  2. 23
      code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js
  3. 6
      code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js
  4. 3
      code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js
  5. 17
      code/VideoAccess-VCMP/api/app/lib/utils/xlsxDownload.js

1
.gitignore

@ -138,3 +138,4 @@ dist
*yarn.lock
*package-lock.json
*log/
*downloadFiles/

23
code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js

@ -238,6 +238,28 @@ async function del (ctx) {
}
}
async function cameraExport(ctx){
try {
const { models } = ctx.fs.dc
const { userId, token } = ctx.fs.api
const { utils: { simpleExcelDown } } = ctx.app.fs
// const filePath = await simpleExcelDown({ data: exportData, header, fileName: `NVR信息列表_${userId}_${moment().format('YYYYMMDDHHmmss')}` })
// const fileData = fs.readFileSync(filePath);
// let fileName = filePath.split('/').pop()
// ctx.status = 200;
// ctx.set('Content-Type', 'application/x-xls');
// ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName));
// ctx.body = fileData;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
}
}
async function getAbility (ctx) {
try {
const { models } = ctx.fs.dc;
@ -275,6 +297,7 @@ module.exports = {
detail,
banned,
del,
cameraExport,
getAbility,
getKind,
};

6
code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js

@ -332,9 +332,9 @@ async function nvrExport (ctx) {
}
}
}
n.projectName = [...projectName].join('')
n.pcode = [...pcode].join(',')
n.structure = [...structure].join('')
n.projectName = [...projectName].join('\r\n')
n.pcode = [...pcode].join('\r\n')
n.structure = [...structure].join('\r\n')
exportData.push(n)
}

3
code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js

@ -29,6 +29,9 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['DEL/camera'] = { content: '删除摄像头', visible: false };
router.delete('/camera', camera.del);
app.fs.api.logAttr['GET/camera/export'] = { content: '导出摄像头信息', visible: false };
router.get('/camera/export', camera.cameraExport);
app.fs.api.logAttr['GET/camera/ability'] = { content: '获取摄像头能力列表', visible: false };
router.get('/camera/ability', camera.getAbility);

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

@ -6,8 +6,22 @@ const moment = require('moment')
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') } = {}) {
const fileDirPath = path.join(__dirname, `../../downloadFiles`)
makeDir(fileDirPath)
const file = new xlsx.File();
const sheet_1 = file.addSheet('sheet_1');
@ -62,6 +76,7 @@ module.exports = function (app, opts) {
}
return {
simpleExcelDown
simpleExcelDown,
makeDir
}
}
Loading…
Cancel
Save