Commit 62dd228b authored by duanledexianxianxian's avatar duanledexianxianxian

sync

parent 19001b76
......@@ -2,8 +2,10 @@ import React from 'react';
import { connect } from 'dva';
import router from 'umi/router';
import store from '@/utils/store';
import { Input, Icon, Button, message } from 'antd';
import config from '@/config';
import styles from './index.less';
@connect()
......@@ -27,14 +29,6 @@ class Login extends React.Component {
dispatch({
type: 'userLogin/login',
payload: { userName: username, password },
}).then(({ code, data }) => {
if (code === 'sys.success') {
const { token, userId } = data;
// message.success("登录成功");
store.set('token', token);
store.set('userId', userId);
router.push(config.home || '/profile/message');
}
});
};
......
import { login } from '../services';
import store from '@/utils/store';
import { routerRedux } from 'dva/router';
import { getPageQuery } from '@/utils';
const initData = {};
export default {
......@@ -7,12 +10,43 @@ export default {
...initData,
},
effects: {
*login({ payload }, { call }) {
const res = yield call(login, payload);
return res;
*login({ payload }, { call, put }) {
const { code, data } = yield call(login, payload);
if (code === 'sys.success') {
const { token, userId } = data;
store.set('token', token);
store.set('userId', userId);
const urlParams = new URL(window.location.href);
const params = getPageQuery();
// 是否需要重定向
let { redirect } = params;
if (redirect) {
const redirectUrlParams = new URL(redirect);
// origin相同
if (redirectUrlParams.origin === urlParams.origin) {
redirect = redirect.substr(urlParams.origin.length);
if (redirect.match(/^\/.*#/)) {
redirect = redirect.substr(redirect.indexOf('#') + 1);
}
} else {
window.location.href = redirect;
return;
}
}
yield put(routerRedux.replace(redirect || '/'));
}
},
},
reducers: {
clearData: () => ({ ...initData }),
changeLoginStatus(state, { payload }) {
// setAuthority(payload.currentAuthority);
// return {
// ...state,
// status: payload.status,
// type: payload.type,
// };
},
},
};
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable no-bitwise */
// 工具类已经转移到solomon-utils下,如果需要添加工具部分,请先考虑是否需要添加到solomon-utils下
import pathToRegexp from 'path-to-regexp';
import { parse } from 'qs';
/**
* 获取链接的query url部分
*/
export function getPageQuery() {
return parse(window.location.href.split('?')[1]);
}
export const generateUUID = () => {
let d = new Date().getTime();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment