用户登陆超时,重新登陆后原路径参数丢失解决,问题地址:

https://gitee.com/y_project/RuoYi-Vue/issues/I4XHZR
This commit is contained in:
fury_128 2022-03-18 10:58:42 +08:00
parent 857054179c
commit 131719ef04
2 changed files with 228 additions and 220 deletions

View File

@ -45,7 +45,7 @@ router.beforeEach((to, from, next) => {
// 在免登录白名单,直接进入 // 在免登录白名单,直接进入
next() next()
} else { } else {
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 next({ path: '/login' ,query:{re_path:to.path,...to.query}}) // 否则全部重定向到登录页
NProgress.done() NProgress.done()
} }
} }

View File

@ -1,219 +1,227 @@
<template> <template>
<div class="login"> <div class="login">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
<h3 class="title">若依后台管理系统</h3> <h3 class="title">若依后台管理系统</h3>
<el-form-item prop="username"> <el-form-item prop="username">
<el-input <el-input
v-model="loginForm.username" v-model="loginForm.username"
type="text" type="text"
auto-complete="off" auto-complete="off"
placeholder="账号" placeholder="账号"
> >
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" /> <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item prop="password"> <el-form-item prop="password">
<el-input <el-input
v-model="loginForm.password" v-model="loginForm.password"
type="password" type="password"
auto-complete="off" auto-complete="off"
placeholder="密码" placeholder="密码"
@keyup.enter.native="handleLogin" @keyup.enter.native="handleLogin"
> >
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item prop="code" v-if="captchaOnOff"> <el-form-item prop="code" v-if="captchaOnOff">
<el-input <el-input
v-model="loginForm.code" v-model="loginForm.code"
auto-complete="off" auto-complete="off"
placeholder="验证码" placeholder="验证码"
style="width: 63%" style="width: 63%"
@keyup.enter.native="handleLogin" @keyup.enter.native="handleLogin"
> >
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" /> <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
</el-input> </el-input>
<div class="login-code"> <div class="login-code">
<img :src="codeUrl" @click="getCode" class="login-code-img"/> <img :src="codeUrl" @click="getCode" class="login-code-img"/>
</div> </div>
</el-form-item> </el-form-item>
<el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox> <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
<el-form-item style="width:100%;"> <el-form-item style="width:100%;">
<el-button <el-button
:loading="loading" :loading="loading"
size="medium" size="medium"
type="primary" type="primary"
style="width:100%;" style="width:100%;"
@click.native.prevent="handleLogin" @click.native.prevent="handleLogin"
> >
<span v-if="!loading"> </span> <span v-if="!loading"> </span>
<span v-else> 中...</span> <span v-else> 中...</span>
</el-button> </el-button>
<div style="float: right;" v-if="register"> <div style="float: right;" v-if="register">
<router-link class="link-type" :to="'/register'">立即注册</router-link> <router-link class="link-type" :to="'/register'">立即注册</router-link>
</div> </div>
</el-form-item> </el-form-item>
</el-form> </el-form>
<!-- 底部 --> <!-- 底部 -->
<div class="el-login-footer"> <div class="el-login-footer">
<span>Copyright © 2018-2022 ruoyi.vip All Rights Reserved.</span> <span>Copyright © 2018-2022 ruoyi.vip All Rights Reserved.</span>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { getCodeImg } from "@/api/login"; import { getCodeImg } from "@/api/login";
import Cookies from "js-cookie"; import Cookies from "js-cookie";
import { encrypt, decrypt } from '@/utils/jsencrypt' import { encrypt, decrypt } from '@/utils/jsencrypt'
import {tansParams} from "@/utils/ruoyi";
export default {
name: "Login", export default {
data() { name: "Login",
return { data() {
codeUrl: "", return {
loginForm: { codeUrl: "",
username: "admin", loginForm: {
password: "admin123", username: "admin",
rememberMe: false, password: "admin123",
code: "", rememberMe: false,
uuid: "" code: "",
}, uuid: ""
loginRules: { },
username: [ loginRules: {
{ required: true, trigger: "blur", message: "请输入您的账号" } username: [
], { required: true, trigger: "blur", message: "请输入您的账号" }
password: [ ],
{ required: true, trigger: "blur", message: "请输入您的密码" } password: [
], { required: true, trigger: "blur", message: "请输入您的密码" }
code: [{ required: true, trigger: "change", message: "请输入验证码" }] ],
}, code: [{ required: true, trigger: "change", message: "请输入验证码" }]
loading: false, },
// loading: false,
captchaOnOff: true, //
// captchaOnOff: true,
register: false, //
redirect: undefined register: false,
}; redirect: undefined
}, };
watch: { },
$route: { watch: {
handler: function(route) { $route: {
this.redirect = route.query && route.query.redirect; handler: function(route) {
}, let re_path= route.query && route.query.re_path;
immediate: true if (re_path) {
} let param = JSON.parse(JSON.stringify(route.query));
}, console.log(route.query);
created() { delete param.re_path;
this.getCode(); re_path = `${re_path}?${tansParams(param)}`;
this.getCookie(); }
}, this.redirect = re_path;
methods: { },
getCode() { immediate: true
getCodeImg().then(res => { }
this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff; },
if (this.captchaOnOff) { created() {
this.codeUrl = "data:image/gif;base64," + res.img; this.getCode();
this.loginForm.uuid = res.uuid; this.getCookie();
} },
}); methods: {
}, getCode() {
getCookie() { getCodeImg().then(res => {
const username = Cookies.get("username"); this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff;
const password = Cookies.get("password"); if (this.captchaOnOff) {
const rememberMe = Cookies.get('rememberMe') this.codeUrl = "data:image/gif;base64," + res.img;
this.loginForm = { this.loginForm.uuid = res.uuid;
username: username === undefined ? this.loginForm.username : username, }
password: password === undefined ? this.loginForm.password : decrypt(password), });
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe) },
}; getCookie() {
}, const username = Cookies.get("username");
handleLogin() { const password = Cookies.get("password");
this.$refs.loginForm.validate(valid => { const rememberMe = Cookies.get('rememberMe')
if (valid) { this.loginForm = {
this.loading = true; username: username === undefined ? this.loginForm.username : username,
if (this.loginForm.rememberMe) { password: password === undefined ? this.loginForm.password : decrypt(password),
Cookies.set("username", this.loginForm.username, { expires: 30 }); rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 }); };
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 }); },
} else { handleLogin() {
Cookies.remove("username"); this.$refs.loginForm.validate(valid => {
Cookies.remove("password"); if (valid) {
Cookies.remove('rememberMe'); this.loading = true;
} if (this.loginForm.rememberMe) {
this.$store.dispatch("Login", this.loginForm).then(() => { Cookies.set("username", this.loginForm.username, { expires: 30 });
this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
}).catch(() => { Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
this.loading = false; } else {
if (this.captchaOnOff) { Cookies.remove("username");
this.getCode(); Cookies.remove("password");
} Cookies.remove('rememberMe');
}); }
} this.$store.dispatch("Login", this.loginForm).then(() => {
}); this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
} }).catch(() => {
} this.loading = false;
}; if (this.captchaOnOff) {
</script> this.getCode();
}
<style rel="stylesheet/scss" lang="scss"> });
.login { }
display: flex; });
justify-content: center; }
align-items: center; }
height: 100%; };
background-image: url("../assets/images/login-background.jpg"); </script>
background-size: cover;
} <style rel="stylesheet/scss" lang="scss">
.title { .login {
margin: 0px auto 30px auto; display: flex;
text-align: center; justify-content: center;
color: #707070; align-items: center;
} height: 100%;
background-image: url("../assets/images/login-background.jpg");
.login-form { background-size: cover;
border-radius: 6px; }
background: #ffffff; .title {
width: 400px; margin: 0px auto 30px auto;
padding: 25px 25px 5px 25px; text-align: center;
.el-input { color: #707070;
height: 38px; }
input {
height: 38px; .login-form {
} border-radius: 6px;
} background: #ffffff;
.input-icon { width: 400px;
height: 39px; padding: 25px 25px 5px 25px;
width: 14px; .el-input {
margin-left: 2px; height: 38px;
} input {
} height: 38px;
.login-tip { }
font-size: 13px; }
text-align: center; .input-icon {
color: #bfbfbf; height: 39px;
} width: 14px;
.login-code { margin-left: 2px;
width: 33%; }
height: 38px; }
float: right; .login-tip {
img { font-size: 13px;
cursor: pointer; text-align: center;
vertical-align: middle; color: #bfbfbf;
} }
} .login-code {
.el-login-footer { width: 33%;
height: 40px; height: 38px;
line-height: 40px; float: right;
position: fixed; img {
bottom: 0; cursor: pointer;
width: 100%; vertical-align: middle;
text-align: center; }
color: #fff; }
font-family: Arial; .el-login-footer {
font-size: 12px; height: 40px;
letter-spacing: 1px; line-height: 40px;
} position: fixed;
.login-code-img { bottom: 0;
height: 38px; width: 100%;
} text-align: center;
</style> color: #fff;
font-family: Arial;
font-size: 12px;
letter-spacing: 1px;
}
.login-code-img {
height: 38px;
}
</style>