From 62dd228b62b9f0dfafa06ccb7af2d8354d8662e6 Mon Sep 17 00:00:00 2001 From: duanledexianxianxian Date: Fri, 28 Jun 2019 08:24:34 +0800 Subject: [PATCH] sync --- src/pages/user/login/index.js | 10 ++----- src/pages/user/login/models/index.js | 40 +++++++++++++++++++++++++--- src/utils/index.js | 10 +++++-- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/pages/user/login/index.js b/src/pages/user/login/index.js index 1feeb182..24e5d347 100644 --- a/src/pages/user/login/index.js +++ b/src/pages/user/login/index.js @@ -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'); - } }); }; diff --git a/src/pages/user/login/models/index.js b/src/pages/user/login/models/index.js index 24235f10..5fa8f4f2 100644 --- a/src/pages/user/login/models/index.js +++ b/src/pages/user/login/models/index.js @@ -1,4 +1,7 @@ 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, + // }; + }, }, }; diff --git a/src/utils/index.js b/src/utils/index.js index 24770d8d..fb34da11 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,8 +1,14 @@ // 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(); -- GitLab