From 9ec50cf0ce7db2b344b158515195af682fd0e6c2 Mon Sep 17 00:00:00 2001 From: DEV_DSW <562304744@qq.com> Date: Thu, 4 Jun 2026 09:30:52 +0800 Subject: [PATCH] refactor(navigation): fix phone login country code and refactor nav hooks Extract shared navigation functions (goHome, goLogin, goBack) into a new useNavigator hook that uses vue-router. Remove the deprecated useGoHome.ts file. Update useGoLogin.ts to import the new navigation utilities, clean up unused code, and fix the checkToken function to correctly read from localStorage. Fix missing country dial code in phone login request parameters. --- src/hooks/useGoHome.ts | 1 - src/hooks/useGoLogin.ts | 26 ++++---------------------- src/hooks/useNavigator.ts | 22 ++++++++++++++++++++++ src/pages/login/index.vue | 2 +- 4 files changed, 27 insertions(+), 24 deletions(-) delete mode 100644 src/hooks/useGoHome.ts create mode 100644 src/hooks/useNavigator.ts diff --git a/src/hooks/useGoHome.ts b/src/hooks/useGoHome.ts deleted file mode 100644 index 600b96c..0000000 --- a/src/hooks/useGoHome.ts +++ /dev/null @@ -1 +0,0 @@ -export const goHome = () => uni.reLaunch({ url: "/pages/index/index" }); diff --git a/src/hooks/useGoLogin.ts b/src/hooks/useGoLogin.ts index b2fc1f0..b77fd97 100644 --- a/src/hooks/useGoLogin.ts +++ b/src/hooks/useGoLogin.ts @@ -1,14 +1,8 @@ -import { oauthToken, checkUserPhone } from "@/api/login"; - -// 跳转登录 -export const goLogin = () => {}; - -// 登录成功后,返回上一页 -export const goBack = () => {}; +import { goLogin } from "./useNavigator"; // 检测token -export const checkToken = () => { - const token = true || localStorage.getItem("token"); +export const checkToken = (): Promise => { + const token = localStorage.getItem("token"); return new Promise((resolve) => { if (!token) { @@ -16,18 +10,6 @@ export const checkToken = () => { return; } - resolve(token); + resolve(); }); }; - -// 登录逻辑 -export const onLogin = async () => {}; - -/// 检查手机号登录 -export const onCheckPhoneLogin = async () => {}; - -// apple登录 -export const onAppleLogin = async () => {}; - -// 刷新 token -export const refreshToken = async () => {}; diff --git a/src/hooks/useNavigator.ts b/src/hooks/useNavigator.ts new file mode 100644 index 0000000..a5c5c7d --- /dev/null +++ b/src/hooks/useNavigator.ts @@ -0,0 +1,22 @@ +import { useRouter } from "vue-router"; + +// 跳转首页 +export const goHome = () => { + const router = useRouter(); + + router.push({ name: "home" }); +}; + +// 跳转登录页 +export const goLogin = () => { + const router = useRouter(); + + router.push({ name: "login" }); +}; + +// 返回上一页 +export const goBack = () => { + const router = useRouter(); + + router.back(); +}; diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index b2d0697..8d3adc0 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -227,7 +227,7 @@ async function handlePhoneLogin() { try { await oauthToken({ scope: "server", - mobile: phoneDigits, + mobile: `${selectedCountry.value.dialCode}${phoneDigits}`, code: codeValue, grant_type: "mobile", });