收费总览页面

This commit is contained in:
zhouyanli
2026-08-07 16:36:05 +08:00
parent d8faa12083
commit 5b23e48e2c
12 changed files with 163 additions and 61 deletions

View File

@@ -136,6 +136,13 @@ import { usePermStore } from '@/stores/usePermStore'
const permStore = usePermStore()
// 首次加载标记:onLoad 和 onShow 在首次进入时都会触发,用此标记避免重复请求
const hasInit = ref(false)
// banner 缓存 key 和缓存时长(30分钟)
const BANNER_CACHE_KEY = 'home_banner_cache'
const BANNER_CACHE_TIME = 30 * 60 * 1000
// 列表数据状态
const currentCommunity = ref('请先绑定房屋')
const bannerList = ref([])
@@ -342,17 +349,34 @@ const getNoticeData = () => {
})
.catch(() => {})
}
// 获取bannar图
function getbannarData() {
// 获取bannar图(带缓存:30分钟内优先用缓存,请求成功后更新缓存)
function getbannarData(forceRefresh = false) {
// 非强制刷新时,优先读缓存
if (!forceRefresh) {
try {
const cached = uni.getStorageSync(BANNER_CACHE_KEY)
if (cached) {
const { data, time } = JSON.parse(cached)
if (data && data.length > 0 && Date.now() - time < BANNER_CACHE_TIME) {
bannerList.value = data
return // 缓存有效,不发起请求
}
}
} catch (e) {}
}
getBannarList()
.then(res => {
if (res.code === 200 && res.data) {
// 只有数据真正变化时才更新,避免 swiper 重新渲染导致闪动
const newData = res.data
const oldData = bannerList.value
if (JSON.stringify(newData) !== JSON.stringify(oldData)) {
bannerList.value = newData
}
// 写入缓存
uni.setStorageSync(BANNER_CACHE_KEY, JSON.stringify({
data: newData,
time: Date.now()
}))
} else {
bannerList.value = []
}
@@ -386,21 +410,26 @@ const slelctHomeData = data => {
getInspectionData()
}
const permissionlist = ref([])
onShow(() => {
if (!hasInit.value) {
// 首次加载:onLoad 已触发过核心数据请求,这里只补 onLoad 没调的和需要每次都刷新的
hasInit.value = true
getbannarData() // onLoad 没调 banner
getMyOrderNum() // onLoad 没调工单数
permStore.initPerm() // 刷新权限缓存
// currentVillageData 和 getInspectionData 已在 onLoad 中调用,不再重复
return
}
// 从其他页面返回 / 从后台恢复:只刷新可能变化的数据
getbannarData()
getInspectionData()
currentVillageData()
getMyOrderNum()
permStore.initPerm()
// 小区和巡检数据不频繁变化,从后台恢复时用缓存/旧数据,减少请求
})
onLoad(() => {
uni.$on('confirm', slelctHomeData)
// 优先调用接口获取当前小区,失败时再读缓存
currentVillageData()
getInspectionData()
// getbannarData()
})
onUnload(() => {