|
@@ -1,30 +1,26 @@
|
|
|
<script setup lang="ts">
|
|
|
import { onMounted, reactive, ref } from 'vue'
|
|
|
-import type { FormRules, FormInstance } from 'element-plus'
|
|
|
+import type { FormInstance } from 'element-plus'
|
|
|
+import type { RuleInfo } from '@/types/input'
|
|
|
import { useRequest } from '@/hooks/useRequest'
|
|
|
import router from '@/router'
|
|
|
import axiosInstance from '@/utils/axios/axiosInstance'
|
|
|
-import TextInput from '@/components/input/TextInput.vue'
|
|
|
+import MyButton from '@/components/form/MyButton.vue'
|
|
|
+import MyInput from '@/components/form/MyInput.vue'
|
|
|
+import login from '@/router/login'
|
|
|
|
|
|
const { AllApi, analysisResCode } = useRequest()
|
|
|
|
|
|
-interface loginRuleType {
|
|
|
+interface LoginInfoType {
|
|
|
userName: string
|
|
|
password: string
|
|
|
}
|
|
|
|
|
|
-const rules = reactive<FormRules<loginRuleType>>({
|
|
|
- userName: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
|
|
- password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
|
|
|
-})
|
|
|
-
|
|
|
-const loginInfo = reactive<loginRuleType>({
|
|
|
+const loginInfo = reactive<LoginInfoType>({
|
|
|
userName: '',
|
|
|
password: ''
|
|
|
})
|
|
|
|
|
|
-const loginFormRef = ref<FormInstance>()
|
|
|
-
|
|
|
const userLogin = () => {
|
|
|
axiosInstance
|
|
|
.post(AllApi.userLogin, loginInfo)
|
|
@@ -57,6 +53,46 @@ const onSubmit = (formEl: FormInstance | undefined) => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+const formFieldsRules = reactive<{
|
|
|
+ [key: string]: RuleInfo
|
|
|
+}>({
|
|
|
+ userName: {
|
|
|
+ name: 'username',
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ validator: (): boolean => {
|
|
|
+ console.log(loginInfo.userName.trim())
|
|
|
+ return loginInfo.userName.trim().length > 0
|
|
|
+ },
|
|
|
+ errMsg: '用户名不能为空'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ validator: (): boolean => {
|
|
|
+ return loginInfo.userName.trim().length >= 1 && loginInfo.userName.trim().length <= 16
|
|
|
+ },
|
|
|
+ errMsg: '长度为1-16位'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ password: {
|
|
|
+ name: 'password',
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ validator: (): boolean => {
|
|
|
+ return loginInfo.password.trim().length > 0
|
|
|
+ },
|
|
|
+ errMsg: '密码不能为空'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ validator: (): boolean => {
|
|
|
+ return loginInfo.password.trim().length >= 1 && loginInfo.password.trim().length <= 16
|
|
|
+ },
|
|
|
+ errMsg: '长度为1-16位'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
// 加载数据
|
|
|
onMounted(() => {})
|
|
|
</script>
|
|
@@ -71,30 +107,34 @@ onMounted(() => {})
|
|
|
<div class="loginFormTitle">登录管理系统</div>
|
|
|
<div class="loginFormSubTitle">登录管理系统</div>
|
|
|
<form class="loginForm">
|
|
|
- <TextInput
|
|
|
- :input-obj="{
|
|
|
- inputType: 'text',
|
|
|
- inputValue: loginInfo.userName
|
|
|
- }"
|
|
|
- ></TextInput>
|
|
|
+ <div class="loginFormItem">
|
|
|
+ <MyInput
|
|
|
+ p-input-type="'text'"
|
|
|
+ :pinput-rules="formFieldsRules.userName"
|
|
|
+ v-model="loginInfo.userName"
|
|
|
+ class="userName"
|
|
|
+ >
|
|
|
+ <template #icon>
|
|
|
+ <UserFilled />
|
|
|
+ </template>
|
|
|
+ </MyInput>
|
|
|
+ </div>
|
|
|
+ <div class="loginFormItem">
|
|
|
+ <MyInput
|
|
|
+ p-input-type="'password'"
|
|
|
+ :pinput-rules="formFieldsRules.password"
|
|
|
+ v-model="loginInfo.password"
|
|
|
+ class="password"
|
|
|
+ >
|
|
|
+ <template #icon>
|
|
|
+ <icon-mdi-password></icon-mdi-password>
|
|
|
+ </template>
|
|
|
+ </MyInput>
|
|
|
+ </div>
|
|
|
+ <div class="loginFormItem loginBtn">
|
|
|
+ <MyButton @click-event="userLogin" :btn-info="{ text: '登录' }"></MyButton>
|
|
|
+ </div>
|
|
|
</form>
|
|
|
- <!-- <el-form
|
|
|
- ref="loginFormRef"
|
|
|
- class="loginForm"
|
|
|
- :rules="rules"
|
|
|
- :model="loginInfo"
|
|
|
- label-width="auto"
|
|
|
- >
|
|
|
- <el-form-item label="用户名" prop="userName">
|
|
|
- <el-input class="formItem" v-model="loginInfo.userName" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="密码" prop="password">
|
|
|
- <el-input class="formItem" v-model="loginInfo.password" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item>
|
|
|
- <el-button type="primary" @click="onSubmit(loginFormRef)">登录</el-button>
|
|
|
- </el-form-item>
|
|
|
- </el-form> -->
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -107,6 +147,18 @@ onMounted(() => {})
|
|
|
height: 100vh;
|
|
|
background-color: lightblue;
|
|
|
position: relative;
|
|
|
+ font-family:
|
|
|
+ Inter,
|
|
|
+ -apple-system,
|
|
|
+ BlinkMacSystemFont,
|
|
|
+ PingFang SC,
|
|
|
+ Hiragino Sans GB,
|
|
|
+ noto sans,
|
|
|
+ Microsoft YaHei,
|
|
|
+ Helvetica Neue,
|
|
|
+ Helvetica,
|
|
|
+ Arial,
|
|
|
+ sans-serif;
|
|
|
}
|
|
|
|
|
|
.loginBox {
|
|
@@ -159,7 +211,17 @@ onMounted(() => {})
|
|
|
align-items: center;
|
|
|
}
|
|
|
|
|
|
-.formItem {
|
|
|
+.loginFormItem {
|
|
|
width: 100%;
|
|
|
+ // min-height: 52px;
|
|
|
+}
|
|
|
+
|
|
|
+.loginBtn {
|
|
|
+ margin-bottom: 30px;
|
|
|
+ margin-top: 30px;
|
|
|
+}
|
|
|
+
|
|
|
+.userName {
|
|
|
+ margin: 1% 0;
|
|
|
}
|
|
|
</style>
|