refactor: 移除前端接口缓存 — 每次 onShow 都实时请求最新数据

This commit is contained in:
2026-06-09 09:21:16 +08:00
parent 4e4b7dac69
commit ac20a70a20
2 changed files with 8 additions and 32 deletions

View File

@@ -204,18 +204,9 @@ function openLink(url: string) {
// #endif
}
// 数据新鲜度控制30秒内不重复请求
let lastLoadTime = 0
const CACHE_TTL = 30000
async function loadData(silent = false, force = false) {
async function loadData(silent = false) {
await waitForReady()
// 数据新鲜度判断30秒内不重复请求
if (!force && silent && Date.now() - lastLoadTime < CACHE_TTL) {
return
}
try {
if (!silent) loading.value = true
loadError.value = false
@@ -226,7 +217,6 @@ async function loadData(silent = false, force = false) {
txStore.fetchTransactions({ page: 1 })
])
recentTx.value = txStore.transactions.slice(0, 5)
lastLoadTime = Date.now()
// 第二级:次要数据(异步,不阻塞首屏)
Promise.all([
@@ -270,13 +260,12 @@ onMounted(() => {
})
// Refresh data when returning from other pages (e.g., after adding a transaction)
// force=true 跳过缓存 TTL确保新记录立即可见
onShow(() => {
if (initialLoaded.value && !loading.value) loadData(true, true)
if (initialLoaded.value && !loading.value) loadData(true)
})
onPullDownRefresh(() => {
loadData(false, true).finally(() => uni.stopPullDownRefresh())
loadData().finally(() => uni.stopPullDownRefresh())
})
function goAdd(type: string) {