事先把遍历后的内容存储到内存中,免得查找其他作者时重新获取数据

This commit is contained in:
Kunagisa 2025-06-14 14:39:17 +08:00
parent 0317061c4d
commit 117dd2d233
2 changed files with 22 additions and 18 deletions

View File

@ -50,7 +50,7 @@ export const getUserInfo = async () => {
export const logoutUser = () => { // 不再是 async因为它不执行异步导航
// console.log('jwt.js: logoutUser called. Clearing local storage.');
localStorage.removeItem('access_token');
localStorage.removeItem('user_id'); // 如果您也存储了user_id
localStorage.removeItem('user_id');
// 导航将由调用者(如路由守卫)处理
};

View File

@ -182,18 +182,20 @@ const fetchAuthorMaps = async () => {
return
}
authorName.value = author
//
const cacheKey = 'allMaps'
let allMaps = []
const cached = sessionStorage.getItem(cacheKey)
if (cached) {
allMaps = JSON.parse(cached)
} else {
//
let page = 1
let hasMore = true
while (hasMore) {
const response = await getMaps({
page: page,
ordering: '-create_time'
})
if (response.results && response.results.length > 0) {
allMaps = allMaps.concat(response.results)
hasMore = !!response.next
@ -202,6 +204,8 @@ const fetchAuthorMaps = async () => {
hasMore = false
}
}
sessionStorage.setItem(cacheKey, JSON.stringify(allMaps))
}
//
authorMaps.value = allMaps.filter(map => map.user === author)
console.log('作者地图列表:', authorMaps.value)