Browse Source

AUTH CROSS

release_0.0.2
yuan_yi 3 years ago
parent
commit
63e8968c10
  1. 1
      code/VideoAccess-VCMP/api/.vscode/launch.json
  2. 1
      code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js
  3. 18
      code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js
  4. 7
      code/VideoAccess-VCMP/api/app/lib/service/paasRequest.js
  5. 8
      code/VideoAccess-VCMP/api/config.js
  6. 144
      code/VideoAccess-VCMP/web/client/src/layout/components/header/index.jsx
  7. 110
      code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx
  8. 317
      code/VideoAccess-VCMP/web/client/src/layout/index.jsx
  9. 111
      code/VideoAccess-VCMP/web/client/src/sections/auth/actions/auth.js
  10. 12
      code/VideoAccess-VCMP/web/client/src/sections/auth/containers/login.jsx

1
code/VideoAccess-VCMP/api/.vscode/launch.json

@ -20,6 +20,7 @@
"--redisPort 6379", "--redisPort 6379",
"--axyApiUrl http://127.0.0.1:4100", "--axyApiUrl http://127.0.0.1:4100",
"--iotAuthApi http://127.0.0.1:4200", "--iotAuthApi http://127.0.0.1:4200",
"--iotVideoServerUrl http://221.230.55.27:8081",
"--godUrl https://restapi.amap.com/v3", "--godUrl https://restapi.amap.com/v3",
"--godKey 21c2d970e1646bb9a795900dd00093ce" "--godKey 21c2d970e1646bb9a795900dd00093ce"
] ]

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,

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;

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 参数错误!'
} }

8
code/VideoAccess-VCMP/api/config.js

@ -14,8 +14,9 @@ args.option(['f', 'fileHost'], '文件中心本地化存储: WebApi 服务器地
args.option('redisHost', 'redisHost'); args.option('redisHost', 'redisHost');
args.option('redisPort', 'redisPort'); args.option('redisPort', 'redisPort');
args.option('redisPswd', 'redisPassword'); args.option('redisPswd', 'redisPassword');
args.option('iotAuthApi', 'IOT 鉴权 api');
args.option('axyApiUrl', '安心云 api'); args.option('axyApiUrl', '安心云 api');
args.option('iotAuthApi', 'IOT 鉴权 api');
args.option('iotVideoServerUrl', '视频后端服务地址');
args.option('godUrl', '高德地图API请求地址'); args.option('godUrl', '高德地图API请求地址');
args.option('godKey', '高德地图API key'); args.option('godKey', '高德地图API key');
@ -29,6 +30,7 @@ const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redis
const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码 const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码
const IOT_AUTH_API = process.env.IOT_AUTH_API || flags.iotAuthApi; const IOT_AUTH_API = process.env.IOT_AUTH_API || flags.iotAuthApi;
const IOT_VIDEO_SERVER_URL = process.env.IOT_VIDEO_SERVER_URL || flags.iotVideoServerUrl
const AXY_API_URL = process.env.AXY_API_URL || flags.axyApiUrl; const AXY_API_URL = process.env.AXY_API_URL || flags.axyApiUrl;
const GOD_URL = process.env.GOD_URL || flags.godUrl || 'https://restapi.amap.com/v3'; const GOD_URL = process.env.GOD_URL || flags.godUrl || 'https://restapi.amap.com/v3';
const GOD_KEY = process.env.GOD_KEY || flags.godKey; const GOD_KEY = process.env.GOD_KEY || flags.godKey;
@ -85,6 +87,10 @@ const product = {
key: GOD_KEY key: GOD_KEY
} }
} }
}, {
name: 'videoServerRequest',
root: IOT_VIDEO_SERVER_URL + '/api',
dataWord: 'text'
},] },]
} }
} }

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

