feat: 短信登录
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { View, Text, Input, Button, Image } from '@tarojs/components';
|
import { View, Text, Input, Button, Image } from '@tarojs/components';
|
||||||
import Taro, { useRouter } from '@tarojs/taro';
|
import Taro, { useRouter } from '@tarojs/taro';
|
||||||
import { phone_auth_login, send_sms_code } from '../../../services/loginService';
|
import { phone_auth_login, send_sms_code, save_login_state } from '../../../services/loginService';
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
|
|
||||||
const VerificationPage: React.FC = () => {
|
const VerificationPage: React.FC = () => {
|
||||||
@@ -12,7 +12,7 @@ const VerificationPage: React.FC = () => {
|
|||||||
const [is_loading, setIsLoading] = useState(false);
|
const [is_loading, setIsLoading] = useState(false);
|
||||||
const [code_input_focus, setCodeInputFocus] = useState(false);
|
const [code_input_focus, setCodeInputFocus] = useState(false);
|
||||||
|
|
||||||
|
const { params: { redirect } } = useRouter();
|
||||||
|
|
||||||
// 计算登录按钮是否应该启用
|
// 计算登录按钮是否应该启用
|
||||||
const can_login = phone.length === 11 && verification_code.length === 6 && !is_loading;
|
const can_login = phone.length === 11 && verification_code.length === 6 && !is_loading;
|
||||||
@@ -120,15 +120,19 @@ const VerificationPage: React.FC = () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// 调用登录服务
|
// 调用登录服务
|
||||||
debugger;
|
// debugger;
|
||||||
const result = await phone_auth_login({ phone, verification_code });
|
const result = await phone_auth_login({ phone, verification_code });
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
save_login_state(result.token!, result.user_info!)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
if (redirect) {
|
||||||
|
Taro.redirectTo({ url: decodeURIComponent(redirect) });
|
||||||
|
} else {
|
||||||
Taro.redirectTo({
|
Taro.redirectTo({
|
||||||
url: '/pages/list/index'
|
url: '/pages/list/index'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}, 200);
|
}, 200);
|
||||||
} else {
|
} else {
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
|
|||||||
Reference in New Issue
Block a user