Merge branch 'lzwdev' into feature-20240104
commit
59b5348afa
@ -1,56 +1,58 @@
|
|||||||
import router from './router'
|
import router from "./router";
|
||||||
import store from './store'
|
import store from "./store";
|
||||||
import { Message } from 'element-ui'
|
import { Message } from "element-ui";
|
||||||
import NProgress from 'nprogress'
|
import NProgress from "nprogress";
|
||||||
import 'nprogress/nprogress.css'
|
import "nprogress/nprogress.css";
|
||||||
import { getToken } from '@/utils/auth'
|
import { getToken } from "@/utils/auth";
|
||||||
import { isRelogin } from '@/utils/request'
|
import { isRelogin } from "@/utils/request";
|
||||||
|
|
||||||
NProgress.configure({ showSpinner: false })
|
NProgress.configure({ showSpinner: false });
|
||||||
|
|
||||||
const whiteList = ['/login', '/register']
|
const whiteList = ["/login", "/register"];
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
NProgress.start()
|
NProgress.start();
|
||||||
if (getToken()) {
|
if (getToken()) {
|
||||||
to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
|
to.meta.title && store.dispatch("settings/setTitle", to.meta.title);
|
||||||
/* has token*/
|
/* has token*/
|
||||||
if (to.path === '/login') {
|
if (to.path === "/login") {
|
||||||
next({ path: '/' })
|
next({ path: "/" });
|
||||||
NProgress.done()
|
NProgress.done();
|
||||||
} else {
|
} else {
|
||||||
if (store.getters.roles.length === 0) {
|
if (store.getters.roles.length === 0) {
|
||||||
isRelogin.show = true
|
isRelogin.show = true;
|
||||||
// 判断当前用户是否已拉取完user_info信息
|
// 判断当前用户是否已拉取完user_info信息
|
||||||
store.dispatch('GetInfo').then(() => {
|
store
|
||||||
isRelogin.show = false
|
.dispatch("GetInfo")
|
||||||
store.dispatch('GenerateRoutes').then(accessRoutes => {
|
.then(() => {
|
||||||
// 根据roles权限生成可访问的路由表
|
isRelogin.show = false;
|
||||||
router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
store.dispatch("GenerateRoutes").then((accessRoutes) => {
|
||||||
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
|
// 根据roles权限生成可访问的路由表
|
||||||
})
|
router.addRoutes(accessRoutes); // 动态添加可访问路由表
|
||||||
}).catch(err => {
|
next({ ...to, replace: true }); // hack方法 确保addRoutes已完成
|
||||||
store.dispatch('LogOut').then(() => {
|
});
|
||||||
Message.error(err)
|
|
||||||
next({ path: '/' })
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
store.dispatch("LogOut").then(() => {
|
||||||
|
Message.error(err);
|
||||||
|
next({ path: "/" });
|
||||||
|
});
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
next()
|
next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 没有token
|
|
||||||
if (whiteList.indexOf(to.path) !== -1) {
|
if (whiteList.indexOf(to.path) !== -1) {
|
||||||
// 在免登录白名单,直接进入
|
// 在免登录白名单,直接进入
|
||||||
next()
|
next();
|
||||||
} else {
|
} else {
|
||||||
next(`/login?redirect=${encodeURIComponent(to.fullPath)}`) // 否则全部重定向到登录页
|
next(`/login?redirect=${encodeURIComponent(to.fullPath)}`); // 否则全部重定向到登录页
|
||||||
NProgress.done()
|
NProgress.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
router.afterEach(() => {
|
router.afterEach(() => {
|
||||||
NProgress.done()
|
NProgress.done();
|
||||||
})
|
});
|
||||||
|
|||||||
@ -1,219 +1,251 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="login">
|
<div class="login">
|
||||||
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
|
<el-form
|
||||||
<h3 class="title">花至后台管理系统</h3>
|
ref="loginForm"
|
||||||
<el-form-item prop="username">
|
:model="loginForm"
|
||||||
<el-input
|
:rules="loginRules"
|
||||||
v-model="loginForm.username"
|
class="login-form"
|
||||||
type="text"
|
>
|
||||||
auto-complete="off"
|
<h3 class="title">花至后台管理系统</h3>
|
||||||
placeholder="账号"
|
<el-form-item prop="username">
|
||||||
>
|
<el-input
|
||||||
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
|
v-model="loginForm.username"
|
||||||
</el-input>
|
type="text"
|
||||||
</el-form-item>
|
auto-complete="off"
|
||||||
<el-form-item prop="password">
|
placeholder="账号"
|
||||||
<el-input
|
>
|
||||||
v-model="loginForm.password"
|
<svg-icon
|
||||||
type="password"
|
slot="prefix"
|
||||||
auto-complete="off"
|
icon-class="user"
|
||||||
placeholder="密码"
|
class="el-input__icon input-icon"
|
||||||
@keyup.enter.native="handleLogin"
|
/>
|
||||||
>
|
</el-input>
|
||||||
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
</el-form-item>
|
||||||
</el-input>
|
<el-form-item prop="password">
|
||||||
</el-form-item>
|
<el-input
|
||||||
<el-form-item prop="code" v-if="captchaEnabled">
|
v-model="loginForm.password"
|
||||||
<el-input
|
type="password"
|
||||||
v-model="loginForm.code"
|
auto-complete="off"
|
||||||
auto-complete="off"
|
placeholder="密码"
|
||||||
placeholder="验证码"
|
@keyup.enter.native="handleLogin"
|
||||||
style="width: 63%"
|
>
|
||||||
@keyup.enter.native="handleLogin"
|
<svg-icon
|
||||||
>
|
slot="prefix"
|
||||||
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
|
icon-class="password"
|
||||||
</el-input>
|
class="el-input__icon input-icon"
|
||||||
<div class="login-code">
|
/>
|
||||||
<img :src="codeUrl" @click="getCode" class="login-code-img"/>
|
</el-input>
|
||||||
</div>
|
</el-form-item>
|
||||||
</el-form-item>
|
<el-form-item prop="code" v-if="captchaEnabled">
|
||||||
<el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
|
<el-input
|
||||||
<el-form-item style="width:100%;">
|
v-model="loginForm.code"
|
||||||
<el-button
|
auto-complete="off"
|
||||||
:loading="loading"
|
placeholder="验证码"
|
||||||
size="medium"
|
style="width: 63%"
|
||||||
type="primary"
|
@keyup.enter.native="handleLogin"
|
||||||
style="width:100%;"
|
>
|
||||||
@click.native.prevent="handleLogin"
|
<svg-icon
|
||||||
>
|
slot="prefix"
|
||||||
<span v-if="!loading">登 录</span>
|
icon-class="validCode"
|
||||||
<span v-else>登 录 中...</span>
|
class="el-input__icon input-icon"
|
||||||
</el-button>
|
/>
|
||||||
<div style="float: right;" v-if="register">
|
</el-input>
|
||||||
<router-link class="link-type" :to="'/register'">立即注册</router-link>
|
<div class="login-code">
|
||||||
</div>
|
<img :src="codeUrl" @click="getCode" class="login-code-img" />
|
||||||
</el-form-item>
|
</div>
|
||||||
</el-form>
|
</el-form-item>
|
||||||
<!-- 底部 -->
|
<el-checkbox
|
||||||
<div class="el-login-footer">
|
v-model="loginForm.rememberMe"
|
||||||
<span>Copyright © 2018-2023 ruoyi.vip All Rights Reserved.</span>
|
style="margin: 0px 0px 25px 0px"
|
||||||
</div>
|
>记住密码</el-checkbox
|
||||||
</div>
|
>
|
||||||
|
<el-form-item style="width: 100%">
|
||||||
|
<el-button
|
||||||
|
:loading="loading"
|
||||||
|
size="medium"
|
||||||
|
type="primary"
|
||||||
|
style="width: 100%"
|
||||||
|
@click.native.prevent="handleLogin"
|
||||||
|
>
|
||||||
|
<span v-if="!loading">登 录</span>
|
||||||
|
<span v-else>登 录 中...</span>
|
||||||
|
</el-button>
|
||||||
|
<div style="float: right" v-if="register">
|
||||||
|
<router-link class="link-type" :to="'/register'"
|
||||||
|
>立即注册</router-link
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<!-- 底部 -->
|
||||||
|
<div class="el-login-footer">
|
||||||
|
<span>Copyright © 2018-2023 ruoyi.vip All Rights Reserved.</span>
|
||||||
|
</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'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Login",
|
name: 'Login',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
codeUrl: "",
|
codeUrl: '',
|
||||||
loginForm: {
|
loginForm: {
|
||||||
username: "admin",
|
username: 'admin',
|
||||||
password: "admin123",
|
password: 'admin123',
|
||||||
rememberMe: false,
|
rememberMe: false,
|
||||||
code: "",
|
code: '',
|
||||||
uuid: ""
|
uuid: '',
|
||||||
},
|
},
|
||||||
loginRules: {
|
loginRules: {
|
||||||
username: [
|
username: [
|
||||||
{ required: true, trigger: "blur", message: "请输入您的账号" }
|
{ required: true, trigger: 'blur', message: '请输入您的账号' },
|
||||||
],
|
],
|
||||||
password: [
|
password: [
|
||||||
{ required: true, trigger: "blur", message: "请输入您的密码" }
|
{ required: true, trigger: 'blur', message: '请输入您的密码' },
|
||||||
],
|
],
|
||||||
code: [{ required: true, trigger: "change", message: "请输入验证码" }]
|
code: [{ required: true, trigger: 'change', message: '请输入验证码' }],
|
||||||
},
|
},
|
||||||
loading: false,
|
loading: false,
|
||||||
// 验证码开关
|
// 验证码开关
|
||||||
captchaEnabled: true,
|
captchaEnabled: true,
|
||||||
// 注册开关
|
// 注册开关
|
||||||
register: false,
|
register: false,
|
||||||
redirect: undefined
|
redirect: undefined,
|
||||||
};
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
$route: {
|
$route: {
|
||||||
handler: function(route) {
|
handler: function (route) {
|
||||||
this.redirect = route.query && route.query.redirect;
|
this.redirect = route.query && route.query.redirect
|
||||||
},
|
},
|
||||||
immediate: true
|
immediate: true,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.getCode();
|
this.getCode()
|
||||||
this.getCookie();
|
this.getCookie()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getCode() {
|
getCode() {
|
||||||
getCodeImg().then(res => {
|
getCodeImg().then((res) => {
|
||||||
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
this.captchaEnabled =
|
||||||
if (this.captchaEnabled) {
|
res.captchaEnabled === undefined ? true : res.captchaEnabled
|
||||||
this.codeUrl = "data:image/gif;base64," + res.img;
|
if (this.captchaEnabled) {
|
||||||
this.loginForm.uuid = res.uuid;
|
this.codeUrl = 'data:image/gif;base64,' + res.img
|
||||||
}
|
this.loginForm.uuid = res.uuid
|
||||||
});
|
}
|
||||||
},
|
})
|
||||||
getCookie() {
|
},
|
||||||
const username = Cookies.get("username");
|
getCookie() {
|
||||||
const password = Cookies.get("password");
|
const username = Cookies.get('username')
|
||||||
const rememberMe = Cookies.get('rememberMe')
|
const password = Cookies.get('password')
|
||||||
this.loginForm = {
|
const rememberMe = Cookies.get('rememberMe')
|
||||||
username: username === undefined ? this.loginForm.username : username,
|
this.loginForm = {
|
||||||
password: password === undefined ? this.loginForm.password : decrypt(password),
|
username: username === undefined ? this.loginForm.username : username,
|
||||||
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
password:
|
||||||
};
|
password === undefined ? this.loginForm.password : decrypt(password),
|
||||||
},
|
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
||||||
handleLogin() {
|
}
|
||||||
this.$refs.loginForm.validate(valid => {
|
},
|
||||||
if (valid) {
|
handleLogin() {
|
||||||
this.loading = true;
|
this.$refs.loginForm.validate((valid) => {
|
||||||
if (this.loginForm.rememberMe) {
|
if (valid) {
|
||||||
Cookies.set("username", this.loginForm.username, { expires: 30 });
|
this.loading = true
|
||||||
Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
|
if (this.loginForm.rememberMe) {
|
||||||
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
|
Cookies.set('username', this.loginForm.username, { expires: 30 })
|
||||||
} else {
|
Cookies.set('password', encrypt(this.loginForm.password), {
|
||||||
Cookies.remove("username");
|
expires: 30,
|
||||||
Cookies.remove("password");
|
})
|
||||||
Cookies.remove('rememberMe');
|
Cookies.set('rememberMe', this.loginForm.rememberMe, {
|
||||||
}
|
expires: 30,
|
||||||
this.$store.dispatch("Login", this.loginForm).then(() => {
|
})
|
||||||
this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
} else {
|
||||||
}).catch(() => {
|
Cookies.remove('username')
|
||||||
this.loading = false;
|
Cookies.remove('password')
|
||||||
if (this.captchaEnabled) {
|
Cookies.remove('rememberMe')
|
||||||
this.getCode();
|
}
|
||||||
}
|
this.$store
|
||||||
});
|
.dispatch('Login', this.loginForm)
|
||||||
}
|
.then(() => {
|
||||||
});
|
this.$router.push({ path: this.redirect || '/' }).catch(() => {})
|
||||||
}
|
})
|
||||||
}
|
.catch(() => {
|
||||||
};
|
this.loading = false
|
||||||
|
if (this.captchaEnabled) {
|
||||||
|
this.getCode()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style rel="stylesheet/scss" lang="scss">
|
<style rel="stylesheet/scss" lang="scss">
|
||||||
.login {
|
.login {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-image: url("../assets/images/login-background.jpg");
|
background-image: url('../assets/images/login-background.jpg');
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
}
|
}
|
||||||
.title {
|
.title {
|
||||||
margin: 0px auto 30px auto;
|
margin: 0px auto 30px auto;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #707070;
|
color: #707070;
|
||||||
}
|
}
|
||||||
|
|
||||||
.login-form {
|
.login-form {
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
width: 400px;
|
width: 400px;
|
||||||
padding: 25px 25px 5px 25px;
|
padding: 25px 25px 5px 25px;
|
||||||
.el-input {
|
.el-input {
|
||||||
height: 38px;
|
height: 38px;
|
||||||
input {
|
input {
|
||||||
height: 38px;
|
height: 38px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.input-icon {
|
.input-icon {
|
||||||
height: 39px;
|
height: 39px;
|
||||||
width: 14px;
|
width: 14px;
|
||||||
margin-left: 2px;
|
margin-left: 2px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.login-tip {
|
.login-tip {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #bfbfbf;
|
color: #bfbfbf;
|
||||||
}
|
}
|
||||||
.login-code {
|
.login-code {
|
||||||
width: 33%;
|
width: 33%;
|
||||||
height: 38px;
|
height: 38px;
|
||||||
float: right;
|
float: right;
|
||||||
img {
|
img {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.el-login-footer {
|
.el-login-footer {
|
||||||
height: 40px;
|
height: 40px;
|
||||||
line-height: 40px;
|
line-height: 40px;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-family: Arial;
|
font-family: Arial;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
letter-spacing: 1px;
|
letter-spacing: 1px;
|
||||||
}
|
}
|
||||||
.login-code-img {
|
.login-code-img {
|
||||||
height: 38px;
|
height: 38px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue