import { Text, View } from "@tarojs/components"; import "./index.scss"; import { Button, Form, Input } from "@nutui/nutui-react-taro"; import { verifyPhone } from "../../utils"; import { sendCodeApi, smsLoginApi } from "../../api/auth"; import { setStorageSync, redirectTo } from "@tarojs/taro"; import { useState } from "react"; const LoginIndex = () => { const [form] = Form.useForm(); const [showCode, setShowCode] = useState(false); const mobile = Form.useWatch("mobile", form); const code = Form.useWatch("code", form); /** * 发送验证码 */ const sendCode = async () => { console.log(mobile); setShowCode(true); await sendCodeApi({ mobile }).then((res) => { console.log(res); }); }; /** * 短信登录 */ const smsLogin = async () => { await smsLoginApi({ mobile, code }).then((res: any) => { const { data } = res; const { token, username, mobile, is_vip, vip_code, vip_info, circle_info, } = data; setStorageSync("Authorization", token); setStorageSync("User", { username, mobile, is_vip, vip_code }); setStorageSync("vipInfo", vip_info); setStorageSync("circleInfo", circle_info); redirectTo({ url: "/pages/index/index" }); }); }; return ( 手机号登录
{!showCode && ( )} {/* */} {showCode && ( )} {/* */} {/* */}
{showCode ? ( ) : ( )}
); }; export default LoginIndex;