🐞 fix:

修复已知bug
This commit is contained in:
john 2024-05-24 10:21:29 +08:00
parent 2173394a71
commit 3795aedede
5 changed files with 170 additions and 133 deletions

View File

@ -1,10 +1,5 @@
import React from 'react' import ReactDOM from "react-dom/client";
import ReactDOM from 'react-dom/client' import App from "./App.tsx";
import App from './App.tsx' import "./index.css";
import './index.css'
ReactDOM.createRoot(document.getElementById('root')!).render( ReactDOM.createRoot(document.getElementById("root")!).render(<App />);
<React.StrictMode>
<App />
</React.StrictMode>,
)

View File

@ -7,12 +7,12 @@ import { useCountdown } from "../hooks/useCountdown";
import { sendCode, signUp } from "../api"; import { sendCode, signUp } from "../api";
import { sendCodeTypes, signUpTypes, ErrorType } from "../type/SignIn"; import { sendCodeTypes, signUpTypes, ErrorType } from "../type/SignIn";
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile";
import { useLocation, useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { Md5 } from "ts-md5"; import { Md5 } from "ts-md5";
import { FormInstance } from "antd-mobile/es/components/form";
function EmailForm() { function EmailForm() {
const formRef: any = useRef() const formRef = useRef<FormInstance>(null);
const location = useLocation()
const navigate = useNavigate(); const navigate = useNavigate();
const { t } = useTranslation(); const { t } = useTranslation();
const { start, time } = useCountdown(); const { start, time } = useCountdown();
@ -37,24 +37,22 @@ function EmailForm() {
account: email, account: email,
areaCode: "", areaCode: "",
status: 2, status: 2,
signature: Md5.hashStr( signature: Md5.hashStr(`Neer${email},${2},${timestamp}GetCode`),
`Neer${email},${2},${timestamp}GetCode` timestamp,
),
timestamp
}, },
config config
); );
console.log("res", res); console.log("res", res);
if (res.status === 200 && res.data.data.sms) { if (res.status === 200 && res.data.data.sms) {
Toast.show({ Toast.show({
content: t('send successfully'), content: t("send successfully"),
afterClose: () => { afterClose: () => {
start(60 * 1000); start(60 * 1000);
}, },
}); });
} else { } else {
Toast.show({ Toast.show({
content: t('Send failure'), content: t("Send failure"),
afterClose: () => { afterClose: () => {
// start(60 * 1000); // start(60 * 1000);
}, },
@ -62,7 +60,7 @@ function EmailForm() {
} }
} catch (error: unknown) { } catch (error: unknown) {
// 检查 error 是否是 ErrorType 类型 // 检查 error 是否是 ErrorType 类型
if (typeof error === 'object' && error !== null && 'msg' in error) { if (typeof error === "object" && error !== null && "msg" in error) {
const typedError = error as ErrorType; // 使用类型断言 const typedError = error as ErrorType; // 使用类型断言
Toast.show({ Toast.show({
content: typedError.msg, content: typedError.msg,
@ -72,27 +70,12 @@ function EmailForm() {
}); });
} else { } else {
// 处理不是 ErrorType 类型的错误 // 处理不是 ErrorType 类型的错误
console.log('An unexpected error occurred'); console.log("An unexpected error occurred");
} }
console.warn(error); console.warn(error);
} }
}; };
const getShareCode = (url: string) => {
const newStr = url.replace('?', '')?.split('&')
if (!newStr) return ''
const shareStr = newStr.find(item => item.includes('shareCode'))
if (!shareStr) return ''
if (shareStr) {
const code = shareStr.split('=')[1]
if (code) {
// setShareCode(code)
return code
}
}
return ''
}
useEffect(() => { useEffect(() => {
setRemainingTime(time / 1000); setRemainingTime(time / 1000);
}, [time]); }, [time]);
@ -108,20 +91,20 @@ function EmailForm() {
area: "", area: "",
areaCode: "", areaCode: "",
authCode: authCode, authCode: authCode,
shareCode: shareCode || formRef.current?.getFieldValue('shareCode'), shareCode: shareCode || formRef.current?.getFieldValue("shareCode"),
userName: "" userName: "",
}, },
config config
); );
console.log("res", res); console.log("res", res);
if (res.status === 200 && res.data.data.token) { if (res.status === 200 && res.data.data.token) {
console.log(111) console.log(111);
Toast.show({ Toast.show({
content: res.data.msg, content: res.data.msg,
}); });
setTimeout(() => { setTimeout(() => {
navigate("/Download") navigate("/Download");
}, 1000) }, 1000);
} else { } else {
Toast.show({ Toast.show({
content: res.data.msg, content: res.data.msg,
@ -129,24 +112,25 @@ function EmailForm() {
} }
} catch (error: unknown) { } catch (error: unknown) {
// 检查 error 是否是 ErrorType 类型 // 检查 error 是否是 ErrorType 类型
if (typeof error === 'object' && error !== null && 'msg' in error) { if (typeof error === "object" && error !== null && "msg" in error) {
const typedError = error as ErrorType; // 使用类型断言 const typedError = error as ErrorType; // 使用类型断言
Toast.show({ Toast.show({
content: typedError.msg, content: typedError.msg,
}); });
} else { } else {
// 处理不是 ErrorType 类型的错误 // 处理不是 ErrorType 类型的错误
console.log('An unexpected error occurred'); console.log("An unexpected error occurred");
} }
console.warn(error); console.warn(error);
} }
}; };
return ( return (
<Form <Form
ref={formRef} ref={formRef}
name="form" name="form"
initialValues={{ initialValues={{
shareCode: getShareCode(location.search) shareCode: getShareCode(window.location.search),
}} }}
footer={ footer={
<Button <Button
@ -209,4 +193,19 @@ function EmailForm() {
); );
} }
const getShareCode = (url: string) => {
const newStr = url.replace("?", "")?.split("&");
if (!newStr) return "";
const shareStr = newStr.find((item) => item.includes("shareCode"));
if (!shareStr) return "";
if (shareStr) {
const code = shareStr.split("=")[1];
if (code) {
// setShareCode(code)
return code;
}
}
return "";
};
export default EmailForm; export default EmailForm;

View File

@ -1,7 +1,7 @@
import { useState, useEffect, useRef } from "react"; import { useState, useEffect, useRef } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Form, Input, Button } from "antd-mobile"; import { Form, Input, Button } from "antd-mobile";
import { useLocation, useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import "../pages/SignIn.scss"; import "../pages/SignIn.scss";
import useUserStore from "../store/user.ts"; import useUserStore from "../store/user.ts";
import { useCountdown } from "../hooks/useCountdown"; import { useCountdown } from "../hooks/useCountdown";
@ -9,9 +9,9 @@ import { sendCode, signUp } from "../api";
import { sendCodeTypes, signUpTypes, ErrorType } from "../type/SignIn"; import { sendCodeTypes, signUpTypes, ErrorType } from "../type/SignIn";
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile";
import { Md5 } from "ts-md5"; import { Md5 } from "ts-md5";
import { FormInstance } from "antd-mobile/es/components/form/form";
function PhoneForm() { function PhoneForm() {
const formRef: any = useRef() const formRef = useRef<FormInstance>(null);
const location = useLocation()
const { t } = useTranslation(); const { t } = useTranslation();
const { start, time } = useCountdown(); const { start, time } = useCountdown();
const navigate = useNavigate(); const navigate = useNavigate();
@ -23,19 +23,19 @@ function PhoneForm() {
} = useUserStore(); } = useUserStore();
const getShareCode = (url: string) => { const getShareCode = (url: string) => {
const newStr = url.replace('?', '')?.split('&') const newStr = url.replace("?", "")?.split("&");
if (!newStr) return '' if (!newStr) return "";
const shareStr = newStr.find(item => item.includes('shareCode')) const shareStr = newStr.find((item) => item.includes("shareCode"));
if (!shareStr) return '' if (!shareStr) return "";
if (shareStr) { if (shareStr) {
const code = shareStr.split('=')[1] const code = shareStr.split("=")[1];
if (code) { if (code) {
// setShareCode(code) // setShareCode(code)
return code return code;
} }
} }
return '' return "";
} };
const defaultAreaCode = "+1"; const defaultAreaCode = "+1";
const [authCode, setAuthCode] = useState(""); const [authCode, setAuthCode] = useState("");
@ -60,27 +60,30 @@ function PhoneForm() {
return; return;
} }
const timestamp = `${new Date().getTime()}`; const timestamp = `${new Date().getTime()}`;
const res = await sendCode<sendCodeTypes>({ const res = await sendCode<sendCodeTypes>(
{
account: CurrentPhoneNumber, account: CurrentPhoneNumber,
areaCode: SelectCountry?.code || defaultAreaCode, areaCode: SelectCountry?.code || defaultAreaCode,
status: 2, status: 2,
signature: Md5.hashStr( signature: Md5.hashStr(
`Neer${CurrentPhoneNumber},${2},${timestamp}GetCode` `Neer${CurrentPhoneNumber},${2},${timestamp}GetCode`
), ),
timestamp timestamp,
}, config); },
config
);
console.log("res", res); console.log("res", res);
if (res.status === 200 && res.data.data.sms) { if (res.status === 200 && res.data.data.sms) {
console.log(111) console.log(111);
Toast.show({ Toast.show({
content: t('send successfully'), content: t("send successfully"),
afterClose: () => { afterClose: () => {
start(60 * 1000); start(60 * 1000);
}, },
}); });
} else { } else {
Toast.show({ Toast.show({
content: t('Send failure'), content: t("Send failure"),
afterClose: () => { afterClose: () => {
// start(60 * 1000); // start(60 * 1000);
}, },
@ -88,7 +91,7 @@ function PhoneForm() {
} }
} catch (error: unknown) { } catch (error: unknown) {
// 检查 error 是否是 ErrorType 类型 // 检查 error 是否是 ErrorType 类型
if (typeof error === 'object' && error !== null && 'msg' in error) { if (typeof error === "object" && error !== null && "msg" in error) {
const typedError = error as ErrorType; // 使用类型断言 const typedError = error as ErrorType; // 使用类型断言
Toast.show({ Toast.show({
content: typedError.msg, content: typedError.msg,
@ -98,62 +101,64 @@ function PhoneForm() {
}); });
} else { } else {
// 处理不是 ErrorType 类型的错误 // 处理不是 ErrorType 类型的错误
console.log('An unexpected error occurred'); console.log("An unexpected error occurred");
} }
console.warn(error); console.warn(error);
} }
}; };
useEffect(() => { useEffect(() => {
setRemainingTime(time / 1000) setRemainingTime(time / 1000);
}, [time]); }, [time]);
const handleSignUp = async () => { const handleSignUp = async () => {
if (CurrentPhoneNumber === '' || authCode === '') { if (CurrentPhoneNumber === "" || authCode === "") {
return return;
} }
try { try {
const res = await signUp<signUpTypes>({ const res = await signUp<signUpTypes>(
{
account: CurrentPhoneNumber, account: CurrentPhoneNumber,
area: SelectCountry?.cn, area: SelectCountry?.cn,
areaCode: SelectCountry?.code, areaCode: SelectCountry?.code,
authCode: authCode, authCode: authCode,
shareCode: shareCode || formRef.current?.getFieldValue('shareCode'), shareCode: shareCode || formRef.current?.getFieldValue("shareCode"),
userName: "" userName: "",
}, config) },
console.log('res', res) config
);
console.log("res", res);
if (res.status === 200 && res.data.data.token) { if (res.status === 200 && res.data.data.token) {
Toast.show({ Toast.show({
content: res.data.msg, content: res.data.msg,
}) });
setTimeout(() => { setTimeout(() => {
navigate("/Download") navigate("/Download");
}, 1000) }, 1000);
} else { } else {
Toast.show({ Toast.show({
content: res.data.msg, content: res.data.msg,
}) });
} }
} catch (error: unknown) { } catch (error: unknown) {
// 检查 error 是否是 ErrorType 类型 // 检查 error 是否是 ErrorType 类型
if (typeof error === 'object' && error !== null && 'msg' in error) { if (typeof error === "object" && error !== null && "msg" in error) {
const typedError = error as ErrorType; // 使用类型断言 const typedError = error as ErrorType; // 使用类型断言
Toast.show({ Toast.show({
content: typedError.msg, content: typedError.msg,
}); });
} else { } else {
// 处理不是 ErrorType 类型的错误 // 处理不是 ErrorType 类型的错误
console.log('An unexpected error occurred'); console.log("An unexpected error occurred");
} }
console.warn(error); console.warn(error);
} }
}; };
return ( return (
<Form <Form
name="form" name="form"
ref={formRef}
initialValues={{ initialValues={{
shareCode: getShareCode(location.search) shareCode: getShareCode(window.location.search),
}} }}
footer={ footer={
<Button <Button

View File

@ -1,10 +1,5 @@
import React from 'react' import ReactDOM from "react-dom/client";
import ReactDOM from 'react-dom/client' import App from "./App.tsx";
import App from './App.tsx' import "./index.css";
import './index.css' import "./i18n/config.ts";
import './i18n/config.ts' ReactDOM.createRoot(document.getElementById("root")!).render(<App />);
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)

View File

@ -4,7 +4,7 @@ import phoneIconSelect from "../assets/iconfont/phone_Select.svg";
import phoneIcon from "../assets/iconfont/phone.svg"; import phoneIcon from "../assets/iconfont/phone.svg";
import emailIcon from "../assets/iconfont/email.svg"; import emailIcon from "../assets/iconfont/email.svg";
import emailIconSelect from "../assets/iconfont/email_Select.svg"; import emailIconSelect from "../assets/iconfont/email_Select.svg";
import Logo from "../assets/img/logo.png" import Logo from "../assets/img/logo.png";
import "./SignIn.scss"; import "./SignIn.scss";
import EmailForm from "../components/EmailForm"; import EmailForm from "../components/EmailForm";
import PhoneForm from "../components/PhoneForm"; import PhoneForm from "../components/PhoneForm";
@ -14,15 +14,15 @@ import { Popover } from "antd-mobile";
function SignIn() { function SignIn() {
const { t, i18n } = useTranslation(); const { t, i18n } = useTranslation();
const lang: string = getI18n().language const lang: string = getI18n().language;
const [visible, setVisible] = useState(false) const [visible, setVisible] = useState(false);
const [selectIndex, setSelectIndex] = useState<number>(0); const [selectIndex, setSelectIndex] = useState<number>(0);
const { previousPathName, UpdatePreviousPathName } = useUserStore() const { previousPathName, UpdatePreviousPathName } = useUserStore();
const navigate = useNavigate(); const navigate = useNavigate();
const handleTabs = (num: number) => { const handleTabs = (num: number) => {
return () => { return () => {
UpdatePreviousPathName('/'); UpdatePreviousPathName("/");
setSelectIndex(num); setSelectIndex(num);
}; };
}; };
@ -40,33 +40,60 @@ function SignIn() {
<div className="language"> <div className="language">
<Popover <Popover
className="popoverContainer" className="popoverContainer"
mode='dark' mode="dark"
visible={visible} visible={visible}
placement='bottom-end' placement="bottom-end"
trigger='click' trigger="click"
content={<ul style={{ content={
listStyle: 'none', <ul
display: 'flex', style={{
flexDirection: 'column', listStyle: "none",
justifyContent: 'flex-start', display: "flex",
alignItems: 'center', flexDirection: "column",
justifyContent: "flex-start",
alignItems: "center",
margin: 0, margin: 0,
padding: '5px 10px', padding: "5px 10px",
fontSize: 14, fontSize: 14,
background: '#333333', background: "#333333",
borderRadius: 6 borderRadius: 6,
}}> }}
<li style={{ borderBottom: '1px solid #2f2f2f', padding: '5px 10px', cursor: 'pointer' }}><span onClick={() => {
i18n.changeLanguage('cn')
setVisible(false)
}}></span></li>
<li style={{ padding: '5px 10px', cursor: 'pointer' }}><span onClick={() => {
i18n.changeLanguage('en')
setVisible(false)
}}>English</span></li>
</ul>}
> >
<span style={{ cursor: 'pointer' }} onClick={() => setVisible(!visible)}>{lang === 'cn' ? '中文' : 'English'}</span> <li
style={{
borderBottom: "1px solid #2f2f2f",
padding: "5px 10px",
cursor: "pointer",
}}
>
<span
onClick={() => {
i18n.changeLanguage("cn");
setVisible(false);
}}
>
</span>
</li>
<li style={{ padding: "5px 10px", cursor: "pointer" }}>
<span
onClick={() => {
i18n.changeLanguage("en");
setVisible(false);
}}
>
English
</span>
</li>
</ul>
}
>
<span
style={{ cursor: "pointer" }}
onClick={() => setVisible(!visible)}
>
{lang === "cn" ? "中文" : "English"}
</span>
</Popover> </Popover>
</div> </div>
<div className="logo"> <div className="logo">
@ -91,14 +118,30 @@ function SignIn() {
{selectIndex === 0 && <EmailForm></EmailForm>} {selectIndex === 0 && <EmailForm></EmailForm>}
{selectIndex === 1 && <PhoneForm></PhoneForm>} {selectIndex === 1 && <PhoneForm></PhoneForm>}
<div className="to-download"> <div className="to-download">
<p style={{ color: '#999999' }}>{t("If you already have an account")}</p> <p style={{ color: "#999999" }}>
<p onClick={() => navigate("/Download")}>{t("Download the APP directly")}</p> {t("If you already have an account")}
</p>
<p onClick={() => navigate("/Download")}>
{t("download the APP directly")}
</p>
</div> </div>
<div className="terms-service"> <div className="terms-service">
<p>{t("Continuing to represent you in agreeing to our")}</p> <p>{t("Continuing to represent you in agreeing to our")}</p>
<p> <p>
<span><a target="_blank" href="https://lm0-1.gitbook.io/terms-of-service/">{t("Terms of Service")}</a></span> {t("and")}{" "} <span>
<span><a target="_blank" href="https://lm0-1.gitbook.io/privacy-policy/">{t("Privacy Policy")}</a></span> <a
target="_blank"
href="https://lm0-1.gitbook.io/terms-of-service/"
>
{t("Terms of Service")}
</a>
</span>{" "}
{t("and")}{" "}
<span>
<a target="_blank" href="https://lm0-1.gitbook.io/privacy-policy/">
{t("Privacy Policy")}
</a>
</span>
</p> </p>
</div> </div>
</div> </div>