修复bug
This commit is contained in:
@@ -272,16 +272,27 @@
|
||||
dataLoaded.value = false
|
||||
}
|
||||
|
||||
const getCurrentCommunityData = () => {
|
||||
const getCurrentCommunityData = (reloadedVillageId) => {
|
||||
// 删除房屋后 reloadUserInfo 会返回 currentVillageId=0,
|
||||
// 此时直接清空,避免再请求可能返回过期数据的 /village/current 导致小区名残留
|
||||
if (reloadedVillageId === 0 || reloadedVillageId === '0') {
|
||||
currentCommunity.value = '请绑定房屋'
|
||||
currentVillageId.value = ''
|
||||
uni.removeStorageSync('currentVillageId')
|
||||
saveHomeCache()
|
||||
return Promise.resolve()
|
||||
}
|
||||
return getCurrentVillage().then(res => {
|
||||
if (res.code === 200 && res.data && res.data.villageId) {
|
||||
currentCommunity.value = res.data.villageName || '未命名小区'
|
||||
currentCommunity.value = res.data.villageName
|
||||
saveHomeCache()
|
||||
currentVillageId.value = res.data.villageId
|
||||
uni.setStorageSync('currentVillageId', res.data.villageId)
|
||||
} else {
|
||||
currentCommunity.value = '请绑定房屋'
|
||||
currentVillageId.value = ''
|
||||
uni.removeStorageSync('currentVillageId')
|
||||
saveHomeCache()
|
||||
}
|
||||
}).catch(err => {
|
||||
// 有 token 才提示错误(无 token 用户正常浏览首页,API 401 属于预期行为)
|
||||
@@ -317,20 +328,23 @@
|
||||
const token = uni.getStorageSync('token') || ''
|
||||
dataLoaded.value = true
|
||||
const needReload = uni.getStorageSync('needReloadUserInfo')
|
||||
// 重新加载用户信息时,拿到权威的 currentVillageId(删除房屋后会变成 0)
|
||||
let reloadedVillageId = null
|
||||
if (token && needReload) {
|
||||
uni.removeStorageSync('needReloadUserInfo')
|
||||
getReloadUserInfo().then(res => {
|
||||
try {
|
||||
const res = await getReloadUserInfo()
|
||||
if (res.code === 200 && res.data) {
|
||||
if (res.data.userId) uni.setStorageSync('userId', res.data.userId)
|
||||
const reloadedVillageId = res.data.currentVillageId || 0
|
||||
reloadedVillageId = res.data.currentVillageId || 0
|
||||
uni.setStorageSync('currentVillageId', reloadedVillageId)
|
||||
}
|
||||
}).catch(err => {
|
||||
} catch (err) {
|
||||
console.error('重新加载用户信息失败', err)
|
||||
})
|
||||
}
|
||||
}
|
||||
// 先获取小区信息,确保 villageId 已更新,再请求依赖 villageId 的接口
|
||||
await getCurrentCommunityData()
|
||||
await getCurrentCommunityData(reloadedVillageId)
|
||||
getNoticeData()
|
||||
getNewActivityList()
|
||||
getbannarData()
|
||||
@@ -361,12 +375,14 @@
|
||||
onShow(() => {
|
||||
const currentUserId = uni.getStorageSync('userId') || ''
|
||||
const userIdChanged = lastUserId.value !== currentUserId
|
||||
const needReload = uni.getStorageSync('needReloadUserInfo')
|
||||
refreshing.value = false
|
||||
if (userIdChanged) {
|
||||
resetPageData()
|
||||
refreshAllData()
|
||||
} else if (!dataLoaded.value) {
|
||||
} else if (!dataLoaded.value || needReload) {
|
||||
// 首次进入且之前因无 token 跳过了 API,现在有 token 则补拉
|
||||
// 或房屋/小区信息有变更(如删除房屋后),需要重新拉取
|
||||
refreshAllData()
|
||||
}
|
||||
lastUserId.value = currentUserId
|
||||
|
||||
Reference in New Issue
Block a user