Browse Source

跳转 100%

release_0.0.2
巴林闲侠 3 years ago
parent
commit
2c64beb088
  1. 21
      code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js
  2. 26
      code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js
  3. 17
      code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js
  4. 9
      code/VideoAccess-VCMP/web/client/src/layout/actions/global.js
  5. 35
      code/VideoAccess-VCMP/web/client/src/layout/components/sider/index.jsx
  6. 4
      code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx
  7. 6
      code/VideoAccess-VCMP/web/client/src/layout/index.jsx
  8. 6
      code/VideoAccess-VCMP/web/client/src/sections/auth/actions/auth.js
  9. 7
      code/VideoAccess-VCMP/web/client/src/sections/auth/containers/login.jsx
  10. 3
      code/VideoAccess-VCMP/web/client/src/utils/index.js
  11. 1
      code/VideoAccess-VCMP/web/client/src/utils/webapi.js
  12. 13
      code/VideoAccess-VCMP/web/config.js
  13. 2
      code/VideoAccess-VCMP/web/package.json
  14. 7
      code/VideoAccess-VCMP/web/routes/attachment/index.js

21
code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js

@ -350,10 +350,11 @@ async function getCascadeSipList (ctx) {
const { models } = ctx.fs.dc const { models } = ctx.fs.dc
const sipListRes = await models.GbCamera.findAll({ const sipListRes = await models.GbCamera.findAll({
attributes: ['id', 'streamid'], attributes: ['id', 'sipip'],
where: { where: {
level: 0, level: 0,
ipctype: '级联', ipctype: '级联',
sipip: { $ne: null }
} }
}) })
ctx.status = 200; ctx.status = 200;
@ -383,7 +384,9 @@ async function verifyCascadeCamera (ctx) {
async function createCascadeCamera (ctx) { async function createCascadeCamera (ctx) {
let errMsg = '添加级联摄像头信息失败' let errMsg = '添加级联摄像头信息失败'
const transaction = await ctx.fs.dc.orm.transaction();
try { try {
const { models } = ctx.fs.dc
const { userId, token } = ctx.fs.api const { userId, token } = ctx.fs.api
const { sip, externalDomain, cascadeType } = ctx.request.body const { sip, externalDomain, cascadeType } = ctx.request.body
const { utils: { getGbCameraLevel3ByStreamId, verifyCascadeInfo } } = ctx.app.fs const { utils: { getGbCameraLevel3ByStreamId, verifyCascadeInfo } } = ctx.app.fs
@ -396,7 +399,8 @@ async function createCascadeCamera (ctx) {
await models.Camera.findAll({ await models.Camera.findAll({
where: { where: {
type: 'cascade', type: 'cascade',
serialNo: { $in: allCameraIds } serialNo: { $in: allCameraIds },
delete: false
} }
}) : [] }) : []
let addData = [] let addData = []
@ -410,13 +414,19 @@ async function createCascadeCamera (ctx) {
} }
const added = addedCmeraRes.some(ac => ac.streamid == c.streamid) const added = addedCmeraRes.some(ac => ac.streamid == c.streamid)
if (added) { if (added) {
updateData.push({ let data = {
...storageData, ...storageData,
id: added.id, id: added.id,
}
updateData.push(data)
await models.Camera.update(data, {
where: { id: added.id },
transaction
}) })
} else { } else {
addData.push({ addData.push({
...storageData, ...storageData,
type: 'cascade',
serialNo: c.streamid, serialNo: c.streamid,
createTime: moment().format(), createTime: moment().format(),
createUserId: userId, createUserId: userId,
@ -424,8 +434,13 @@ async function createCascadeCamera (ctx) {
}) })
} }
} }
await models.Camera.bulkCreate(addData, {
transaction
})
await transaction.commit();
ctx.status = 204; ctx.status = 204;
} catch (error) { } catch (error) {
await transaction.rollback();
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {

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

@ -5,7 +5,7 @@ const moment = require('moment')
async function getCameraProject (ctx, next) { async function getCameraProject (ctx, next) {
try { try {
const models = ctx.fs.dc.models; 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 const { userId, token } = ctx.fs.api
let findOption = { let findOption = {
@ -36,11 +36,14 @@ async function getCameraProject (ctx, next) {
findOption.offset = page * limit findOption.offset = page * limit
} }
if (keyword) { if (keyword) {
findOption.where.$or = [{ findOption.where.$or = [
{
name: { $like: `%${keyword}%` } name: { $like: `%${keyword}%` }
}, { },
serialNo: { $like: `%${keyword}%` } // {
}] // serialNo: { $like: `%${keyword}%` }
// }
]
} }
if (type) { if (type) {
findOption.where.type = type findOption.where.type = type
@ -53,6 +56,9 @@ async function getCameraProject (ctx, next) {
abilityId: abilityId abilityId: abilityId
} }
} }
if (externalDomain) {
findOption.where.externalDomain = externalDomain
}
findOption.include.push(abilityFind) findOption.include.push(abilityFind)
const cameraRes = await models.Camera.findAll(findOption) const cameraRes = await models.Camera.findAll(findOption)
@ -80,12 +86,10 @@ async function getCameraProject (ctx, next) {
: [] : []
for (let { dataValues: camera } of cameraRes) { for (let { dataValues: camera } of cameraRes) {
const corBindCamera = axbindCameraRes.find(b => b.cameraId == camera.id) const corBindCamera = axbindCameraRes.filter(b => b.cameraId == camera.id)
if (corBindCamera) { camera.station = corBindCamera.reduce((station, c) => {
camera.station = corBindCamera.stations return station.concat.apply(station, c.stations)
} else { }, [])
camera.station = []
}
const corUser = corUsers.find(u => u.id == camera.createUserId) const corUser = corUsers.find(u => u.id == camera.createUserId)
camera.createUser = { camera.createUser = {

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

@ -132,7 +132,24 @@ async function get (ctx) {
findOption.where.venderId = venderId findOption.where.venderId = venderId
} }
if (state) { 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) findOption.include.push(gbNvrOption)

9
code/VideoAccess-VCMP/web/client/src/layout/actions/global.js

@ -31,12 +31,13 @@ export function resize (clientHeight, clientWidth) {
export const INIT_API_ROOT = 'INIT_API_ROOT'; export const INIT_API_ROOT = 'INIT_API_ROOT';
export function initApiRoot () { export function initApiRoot () {
return dispatch => { return dispatch => {
RouteRequest.get(RouteTable.apiRoot).then(res => { return RouteRequest.get(RouteTable.apiRoot).then(res => {
localStorage.setItem('apiRoot', res.root); localStorage.setItem('apiRoot', JSON.stringify(res));
dispatch({ return dispatch({
type: INIT_API_ROOT, type: INIT_API_ROOT,
payload: { payload: {
apiRoot: res.root apiRoot: res.root,
iotAuthWeb: res.iotAuthWeb
} }
}) })
}); });

35
code/VideoAccess-VCMP/web/client/src/layout/components/sider/index.jsx

@ -6,7 +6,7 @@ import { push } from 'react-router-redux';
let scrollbar = null let scrollbar = null
const Sider = props => { const Sider = props => {
const { collapsed, clientHeight, dispatch } = props const { collapsed, clientHeight, dispatch, pathname } = props
const [items, setItems] = useState([]) const [items, setItems] = useState([])
const [selectedKeys, setSelectedKeys] = useState([]) const [selectedKeys, setSelectedKeys] = useState([])
const [openKeys, setOpenKeys] = useState([]) const [openKeys, setOpenKeys] = useState([])
@ -14,6 +14,27 @@ const Sider = props => {
useEffect(() => { useEffect(() => {
const { sections, dispatch, user } = props; const { sections, dispatch, user } = props;
let nextItems = [] 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) { for (let c of sections) {
if (typeof c.getNavItem == 'function') { if (typeof c.getNavItem == 'function') {
let item = c.getNavItem(user, dispatch); let item = c.getNavItem(user, dispatch);
@ -24,6 +45,17 @@ const Sider = props => {
} }
setItems(nextItems) setItems(nextItems)
const { selectedKeys, openKeys } = initKeys(
nextItems,
{
selectedKeys: [],
openKeys: []
}
)
if (selectedKeys.length || openKeys.length) {
setSelectedKeys(selectedKeys)
setOpenKeys(openKeys)
} else {
const lastSelectedKeys = localStorage.getItem('vcmp_selected_sider') const lastSelectedKeys = localStorage.getItem('vcmp_selected_sider')
if (lastSelectedKeys) { if (lastSelectedKeys) {
setSelectedKeys(JSON.parse(lastSelectedKeys)) setSelectedKeys(JSON.parse(lastSelectedKeys))
@ -32,6 +64,7 @@ const Sider = props => {
if (lastOpenKeys) { if (lastOpenKeys) {
setOpenKeys(JSON.parse(lastOpenKeys)) setOpenKeys(JSON.parse(lastOpenKeys))
} }
}
scrollbar = new PerfectScrollbar('#page-slider', { suppressScrollX: true }); scrollbar = new PerfectScrollbar('#page-slider', { suppressScrollX: true });
}, []) }, [])

4
code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx

@ -90,9 +90,7 @@ const LayoutContainer = props => {
}}> }}>
<video <video
autoPlay loop muted autoPlay loop muted
style={{ style={{}}
// width: "100%", objectFit: "cover", objectPosition: 'left top', height: 'calc(100vh - 4px)'
}}
src="/assets/video/cross_loading.mp4" src="/assets/video/cross_loading.mp4"
type="video/mp4" type="video/mp4"
/> />

6
code/VideoAccess-VCMP/web/client/src/layout/index.jsx

@ -83,7 +83,7 @@ const Root = props => {
} }
} }
useEffect(() => { useEffect(async () => {
let innerRoutes = [] let innerRoutes = []
let outerRoutes = [] let outerRoutes = []
let reducers = {} let reducers = {}
@ -126,8 +126,8 @@ const Root = props => {
store.dispatch(resize(document.body.clientHeight, document.body.clientWidth)); store.dispatch(resize(document.body.clientHeight, document.body.clientWidth));
store.dispatch(actions.auth.initAuth()); store.dispatch(actions.auth.initAuth());
store.dispatch(initWebSocket({})) store.dispatch(initWebSocket({}))
store.dispatch(initApiRoot()) const resourceRoot = await store.dispatch(initApiRoot())
console.log(resourceRoot);
const combineRoutes = flatRoutes(innerRoutes); const combineRoutes = flatRoutes(innerRoutes);
setInnerRoutes(combineRoutes) setInnerRoutes(combineRoutes)

6
code/VideoAccess-VCMP/web/client/src/sections/auth/actions/auth.js

@ -1,6 +1,6 @@
'use strict'; 'use strict';
import { ApiTable, AuthRequest } from '$utils' import { ApiTable, AxyRequest } from '$utils'
export const INIT_AUTH = 'INIT_AUTH'; export const INIT_AUTH = 'INIT_AUTH';
export function initAuth (userData) { export function initAuth (userData) {
@ -42,7 +42,7 @@ export function login (username, password) {
// }, // },
// }); // });
return AuthRequest.post(ApiTable.login, { username, password }) return AxyRequest.post(ApiTable.login, { username, password, domain: 'anxinyun' })
.then(user => { .then(user => {
sessionStorage.setItem('user', JSON.stringify(user)); sessionStorage.setItem('user', JSON.stringify(user));
return dispatch({ return dispatch({
@ -64,7 +64,7 @@ export function login (username, password) {
export const LOGOUT = 'LOGOUT'; export const LOGOUT = 'LOGOUT';
export function logout () { export function logout () {
const user = JSON.parse(sessionStorage.getItem('user')) const user = JSON.parse(sessionStorage.getItem('user'))
AuthRequest.put(ApiTable.logout, { AxyRequest.put(ApiTable.logout, {
token: user.token token: user.token
}); });
sessionStorage.removeItem('user'); sessionStorage.removeItem('user');

7
code/VideoAccess-VCMP/web/client/src/sections/auth/containers/login.jsx

@ -48,9 +48,10 @@ const Login = props => {
width: 446, width: 446,
height: 348, height: 348,
padding: '45px 60px', padding: '45px 60px',
backgroundImage: "url('/assets/images/background/loginbg.png')", // backgroundImage: "url('/assets/images/background/loginbg.png')",
backgroundSize: '100% 100%', // backgroundSize: '100% 100%',
backgroundRepeat: 'no-repeat', // backgroundRepeat: 'no-repeat',
background: 'linear-gradient(rgba(255,255,255,1),rgba(255,255,255,.3))',
position: 'absolute', position: 'absolute',
top: '33.89%', top: '33.89%',
right: '16.43%', right: '16.43%',

3
code/VideoAccess-VCMP/web/client/src/utils/index.js

@ -1,7 +1,7 @@
'use strict'; 'use strict';
import { isAuthorized } from './func'; import { isAuthorized } from './func';
import { AuthorizationCode } from './authCode'; import { AuthorizationCode } from './authCode';
import { ApiTable, RouteTable, AuthRequest } from './webapi' import { ApiTable, RouteTable, AuthRequest, AxyRequest } from './webapi'
export { export {
isAuthorized, isAuthorized,
@ -11,4 +11,5 @@ export {
ApiTable, ApiTable,
RouteTable, RouteTable,
AuthRequest, AuthRequest,
AxyRequest,
} }

1
code/VideoAccess-VCMP/web/client/src/utils/webapi.js

@ -2,6 +2,7 @@
import { ProxyRequest } from "@peace/utils"; import { ProxyRequest } from "@peace/utils";
export const AuthRequest = new ProxyRequest("_auth"); export const AuthRequest = new ProxyRequest("_auth");
export const AxyRequest = new ProxyRequest("_axy");
export const ApiTable = { export const ApiTable = {
login: "login", login: "login",

13
code/VideoAccess-VCMP/web/config.js

@ -13,13 +13,17 @@ dev && console.log('\x1B[33m%s\x1b[0m', '请遵循并及时更新 readme.md,
args.option(['p', 'port'], '启动端口'); args.option(['p', 'port'], '启动端口');
args.option(['u', 'api-url'], 'webapi的URL'); args.option(['u', 'api-url'], 'webapi的URL');
args.option('apiAuthUrl', 'IOT 鉴权 api'); args.option('apiAuthUrl', 'IOT 鉴权 api');
args.option('apiAnxinyunUrl', '安心云 api');
args.option('iotAuthWeb', 'IOT 鉴权 web');
const flags = args.parse(process.argv); const flags = args.parse(process.argv);
const API_URL = process.env.API_URL || flags.apiUrl; const API_URL = process.env.API_URL || flags.apiUrl;
const API_AUTH_URL = process.env.API_AUTH_URL || flags.apiAuthUrl; const API_AUTH_URL = process.env.API_AUTH_URL || flags.apiAuthUrl;
const IOT_AUTH_WEB = process.env.IOT_AUTH_WEB || flags.iotAuthWeb;
const API_ANXINYUN_URL = process.env.API_ANXINYUN_URL || flags.apiAnxinyunUrl;
if (!API_URL) { if (!API_URL || !API_ANXINYUN_URL || !API_AUTH_URL) {
console.log('缺少启动参数,异常退出'); console.log('缺少启动参数,异常退出');
args.showHelp(); args.showHelp();
process.exit(-1); process.exit(-1);
@ -40,10 +44,17 @@ const product = {
host: API_AUTH_URL, host: API_AUTH_URL,
match: /^\/_auth\//, match: /^\/_auth\//,
} }
}, {
entry: require('./middlewares/proxy').entry,
opts: {
host: API_ANXINYUN_URL,
match: /^\/_axy\//,
}
}, { }, {
entry: require('./routes').entry, entry: require('./routes').entry,
opts: { opts: {
apiUrl: API_URL, apiUrl: API_URL,
iotAuthWeb: IOT_AUTH_WEB,
staticRoot: './client', staticRoot: './client',
} }
}, { }, {

2
code/VideoAccess-VCMP/web/package.json

@ -7,7 +7,7 @@
"test": "mocha", "test": "mocha",
"start-vite": "cross-env NODE_ENV=developmentVite npm run start-params", "start-vite": "cross-env NODE_ENV=developmentVite npm run start-params",
"start": "cross-env NODE_ENV=development npm run start-params", "start": "cross-env NODE_ENV=development npm run start-params",
"start-params": "node server -p 5000 -u http://10.8.30.7:4000 --apiAuthUrl http://10.8.30.7:4200", "start-params": "node server -p 5000 -u http://10.8.30.7:4000 --apiAuthUrl http://10.8.30.7:4200 --apiAnxinyunUrl http://10.8.30.7:4100 --iotAuthWeb http://10.8.30.7:5200",
"deploy": "export NODE_ENV=production&& npm run build && node server", "deploy": "export NODE_ENV=production&& npm run build && node server",
"build-dev": "cross-env NODE_ENV=development&&webpack --config webpack.config.js", "build-dev": "cross-env NODE_ENV=development&&webpack --config webpack.config.js",
"build": "export NODE_ENV=production&&webpack --config webpack.config.prod.js" "build": "export NODE_ENV=production&&webpack --config webpack.config.prod.js"

7
code/VideoAccess-VCMP/web/routes/attachment/index.js

@ -19,10 +19,13 @@ module.exports = {
entry: function (app, router, opts) { entry: function (app, router, opts) {
const getApiRoot = async function (ctx) { const getApiRoot = async function (ctx) {
const { apiUrl } = opts; const { apiUrl, iotAuthWeb } = opts;
ctx.status = 200; ctx.status = 200;
ctx.body = { root: apiUrl }; ctx.body = {
root: apiUrl,
iotAuthWeb
};
}; };
let upload = async function (ctx, next) { let upload = async function (ctx, next) {

Loading…
Cancel
Save