调整微信小程序的报错。
This commit is contained in:
@@ -24,9 +24,12 @@ function getHostUserInfo() {
|
||||
return {};
|
||||
}
|
||||
|
||||
// 初始化用户信息(只调用一次)
|
||||
const initialUserInfo = getHostUserInfo() || {};
|
||||
|
||||
const data = {
|
||||
userInfo: getHostUserInfo(),
|
||||
hasLogin: Object.keys(getHostUserInfo()).length != 0
|
||||
userInfo: initialUserInfo,
|
||||
hasLogin: Object.keys(initialUserInfo).length != 0
|
||||
}
|
||||
|
||||
// 定义 mutations, 修改属性
|
||||
@@ -69,17 +72,20 @@ export const mutations = {
|
||||
return false;
|
||||
},
|
||||
setUserInfo(data, {cover}={cover:false}) {
|
||||
let userInfo = cover?data:Object.assign(store.userInfo,data)
|
||||
store.userInfo = Object.assign({},userInfo)
|
||||
store.hasLogin = Object.keys(store.userInfo).length != 0
|
||||
// 确保data是一个对象
|
||||
const safeData = data && typeof data === 'object' ? data : {};
|
||||
let userInfo = cover ? safeData : Object.assign({}, store.userInfo || {}, safeData);
|
||||
store.userInfo = Object.assign({}, userInfo);
|
||||
store.hasLogin = Object.keys(store.userInfo).length != 0;
|
||||
|
||||
if (typeof uni !== 'undefined' && uni && typeof uni.setStorageSync === 'function') {
|
||||
try {
|
||||
uni.setStorageSync('uni-id-pages-userInfo', store.userInfo)
|
||||
uni.setStorageSync('uni-id-pages-userInfo', store.userInfo);
|
||||
} catch (e) {
|
||||
// 静默失败
|
||||
}
|
||||
}
|
||||
return data
|
||||
return safeData;
|
||||
},
|
||||
async logout() {
|
||||
// 检查 uni 是否可用
|
||||
|
||||
Reference in New Issue
Block a user