From 44606dfd4c345a1910f06524b8ac37614613e8c0 Mon Sep 17 00:00:00 2001 From: yuan_yi <1650192445@qq.com> Date: Tue, 31 May 2022 09:41:25 +0800 Subject: [PATCH] =?UTF-8?q?nvr=20=E4=BF=A1=E6=81=AF=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- .../api/app/lib/controllers/camera/index.js | 23 +++++++++++++++++++ .../api/app/lib/controllers/nvr/index.js | 6 ++--- .../api/app/lib/routes/camera/index.js | 3 +++ .../api/app/lib/utils/xlsxDownload.js | 17 +++++++++++++- 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 455637e..08281f6 100644 --- a/.gitignore +++ b/.gitignore @@ -137,4 +137,5 @@ dist *yarn.lock *package-lock.json -*log/ \ No newline at end of file +*log/ +*downloadFiles/ \ No newline at end of file diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js index 04cb2cd..f5e967a 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js +++ b/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, }; \ No newline at end of file diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js b/code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js index ed1a050..cbe4cda 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js +++ b/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) } diff --git a/code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js b/code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js index 9157725..a57b9aa 100644 --- a/code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js +++ b/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); diff --git a/code/VideoAccess-VCMP/api/app/lib/utils/xlsxDownload.js b/code/VideoAccess-VCMP/api/app/lib/utils/xlsxDownload.js index 786e83e..614a669 100644 --- a/code/VideoAccess-VCMP/api/app/lib/utils/xlsxDownload.js +++ b/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 } } \ No newline at end of file