@ -4,82 +4,84 @@ import { connect } from "react-redux";
import { Nav, Avatar, Dropdown } from "@douyinfe/semi-ui"; import { Nav, Avatar, Dropdown } from "@douyinfe/semi-ui";
const Header = (props) => { const Header = (props) => {
const { dispatch, history, user, actions, socket } = props; const { dispatch, history, user, actions, socket } = props;
return ( return (
<> <>
<Nav <Nav
mode={"horizontal"} mode={"horizontal"}
onClick={({ itemKey }) => { onClick={({ itemKey }) => {
if (itemKey == "logout") { if (itemKey == "logout") {
dispatch(actions.auth.logout(user)); dispatch(actions.auth.logout(user));
if (socket) { const iotAuth = document.getElementById('iotAuth').contentWindow;
socket.disconnect(); iotAuth.postMessage({ action: 'logout' }, '*');
} if (socket) {
history.push(`/signin`); socket.disconnect();
} }
}} history.push(`/signin`);
style={{ }
height: 60, }}
minWidth: 520, style={{
background: "url(/assets/images/background/header.png)", height: 60,
backgroundSize: "100% 100%", minWidth: 520,
color: "white", background: "url(/assets/images/background/header.png)",
}} backgroundSize: "100% 100%",
header={{ color: "white",
logo: ( }}
<img header={{
src="/assets/images/background/logo.png" logo: (
style={{ display: "inline-block", width: 280, height: 52}} <img
/> src="/assets/images/background/logo.png"
), style={{ display: "inline-block", width: 280, height: 52 }}
text: "", />
}} ),
footer={ text: "",
<Nav.Sub }}
itemKey={"user"} footer={
text={ <Nav.Sub
<div itemKey={"user"}
style={{ text={
marginLeft: 20, <div
display: "inline-block", style={{
color: "white", marginLeft: 20,
}} display: "inline-block",
> color: "white",
<img }}
src="/assets/images/background/notice.png" >
style={{ <img
display: "inline-block", src="/assets/images/background/notice.png"
width: 18, style={{
height: 18, display: "inline-block",
position: "relative", width: 18,
top: 6, height: 18,
left: -10, position: "relative",
}} top: 6,
/> left: -10,
}}
/>
<Avatar size="small" color="light-blue" style={{ margin: 4 }}> <Avatar size="small" color="light-blue" style={{ margin: 4 }}>
<img src="/assets/images/avatar/6.png" /> <img src="/assets/images/avatar/6.png" />
</Avatar> </Avatar>
{user && user.namePresent} {user && user.namePresent}
</div> </div>
}
>
<Nav.Item itemKey={"logout"} text={"退出"} />
</Nav.Sub>
} }
> />
<Nav.Item itemKey={"logout"} text={"退出"} /> </>
</Nav.Sub> );
}
/>
</>
);
}; };
function mapStateToProps(state) { function mapStateToProps (state) {
const { global, auth, webSocket } = state; const { global, auth, webSocket } = state;
return { return {
actions: global.actions, actions: global.actions,
user: auth.user, user: auth.user,
socket: webSocket.socket, socket: webSocket.socket,
}; };
} }
export default connect(mapStateToProps)(Header); export default connect(mapStateToProps)(Header);

110
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,58 +69,74 @@ const LayoutContainer = props => {
} }
const dom = document.getElementById('page-content'); const dom = document.getElementById('page-content');
if (dom) { if (dom) {
scrollbar.update(); if (!scrollbar) {
dom.scrollTop = 0; scrollbar = new PerfectScrollbar('#page-content', { suppressScrollX: true });
} else {
scrollbar.update();
dom.scrollTop = 0;
}
} }
}) })
return ( return (
<Layout id="layout"> <Layout id="layout">
<Layout.Header> {
<Header authCrossLoading ?
user={user}
pathname={location.pathname}
toggleCollapsed={() => {
setCollapsed(!collapsed);
}}
collapsed={collapsed}
history={history}
/>
</Layout.Header>
<Layout>
<Layout.Sider>
<Sider
sections={sections}
dispatch={dispatch}
user={user}
pathname={location.pathname}
collapsed={collapsed}
/>
</Layout.Sider>
<Layout.Content>
<div style={{ <div style={{
margin: '12px 12px 0px', position: 'absolute', height: '100%', width: '100%',
background: "#F6FAFF", display: 'flex', alignItems: 'center', placeContent: 'center',
}}> }}>
<div id="page-content" style={{ 载入中...
height: clientHeight - 12,
minWidth: 520,
position: 'relative',
}}>
<div style={{
minHeight: clientHeight - 32 - 12,
position: 'relative',
padding: '12px 8px',
}}>
{children}
</div>
<Layout.Footer>
<Footer />
</Layout.Footer>
</div>
</div> </div>
</Layout.Content> :
</Layout> <>
<Layout.Header>
<Header
user={user}
pathname={location.pathname}
toggleCollapsed={() => {
setCollapsed(!collapsed);
}}
collapsed={collapsed}
history={history}
/>
</Layout.Header>
<Layout>
<Layout.Sider>
<Sider
sections={sections}
dispatch={dispatch}
user={user}
pathname={location.pathname}
collapsed={collapsed}
/>
</Layout.Sider>
<Layout.Content>
<div style={{
margin: '12px 12px 0px',
background: "#F6FAFF",
}}>
<div id="page-content" style={{
height: clientHeight - 12,
minWidth: 520,
position: 'relative',
}}>
<div style={{
minHeight: clientHeight - 32 - 12,
position: 'relative',
padding: '12px 8px',
}}>
{children}
</div>
<Layout.Footer>
<Footer />
</Layout.Footer>
</div>
</div>
</Layout.Content>
</Layout>
</>
}
</Layout > </Layout >
) )
} }

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

