| | |
| | | <template>
|
| | | <div class="login">
|
| | | <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
|
| | | <h3 class="title">若依后台管理系统</h3>
|
| | | <h3 class="title">{{title}}</h3>
|
| | | <el-form-item prop="username">
|
| | | <el-input
|
| | | v-model="loginForm.username"
|
| | |
| | | </el-form>
|
| | | <!-- 底部 -->
|
| | | <div class="el-login-footer">
|
| | | <span>Copyright © 2018-2022 ruoyi.vip All Rights Reserved.</span>
|
| | | <span>Copyright © 2018-2025 ruoyi.vip All Rights Reserved.</span>
|
| | | </div>
|
| | | </div>
|
| | | </template>
|
| | |
|
| | | <script>
|
| | | import { getCodeImg } from "@/api/login";
|
| | | import Cookies from "js-cookie";
|
| | | import { getCodeImg } from "@/api/login"
|
| | | import Cookies from "js-cookie"
|
| | | import { encrypt, decrypt } from '@/utils/jsencrypt'
|
| | |
|
| | | export default {
|
| | | name: "Login",
|
| | | data() {
|
| | | return {
|
| | | title: process.env.VUE_APP_TITLE,
|
| | | codeUrl: "",
|
| | | loginForm: {
|
| | | username: "admin",
|
| | |
| | | // 注册开关
|
| | | register: false,
|
| | | redirect: undefined
|
| | | };
|
| | | }
|
| | | },
|
| | | watch: {
|
| | | $route: {
|
| | | handler: function(route) {
|
| | | this.redirect = route.query && route.query.redirect;
|
| | | this.redirect = route.query && route.query.redirect
|
| | | },
|
| | | immediate: true
|
| | | }
|
| | | },
|
| | | created() {
|
| | | this.getCode();
|
| | | this.getCookie();
|
| | | this.getCode()
|
| | | this.getCookie()
|
| | | },
|
| | | methods: {
|
| | | getCode() {
|
| | | getCodeImg().then(res => {
|
| | | this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
| | | this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
|
| | | if (this.captchaEnabled) {
|
| | | this.codeUrl = "data:image/gif;base64," + res.img;
|
| | | this.loginForm.uuid = res.uuid;
|
| | | this.codeUrl = "data:image/gif;base64," + res.img
|
| | | this.loginForm.uuid = res.uuid
|
| | | }
|
| | | });
|
| | | })
|
| | | },
|
| | | getCookie() {
|
| | | const username = Cookies.get("username");
|
| | | const password = Cookies.get("password");
|
| | | const username = Cookies.get("username")
|
| | | const password = Cookies.get("password")
|
| | | const rememberMe = Cookies.get('rememberMe')
|
| | | this.loginForm = {
|
| | | username: username === undefined ? this.loginForm.username : username,
|
| | | password: password === undefined ? this.loginForm.password : decrypt(password),
|
| | | rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
| | | };
|
| | | }
|
| | | },
|
| | | handleLogin() {
|
| | | this.$refs.loginForm.validate(valid => {
|
| | | if (valid) {
|
| | | this.loading = true;
|
| | | this.loading = true
|
| | | if (this.loginForm.rememberMe) {
|
| | | Cookies.set("username", this.loginForm.username, { expires: 30 });
|
| | | Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
|
| | | Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
|
| | | Cookies.set("username", this.loginForm.username, { expires: 30 })
|
| | | Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 })
|
| | | Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 })
|
| | | } else {
|
| | | Cookies.remove("username");
|
| | | Cookies.remove("password");
|
| | | Cookies.remove('rememberMe');
|
| | | Cookies.remove("username")
|
| | | Cookies.remove("password")
|
| | | Cookies.remove('rememberMe')
|
| | | }
|
| | | this.$store.dispatch("Login", this.loginForm).then(() => {
|
| | | this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
| | | this.$router.push({ path: this.redirect || "/" }).catch(()=>{})
|
| | | }).catch(() => {
|
| | | this.loading = false;
|
| | | this.loading = false
|
| | | if (this.captchaEnabled) {
|
| | | this.getCode();
|
| | | this.getCode()
|
| | | }
|
| | | });
|
| | | })
|
| | | }
|
| | | });
|
| | | })
|
| | | }
|
| | | }
|
| | | };
|
| | | }
|
| | | </script>
|
| | |
|
| | | <style rel="stylesheet/scss" lang="scss">
|
| | |
| | | background: #ffffff;
|
| | | width: 400px;
|
| | | padding: 25px 25px 5px 25px;
|
| | | z-index: 1;
|
| | | .el-input {
|
| | | height: 38px;
|
| | | input {
|