feat(微信登录): 优化微信登录流程并添加企业用户信息

- 在页面显示时刷新余额
- 添加企业用户信息字段到WxUserDTO类型
- 重构微信登录回调处理,合并openid和用户信息设置
- 默认设置isHandleWxCallbackComplete为true
- 新增wxMpCallback方法处理微信小程序回调
This commit is contained in:
dzq 2025-11-07 17:24:53 +08:00
parent 3c61d698a6
commit 3b3dd32155
4 changed files with 30 additions and 7 deletions

View File

@ -30,6 +30,17 @@ export interface WxUserDTO {
ab98Name?: string;
/** 汇邦云用户头像 */
ab98FaceImg?: string;
/** 企业用户信息 */
qyUser?: {
/** 企业用户ID */
id?: number;
/** 企业用户标识 */
userid?: string;
/** 企业用户姓名 */
name?: string;
/** 企业用户头像 */
avatar?: string;
};
}
/** 动态码响应数据 */

View File

@ -30,14 +30,13 @@ const shopId = ref<number>(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 || '')

View File

@ -83,7 +83,11 @@ const navigateToPage = (pagePath: string, options: { type?: 'navigateTo' | 'swit
onMounted(() => {
wxStore.refreshBalance()
})
});
onShow(() => {
wxStore.refreshBalance()
});
//
const handleGenerateDynamicCode = async () => {

View File

@ -36,7 +36,7 @@ export const useWxStore = defineStore("wx", () => {
const isFakeQyLogin = ref<boolean>(false);
// handleWxCallback 是否完成
const isHandleWxCallbackComplete = ref<boolean>(false);
const isHandleWxCallbackComplete = ref<boolean>(true);
const wxUserDTO = ref<WxUserDTO | null>(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 }
})
/**