Merge branch 'feature/login_auto_redirect' into develop
Former-commit-id: 8064e89dc8772f63c8d0bedbcae97aebd6d93a1c [formerly 8064e89dc8772f63c8d0bedbcae97aebd6d93a1c [formerly 8064e89dc8772f63c8d0bedbcae97aebd6d93a1c [formerly 8064e89dc8772f63c8d0bedbcae97aebd6d93a1c [formerly 0121e12f2822777909d0450ea85890d356f99121 [formerly 71115327facbd20391c94055e0b3bceff9b6fc08]]]]] Former-commit-id: 48d67edc5f926bb2835c4ae36deca7a277605c8b Former-commit-id: 55c528f9a1fb23ee454dac4c01e27511e3e8be32 Former-commit-id: 62e6831fc00d5f3d365882c251f865a755843dbb [formerly a4a4339cb6966bf6f4dd7413f22767b5135bc8da] Former-commit-id: 4e2105b08270a27a6b8636744b5602c441a93cfe Former-commit-id: 5ad207105f902a38385760fb646022bda23e3196 Former-commit-id: bc80ac65c239b0b30d1a2fb9eaae02ec9c69769a Former-commit-id: 6d01367180a71343a180cf3a9201ea4142a4c7d8 Former-commit-id: 6fa5c50a33edbbbd030c2ea904fcaa9ea0a52d81
This commit is contained in:
@@ -1 +1 @@
|
|||||||
33948f39bdcc1391fd42429bd95b3b98c167fb23
|
28e37c79429114aea200a5e2a7bcc6f8707ab39d
|
||||||
@@ -26,6 +26,9 @@ router.beforeEach((to, from, next) => {
|
|||||||
if (token && token !== 'undefined') {
|
if (token && token !== 'undefined') {
|
||||||
next()
|
next()
|
||||||
} else {
|
} else {
|
||||||
|
// 将当前预计打开的页面完整地址临时存储 登陆后继续跳转
|
||||||
|
// 这个 cookie(redirect) 会在登陆后自动删除
|
||||||
|
util.cookies.set('redirect', to.fullPath)
|
||||||
// 没有登陆的时候跳转到登陆界面
|
// 没有登陆的时候跳转到登陆界面
|
||||||
next({
|
next({
|
||||||
name: 'login'
|
name: 'login'
|
||||||
|
|||||||
@@ -10,8 +10,18 @@ export default {
|
|||||||
* @param {Object} param vm {Object} vue 实例
|
* @param {Object} param vm {Object} vue 实例
|
||||||
* @param {Object} param username {String} 用户账号
|
* @param {Object} param username {String} 用户账号
|
||||||
* @param {Object} param password {String} 密码
|
* @param {Object} param password {String} 密码
|
||||||
|
* @param {Object} param route {Object} 登陆成功后定向的路由对象
|
||||||
*/
|
*/
|
||||||
login ({ commit }, { vm, username, password }) {
|
login ({
|
||||||
|
commit
|
||||||
|
}, {
|
||||||
|
vm,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
route = {
|
||||||
|
name: 'index'
|
||||||
|
}
|
||||||
|
}) {
|
||||||
// 开始请求登录接口
|
// 开始请求登录接口
|
||||||
AccountLogin({
|
AccountLogin({
|
||||||
username,
|
username,
|
||||||
@@ -31,10 +41,12 @@ export default {
|
|||||||
}, { root: true })
|
}, { root: true })
|
||||||
// 用户登陆后从持久化数据加载一系列的设置
|
// 用户登陆后从持久化数据加载一系列的设置
|
||||||
commit('load')
|
commit('load')
|
||||||
// 跳转路由
|
// 更新路由 尝试去获取 cookie 里保存的需要重定向的页面完整地址
|
||||||
vm.$router.push({
|
const path = util.cookies.get('redirect')
|
||||||
name: 'index'
|
// 根据是否存有重定向页面判断如何重定向
|
||||||
})
|
vm.$router.replace(path ? { path } : route)
|
||||||
|
// 删除 cookie 中保存的重定向页面
|
||||||
|
util.cookies.remove('redirect')
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.group('登陆结果')
|
console.group('登陆结果')
|
||||||
|
|||||||
Reference in New Issue
Block a user