ZHIWEI666 commited on
Commit
47015d8
·
verified ·
1 Parent(s): d486d57

Upload 64 files

Browse files
前端页面/core/网络请求_基础设施.js CHANGED
@@ -343,18 +343,18 @@ async function request(endpoint, options = {}) {
343
  (error instanceof TypeError && error.message.includes('fetch')) // 网络错误
344
  );
345
 
346
- if (isRetryable && attempt < maxRetries) {
347
- lastError = error;
348
- continue; // 重试
 
 
 
 
 
 
349
  }
350
 
351
- // 🔧 P3优化:错误分类处理,提供更清晰的错误信息
352
- if (error.name === 'AbortError') {
353
- throw new Error('网络请求超时,请检查网络连接');
354
- }
355
- if (error instanceof TypeError && (error.message.includes('fetch') || error.message.includes('Failed to fetch'))) {
356
- throw new Error('网络连接失败,请检查网络');
357
- }
358
  if (error instanceof SyntaxError) {
359
  throw new Error('服务器响应格式错误');
360
  }
 
343
  (error instanceof TypeError && error.message.includes('fetch')) // 网络错误
344
  );
345
 
346
+ if (isRetryable) {
347
+ // 🔧 修复:重试耗尽时不再直接 throw(否则循环后的「过期缓存兜底」
348
+ // 分支永远不可达,断网时无法无缝切换本地数据)。记录友好错误后跳出循环,
349
+ // 让 GET 请求走过期缓存回退;无缓存时仍以该友好错误抛出。
350
+ lastError = error.name === 'AbortError'
351
+ ? new Error('网络请求超时,请检查网络连接')
352
+ : new Error('网络连接失败,请检查网络');
353
+ if (attempt < maxRetries) continue; // 重试
354
+ break; // 重试耗尽 → 跳到过期缓存兜底
355
  }
356
 
357
+ // 🔧 P3优化:错误分类处理,提供更清晰的错误信息(不可重试错误直接抛出)
 
 
 
 
 
 
358
  if (error instanceof SyntaxError) {
359
  throw new Error('服务器响应格式错误');
360
  }
前端页面/core/网络请求_缓存管理.js CHANGED
@@ -135,8 +135,9 @@ export function getCache(key) {
135
  _updateLRU(fk);
136
  return cached.value;
137
  }
138
- // 过期,清除
139
- localStorage.removeItem(fk);
 
140
  }
141
  } catch (e) {
142
  console.warn("⚠️ 缓存读取失败:", key);
@@ -180,8 +181,8 @@ export function getCacheWithMeta(key, ignoreExpiry = false) {
180
  _updateLRU(fk);
181
  return { value: cached.value, expired, found: true };
182
  }
183
- // 过期且不忽略,清除
184
- localStorage.removeItem(fk);
185
  }
186
  } catch (e) {
187
  console.warn("⚠️ 缓存读取失败:", key);
 
135
  _updateLRU(fk);
136
  return cached.value;
137
  }
138
+ // 🔧 修复:过期条目不再物理删除,保留给断网时的过期缓存兜底使用;
139
+ // 过期数据的真正清理由配额溢出时的 _cleanExpiredStorage / LRU 淘汰承担。
140
+ // (原实现此处删除会导致 request() 新鲜检查先删、离线兜底后读而落空)
141
  }
142
  } catch (e) {
143
  console.warn("⚠️ 缓存读取失败:", key);
 
181
  _updateLRU(fk);
182
  return { value: cached.value, expired, found: true };
183
  }
184
+ // 🔧 修复:与 getCache 一致,过期条目保留不删(供离线兜底),仅返回未命中;
185
+ // 内存中的过期副本已在上方删除,下次可重新从 storage 回填
186
  }
187
  } catch (e) {
188
  console.warn("⚠️ 缓存读取失败:", key);
前端页面/task/管理员仲裁组件.js CHANGED
@@ -9,7 +9,7 @@ import { api } from "../core/网络请求API.js";
9
  import { showToast } from "../components/UI交互提示组件.js";
10
  import { t, getLanguage } from "../components/用户体验增强.js";
11
  import { globalModal } from "../components/全局弹窗管理器.js";
12
- import { setCache, getCache, removeCache, createSkeleton } from "../components/性能优化工具.js";
13
 
14
  const escapeHtml = (str) => {
15
  if (!str) return '';
@@ -145,8 +145,8 @@ async function renderDisputeList(container, currentUser, statusFilter = null) {
145
  };
146
  });
147
 
148
- // 🚀 缓存优先策略:尝试从缓存加载
149
- const cachedData = getCache(CACHE_KEY);
150
 
151
  if (cachedData && cachedData.length > 0) {
152
  // 有缓存,先显示缓存数据
 
9
  import { showToast } from "../components/UI交互提示组件.js";
10
  import { t, getLanguage } from "../components/用户体验增强.js";
11
  import { globalModal } from "../components/全局弹窗管理器.js";
12
+ import { setCache, getCacheWithMeta, removeCache, createSkeleton } from "../components/性能优化工具.js";
13
 
14
  const escapeHtml = (str) => {
15
  if (!str) return '';
 
145
  };
146
  });
147
 
148
+ // 🚀 缓存优先策略:尝试从缓存加载(含过期缓存:离线容灾,与榜单/讨论区/任务榜一致)
149
+ const { value: cachedData } = getCacheWithMeta(CACHE_KEY, true);
150
 
151
  if (cachedData && cachedData.length > 0) {
152
  // 有缓存,先显示缓存数据