Browse Source

版本

master
wenlele 2 years ago
parent
commit
d24760eaac
  1. 4
      code/web/client/src/layout/actions/index.js
  2. 60
      code/web/client/src/layout/actions/webSocket.js
  3. 13
      code/web/client/src/layout/components/header/index.jsx
  4. 2
      code/web/client/src/layout/components/sider/index.jsx
  5. 8
      code/web/client/src/layout/index.jsx
  6. 4
      code/web/client/src/layout/reducers/index.js
  7. 36
      code/web/client/src/layout/reducers/webSocket.js
  8. 4
      code/web/client/src/sections/auth/actions/auth.js
  9. 2
      code/web/client/src/sections/auth/containers/cross.jsx
  10. 2
      code/web/client/src/sections/auth/containers/login.jsx
  11. 8
      code/web/client/src/sections/edition/containers/administer.jsx
  12. 5
      code/web/client/src/sections/edition/index.js
  13. 3
      code/web/client/src/sections/edition/nav-item.jsx
  14. 2
      code/web/client/src/utils/webapi.js

4
code/web/client/src/layout/actions/index.js

@ -1,9 +1,9 @@
'use strict'; 'use strict';
import * as global from './global' import * as global from './global'
import * as socket from './webSocket'; // import * as socket from './webSocket';
export default { export default {
...global, ...global,
...socket, // ...socket,
}; };

60
code/web/client/src/layout/actions/webSocket.js

@ -1,33 +1,33 @@
'use strict'; 'use strict';
import io from 'socket.io-client'; import io from 'socket.io-client';
export const INIT_WEB_SOCKET = 'INIT_WEB_SOCKET' // export const INIT_WEB_SOCKET = 'INIT_WEB_SOCKET'
export function initWebSocket ({ ioUrl, token }) { // export function initWebSocket ({ ioUrl, token }) {
if (!ioUrl) { // if (!ioUrl) {
ioUrl = localStorage.getItem('apiRoot') // ioUrl = localStorage.getItem('apiRoot')
} // }
if (!token) { // if (!token) {
const user = sessionStorage.getItem('user') // const user = sessionStorage.getItem('user')
if (user) { // if (user) {
token = JSON.parse(user).token // token = JSON.parse(user).token
} // }
} // }
if (!ioUrl || !token) { // if (!ioUrl || !token) {
return { // return {
type: '', // type: '',
} // }
} // }
return dispatch => { // return dispatch => {
const socket = io(ioUrl, { // const socket = io(ioUrl, {
query: { // query: {
token: token // token: token
}, // },
}); // });
dispatch({ // dispatch({
type: INIT_WEB_SOCKET, // type: INIT_WEB_SOCKET,
payload: { // payload: {
socket: socket // socket: socket
} // }
}) // })
} // }
} // }

13
code/web/client/src/layout/components/header/index.jsx

@ -4,7 +4,7 @@ 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, } = props;
return ( return (
<> <>
@ -13,9 +13,9 @@ const Header = (props) => {
onClick={({ itemKey }) => { onClick={({ itemKey }) => {
if (itemKey == "logout") { if (itemKey == "logout") {
dispatch(actions.auth.logout()); dispatch(actions.auth.logout());
if (socket) { // if (socket) {
socket.disconnect(); // socket.disconnect();
} // }
history.push(`/signin`); history.push(`/signin`);
} }
}} }}
@ -64,7 +64,6 @@ const Header = (props) => {
<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}
</div> </div>
} }
> >
@ -77,11 +76,11 @@ const Header = (props) => {
}; };
function mapStateToProps (state) { function mapStateToProps (state) {
const { global, auth, webSocket } = state; const { global, auth, } = state;
return { return {
actions: global.actions, actions: global.actions,
user: auth.user, user: auth.user,
socket: webSocket.socket, // socket: webSocket.socket,
}; };
} }

2
code/web/client/src/layout/components/sider/index.jsx

@ -14,6 +14,7 @@ const Sider = props => {
useEffect(() => { useEffect(() => {
const { sections, dispatch, user } = props; const { sections, dispatch, user } = props;
let nextItems = [] let nextItems = []
console.log(sections);
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);
@ -22,6 +23,7 @@ const Sider = props => {
} }
} }
} }
console.log(nextItems);
setItems(nextItems) setItems(nextItems)
const lastSelectedKeys = localStorage.getItem('fs_iot_auth_selected_sider') const lastSelectedKeys = localStorage.getItem('fs_iot_auth_selected_sider')

8
code/web/client/src/layout/index.jsx

@ -15,11 +15,13 @@ import 'moment/locale/zh-cn';
moment.locale('zh-cn'); 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;
console.log(sections);
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([])
@ -125,7 +127,7 @@ const Root = props => {
store.dispatch(initLayout(title, copyright, sections, actions)); store.dispatch(initLayout(title, copyright, sections, actions));
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()) store.dispatch(initApiRoot())
const combineRoutes = flatRoutes(innerRoutes); const combineRoutes = flatRoutes(innerRoutes);

