Browse Source

Merge branch 'dev_trial' of https://gitea.free-sun.vip/free-sun/FS-IOT into dev_trial

release_0.0.2
wenlele 3 years ago
parent
commit
8fd9b56cc7
  1. 1
      code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js
  2. 22
      code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js
  3. 18
      code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js
  4. 4
      code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js
  5. 7
      code/VideoAccess-VCMP/api/app/lib/service/paasRequest.js
  6. 4
      code/VideoAccess-VCMP/web/client/src/components/simpleFileDownButton.jsx
  7. 2
      code/VideoAccess-VCMP/web/client/src/layout/components/header/index.jsx
  8. 22
      code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx
  9. 23
      code/VideoAccess-VCMP/web/client/src/layout/index.jsx
  10. 13
      code/VideoAccess-VCMP/web/client/src/sections/auth/actions/auth.js
  11. 2
      code/VideoAccess-VCMP/web/client/src/sections/auth/containers/login.jsx
  12. 2
      code/VideoAccess-VCMP/web/client/src/sections/equipmentWarehouse/components/skeletonScreen.jsx
  13. 4
      code/VideoAccess-VCMP/web/webpack.config.js

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

@ -161,6 +161,7 @@ async function createNvrCamera (ctx) {
}) })
} else { } else {
createData.push({ createData.push({
type: 'nvr',
serialNo: c.streamid, serialNo: c.streamid,
name: c.name, name: c.name,
sip: corCamera.sipip, sip: corCamera.sipip,

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

@ -221,23 +221,35 @@ async function banned (ctx) {
} }
async function del (ctx) { async function del (ctx) {
const transaction = await ctx.fs.dc.orm.transaction();
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { cameraId } = ctx.query const { cameraId } = ctx.params
const { token } = ctx.fs.api const { token } = ctx.fs.api
await models.cameraId.destroy({ await models.CameraAbilityBind.destroy({
where: {
cameraId: cameraId
},
transaction
})
await models.Camera.destroy({
where: { where: {
id: cameraId id: cameraId
} },
transaction
}) })
if (cameraId.length) {
await ctx.app.fs.axyRequest.delete('vcmp/camera/project', { query: { token, cameraId: cameraId.join(',') } }) if (cameraId) {
await ctx.app.fs.axyRequest.delete('vcmp/camera/project', { query: { token, cameraId: cameraId } })
} }
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 = {}

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

@ -243,7 +243,20 @@ async function detail (ctx) {
} }
const corUser = await ctx.app.fs.authRequest.get(`user/${nvrRes.createUserId}/message`, { query: { token } }) const corUser = await ctx.app.fs.authRequest.get(`user/${nvrRes.createUserId}/message`, { query: { token } })
const serverDRes = (await ctx.app.fs.videoServerRequest.post(`gateway/plugins`) || '')
const serverDArr = JSON.parse(serverDRes.replace(/'/g, '"')) || []
const serverDConfig = serverDArr.find(s => s.Name == 'GB28181')
let serveD = {}
if (serverDConfig) {
const { Config } = serverDConfig
let ConfigArr = Config.split('\n')
for (let c of ConfigArr) {
let config = c.split(' = ')
if (config.length == 2) {
serveD[config[0].trim()] = config[1].trim().replace(/\"/g, '')
}
}
}
let nvrDetail = { let nvrDetail = {
...nvrRes.dataValues, ...nvrRes.dataValues,
station: bindStations, station: bindStations,
@ -251,7 +264,8 @@ async function detail (ctx) {
createUser: { createUser: {
namePresent: corUser[0].namePresent namePresent: corUser[0].namePresent
}, },
accessWay: 'GB/T28181' accessWay: 'GB/T28181',
accessInfo: serveD
} }
ctx.status = 200; ctx.status = 200;

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

@ -35,8 +35,8 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['PUT/camera/banned'] = { content: '禁用摄像头', visible: false }; app.fs.api.logAttr['PUT/camera/banned'] = { content: '禁用摄像头', visible: false };
router.put('/camera/banned', camera.banned); router.put('/camera/banned', camera.banned);
app.fs.api.logAttr['DEL/camera'] = { content: '删除摄像头', visible: false }; app.fs.api.logAttr['DEL/camera/:cameraId'] = { content: '删除摄像头', visible: false };
router.delete('/camera', camera.del); router.delete('/camera/:cameraId', camera.del);
app.fs.api.logAttr['GET/camera/export'] = { content: '导出摄像头信息', visible: false }; app.fs.api.logAttr['GET/camera/export'] = { content: '导出摄像头信息', visible: false };
router.get('/camera/export', camera.cameraExport); router.get('/camera/export', camera.cameraExport);

7
code/VideoAccess-VCMP/api/app/lib/service/paasRequest.js

@ -2,9 +2,10 @@
const request = require('superagent') const request = require('superagent')
class paasRequest { class paasRequest {
constructor(root, { query = {} } = {}) { constructor(root, { query = {} } = {}, option) {
this.root = root; this.root = root;
this.query = query this.query = query
this.option = option
} }
#buildUrl = (url) => { #buildUrl = (url) => {
@ -16,7 +17,7 @@ class paasRequest {
if (err) { if (err) {
reject(err); reject(err);
} else { } else {
resolve(res.body); resolve(res[this.option.dataWord]);
} }
}; };
} }
@ -51,7 +52,7 @@ function factory (app, opts) {
try { try {
for (let r of opts.pssaRequest) { for (let r of opts.pssaRequest) {
if (r.name && r.root) { if (r.name && r.root) {
app.fs[r.name] = new paasRequest(r.root, { ...(r.params || {}) }) app.fs[r.name] = new paasRequest(r.root, { ...(r.params || {}) }, { dataWord: r.dataWord || 'body' })
} else { } else {
throw 'opts.pssaRequest 参数错误!' throw 'opts.pssaRequest 参数错误!'
} }

4
code/VideoAccess-VCMP/web/client/src/components/simpleFileDownButton.jsx

@ -23,7 +23,9 @@ const SimpleFileDownButton = (props) => {
> >
导出 导出
</Button> </Button>
<iframe src={`/_api/${downloadUrl}`} style={{ display: 'none' }} /> {
downloadUrl ? <iframe src={`/_api/${downloadUrl}`} style={{ display: 'none' }} /> : ''
}
</> </>
) )
} }

2
code/VideoAccess-VCMP/web/client/src/layout/components/header/index.jsx

@ -13,6 +13,8 @@ const Header = (props) => {
onClick={({ itemKey }) => { onClick={({ itemKey }) => {
if (itemKey == "logout") { if (itemKey == "logout") {
dispatch(actions.auth.logout(user)); dispatch(actions.auth.logout(user));
const iotAuth = document.getElementById('iotAuth').contentWindow;
iotAuth.postMessage({ action: 'logout' }, '*');
if (socket) { if (socket) {
socket.disconnect(); socket.disconnect();
} }

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

@ -26,7 +26,7 @@ let scrollbar
const LayoutContainer = props => { const LayoutContainer = props => {
const { const {
dispatch, msg, user, copyright, children, sections, clientWidth, clientHeight, dispatch, msg, user, copyright, children, sections, clientWidth, clientHeight,
location, match, routes, history location, match, routes, history, authCrossLoading
} = props } = props
const [collapsed, setCollapsed] = useState(false) const [collapsed, setCollapsed] = useState(false)
@ -40,8 +40,6 @@ const LayoutContainer = props => {
} }
useEffect(() => { useEffect(() => {
scrollbar = new PerfectScrollbar('#page-content', { suppressScrollX: true });
window.addEventListener('resize', resize_); window.addEventListener('resize', resize_);
return () => { return () => {
window.removeEventListener('resize', resize_); window.removeEventListener('resize', resize_);
@ -50,7 +48,7 @@ const LayoutContainer = props => {
useEffect(() => { useEffect(() => {
NProgress.done(); NProgress.done();
if (!user || !user.authorized) { if ((!user || !user.authorized) && !authCrossLoading) {
history.push('/signin'); history.push('/signin');
} }
if (msg) { if (msg) {
@ -71,13 +69,27 @@ const LayoutContainer = props => {
} }
const dom = document.getElementById('page-content'); const dom = document.getElementById('page-content');
if (dom) { if (dom) {
if (!scrollbar) {
scrollbar = new PerfectScrollbar('#page-content', { suppressScrollX: true });
} else {
scrollbar.update(); scrollbar.update();
dom.scrollTop = 0; dom.scrollTop = 0;
} }
}
}) })
return ( return (
<Layout id="layout"> <Layout id="layout">
{
authCrossLoading ?
<div style={{
position: 'absolute', height: '100%', width: '100%',
display: 'flex', alignItems: 'center', placeContent: 'center',
}}>
载入中...
</div>
:
<>
<Layout.Header> <Layout.Header>
<Header <Header
user={user} user={user}
@ -123,6 +135,8 @@ const LayoutContainer = props => {
</div> </div>
</Layout.Content> </Layout.Content>
</Layout> </Layout>
</>
}
</Layout > </Layout >
) )
} }

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

@ -24,6 +24,7 @@ const Root = props => {
const [outerRoutes, setOuterRoutes] = useState([]) const [outerRoutes, setOuterRoutes] = useState([])
const [combineRoutes, setCombineRoutes] = useState([]) const [combineRoutes, setCombineRoutes] = useState([])
const [innnerRoutes, setInnerRoutes] = useState([]) const [innnerRoutes, setInnerRoutes] = useState([])
const [authCrossLoading, setAuthCrossLoading] = useState(true)
const flatRoutes = (routes) => { const flatRoutes = (routes) => {
const combineRoutes = []; const combineRoutes = [];
@ -148,9 +149,24 @@ const Root = props => {
component={route.component} component={route.component}
/> />
))) )))
window.addEventListener('message', async function (e) { // message
const { data } = e
if (data && data.action) {
if (data.action == 'initUser') {
await store.dispatch(actions.auth.initAuth(e.data))
} else if (data.action == 'logout') {
await store.dispatch(actions.auth.logout())
}
}
setAuthCrossLoading(false)
});
}, []) }, [])
return ( return (
<>
{
store ? store ?
<ConfigProvider locale={zhCN}> <ConfigProvider locale={zhCN}>
<Provider store={store}> <Provider store={store}>
@ -160,6 +176,7 @@ const Root = props => {
<Layout <Layout
history={history} history={history}
routes={innnerRoutes} routes={innnerRoutes}
authCrossLoading={authCrossLoading}
> >
{combineRoutes} {combineRoutes}
</Layout> </Layout>
@ -172,6 +189,12 @@ const Root = props => {
</Provider> </Provider>
</ConfigProvider> </ConfigProvider>
: '' : ''
}
<iframe id="iotAuth" src="http://localhost:5200/cross" style={{ position: 'absolute', top: 0 }} frameBorder={0} >
<p>你的浏览器不支持 iframe</p>
</iframe>
</>
) )
} }

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

@ -3,8 +3,12 @@
import { ApiTable, AuthRequest } from '$utils' import { ApiTable, AuthRequest } from '$utils'
export const INIT_AUTH = 'INIT_AUTH'; export const INIT_AUTH = 'INIT_AUTH';
export function initAuth () { export function initAuth (userData) {
const user = JSON.parse(sessionStorage.getItem('user')) || {}; const sessionUser = JSON.parse(sessionStorage.getItem('user'))
const user = userData || sessionUser || {};
if (user.authorized && !sessionUser) {
sessionStorage.setItem('user', JSON.stringify(user))
}
return { return {
type: INIT_AUTH, type: INIT_AUTH,
payload: { payload: {
@ -58,11 +62,12 @@ export function login (username, password) {
} }
export const LOGOUT = 'LOGOUT'; export const LOGOUT = 'LOGOUT';
export function logout (user) { export function logout () {
sessionStorage.removeItem('user'); const user = JSON.parse(sessionStorage.getItem('user'))
AuthRequest.put(ApiTable.logout, { AuthRequest.put(ApiTable.logout, {
token: user.token token: user.token
}); });
sessionStorage.removeItem('user');
return { return {
type: LOGOUT type: LOGOUT
}; };

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

@ -20,6 +20,8 @@ const Login = props => {
useEffect(() => { useEffect(() => {
if (user && user.authorized) { if (user && user.authorized) {
const iotAuth = document.getElementById('iotAuth').contentWindow;
iotAuth.postMessage({ action: 'login', user: user }, '*');
dispatch(push('/equipmentWarehouse/nvr')); dispatch(push('/equipmentWarehouse/nvr'));
localStorage.setItem('vcmp_selected_sider', JSON.stringify(['nvr'])) localStorage.setItem('vcmp_selected_sider', JSON.stringify(['nvr']))
localStorage.setItem('vcmp_open_sider', JSON.stringify(['equipmentWarehouse'])) localStorage.setItem('vcmp_open_sider', JSON.stringify(['equipmentWarehouse']))

2
code/VideoAccess-VCMP/web/client/src/sections/equipmentWarehouse/components/skeletonScreen.jsx

@ -1,4 +1,4 @@
import React from "react"; import React, { useState, useEffect } from "react";
import { Table } from "@douyinfe/semi-ui"; import { Table } from "@douyinfe/semi-ui";

4
code/VideoAccess-VCMP/web/webpack.config.js

@ -32,7 +32,9 @@ module.exports = {
}, },
plugins: [ plugins: [
new webpack.HotModuleReplacementPlugin(), new webpack.HotModuleReplacementPlugin(),
new BundleAnalyzerPlugin(), new BundleAnalyzerPlugin({
analyzerPort: 8000,
}),
], ],
module: { module: {
rules: [{ rules: [{

Loading…
Cancel
Save