Initial project
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<template>
|
||||
<t-form class="tui-login-form" :data="loginRequest" :rules="rules" @submit="doSubmit">
|
||||
<t-form-item label="用户" name="user">
|
||||
<t-input class="user" v-model="loginRequest.data.user" placeholder="UID、邮箱或用户名" />
|
||||
</t-form-item>
|
||||
<t-form-item label="密码" name="password">
|
||||
<t-input type="password" v-model="loginRequest.data.password" placeholder="" />
|
||||
</t-form-item>
|
||||
<t-form-item label="验证码" name="captcha">
|
||||
<div class="captcha-box">
|
||||
<t-input class="captcha" v-model="loginRequest.captcha" placeholder="" />
|
||||
<captcha :api="CommonAPI.getCaptchaAPI()" :width="90" :height="28" :from="CaptchaFrom.LOGIN" />
|
||||
</div>
|
||||
</t-form-item>
|
||||
<div class="exec">
|
||||
<t-button
|
||||
class="button"
|
||||
type="submit"
|
||||
:loading="doSubmitting"
|
||||
:disabled="doSubmitting"
|
||||
>登录</t-button>
|
||||
</div>
|
||||
</t-form>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { Captcha, CaptchaData, CaptchaFrom, CommonAPI, LoginRequest, UserAPI, userStore } from "timi-web";
|
||||
import { Emits, useHandler } from "~/components/authorize-form/emits";
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
|
||||
const rules = {
|
||||
user: [
|
||||
{
|
||||
required: true,
|
||||
message: "请输入用户名"
|
||||
}
|
||||
],
|
||||
password: [
|
||||
{
|
||||
required: true,
|
||||
message: "请输入密码"
|
||||
}
|
||||
],
|
||||
captcha: [
|
||||
{
|
||||
required: true,
|
||||
message: "请输入验证码"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const emits = defineEmits<Emits>();
|
||||
const { onLoginSuccess } = useHandler(emits);
|
||||
|
||||
const doSubmitting = ref<boolean>(false);
|
||||
|
||||
const loginRequest = reactive<CaptchaData<LoginRequest>>({
|
||||
from: CaptchaFrom.LOGIN,
|
||||
captcha: "",
|
||||
data: {
|
||||
user: "",
|
||||
password: ""
|
||||
}
|
||||
});
|
||||
|
||||
const doSubmit = async () => {
|
||||
doSubmitting.value = true;
|
||||
UserAPI.login(loginRequest).then(async (response) => {
|
||||
await userStore.updateToken(response);
|
||||
await onLoginSuccess();
|
||||
doSubmitting.value = false;
|
||||
}).catch(msg => {
|
||||
MessagePlugin.error(msg, 5E3);
|
||||
doSubmitting.value = false;
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.tui-login-form {
|
||||
padding: 1rem;
|
||||
margin-left: -32px;
|
||||
|
||||
.captcha-box {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
.captcha {
|
||||
width: 7rem;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.exec {
|
||||
display: flex;
|
||||
margin-top: 2rem;
|
||||
justify-content: center;
|
||||
|
||||
.button {
|
||||
width: 8rem;
|
||||
margin-left: 32px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user