58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
import { get } from './request.js'
|
|
import { getToken } from './auth-session.js'
|
|
import { resolveMenuIconColors } from './menu-icon-colors.js'
|
|
|
|
function authHeader() {
|
|
const token = getToken()
|
|
return token ? { Authorization: 'Bearer ' + token } : {}
|
|
}
|
|
|
|
/**
|
|
* 市场业务叶子 path → van-icon 名(与 static/menu-icons/market-*.png 对齐)。
|
|
* 后端未下发 icon 时由前端兜底,避免空置文字宫格。
|
|
*/
|
|
export function resolveMarketMenuIcon(path) {
|
|
const p = String(path || '').toLowerCase()
|
|
if (p.indexOf('market/webview') < 0 || p.indexOf('entry=') < 0) {
|
|
return ''
|
|
}
|
|
if (p.indexOf('payment-chase') >= 0) return 'market-payment-chase'
|
|
if (p.indexOf('presign') >= 0) return 'market-presign'
|
|
if (p.indexOf('protocol') >= 0) return 'market-protocol'
|
|
if (p.indexOf('payment') >= 0) return 'market-payment'
|
|
if (p.indexOf('freight') >= 0) return 'market-freight'
|
|
return ''
|
|
}
|
|
|
|
/** 当前用户移动端菜单(扁平列表) */
|
|
export async function fetchMyMobileMenus() {
|
|
const data = await get('/mini/menus', authHeader())
|
|
const list = data?.list || data || []
|
|
return list.map(normalizeMenu).filter((m) => m.path)
|
|
}
|
|
|
|
export function normalizeMenu(m = {}) {
|
|
const hasExplicitIcon = Object.prototype.hasOwnProperty.call(m, 'icon')
|
|
let icon = hasExplicitIcon ? String(m.icon ?? '') : 'approve'
|
|
const path = m.path || ''
|
|
if (!icon) {
|
|
const marketIcon = resolveMarketMenuIcon(path)
|
|
if (marketIcon) icon = marketIcon
|
|
}
|
|
const colors = resolveMenuIconColors({
|
|
icon,
|
|
iconBg: m.iconBg || m.icon_bg,
|
|
iconFg: m.iconFg || m.icon_fg
|
|
})
|
|
return {
|
|
id: m.id,
|
|
title: m.title || m.menuName || m.menu_name,
|
|
groupTitle: m.groupTitle || m.group_title || '',
|
|
icon,
|
|
path,
|
|
iconBg: colors.iconBg,
|
|
iconFg: colors.iconFg,
|
|
tone: m.tone || ''
|
|
}
|
|
}
|