web-backset.cn/apps/server2/src/view/page/login/index.ts

75 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-02-11 13:21:06 +08:00
import './index.less';
import $ from 'cash-dom';
import { getVerifyCode, userLogin } from '../../api';
import { IUserLoginRequest } from 'src/dto/user.dto';
import { IVerifyCodeRequest } from 'src/dto/sms.dto';
import { RegUtil } from '@backset/util';
$(function () {
$('#page-signup')
.on('click', '#btn-switch-login-type', handleSwitchLoginType)
.on('click', '#btn-signup-password', handlePasswordLogin)
.on('click', '#btn-signup-verify', handleVerifyLogin)
.on('click', '#btn-verify-code', handleGetVerifyCode);
/**
*
*/
function handleGetVerifyCode() {
const params: IVerifyCodeRequest = { phone: '' + $('#tel').val() };
if (!RegUtil.PHONE.test(params.phone)) return;
// return message.error({ text: '手机号格式错误' });
$('#btn-verify-code').addClass('loading');
getVerifyCode(params).then((res) => {
console.log(res);
if (res) {
$('#btn-verify-code').removeClass('loading');
}
});
}
/**
*
*/
function handleVerifyLogin() {
const params: IUserLoginRequest = {
login_type: 'verifycode',
user_login: '' + $('#tel').val(),
verify_code: '' + $('#verify-code').val(),
};
userLogin(params).then((res) => {
console.log(res);
});
}
/**
*
*/
function handlePasswordLogin() {
const params: IUserLoginRequest = {
login_type: 'password',
user_login: '' + $('#username').val(),
user_pass: '' + $('#password').val(),
};
userLogin(params).then((res) => {
console.log(res);
});
}
/**
*
*/
function handleSwitchLoginType() {
const switchVerify = $(this).attr('data-login-type') === 'password';
if (switchVerify) {
$('#verify-form').removeClass('d-none');
$('#password-form').addClass('d-none');
$(this).attr('data-login-type', 'verify').html('密码登陆');
} else {
$('#verify-form').addClass('d-none');
$('#password-form').removeClass('d-none');
$(this).attr('data-login-type', 'password').html('验证码登陆');
}
}
});