diff --git a/code/VideoAccess-VCMP/api/app/lib/routes/nvr/index.js b/code/VideoAccess-VCMP/api/app/lib/routes/nvr/index.js index 0ddef8f..eca607a 100644 --- a/code/VideoAccess-VCMP/api/app/lib/routes/nvr/index.js +++ b/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); }; diff --git a/code/VideoAccess-VCMP/api/app/lib/utils/index.js b/code/VideoAccess-VCMP/api/app/lib/utils/index.js index 93dd58d..c96bf7e 100644 --- a/code/VideoAccess-VCMP/api/app/lib/utils/index.js +++ b/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, diff --git a/code/VideoAccess-VCMP/api/app/lib/utils/xlsxDownload.js b/code/VideoAccess-VCMP/api/app/lib/utils/xlsxDownload.js new file mode 100644 index 0000000..71c10bf --- /dev/null +++ b/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 + } +} \ No newline at end of file diff --git a/code/VideoAccess-VCMP/api/package.json b/code/VideoAccess-VCMP/api/package.json index c4d0945..c71edec 100644 --- a/code/VideoAccess-VCMP/api/package.json +++ b/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", diff --git a/code/VideoAccess-VCMP/web/client/src/sections/equipmentWarehouse/containers/nvr.jsx b/code/VideoAccess-VCMP/web/client/src/sections/equipmentWarehouse/containers/nvr.jsx index 897d61e..98db120 100644 --- a/code/VideoAccess-VCMP/web/client/src/sections/equipmentWarehouse/containers/nvr.jsx +++ b/code/VideoAccess-VCMP/web/client/src/sections/equipmentWarehouse/containers/nvr.jsx @@ -2,14 +2,14 @@ import React, { useState, useEffect, useRef } from "react"; import { connect } from "react-redux"; import moment from "moment"; import { - Button, - Form, - Input, - Row, - Table, - Pagination, - Skeleton, - Popconfirm, + Button, + Form, + Input, + Row, + Table, + Pagination, + Skeleton, + Popconfirm, } from "@douyinfe/semi-ui"; import "../style.less"; import NvrModal from "../components/nvrModal"; @@ -17,336 +17,336 @@ import Setup from "../components/setup"; import SideSheets from "../components/sideSheet"; export const accessType = [ - { name: "萤石云平台摄像头", key: "yingshi" }, - { name: "NVR摄像头", key: "nvr" }, - { name: "IPC 网络摄像头", key: "ipc" }, - { name: "不明厂家", key: "cascade" }, + { name: "萤石云平台摄像头", key: "yingshi" }, + { name: "NVR摄像头", key: "nvr" }, + { name: "IPC 网络摄像头", key: "ipc" }, + { name: "不明厂家", key: "cascade" }, ]; const NvrHeader = (props) => { - const { dispatch, actions, user, loading, equipmentWarehouseNvr } = props; - const { equipmentWarehouse } = actions; - // const [loading, setLoading] = useState(false); - const [setup, setSetup] = useState(false); - const [sideSheet, setSideSheet] = useState(false); - const [setupp, setSetupp] = useState([]); - const [venderList, setvenderList] = useState([]); //厂商信息 - const [query, setQuery] = useState({ limit: 10, page: 0 }); //页码信息 - const [search, setearch] = useState({}); //搜索条件 - const [rowId, setRowId] = useState(); //表格数据id + const { dispatch, actions, user, loading, equipmentWarehouseNvr } = props; + const { equipmentWarehouse } = actions; + // const [loading, setLoading] = useState(false); + const [setup, setSetup] = useState(false); + const [sideSheet, setSideSheet] = useState(false); + const [setupp, setSetupp] = useState([]); + const [venderList, setvenderList] = useState([]); //厂商信息 + const [query, setQuery] = useState({ limit: 10, page: 0 }); //页码信息 + const [search, setearch] = useState({}); //搜索条件 + const [rowId, setRowId] = useState(); //表格数据id - const api = useRef(); - const SETUPS = "setups"; + const api = useRef(); + const SETUPS = "setups"; - useEffect(() => { - dispatch(actions.equipmentWarehouse.getVender()).then((res) => { - setvenderList(res.payload.data); - attribute(res.payload.data); - }); - //初始化表格显示设置 - localStorage.getItem(SETUPS) == null - ? localStorage.setItem( - SETUPS, - JSON.stringify(["manufactor", "passageway", "port", "state"]) - ) - : ""; - // ; - }, []); - useEffect(() => { - equipmentGetNvr(); - }, [query, search]); - - function equipmentGetNvr() { - dispatch(equipmentWarehouse.getNvr({ ...query, ...search })); - } - const columns = [ - { - title: "序号", - render: (text, record, index) => { - return index + 1; - }, - }, - { - title: "设备名称", - dataIndex: "name", - render: (text, r, index) => { - return ( -
- - {r.name} -
- ); - }, - }, - { - title: "SIP地址", - dataIndex: "owner", - }, - { - title: "操作", - width: "20%", - dataIndex: "", - render: (_, row) => { - return ( -
- - - { - dispatch(equipmentWarehouse.delNvr(row.id)).then(() => { - equipmentGetNvr(); - }); - }} - > - - -
- ); - }, - }, - ]; - - //获取表格属性设置 - function attribute(data) { - const arr = localStorage.getItem(SETUPS) - ? JSON.parse(localStorage.getItem(SETUPS)) - : []; + useEffect(() => { + dispatch(actions.equipmentWarehouse.getVender()).then((res) => { + setvenderList(res.payload.data); + attribute(res.payload.data); + }); + //初始化表格显示设置 + localStorage.getItem(SETUPS) == null + ? localStorage.setItem( + SETUPS, + JSON.stringify(["manufactor", "passageway", "port", "state"]) + ) + : ""; + // ; + }, []); + useEffect(() => { + equipmentGetNvr(); + }, [query, search]); - const column = [ - { - title: "设备厂家", - dataIndex: "venderId", - key: "manufactor", - render: (_, r, index) => { - let manufactorName = data.find((item) => item.id == r.venderId); - return manufactorName ? manufactorName.name : ""; - }, - }, - { - title: "添加账号", - dataIndex: "createUserId", - key: "accountNumber", - }, + function equipmentGetNvr () { + dispatch(equipmentWarehouse.getNvr({ ...query, ...search })); + } + const columns = [ { - title: "通道数", - dataIndex: "channelCount", - key: "passageway", + title: "序号", + render: (text, record, index) => { + return index + 1; + }, }, { - title: "端口", - dataIndex: "port", - key: "port", + title: "设备名称", + dataIndex: "name", + render: (text, r, index) => { + return ( +
+ + {r.name} +
+ ); + }, }, { - title: "设备状态", - dataIndex: "size", - key: "state", + title: "SIP地址", + dataIndex: "owner", }, { - title: "创建时间", - dataIndex: "createTime", - key: "time", - render: (_, r, index) => { - return moment(r.createTime).format("YYYY-MM-DD HH:MM:SS"); - }, + title: "操作", + width: "20%", + dataIndex: "", + render: (_, row) => { + return ( +
+ + + { + dispatch(equipmentWarehouse.delNvr(row.id)).then(() => { + equipmentGetNvr(); + }); + }} + > + + +
+ ); + }, }, - { - title: "项目名称", - dataIndex: "", - key: "name", - // render: (_, r, index) => { - // console.log(r); - // return r.station.length == 0 - // ? "" - // : r.station.map((item, index) => { - // return item.structure.projects.length == 0 - // ? "" - // : station( - // r.station[0].structure.projects[0].name, - // item.structure.projects, - // "name" - // ); - // }); - // }, - }, - { - title: "pcode", - dataIndex: "", - key: "pcode", - }, - { - title: "结构物", - dataIndex: "", - key: "structure", - }, - ]; - for (let i = 0; i < arr.length; i++) { - let colum = column.filter((item) => { - return item.key === arr[i]; - }); - columns.splice(i + 2, 0, colum[0]); - } - setSetupp(columns); - } + ]; - //条件赛选样式 - const screen = { - width: 193, - marginRight: 20, - marginBottom: 16, - color: "rgba(0, 0, 0, 0.65)", - }; + //获取表格属性设置 + function attribute (data) { + const arr = localStorage.getItem(SETUPS) + ? JSON.parse(localStorage.getItem(SETUPS)) + : []; - return ( - <> -
-