menu.js 911 B

123456789101112131415161718192021222324252627282930313233
  1. import { get } from './request.js'
  2. import { getToken } from './auth.js'
  3. import { resolveMenuIconColors } from './menu-icon-colors.js'
  4. function authHeader() {
  5. const token = getToken()
  6. return token ? { Authorization: 'Bearer ' + token } : {}
  7. }
  8. /** 当前用户移动端菜单(扁平列表) */
  9. export async function fetchMyMobileMenus() {
  10. const data = await get('/mini/menus', authHeader())
  11. const list = data?.list || data || []
  12. return list
  13. .map((m) => {
  14. const icon = m.icon || 'approve'
  15. const colors = resolveMenuIconColors({
  16. icon,
  17. iconBg: m.iconBg || m.icon_bg,
  18. iconFg: m.iconFg || m.icon_fg
  19. })
  20. return {
  21. id: m.id,
  22. title: m.title || m.menuName || m.menu_name,
  23. icon,
  24. path: m.path,
  25. iconBg: colors.iconBg,
  26. iconFg: colors.iconFg,
  27. tone: m.tone || ''
  28. }
  29. })
  30. .filter((m) => m.path)
  31. }