|
|
|
@ -1,25 +1,28 @@ |
|
|
|
|
import {FC, useRef, useState} from "react"; |
|
|
|
|
import {FC, useCallback, useEffect, useRef, useState} from "react"; |
|
|
|
|
import {Button, Form, Image, Input, View} from "@tarojs/components"; |
|
|
|
|
import {Profile} from "@/store"; |
|
|
|
|
import {userApi} from "@/api"; |
|
|
|
|
import Taro from "@tarojs/taro"; |
|
|
|
|
import {regexTel} from "@/utils/regu"; |
|
|
|
|
import styles from './check.module.scss' |
|
|
|
|
|
|
|
|
|
const uuid = () => { |
|
|
|
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { |
|
|
|
|
const r = Math.random() * 16 | 0 |
|
|
|
|
const v = c === 'x' ? r : (r & 0x3 | 0x8) |
|
|
|
|
return v.toString(16) |
|
|
|
|
}).replace(/-/g, '') |
|
|
|
|
} |
|
|
|
|
import code from '@/static/img/vCode.png' |
|
|
|
|
import tel from '@/static/img/tel.png' |
|
|
|
|
|
|
|
|
|
const Bing: FC = () => { |
|
|
|
|
const form = useRef<HTMLFormElement | null>(null) |
|
|
|
|
const [loading, setLoading] = useState(false) |
|
|
|
|
const [codeTime, setCodeTime] = useState(0) |
|
|
|
|
const {setUser, setToken, setCompany} = Profile.useContainer() |
|
|
|
|
const [captchaKey, setCaptchaKey] = useState(uuid()) |
|
|
|
|
const openid = localStorage.getItem('openid') |
|
|
|
|
const [phone_number, setPhone_number] = useState<number | undefined>(undefined) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (codeTime > 0) { |
|
|
|
|
setTimeout(() => { |
|
|
|
|
setCodeTime(codeTime - 1) |
|
|
|
|
}, 1000) |
|
|
|
|
} |
|
|
|
|
}, [codeTime]) |
|
|
|
|
|
|
|
|
|
async function Submit(data) { |
|
|
|
|
setLoading(true) |
|
|
|
@ -32,7 +35,6 @@ const Bing: FC = () => { |
|
|
|
|
try { |
|
|
|
|
const res = await userApi.checkout({ |
|
|
|
|
...value, |
|
|
|
|
catch_key: captchaKey, |
|
|
|
|
openid, |
|
|
|
|
}) |
|
|
|
|
if (res) { |
|
|
|
@ -42,27 +44,53 @@ const Bing: FC = () => { |
|
|
|
|
Taro.switchTab({url: '/pages/index/index'}) |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
setCaptchaKey(uuid) |
|
|
|
|
} |
|
|
|
|
setLoading(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const getCode = useCallback(async () => { |
|
|
|
|
if (codeTime > 0) return; |
|
|
|
|
if (!phone_number || !regexTel.exec(String(phone_number))) { |
|
|
|
|
Taro.showToast({title: '手机号错误', icon: 'error'}) |
|
|
|
|
setLoading(false) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
await userApi.getCode(phone_number) |
|
|
|
|
Taro.showToast({title: '请注意查收', icon: "none"}) |
|
|
|
|
setCodeTime(60) |
|
|
|
|
} catch (e) { |
|
|
|
|
Taro.showToast({title: '获取短信验证码失败', icon: "error"}) |
|
|
|
|
} |
|
|
|
|
}, [codeTime, phone_number]) |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<View className='h-10 pt-6 px-3 bg-white'> |
|
|
|
|
<Form className='form' onSubmit={Submit} ref={form}> |
|
|
|
|
<View className='item'> |
|
|
|
|
<View>手机号</View> |
|
|
|
|
<Input name='phone_number' placeholder={'请输入手机号'}/> |
|
|
|
|
<Form onSubmit={Submit} ref={form}> |
|
|
|
|
|
|
|
|
|
<View className={styles.formItem}> |
|
|
|
|
<View> |
|
|
|
|
<Image src={tel} className={styles.image}/> |
|
|
|
|
</View> |
|
|
|
|
<Input |
|
|
|
|
type='number' |
|
|
|
|
name='phone_number' |
|
|
|
|
placeholder={'请输入手机号'} |
|
|
|
|
value={String(phone_number)} |
|
|
|
|
onInput={(e) => setPhone_number(Number(e.detail.value))}/> |
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
<View className='item'> |
|
|
|
|
<View>验证码</View> |
|
|
|
|
<View className={styles.formItem}> |
|
|
|
|
<View> |
|
|
|
|
<Image src={code} className={styles.image}/> |
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
<View className='flex align-center flex-1'> |
|
|
|
|
<Input name='code' className='flex-1' placeholder={'请输入验证码'}/> |
|
|
|
|
<Image className='w-2 ml-1' style='height:28px' |
|
|
|
|
src={process.env.TARO_APP_API + '/api/v1/captcha?key=' + captchaKey} |
|
|
|
|
onClick={() => setCaptchaKey(uuid)}/> |
|
|
|
|
<Input type='number' name='code' className='flex-1' placeholder='请输入短信验证码'/> |
|
|
|
|
<View onClick={getCode}> |
|
|
|
|
{codeTime > 0 ? `${codeTime}` : '获取验证码'} |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
|