修复:登陆后跳转的问题

This commit is contained in:
jmal 2021-02-03 17:01:41 +08:00
parent bca6697e85
commit f923229836
4 changed files with 13 additions and 6 deletions

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -8,7 +8,7 @@
<!--在 head 标签中添加 meta 标签,并设置 viewport-fit=cover 值-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover">
<link rel="icon" href="<%= BASE_URL %>facion.ico">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= webpackConfig.name %></title>
</head>

View File

@ -12,7 +12,6 @@ const whiteList = ['/login','/s','/s_m','/share'] // 白名单
router.beforeEach(async(to, from, next) => {
// 开始进度条
NProgress.start()
// 设置页面标题
document.title = getPageTitle(to.meta.title)
@ -53,7 +52,7 @@ router.beforeEach(async(to, from, next) => {
next()
} else {
// 其他没有token重定向到登录页面。
next(`/login?redirect=${to.path}`)
next(`/login?redirect=${window.location.pathname}`)
NProgress.done()
}
}

View File

@ -5,7 +5,6 @@
<div id='stars2'></div>
<div id='stars3'></div>
<!--<img src="http://localhost:9528/file/public/s/preview/login-bg.png?fileIds=5eca6fe63c9ae7058035e99b">-->
<el-card class="box-card">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
@ -93,6 +92,7 @@
<script>
import { hasUser, initialization } from '@/api/user'
import { getRememberName } from '@/utils/auth'
import store from "@/store";
export default {
name: 'Login',
@ -148,6 +148,9 @@ export default {
$route: {
handler: function(route) {
this.redirect = route.query && route.query.redirect
if(route.query.path){
this.redirect += `&path=${route.query.path}`
}
},
immediate: true
}
@ -192,8 +195,13 @@ export default {
// 登录
this.loading = true
this.$store.dispatch('user/login', this.loginForm).then(() => {
this.$router.push({ path: this.redirect || '/' })
this.loading = false
this.$store.dispatch('user/setMenuList').then((res) => {
console.log(this.redirect)
this.$router.push({ path: this.redirect || '/' })
this.loading = false
}).catch(() => {
this.loading = false
})
}).catch(() => {
this.loading = false
})