登录注册

This commit is contained in:
jjLv 2024-11-12 11:55:57 +08:00
parent adb3347fa0
commit 06e67e1460
3 changed files with 1162 additions and 785 deletions

View File

@ -1,8 +1,8 @@
// SM 配置
export const SM_CONFIG = {
SALT: '2cc0c5f9f1749f1632efa9f63e902323', // SM3 盐值16 字节)
SM4_KEY:"78d1295afa99449b99d6f83820e6965c", // SM4 对称加密密钥
SM4_SALT:"f555adf6c01d0ab0761e626a2dae34a2",
SM4_KEY: "78d1295afa99449b99d6f83820e6965c", // SM4 对称加密密钥
SM4_SALT: "f555adf6c01d0ab0761e626a2dae34a2",
SM2_PUBLIC_KEY: 'your-public-key', // SM2 公钥
SM2_PRIVATE_KEY: 'your-private-key' // SM2 私钥
}
@ -14,7 +14,7 @@ export const AES_CONFIG = {
export function generateUUID() {
// 使用当前时间戳和随机数生成一个 UUID
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0; // 生成随机数
const v = c === 'x' ? r : (r & 0x3 | 0x8); // 根据 UUID 规范生成相应的值
return v.toString(16); // 转换为十六进制

View File

@ -2,7 +2,7 @@
<div class="container">
<div class="bg-cont">
<div class="bg">
<img src="@/assets/images/dp-bg.png">
<img src="@/assets/images/dp-bg.png" />
</div>
</div>
<!-- <div class="lef-cont">
@ -23,28 +23,44 @@
<div class="login">
<h3 class="title">输变电工程施工现场安全风险预警系统</h3>
<div class="login-form">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" >
<el-form ref="loginForm" :model="loginForm" :rules="loginRules">
<!-- -->
<template v-if="loginMethod === 'password'">
<el-form-item prop="username">
<el-input
v-model="loginForm.username"
type="text"
auto-complete="off"
:placeholder="`用户名${config.loginConfig.phonePassword ? '/手机号' : ''}${config.loginConfig.emailPassword ? '/邮箱' : ''}`"
:placeholder="`用户名${
config.loginConfig.phonePassword
? '/手机号'
: ''
}${
config.loginConfig.emailPassword
? '/邮箱'
: ''
}`"
>
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon"/>
<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="密码"
auto-complete="off"
@keyup.enter.native="handleLogin"
>
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/>
<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">
@ -55,25 +71,48 @@
style="width: 63%"
@keyup.enter.native="handleLogin"
>
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon"/>
<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"/>
<img
:src="codeUrl"
@click="getCode"
class="login-code-img"
/>
</div>
</el-form-item>
<el-form-item v-show="isAdmin" prop="verificationCode">
<el-input v-model="loginForm.verificationCode" placeholder="请输入验证码">
<el-input
v-model="loginForm.verificationCode"
placeholder="请输入验证码"
>
<template slot="append">
<el-button
type="primary"
@click="sendAdminCode"
:disabled="isSendingCode || captchaEnabled?!loginForm.code:false"
:disabled="
isSendingCode || captchaEnabled
? !loginForm.code
: false
"
class="send-code-button"
>
{{ countdown === 0 ? '获取验证码' : `${countdown}s` }}
{{
countdown === 0
? '获取验证码'
: `${countdown}s`
}}
</el-button>
</template>
<svg-icon slot="prefix" icon-class="message" class="el-input__icon input-icon"/>
<svg-icon
slot="prefix"
icon-class="message"
class="el-input__icon input-icon"
/>
</el-input>
</el-form-item>
</template>
@ -83,9 +122,17 @@
v-model="loginForm.mobile"
type="text"
auto-complete="off"
:placeholder="`${config.loginConfig.phoneCode ? '手机号' : '/'}${config.loginConfig.emailCode ? '邮箱' : ''}`"
:placeholder="`${
config.loginConfig.phoneCode
? '手机号'
: '/'
}${config.loginConfig.emailCode ? '邮箱' : ''}`"
>
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon"/>
<svg-icon
slot="prefix"
icon-class="user"
class="el-input__icon input-icon"
/>
</el-input>
</el-form-item>
<el-form-item prop="code" v-if="captchaEnabled">
@ -96,60 +143,105 @@
style="width: 63%"
@keyup.enter.native="handleLogin"
>
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon"/>
<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"/>
<img
:src="codeUrl"
@click="getCode"
class="login-code-img"
/>
</div>
</el-form-item>
<el-form-item prop="verificationCode">
<el-input v-model="loginForm.verificationCode" placeholder="请输入验证码">
<el-input
v-model="loginForm.verificationCode"
placeholder="请输入验证码"
>
<template slot="append">
<el-button
type="primary"
@click="sendCode"
:disabled="isSendingCode || captchaEnabled?!loginForm.code:false"
:disabled="
isSendingCode || captchaEnabled
? !loginForm.code
: false
"
class="send-code-button"
>
{{ countdown === 0 ? '获取验证码' : `${countdown}s` }}
{{
countdown === 0
? '获取验证码'
: `${countdown}s`
}}
</el-button>
</template>
<svg-icon slot="prefix" icon-class="message" class="el-input__icon input-icon"/>
<svg-icon
slot="prefix"
icon-class="message"
class="el-input__icon input-icon"
/>
</el-input>
</el-form-item>
</template>
<div class="login-form-center">
<el-link v-if="config.loginConfig.emailCode ||config.loginConfig.phoneCode " @click="toggleLoginMethod">
{{ loginMethod === 'password' ? '短信登录' : '密码登录' }}
<el-link
v-if="
config.loginConfig.emailCode ||
config.loginConfig.phoneCode
"
@click="toggleLoginMethod"
>
{{
loginMethod === 'password'
? '短信登录'
: '密码登录'
}}
</el-link>
<router-link v-if="config.registersConfig.emailRegisters || config.registersConfig.phoneRegisters" to="/register">
<router-link
v-if="
config.registersConfig.emailRegisters ||
config.registersConfig.phoneRegisters
"
to="/register"
>
<el-link>注册账号</el-link>
</router-link>
<!-- <el-checkbox v-model="loginForm.rememberMe">记住密码</el-checkbox> -->
</div>
<el-form-item style="width: 100%;">
<el-button v-if="!isAdmin"
<el-form-item style="width: 100%">
<el-button
v-if="!isAdmin"
:loading="loading"
size="medium"
type="primary"
style="width: 100%;"
@click="loginMethod === 'password' ?IsAdmin():handleLogin()"
style="width: 100%"
@click="
loginMethod === 'password'
? IsAdmin()
: handleLogin()
"
>
<span v-if="!loading"> </span>
<span v-else> 中...</span>
</el-button>
<el-button v-if="isAdmin"
<el-button
v-if="isAdmin"
:loading="loading"
size="medium"
type="primary"
style="width: 100%;"
style="width: 100%"
@click="handleLogin()"
>
<span v-if="!loading"> </span>
<span v-else> 中...</span>
</el-button>
</el-form-item>
<el-form-item>
<!-- <el-form-item>
<div class="login-divider">第三方登录</div>
<div class="login-icons">
<div class="login-icon">
@ -162,7 +254,7 @@
<img :src="qq" alt="QQ">
</div>
</div>
</el-form-item>
</el-form-item>-->
</el-form>
</div>
</div>
@ -176,7 +268,7 @@
<script>
import { getCodeImg } from '@/api/login'
import Cookies from 'js-cookie'
import { decrypt, encrypt } from '@/utils/jsencrypt'
import { encrypt, decrypt } from '@/utils/jsencrypt'
import dingding from '@/assets/images/dingding.svg'
import wx from '@/assets/images/wx.svg'
import qq from '@/assets/images/QQ.svg'
@ -200,16 +292,46 @@ export default {
uuid: '',
loginType: '',
phoneUuid: '',
mobileCodeType: 'LOGIN'
mobileCodeType: 'LOGIN',
},
passwordLoginRules: {
username: [{ required: true, trigger: 'blur', message: '请输入您的账号' }],
password: [{ required: true, trigger: 'blur', message: '请输入您的密码' }],
code: [{ required: true, trigger: 'change', message: '请输入验证码' }]
username: [
{
required: true,
trigger: 'blur',
message: '请输入您的账号',
},
],
password: [
{
required: true,
trigger: 'blur',
message: '请输入您的密码',
},
],
code: [
{
required: true,
trigger: 'change',
message: '请输入验证码',
},
],
},
mobileLoginRules: {
mobile: [{ required: true, trigger: 'blur', message: '请输入您的手机号' }],
verificationCode: [{ required: true, trigger: 'blur', message: '请输入验证码' }]
mobile: [
{
required: true,
trigger: 'blur',
message: '请输入您的手机号',
},
],
verificationCode: [
{
required: true,
trigger: 'blur',
message: '请输入验证码',
},
],
},
loading: false,
captchaEnabled: true,
@ -218,32 +340,39 @@ export default {
countdown: 0,
loginMethod: 'password', // 'password' or 'mobile'
supportsPhoneLogin: false,
supportsEmailLogin: false
supportsEmailLogin: false,
}
},
computed: {
config() {
return JSON.parse(localStorage.getItem('systemConfig')) || {loginConfig:{
return (
JSON.parse(localStorage.getItem('systemConfig')) || {
loginConfig: {
phonePassword: true,
emailPassword: true,
phoneCode: false,
emailCode: false
},registersConfig: {
emailCode: false,
},
registersConfig: {
phoneRegisters: true,
emailRegisters: true
}}; // JSON
emailRegisters: true,
},
}
) // JSON
},
loginRules() {
return this.loginMethod === 'password' ? this.passwordLoginRules : this.mobileLoginRules
}
return this.loginMethod === 'password'
? this.passwordLoginRules
: this.mobileLoginRules
},
},
watch: {
$route: {
handler(route) {
this.redirect = route.query && route.query.redirect
},
immediate: true
}
immediate: true,
},
},
created() {
this.getCode()
@ -251,8 +380,10 @@ export default {
},
methods: {
getCode() {
getCodeImg().then(res => {
this.captchaEnabled = res.captchaEnabled !== undefined ? res.captchaEnabled : true
getCodeImg().then((res) => {
this.captchaEnabled =
res.captchaEnabled !== undefined ? res.captchaEnabled : true
console.log(this.captchaEnabled)
if (this.captchaEnabled) {
this.codeUrl = 'data:image/gif;base64,' + res.img
this.loginForm.uuid = res.uuid
@ -268,33 +399,52 @@ export default {
this.loginForm.rememberMe = rememberMe === 'true'
},
handleLogin() {
this.$refs.loginForm.validate(valid => {
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 })
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')
}
this.loginForm.loginMethod = this.loginMethod
this.$store.dispatch('Login', this.loginForm)
.then(res => {
this.$store
.dispatch('Login', this.loginForm)
.then((res) => {
console.log(res)
if (res.code===200){
if (res.isLogin){
this.$modal.confirm('账号已在其他地方登录是否继续登录!!!!').then(function() {
return this.$router.push({ path: this.redirect || '/' });
}).then(() => {
this.loading = false
}).catch(() => {
if (res.code === 200) {
if (res.isLogin) {
this.$modal
.confirm(
'账号已在其他地方登录是否继续登录!!!!',
)
.then(function () {
return this.$router.push({
path: this.redirect || '/',
})
})
.then(() => {
this.loading = false
})
}else {
this.$router.push({ path: this.redirect || '/' });
.catch(() => {
this.loading = false
})
} else {
this.$router.push({
path: this.redirect || '/',
})
}
}
})
@ -307,29 +457,38 @@ export default {
},
IsAdmin() {
this.loginForm.loginMethod = this.loginMethod
this.$store.dispatch('IsAdmin', this.loginForm).then(res => {
this.$store.dispatch('IsAdmin', this.loginForm).then((res) => {
if (res.data) {
this.isAdmin = res.data
this.$message.success('检测到您是超级管理账号,需进行手机检验')
this.$message.success(
'检测到您是超级管理账号,需进行手机检验',
)
} else {
this.handleLogin()
}
})
},
isLogin() {
this.$refs.loginForm.validate(valid => {
this.$refs.loginForm.validate((valid) => {
if (valid) {
this.loading = true
let that = this
this.loginForm.loginMethod = this.loginMethod
this.$store.dispatch('IsLogin', this.loginForm)
.then(res => {
this.$store
.dispatch('IsLogin', this.loginForm)
.then((res) => {
if (res.data) {
this.$modal.confirm('账号已在其他地方登录是否继续登录!!!!').then(function() {
this.$modal
.confirm(
'账号已在其他地方登录是否继续登录!!!!',
)
.then(function () {
return that.handleLogin()
}).then(() => {
})
.then(() => {
this.loading = false
}).catch(() => {
})
.catch(() => {
this.loading = false
})
} else {
@ -345,8 +504,9 @@ export default {
},
sendAdminCode() {
this.loginForm.mobile = this.loginForm.username
this.$store.dispatch('GetPhoneCode', this.loginForm)
.then(res => {
this.$store
.dispatch('GetPhoneCode', this.loginForm)
.then((res) => {
if (res.code === 200) {
this.loginForm.phoneUuid = res.data
this.$message.success('验证码发送成功')
@ -378,10 +538,17 @@ export default {
return
}
if (!this.loginForm.mobile) {
this.$message.error('请先填写'+this.config.loginConfig.phoneCode ? '手机号' : '/' + this.config.loginConfig.emailCode ? '邮箱' : '')
this.$message.error(
'请先填写' + this.config.loginConfig.phoneCode
? '手机号'
: '/' + this.config.loginConfig.emailCode
? '邮箱'
: '',
)
return
}
this.$store.dispatch('GetPhoneCode', this.loginForm)
this.$store
.dispatch('GetPhoneCode', this.loginForm)
.then(() => {
this.isSendingCode = true
this.countdown = 60
@ -405,7 +572,8 @@ export default {
})
},
toggleLoginMethod() {
this.loginMethod = this.loginMethod === 'password' ? 'mobile' : 'password'
this.loginMethod =
this.loginMethod === 'password' ? 'mobile' : 'password'
this.loginForm.username = ''
this.loginForm.password = ''
this.loginForm.code = ''
@ -413,47 +581,119 @@ export default {
this.loginForm.loginMethod = ''
this.isAdmin = false
this.getCode()
}
}
},
},
}
</script>
<style lang="scss">
@font-face {
font-family: 'titleFont';
src: url('../assets/iconFont/titleFont.ttf');
}
.container {
display: flex;
justify-content: flex-end;
align-items: center;
flex-wrap: wrap;
background-color: #eaf0fb;
height: 100%;
background-image: url("../assets/images/bg.png");
background-size: cover;
}
.bg-cont {
width: 50%;
height: 90%;
display: flex;
justify-content: flex-end;
align-items: center;
.bg {
width: 90%;
height: 70%;
img {
width: 100%;
height: 100%;
}
}
}
.lef-cont {
width: 50%;
height: 100%;
background-color: #7288fa;
box-sizing: border-box;
padding: 5%;
position: relative;
.circle1 {
position: absolute;
top: 8%;
left: 8%;
width: 50px;
height: 50px;
border-radius: 50%;
background-color: #8ea0fb;
}
.circle2 {
position: absolute;
top: calc(8% + 25px);
left: calc(8% + 25px);
width: 30px;
height: 30px;
border-radius: 50%;
background-color: #fff;
}
.tit {
margin-top: 10%;
margin-bottom: 20px;
display: flex;
flex-direction: column;
font-size: 32px;
color: #fff;
}
.tit-en {
display: flex;
flex-direction: column;
font-size: 20px;
color: #fff;
}
.img-cont {
width: 300px;
height: 300px;
margin: 80px auto;
img {
width: 100%;
height: 95%;
}
}
}
.bottom-info {
width: 100%;
height: 10%;
text-align: center;
font-size: 18px;
font-weight: bold;
color: #1e67e7;
}
.login {
width: 42%;
width: 50%;
height: 90%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
}
.title {
font-family: 'titleFont', sans-serif;
margin: 0 auto 50px;
text-align: center;
font-size: 32px;
color: #1E67E7;
font-family: 'titleFont', sans-serif;
margin: 0 auto 50px;
text-align: center;
font-size: 32px;
color: #1e67e7;
}
.login-form {
border-radius: 6px;
background: #ffffff;
width: 400px;
width: 60%;
padding: 25px;
.el-input {
@ -532,11 +772,11 @@ color: #1E67E7;
}
.login-divider:not(:empty)::before {
margin-right: .25em;
margin-right: 0.25em;
}
.login-divider:not(:empty)::after {
margin-left: .25em;
margin-left: 0.25em;
}
.login-icons {
@ -559,21 +799,4 @@ color: #1E67E7;
width: 50px;
height: 50px;
}
.bottom-info{
width: 100%;
height: 10%;
text-align: center;
font-size: 18px;
font-weight: bold;
color: #1E67E7;
}
</style>

View File

@ -12,23 +12,51 @@
<span>Welcome to the Safety Construction Warning System</span>
</div>
<div class="img-cont">
<img src="@/assets/images/warn-bg.png">
<img src="@/assets/images/warn-bg.png" />
</div>
</div>
<div class="register">
<el-form ref="registerForm" :model="registerForm" :rules="registerRules" class="register-form">
<el-form
ref="registerForm"
:model="registerForm"
:rules="registerRules"
class="register-form"
>
<h3 class="title">输变电工程施工现场安全风险预警系统</h3>
<el-form-item prop="nickName">
<el-input v-model="registerForm.nickName" type="text" auto-complete="off" placeholder="请输入姓名">
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon"/>
<el-input
v-model="registerForm.nickName"
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="mobile">
<el-input v-model="registerForm.mobile" type="text" auto-complete="off"
:placeholder="`请输入${config.registersConfig.phoneRegisters ? '手机号' : ''}${config.registersConfig.emailRegisters ? '/邮箱' : ''}`">
<svg-icon slot="prefix" icon-class="phone" class="el-input__icon input-icon"/>
<el-input
v-model="registerForm.mobile"
type="text"
auto-complete="off"
:placeholder="`请输入${
config.registersConfig.phoneRegisters
? '手机号'
: ''
}${
config.registersConfig.emailRegisters ? '/邮箱' : ''
}`"
>
<svg-icon
slot="prefix"
icon-class="phone"
class="el-input__icon input-icon"
/>
</el-input>
</el-form-item>
@ -41,7 +69,11 @@
@keyup.enter.native="handleRegister"
show-password
>
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/>
<svg-icon
slot="prefix"
icon-class="password"
class="el-input__icon input-icon"
/>
</el-input>
</el-form-item>
@ -49,12 +81,16 @@
<el-input
v-model="registerForm.confirmPassword"
type="password"
auto-complete="off"
placeholder="确认密码"
auto-complete="off"
@keyup.enter.native="handleRegister"
show-password
>
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/>
<svg-icon
slot="prefix"
icon-class="password"
class="el-input__icon input-icon"
/>
</el-input>
</el-form-item>
@ -66,48 +102,79 @@
style="width: 63%"
@keyup.enter.native="handleRegister"
>
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon"/>
<svg-icon
slot="prefix"
icon-class="validCode"
class="el-input__icon input-icon"
/>
</el-input>
<div class="register-code">
<img :src="codeUrl" @click="getCode" class="register-code-img"/>
<img
:src="codeUrl"
@click="getCode"
class="register-code-img"
/>
</div>
</el-form-item>
<el-form-item v-show="config.registersConfig.verificationCode" prop="verificationCode">
<el-input v-model="registerForm.verificationCode" :readonly="!isSendingCode" placeholder="请输入验证码">
<el-form-item
v-show="config.registersConfig.verificationCode"
prop="verificationCode"
>
<el-input
v-model="registerForm.verificationCode"
:readonly="!isSendingCode"
placeholder="请输入验证码"
>
<template slot="append">
<el-button
type="primary"
@click="sendCode"
:disabled="isSendingCode || captchaEnabled?!registerForm.code:false"
:disabled="
isSendingCode || captchaEnabled
? !registerForm.code
: false
"
class="send-code-button"
>
{{ isSendingCode ? `${countdown}s` : '获取验证码' }}
{{
isSendingCode
? `${countdown}s`
: '获取验证码'
}}
</el-button>
</template>
<svg-icon slot="prefix" icon-class="message" class="el-input__icon input-icon"/>
<svg-icon
slot="prefix"
icon-class="message"
class="el-input__icon input-icon"
/>
</el-input>
</el-form-item>
<el-form-item style="width:100%;">
<el-form-item style="width: 100%">
<el-button
:loading="loading"
size="medium"
type="primary"
style="width:100%;"
style="width: 100%"
@click.native.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 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-2024 bonus.vip All Rights Reserved.</span>
<span
>Copyright © 2018-2024 bonus.vip All Rights Reserved.</span
>
</div>
</div>
</div>
@ -125,11 +192,15 @@ export default {
return LOGIN
},
config() {
return JSON.parse(localStorage.getItem('systemConfig')) || {registersConfig: {
return (
JSON.parse(localStorage.getItem('systemConfig')) || {
registersConfig: {
phoneRegisters: true,
emailRegisters: true,
verificationCode:true
}}; // JSON
verificationCode: true,
},
}
) // JSON
},
},
data() {
@ -168,39 +239,65 @@ export default {
code: '',
uuid: '',
phoneUuid: '',
mobileCodeType: 'REGISTER'
mobileCodeType: 'REGISTER',
},
registerRules: {
nickName: [
{ required: true, trigger: 'blur', validator: validateNickName }
{
required: true,
trigger: 'blur',
validator: validateNickName,
},
],
mobile: [
{ required: true, message: '请输入手机号/邮箱', trigger: 'blur' },
{ validator: this.validateContact, trigger: 'blur' }
{
required: true,
message: '请输入手机号/邮箱',
trigger: 'blur',
},
{ validator: this.validateContact, trigger: 'blur' },
],
password: [
{ required: true, trigger: 'blur', message: '请输入您的密码' },
{ validator: validateNewPassword, trigger: 'blur' }
{
required: true,
trigger: 'blur',
message: '请输入您的密码',
},
{ validator: validateNewPassword, trigger: 'blur' },
],
confirmPassword: [
{ required: true, trigger: 'blur', message: '请再次输入您的密码' },
{ required: true, validator: equalToPassword, trigger: 'blur' }
{
required: true,
trigger: 'blur',
message: '请再次输入您的密码',
},
{
required: true,
validator: equalToPassword,
trigger: 'blur',
},
],
code: [
{
required: true,
trigger: 'change',
message: '请输入验证码',
},
],
code: [{ required: true, trigger: 'change', message: '请输入验证码' }]
},
loading: false,
captchaEnabled: true
captchaEnabled: true,
}
},
created() {
this.getCode()
},
methods: {
//
getCode() {
getCodeImg().then(res => {
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
getCodeImg().then((res) => {
this.captchaEnabled =
res.captchaEnabled === undefined ? true : res.captchaEnabled
if (this.captchaEnabled) {
this.codeUrl = 'data:image/gif;base64,' + res.img
this.registerForm.uuid = res.uuid
@ -210,19 +307,26 @@ export default {
//
handleRegister() {
this.$refs.registerForm.validate(valid => {
this.$refs.registerForm.validate((valid) => {
if (valid) {
this.loading = true
register(this.registerForm).then(res => {
register(this.registerForm)
.then((res) => {
const username = this.registerForm.username
this.$alert(`<font color="red">恭喜你,您的账号 ${username} 注册成功!</font>`, '系统提示', {
this.$alert(
`<font color="red">恭喜你,您的账号 ${username} 注册成功!</font>`,
'系统提示',
{
dangerouslyUseHTMLString: true,
type: 'success'
}).then(() => {
type: 'success',
},
)
.then(() => {
this.$router.push('/login')
}).catch(() => {
})
}).catch(() => {
.catch(() => {})
})
.catch(() => {
this.loading = false
if (this.captchaEnabled) {
this.getCode()
@ -238,8 +342,9 @@ export default {
this.$message.error('请先填写手机号')
return
}
this.$store.dispatch('GetPhoneCode', this.registerForm)
.then(res => {
this.$store
.dispatch('GetPhoneCode', this.registerForm)
.then((res) => {
console.log(res)
this.isSendingCode = true
this.countdown = 60
@ -247,6 +352,7 @@ export default {
this.countdown -= 1
if (this.countdown <= 0) {
clearInterval(timer)
/* this.isSendingCode = false */
}
}, 1000)
})
@ -263,7 +369,8 @@ export default {
//
validateContact(rule, value, callback) {
const phoneRegex = /^1[3-9]\d{9}$/
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
const emailRegex =
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
if (!value) {
return callback(new Error('请输入电子邮件或电话号码'))
@ -274,23 +381,70 @@ export default {
}
callback()
}
}
},
},
}
</script>
<style rel="stylesheet/scss" lang="scss">
.container {
.container-rg {
display: flex;
justify-content: flex-end;
align-items: center;
height: 100%;
background-image: url("../assets/images/bg.png");
background-size: cover;
}
.lef-cont {
width: 50%;
height: 100%;
background-color: #7288fa;
box-sizing: border-box;
padding: 5%;
position: relative;
.circle1 {
position: absolute;
top: 8%;
left: 8%;
width: 50px;
height: 50px;
border-radius: 50%;
background-color: #8ea0fb;
}
.circle2 {
position: absolute;
top: calc(8% + 25px);
left: calc(8% + 25px);
width: 30px;
height: 30px;
border-radius: 50%;
background-color: #fff;
}
.tit {
margin-top: 10%;
margin-bottom: 20px;
display: flex;
flex-direction: column;
font-size: 32px;
color: #fff;
}
.tit-en {
display: flex;
flex-direction: column;
font-size: 20px;
color: #fff;
}
.img-cont {
width: 300px;
height: 300px;
margin: 80px auto;
img {
width: 100%;
height: 95%;
}
}
}
.register {
width: 42%;
width: 50%;
display: flex;
justify-content: center;
align-items: center;