From fca76138523db319395e0d5bdf5c9978beef19fd Mon Sep 17 00:00:00 2001 From: Anne_LXM Date: Fri, 13 Sep 2024 21:01:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=97=B6=E5=BA=8F=EF=BC=8C=E7=A1=AE=E4=BF=9D=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=8F=98=E5=8C=96=E4=BA=8B=E4=BB=B6=EF=BC=88?= =?UTF-8?q?uni-id-pages-logout=E3=80=81uni-id-pages-login-success=EF=BC=89?= =?UTF-8?q?=E5=8F=91=E5=87=BA=E5=89=8Dstore=E4=B8=8B=E7=9A=84userInfo.=5Fi?= =?UTF-8?q?d=E5=80=BC=E5=B7=B2=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uni-id-pages/common/store.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/uni_modules/uni-id-pages/common/store.js b/uni_modules/uni-id-pages/common/store.js index d8f2108..49b547e 100644 --- a/uni_modules/uni-id-pages/common/store.js +++ b/uni_modules/uni-id-pages/common/store.js @@ -6,13 +6,12 @@ const db = uniCloud.database(); const usersTable = db.collection('uni-id-users') let hostUserInfo = uni.getStorageSync('uni-id-pages-userInfo')||{} -// console.log( hostUserInfo); + const data = { userInfo: hostUserInfo, hasLogin: Object.keys(hostUserInfo).length != 0 } -// console.log('data', data); // 定义 mutations, 修改属性 export const mutations = { // data不为空,表示传递要更新的值(注意不是覆盖是合并),什么也不传时,直接查库获取更新 @@ -37,6 +36,10 @@ export const mutations = { }) } else { + // 不等待联网查询,立即更新用户_id确保store.userInfo中的_id是最新的 + const _id = uniCloud.getCurrentUserInfo().uid + this.setUserInfo({_id},{cover:true}) + // 查库获取用户信息,更新store.userInfo const uniIdCo = uniCloud.importObject("uni-id-co", { customUI: true }) @@ -58,7 +61,7 @@ export const mutations = { } } }, - async setUserInfo(data, {cover}={cover:false}) { + setUserInfo(data, {cover}={cover:false}) { // console.log('set-userInfo', data); let userInfo = cover?data:Object.assign(store.userInfo,data) store.userInfo = Object.assign({},userInfo) @@ -78,13 +81,12 @@ export const mutations = { } uni.removeStorageSync('uni_id_token'); uni.setStorageSync('uni_id_token_expired', 0) + this.setUserInfo({},{cover:true}) + uni.$emit('uni-id-pages-logout') uni.redirectTo({ url: `/${pagesJson.uniIdRouter && pagesJson.uniIdRouter.loginPage ? pagesJson.uniIdRouter.loginPage: 'uni_modules/uni-id-pages/pages/login/login-withoutpwd'}`, }); - uni.$emit('uni-id-pages-logout') - this.setUserInfo({},{cover:true}) }, - loginBack (e = {}) { const {uniIdRedirectUrl = ''} = e let delta = 0; //判断需要返回几层 @@ -139,6 +141,7 @@ export const mutations = { duration: 3000 }); } + // 异步调用(更新用户信息)防止获取头像等操作阻塞页面返回 this.updateUserInfo() uni.$emit('uni-id-pages-login-success') -- GitLab