From 2c64beb088a7364bfdc0096bb0b8728842b0251b Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Wed, 15 Jun 2022 15:00:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=B3=E8=BD=AC=20100%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/app/lib/controllers/camera/create.js | 21 ++- .../api/app/lib/controllers/camera/index.js | 28 ++-- .../api/app/lib/controllers/nvr/index.js | 17 ++ .../web/client/src/layout/actions/global.js | 59 +++---- .../src/layout/components/sider/index.jsx | 49 +++++- .../src/layout/containers/layout/index.jsx | 4 +- .../web/client/src/layout/index.jsx | 10 +- .../client/src/sections/auth/actions/auth.js | 6 +- .../src/sections/auth/containers/login.jsx | 7 +- .../web/client/src/utils/index.js | 3 +- .../web/client/src/utils/webapi.js | 51 +++--- code/VideoAccess-VCMP/web/config.js | 145 +++++++++-------- code/VideoAccess-VCMP/web/package.json | 2 +- .../web/routes/attachment/index.js | 151 +++++++++--------- 14 files changed, 319 insertions(+), 234 deletions(-) diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js index 5cee93c..bbaf1be 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js @@ -350,10 +350,11 @@ async function getCascadeSipList (ctx) { const { models } = ctx.fs.dc const sipListRes = await models.GbCamera.findAll({ - attributes: ['id', 'streamid'], + attributes: ['id', 'sipip'], where: { level: 0, ipctype: '级联', + sipip: { $ne: null } } }) ctx.status = 200; @@ -383,7 +384,9 @@ async function verifyCascadeCamera (ctx) { async function createCascadeCamera (ctx) { let errMsg = '添加级联摄像头信息失败' + const transaction = await ctx.fs.dc.orm.transaction(); try { + const { models } = ctx.fs.dc const { userId, token } = ctx.fs.api const { sip, externalDomain, cascadeType } = ctx.request.body const { utils: { getGbCameraLevel3ByStreamId, verifyCascadeInfo } } = ctx.app.fs @@ -396,7 +399,8 @@ async function createCascadeCamera (ctx) { await models.Camera.findAll({ where: { type: 'cascade', - serialNo: { $in: allCameraIds } + serialNo: { $in: allCameraIds }, + delete: false } }) : [] let addData = [] @@ -410,13 +414,19 @@ async function createCascadeCamera (ctx) { } const added = addedCmeraRes.some(ac => ac.streamid == c.streamid) if (added) { - updateData.push({ + let data = { ...storageData, id: added.id, + } + updateData.push(data) + await models.Camera.update(data, { + where: { id: added.id }, + transaction }) } else { addData.push({ ...storageData, + type: 'cascade', serialNo: c.streamid, createTime: moment().format(), createUserId: userId, @@ -424,8 +434,13 @@ async function createCascadeCamera (ctx) { }) } } + await models.Camera.bulkCreate(addData, { + transaction + }) + await transaction.commit(); ctx.status = 204; } catch (error) { + await transaction.rollback(); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { 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 631f72d..7a65903 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js @@ -5,7 +5,7 @@ const moment = require('moment') async function getCameraProject (ctx, next) { try { const models = ctx.fs.dc.models; - const { limit, page, orderBy, orderDirection, keyword, abilityId, type, venderId, nvrId } = ctx.query + const { limit, page, orderBy, orderDirection, keyword, abilityId, type, venderId, nvrId, externalDomain } = ctx.query const { userId, token } = ctx.fs.api let findOption = { @@ -36,11 +36,14 @@ async function getCameraProject (ctx, next) { findOption.offset = page * limit } if (keyword) { - findOption.where.$or = [{ - name: { $like: `%${keyword}%` } - }, { - serialNo: { $like: `%${keyword}%` } - }] + findOption.where.$or = [ + { + name: { $like: `%${keyword}%` } + }, + // { + // serialNo: { $like: `%${keyword}%` } + // } + ] } if (type) { findOption.where.type = type @@ -53,6 +56,9 @@ async function getCameraProject (ctx, next) { abilityId: abilityId } } + if (externalDomain) { + findOption.where.externalDomain = externalDomain + } findOption.include.push(abilityFind) const cameraRes = await models.Camera.findAll(findOption) @@ -80,12 +86,10 @@ async function getCameraProject (ctx, next) { : [] for (let { dataValues: camera } of cameraRes) { - const corBindCamera = axbindCameraRes.find(b => b.cameraId == camera.id) - if (corBindCamera) { - camera.station = corBindCamera.stations - } else { - camera.station = [] - } + const corBindCamera = axbindCameraRes.filter(b => b.cameraId == camera.id) + camera.station = corBindCamera.reduce((station, c) => { + return station.concat.apply(station, c.stations) + }, []) const corUser = corUsers.find(u => u.id == camera.createUserId) camera.createUser = { 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 6456875..db1f525 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js @@ -132,7 +132,24 @@ async function get (ctx) { findOption.where.venderId = venderId } if (state) { + const onLineMap = { + ON: ['ON', 'ONLINE'], + OFF: ['OFF'], + // UNKONW: [], + DISABLED: [] + } + + let unknowState = [] + for (let k in onLineMap) { + unknowState = unknowState.concat(onLineMap[k]) + } + gbNvrOption.where = { + online: state == 'UNKONW' ? + { $notIn: unknowState } + : { $in: onLineMap[state] } + } + gbNvrOption.required = true } findOption.include.push(gbNvrOption) diff --git a/code/VideoAccess-VCMP/web/client/src/layout/actions/global.js b/code/VideoAccess-VCMP/web/client/src/layout/actions/global.js index 0548a95..e9d0305 100644 --- a/code/VideoAccess-VCMP/web/client/src/layout/actions/global.js +++ b/code/VideoAccess-VCMP/web/client/src/layout/actions/global.js @@ -4,41 +4,42 @@ import { RouteTable } from '$utils' export const INIT_LAYOUT = 'INIT_LAYOUT'; export function initLayout (title, copyright, sections, actions) { - return { - type: INIT_LAYOUT, - payload: { - title, - copyright, - sections, - actions - } - }; + return { + type: INIT_LAYOUT, + payload: { + title, + copyright, + sections, + actions + } + }; } export const RESIZE = 'RESIZE'; export function resize (clientHeight, clientWidth) { - const headerHeight = 60 - const footerHeight = 0 - return { - type: RESIZE, - payload: { - clientHeight: clientHeight - headerHeight - footerHeight, - clientWidth: clientWidth - } - } + const headerHeight = 60 + const footerHeight = 0 + return { + type: RESIZE, + payload: { + clientHeight: clientHeight - headerHeight - footerHeight, + clientWidth: clientWidth + } + } } export const INIT_API_ROOT = 'INIT_API_ROOT'; export function initApiRoot () { - return dispatch => { - RouteRequest.get(RouteTable.apiRoot).then(res => { - localStorage.setItem('apiRoot', res.root); - dispatch({ - type: INIT_API_ROOT, - payload: { - apiRoot: res.root - } - }) - }); - } + return dispatch => { + return RouteRequest.get(RouteTable.apiRoot).then(res => { + localStorage.setItem('apiRoot', JSON.stringify(res)); + return dispatch({ + type: INIT_API_ROOT, + payload: { + apiRoot: res.root, + iotAuthWeb: res.iotAuthWeb + } + }) + }); + } } \ No newline at end of file diff --git a/code/VideoAccess-VCMP/web/client/src/layout/components/sider/index.jsx b/code/VideoAccess-VCMP/web/client/src/layout/components/sider/index.jsx index 3424b40..41adbfd 100644 --- a/code/VideoAccess-VCMP/web/client/src/layout/components/sider/index.jsx +++ b/code/VideoAccess-VCMP/web/client/src/layout/components/sider/index.jsx @@ -6,7 +6,7 @@ import { push } from 'react-router-redux'; let scrollbar = null const Sider = props => { - const { collapsed, clientHeight, dispatch } = props + const { collapsed, clientHeight, dispatch, pathname } = props const [items, setItems] = useState([]) const [selectedKeys, setSelectedKeys] = useState([]) const [openKeys, setOpenKeys] = useState([]) @@ -14,6 +14,27 @@ const Sider = props => { useEffect(() => { const { sections, dispatch, user } = props; let nextItems = [] + const initKeys = (items, lastKeys) => { + for (let it of items) { + if (it.to && it.to == pathname) { + lastKeys.selectedKeys.push(it.itemKey) + return lastKeys + } else if (it.items && it.items.length) { + const preLastKeys = JSON.parse(JSON.stringify(lastKeys)) + preLastKeys.openKeys.push(it.itemKey) + const nextKeys = initKeys(it.items, JSON.parse(JSON.stringify(preLastKeys))) + if (nextKeys.selectedKeys.length > preLastKeys.selectedKeys.length || nextKeys.openKeys.length > preLastKeys.openKeys.length) { + return nextKeys + } + } + } + return lastKeys + return { + selectedKeys: [], + openKeys: [] + } + } + for (let c of sections) { if (typeof c.getNavItem == 'function') { let item = c.getNavItem(user, dispatch); @@ -24,13 +45,25 @@ const Sider = props => { } setItems(nextItems) - const lastSelectedKeys = localStorage.getItem('vcmp_selected_sider') - if (lastSelectedKeys) { - setSelectedKeys(JSON.parse(lastSelectedKeys)) - } - const lastOpenKeys = localStorage.getItem('vcmp_open_sider') - if (lastOpenKeys) { - setOpenKeys(JSON.parse(lastOpenKeys)) + const { selectedKeys, openKeys } = initKeys( + nextItems, + { + selectedKeys: [], + openKeys: [] + } + ) + if (selectedKeys.length || openKeys.length) { + setSelectedKeys(selectedKeys) + setOpenKeys(openKeys) + } else { + const lastSelectedKeys = localStorage.getItem('vcmp_selected_sider') + if (lastSelectedKeys) { + setSelectedKeys(JSON.parse(lastSelectedKeys)) + } + const lastOpenKeys = localStorage.getItem('vcmp_open_sider') + if (lastOpenKeys) { + setOpenKeys(JSON.parse(lastOpenKeys)) + } } scrollbar = new PerfectScrollbar('#page-slider', { suppressScrollX: true }); diff --git a/code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx b/code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx index 6d597fe..8f68235 100644 --- a/code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx +++ b/code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx @@ -90,9 +90,7 @@ const LayoutContainer = props => { }}>