4
code/web/client/src/layout/reducers/index.js

@ -7,11 +7,11 @@
'use strict'; 'use strict';
import global from './global'; import global from './global';
import webSocket from './webSocket' // import webSocket from './webSocket'
import ajaxResponse from './ajaxResponse'; import ajaxResponse from './ajaxResponse';
export default { export default {
global, global,
webSocket, // webSocket,
ajaxResponse, ajaxResponse,
}; };

36
code/web/client/src/layout/reducers/webSocket.js

@ -1,21 +1,21 @@
'use strict'; // 'use strict';
import * as actionTypes from '../actions/webSocket'; // import * as actionTypes from '../actions/webSocket';
import Immutable from 'immutable'; // import Immutable from 'immutable';
const initState = { // const initState = {
socket: null, // socket: null,
}; // };
function webSocket (state = initState, action) { // function webSocket (state = initState, action) {
const payload = action.payload; // const payload = action.payload;
switch (action.type) { // switch (action.type) {
case actionTypes.INIT_WEB_SOCKET: // case actionTypes.INIT_WEB_SOCKET:
return Immutable.fromJS(state).merge({ // return Immutable.fromJS(state).merge({
socket: payload.socket, // socket: payload.socket,
}).toJS(); // }).toJS();
default: // default:
return state; // return state;
} // }
} // }
export default webSocket; // export default webSocket;

4
code/web/client/src/sections/auth/actions/auth.js

@ -42,7 +42,7 @@ export function login (username, password) {
return Request.post(ApiTable.login, { username, password }) return Request.post(ApiTable.login, { username, password })
.then(user => { .then(user => {
sessionStorage.setItem('user', JSON.stringify(user)); sessionStorage.setItem('user', JSON.stringify(user));
localStorage.setItem('fs_iot_cross_user', JSON.stringify(user)); // localStorage.setItem('fs_iot_cross_user', JSON.stringify(user));
return dispatch({ return dispatch({
type: LOGIN_SUCCESS, type: LOGIN_SUCCESS,
payload: { user: user }, payload: { user: user },
@ -66,7 +66,7 @@ export function logout () {
token: user.token token: user.token
}); });
sessionStorage.removeItem('user'); sessionStorage.removeItem('user');
localStorage.removeItem('fs_iot_cross_user'); // localStorage.removeItem('fs_iot_cross_user');
return { return {
type: LOGOUT type: LOGOUT
}; };

2
code/web/client/src/sections/auth/containers/cross.jsx

@ -66,7 +66,7 @@ const Cross = ({ dispatch, actions }) => {
} }
function mapStateToProps (state) { function mapStateToProps (state) {
const { global, auth, webSocket } = state; const { global, auth, } = state;
return { return {
actions: global.actions, actions: global.actions,
user: auth.user, user: auth.user,

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

@ -52,7 +52,7 @@ const Login = props => {
onSubmit={values => { onSubmit={values => {
dispatch(login(values.username, values.password)).then(res => { dispatch(login(values.username, values.password)).then(res => {
const data = res.payload.user const data = res.payload.user
dispatch(actions.layout.initWebSocket({ ioUrl: apiRoot, token: data.token })) // dispatch(actions.layout.initWebSocket({ ioUrl: apiRoot, token: data.token }))
}) })
}} }}
getFormApi={formApi => form.current = formApi} getFormApi={formApi => form.current = formApi}

8
code/web/client/src/sections/edition/containers/administer.jsx

@ -9,15 +9,15 @@ const Administer = props => {
const { dispatch, user, error, actions, apiRoot, isRequesting } = props const { dispatch, user, error, actions, apiRoot, isRequesting } = props
useEffect(() => { useEffect(() => {
}, []) }, [])
return ( return (
<div style={{ <div style={{}}>
}}>
5204620542045204 5204620542045204
</div> </div>
); );

5
code/web/client/src/sections/edition/index.js

@ -3,10 +3,13 @@
import routes from './routes'; import routes from './routes';
import reducers from './reducers'; import reducers from './reducers';
import actions from './actions'; import actions from './actions';
import { getNavItem } from './nav-item';
export default { export default {
key: 'edition', key: 'edition',
name: '版本管理',
reducers: reducers, reducers: reducers,
routes: routes, routes: routes,
actions: actions actions: actions,
getNavItem: getNavItem
}; };

3
code/web/client/src/sections/edition/nav-item.jsx

@ -5,8 +5,7 @@ export function getNavItem (user, dispatch) {
return ( return (
[ [
{ {
itemKey: 'edition', text: 'edition', icon: <IconCode />, itemKey: 'edition', text: '版本管理', icon: <IconCode />, to: '/edition',
to: '/edition',
}, },
] ]
); );

2
code/web/client/src/utils/webapi.js

@ -2,7 +2,7 @@
export const ApiTable = { export const ApiTable = {
login: 'v1/login', login: 'v1/login',
logout: 'logout', logout: 'v1/logout',
crossCheck: 'cross_token/check', crossCheck: 'cross_token/check',
}; };

Loading…
Cancel
Save