From 53571882a0eff7f8c2588d1f0cfb9ab5f38dcad7 Mon Sep 17 00:00:00 2001 From: xingyy <64720302+Concur-max@users.noreply.github.com> Date: Sun, 2 Mar 2025 14:35:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor(auth):=20=E9=87=8D=E6=9E=84=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=A8=A1=E5=9D=97=E5=B9=B6=E4=BC=98=E5=8C=96=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 token 在 codeAuthStore 中的名称,从 token 改为 codeToken - 优化验证码发送逻辑,增加错误处理和加载状态管理 - 调整页面布局和样式,提高用户体验 - 修复了一些小的 UI 问题,例如输入框聚焦状态和倒计时显示 --- app/api-collect-code/http.js | 4 +- app/pages/collectCode/login/index.vue | 225 ++++++++++++++------------ app/stores-collect-code/auth/index.js | 4 +- 3 files changed, 125 insertions(+), 108 deletions(-) diff --git a/app/api-collect-code/http.js b/app/api-collect-code/http.js index e59b001..dfcdaa2 100644 --- a/app/api-collect-code/http.js +++ b/app/api-collect-code/http.js @@ -9,7 +9,7 @@ let http // HTTP 状态码映射 - 使用i18n国际化 export function setupHttp() { if (http) return http - const {token}= codeAuthStore() + const {codeToken}= codeAuthStore() const config = useRuntimeConfig() const baseURL = config.public.NUXT_PUBLIC_API_COLLECT_CODE const router = useRouter() @@ -43,7 +43,7 @@ export function setupHttp() { // 添加 token options.headers = { ...options.headers, - Authorization: token.value, + Authorization: codeToken.value, 'accept-language': i18n.locale.value } diff --git a/app/pages/collectCode/login/index.vue b/app/pages/collectCode/login/index.vue index 02f30af..783c365 100644 --- a/app/pages/collectCode/login/index.vue +++ b/app/pages/collectCode/login/index.vue @@ -8,7 +8,7 @@ import {message} from '@/components/x-message/useMessage.js' import FingerprintJS from '@fingerprintjs/fingerprintjs' import {checkPhone, mobileLogin, userSend} from "@/api-collect-code/auth/index.js"; -const {userInfo, token, fingerprint} = codeAuthStore() +const {userInfo, codeToken, fingerprint} = codeAuthStore() const router = useRouter(); const route = useRoute(); const {locale} = useI18n() @@ -49,27 +49,31 @@ const checkFingerprint = async () => { await router.push('/collectCode/mine') } } +const codeInput = ref(null) const isFocused = ref(false) checkFingerprint() const vanSwipeRef = ref(null) const getCode = async () => { loadingRef.value.loading1 = true - const res = await checkPhone({ - tel: phoneNum.value, - }) - loadingRef.value.loading1 = false - if (res.status === 0) { - const res = await userSend({telNum: phoneNum.value, zone: '+86'}) + try { + const res = await checkPhone({ + tel: phoneNum.value, + }) if (res.status === 0) { - pane.value = 1 - vanSwipeRef.value?.swipeTo(pane.value) - nextTick(()=>{ - codeInput.value.focus() - }) + const sendRes = await userSend({telNum: phoneNum.value, zone: '+86'}) + startCountdown() + pane.value = 1 + await nextTick() + vanSwipeRef.value?.swipeTo(pane.value) + nextTick(() => { + codeInput.value?.focus() + }) } + } catch (error) { + console.error('获取验证码失败:', error) + } finally { + loadingRef.value.loading1 = false } - - } const changeToPwd = async () => { loginType.value = loginType.value === 0 ? 1 : 0 @@ -88,7 +92,7 @@ const goLogin = async () => { }) if (res.status === 0) { userInfo.value = res.data.accountInfo - token.value = res.data.token + codeToken.value = res.data.token fingerprint.value = await getFingerprint() await router.push('/collectCode/mine'); @@ -101,113 +105,126 @@ const showPassword = ref(false) const togglePasswordVisibility = () => { showPassword.value = !showPassword.value } +onMounted(()=>{ + // vanSwipeRef.value?.swipeTo(1) +})