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.
This commit is contained in:
DEV_DSW
2026-06-04 09:30:52 +08:00
parent db499933e5
commit 9ec50cf0ce
4 changed files with 27 additions and 24 deletions

View File

@@ -1 +0,0 @@
export const goHome = () => uni.reLaunch({ url: "/pages/index/index" });

View File

@@ -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<void> => {
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 () => {};

22
src/hooks/useNavigator.ts Normal file
View File

@@ -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();
};

View File

@@ -227,7 +227,7 @@ async function handlePhoneLogin() {
try {
await oauthToken({
scope: "server",
mobile: phoneDigits,
mobile: `${selectedCountry.value.dialCode}${phoneDigits}`,
code: codeValue,
grant_type: "mobile",
});