diff --git a/index.html b/index.html index e4b78ea..0fe0008 100644 --- a/index.html +++ b/index.html @@ -2,9 +2,9 @@ - + - Vite + React + TS + NEER-APP-H5
diff --git a/src/App.tsx b/src/App.tsx index 31b3c52..ae88c1a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,6 @@ import "./App.css"; import { useEffect } from "react"; -import { BrowserRouter as Router, Route, Routes, Navigate } from "react-router-dom"; +import { BrowserRouter as Router, Route, Routes } from "react-router-dom"; import SignIn from "./pages/SignIn"; import Download from "./pages/Download"; import SelectCountry from "./pages/SelectCountry"; diff --git a/src/api/request.ts b/src/api/request.ts index e7dea6c..5c6c529 100644 --- a/src/api/request.ts +++ b/src/api/request.ts @@ -15,7 +15,7 @@ const service = axios.create({ }); // 统一请求拦截,可配置自定义 headers 例如 language、token 等 service.interceptors.request.use( - (config: AxiosRequestConfig) => { + (config: any): any => { // 确保 headers 对象存在 if (!config.headers) { config.headers = {}; diff --git a/src/assets/img/logo.png b/src/assets/img/logo.png new file mode 100644 index 0000000..4de84a5 Binary files /dev/null and b/src/assets/img/logo.png differ diff --git a/src/components/EmailForm.tsx b/src/components/EmailForm.tsx index 8fe0396..8686c34 100644 --- a/src/components/EmailForm.tsx +++ b/src/components/EmailForm.tsx @@ -1,10 +1,11 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { useState, useEffect } from "react"; import { useTranslation } from "react-i18next"; import { Form, Input, Button } from "antd-mobile"; import "../pages/SignIn.scss"; import { useCountdown } from "../hooks/useCountdown"; import { sendCode, signUp } from "../api"; -import { sendCodeTypes, signUpTypes } from "../type/SignIn"; +import { sendCodeTypes, signUpTypes,ErrorType } from "../type/SignIn"; import { Toast } from "antd-mobile"; function EmailForm() { @@ -48,14 +49,20 @@ function EmailForm() { }, }); } - } catch (error) { - Toast.show({ - content: error?.msg, - afterClose: () => { - start(60 * 1000); - }, - }); - + } catch (error:unknown) { + // 检查 error 是否是 ErrorType 类型 + if (typeof error === 'object' && error !== null && 'msg' in error) { + const typedError = error as ErrorType; // 使用类型断言 + Toast.show({ + content: typedError.msg, + afterClose: () => { + start(60 * 1000); + }, + }); + } else { + // 处理不是 ErrorType 类型的错误 + console.log('An unexpected error occurred'); + } console.warn(error); } }; @@ -87,13 +94,17 @@ function EmailForm() { content: res.data.msg, }); } - } catch (error) { - Toast.show({ - content: error?.msg, - afterClose: () => { - start(60 * 1000); - }, - }); + } catch (error:unknown) { + // 检查 error 是否是 ErrorType 类型 + if (typeof error === 'object' && error !== null && 'msg' in error) { + const typedError = error as ErrorType; // 使用类型断言 + Toast.show({ + content: typedError.msg, + }); + } else { + // 处理不是 ErrorType 类型的错误 + console.log('An unexpected error occurred'); + } console.warn(error); } }; diff --git a/src/components/PhoneForm.tsx b/src/components/PhoneForm.tsx index e1024e4..9168e75 100644 --- a/src/components/PhoneForm.tsx +++ b/src/components/PhoneForm.tsx @@ -6,7 +6,7 @@ import "../pages/SignIn.scss"; import useUserStore from "../store/user.ts"; import { useCountdown } from "../hooks/useCountdown"; import { sendCode, signUp } from "../api"; -import { sendCodeTypes, signUpTypes } from "../type/SignIn"; +import { sendCodeTypes, signUpTypes,ErrorType} from "../type/SignIn"; import { Toast } from "antd-mobile"; function PhoneForm() { @@ -62,13 +62,20 @@ function PhoneForm() { }, }); } - } catch (error) { - Toast.show({ - content: error?.msg, - afterClose: () => { - start(60 * 1000); - }, - }); + } catch (error:unknown) { + // 检查 error 是否是 ErrorType 类型 + if (typeof error === 'object' && error !== null && 'msg' in error) { + const typedError = error as ErrorType; // 使用类型断言 + Toast.show({ + content: typedError.msg, + afterClose: () => { + start(60 * 1000); + }, + }); + } else { + // 处理不是 ErrorType 类型的错误 + console.log('An unexpected error occurred'); + } console.warn(error); } }; @@ -98,13 +105,17 @@ function PhoneForm() { content: res.data.msg, }) } - } catch (error) { - Toast.show({ - content: error?.msg, - afterClose: () => { - start(60 * 1000); - }, - }); + } catch (error:unknown) { + // 检查 error 是否是 ErrorType 类型 + if (typeof error === 'object' && error !== null && 'msg' in error) { + const typedError = error as ErrorType; // 使用类型断言 + Toast.show({ + content: typedError.msg, + }); + } else { + // 处理不是 ErrorType 类型的错误 + console.log('An unexpected error occurred'); + } console.warn(error); } diff --git a/src/pages/Download.scss b/src/pages/Download.scss index 81cd445..d43371d 100644 --- a/src/pages/Download.scss +++ b/src/pages/Download.scss @@ -8,10 +8,12 @@ .logo { width: 4.25rem; height: 4.25rem; - background: #bf62ff; - border-radius: 50%; margin-left: 50%; transform: translateX(-50%); + img { + width: 100%; + height: 100%; + } } .btn-box { diff --git a/src/pages/Download.tsx b/src/pages/Download.tsx index add6c54..08e7ef5 100644 --- a/src/pages/Download.tsx +++ b/src/pages/Download.tsx @@ -1,6 +1,7 @@ import googleIcon from '../assets/img/google.png' import appStoreIcon from '../assets/img/app_store.png' import { useTranslation } from "react-i18next"; +import Logo from "../assets/img/logo.png" import "./Download.scss"; @@ -9,7 +10,9 @@ function Download() { return (
-
+
+ +
diff --git a/src/pages/SelectCountry.tsx b/src/pages/SelectCountry.tsx index d7d5184..20f9321 100644 --- a/src/pages/SelectCountry.tsx +++ b/src/pages/SelectCountry.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from "react"; +import { useState } from "react"; import { useTranslation } from "react-i18next"; import gobackIcon from "../assets/iconfont/goback.svg"; import searchIcon from "../assets/iconfont/search.svg"; @@ -62,7 +62,7 @@ function SelectCountry() { className={`area-item ${isSelected && "selected"}`} onClick={() => handleSelectCountry(item, index)} > - {item[lang]} + {(item as never)[lang]} {item.code}
); @@ -75,7 +75,7 @@ function SelectCountry() { className={`area-item ${isSelected && "selected"}`} onClick={() => handleSelectCountry(item, index)} > - {item[lang]} + {(item as never)[lang]} {item.code}
); diff --git a/src/pages/SignIn.scss b/src/pages/SignIn.scss index 5533d25..bc06b02 100644 --- a/src/pages/SignIn.scss +++ b/src/pages/SignIn.scss @@ -8,10 +8,12 @@ .logo { width: 4.25rem; height: 4.25rem; - background: #bf62ff; - border-radius: 50%; margin-left: 50%; transform: translateX(-50%); + img { + width: 100%; + height: 100%; + } } .tabs { diff --git a/src/pages/SignIn.tsx b/src/pages/SignIn.tsx index 134d0c6..af7d2ad 100644 --- a/src/pages/SignIn.tsx +++ b/src/pages/SignIn.tsx @@ -4,6 +4,7 @@ import phoneIconSelect from "../assets/iconfont/phone_Select.svg"; import phoneIcon from "../assets/iconfont/phone.svg"; import emailIcon from "../assets/iconfont/email.svg"; import emailIconSelect from "../assets/iconfont/email_Select.svg"; +import Logo from "../assets/img/logo.png" import "./SignIn.scss"; import EmailForm from "../components/EmailForm"; import PhoneForm from "../components/PhoneForm"; @@ -33,7 +34,9 @@ function SignIn() { }, [previousPathName]); return (
-
+
+ +