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';
import * as global from './global'
import * as socket from './webSocket';
// import * as socket from './webSocket';
export default {
...global,
...socket,
// ...socket,
};

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

@ -1,33 +1,33 @@
'use strict';
import io from 'socket.io-client';
export const INIT_WEB_SOCKET = 'INIT_WEB_SOCKET'
export function initWebSocket ({ ioUrl, token }) {
if (!ioUrl) {
ioUrl = localStorage.getItem('apiRoot')
}
if (!token) {
const user = sessionStorage.getItem('user')
if (user) {
token = JSON.parse(user).token
}
}
if (!ioUrl || !token) {
return {
type: '',
}
}
return dispatch => {
const socket = io(ioUrl, {
query: {
token: token
},
});
dispatch({
type: INIT_WEB_SOCKET,
payload: {
socket: socket
}
})
}
}
// export const INIT_WEB_SOCKET = 'INIT_WEB_SOCKET'
// export function initWebSocket ({ ioUrl, token }) {
// if (!ioUrl) {
// ioUrl = localStorage.getItem('apiRoot')
// }
// if (!token) {
// const user = sessionStorage.getItem('user')
// if (user) {
// token = JSON.parse(user).token
// }
// }
// if (!ioUrl || !token) {
// return {
// type: '',
// }
// }
// return dispatch => {
// const socket = io(ioUrl, {
// query: {
// token: token
// },
// });
// dispatch({
// type: INIT_WEB_SOCKET,
// payload: {
// 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";
const Header = (props) => {
const { dispatch, history, user, actions, socket } = props;
const { dispatch, history, user, actions, } = props;
return (
<>
@ -13,9 +13,9 @@ const Header = (props) => {
onClick={({ itemKey }) => {
if (itemKey == "logout") {
dispatch(actions.auth.logout());
if (socket) {
socket.disconnect();
}
// if (socket) {
// socket.disconnect();
// }
history.push(`/signin`);
}
}}
@ -64,7 +64,6 @@ const Header = (props) => {
<Avatar size="small" color="light-blue" style={{ margin: 4 }}>
<img src="/assets/images/avatar/6.png" />
</Avatar>
{user && user.namePresent}
</div>
}
>
@ -77,11 +76,11 @@ const Header = (props) => {
};
function mapStateToProps (state) {
const { global, auth, webSocket } = state;
const { global, auth, } = state;
return {
actions: global.actions,
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(() => {
const { sections, dispatch, user } = props;
let nextItems = []
console.log(sections);
for (let c of sections) {
if (typeof c.getNavItem == 'function') {
let item = c.getNavItem(user, dispatch);
@ -22,6 +23,7 @@ const Sider = props => {
}
}
}
console.log(nextItems);
setItems(nextItems)
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');
const { initLayout, initApiRoot, resize, initWebSocket } = layoutActions;
const { initLayout, initApiRoot, resize,
// initWebSocket
} = layoutActions;
const Root = props => {
const { sections, title, copyright } = props;
console.log(sections);
const [history, setHistory] = useState(null)
const [store, setStore] = useState(null)
const [outerRoutes, setOuterRoutes] = useState([])
@ -125,7 +127,7 @@ const Root = props => {
store.dispatch(initLayout(title, copyright, sections, actions));
store.dispatch(resize(document.body.clientHeight, document.body.clientWidth));
store.dispatch(actions.auth.initAuth());
store.dispatch(initWebSocket({}))
// store.dispatch(initWebSocket({}))
store.dispatch(initApiRoot())
const combineRoutes = flatRoutes(innerRoutes);

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

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

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

@ -1,21 +1,21 @@
'use strict';
import * as actionTypes from '../actions/webSocket';
import Immutable from 'immutable';
// 'use strict';
// import * as actionTypes from '../actions/webSocket';
// import Immutable from 'immutable';
const initState = {
socket: null,
};
// const initState = {
// socket: null,
// };
function webSocket (state = initState, action) {
const payload = action.payload;
switch (action.type) {
case actionTypes.INIT_WEB_SOCKET:
return Immutable.fromJS(state).merge({
socket: payload.socket,
}).toJS();
default:
return state;
}
}
// function webSocket (state = initState, action) {
// const payload = action.payload;
// switch (action.type) {
// case actionTypes.INIT_WEB_SOCKET:
// return Immutable.fromJS(state).merge({
// socket: payload.socket,
// }).toJS();
// default:
// 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 })
.then(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({
type: LOGIN_SUCCESS,
payload: { user: user },
@ -66,7 +66,7 @@ export function logout () {
token: user.token
});
sessionStorage.removeItem('user');
localStorage.removeItem('fs_iot_cross_user');
// localStorage.removeItem('fs_iot_cross_user');
return {
type: LOGOUT
};

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

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

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

@ -52,7 +52,7 @@ const Login = props => {
onSubmit={values => {
dispatch(login(values.username, values.password)).then(res => {
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}

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
useEffect(() => {
}, [])
return (
<div style={{
}}>
<div style={{}}>
5204620542045204
</div>
);

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

@ -3,10 +3,13 @@
import routes from './routes';
import reducers from './reducers';
import actions from './actions';
import { getNavItem } from './nav-item';
export default {
key: 'edition',
name: '版本管理',
reducers: reducers,
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 (
[
{
itemKey: 'edition', text: 'edition', icon: <IconCode />,
to: '/edition',
itemKey: 'edition', text: '版本管理', icon: <IconCode />, to: '/edition',
},
]
);

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

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

Loading…
Cancel
Save