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:
@@ -1 +0,0 @@
|
||||
export const goHome = () => uni.reLaunch({ url: "/pages/index/index" });
|
||||
@@ -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
22
src/hooks/useNavigator.ts
Normal 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();
|
||||
};
|
||||
@@ -227,7 +227,7 @@ async function handlePhoneLogin() {
|
||||
try {
|
||||
await oauthToken({
|
||||
scope: "server",
|
||||
mobile: phoneDigits,
|
||||
mobile: `${selectedCountry.value.dialCode}${phoneDigits}`,
|
||||
code: codeValue,
|
||||
grant_type: "mobile",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user