import './App.less' import { checkRoleApi, getPackApi, getServerListApi, pushLingkLogApi, sendPhoneCodeApi } from './api' import { useAjax } from './hooks/useAjax' import { App as AntdApp, Button, Form, Input, message, Select, Typography } from 'antd' import headerImg from './assets/image/header.png' import { isMobile } from './utils' import { useEffect, useState } from 'react' import iconSucc from './assets/image/icon-succ.png' function App() { /**************************************/ const [form] = Form.useForm() const serverId = Form.useWatch('serverId', form) const roleName = Form.useWatch('roleName', form) const userPhone = Form.useWatch('userPhone', form) const [linkLogId, setLinkLogId] = useState() const [serverList, setServerList] = useState<{ label: string, value: any }[]>([]) const [isCheckRoleSucc, setIsCheckRoleSucc] = useState(false) const [phone, setPhone] = useState() const [msg, setMsg] = useState('发送验证码') const [succ, setSucc] = useState(false) const [code, setCode] = useState() const getServerList = useAjax((params) => getServerListApi(params)) const pushLingkLog = useAjax((params) => pushLingkLogApi(params)) const checkRole = useAjax((params) => checkRoleApi(params)) const sendPhoneCode = useAjax((params) => sendPhoneCodeApi(params)) const getPack = useAjax((params) => getPackApi(params)) /**************************************/ useEffect(() => { pushLingkLog.run({ url: window.location.href }).then(res => { if (res?.data) { setLinkLogId(res?.data) } }) }, []) useEffect(() => { if (linkLogId) { getServerList.run({ linkLogId }).then(res => { if (res?.data) { setServerList(Object.keys(res.data).map(key => ({ label: res.data[key], value: key }))) } }) } }, [linkLogId]) const handleCheckRole = () => { checkRole.run({ linkLogId, serverId, roleName }).then(res => { if (res?.data?.result) { setIsCheckRoleSucc(true) message.success(res?.data?.msg || '验证成功') if (res?.data?.userPhone) { setPhone(res?.data?.userPhone) form.setFieldsValue({ userPhone: res?.data?.userPhone }) } } else { setIsCheckRoleSucc(false) message.error(res?.data?.msg || '验证失败') setPhone(undefined) } }) } // 发送验证码 const handleSendCode = () => { sendPhoneCode.run({ phoneNumber: userPhone, linkLogId }).then(res => { if (res?.data) { message.success('发送成功') setMsg(60) timeOut(60) } }) } const onFinish = (values: any) => { const params = JSON.parse(JSON.stringify(values)) delete params.serverId delete params.roleName getPack.run({ ...params, linkLogId }).then(res => { if (res?.data?.result) { setSucc(true) setCode(res?.data?.msg) } else { message.error(res?.data?.msg || '领取失败') } }) }; // 倒计时 const timeOut = (num: number) => { let timer: any = null if (num > 0) { timer = setTimeout(() => { setMsg(num - 1) timeOut(num - 1) clearTimeout(timer) timer = null }, 1000) } else { setMsg('发送验证码') } } return
{ setIsCheckRoleSucc(false) }} />
手机号码如果不正确,请联系客服修改 : undefined} rules={[ { required: phone ? false : true, validator(_rule, value) { if (phone) { return Promise.resolve() } if (!value) { return Promise.reject(new Error('请输入手机号!')) } else if (!isMobile(value)) { return Promise.reject(new Error('请输入正确的手机号!')) } return Promise.resolve() } } ]} >
{succ &&
领取成功
复制, tooltips: ['复制', '复制成功'] }}>{code}
}
} export default App