@ -18,161 +18,184 @@ moment.locale('zh-cn');
const { initLayout, initApiRoot, resize, initWebSocket } = layoutActions; const { initLayout, initApiRoot, resize, initWebSocket } = layoutActions;
const Root = props => { const Root = props => {
const { sections, title, copyright } = props; const { sections, title, copyright } = props;
const [history, setHistory] = useState(null) const [history, setHistory] = useState(null)
const [store, setStore] = useState(null) const [store, setStore] = useState(null)
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 combineRoutes = []; const flatRoutes = (routes) => {
const combineRoutes = [];
function flat (routes, parentRoute) {
routes.forEach((route, i) => { function flat (routes, parentRoute) {
let obj = { routes.forEach((route, i) => {
path: route.path, let obj = {
breadcrumb: route.breadcrumb, path: route.path,
component: route.component || null, breadcrumb: route.breadcrumb,
authCode: route.authCode || '', component: route.component || null,
key: route.key authCode: route.authCode || '',
} key: route.key
if (!route.path.startsWith("/")) { }
console.error('路由配置需以 "/" 开始:' + route.path); if (!route.path.startsWith("/")) {
} console.error('路由配置需以 "/" 开始:' + route.path);
if (route.path.length > 1 && route.path[route.path.length] == '/') { }
console.error('除根路由路由配置不可以以 "/" 结束:' + route.path); if (route.path.length > 1 && route.path[route.path.length] == '/') {
} console.error('除根路由路由配置不可以以 "/" 结束:' + route.path);
if (parentRoute && parentRoute != '/') { }
obj.path = parentRoute + route.path; if (parentRoute && parentRoute != '/') {
} obj.path = parentRoute + route.path;
if (route.exact) { }
obj.exact = true if (route.exact) {
} obj.exact = true
if (route.hasOwnProperty('childRoutes')) { }
combineRoutes.push(obj); if (route.hasOwnProperty('childRoutes')) {
flat(route.childRoutes, obj.path) combineRoutes.push(obj);
} else { flat(route.childRoutes, obj.path)
combineRoutes.push(obj)
}
})
}
flat(routes);
return combineRoutes;
}
const initReducer = (reducers, reducerName, action) => {
let reducerParams = {}
const { actionType, initReducer, reducer } = action()()
if (initReducer || reducer) {
if (reducer) {
if (reducer.name) {
reducerName = reducer.name
}
if (reducer.params) {
reducerParams = reducer.params
}
} else { } else {
reducerName = `${reducerName}Rslt` combineRoutes.push(obj)
} }
reducers[reducerName] = function (state, action) { })
return basicReducer(state, action, Object.assign({ actionType: actionType }, reducerParams)); }
flat(routes);
return combineRoutes;
}
const initReducer = (reducers, reducerName, action) => {
let reducerParams = {}
const { actionType, initReducer, reducer } = action()()
if (initReducer || reducer) {
if (reducer) {
if (reducer.name) {
reducerName = reducer.name
} }
} if (reducer.params) {
} reducerParams = reducer.params
useEffect(() => {
let innerRoutes = []
let outerRoutes = []
let reducers = {}
let actions = {
layout: layoutActions
}
for (let s of sections) {
if (!s.key) console.warn('请给你的section添加一个key值,section name:' + s.name);
for (let r of s.routes) {
if (r.type == 'inner' || r.type == 'home') {
innerRoutes.push(r.route)
} else if (r.type == 'outer') {
outerRoutes.push(r.route)
}
} }
if (s.reducers) { } else {
reducers = { ...reducers, ...s.reducers } reducerName = `${reducerName}Rslt`
}
reducers[reducerName] = function (state, action) {
return basicReducer(state, action, Object.assign({ actionType: actionType }, reducerParams));
}
}
}
useEffect(() => {
let innerRoutes = []
let outerRoutes = []
let reducers = {}
let actions = {
layout: layoutActions
}
for (let s of sections) {
if (!s.key) console.warn('请给你的section添加一个key值,section name:' + s.name);
for (let r of s.routes) {
if (r.type == 'inner' || r.type == 'home') {
innerRoutes.push(r.route)
} else if (r.type == 'outer') {
outerRoutes.push(r.route)
} }
if (s.actions) { }
actions = { ...actions, [s.key]: s.actions } if (s.reducers) {
if (s.key != 'auth') { reducers = { ...reducers, ...s.reducers }
for (let ak in s.actions) { }
let actions = s.actions[ak] if (s.actions) {
if (actions && typeof actions == 'object') { actions = { ...actions, [s.key]: s.actions }
for (let actionName in actions) { if (s.key != 'auth') {
initReducer(reducers, actionName, actions[actionName]) for (let ak in s.actions) {
} let actions = s.actions[ak]
} else if (typeof actions == 'function') { if (actions && typeof actions == 'object') {
initReducer(reducers, ak, actions) for (let actionName in actions) {
} initReducer(reducers, actionName, actions[actionName])
} }
} } else if (typeof actions == 'function') {
initReducer(reducers, ak, actions)
}
}
} }
} }
}
let history = createBrowserHistory();
let store = configStore(reducers, history); let history = createBrowserHistory();
store.dispatch(initLayout(title, copyright, sections, actions)); let store = configStore(reducers, history);
store.dispatch(resize(document.body.clientHeight, document.body.clientWidth)); store.dispatch(initLayout(title, copyright, sections, actions));
store.dispatch(actions.auth.initAuth()); store.dispatch(resize(document.body.clientHeight, document.body.clientWidth));
store.dispatch(initWebSocket({})) store.dispatch(actions.auth.initAuth());
store.dispatch(initApiRoot()) store.dispatch(initWebSocket({}))
store.dispatch(initApiRoot())
const combineRoutes = flatRoutes(innerRoutes);
const combineRoutes = flatRoutes(innerRoutes);
setInnerRoutes(combineRoutes)
setHistory(history) setInnerRoutes(combineRoutes)
setStore(store) setHistory(history)
setOuterRoutes(outerRoutes.map(route => ( setStore(store)
<Route setOuterRoutes(outerRoutes.map(route => (
key={route.key} <Route
exact key={route.key}
path={route.path} exact
component={route.component} path={route.path}
/> component={route.component}
))) />
setCombineRoutes(combineRoutes.map(route => ( )))
<Route setCombineRoutes(combineRoutes.map(route => (
key={route.key} <Route
exact={route.hasOwnProperty('exact') ? route.exact : true} key={route.key}
path={route.path} exact={route.hasOwnProperty('exact') ? route.exact : true}
component={route.component} path={route.path}
/> component={route.component}
))) />
}, []) )))
return ( window.addEventListener('message', async function (e) { // message
store ? const { data } = e
<ConfigProvider locale={zhCN}> if (data && data.action) {
<Provider store={store}> if (data.action == 'initUser') {
<ConnectedRouter history={history}> await store.dispatch(actions.auth.initAuth(e.data))
} else if (data.action == 'logout') {
await store.dispatch(actions.auth.logout())
}
}
setAuthCrossLoading(false)
});
}, [])
return (
<>
{
store ?
<ConfigProvider locale={zhCN}>
<Provider store={store}>
<ConnectedRouter history={history}>
<Switch> <Switch>
{outerRoutes} {outerRoutes}
<Layout <Layout
history={history} history={history}
routes={innnerRoutes} routes={innnerRoutes}
> authCrossLoading={authCrossLoading}
{combineRoutes} >
</Layout> {combineRoutes}
<Route </Layout>
path={'*'} <Route
component={NoMatch} path={'*'}
/> component={NoMatch}
/>
</Switch> </Switch>
</ConnectedRouter> </ConnectedRouter>
</Provider> </Provider>
</ConfigProvider> </ConfigProvider>
: '' : ''
) }
<iframe id="iotAuth" src="http://localhost:5200/cross" style={{ position: 'absolute', top: 0 }} frameBorder={0} >
<p>你的浏览器不支持 iframe</p>
</iframe>
</>
)
} }
export default Root; export default Root;

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

