| | |
| | | <template> |
| | | <div class="login"> |
| | | <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> |
| | | <h3 class="title">若依后台管理系统</h3> |
| | | <el-form-item prop="username"> |
| | | <el-input |
| | | v-model="loginForm.username" |
| | | type="text" |
| | | auto-complete="off" |
| | | placeholder="账号" |
| | | > |
| | | <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" /> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item prop="password"> |
| | | <el-input |
| | | v-model="loginForm.password" |
| | | type="password" |
| | | auto-complete="off" |
| | | placeholder="密码" |
| | | @keyup.enter.native="handleLogin" |
| | | > |
| | | <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item prop="code" v-if="captchaEnabled"> |
| | | <el-input |
| | | v-model="loginForm.code" |
| | | auto-complete="off" |
| | | placeholder="验证码" |
| | | style="width: 63%" |
| | | @keyup.enter.native="handleLogin" |
| | | > |
| | | <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" /> |
| | | </el-input> |
| | | <div class="login-code"> |
| | | <img :src="codeUrl" @click="getCode" class="login-code-img"/> |
| | | <div class="login-container"> |
| | | <div class="login-wrapper"> |
| | | <div class="info-wrapper enter-x"> |
| | | <div class="title-wrapper"> |
| | | <div class="logo"> |
| | | <img src="../assets/icons/logo.png" alt=""> |
| | | </div> |
| | | <p class="title">运维考核平台</p> |
| | | </div> |
| | | <div class="logo-wrapper"> |
| | | <img src="../assets/svg/login-box-bg.svg" alt=""> |
| | | </div> |
| | | </div> |
| | | </el-form-item> |
| | | <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox> |
| | | <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 class="form-wrapper"> |
| | | <h1 class="title">登录</h1> |
| | | <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> |
| | | <el-form-item prop="username"> |
| | | <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号"> |
| | | <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" /> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item prop="password"> |
| | | <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码" |
| | | @keyup.enter.native="handleLogin"> |
| | | <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item prop="code" v-if="captchaEnabled"> |
| | | <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" |
| | | @keyup.enter.native="handleLogin"> |
| | | <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" /> |
| | | </el-input> |
| | | <div class="login-code"> |
| | | <img :src="codeUrl" @click="getCode" class="login-code-img" /> |
| | | </div> |
| | | </el-form-item> |
| | | <el-checkbox v-model="loginForm.rememberMe" style=" margin:0px 0px 25px 0px;">记住密码</el-checkbox> |
| | | <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> |
| | | </el-form-item> |
| | | </el-form> |
| | | <!-- 底部 --> |
| | | <div class="el-login-footer"> |
| | | <span>Copyright © 2018-2023 ruoyi.vip All Rights Reserved.</span> |
| | | <el-dialog title="为了您的账号安全,首次登陆请修改密码" :visible.sync="loginInfo.firstLogin == 0"> |
| | | <el-form> |
| | | <el-form-item label="新密码"> |
| | | <el-input v-model="newPassword" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="请确认密码"> |
| | | <el-input v-model="confirmPassword" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | </el-form> |
| | | <div slot="footer" class="dialog-footer"> |
| | | <el-button type="primary" @click="updatePwd">确 定</el-button> |
| | | </div> |
| | | </el-dialog> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | |
| | | |
| | | </template> |
| | | |
| | | <script> |
| | | import { getCodeImg } from "@/api/login"; |
| | | import { getCodeImg, getInfo } from "@/api/login"; |
| | | import Cookies from "js-cookie"; |
| | | import { encrypt, decrypt } from '@/utils/jsencrypt' |
| | | import { updateUserPwd } from "@/api/system/user"; |
| | | |
| | | export default { |
| | | //新增对象、变量 |
| | | name: "Login", |
| | | data() { |
| | | const equalToPassword = (rule, value, callback) => { |
| | | if (this.newPassword !== value) { |
| | | callback(new Error("两次输入的密码不一致")); |
| | | } else { |
| | | callback(); |
| | | } |
| | | }; |
| | | const validatePassword = (rule, value, callback) => { |
| | | var regex = /(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[\W_])/; |
| | | if (value.length < 8 || value.length > 10) { |
| | | callback(new Error('请输入8-10位大写字母+小写字母+数字+特殊字符')); |
| | | } |
| | | else if (!regex.test(value)) { |
| | | callback(new Error("请输入8-10位大写字母+小写字母+数字+特殊字符")); |
| | | } else { |
| | | callback(); |
| | | } |
| | | }; |
| | | return { |
| | | codeUrl: "", |
| | | loginForm: { |
| | | username: "admin", |
| | | password: "admin123", |
| | | username: "", |
| | | password: "", |
| | | rememberMe: false, |
| | | code: "", |
| | | uuid: "" |
| | | }, |
| | | loginInfo: { |
| | | firstLogin: 1 |
| | | }, |
| | | newPassword: undefined, |
| | | confirmPassword: undefined, |
| | | loginRules: { |
| | | username: [ |
| | | { required: true, trigger: "blur", message: "请输入您的账号" } |
| | |
| | | { required: true, trigger: "blur", message: "请输入您的密码" } |
| | | ], |
| | | code: [{ required: true, trigger: "change", message: "请输入验证码" }] |
| | | }, |
| | | rules: { |
| | | newPassword: [ |
| | | { required: true, message: "新密码不能为空", trigger: "blur" }, |
| | | { required: true, validator: validatePassword, trigger: "blur" } |
| | | ], |
| | | confirmPassword: [ |
| | | { required: true, message: "确认密码不能为空", trigger: "blur" }, |
| | | { required: true, validator: equalToPassword, trigger: "blur" } |
| | | ] |
| | | }, |
| | | loading: false, |
| | | // 验证码开关 |
| | |
| | | }, |
| | | watch: { |
| | | $route: { |
| | | handler: function(route) { |
| | | handler: function (route) { |
| | | console.log(route); |
| | | this.redirect = route.query && route.query.redirect; |
| | | }, |
| | | immediate: true |
| | |
| | | this.$refs.loginForm.validate(valid => { |
| | | if (valid) { |
| | | 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.remove("password"); |
| | | Cookies.remove('rememberMe'); |
| | | } |
| | | this.$store.dispatch("Login", this.loginForm).then(() => { |
| | | this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); |
| | | |
| | | this.$store.dispatch("Login", this.loginForm).then((res) => { |
| | | getInfo().then(loginInfo => { |
| | | this.loginInfo = loginInfo.user |
| | | //如果返回为1正常跳转 |
| | | if (this.loginInfo.firstLogin == 1) { |
| | | // this.$router.push({ path: "/" }).catch(() => { }); |
| | | // return; |
| | | this.$router.push({ path: this.redirect || "/screen" }).catch(() => { }); |
| | | } else { |
| | | localStorage.setItem('firstLogin', 0) |
| | | } |
| | | }).catch(() => { }) |
| | | }).catch(() => { |
| | | this.loading = false; |
| | | if (this.captchaEnabled) { |
| | |
| | | }); |
| | | } |
| | | }); |
| | | }, |
| | | // 新增修改方法 |
| | | updatePwd() { |
| | | updateUserPwd("", this.newPassword, 0).then(response => { |
| | | // 修改完成将firstLogin改为1 |
| | | localStorage.setItem('firstLogin', 1) |
| | | this.$modal.msgSuccess("修改成功"); |
| | | this.$router.push({ path: this.redirect || "/" }).catch(() => { }); |
| | | }).catch((e) => { |
| | | console.info(e) |
| | | }); |
| | | } |
| | | } |
| | | }; |
| | | </script> |
| | | |
| | | <style rel="stylesheet/scss" lang="scss"> |
| | | <style rel="stylesheet/scss" lang="scss" scoped> |
| | | $light_gray: #eee; |
| | | |
| | | .login { |
| | | width: 100%; |
| | | height: 100%; |
| | | display: flex; |
| | | justify-content: center; |
| | | align-items: center; |
| | | height: 100%; |
| | | background-image: url("../assets/images/login-background.jpg"); |
| | | background-size: cover; |
| | | // background-image: url("../assets/images/login-background.jpg"); |
| | | // background-size: cover; |
| | | |
| | | &::before { |
| | | content: ''; |
| | | position: absolute; |
| | | top: 0; |
| | | left: 0; |
| | | width: 100%; |
| | | height: 100%; |
| | | margin-left: -48%; |
| | | background-image: url('../assets/svg/login-bg.svg'); |
| | | background-repeat: no-repeat; |
| | | background-position: 100%; |
| | | background-size: auto 100%; |
| | | } |
| | | } |
| | | .title { |
| | | margin: 0px auto 30px auto; |
| | | text-align: center; |
| | | color: #707070; |
| | | |
| | | .login-container { |
| | | margin: 0 auto; |
| | | width: 100%; |
| | | height: 100%; |
| | | box-sizing: border-box; |
| | | position: relative; |
| | | z-index: 2; |
| | | padding: 0 20px; |
| | | } |
| | | |
| | | .login-wrapper { |
| | | display: flex; |
| | | height: 100%; |
| | | } |
| | | |
| | | .info-wrapper { |
| | | width: 50%; |
| | | height: 100%; |
| | | display: flex; |
| | | flex-direction: column; |
| | | justify-content: center; |
| | | position: relative; |
| | | |
| | | .logo-wrapper { |
| | | transform: translateX(-80px); |
| | | opacity: 0; |
| | | animation: enter-x 0.3s ease forwards; |
| | | |
| | | img { |
| | | width: 50%; |
| | | } |
| | | } |
| | | |
| | | .title-wrapper { |
| | | transform: translateX(-80px); |
| | | opacity: 0; |
| | | animation: enter-x 0.3s ease forwards; |
| | | animation-delay: 0.1s; |
| | | display: flex; |
| | | align-items: center; |
| | | margin-bottom: 50px; |
| | | |
| | | .title { |
| | | text-align: left; |
| | | font-size: 30px; |
| | | color: #fff; |
| | | margin-left: 10px; |
| | | } |
| | | } |
| | | } |
| | | |
| | | .form-wrapper { |
| | | width: 50%; |
| | | height: 100%; |
| | | display: flex; |
| | | flex-direction: column; |
| | | justify-content: center; |
| | | align-items: center; |
| | | |
| | | .title { |
| | | transform: translateX(80px); |
| | | opacity: 0; |
| | | animation: enter-x 0.3s ease forwards; |
| | | } |
| | | |
| | | .login-form { |
| | | transform: translateX(80px); |
| | | opacity: 0; |
| | | animation: enter-x 0.3s ease forwards; |
| | | animation-delay: 0.1s; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | .login-form { |
| | | border-radius: 6px; |
| | | background: #ffffff; |
| | | width: 400px; |
| | | padding: 25px 25px 5px 25px; |
| | | |
| | | .el-input { |
| | | height: 38px; |
| | | |
| | | input { |
| | | height: 38px; |
| | | } |
| | | } |
| | | |
| | | .input-icon { |
| | | height: 39px; |
| | | width: 14px; |
| | | margin-left: 2px; |
| | | } |
| | | } |
| | | |
| | | .login-tip { |
| | | font-size: 13px; |
| | | text-align: center; |
| | | color: #bfbfbf; |
| | | } |
| | | |
| | | .login-code { |
| | | width: 33%; |
| | | height: 38px; |
| | | float: right; |
| | | |
| | | img { |
| | | cursor: pointer; |
| | | vertical-align: middle; |
| | | } |
| | | } |
| | | |
| | | .el-login-footer { |
| | | height: 40px; |
| | | line-height: 40px; |
| | |
| | | font-size: 12px; |
| | | letter-spacing: 1px; |
| | | } |
| | | |
| | | .login-code-img { |
| | | height: 38px; |
| | | } |
| | | |
| | | .title-container { |
| | | position: absolute; |
| | | transform: translateY(-400%); |
| | | left: 35%; |
| | | |
| | | .title { |
| | | font-size: 40px; |
| | | color: $light_gray; |
| | | margin: 0px auto 20px auto; |
| | | text-align: center; |
| | | font-weight: bold; |
| | | letter-spacing: 20px; |
| | | } |
| | | } |
| | | |
| | | @media (min-width: 640px) { |
| | | .login-container { |
| | | max-width: 640px; |
| | | } |
| | | } |
| | | |
| | | @media (min-width: 768px) { |
| | | .login-container { |
| | | max-width: 768px; |
| | | } |
| | | } |
| | | |
| | | |
| | | @media (min-width: 1024px) { |
| | | .login-container { |
| | | max-width: 1024px; |
| | | } |
| | | } |
| | | |
| | | @media (min-width: 1280px) { |
| | | .login-container { |
| | | max-width: 1280px; |
| | | } |
| | | } |
| | | |
| | | @media (min-width: 1536px) { |
| | | .login-container { |
| | | max-width: 1536px; |
| | | } |
| | | } |
| | | |
| | | @keyframes enter-x { |
| | | 100% { |
| | | opacity: 1; |
| | | transform: translateX(0); |
| | | } |
| | | } |
| | | </style> |