feat(微信登录): 优化微信登录流程并添加企业用户信息
- 在页面显示时刷新余额 - 添加企业用户信息字段到WxUserDTO类型 - 重构微信登录回调处理,合并openid和用户信息设置 - 默认设置isHandleWxCallbackComplete为true - 新增wxMpCallback方法处理微信小程序回调
This commit is contained in:
parent
3c61d698a6
commit
3b3dd32155
|
|
@ -30,6 +30,17 @@ export interface WxUserDTO {
|
|||
ab98Name?: string;
|
||||
/** 汇邦云用户头像 */
|
||||
ab98FaceImg?: string;
|
||||
/** 企业用户信息 */
|
||||
qyUser?: {
|
||||
/** 企业用户ID */
|
||||
id?: number;
|
||||
/** 企业用户标识 */
|
||||
userid?: string;
|
||||
/** 企业用户姓名 */
|
||||
name?: string;
|
||||
/** 企业用户头像 */
|
||||
avatar?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** 动态码响应数据 */
|
||||
|
|
|
|||
|
|
@ -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 || '')
|
||||
|
|
|
|||
|
|
@ -83,7 +83,11 @@ const navigateToPage = (pagePath: string, options: { type?: 'navigateTo' | 'swit
|
|||
|
||||
onMounted(() => {
|
||||
wxStore.refreshBalance()
|
||||
})
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
wxStore.refreshBalance()
|
||||
});
|
||||
|
||||
// 生成动态码
|
||||
const handleGenerateDynamicCode = async () => {
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
})
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue