Files
2026-11-03 11:13:59 +08:00

65 lines
1.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 移动端「工作台」接口
*
* /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
}
/**
* 免登录模块宫格:GET /api/modules/public(公开接口,无需 token)。
* 返回 [{ id, code, name, icon, path, description, require_login }]。
* 供未登录用户渲染 nav 首页,按 require_login 决定点击是「进登录引导」还是「直接进入」。
*/
export function fetchPublicModules() {
return request({
url: '/api/modules/public',
method: 'GET',
silent: true,
timeout: 15000
})
}
/**
* 免登录菜单:GET /api/menus/public(公开接口,无需 token)。
* 返回 [{ id, pid, title, path, icon, type, sort, module, leaf }],
* 菜单级 require_login=0 的集合:游客(持游客令牌)可用功能的唯一入口清单,
* nav 宫格据此判定模块是否可免登录进入,子系统据此渲染游客功能列表。
*/
export function fetchPublicMenus() {
return request({
url: '/api/menus/public',
method: 'GET',
silent: true,
timeout: 15000
})
}