2023-11-28 20:33:38 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="login">
|
2023-12-12 13:36:08 +08:00
|
|
|
<div class="login-bar">
|
|
|
|
|
<div class="form-bar">
|
|
|
|
|
<h3 class="title">智慧仓储管理平台</h3>
|
|
|
|
|
<el-tabs v-model="activeName" style="width: 82%;margin: 0 auto">
|
|
|
|
|
<el-tab-pane label="账号登录" name="account"></el-tab-pane>
|
|
|
|
|
<el-tab-pane label="手机登录" name="phone"></el-tab-pane>
|
|
|
|
|
</el-tabs>
|
|
|
|
|
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
|
|
|
|
|
<el-form-item prop="username" v-if="activeName=='account'">
|
|
|
|
|
<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>
|
2024-01-10 16:29:46 +08:00
|
|
|
<el-form-item prop="password" v-if="activeName=='account'">
|
2023-12-12 13:36:08 +08:00
|
|
|
<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>
|
2024-01-10 16:29:46 +08:00
|
|
|
<el-form-item prop="code" v-if="captchaEnabled && activeName=='account'">
|
2023-12-12 13:36:08 +08:00
|
|
|
<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>
|
2024-01-10 16:29:46 +08:00
|
|
|
<el-form-item style="width:100%;" v-if="activeName=='account'">
|
2023-12-12 13:36:08 +08:00
|
|
|
<el-button
|
|
|
|
|
:loading="loading"
|
|
|
|
|
size="medium"
|
|
|
|
|
type="primary"
|
|
|
|
|
style="width:100%;"
|
2024-01-10 16:29:46 +08:00
|
|
|
|
2023-12-12 13:36:08 +08:00
|
|
|
@click.native.prevent="handleLogin"
|
|
|
|
|
>
|
|
|
|
|
<span v-if="!loading">登 录</span>
|
|
|
|
|
<span v-else>登 录 中...</span>
|
|
|
|
|
</el-button>
|
|
|
|
|
<div style="float: right;" v-if="register">
|
2024-01-10 16:29:46 +08:00
|
|
|
<!-- <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>-->
|
2023-12-12 13:36:08 +08:00
|
|
|
<router-link class="link-type" :to="'/register'">立即注册</router-link>
|
|
|
|
|
</div>
|
|
|
|
|
</el-form-item>
|
2024-01-10 16:29:46 +08:00
|
|
|
|
|
|
|
|
<el-form-item prop="phone" v-if="activeName=='phone'">
|
|
|
|
|
<el-input
|
|
|
|
|
v-model="loginForm.phone"
|
|
|
|
|
type="text"
|
|
|
|
|
:readonly="readonlyFlag"
|
|
|
|
|
@focus="handleInputClick"
|
|
|
|
|
auto-complete="off"
|
|
|
|
|
placeholder="手机号"
|
|
|
|
|
>
|
|
|
|
|
<svg-icon slot="prefix" icon-class="phone" class="el-input__icon input-icon"/>
|
|
|
|
|
</el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item prop="textCode" v-if="activeName=='phone'">
|
|
|
|
|
<el-input
|
|
|
|
|
v-model="loginForm.textCode"
|
|
|
|
|
auto-complete="off"
|
|
|
|
|
placeholder="验证码"
|
|
|
|
|
style="width: 63%"
|
|
|
|
|
>
|
|
|
|
|
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon"/>
|
|
|
|
|
</el-input>
|
|
|
|
|
<div class="login-code">
|
|
|
|
|
<!-- <div class="login-code-img" style="border: 1px solid rgb(220, 223, 230);" @click="getTextCode">获取验证码</div> -->
|
|
|
|
|
<div class="login-code-img" style="border: 1px solid rgb(220, 223, 230);" v-show="show === 1" @click="getTextCode">获取验证码</div>
|
|
|
|
|
<div class="login-code-img" style="border: 1px solid rgb(220, 223, 230);" v-show="show === 2">{{ count }} s</div>
|
|
|
|
|
<div class="login-code-img" style="border: 1px solid rgb(220, 223, 230);" v-show="show === 3" @click="getTextCode">重发</div>
|
|
|
|
|
</div>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item style="width:100%;" v-if="activeName=='phone'">
|
|
|
|
|
<el-button
|
|
|
|
|
:loading="loading"
|
|
|
|
|
size="medium"
|
|
|
|
|
type="primary"
|
|
|
|
|
style="width:100%;"
|
|
|
|
|
@click.native.prevent="textLogin"
|
|
|
|
|
>
|
|
|
|
|
<span v-if="!loading">登 录</span>
|
|
|
|
|
<span v-else>登 录 中...</span>
|
|
|
|
|
</el-button>
|
|
|
|
|
<div style="float: right;" v-if="register">
|
|
|
|
|
<!-- <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>-->
|
|
|
|
|
<router-link class="link-type" :to="'/register'">立即注册</router-link>
|
|
|
|
|
</div>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-12 13:36:08 +08:00
|
|
|
</el-form>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2023-11-28 20:33:38 +08:00
|
|
|
<!-- 底部 -->
|
|
|
|
|
<div class="el-login-footer">
|
|
|
|
|
<span>Copyright © 2018-2023 ruoyi.vip All Rights Reserved.</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2024-01-10 16:29:46 +08:00
|
|
|
import {getCodeImg,sendCode} from "@/api/login";
|
2023-11-28 20:33:38 +08:00
|
|
|
import Cookies from "js-cookie";
|
2023-12-12 13:36:08 +08:00
|
|
|
import {encrypt, decrypt} from '@/utils/jsencrypt'
|
2023-11-28 20:33:38 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: "Login",
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
codeUrl: "",
|
|
|
|
|
loginForm: {
|
2024-01-10 16:29:46 +08:00
|
|
|
username: "",
|
|
|
|
|
password: "",
|
2023-12-12 13:36:08 +08:00
|
|
|
phone: '',
|
2023-11-28 20:33:38 +08:00
|
|
|
rememberMe: false,
|
|
|
|
|
code: "",
|
|
|
|
|
uuid: ""
|
|
|
|
|
},
|
|
|
|
|
loginRules: {
|
|
|
|
|
username: [
|
2023-12-12 13:36:08 +08:00
|
|
|
{required: true, trigger: "blur", message: "请输入您的账号"}
|
|
|
|
|
],
|
|
|
|
|
phone: [
|
|
|
|
|
{required: true, trigger: "blur", message: "请输入您的手机号"}
|
2023-11-28 20:33:38 +08:00
|
|
|
],
|
2024-01-10 16:29:46 +08:00
|
|
|
textCode: [
|
|
|
|
|
{required: true, trigger: "blur", message: "请输入短信验证码"}
|
|
|
|
|
],
|
2023-11-28 20:33:38 +08:00
|
|
|
password: [
|
2023-12-12 13:36:08 +08:00
|
|
|
{required: true, trigger: "blur", message: "请输入您的密码"}
|
2023-11-28 20:33:38 +08:00
|
|
|
],
|
2023-12-12 13:36:08 +08:00
|
|
|
code: [{required: true, trigger: "change", message: "请输入验证码"}]
|
2023-11-28 20:33:38 +08:00
|
|
|
},
|
|
|
|
|
loading: false,
|
|
|
|
|
// 验证码开关
|
|
|
|
|
captchaEnabled: true,
|
|
|
|
|
// 注册开关
|
|
|
|
|
register: false,
|
2023-12-12 13:36:08 +08:00
|
|
|
redirect: undefined,
|
|
|
|
|
activeName: 'account',
|
2024-01-10 16:29:46 +08:00
|
|
|
readonlyFlag: true,
|
|
|
|
|
show: 1,
|
|
|
|
|
count: '',
|
|
|
|
|
timer: null
|
2023-11-28 20:33:38 +08:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
$route: {
|
2023-12-12 13:36:08 +08:00
|
|
|
handler: function (route) {
|
2023-11-28 20:33:38 +08:00
|
|
|
this.redirect = route.query && route.query.redirect;
|
|
|
|
|
},
|
|
|
|
|
immediate: true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
this.getCode();
|
|
|
|
|
this.getCookie();
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
getCode() {
|
|
|
|
|
getCodeImg().then(res => {
|
|
|
|
|
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
|
|
|
|
if (this.captchaEnabled) {
|
|
|
|
|
this.codeUrl = "data:image/gif;base64," + res.img;
|
|
|
|
|
this.loginForm.uuid = res.uuid;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2024-01-10 16:29:46 +08:00
|
|
|
//防止手机号自动充填
|
|
|
|
|
handleInputClick(){
|
|
|
|
|
this.readonlyFlag = false
|
|
|
|
|
},
|
|
|
|
|
//获取短信验证码
|
|
|
|
|
getTextCode() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const regExp = /^1[3456789]\d{9}$/;
|
|
|
|
|
if (regExp.test(this.loginForm.phone)) {
|
|
|
|
|
console.log('手机号格式正确');
|
|
|
|
|
sendCode({phone:this.loginForm.phone}).then(res => {
|
|
|
|
|
if(res.code==200){
|
|
|
|
|
this.$modal.msgSuccess("发送成功");
|
|
|
|
|
const TIME_COUNT = 10
|
|
|
|
|
if (!this.timer) {
|
|
|
|
|
this.count = TIME_COUNT
|
|
|
|
|
this.show = 2
|
|
|
|
|
this.timer = setInterval(() => {
|
|
|
|
|
if (this.count > 0 && this.count <= TIME_COUNT) {
|
|
|
|
|
this.count--
|
|
|
|
|
} else {
|
|
|
|
|
this.show = 3
|
|
|
|
|
clearInterval(this.timer)
|
|
|
|
|
this.timer = null
|
|
|
|
|
}
|
|
|
|
|
}, 1000)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.$modal.msgError("手机号格式不正确");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
textLogin(){
|
|
|
|
|
// checkCode
|
|
|
|
|
console.log(this.loginForm)
|
|
|
|
|
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.set('rememberMe', this.loginForm.rememberMe, {expires: 30});
|
|
|
|
|
} else {
|
|
|
|
|
Cookies.remove("username");
|
|
|
|
|
Cookies.remove("password");
|
|
|
|
|
Cookies.remove('rememberMe');
|
|
|
|
|
}
|
|
|
|
|
console.log(this.loginForm)
|
|
|
|
|
this.$store.dispatch("textLogin", this.loginForm).then(() => {
|
|
|
|
|
this.$router.push({path: this.redirect || "/"}).catch(() => {
|
|
|
|
|
});
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
this.loading = false;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2023-11-28 20:33:38 +08:00
|
|
|
getCookie() {
|
|
|
|
|
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;
|
|
|
|
|
if (this.loginForm.rememberMe) {
|
2023-12-12 13:36:08 +08:00
|
|
|
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});
|
2023-11-28 20:33:38 +08:00
|
|
|
} else {
|
|
|
|
|
Cookies.remove("username");
|
|
|
|
|
Cookies.remove("password");
|
|
|
|
|
Cookies.remove('rememberMe');
|
|
|
|
|
}
|
|
|
|
|
this.$store.dispatch("Login", this.loginForm).then(() => {
|
2023-12-12 13:36:08 +08:00
|
|
|
this.$router.push({path: this.redirect || "/"}).catch(() => {
|
|
|
|
|
});
|
2023-11-28 20:33:38 +08:00
|
|
|
}).catch(() => {
|
|
|
|
|
this.loading = false;
|
|
|
|
|
if (this.captchaEnabled) {
|
|
|
|
|
this.getCode();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style rel="stylesheet/scss" lang="scss">
|
|
|
|
|
.login {
|
2023-12-12 13:36:08 +08:00
|
|
|
//display: flex;
|
|
|
|
|
//justify-content: center;
|
|
|
|
|
//align-items: center;
|
|
|
|
|
position: relative;
|
2023-11-28 20:33:38 +08:00
|
|
|
height: 100%;
|
2023-12-12 13:36:08 +08:00
|
|
|
background-image: url("../assets/images/login.png");
|
|
|
|
|
background-size: 100% 100%;
|
|
|
|
|
//background: #1891FF;
|
2023-11-28 20:33:38 +08:00
|
|
|
}
|
2023-12-12 13:36:08 +08:00
|
|
|
|
2023-11-28 20:33:38 +08:00
|
|
|
.title {
|
|
|
|
|
margin: 0px auto 30px auto;
|
2023-12-12 13:36:08 +08:00
|
|
|
//text-align: center;
|
2023-11-28 20:33:38 +08:00
|
|
|
color: #707070;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-12 13:36:08 +08:00
|
|
|
.login-bar {
|
|
|
|
|
position: absolute;
|
|
|
|
|
height: auto;
|
|
|
|
|
top: 20%;
|
|
|
|
|
left: 14%;
|
|
|
|
|
width: auto;
|
|
|
|
|
height: 500px;
|
2023-11-28 20:33:38 +08:00
|
|
|
border-radius: 6px;
|
2023-12-12 13:36:08 +08:00
|
|
|
display: flex;
|
|
|
|
|
background: #fff;
|
|
|
|
|
text-align: center;
|
|
|
|
|
padding-top: 40px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.form-bar {
|
|
|
|
|
//height: 500px;
|
|
|
|
|
background: #fff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.login-form {
|
|
|
|
|
//border-radius: 6px;
|
|
|
|
|
//height: 100%;
|
2023-11-28 20:33:38 +08:00
|
|
|
background: #ffffff;
|
|
|
|
|
width: 400px;
|
|
|
|
|
padding: 25px 25px 5px 25px;
|
2023-12-12 13:36:08 +08:00
|
|
|
|
2023-11-28 20:33:38 +08:00
|
|
|
.el-input {
|
2023-12-12 13:36:08 +08:00
|
|
|
height: 45px;
|
|
|
|
|
|
2023-11-28 20:33:38 +08:00
|
|
|
input {
|
|
|
|
|
height: 38px;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-12 13:36:08 +08:00
|
|
|
|
2023-11-28 20:33:38 +08:00
|
|
|
.input-icon {
|
|
|
|
|
height: 39px;
|
|
|
|
|
width: 14px;
|
|
|
|
|
margin-left: 2px;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-12 13:36:08 +08:00
|
|
|
|
2023-11-28 20:33:38 +08:00
|
|
|
.login-tip {
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
color: #bfbfbf;
|
|
|
|
|
}
|
2023-12-12 13:36:08 +08:00
|
|
|
|
2023-11-28 20:33:38 +08:00
|
|
|
.login-code {
|
|
|
|
|
width: 33%;
|
|
|
|
|
height: 38px;
|
|
|
|
|
float: right;
|
2023-12-12 13:36:08 +08:00
|
|
|
|
2023-11-28 20:33:38 +08:00
|
|
|
img {
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-12 13:36:08 +08:00
|
|
|
|
2023-11-28 20:33:38 +08:00
|
|
|
.el-login-footer {
|
|
|
|
|
height: 40px;
|
|
|
|
|
line-height: 40px;
|
|
|
|
|
position: fixed;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
width: 100%;
|
|
|
|
|
text-align: center;
|
|
|
|
|
color: #fff;
|
|
|
|
|
font-family: Arial;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
letter-spacing: 1px;
|
|
|
|
|
}
|
2023-12-12 13:36:08 +08:00
|
|
|
|
2023-11-28 20:33:38 +08:00
|
|
|
.login-code-img {
|
|
|
|
|
height: 38px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|