upper to timi-ts
This commit is contained in:
@@ -6,10 +6,10 @@
|
||||
<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">
|
||||
<t-form-item v-if="captcha" label="验证码" name="captcha">
|
||||
<div class="captcha-box">
|
||||
<t-input class="captcha" v-model="loginRequest.captcha" placeholder="" />
|
||||
<captcha :api="CommonAPI.getCaptchaAPI()" :width="90" :height="28" />
|
||||
<captcha :request="captcha" :width="90" :height="28" @update="onCaptchaUpdate" />
|
||||
</div>
|
||||
</t-form-item>
|
||||
<div class="exec">
|
||||
@@ -24,10 +24,22 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { Captcha, CaptchaData, CommonAPI, LoginRequest, UserAPI } from "timi-web";
|
||||
import { Captcha } from "timi-web";
|
||||
import { Emits, useHandler } from "~/components/authorize-form/emits";
|
||||
import type {
|
||||
CaptchaData,
|
||||
CaptchaRequest,
|
||||
CaptchaResult,
|
||||
LoginHandler,
|
||||
LoginRequest
|
||||
} from "./types";
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
|
||||
const props = defineProps<{
|
||||
captcha?: CaptchaRequest;
|
||||
login?: LoginHandler;
|
||||
}>();
|
||||
|
||||
const rules = {
|
||||
user: [
|
||||
{
|
||||
@@ -63,16 +75,25 @@ const loginRequest = reactive<CaptchaData<LoginRequest>>({
|
||||
}
|
||||
});
|
||||
|
||||
function onCaptchaUpdate(result: CaptchaResult) {
|
||||
loginRequest.captchaId = result.id;
|
||||
}
|
||||
|
||||
const doSubmit = async () => {
|
||||
const login = props.login;
|
||||
if (!login) {
|
||||
MessagePlugin.error("未配置登录处理函数", 5E3);
|
||||
return;
|
||||
}
|
||||
doSubmitting.value = true;
|
||||
UserAPI.login(loginRequest).then(async (response) => {
|
||||
// await userStore.updateToken(response);
|
||||
try {
|
||||
await login(loginRequest);
|
||||
await onLoginSuccess();
|
||||
} catch (error) {
|
||||
MessagePlugin.error(String(error), 5E3);
|
||||
} finally {
|
||||
doSubmitting.value = false;
|
||||
}).catch(msg => {
|
||||
MessagePlugin.error(msg, 5E3);
|
||||
doSubmitting.value = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user