@ -3,73 +3,78 @@
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'))
return { const user = userData || sessionUser || {};
type: INIT_AUTH, if (user.authorized && !sessionUser) {
payload: { sessionStorage.setItem('user', JSON.stringify(user))
user: user }
} return {
}; type: INIT_AUTH,
payload: {
user: user
}
};
} }
export const REQUEST_LOGIN = 'REQUEST_LOGIN'; export const REQUEST_LOGIN = 'REQUEST_LOGIN';
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS'; export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
export const LOGIN_ERROR = 'LOGIN_ERROR'; export const LOGIN_ERROR = 'LOGIN_ERROR';
export function login (username, password) { export function login (username, password) {
return dispatch => { return dispatch => {
dispatch({ type: REQUEST_LOGIN }); dispatch({ type: REQUEST_LOGIN });
if (!username || !password) { if (!username || !password) {
dispatch({ dispatch({
type: LOGIN_ERROR, type: LOGIN_ERROR,
payload: { error: '请输入账号名和密码' } payload: { error: '请输入账号名和密码' }
}); });
return Promise.resolve(); return Promise.resolve();
} }
// return dispatch({ // return dispatch({
// type: LOGIN_SUCCESS, // type: LOGIN_SUCCESS,
// payload: { // payload: {
// user: { // user: {
// authorized: true, // authorized: true,
// namePresent: 'TEST' // namePresent: 'TEST'
// } // }
// }, // },
// }); // });
return AuthRequest.post(ApiTable.login, { username, password }) return AuthRequest.post(ApiTable.login, { username, password })
.then(user => { .then(user => {
sessionStorage.setItem('user', JSON.stringify(user)); sessionStorage.setItem('user', JSON.stringify(user));
return dispatch({ return dispatch({
type: LOGIN_SUCCESS, type: LOGIN_SUCCESS,
payload: { user: user }, payload: { user: user },
});
}, error => {
let { body } = error.response;
return dispatch({
type: LOGIN_ERROR,
payload: {
error: body && body.message ? body.message : '登录失败'
}
})
}); });
} }, error => {
let { body } = error.response;
return dispatch({
type: LOGIN_ERROR,
payload: {
error: body && body.message ? body.message : '登录失败'
}
})
});
}
} }
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
}); });
return { sessionStorage.removeItem('user');
type: LOGOUT return {
}; type: LOGOUT
};
} }
export default { export default {
initAuth, initAuth,
login, login,
logout logout
} }

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

@ -20,16 +20,11 @@ const Login = props => {
useEffect(() => { useEffect(() => {
if (user && user.authorized) { if (user && user.authorized) {
const iotAuth = document.getElementById('iotAuth').contentWindow;
const receiver = document.getElementById('iotAuth').contentWindow; iotAuth.postMessage({ action: 'login', user: user }, '*');
// receiver.postMessage(user, "http://localhost:4200/cross");
receiver.postMessage('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']))
} }
}, [user]) }, [user])
@ -86,9 +81,6 @@ const Login = props => {
<Button htmlType='submit' block theme="solid" style={{ marginTop: 17, height: 40, backgroundColor: '#1859C1' }}>立即登录</Button> <Button htmlType='submit' block theme="solid" style={{ marginTop: 17, height: 40, backgroundColor: '#1859C1' }}>立即登录</Button>
</Form> </Form>
</div> </div>
<iframe loading="lazy" id="iotAuth" src="http://localhost:5200/cross" frameBorder={0}>
<p>你的浏览器不支持 iframe</p>
</iframe>
</div> </div>
); );
} }

Loading…
Cancel
Save