|
@@ -1,13 +1,11 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { onMounted, reactive, ref } from 'vue'
|
|
|
-import type { FormInstance } from 'element-plus'
|
|
|
+import { onMounted, reactive } from 'vue'
|
|
|
import type { RuleInfo } from '@/types/input'
|
|
|
import { useRequest } from '@/hooks/useRequest'
|
|
|
import router from '@/router'
|
|
|
import axiosInstance from '@/utils/axios/axiosInstance'
|
|
|
import MyButton from '@/components/form/MyButton.vue'
|
|
|
import MyInput from '@/components/form/MyInput.vue'
|
|
|
-import login from '@/router/login'
|
|
|
|
|
|
const { AllApi, analysisResCode } = useRequest()
|
|
|
|
|
@@ -22,35 +20,28 @@ const loginInfo = reactive<LoginInfoType>({
|
|
|
})
|
|
|
|
|
|
const userLogin = () => {
|
|
|
- axiosInstance
|
|
|
- .post(AllApi.userLogin, loginInfo)
|
|
|
- .then((data) => {
|
|
|
- let result = JSON.parse(JSON.stringify(data))
|
|
|
- analysisResCode(result, 'login')
|
|
|
- .then(() => {
|
|
|
- localStorage.setItem('token', result.token)
|
|
|
- localStorage.setItem('refreshToken', result.refreshToken)
|
|
|
- console.log('设置了')
|
|
|
- router.push('/')
|
|
|
- })
|
|
|
- .catch((err) => {
|
|
|
- console.log(err)
|
|
|
- })
|
|
|
- })
|
|
|
- .catch((err) => {
|
|
|
- console.log(err)
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-const onSubmit = (formEl: FormInstance | undefined) => {
|
|
|
- if (!formEl) return
|
|
|
- formEl.validate((valid, fields) => {
|
|
|
- if (valid) {
|
|
|
- userLogin()
|
|
|
- } else {
|
|
|
- console.log('error submit!', fields)
|
|
|
- }
|
|
|
+ let vaild = Object.keys(loginInfo).every((key) => {
|
|
|
+ return formFieldsRules[key].rules.every((item) => item.validator())
|
|
|
})
|
|
|
+ if (vaild) {
|
|
|
+ axiosInstance
|
|
|
+ .post(AllApi.userLogin, loginInfo)
|
|
|
+ .then((data) => {
|
|
|
+ let result = JSON.parse(JSON.stringify(data))
|
|
|
+ analysisResCode(result, 'login')
|
|
|
+ .then(() => {
|
|
|
+ localStorage.setItem('token', result.token)
|
|
|
+ localStorage.setItem('refreshToken', result.refreshToken)
|
|
|
+ router.push('/')
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err)
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const formFieldsRules = reactive<{
|
|
@@ -58,10 +49,10 @@ const formFieldsRules = reactive<{
|
|
|
}>({
|
|
|
userName: {
|
|
|
name: 'username',
|
|
|
+ placeholder: '请输入用户名',
|
|
|
rules: [
|
|
|
{
|
|
|
validator: (): boolean => {
|
|
|
- console.log(loginInfo.userName.trim())
|
|
|
return loginInfo.userName.trim().length > 0
|
|
|
},
|
|
|
errMsg: '用户名不能为空'
|
|
@@ -70,12 +61,13 @@ const formFieldsRules = reactive<{
|
|
|
validator: (): boolean => {
|
|
|
return loginInfo.userName.trim().length >= 1 && loginInfo.userName.trim().length <= 16
|
|
|
},
|
|
|
- errMsg: '长度为1-16位'
|
|
|
+ errMsg: '用户名长度为1-16位'
|
|
|
}
|
|
|
]
|
|
|
},
|
|
|
password: {
|
|
|
name: 'password',
|
|
|
+ placeholder: '请输入密码',
|
|
|
rules: [
|
|
|
{
|
|
|
validator: (): boolean => {
|
|
@@ -87,7 +79,7 @@ const formFieldsRules = reactive<{
|
|
|
validator: (): boolean => {
|
|
|
return loginInfo.password.trim().length >= 1 && loginInfo.password.trim().length <= 16
|
|
|
},
|
|
|
- errMsg: '长度为1-16位'
|
|
|
+ errMsg: '密码长度为1-16位'
|
|
|
}
|
|
|
]
|
|
|
}
|
|
@@ -101,16 +93,23 @@ onMounted(() => {})
|
|
|
<div class="container">
|
|
|
<div class="loginBox">
|
|
|
<div class="banner"></div>
|
|
|
- <div class="logo"></div>
|
|
|
+ <div class="logoBox">
|
|
|
+ <div class="logoImg">
|
|
|
+ <el-image :fit="'fill'" class="logoImg" src="/src/assets/logo.svg"></el-image>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <span class="logoText">淳皓科技</span>
|
|
|
+ </div>
|
|
|
<div class="content">
|
|
|
<div class="loginFormBox">
|
|
|
- <div class="loginFormTitle">登录管理系统</div>
|
|
|
+ <div class="loginFormTitle">登录淳皓游戏管理系统</div>
|
|
|
<div class="loginFormSubTitle">登录管理系统</div>
|
|
|
<form class="loginForm">
|
|
|
<div class="loginFormItem">
|
|
|
<MyInput
|
|
|
- p-input-type="'text'"
|
|
|
+ :p-input-type="'text'"
|
|
|
:pinput-rules="formFieldsRules.userName"
|
|
|
+ :placeholder="formFieldsRules.userName.placeholder"
|
|
|
v-model="loginInfo.userName"
|
|
|
class="userName"
|
|
|
>
|
|
@@ -121,8 +120,9 @@ onMounted(() => {})
|
|
|
</div>
|
|
|
<div class="loginFormItem">
|
|
|
<MyInput
|
|
|
- p-input-type="'password'"
|
|
|
+ :p-input-type="'password'"
|
|
|
:pinput-rules="formFieldsRules.password"
|
|
|
+ :placeholder="formFieldsRules.password.placeholder"
|
|
|
v-model="loginInfo.password"
|
|
|
class="password"
|
|
|
>
|
|
@@ -145,7 +145,7 @@ onMounted(() => {})
|
|
|
.container {
|
|
|
width: 100vw;
|
|
|
height: 100vh;
|
|
|
- background-color: lightblue;
|
|
|
+ // background-color: lightblue;
|
|
|
position: relative;
|
|
|
font-family:
|
|
|
Inter,
|
|
@@ -168,14 +168,42 @@ onMounted(() => {})
|
|
|
transform: translate(-50%, -50%);
|
|
|
width: 900px;
|
|
|
height: 500px;
|
|
|
- background-color: lightcoral;
|
|
|
+ // background-color: lightcoral;
|
|
|
display: flex;
|
|
|
}
|
|
|
|
|
|
.banner {
|
|
|
width: 400px;
|
|
|
height: 100%;
|
|
|
- background-color: lightgreen;
|
|
|
+ background-image: linear-gradient(to top, #30cfd0 0%, #330867 100%);
|
|
|
+ // background-color: lightgreen;
|
|
|
+}
|
|
|
+
|
|
|
+.logoBox {
|
|
|
+ box-sizing: border-box;
|
|
|
+ position: fixed;
|
|
|
+ left: 24px;
|
|
|
+ top: 22px;
|
|
|
+ min-height: 33px;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+}
|
|
|
+
|
|
|
+.logoImg {
|
|
|
+ width: 33px;
|
|
|
+ height: 33px;
|
|
|
+}
|
|
|
+
|
|
|
+.logoText {
|
|
|
+ display: inline-flex;
|
|
|
+ align-items: center;
|
|
|
+ height: 100%;
|
|
|
+ min-height: 32px;
|
|
|
+ margin-right: 4px;
|
|
|
+ margin-left: 10px;
|
|
|
+ color: white;
|
|
|
+ font-size: 20px;
|
|
|
+ font-weight: 600;
|
|
|
}
|
|
|
|
|
|
.content {
|
|
@@ -185,11 +213,14 @@ onMounted(() => {})
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
justify-content: center;
|
|
|
+ border: 1px solid #e5e6eb;
|
|
|
+ border-left: none;
|
|
|
}
|
|
|
|
|
|
.loginFormBox {
|
|
|
width: 320px;
|
|
|
}
|
|
|
+
|
|
|
.loginFormTitle {
|
|
|
color: black;
|
|
|
font-weight: 500;
|
|
@@ -207,7 +238,7 @@ onMounted(() => {})
|
|
|
width: 100%;
|
|
|
display: flex;
|
|
|
flex-direction: column;
|
|
|
-
|
|
|
+ margin-top: 15px;
|
|
|
align-items: center;
|
|
|
}
|
|
|
|
|
@@ -218,7 +249,6 @@ onMounted(() => {})
|
|
|
|
|
|
.loginBtn {
|
|
|
margin-bottom: 30px;
|
|
|
- margin-top: 30px;
|
|
|
}
|
|
|
|
|
|
.userName {
|