|
@@ -1,9 +1,11 @@
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
|
|
+import { useRouter } from 'vue-router'
|
|
|
import ErrorTips from './components/ErrorTips.vue'
|
|
import ErrorTips from './components/ErrorTips.vue'
|
|
|
|
|
|
|
|
|
|
+const router = useRouter()
|
|
|
const loginForm = ref({
|
|
const loginForm = ref({
|
|
|
- username: '',
|
|
|
|
|
- password: '',
|
|
|
|
|
|
|
+ username: 'ra.admin',
|
|
|
|
|
+ password: 'abc123456789',
|
|
|
email: '',
|
|
email: '',
|
|
|
code: ''
|
|
code: ''
|
|
|
})
|
|
})
|
|
@@ -11,18 +13,105 @@ const loginForm = ref({
|
|
|
const status = ref('login')
|
|
const status = ref('login')
|
|
|
watch(status, () => {
|
|
watch(status, () => {
|
|
|
loginForm.value = {
|
|
loginForm.value = {
|
|
|
- username: '',
|
|
|
|
|
- password: '',
|
|
|
|
|
|
|
+ username: 'ra.admin',
|
|
|
|
|
+ password: 'abc123456789',
|
|
|
email: '',
|
|
email: '',
|
|
|
code: ''
|
|
code: ''
|
|
|
}
|
|
}
|
|
|
|
|
+ loginError.value = {
|
|
|
|
|
+ username: false,
|
|
|
|
|
+ password: false,
|
|
|
|
|
+ email: false,
|
|
|
|
|
+ code: false
|
|
|
|
|
+ }
|
|
|
|
|
+ verificationCode.value = ''
|
|
|
|
|
+ getCode()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-const loginError = ref({
|
|
|
|
|
|
|
+const loginError: any = ref({
|
|
|
username: false,
|
|
username: false,
|
|
|
password: false,
|
|
password: false,
|
|
|
|
|
+ email: false,
|
|
|
code: false
|
|
code: false
|
|
|
})
|
|
})
|
|
|
|
|
+const verificationCode = ref()
|
|
|
|
|
+// 获取验证码
|
|
|
|
|
+const getCode = () => {
|
|
|
|
|
+ $api.getVerifcationCode().then((res: any) => {
|
|
|
|
|
+ if (res.code === 200) {
|
|
|
|
|
+ verificationCode.value = `data:image/png;base64,${res.data.imagePngBase64}`
|
|
|
|
|
+ } else {
|
|
|
|
|
+ verificationCode.value = ''
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+getCode()
|
|
|
|
|
+
|
|
|
|
|
+// 验证当前用户是否存在
|
|
|
|
|
+const handleCheckUser = () => {
|
|
|
|
|
+ if (!loginForm.value.username) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ // 这里是验证用户是否存在的逻辑
|
|
|
|
|
+ $api.isUserNameExit({ uname: loginForm.value.username }).then((res: any) => {
|
|
|
|
|
+ if (res.code === 200) {
|
|
|
|
|
+ if (res.data.msg !== 'no_exist') {
|
|
|
|
|
+ isUserNameExit.value = true
|
|
|
|
|
+ } else {
|
|
|
|
|
+ loginError.value.username = true
|
|
|
|
|
+ isUserNameExit.value = false
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ isUserNameExit.value = false
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 点击登录按钮
|
|
|
|
|
+const handleLogin = () => {
|
|
|
|
|
+ // 这里是登录逻辑
|
|
|
|
|
+ $api
|
|
|
|
|
+ .login({
|
|
|
|
|
+ uname: loginForm.value.username,
|
|
|
|
|
+ psw: loginForm.value.password,
|
|
|
|
|
+ verifcation_code: loginForm.value.code
|
|
|
|
|
+ })
|
|
|
|
|
+ .then((res: any) => {
|
|
|
|
|
+ if (res.code === 200) {
|
|
|
|
|
+ const { data } = res
|
|
|
|
|
+ if (data.msg === 'today') {
|
|
|
|
|
+ ElMessageBox.alert('Your password will expire today, please reset', 'Prompt', {
|
|
|
|
|
+ confirmButtonText: 'OK',
|
|
|
|
|
+ type: 'warning',
|
|
|
|
|
+ confirmButtonClass: 'el-button--dark'
|
|
|
|
|
+ })
|
|
|
|
|
+ } else if (data.msg === 'last') {
|
|
|
|
|
+ ElMessageBox.alert(
|
|
|
|
|
+ `Your password will expire in${data.data}days, please reset`,
|
|
|
|
|
+ 'Prompt',
|
|
|
|
|
+ {
|
|
|
|
|
+ confirmButtonText: 'OK',
|
|
|
|
|
+ type: 'warning',
|
|
|
|
|
+ confirmButtonClass: 'el-button--dark'
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ router.push('/')
|
|
|
|
|
+ } else if (res.code === 400) {
|
|
|
|
|
+ // 验证码错误
|
|
|
|
|
+ if (res.data.msg === 'password_error') {
|
|
|
|
|
+ loginError.value.password = true
|
|
|
|
|
+ } else if (res.data.msg === 'verifcation_error') {
|
|
|
|
|
+ loginError.value.code = true
|
|
|
|
|
+ } else if (res.data.msg === 'error_times') {
|
|
|
|
|
+ errorTipsRef.value.openDialog()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .finally(() => {
|
|
|
|
|
+ getCode()
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
const isUserNameExit = ref(false)
|
|
const isUserNameExit = ref(false)
|
|
|
|
|
|
|
@@ -31,18 +120,26 @@ const handleForgot = () => {
|
|
|
isUserNameExit.value = false
|
|
isUserNameExit.value = false
|
|
|
handleDeleteEmailTips()
|
|
handleDeleteEmailTips()
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-const handleSubmit = () => {
|
|
|
|
|
- if (status.value === 'reset') {
|
|
|
|
|
- isEmailTips.value = true
|
|
|
|
|
- status.value = 'login'
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
|
|
+const handleSendPassword = () => {
|
|
|
|
|
+ // 这里是发送密码逻辑
|
|
|
|
|
+ $api
|
|
|
|
|
+ .forgotPassword({
|
|
|
|
|
+ login: loginForm.value.username,
|
|
|
|
|
+ email: loginForm.value.email
|
|
|
|
|
+ })
|
|
|
|
|
+ .then((res: any) => {
|
|
|
|
|
+ if (res.code === 200) {
|
|
|
|
|
+ isEmailTips.value = true
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const isEmailTips = ref(false)
|
|
const isEmailTips = ref(false)
|
|
|
-const handleDeleteEmailTips = () => {
|
|
|
|
|
|
|
+const handleDeleteEmailTips = (type?: any) => {
|
|
|
isEmailTips.value = false
|
|
isEmailTips.value = false
|
|
|
|
|
+ if (type) {
|
|
|
|
|
+ loginError.value[type] = false
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const errorTipsRef = ref()
|
|
const errorTipsRef = ref()
|
|
@@ -73,8 +170,8 @@ const errorTipsRef = ref()
|
|
|
v-model="loginForm.username"
|
|
v-model="loginForm.username"
|
|
|
class="user-name"
|
|
class="user-name"
|
|
|
placeholder="Please input user name"
|
|
placeholder="Please input user name"
|
|
|
- @focus="handleDeleteEmailTips"
|
|
|
|
|
- @change="isUserNameExit = true"
|
|
|
|
|
|
|
+ @focus="handleDeleteEmailTips('username')"
|
|
|
|
|
+ @change="handleCheckUser"
|
|
|
>
|
|
>
|
|
|
<template #prefix>
|
|
<template #prefix>
|
|
|
<span class="font_family icon-icon_username_b"></span>
|
|
<span class="font_family icon-icon_username_b"></span>
|
|
@@ -95,7 +192,7 @@ const errorTipsRef = ref()
|
|
|
type="password"
|
|
type="password"
|
|
|
placeholder="Please input password"
|
|
placeholder="Please input password"
|
|
|
show-password
|
|
show-password
|
|
|
- @focus="handleDeleteEmailTips"
|
|
|
|
|
|
|
+ @focus="handleDeleteEmailTips('password')"
|
|
|
><template #prefix>
|
|
><template #prefix>
|
|
|
<span class="font_family icon-icon_password_b"></span>
|
|
<span class="font_family icon-icon_password_b"></span>
|
|
|
</template>
|
|
</template>
|
|
@@ -107,14 +204,14 @@ const errorTipsRef = ref()
|
|
|
class="verification-code"
|
|
class="verification-code"
|
|
|
v-model="loginForm.code"
|
|
v-model="loginForm.code"
|
|
|
placeholder="Verification Code"
|
|
placeholder="Verification Code"
|
|
|
- @focus="handleDeleteEmailTips"
|
|
|
|
|
|
|
+ @focus="handleDeleteEmailTips('code')"
|
|
|
>
|
|
>
|
|
|
<template #append>
|
|
<template #append>
|
|
|
- <img class="verification-code-img" src="./image/code.png" alt="" />
|
|
|
|
|
|
|
+ <img class="verification-code-img" :src="verificationCode" alt="" />
|
|
|
</template>
|
|
</template>
|
|
|
</el-input>
|
|
</el-input>
|
|
|
<div class="error" v-if="loginError.code">Incorrect verification code.</div>
|
|
<div class="error" v-if="loginError.code">Incorrect verification code.</div>
|
|
|
- <el-button @click="handleSubmit" class="el-button--dark login-btn">Login</el-button>
|
|
|
|
|
|
|
+ <el-button @click="handleLogin" class="el-button--dark login-btn">Login</el-button>
|
|
|
</div>
|
|
</div>
|
|
|
<template #footer>
|
|
<template #footer>
|
|
|
<div class="license">
|
|
<div class="license">
|
|
@@ -125,7 +222,7 @@ const errorTipsRef = ref()
|
|
|
</el-card>
|
|
</el-card>
|
|
|
<el-card class="login-card" v-else>
|
|
<el-card class="login-card" v-else>
|
|
|
<div class="title">
|
|
<div class="title">
|
|
|
- <span class="welcome"> Reset Password</span>
|
|
|
|
|
|
|
+ <span class="welcome">Password Retrieval</span>
|
|
|
<span class="tips">We'll send you new password in email</span>
|
|
<span class="tips">We'll send you new password in email</span>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="login-form">
|
|
<div class="login-form">
|
|
@@ -138,7 +235,7 @@ const errorTipsRef = ref()
|
|
|
v-model="loginForm.username"
|
|
v-model="loginForm.username"
|
|
|
class="user-name"
|
|
class="user-name"
|
|
|
placeholder="Please input user name"
|
|
placeholder="Please input user name"
|
|
|
- @focus="handleDeleteEmailTips"
|
|
|
|
|
|
|
+ @focus="handleDeleteEmailTips('username')"
|
|
|
>
|
|
>
|
|
|
<template #prefix>
|
|
<template #prefix>
|
|
|
<span class="font_family icon-icon_username_b"></span>
|
|
<span class="font_family icon-icon_username_b"></span>
|
|
@@ -155,10 +252,10 @@ const errorTipsRef = ref()
|
|
|
</div>
|
|
</div>
|
|
|
<el-input
|
|
<el-input
|
|
|
ref="passWordRef"
|
|
ref="passWordRef"
|
|
|
- :class="{ 'is-error': loginError.password }"
|
|
|
|
|
|
|
+ :class="{ 'is-error': loginError.email }"
|
|
|
v-model="loginForm.email"
|
|
v-model="loginForm.email"
|
|
|
placeholder="Please input your email address"
|
|
placeholder="Please input your email address"
|
|
|
- show-password
|
|
|
|
|
|
|
+ @focus="handleDeleteEmailTips('email')"
|
|
|
><template #prefix>
|
|
><template #prefix>
|
|
|
<span class="font_family icon-icon_email_b"></span>
|
|
<span class="font_family icon-icon_email_b"></span>
|
|
|
</template>
|
|
</template>
|
|
@@ -172,13 +269,16 @@ const errorTipsRef = ref()
|
|
|
class="verification-code"
|
|
class="verification-code"
|
|
|
v-model="loginForm.code"
|
|
v-model="loginForm.code"
|
|
|
placeholder="Verification Code"
|
|
placeholder="Verification Code"
|
|
|
|
|
+ @focus="handleDeleteEmailTips('code')"
|
|
|
><template #append>
|
|
><template #append>
|
|
|
- <img class="verification-code-img" src="./image/code.png" alt="" /> </template
|
|
|
|
|
|
|
+ <img class="verification-code-img" :src="verificationCode" alt="" /> </template
|
|
|
></el-input>
|
|
></el-input>
|
|
|
<div class="error" v-if="loginError.code">
|
|
<div class="error" v-if="loginError.code">
|
|
|
This is the prompt information given by the verification
|
|
This is the prompt information given by the verification
|
|
|
</div>
|
|
</div>
|
|
|
- <el-button @click="handleSubmit" class="el-button--dark login-btn">Send Password</el-button>
|
|
|
|
|
|
|
+ <el-button @click="handleSendPassword" class="el-button--dark login-btn"
|
|
|
|
|
+ >Send Password</el-button
|
|
|
|
|
+ >
|
|
|
<div @click="status = 'login'" class="back-text">
|
|
<div @click="status = 'login'" class="back-text">
|
|
|
<span class="font_family icon-icon_back_b"></span>
|
|
<span class="font_family icon-icon_back_b"></span>
|
|
|
<span class="text"> Back to login</span>
|
|
<span class="text"> Back to login</span>
|