登录注册
This commit is contained in:
@ -1,15 +1,15 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 登录方法
|
||||
export function login(username, password, code, uuid) {
|
||||
export function login(account, password, mode,captcha) {
|
||||
const data = {
|
||||
username,
|
||||
account,
|
||||
password,
|
||||
code,
|
||||
uuid
|
||||
mode,
|
||||
captcha
|
||||
}
|
||||
return request({
|
||||
url: '/login',
|
||||
url: '/enterprise/v1/account/login',
|
||||
headers: {
|
||||
isToken: false
|
||||
},
|
||||
@ -21,7 +21,7 @@ export function login(username, password, code, uuid) {
|
||||
// 注册方法
|
||||
export function register(data) {
|
||||
return request({
|
||||
url: '/register',
|
||||
url: '/enterprise/v1/account/register',
|
||||
headers: {
|
||||
isToken: false
|
||||
},
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 509 KiB |
58
src/components/webGetCode/index.vue
Normal file
58
src/components/webGetCode/index.vue
Normal file
@ -0,0 +1,58 @@
|
||||
<template>
|
||||
<div class="login-code">
|
||||
<el-button
|
||||
class="x_btns login-code-img"
|
||||
size="medium"
|
||||
type="primary"
|
||||
style="width: 100%"
|
||||
@click.prevent="getCode"
|
||||
:disabled="isDisabled"
|
||||
>
|
||||
<span>{{ buttonName }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const disabled = ref(true);
|
||||
const buttonName = ref("获取验证码");
|
||||
const isDisabled = ref(false);
|
||||
const time = ref(60);
|
||||
function getCode() {
|
||||
isDisabled.value = true;
|
||||
let interval = setInterval(function () {
|
||||
buttonName.value = time.value + "后重新发送";
|
||||
--time.value;
|
||||
if (time.value < 0) {
|
||||
buttonName.value = "重新发送";
|
||||
time.value = 60;
|
||||
isDisabled.value = false;
|
||||
clearInterval(interval);
|
||||
}
|
||||
}, 1000);
|
||||
console.log(66666);
|
||||
// getCodeImg().then((res) => {
|
||||
// captchaOnOff.value =
|
||||
// res.captchaOnOff === undefined ? true : res.captchaOnOff;
|
||||
// if (captchaOnOff.value) {
|
||||
// codeUrl.value = "data:image/gif;base64," + res.img;
|
||||
// loginForm.value.mode = res.mode;
|
||||
// }
|
||||
// });
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.login-code {
|
||||
width: 30%;
|
||||
height: 38px;
|
||||
float: right;
|
||||
img {
|
||||
cursor: pointer;
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
.login-code-img {
|
||||
height: 36px;
|
||||
}
|
||||
</style>
|
@ -2,6 +2,8 @@ import { createApp } from 'vue'
|
||||
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
import md5 from 'js-md5';
|
||||
|
||||
import ElementPlus from 'element-plus'
|
||||
import locale from 'element-plus/lib/locale/lang/zh-cn' // 中文语言
|
||||
|
||||
@ -56,6 +58,7 @@ app.config.globalProperties.selectDictLabel = selectDictLabel
|
||||
app.config.globalProperties.modeOptions = modeOptions
|
||||
app.config.globalProperties.educationOptions = educationOptions
|
||||
app.config.globalProperties.enterpriseOptions = enterpriseOptions
|
||||
app.config.globalProperties.md5 = md5;
|
||||
|
||||
// 全局组件挂载
|
||||
app.component('DictTag', DictTag)
|
||||
|
@ -32,14 +32,14 @@ const user = {
|
||||
actions: {
|
||||
// 登录
|
||||
Login({ commit }, userInfo) {
|
||||
const username = userInfo.username.trim()
|
||||
const account = userInfo.username.trim()
|
||||
const password = userInfo.password
|
||||
const code = userInfo.code
|
||||
const uuid = userInfo.uuid
|
||||
const mode = userInfo.mode
|
||||
const captcha = userInfo.captcha
|
||||
return new Promise((resolve, reject) => {
|
||||
login(username, password, code, uuid).then(res => {
|
||||
setToken(res.token)
|
||||
commit('SET_TOKEN', res.token)
|
||||
login(account, password, mode,captcha).then(res => {
|
||||
setToken(res.data.token)
|
||||
commit('SET_TOKEN', res.data.token)
|
||||
resolve()
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
|
@ -42,7 +42,7 @@ service.interceptors.response.use(res => {
|
||||
// 未设置状态码则默认成功状态
|
||||
const code = res.data.code || 200;
|
||||
// 获取错误信息
|
||||
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
||||
const msg = errorCode[code] || res.data.message || errorCode['default']
|
||||
// 二进制数据则直接返回
|
||||
if(res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer'){
|
||||
return res.data
|
||||
|
@ -1,45 +1,116 @@
|
||||
<template>
|
||||
<div class="login">
|
||||
<div class="content">
|
||||
<img class="loginImg" src="../assets/images/login.png" alt="" srcset="">
|
||||
<el-form ref="loginRef" :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="账号">
|
||||
<template #prefix>
|
||||
<svg-icon icon-class="user" class="el-input__icon input-icon" />
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码" @keyup.enter="handleLogin">
|
||||
<template #prefix>
|
||||
<svg-icon icon-class="password" class="el-input__icon input-icon" />
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="code" v-if="captchaOnOff">
|
||||
<el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" @keyup.enter="handleLogin">
|
||||
<template #prefix>
|
||||
<svg-icon icon-class="validCode" class="el-input__icon input-icon" />
|
||||
</template>
|
||||
</el-input>
|
||||
<div class="login-code">
|
||||
<img :src="codeUrl" @click="getCode" class="login-code-img" />
|
||||
<img class="loginImg" src="../assets/images/login.png" alt="" srcset="" />
|
||||
<div class="login-form">
|
||||
<el-tabs v-model="loginForm.mode" v-if="isLogin">
|
||||
<el-tab-pane label="账号密码登录" name="102"></el-tab-pane>
|
||||
<el-tab-pane label="手机快捷登录" name="101"></el-tab-pane>
|
||||
</el-tabs>
|
||||
<div v-if="isLogin">
|
||||
<el-form ref="loginRef" :model="loginForm" :rules="loginRules">
|
||||
<el-form-item prop="username">
|
||||
<el-input
|
||||
v-model="loginForm.username"
|
||||
type="text"
|
||||
auto-complete="off"
|
||||
placeholder="手机号"
|
||||
>
|
||||
<template #prefix>
|
||||
<svg-icon
|
||||
icon-class="user"
|
||||
class="el-input__icon input-icon"
|
||||
/>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password" v-if="loginForm.mode == 102">
|
||||
<el-input
|
||||
v-model="loginForm.password"
|
||||
type="password"
|
||||
auto-complete="off"
|
||||
placeholder="密码"
|
||||
@keyup.enter="handleLogin"
|
||||
>
|
||||
<template #prefix>
|
||||
<svg-icon
|
||||
icon-class="password"
|
||||
class="el-input__icon input-icon"
|
||||
/>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="captcha" v-if="loginForm.mode == 101">
|
||||
<el-input
|
||||
v-model="loginForm.captcha"
|
||||
auto-complete="off"
|
||||
placeholder="验证码"
|
||||
style="width: 65%"
|
||||
@keyup.enter="handleLogin"
|
||||
>
|
||||
<template #prefix>
|
||||
<svg-icon
|
||||
icon-class="validCode"
|
||||
class="el-input__icon input-icon"
|
||||
/>
|
||||
</template>
|
||||
</el-input>
|
||||
<webGetCode />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-checkbox v-model="loginForm.rememberMe">记住账号</el-checkbox>
|
||||
</el-form-item>
|
||||
<el-form-item style="width: 100%">
|
||||
<el-button
|
||||
class="x_btns"
|
||||
:loading="loading"
|
||||
size="medium"
|
||||
type="primary"
|
||||
style="width: 100%"
|
||||
@click.prevent="handleLogin"
|
||||
>
|
||||
<span v-if="!loading">登 录</span>
|
||||
<span v-else>登 录 中...</span>
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div style="overflow: hidden">
|
||||
<div style="float: left" v-if="isLogin">
|
||||
<span class="text_col pointer" :to="'/login'">忘记密码</span>
|
||||
</div>
|
||||
<div style="float: right" v-if="register">
|
||||
<span
|
||||
@click="isLogin = false"
|
||||
style="color: #0054ff"
|
||||
class="pointer"
|
||||
>注册</span
|
||||
>
|
||||
</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.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>
|
||||
|
||||
<el-form
|
||||
v-if="isLogin"
|
||||
:model="registerForm"
|
||||
status-icon
|
||||
:rules="isCheckRules"
|
||||
ref="isCheck"
|
||||
>
|
||||
<el-form-item prop="isCheck">
|
||||
<div style="margin-top: 43px">
|
||||
<div class="text_col">其他登录方式</div>
|
||||
<el-checkbox
|
||||
v-model="registerForm.isCheck"
|
||||
style="margin-top: 43px"
|
||||
>
|
||||
<span class="text_col">登录即同意</span
|
||||
><span style="color: #0054ff">《协议》</span>
|
||||
</el-checkbox>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<Register v-model:isLogin="isLogin" v-else />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 底部 -->
|
||||
@ -48,87 +119,104 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { getCodeImg } from "@/api/login";
|
||||
import Cookies from "js-cookie";
|
||||
import { encrypt, decrypt } from "@/utils/jsencrypt";
|
||||
import Register from "./register.vue";
|
||||
import webGetCode from "@/components/webGetCode";
|
||||
|
||||
const store = useStore();
|
||||
const router = useRouter();
|
||||
const { proxy } = getCurrentInstance();
|
||||
|
||||
const isLogin = ref(true);
|
||||
|
||||
const loginForm = ref({
|
||||
username: "admin",
|
||||
password: "admin123",
|
||||
username: "",
|
||||
password: "",
|
||||
rememberMe: false,
|
||||
code: "",
|
||||
uuid: ""
|
||||
mode: "102",
|
||||
captcha: "",
|
||||
});
|
||||
|
||||
const registerForm = ref({
|
||||
isCheck: false,
|
||||
});
|
||||
|
||||
const disabled = ref(true);
|
||||
const buttonName = ref("获取验证码");
|
||||
const isDisabled = ref(false);
|
||||
const time = ref(10);
|
||||
|
||||
const loginRules = {
|
||||
username: [{ required: true, trigger: "blur", message: "请输入您的账号" }],
|
||||
username: [{ required: true, trigger: "blur", message: "请输入您的手机号" }],
|
||||
password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
|
||||
code: [{ required: true, trigger: "change", message: "请输入验证码" }]
|
||||
captcha: [{ required: true, trigger: "change", message: "请输入验证码" }],
|
||||
};
|
||||
|
||||
const isCheck = (rule, value, callback) => {
|
||||
if (!value) {
|
||||
callback(new Error("请阅读并勾选"));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
const isCheckRules = {
|
||||
isCheck: [{ required: true, validator: isCheck, trigger: "change" }],
|
||||
};
|
||||
|
||||
const codeUrl = ref("");
|
||||
const loading = ref(false);
|
||||
// 验证码开关
|
||||
const captchaOnOff = ref(true);
|
||||
// 注册开关
|
||||
const register = ref(false);
|
||||
const register = ref(true);
|
||||
const redirect = ref(undefined);
|
||||
|
||||
function handleLogin () {
|
||||
proxy.$refs.loginRef.validate(valid => {
|
||||
if (valid) {
|
||||
loading.value = true;
|
||||
// 勾选了需要记住密码设置在cookie中设置记住用户明和名命
|
||||
if (loginForm.value.rememberMe) {
|
||||
Cookies.set("username", loginForm.value.username, { expires: 30 });
|
||||
Cookies.set("password", encrypt(loginForm.value.password), { expires: 30 });
|
||||
Cookies.set("rememberMe", loginForm.value.rememberMe, { expires: 30 });
|
||||
} else {
|
||||
// 否则移除
|
||||
Cookies.remove("username");
|
||||
Cookies.remove("password");
|
||||
Cookies.remove("rememberMe");
|
||||
}
|
||||
// 调用action的登录方法
|
||||
store.dispatch("Login", loginForm.value).then(() => {
|
||||
router.push({ path: redirect.value || "/" });
|
||||
}).catch(() => {
|
||||
loading.value = false;
|
||||
// 重新获取验证码
|
||||
if (captchaOnOff.value) {
|
||||
getCode();
|
||||
function handleLogin() {
|
||||
proxy.$refs.loginRef.validate((valid) => {
|
||||
proxy.$refs.isCheck.validate((valid2) => {
|
||||
if (valid && valid2) {
|
||||
loading.value = true;
|
||||
if (loginForm.value.rememberMe) {
|
||||
Cookies.set("username", loginForm.value.username, { expires: 30 });
|
||||
Cookies.set("password", loginForm.value.password, {
|
||||
expires: 30,
|
||||
});
|
||||
Cookies.set("rememberMe", loginForm.value.rememberMe, {
|
||||
expires: 30,
|
||||
});
|
||||
} else {
|
||||
// 否则移除
|
||||
Cookies.remove("username");
|
||||
Cookies.remove("password");
|
||||
Cookies.remove("rememberMe");
|
||||
}
|
||||
});
|
||||
}
|
||||
// 调用action的登录方法
|
||||
let formData = Object.assign({}, loginForm.value);
|
||||
formData.password = proxy.md5(formData.password);
|
||||
formData.mode = formData.mode - 0;
|
||||
store
|
||||
.dispatch("Login", formData)
|
||||
.then(() => {
|
||||
router.push({ path: redirect.value || "/" });
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getCode () {
|
||||
getCodeImg().then(res => {
|
||||
captchaOnOff.value = res.captchaOnOff === undefined ? true : res.captchaOnOff;
|
||||
if (captchaOnOff.value) {
|
||||
codeUrl.value = "data:image/gif;base64," + res.img;
|
||||
loginForm.value.uuid = res.uuid;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getCookie () {
|
||||
function getCookie() {
|
||||
const username = Cookies.get("username");
|
||||
const password = Cookies.get("password");
|
||||
const rememberMe = Cookies.get("rememberMe");
|
||||
loginForm.value = {
|
||||
username: username === undefined ? loginForm.value.username : username,
|
||||
password: password === undefined ? loginForm.value.password : decrypt(password),
|
||||
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
||||
password: password === undefined ? loginForm.value.password : password,
|
||||
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
||||
mode: loginForm.value.mode,
|
||||
};
|
||||
}
|
||||
|
||||
getCode();
|
||||
getCookie();
|
||||
</script>
|
||||
|
||||
@ -169,10 +257,10 @@ getCookie();
|
||||
|
||||
.login-form {
|
||||
width: 516px;
|
||||
height: 517px;
|
||||
min-height: 517px;
|
||||
background: #ffffff;
|
||||
box-sizing: border-box;
|
||||
padding: 25px;
|
||||
padding: 30px 33px;
|
||||
.tit {
|
||||
padding: 30px 0;
|
||||
text-align: center;
|
||||
@ -181,6 +269,9 @@ getCookie();
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
}
|
||||
.el-tab-pane {
|
||||
padding-top: 10px;
|
||||
}
|
||||
.el-input {
|
||||
height: 38px;
|
||||
input {
|
||||
@ -192,6 +283,18 @@ getCookie();
|
||||
width: 14px;
|
||||
margin-left: 2px;
|
||||
}
|
||||
::v-deep .el-tabs__active-bar {
|
||||
background-color: #0054ff;
|
||||
}
|
||||
::v-deep .el-tabs__item {
|
||||
color: #666666;
|
||||
font-size: 16px;
|
||||
&.is-active {
|
||||
font-weight: 500;
|
||||
color: #0054ff;
|
||||
font-size: 20px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.login-tip {
|
||||
font-size: 13px;
|
||||
@ -199,7 +302,7 @@ getCookie();
|
||||
color: #bfbfbf;
|
||||
}
|
||||
.login-code {
|
||||
width: 33%;
|
||||
width: 30%;
|
||||
height: 38px;
|
||||
float: right;
|
||||
img {
|
||||
@ -220,6 +323,9 @@ getCookie();
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.login-code-img {
|
||||
height: 38px;
|
||||
height: 36px;
|
||||
}
|
||||
.text_col {
|
||||
color: #999999;
|
||||
}
|
||||
</style>
|
@ -1,84 +1,117 @@
|
||||
<template>
|
||||
<div class="register">
|
||||
<el-form ref="registerRef" :model="registerForm" :rules="registerRules" class="register-form">
|
||||
<h3 class="title">xxx后台管理系统</h3>
|
||||
<el-form-item prop="username">
|
||||
<el-input v-model="registerForm.username" type="text" auto-complete="off" placeholder="账号">
|
||||
<template #prefix><svg-icon icon-class="user" class="el-input__icon input-icon" /></template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input
|
||||
v-model="registerForm.password"
|
||||
type="password"
|
||||
auto-complete="off"
|
||||
placeholder="密码"
|
||||
@keyup.enter="handleRegister"
|
||||
<el-form
|
||||
ref="registerRef"
|
||||
:model="registerForm"
|
||||
:rules="registerRules"
|
||||
class="register-form"
|
||||
>
|
||||
<h3 class="title">注册</h3>
|
||||
<el-form-item prop="mobile">
|
||||
<el-input
|
||||
v-model="registerForm.mobile"
|
||||
type="text"
|
||||
auto-complete="off"
|
||||
placeholder="手机号"
|
||||
>
|
||||
<template #prefix
|
||||
><svg-icon icon-class="user" class="el-input__icon input-icon"
|
||||
/></template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input
|
||||
v-model="registerForm.password"
|
||||
type="password"
|
||||
auto-complete="off"
|
||||
placeholder="密码"
|
||||
@keyup.enter="handleRegister"
|
||||
>
|
||||
<template #prefix
|
||||
><svg-icon icon-class="password" class="el-input__icon input-icon"
|
||||
/></template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="repeat_pass">
|
||||
<el-input
|
||||
v-model="registerForm.repeat_pass"
|
||||
type="password"
|
||||
auto-complete="off"
|
||||
placeholder="确认密码"
|
||||
@keyup.enter="handleRegister"
|
||||
>
|
||||
<template #prefix
|
||||
><svg-icon icon-class="password" class="el-input__icon input-icon"
|
||||
/></template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="captcha" style="margin-bottom: 0">
|
||||
<el-input
|
||||
v-model="registerForm.captcha"
|
||||
auto-complete="off"
|
||||
placeholder="验证码"
|
||||
style="width: 65%"
|
||||
@keyup.enter="handleRegister"
|
||||
>
|
||||
<template #prefix
|
||||
><svg-icon icon-class="validCode" class="el-input__icon input-icon"
|
||||
/></template>
|
||||
</el-input>
|
||||
<webGetCode />
|
||||
</el-form-item>
|
||||
<el-form-item prop="isCheck" style="margin: 10px 0; height: 28px">
|
||||
<el-checkbox v-model="registerForm.isCheck">
|
||||
<span style="color: #999999">勾选即同意</span
|
||||
><span style="color: #0054ff">《协议》</span>
|
||||
</el-checkbox>
|
||||
</el-form-item>
|
||||
<el-form-item style="width: 100%; margin-top: 35px">
|
||||
<el-button
|
||||
class="x_btns"
|
||||
:loading="loading"
|
||||
size="medium"
|
||||
type="primary"
|
||||
style="width: 100%"
|
||||
@click.prevent="handleRegister"
|
||||
>
|
||||
<span v-if="!loading">注 册</span>
|
||||
<span v-else>注 册 中...</span>
|
||||
</el-button>
|
||||
<div style="float: right">
|
||||
<span
|
||||
class="x_blue pointer"
|
||||
@click="handleLogin"
|
||||
style="font-size: 16px"
|
||||
>登录</span
|
||||
>
|
||||
<template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="confirmPassword">
|
||||
<el-input
|
||||
v-model="registerForm.confirmPassword"
|
||||
type="password"
|
||||
auto-complete="off"
|
||||
placeholder="确认密码"
|
||||
@keyup.enter="handleRegister"
|
||||
>
|
||||
<template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="code" v-if="captchaOnOff">
|
||||
<el-input
|
||||
v-model="registerForm.code"
|
||||
auto-complete="off"
|
||||
placeholder="验证码"
|
||||
style="width: 63%"
|
||||
@keyup.enter="handleRegister"
|
||||
>
|
||||
<template #prefix><svg-icon icon-class="validCode" class="el-input__icon input-icon" /></template>
|
||||
</el-input>
|
||||
<div class="register-code">
|
||||
<img :src="codeUrl" @click="getCode" class="register-code-img"/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item style="width:100%;">
|
||||
<el-button
|
||||
:loading="loading"
|
||||
size="medium"
|
||||
type="primary"
|
||||
style="width:100%;"
|
||||
@click.prevent="handleRegister"
|
||||
>
|
||||
<span v-if="!loading">注 册</span>
|
||||
<span v-else>注 册 中...</span>
|
||||
</el-button>
|
||||
<div style="float: right;">
|
||||
<router-link class="link-type" :to="'/login'">使用已有账户登录</router-link>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<!-- 底部 -->
|
||||
<div class="el-register-footer">
|
||||
<span>Copyright © 2018-2021 ruoyi.vip All Rights Reserved.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ElMessageBox } from "element-plus";
|
||||
import { getCodeImg, register } from "@/api/login";
|
||||
import webGetCode from "@/components/webGetCode";
|
||||
|
||||
const props = defineProps({
|
||||
isLogin: Boolean,
|
||||
});
|
||||
|
||||
const emit = defineEmits();
|
||||
|
||||
function handleLogin() {
|
||||
emit("update:isLogin", true);
|
||||
}
|
||||
|
||||
const router = useRouter();
|
||||
const { proxy } = getCurrentInstance();
|
||||
|
||||
const registerForm = ref({
|
||||
username: "",
|
||||
mobile: "",
|
||||
password: "",
|
||||
confirmPassword: "",
|
||||
code: "",
|
||||
uuid: ""
|
||||
repeat_pass: "",
|
||||
captcha: "",
|
||||
isCheck: false,
|
||||
});
|
||||
|
||||
const equalToPassword = (rule, value, callback) => {
|
||||
@ -88,82 +121,84 @@ const equalToPassword = (rule, value, callback) => {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
const isCheck = (rule, value, callback) => {
|
||||
if (!value) {
|
||||
callback(new Error("请阅读并勾选"));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
const registerRules = {
|
||||
username: [
|
||||
{ required: true, trigger: "blur", message: "请输入您的账号" },
|
||||
{ min: 2, max: 20, message: "用户账号长度必须介于 2 和 20 之间", trigger: "blur" }
|
||||
mobile: [
|
||||
{ required: true, message: "手机号不能为空", trigger: "blur" },
|
||||
{
|
||||
pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
|
||||
message: "请输入正确的手机号码",
|
||||
trigger: "blur",
|
||||
},
|
||||
],
|
||||
password: [
|
||||
{ required: true, trigger: "blur", message: "请输入您的密码" },
|
||||
{ min: 5, max: 20, message: "用户密码长度必须介于 5 和 20 之间", trigger: "blur" }
|
||||
{
|
||||
min: 5,
|
||||
max: 20,
|
||||
message: "用户密码长度必须介于 5 和 20 之间",
|
||||
trigger: "blur",
|
||||
},
|
||||
],
|
||||
confirmPassword: [
|
||||
repeat_pass: [
|
||||
{ required: true, trigger: "blur", message: "请再次输入您的密码" },
|
||||
{ required: true, validator: equalToPassword, trigger: "blur" }
|
||||
{ required: true, validator: equalToPassword, trigger: "blur" },
|
||||
],
|
||||
code: [{ required: true, trigger: "change", message: "请输入验证码" }]
|
||||
captcha: [{ required: true, trigger: "change", message: "请输入验证码" }],
|
||||
isCheck: [{ required: true, validator: isCheck, trigger: "change" }],
|
||||
};
|
||||
|
||||
const codeUrl = ref("");
|
||||
const loading = ref(false);
|
||||
const captchaOnOff = ref(true);
|
||||
|
||||
function handleRegister() {
|
||||
proxy.$refs.registerRef.validate(valid => {
|
||||
proxy.$refs.registerRef.validate((valid) => {
|
||||
if (valid) {
|
||||
loading.value = true;
|
||||
register(registerForm.value).then(res => {
|
||||
const username = registerForm.value.username;
|
||||
ElMessageBox.alert("<font color='red'>恭喜你,您的账号 " + username + " 注册成功!</font>", "系统提示", {
|
||||
dangerouslyUseHTMLString: true,
|
||||
type: "success",
|
||||
}).then(() => {
|
||||
router.push("/login");
|
||||
}).catch(() => {});
|
||||
}).catch(() => {
|
||||
loading.value = false;
|
||||
if (captchaOnOff) {
|
||||
getCode();
|
||||
}
|
||||
});
|
||||
register(registerForm.value)
|
||||
.then((res) => {
|
||||
const mobile = registerForm.value.mobile;
|
||||
ElMessageBox.alert(
|
||||
"<font color='red'>恭喜你,您的账号 " +
|
||||
mobile +
|
||||
" 注册成功!</font>",
|
||||
"系统提示",
|
||||
{
|
||||
dangerouslyUseHTMLString: true,
|
||||
type: "success",
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
handleLogin();
|
||||
// router.push("/login");
|
||||
})
|
||||
.catch(() => {});
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getCode() {
|
||||
getCodeImg().then(res => {
|
||||
captchaOnOff.value = res.captchaOnOff === undefined ? true : res.captchaOnOff;
|
||||
if (captchaOnOff.value) {
|
||||
codeUrl.value = "data:image/gif;base64," + res.img;
|
||||
registerForm.value.uuid = res.uuid;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getCode();
|
||||
</script>
|
||||
|
||||
<style lang='scss' scoped>
|
||||
.register {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
background-image: url("../assets/images/login-background.jpg");
|
||||
background-size: cover;
|
||||
}
|
||||
.title {
|
||||
margin: 0px auto 30px auto;
|
||||
margin: 0px auto 40px auto;
|
||||
text-align: center;
|
||||
color: #707070;
|
||||
color: #333333;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.register-form {
|
||||
border-radius: 6px;
|
||||
background: #ffffff;
|
||||
width: 400px;
|
||||
padding: 25px 25px 5px 25px;
|
||||
.el-input {
|
||||
height: 38px;
|
||||
input {
|
||||
@ -181,15 +216,6 @@ getCode();
|
||||
text-align: center;
|
||||
color: #bfbfbf;
|
||||
}
|
||||
.register-code {
|
||||
width: 33%;
|
||||
height: 38px;
|
||||
float: right;
|
||||
img {
|
||||
cursor: pointer;
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
.el-register-footer {
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
@ -202,7 +228,4 @@ getCode();
|
||||
font-size: 12px;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.register-code-img {
|
||||
height: 38px;
|
||||
}
|
||||
</style>
|
||||
|
275
src/views/signin.vue
Normal file
275
src/views/signin.vue
Normal file
@ -0,0 +1,275 @@
|
||||
<template>
|
||||
<div class="login">
|
||||
<div class="content">
|
||||
<img class="loginImg" src="../assets/images/login.png" alt="" srcset="" />
|
||||
<el-form
|
||||
v-if="isLogin"
|
||||
ref="loginRef"
|
||||
: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="手机号"
|
||||
>
|
||||
<template #prefix>
|
||||
<svg-icon icon-class="user" class="el-input__icon input-icon" />
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input
|
||||
v-model="loginForm.password"
|
||||
type="password"
|
||||
auto-complete="off"
|
||||
placeholder="密码"
|
||||
@keyup.enter="handleLogin"
|
||||
>
|
||||
<template #prefix>
|
||||
<svg-icon
|
||||
icon-class="password"
|
||||
class="el-input__icon input-icon"
|
||||
/>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="code" v-if="captchaOnOff">
|
||||
<el-input
|
||||
v-model="loginForm.code"
|
||||
auto-complete="off"
|
||||
placeholder="验证码"
|
||||
style="width: 63%"
|
||||
@keyup.enter="handleLogin"
|
||||
>
|
||||
<template #prefix>
|
||||
<svg-icon
|
||||
icon-class="validCode"
|
||||
class="el-input__icon input-icon"
|
||||
/>
|
||||
</template>
|
||||
</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.prevent="handleLogin"
|
||||
>
|
||||
<span v-if="!loading">登 录</span>
|
||||
<span v-else>登 录 中...</span>
|
||||
</el-button>
|
||||
<div style="float: right" v-if="register">
|
||||
<router-link :to="'/register'"></router-link>
|
||||
<span class="link-type" @click="isLogin = false">注册</span>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<Register v-model="isLogin" v-else />
|
||||
</div>
|
||||
|
||||
<!-- 底部 -->
|
||||
<div class="foot">Copyright © 2007-2021 中科云 版权所有</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { getCodeImg } from "@/api/login";
|
||||
import Cookies from "js-cookie";
|
||||
import { encrypt, decrypt } from "@/utils/jsencrypt";
|
||||
import Register from "./register.vue";
|
||||
|
||||
const store = useStore();
|
||||
const router = useRouter();
|
||||
const { proxy } = getCurrentInstance();
|
||||
|
||||
const isLogin = ref(true);
|
||||
|
||||
const loginForm = ref({
|
||||
username: "admin",
|
||||
password: "admin123",
|
||||
rememberMe: false,
|
||||
code: "",
|
||||
uuid: "",
|
||||
});
|
||||
|
||||
const loginRules = {
|
||||
username: [{ required: true, trigger: "blur", message: "请输入您的手机号" }],
|
||||
password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
|
||||
code: [{ required: true, trigger: "change", message: "请输入验证码" }],
|
||||
};
|
||||
|
||||
const codeUrl = ref("");
|
||||
const loading = ref(false);
|
||||
// 验证码开关
|
||||
const captchaOnOff = ref(false);
|
||||
// 注册开关
|
||||
const register = ref(true);
|
||||
const redirect = ref(undefined);
|
||||
|
||||
function handleLogin() {
|
||||
proxy.$refs.loginRef.validate((valid) => {
|
||||
if (valid) {
|
||||
loading.value = true;
|
||||
// 勾选了需要记住密码设置在cookie中设置记住用户明和名命
|
||||
if (loginForm.value.rememberMe) {
|
||||
Cookies.set("username", loginForm.value.username, { expires: 30 });
|
||||
Cookies.set("password", encrypt(loginForm.value.password), {
|
||||
expires: 30,
|
||||
});
|
||||
Cookies.set("rememberMe", loginForm.value.rememberMe, { expires: 30 });
|
||||
} else {
|
||||
// 否则移除
|
||||
Cookies.remove("username");
|
||||
Cookies.remove("password");
|
||||
Cookies.remove("rememberMe");
|
||||
}
|
||||
// 调用action的登录方法
|
||||
store
|
||||
.dispatch("Login", loginForm.value)
|
||||
.then(() => {
|
||||
router.push({ path: redirect.value || "/" });
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
// 重新获取验证码
|
||||
if (captchaOnOff.value) {
|
||||
getCode();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getCode() {
|
||||
getCodeImg().then((res) => {
|
||||
captchaOnOff.value =
|
||||
res.captchaOnOff === undefined ? true : res.captchaOnOff;
|
||||
if (captchaOnOff.value) {
|
||||
codeUrl.value = "data:image/gif;base64," + res.img;
|
||||
loginForm.value.uuid = res.uuid;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getCookie() {
|
||||
const username = Cookies.get("username");
|
||||
const password = Cookies.get("password");
|
||||
const rememberMe = Cookies.get("rememberMe");
|
||||
loginForm.value = {
|
||||
username: username === undefined ? loginForm.value.username : username,
|
||||
password:
|
||||
password === undefined ? loginForm.value.password : decrypt(password),
|
||||
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
||||
};
|
||||
}
|
||||
|
||||
// getCode();
|
||||
getCookie();
|
||||
</script>
|
||||
|
||||
<style lang='scss' scoped>
|
||||
.login {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
.content {
|
||||
padding: 0 250px;
|
||||
flex: 1;
|
||||
background: #b1ccff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.loginImg {
|
||||
width: 705px;
|
||||
height: 458px;
|
||||
}
|
||||
}
|
||||
.foot {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
background: #fff;
|
||||
font-size: 14px;
|
||||
font-family: Source Han Sans CN;
|
||||
font-weight: 500;
|
||||
color: #666666;
|
||||
}
|
||||
}
|
||||
.title {
|
||||
margin: 0px auto 30px auto;
|
||||
text-align: center;
|
||||
color: #707070;
|
||||
}
|
||||
|
||||
.login-form {
|
||||
width: 516px;
|
||||
height: 517px;
|
||||
background: #ffffff;
|
||||
box-sizing: border-box;
|
||||
padding: 25px;
|
||||
.tit {
|
||||
padding: 30px 0;
|
||||
text-align: center;
|
||||
font-size: 20px;
|
||||
font-family: Source Han Sans CN;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
}
|
||||
.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;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
font-family: Arial;
|
||||
font-size: 12px;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.login-code-img {
|
||||
height: 38px;
|
||||
}
|
||||
</style>
|
Reference in New Issue
Block a user