Files
yunzerwebsiteallinone/uniapp/api/workspace.js
T
2026-10-07 13:46:32 +08:00

36 lines
947 B
JavaScript

/**
* 移动端「工作台」接口
*
* /api/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: '/api/home',
method: 'GET',
silent: true,
timeout: 15000
})
cache = data
cacheAt = Date.now()
return data
}
/** 登出 / 切换企业后调用,避免脏数据留在内存缓存里 */
export function clearHomeCache() {
cache = null
cacheAt = 0
}