From 401d8ac4ca4940bd0cee4bcf345ad90256d63328 Mon Sep 17 00:00:00 2001 From: dzq Date: Sat, 10 May 2025 17:16:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=99=BB=E5=BD=95):=20=E6=B7=BB=E5=8A=A0o?= =?UTF-8?q?penid=E6=94=AF=E6=8C=81=E5=B9=B6=E5=BC=95=E5=85=A5=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=AA=8C=E8=AF=81=E7=A0=81=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为了增强登录安全性和支持微信登录,本次提交引入了openid字段,并在用户登录流程中添加了验证码机制。具体修改包括: 1. 在VerifySmsParams类型中添加openid字段 2. 在Ab98Login.vue中传递openid参数 3. 在App.vue中更新tokenLogin调用以包含openid 4. 在ab98/index.ts中修改tokenLogin接口以支持openid 5. 在ab98-user.ts中引入登录验证码逻辑,确保登录状态验证更加安全 --- src/App.vue | 2 +- src/common/apis/ab98/index.ts | 4 ++-- src/common/apis/ab98/type.ts | 1 + src/pages/login/Ab98Login.vue | 3 ++- src/pinia/stores/ab98-user.ts | 10 ++++++++-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/App.vue b/src/App.vue index 8d548ca..3687a23 100644 --- a/src/App.vue +++ b/src/App.vue @@ -47,7 +47,7 @@ onMounted(() => { () => wxStore.userid, (newVal) => { if (newVal && !ab98UserStore.isLogin) { - tokenLogin(ab98UserStore.tokenLogin, newVal).then(res => { + tokenLogin(ab98UserStore.tokenLogin, newVal, wxStore.openid).then(res => { if (res?.code === 0 && res.data?.success) { ab98UserStore.setTel(res.data.tel) ab98UserStore.setUserInfo(res.data) diff --git a/src/common/apis/ab98/index.ts b/src/common/apis/ab98/index.ts index cea2f24..ecfbb60 100644 --- a/src/common/apis/ab98/index.ts +++ b/src/common/apis/ab98/index.ts @@ -55,10 +55,10 @@ export function logoutApi(token: string) { } /** ab98Token登录 */ -export function tokenLogin(token: string, userid: string) { +export function tokenLogin(token: string, userid: string, openid: string) { return request>({ url: '/wx/login/tokenLogin', method: 'get', - params: { token, userid } + params: { token, userid, openid } }) } \ No newline at end of file diff --git a/src/common/apis/ab98/type.ts b/src/common/apis/ab98/type.ts index c063181..2f1e78a 100644 --- a/src/common/apis/ab98/type.ts +++ b/src/common/apis/ab98/type.ts @@ -57,4 +57,5 @@ export type VerifySmsParams = { /** 验证码 */ vcode: string userid: string + openid: string } \ No newline at end of file diff --git a/src/pages/login/Ab98Login.vue b/src/pages/login/Ab98Login.vue index a81cd76..ccee5c6 100644 --- a/src/pages/login/Ab98Login.vue +++ b/src/pages/login/Ab98Login.vue @@ -111,7 +111,8 @@ const handleSubmit = async () => { token: userStore.token, tel: form.value.tel, vcode: form.value.vcode, - userid: wxStore.userid + userid: wxStore.userid, + openid: wxStore.openid }) if (data.success) { diff --git a/src/pinia/stores/ab98-user.ts b/src/pinia/stores/ab98-user.ts index 98e50c7..5fc646c 100644 --- a/src/pinia/stores/ab98-user.ts +++ b/src/pinia/stores/ab98-user.ts @@ -9,7 +9,8 @@ const STORAGE_KEYS = { USERID: 'ab98_userid', REGISTERED: 'ab98_registered', TEL: 'ab98_tel', - TOKEN: 'ab98_token' + TOKEN: 'ab98_token', + LOGIN_CODE: 'ab98_login_code' } /** @@ -39,9 +40,12 @@ export const useAb98UserStore = defineStore("ab98User", () => { const token = ref(storedToken ? decodeURIComponent(storedToken) : ""); const tokenLogin = ref(""); + // 登录验证码 + const loginCode = '1'; // 默认验证码 // 用户登录状态 const isLogin = ref(false); - isLogin.value = tel.value ? true : false; + const storedLoginCode = localStorage.getItem(STORAGE_KEYS.LOGIN_CODE); + isLogin.value = tel.value && storedLoginCode === String(loginCode) ? true : false; /** * 更新用户基本信息 @@ -60,6 +64,7 @@ export const useAb98UserStore = defineStore("ab98User", () => { localStorage.setItem(STORAGE_KEYS.REGISTERED, JSON.stringify(data.registered)) tel.value = data.tel localStorage.setItem(STORAGE_KEYS.TEL, encodeURIComponent(data.tel)) + localStorage.setItem(STORAGE_KEYS.LOGIN_CODE, encodeURIComponent(loginCode)) } /** @@ -80,6 +85,7 @@ export const useAb98UserStore = defineStore("ab98User", () => { tel.value = "" localStorage.removeItem(STORAGE_KEYS.TEL) localStorage.removeItem(STORAGE_KEYS.TOKEN) + localStorage.removeItem(STORAGE_KEYS.LOGIN_CODE) } /**