diff --git a/docs/zh/sys-vuex/README.md.REMOVED.git-id b/docs/zh/sys-vuex/README.md.REMOVED.git-id index a901b125..7db055cd 100644 --- a/docs/zh/sys-vuex/README.md.REMOVED.git-id +++ b/docs/zh/sys-vuex/README.md.REMOVED.git-id @@ -1 +1 @@ -33948f39bdcc1391fd42429bd95b3b98c167fb23 \ No newline at end of file +28e37c79429114aea200a5e2a7bcc6f8707ab39d \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index b3766ab0..38fc6878 100755 --- a/src/router/index.js +++ b/src/router/index.js @@ -26,6 +26,9 @@ router.beforeEach((to, from, next) => { if (token && token !== 'undefined') { next() } else { + // 将当前预计打开的页面完整地址临时存储 登陆后继续跳转 + // 这个 cookie(redirect) 会在登陆后自动删除 + util.cookies.set('redirect', to.fullPath) // 没有登陆的时候跳转到登陆界面 next({ name: 'login' diff --git a/src/store/modules/d2admin/modules/account.js b/src/store/modules/d2admin/modules/account.js index aafbf581..3e28d6c2 100644 --- a/src/store/modules/d2admin/modules/account.js +++ b/src/store/modules/d2admin/modules/account.js @@ -10,8 +10,18 @@ export default { * @param {Object} param vm {Object} vue 实例 * @param {Object} param username {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({ username, @@ -31,10 +41,12 @@ export default { }, { root: true }) // 用户登陆后从持久化数据加载一系列的设置 commit('load') - // 跳转路由 - vm.$router.push({ - name: 'index' - }) + // 更新路由 尝试去获取 cookie 里保存的需要重定向的页面完整地址 + const path = util.cookies.get('redirect') + // 根据是否存有重定向页面判断如何重定向 + vm.$router.replace(path ? { path } : route) + // 删除 cookie 中保存的重定向页面 + util.cookies.remove('redirect') }) .catch(err => { console.group('登陆结果')