修改首页轮播报错、活动显示、公共页样式显示、我的车位等bug
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
<scroll-view class="main-scroll" scroll-y>
|
||||
<!-- banner -->
|
||||
<view class="bannarClass">
|
||||
<up-swiper :list="bannerList" indicator indicatorMode="dot" imgMode="aspectFill" radius="10"></up-swiper>
|
||||
<up-swiper :key="bannerSwiperKey" :list="bannerList" indicator indicatorMode="dot" imgMode="aspectFill" radius="10"></up-swiper>
|
||||
</view>
|
||||
<!-- 公告 -->
|
||||
<view class="noticeClass" @click="getNoticeMore">
|
||||
@@ -139,7 +139,10 @@
|
||||
<text>{{activity.createName}}</text>
|
||||
</view>
|
||||
<view class="activity-enrollment">
|
||||
<text>活动名额{{activity.quota}}人,已报名{{activity.appliedCount}}人</text>
|
||||
<text>
|
||||
<text v-if="activity.quota !== 0">活动名额{{ activity.quota }},</text>
|
||||
已报名{{activity.appliedCount}}人
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</up-col>
|
||||
@@ -165,7 +168,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { ref, nextTick } from 'vue'
|
||||
import {onLoad,onUnload,onShow} from '@dcloudio/uni-app'
|
||||
import moment from 'moment'
|
||||
import {getNoticeLatest,getCurrentVillage,getActivitylatest,getBannarList,getReloadUserInfo} from "/pageSubPack/api/api.js"
|
||||
@@ -179,6 +182,7 @@ const currentCommunity = ref('请绑定房屋')
|
||||
const currentVillageId = ref('')
|
||||
const statusBarHeight = ref(0)
|
||||
const bannerList = ref([])
|
||||
const bannerSwiperKey = ref(0)
|
||||
const noticeText = ref('暂无公告')
|
||||
const noticeId = ref('')
|
||||
const lastUserId = ref('') // 用于检测是否切换账号
|
||||
@@ -201,7 +205,13 @@ const getbannarData = async () =>{
|
||||
try{
|
||||
const res = await getBannarList({villageId:uni.getStorageSync('currentVillageId')})
|
||||
if(res.code === 200){
|
||||
bannerList.value = res.data.map(item =>item.url)
|
||||
const newList = res.data.map(item => item.url)
|
||||
// 只有 banner 数据真正变化时才更新,避免 swiper 反复重建
|
||||
if (JSON.stringify(newList) !== JSON.stringify(bannerList.value)) {
|
||||
bannerList.value = newList
|
||||
await nextTick()
|
||||
bannerSwiperKey.value++
|
||||
}
|
||||
}else{
|
||||
uni.showToast({title:'获取失败',icon:'error'})
|
||||
}
|
||||
@@ -301,21 +311,24 @@ const refreshAllData = async () => {
|
||||
getbannarData()
|
||||
}
|
||||
|
||||
// 切换账号时重置页面数据
|
||||
const resetPageData = () => {
|
||||
currentCommunity.value = '请先绑定房屋'
|
||||
currentVillageId.value = ''
|
||||
activityList.value = []
|
||||
bannerList.value = []
|
||||
noticeText.value = '暂无公告'
|
||||
noticeId.value = ''
|
||||
}
|
||||
|
||||
onShow(() => {
|
||||
const currentUserId = uni.getStorageSync('userId') || ''
|
||||
// 检测到切换账号:重置数据并重新加载
|
||||
if (lastUserId.value && lastUserId.value !== currentUserId) {
|
||||
// 切换账号时重置页面数据
|
||||
currentCommunity.value = '请先绑定房屋'
|
||||
currentVillageId.value = ''
|
||||
activityList.value = []
|
||||
bannerList.value = []
|
||||
noticeText.value = '暂无公告'
|
||||
noticeId.value = ''
|
||||
resetPageData()
|
||||
refreshAllData()
|
||||
}
|
||||
// 首次显示 或 非切换账号的普通返回,也刷新数据
|
||||
else {
|
||||
} else {
|
||||
// 首次显示 或 非切换账号的普通返回,直接刷新数据(不清空已有数据)
|
||||
refreshAllData()
|
||||
}
|
||||
lastUserId.value = currentUserId
|
||||
@@ -331,8 +344,7 @@ onLoad(() => {
|
||||
// 记录当前用户ID,用于 onShow 中检测是否切换账号
|
||||
lastUserId.value = uni.getStorageSync('userId') || ''
|
||||
|
||||
// 页面加载时刷新数据
|
||||
refreshAllData()
|
||||
// 数据刷新统一放到 onShow,避免 onLoad + onShow 首次重复请求
|
||||
})
|
||||
|
||||
// 页面销毁时移除监听(防止内存泄漏)
|
||||
|
||||
Reference in New Issue
Block a user