From 3b3dd321557785d8f30bf5e1a1e9cad3128eeda2 Mon Sep 17 00:00:00 2001 From: dzq Date: Fri, 7 Nov 2025 17:24:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BE=AE=E4=BF=A1=E7=99=BB=E5=BD=95):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BE=AE=E4=BF=A1=E7=99=BB=E5=BD=95=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E5=B9=B6=E6=B7=BB=E5=8A=A0=E4=BC=81=E4=B8=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在页面显示时刷新余额 - 添加企业用户信息字段到WxUserDTO类型 - 重构微信登录回调处理,合并openid和用户信息设置 - 默认设置isHandleWxCallbackComplete为true - 新增wxMpCallback方法处理微信小程序回调 --- src/api/users/types.ts | 11 +++++++++++ src/pages/index/index.vue | 5 ++--- src/pages/me/index.vue | 6 +++++- src/pinia/stores/wx.ts | 15 ++++++++++++--- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/api/users/types.ts b/src/api/users/types.ts index 7dc9b34..fbf16d7 100644 --- a/src/api/users/types.ts +++ b/src/api/users/types.ts @@ -30,6 +30,17 @@ export interface WxUserDTO { ab98Name?: string; /** 汇邦云用户头像 */ ab98FaceImg?: string; + /** 企业用户信息 */ + qyUser?: { + /** 企业用户ID */ + id?: number; + /** 企业用户标识 */ + userid?: string; + /** 企业用户姓名 */ + name?: string; + /** 企业用户头像 */ + avatar?: string; + }; } /** 动态码响应数据 */ diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 4ec71e3..14c4d6d 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -30,14 +30,13 @@ const shopId = ref(0) // 页面加载 onMounted(async () => { - await wxStore.fakeQyLogin(); + // await wxStore.fakeQyLogin(); uni.login({ provider: 'weixin', //使用微信登录 success: function (loginRes) { mpCodeToOpenId(loginRes.code).then((wxUser) => { console.log('wxUser:', wxUser); - wxStore.setOpenid(wxUser.data.openid); - wxStore.setWxUserDTO(wxUser.data); + wxStore.wxMpCallback(wxUser.data); if (wxUser.data.ab98UserId) { ab98UserStore.setAb98UserName(wxUser.data.ab98Name || wxUser.data.nickName || '') ab98UserStore.setAb98UserFaceImg(wxUser.data.ab98FaceImg || '') diff --git a/src/pages/me/index.vue b/src/pages/me/index.vue index 188ac69..7b6779e 100644 --- a/src/pages/me/index.vue +++ b/src/pages/me/index.vue @@ -83,7 +83,11 @@ const navigateToPage = (pagePath: string, options: { type?: 'navigateTo' | 'swit onMounted(() => { wxStore.refreshBalance() -}) +}); + +onShow(() => { + wxStore.refreshBalance() +}); // 生成动态码 const handleGenerateDynamicCode = async () => { diff --git a/src/pinia/stores/wx.ts b/src/pinia/stores/wx.ts index daa93ea..b7287f6 100644 --- a/src/pinia/stores/wx.ts +++ b/src/pinia/stores/wx.ts @@ -36,7 +36,7 @@ export const useWxStore = defineStore("wx", () => { const isFakeQyLogin = ref(false); // handleWxCallback 是否完成 - const isHandleWxCallbackComplete = ref(false); + const isHandleWxCallbackComplete = ref(true); const wxUserDTO = ref(null); @@ -182,14 +182,23 @@ export const useWxStore = defineStore("wx", () => { return true; } - const setWxUserDTO = (userDTO: WxUserDTO | null) => { + const wxMpCallback = (userDTO: WxUserDTO) => { + corpid.value = "wpZ1ZrEgAA2QTxIRcB4cMtY7hQbTcPAw"; + openid.value = userDTO.openid || openid.value; wxUserDTO.value = userDTO; + if (userDTO.qyUserId) { + qyUserId.value = userDTO.qyUserId; + } + if (userDTO.qyUser) { + userid.value = userDTO.qyUser.userid || userid.value; + } + refreshBalance(); } return { code, state, openid, corpid, userid, balance, useBalance, balanceLimit, isCabinetAdmin, corpidLogin, name, ab98User, qyUserId, isFakeQyLogin, isHandleWxCallbackComplete, wxUserDTO, setOpenid, setBalance, handleWxCallback, setIsCabinetAdmin, - refreshBalance, setAb98User, fakeQyLogin, waitForHandleWxCallbackComplete, setWxUserDTO } + refreshBalance, setAb98User, fakeQyLogin, waitForHandleWxCallbackComplete, wxMpCallback } }) /**