批量优化

This commit is contained in:
hero920103 committed 2026-10-03 23:46:55 +08:00
1 parent e3db229f41
commit aa92ca40a2
79 files changed
+7495 -1104

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
/**
* 移动端「工作台」接口
*
* /app/home 一次返回首屏所需的全部数据(应用模块卡片 + 可见菜单 + KPI),
* 避免移动端首屏多次往返。
*/
import { request } from '@/api/request.js'
/**
* 内存缓存:nav.vue 与 dashboard 都会拉同一份数据,
* 30 秒内复用,避免切页反复请求。登出/切换企业时由 clearHomeCache 失效。
*/
const CACHE_TTL = 30 * 1000
let cache = null
let cacheAt = 0
/** 工作台聚合数据:{ user, modules, menus, stats } */
export async function fetchHome(force = false) {
if (!force && cache && Date.now() - cacheAt < CACHE_TTL) return cache
const data = await request({
url: '/app/home',
method: 'GET',
silent: true,
timeout: 15000
})
cache = data
cacheAt = Date.now()
return data
}
/** 登出 / 切换企业后调用,避免脏数据留在内存缓存里 */
export function clearHomeCache() {
cache = null
cacheAt = 0
}