front/src/components/top-nav/index.vue
zzh 188675e9bf
All checks were successful
Build and Deploy Front / deploy (push) Successful in 10m35s
refine: 管理端顶栏透明坞与右侧工具条收束
统一菜单坞、页签字号与右侧分组触控态,去掉用户名展示并优化仓库入口,避免再加第二坞。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-25 11:21:51 +08:00

2012 lines
59 KiB
Vue
Raw 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.

<template>
<div id="top-nav" class="top-nav" :class="{ tabNavEnable: tabNavEnable }">
<div class="top-nav-header">
<!-- 左对齐菜单坞(与下方页签左缘对齐) -->
<div
class="top-nav-menu"
ref="topMenuCon"
@wheel="onMenuWheel"
@pointerleave="onMenuBarPointerLeave"
>
<a
v-if="navLogoSrc"
class="top-nav-logo"
href="/"
:title="brandCopy.navFullName"
@click="goOfficialSite"
>
<img :src="navLogoSrc" :alt="brandCopy.navName" />
</a>
<div
v-show="indicatorVisible"
class="top-nav-menu-indicator"
:class="{
'is-ready': indicatorReady,
'is-hover': indicatorIsHover,
}"
:style="indicatorStyle"
/>
<template v-if="topNavEnable">
<template v-for="item in fittedTopMenus" :key="menuKey(item)">
<a-trigger
v-if="hasChildren(item) && menuDataReady"
trigger="hover"
position="bl"
:popup-offset="0"
:popup-visible="openedSubmenuKey === menuKey(item)"
:mouse-enter-delay="SUBMENU_ENTER_DELAY"
:mouse-leave-delay="navPaintLock ? 0 : SUBMENU_LEAVE_DELAY"
@popup-visible-change="(v: boolean) => onSubmenuPopupVisibleChange(menuKey(item), v)"
>
<span
:ref="(el) => setMenuItemRef(menuKey(item), el)"
class="top-nav-menu-item"
:class="{
active: isTopMenuActive(item),
'is-open': openedSubmenuKey === menuKey(item),
}"
:data-menu-key="menuKey(item)"
@pointerenter="onMenuItemPointerEnter(menuKey(item))"
@click="(e: MouseEvent) => onTopMenuClick(e, item)"
>
{{ formatMenuTitle(item) }}
</span>
<template #content>
<div class="nav-submenu-panel">
<div class="nav-submenu-panel__bridge" aria-hidden="true" />
<div class="nav-submenu-panel__title">
{{ formatMenuTitle(item) }}
</div>
<div class="child-window">
<div
v-for="(row, rowIndex) in getMenuRows(filterPage(item.children))"
:key="rowIndex"
class="child-window-item"
>
<div
v-for="(menuItem, childItem) in row"
:key="childKey(menuItem, childItem)"
class="child-menu-item"
:class="{ active: isSubMenuActive(menuItem) }"
@pointerenter="prefetchMenuRoute(menuItem)"
@pointerdown.prevent="gotoFromSubmenu(menuItem)"
@click.prevent="gotoFromSubmenu(menuItem)"
>
<span class="child-menu-item__icon">
<component
:is="getSubMenuIcon(menuItem, item, menuNameToLocaleKeyMap)"
/>
</span>
<span class="child-menu-item__text">
{{ formatMenuTitle(menuItem) }}
</span>
</div>
</div>
</div>
</div>
</template>
</a-trigger>
<span
v-else
:ref="(el) => setMenuItemRef(menuKey(item), el)"
class="top-nav-menu-item"
:class="{ active: isTopMenuActive(item) }"
:data-menu-key="menuKey(item)"
@pointerenter="onMenuItemPointerEnter(menuKey(item))"
@click="(e: MouseEvent) => onTopMenuClick(e, item)"
>
{{ formatMenuTitle(item) }}
</span>
</template>
<a-trigger
v-if="overflowTopMenus.length"
trigger="hover"
position="br"
:popup-offset="0"
:popup-visible="openedSubmenuKey === MORE_MENU_KEY"
:mouse-enter-delay="SUBMENU_ENTER_DELAY"
:mouse-leave-delay="navPaintLock ? 0 : SUBMENU_LEAVE_DELAY"
@popup-visible-change="(v: boolean) => onSubmenuPopupVisibleChange(MORE_MENU_KEY, v)"
>
<span
:ref="(el) => setMenuItemRef(MORE_MENU_KEY, el)"
class="top-nav-menu-item top-nav-menu-more"
:class="{
active: isOverflowActive,
'is-open': openedSubmenuKey === MORE_MENU_KEY,
}"
:data-menu-key="MORE_MENU_KEY"
@pointerenter="onMenuItemPointerEnter(MORE_MENU_KEY)"
>
{{ t('nav.more', '更多') }}
</span>
<template #content>
<!-- 客户扁平导航:溢出项直接列表,不按一级分组 -->
<div v-if="isCustomerFlatNav" class="nav-more-panel nav-more-panel--flat">
<div
v-for="item in overflowTopMenus"
:key="menuKey(item)"
class="nav-more-item"
:class="{ active: isTopMenuActive(item) }"
@pointerenter="prefetchMenuRoute(item)"
@pointerdown.prevent="gotoFromSubmenu(item)"
@click.prevent="gotoFromSubmenu(item)"
>
<span class="nav-more-item__icon">
<component :is="getSubMenuIcon(item, undefined, menuNameToLocaleKeyMap)" />
</span>
<span class="nav-more-item__text">{{ formatMenuTitle(item) }}</span>
</div>
</div>
<div v-else class="nav-more-panel">
<div
v-for="item in overflowTopMenus"
:key="menuKey(item)"
class="nav-more-group"
>
<div
class="nav-more-group__title"
:class="{ active: isTopMenuActive(item) }"
@click="(e: MouseEvent) => onTopMenuClick(e, item)"
>
{{ formatMenuTitle(item) }}
</div>
<div
v-for="(child, childIdx) in filterPage(item.children)"
:key="childKey(child, childIdx)"
class="nav-more-item"
:class="{ active: isSubMenuActive(child) }"
@pointerenter="prefetchMenuRoute(child)"
@pointerdown.prevent="gotoFromSubmenu(child)"
@click.prevent="gotoFromSubmenu(child)"
>
<span class="nav-more-item__icon">
<component :is="getSubMenuIcon(child, item, menuNameToLocaleKeyMap)" />
</span>
<span class="nav-more-item__text">{{ formatMenuTitle(child) }}</span>
</div>
</div>
</div>
</template>
</a-trigger>
</template>
</div>
<!-- 右侧操作区:无坞;分组 + 细分割线,工具条感 -->
<div class="top-nav-right">
<!-- 余额(仅客户门户) -->
<div v-if="showBalanceNav" class="top-nav-right-cluster">
<div class="top-nav-right-item">
<a-dropdown trigger="hover" position="br">
<div class="balance-dropdown-trigger">
<span class="balance-label">{{ t('nav.balance.label') }}</span>
<span class="balance-value">{{ balanceDisplay }}</span>
</div>
<template #content>
<a-doption @click="() => onBalanceMenuClick({ key: 'recharge' })">
{{ t('nav.balance.recharge') }}
</a-doption>
<a-doption @click="() => onBalanceMenuClick({ key: 'rechargeRecord' })">
{{ t('nav.balance.rechargeRecord') }}
</a-doption>
<a-doption @click="() => onBalanceMenuClick({ key: 'accountFlow' })">
{{ t('nav.balance.accountFlow') }}
</a-doption>
<a-doption :disabled="balanceRefreshing" @click="onRefreshBalance">
{{ t('nav.balance.refresh') }}
</a-doption>
</template>
</a-dropdown>
</div>
</div>
<span v-if="showBalanceNav" class="top-nav-right-sep" aria-hidden="true" />
<div class="top-nav-right-cluster top-nav-right-cluster--meta">
<div class="top-nav-right-item top-nav-right-item--warehouse">
<ContactService variant="navbar" />
</div>
</div>
<span class="top-nav-right-sep" aria-hidden="true" />
<div class="top-nav-right-cluster">
<div class="top-nav-right-item top-nav-right-item--icon">
<a-tooltip
position="bottom"
:disabled="printConnectionState.connecting"
:mouse-enter-delay="0"
:mouse-leave-delay="0"
>
<template #content>
<span>{{ printConnectionTitle }}</span>
</template>
<span
class="print-connection-trigger"
role="button"
tabindex="0"
:class="{
'is-enabled': printConnectionState.enabled,
'is-loading': printConnectionState.connecting,
}"
@click.prevent="onPrintConnectionClick"
@keydown.enter.prevent="onPrintConnectionClick"
>
<icon-printer class="print-connection-icon" />
<span class="print-connection-dot" aria-hidden="true" />
</span>
</a-tooltip>
</div>
<div class="top-nav-right-item top-nav-right-item--icon">
<a-tooltip position="bottom" :mouse-enter-delay="0" :mouse-leave-delay="0">
<template #content>
<span>{{ t('nav.printControl.download') }}</span>
</template>
<a
class="print-connection-trigger print-control-download"
:href="PRINT_CONTROL_DOWNLOAD_URL"
target="_blank"
rel="noopener noreferrer"
:aria-label="t('nav.printControl.download')"
>
<icon-download class="print-connection-icon" />
</a>
</a-tooltip>
</div>
</div>
<span class="top-nav-right-sep" aria-hidden="true" />
<div class="top-nav-right-cluster">
<div class="top-nav-right-item top-nav-right-item--icon">
<RightTopMessage />
</div>
<div class="top-nav-right-item top-nav-right-item--icon">
<SelectLang />
</div>
</div>
<span class="top-nav-right-sep" aria-hidden="true" />
<div class="top-nav-right-cluster top-nav-right-cluster--user">
<div class="top-nav-right-item user-menu-item">
<RightTopUser compact />
</div>
</div>
</div>
</div>
<!-- Tab 导航栏 -->
<div v-if="tabNavEnable" class="top-nav-tabs">
<TabBar />
</div>
</div>
</template>
<script lang="ts" setup>
import { computed, ref, onMounted, onUnmounted, watch, nextTick, type ComponentPublicInstance } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { useAppStore } from '@/store';
import { useTabBarStore } from '@/store';
import { useRbacUserStore } from '@/store/modules/rbac-user';
import TabBar from '@/components/tab-bar/index.vue';
import RightTopUser from './RightTopUser.vue';
import RightTopMessage from './RightTopMessage.vue';
import SelectLang from './SelectLang.vue';
import ContactService from '@/components/ContactService/index.vue';
import { IconPrinter, IconDownload } from '@arco-design/web-vue/es/icon';
import { Message } from '@arco-design/web-vue';
import { openWindow, regexUrl } from '@/utils';
import { MenuService, AuthService } from '@/api/rbac';
import type { MenuTreeDto } from '@/api/rbac';
import { brandLogoImages } from '@/utils/brandLogo';
import { brandCopy } from '@/utils/brandCopy';
import {
initHiprintClientState,
setHiprintClientEnabled,
useHiprintClientState,
} from '@/utils/hiprint/hiprintClientState';
import { getMapIdFromAccessToken } from '@/utils/jwt';
import { getSubMenuIcon } from '@/utils/menu-icon';
import { MENU_NAME_TO_LOCALE_KEY, translateMenuTitle } from '@/utils/menu-i18n';
import { canAccessCustomerPortalRoute, isAdminPortalOnlyPath, isCustomerPortalOnlyPath } from '@/utils/login-portal';
import {
buildCustomerFlatNavMenus,
pickCustomerTopNavMenus,
} from '@/utils/customer-portal-nav';
import { resolveCurrentCustomer } from '@/api/customer/resolve';
import { CUSTOMER_BALANCE_CHANGED_EVENT } from '@/api/customer/accountFlow';
import { resolvePortalDrawerPanel } from '@/views/user/portal-drawer/types';
import { PRINT_CONTROL_DOWNLOAD_URL } from '@/constants/printControl';
import { armPageFlip } from '@/utils/page-transition-flag';
import {
ensureHeavyPlugins,
routeNeedsHeavyPlugins,
} from '@/plugins/heavy-plugins';
const { t } = useI18n();
const route = useRoute();
const router = useRouter();
const appStore = useAppStore();
const tabBarStore = useTabBarStore();
const rbacUserStore = useRbacUserStore();
const navLogoSrc = computed(() => brandLogoImages.portal);
const topMenuCon = ref<HTMLElement | null>(null);
const topNavEnable = computed(() => true); // 启用顶部导航
const tabNavEnable = computed(() => appStore.tabBar);
const printConnectionState = useHiprintClientState();
/** 顶栏 Logo → 官网首页(与登录门户切换同一套中心虹膜过渡) */
function goOfficialSite(e: MouseEvent) {
if (
e.button !== 0 ||
e.metaKey ||
e.ctrlKey ||
e.shiftKey ||
e.altKey
) {
return;
}
e.preventDefault();
if (route.name === 'siteRoot') return;
armPageFlip();
void router.push({ name: 'siteRoot' });
}
const menuItemEls = new Map<string, HTMLElement>();
const indicatorReady = ref(false);
const indicatorVisible = ref(false);
const indicatorStyle = ref<Record<string, string>>({
width: '0px',
transform: 'translate3d(0,0,0)',
});
/** 磁吸:当前指针悬停的一级菜单;空则吸回路由选中项 */
const hoverMenuKey = ref('');
/** 跳转中目标一级(路由尚未变时避免滑块先吸回旧项再弹到新项) */
const pendingNavTopKey = ref('');
/** 下拉进入/离开延迟(ms):偏快,横向扫菜单时几乎无感 */
const SUBMENU_ENTER_DELAY = 20;
const SUBMENU_LEAVE_DELAY = 120;
function menuKey(item: any): string {
return String(item?.path || item?.route || item?.id || item?.name || '');
}
function childKey(item: any, fallback: number | string): string {
return String(item?.path || item?.route || item?.id || fallback);
}
function setMenuItemRef(key: string, el: Element | ComponentPublicInstance | null) {
if (!key) return;
if (!el) {
menuItemEls.delete(key);
return;
}
const node = (el as ComponentPublicInstance).$el
? ((el as ComponentPublicInstance).$el as HTMLElement)
: (el as HTMLElement);
if (node instanceof HTMLElement) {
menuItemEls.set(key, node);
}
}
function resolveIndicatorKey() {
if (hoverMenuKey.value) return hoverMenuKey.value;
if (openedSubmenuKey.value) return openedSubmenuKey.value;
if (pendingNavTopKey.value) return pendingNavTopKey.value;
return isOverflowActive.value ? MORE_MENU_KEY : belongTopMenu.value;
}
function moveIndicatorToKey(key: string, opts?: { scrollIntoView?: boolean }) {
const wrap = topMenuCon.value;
if (!wrap || !key) {
indicatorVisible.value = false;
return;
}
const el = menuItemEls.get(key);
if (!el) {
indicatorVisible.value = false;
return;
}
const wrapRect = wrap.getBoundingClientRect();
const elRect = el.getBoundingClientRect();
const left = elRect.left - wrapRect.left + wrap.scrollLeft;
indicatorStyle.value = {
width: `${elRect.width}px`,
transform: `translate3d(${left}px, 0, 0)`,
};
indicatorVisible.value = true;
requestAnimationFrame(() => {
indicatorReady.value = true;
});
if (opts?.scrollIntoView) {
if (elRect.left < wrapRect.left + 8) {
wrap.scrollBy({ left: elRect.left - wrapRect.left - 24, behavior: 'smooth' });
} else if (elRect.right > wrapRect.right - 8) {
wrap.scrollBy({ left: elRect.right - wrapRect.right + 24, behavior: 'smooth' });
}
}
}
function updateActiveIndicator() {
moveIndicatorToKey(resolveIndicatorKey(), {
scrollIntoView: !hoverMenuKey.value && !openedSubmenuKey.value,
});
}
function onMenuItemPointerEnter(key: string) {
if (!key || hoverMenuKey.value === key) return;
hoverMenuKey.value = key;
moveIndicatorToKey(key);
}
function onMenuBarPointerLeave(e: PointerEvent) {
if (navPaintLock.value) return;
const next = e.relatedTarget as Node | null;
// 指针进入二级浮层时保持当前一级高亮,不吸回
if (
next &&
(next as Element).closest?.(
'.nav-submenu-panel, .nav-more-panel, .arco-trigger-popup',
)
) {
return;
}
hoverMenuKey.value = '';
moveIndicatorToKey(
openedSubmenuKey.value ||
pendingNavTopKey.value ||
(isOverflowActive.value ? MORE_MENU_KEY : belongTopMenu.value),
);
}
function onMenuWheel(e: WheelEvent) {
const wrap = topMenuCon.value;
if (!wrap) return;
if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) return;
const maxScroll = wrap.scrollWidth - wrap.clientWidth;
if (maxScroll <= 0) return;
e.preventDefault();
wrap.scrollLeft += e.deltaY;
moveIndicatorToKey(resolveIndicatorKey());
}
async function onTopMenuClick(e: MouseEvent, item: any) {
e.preventDefault();
const children = filterPage(item.children);
if (children.length > 0) {
// 有二级时只展开面板,不抢先进第一项(否则再点目标页等于连续加载两次)
if (openedSubmenuKey.value === MORE_MENU_KEY) {
return;
}
const key = menuKey(item);
openedSubmenuKey.value = key;
hoverMenuKey.value = key;
moveIndicatorToKey(key);
return;
}
paintNavThenGo(item);
}
async function onTogglePrintConnection(value: string | number | boolean) {
try {
await setHiprintClientEnabled(!!value);
} catch (e: any) {
Message.warning(`连接失败:${e?.message || '请先启动 hiprint 客户端'}`);
}
}
const printConnectionTitle = computed(() => {
if (printConnectionState.connecting) return '打印连接中…';
return printConnectionState.enabled ? '打印已连接,点击断开' : '打印未连接,点击连接';
});
async function onPrintConnectionClick() {
if (printConnectionState.connecting) return;
await onTogglePrintConnection(!printConnectionState.enabled);
}
// 菜单数据 - 全量菜单树和用户菜单权限
const allMenuTreeData = ref<MenuTreeDto[]>([]);
const menuLoading = ref(false);
const menuDataReady = ref(false);
// 使用 store 中的用户菜单权限(computed,自动响应式)
const userMenuTreeData = computed(() => rbacUserStore.menus || []);
// 根据用户菜单权限过滤菜单树(按菜单 Id + 权限码双重匹配,避免子菜单丢失)
function filterMenuByUserPermission(allMenus: MenuTreeDto[], userMenus: MenuTreeDto[]): MenuTreeDto[] {
const userMenuIdSet = new Set<string>();
const userPermissionSet = new Set(
(rbacUserStore.permissions || []).map((p) => String(p).toLowerCase()),
);
function collectMenuIds(menus: MenuTreeDto[]) {
menus.forEach(menu => {
if (menu.id) {
userMenuIdSet.add(String(menu.id));
}
if (menu.children && menu.children.length > 0) {
collectMenuIds(menu.children);
}
});
}
collectMenuIds(userMenus);
function hasMenuPermission(menu: MenuTreeDto): boolean {
const menuId = menu.id ? String(menu.id) : '';
if (menuId && userMenuIdSet.has(menuId)) {
return true;
}
const code = menu.permissionCode?.trim();
if (code && userPermissionSet.has(code.toLowerCase())) {
return true;
}
return false;
}
function filterMenus(menus: MenuTreeDto[]): MenuTreeDto[] {
const result: MenuTreeDto[] = [];
for (const menu of menus) {
let filteredChildren: MenuTreeDto[] | null = null;
if (menu.children && menu.children.length > 0) {
filteredChildren = filterMenus(menu.children);
}
const allowed = hasMenuPermission(menu)
|| (filteredChildren != null && filteredChildren.length > 0);
if (allowed) {
result.push({
...menu,
children: filteredChildren && filteredChildren.length > 0 ? filteredChildren : null,
});
}
}
return result;
}
return filterMenus(allMenus);
}
// 将 MenuTreeDto 转换为导航栏菜单格式
function convertMenuTreeToNavMenu(menuTree: MenuTreeDto[]): any[] {
return menuTree
.filter(menu => {
// 只显示一级菜单(type === 1 或没有 type)
if (menu.type === 2) return false; // 过滤按钮
if (menu.isHidden) return false; // 过滤隐藏菜单
return true;
})
.map(menu => {
const menuRoute = String(menu.route || '');
const navMenu: any = {
id: menu.id,
name: menu.name,
path: menu.route,
route: menu.route,
type: menu.type,
meta: {
title: menu.name,
icon: menu.icon,
order: menu.order,
isHide: menu.isHidden || false,
customerPortalOnly: isCustomerPortalOnlyPath(menuRoute),
adminPortalOnly: isAdminPortalOnlyPath(menuRoute),
},
};
// 只保留二级菜单,移除三级及更深层级
if (menu.children && menu.children.length > 0) {
navMenu.children = menu.children
.filter((child: MenuTreeDto) => {
if (child.type === 2) return false; // 过滤按钮
if (child.isHidden) return false; // 过滤隐藏菜单
return true;
})
.map((child: MenuTreeDto) => {
const childRoute = String(child.route || '');
// 移除二级菜单的 children
return {
id: child.id,
name: child.name,
path: child.route,
route: child.route,
type: child.type,
meta: {
title: child.name,
icon: child.icon,
order: child.order,
isHide: child.isHidden || false,
customerPortalOnly: isCustomerPortalOnlyPath(childRoute),
adminPortalOnly: isAdminPortalOnlyPath(childRoute),
},
};
});
}
return navMenu;
});
}
// 菜单数据 - 优先用用户 menus 立即渲染;全量树到位后按权限过滤
const menuData = computed(() => {
const userMenus = userMenuTreeData.value;
if (userMenus.length === 0) {
return [];
}
if (allMenuTreeData.value.length > 0) {
const filteredMenus = filterMenuByUserPermission(
allMenuTreeData.value,
userMenus,
);
return convertMenuTreeToNavMenu(filteredMenus);
}
return convertMenuTreeToNavMenu(userMenus);
});
/** 客户门户:压平后的全量二级(侧栏索引同源) */
const customerMenuSource = computed(() => {
const userMenus = userMenuTreeData.value;
if (!userMenus.length) return [];
if (allMenuTreeData.value.length > 0) {
return filterMenuByUserPermission(allMenuTreeData.value, userMenus);
}
return userMenus;
});
const customerFlatMenus = computed(() => {
if (!rbacUserStore.isCustomerPortal()) return [];
return buildCustomerFlatNavMenus(
customerMenuSource.value,
rbacUserStore.loginPortalType,
);
});
const isCustomerFlatNav = computed(() => rbacUserStore.isCustomerPortal());
const visibleTopMenus = computed(() => {
// 客户 P0/P1:顶栏只平铺高频二级,不再展示「订单/仓储/系统」等一级模块名
if (isCustomerFlatNav.value) {
return pickCustomerTopNavMenus(customerFlatMenus.value);
}
return menuData.value.filter((item: any) => !item.meta?.isHide);
});
const MORE_MENU_KEY = '__more__';
const MORE_BTN_RESERVE = 64;
const fittedTopMenus = ref<any[]>([]);
const overflowTopMenus = ref<any[]>([]);
const isOverflowActive = computed(() =>
overflowTopMenus.value.some((m) => menuKey(m) === belongTopMenu.value),
);
// 首屏先铺全量,避免 overflow 计算前菜单空白
watch(
visibleTopMenus,
(menus) => {
if (!fittedTopMenus.value.length && menus.length) {
fittedTopMenus.value = [...menus];
}
},
{ immediate: true },
);
let overflowRecalcToken = 0;
async function recalcMenuOverflow() {
const token = ++overflowRecalcToken;
const menus = visibleTopMenus.value;
if (!menus.length) {
fittedTopMenus.value = [];
overflowTopMenus.value = [];
return;
}
// 先全部放进可视区测量宽度
fittedTopMenus.value = [...menus];
overflowTopMenus.value = [];
await nextTick();
if (token !== overflowRecalcToken) return;
const wrap = topMenuCon.value;
if (!wrap) return;
const itemMargin = 6; // margin: 0 3px(程序坞内)
const logoEl = wrap.querySelector('.top-nav-logo') as HTMLElement | null;
const logoReserve = logoEl ? logoEl.offsetWidth + 8 : 0;
const widths = menus.map((item) => {
const el = menuItemEls.get(menuKey(item));
return (el?.offsetWidth || 56) + itemMargin;
});
const totalNeeded = widths.reduce((sum, w) => sum + w, 0);
const menuBudget = Math.max(80, wrap.clientWidth - logoReserve);
if (totalNeeded <= menuBudget + 1) {
fittedTopMenus.value = [...menus];
overflowTopMenus.value = [];
await nextTick();
updateActiveIndicator();
return;
}
const available = Math.max(80, menuBudget - MORE_BTN_RESERVE);
let used = 0;
let fitCount = 0;
for (let i = 0; i < menus.length; i++) {
const next = used + widths[i];
if (fitCount > 0 && next > available) break;
used = next;
fitCount += 1;
}
if (fitCount <= 0) fitCount = 1;
if (fitCount >= menus.length) {
fittedTopMenus.value = [...menus];
overflowTopMenus.value = [];
await nextTick();
updateActiveIndicator();
return;
}
let fit = menus.slice(0, fitCount);
let overflow = menus.slice(fitCount);
const activeKey = belongTopMenu.value;
const activeInOverflowIdx = overflow.findIndex((m) => menuKey(m) === activeKey);
if (activeKey && activeInOverflowIdx >= 0 && fit.length > 0) {
const [activeItem] = overflow.splice(activeInOverflowIdx, 1);
const displaced = fit.pop()!;
fit.push(activeItem);
overflow.unshift(displaced);
}
fittedTopMenus.value = fit;
overflowTopMenus.value = overflow;
await nextTick();
if (token !== overflowRecalcToken) return;
updateActiveIndicator();
}
/** 最长路径匹配,避免短前缀误高亮 */
const belongTopMenu = computed(() => {
const currentPath = route.path;
let bestKey = '';
let bestLen = -1;
for (const menu of visibleTopMenus.value) {
const menuPath = String(menu.path || menu.route || '');
const key = menuKey(menu);
if (!key) continue;
let score = -1;
if (menuPath && (currentPath === menuPath || currentPath.startsWith(`${menuPath}/`))) {
score = menuPath.length;
}
if (menu.children) {
for (const child of menu.children) {
const childPath = String(child.path || child.route || '');
if (
childPath &&
(currentPath === childPath || currentPath.startsWith(`${childPath}/`)) &&
childPath.length > score
) {
score = childPath.length;
}
}
}
if (score > bestLen) {
bestLen = score;
bestKey = key;
}
}
return bestKey;
});
function isTopMenuActive(item: any) {
return belongTopMenu.value === menuKey(item);
}
function getMenuItemPath(item: any): string {
return String(item?.path || item?.route || '');
}
/** 当前路由对应的最长匹配二级菜单 path,避免短前缀误高亮 */
const activeSubMenuPath = computed(() => {
const currentPath = route.path;
let best = '';
let bestLen = -1;
for (const menu of visibleTopMenus.value) {
for (const child of filterPage(menu.children) || []) {
const childPath = getMenuItemPath(child);
if (
childPath &&
(currentPath === childPath || currentPath.startsWith(`${childPath}/`)) &&
childPath.length > bestLen
) {
bestLen = childPath.length;
best = childPath;
}
}
}
return best;
});
function isSubMenuActive(item: any) {
const path = getMenuItemPath(item);
return !!path && path === activeSubMenuPath.value;
}
/** 弹出二级/更多菜单时,把当前页对应项滚入可视区 */
const openedSubmenuKey = ref('');
const navPaintLock = ref(false);
let navPaintUnlockTimer = 0;
const indicatorIsHover = computed(() => {
const activeKey = isOverflowActive.value ? MORE_MENU_KEY : belongTopMenu.value;
const shown = hoverMenuKey.value || openedSubmenuKey.value;
return !!shown && shown !== activeKey;
});
function onSubmenuPopupVisibleChange(key: string, visible: boolean) {
if (navPaintLock.value) {
openedSubmenuKey.value = '';
hoverMenuKey.value = '';
return;
}
if (visible) {
// 横向扫过相邻一级时直接换面板,避免先关再开闪一下
openedSubmenuKey.value = key;
hoverMenuKey.value = key;
moveIndicatorToKey(key);
// 展开一级时预取二级路由 chunk,缩短点击后白屏
if (key === MORE_MENU_KEY) {
overflowTopMenus.value.forEach((item) => {
filterPage(item.children).forEach((child) => prefetchMenuRoute(child));
});
} else {
const parent =
fittedTopMenus.value.find((m) => menuKey(m) === key) ||
overflowTopMenus.value.find((m) => menuKey(m) === key);
if (parent) {
filterPage(parent.children).forEach((child) => prefetchMenuRoute(child));
}
}
nextTick(() => {
requestAnimationFrame(() => {
const el = document.querySelector(
'.nav-submenu-panel .child-menu-item.active, .nav-more-panel .nav-more-item.active',
) as HTMLElement | null;
el?.scrollIntoView({ block: 'nearest', behavior: 'auto' });
});
});
return;
}
// 仅当关闭的是当前打开项时才清空(防止 A 的 leave 盖掉刚打开的 B)
if (openedSubmenuKey.value === key) {
openedSubmenuKey.value = '';
}
}
// 加载菜单:优先复用登录带回的 user menus,避免再打全量 get-menu-tree
async function loadMenuTree() {
menuLoading.value = true;
try {
if (!rbacUserStore.isLoggedIn) {
allMenuTreeData.value = [];
menuDataReady.value = true;
return;
}
let currentUserMenus = rbacUserStore.menus;
if (!currentUserMenus || currentUserMenus.length === 0) {
try {
await rbacUserStore.ensureCurrentUser();
currentUserMenus = rbacUserStore.menus;
} catch (userError) {
console.error('获取用户信息失败:', userError);
}
}
if (currentUserMenus && currentUserMenus.length > 0) {
allMenuTreeData.value = [];
await nextTick();
menuDataReady.value = true;
tabBarStore.refreshTagTitles();
return;
}
// 兜底:用户 menus 仍为空时再拉全量树(管理页等特殊场景)
try {
const allMenus = await MenuService.getRbacMenuGetMenuTree() || [];
allMenuTreeData.value = allMenus;
await nextTick();
menuDataReady.value = true;
tabBarStore.refreshTagTitles();
} catch (menuError) {
console.error('加载全量菜单树失败:', menuError);
allMenuTreeData.value = [];
await nextTick();
menuDataReady.value = true;
tabBarStore.refreshTagTitles();
}
} catch (error) {
console.error('加载菜单树或用户信息失败:', error);
allMenuTreeData.value = [];
await nextTick();
menuDataReady.value = true;
} finally {
menuLoading.value = false;
}
}
// 顶部菜单标题:按路由 locale / 中文名映射走 i18n,随语言切换更新
const formatMenuTitle = (menu: any) => {
if (!menu) return '';
if (typeof menu === 'string') {
return translateMenuTitle(t, { name: menu });
}
return translateMenuTitle(t, {
name: menu.name,
route: menu.route || menu.path,
path: menu.path || menu.route,
meta: menu.meta,
});
};
// 中文菜单名称到 locale key(图标辅助;与 menu-i18n 共用)
const menuNameToLocaleKeyMap = MENU_NAME_TO_LOCALE_KEY;
// 过滤页面 - 只显示2级菜单,忽略3级菜单
const filterPage = (pages?: any[]) => {
if (!pages) return [];
return pages
.filter(item => {
// 过滤掉隐藏的菜单
if (item.meta?.isHide || item.meta?.hideInMenu) return false;
// 过滤掉按钮类型的菜单
if (item.type === 2) return false;
const itemPath = String(item.path || item.route || '');
if (
!canAccessCustomerPortalRoute(rbacUserStore.loginPortalType, {
path: itemPath,
customerPortalOnly: item.meta?.customerPortalOnly,
adminPortalOnly: item.meta?.adminPortalOnly,
})
) {
return false;
}
if (
!rbacUserStore.isCustomerPortal() &&
(item.name === 'UserProfile' || item.title === '个人中心')
) {
return false;
}
return true;
})
.map(item => {
// 确保二级菜单不包含 children(三级菜单)
const { children, ...itemWithoutChildren } = item;
return itemWithoutChildren;
});
};
// 检查是否有子菜单
const hasChildren = (item: any) => {
if (!item.children || item.children.length === 0) return false;
// 检查是否有可见的子菜单
return item.children.some((child: any) => {
if (child.meta?.isHide || child.meta?.hideInMenu) return false;
if (child.type === 2) return false; // 过滤按钮
const childPath = String(child.path || child.route || '');
if (
!canAccessCustomerPortalRoute(rbacUserStore.loginPortalType, {
path: childPath,
customerPortalOnly: child.meta?.customerPortalOnly,
adminPortalOnly: child.meta?.adminPortalOnly,
})
) {
return false;
}
if (
!rbacUserStore.isCustomerPortal() &&
(child.name === 'UserProfile' || child.title === '个人中心')
) {
return false;
}
return true;
});
};
// 将菜单项按每行4个分组
const getMenuRows = (items: any[]) => {
const rows: any[][] = [];
for (let i = 0; i < items.length; i += 4) {
rows.push(items.slice(i, i + 4));
}
return rows;
};
// 路径到路由名称的映射(用于回退,避免使用中文显示名称)
const pathToRouteNameMap: Record<string, string> = {
'/channel/salesProducts': 'SalesProducts',
'/channel/serviceChannels': 'ServiceChannels',
'/channel/priceArea': 'PriceArea',
'/channel/blacklist': 'Blacklist',
'/channel/remoteZones': 'RemoteZones',
'/channel/weightRules': 'WeightRules',
'/channel/weightRounding': 'WeightRounding',
'/channel/autoTrigger': 'AutoTrigger',
'/channel/numberRules': 'NumberRules',
'/channel/issueTemplate': 'IssueTemplate',
'/channel/guide': 'ChannelGuide',
'/marketing/guide': 'MarketingGuide',
'/order/guide': 'OrderGuide',
'/warehouse/guide': 'WarehouseGuide',
'/operation/guide': 'OperationGuide',
'/kb/training': 'KbTraining',
'/kb/category': 'KbCategory',
'/kb/article': 'KbArticle',
// Track 相关路由
'/track/guide': 'TrackGuide',
'/track/order': 'TrackOrder',
'/track/warningOrder': 'TrackWarningOrder',
'/track/state': 'TrackState',
'/track/flag': 'TrackFlag',
'/track/content': 'TrackContent',
'/track/pull': 'TrackPull',
'/track/push': 'TrackPush',
'/track/kpiEarlyWarningConfig': 'KpiEarlyWarningConfig',
'/xhs/startService': 'XhsStartService',
'/xhs/analysis': 'XhsAnalysis',
'/xhs/creation': 'XhsCreation',
'/xhs/publishHistory': 'XhsPublishHistory',
'/xhs/skills': 'XhsSkills',
'/xhs/humanSettings': 'XhsHumanSettings',
'/user/marketing/invite': 'UserMarketingInvite',
'/user/marketing/member': 'UserMarketingMember',
'/user/marketing/coupons': 'UserMarketingCoupons',
'/user/marketing/commission': 'UserMarketingCommission',
};
// 跳转
const goto = (item: any) => {
if (!item) {
return;
}
// 获取路径,优先使用 path,其次使用 route
let targetPath = item.path || item.route;
if (!targetPath) {
return;
}
// 确保路径以 / 开头
if (!targetPath.startsWith('/') && !regexUrl.test(targetPath)) {
targetPath = '/' + targetPath;
}
// 如果是外部链接,使用 openWindow
if (regexUrl.test(targetPath)) {
openWindow(targetPath);
return;
}
const portalPanel = resolvePortalDrawerPanel(targetPath);
if (portalPanel) {
openPortalSideDrawer(portalPanel);
return;
}
if (router.currentRoute.value.path === targetPath) {
tabBarStore.clearPreview();
return;
}
// 使用路由 path 跳转
router.push(targetPath).catch((error) => {
tabBarStore.clearPreview();
console.error(`路由跳转失败: path=${targetPath}`, error);
// 尝试使用路由名称跳转(从映射中获取,而不是使用 item.name,因为 item.name 是中文显示名称)
const routeName = pathToRouteNameMap[targetPath];
if (routeName) {
router.push({ name: routeName }).catch((nameError) => {
console.error(`使用路由名称跳转也失败: name=${routeName}`, nameError);
});
} else {
// 如果没有映射,尝试使用 item.name(可能是路由名称,也可能是显示名称)
// 但这种情况应该尽量避免,因为 item.name 通常是显示名称
if (item.name && /^[A-Z]/.test(item.name)) {
// 如果 item.name 以大写字母开头,可能是路由名称
router.push({ name: item.name }).catch((nameError) => {
console.error(`使用路由名称跳转也失败: name=${item.name}`, nameError);
});
}
}
});
};
function prefetchMenuRoute(item: any) {
const rawPath = item?.path || item?.route;
if (!rawPath || regexUrl.test(rawPath)) return;
const targetPath = rawPath.startsWith('/') ? rawPath : `/${rawPath}`;
if (routeNeedsHeavyPlugins(targetPath)) {
void ensureHeavyPlugins();
}
try {
const resolved = router.resolve(targetPath);
const rec = resolved.matched[resolved.matched.length - 1];
const loader = rec?.components?.default as unknown;
if (typeof loader === 'function') {
const result = (loader as () => unknown)();
if (result && typeof (result as Promise<unknown>).then === 'function') {
(result as Promise<unknown>).catch(() => undefined);
}
}
} catch {
// 预取失败不影响点击跳转
}
}
function previewMenuNavigation(item: any) {
const rawPath = item?.path || item?.route;
if (!rawPath || regexUrl.test(rawPath)) return;
const targetPath = rawPath.startsWith('/') ? rawPath : `/${rawPath}`;
if (resolvePortalDrawerPanel(targetPath)) return;
try {
const resolved = router.resolve(targetPath);
const name = String(resolved.name || '');
if (!name) return;
tabBarStore.previewNavigate({
title: formatMenuTitle(item) || name,
name,
fullPath: resolved.fullPath || targetPath,
query: resolved.query,
});
} catch {
// 解析失败则等路由完成后再亮标签
}
}
/** 二级项所属一级(溢出则落到「更多」) */
function findTopMenuKeyForItem(item: any): string {
const targetKey = menuKey(item);
const targetPath = String(item?.path || item?.route || '');
if (!targetKey && !targetPath) return '';
for (const menu of visibleTopMenus.value) {
const topKey = menuKey(menu);
if (topKey && topKey === targetKey) {
return overflowTopMenus.value.some((m) => menuKey(m) === topKey)
? MORE_MENU_KEY
: topKey;
}
for (const child of filterPage(menu.children) || []) {
const childPath = String(child.path || child.route || '');
const childMatched =
(targetKey && menuKey(child) === targetKey) ||
(targetPath && childPath === targetPath);
if (!childMatched) continue;
return overflowTopMenus.value.some((m) => menuKey(m) === topKey)
? MORE_MENU_KEY
: topKey;
}
}
return '';
}
/** 先关弹层、亮标签,下一帧再走路由,避免页面重渲染把顶栏一起卡住 */
let navGoingTo = '';
function paintNavThenGo(item: any) {
const rawPath = String(item?.path || item?.route || '');
if (navGoingTo && navGoingTo === rawPath) return;
navGoingTo = rawPath;
// 先锁再关弹层,避免 leave/关闭回调把滑块吸回旧一级
navPaintLock.value = true;
pendingNavTopKey.value = findTopMenuKeyForItem(item);
openedSubmenuKey.value = '';
hoverMenuKey.value = '';
if (navPaintUnlockTimer) {
window.clearTimeout(navPaintUnlockTimer);
}
previewMenuNavigation(item);
// 先亮标签再跳转;单帧足够顶栏绘制,避免 nextTick+rAF+280ms 叠出可感延迟
nextTick(() => {
updateActiveIndicator();
goto(item);
navPaintUnlockTimer = window.setTimeout(() => {
navPaintLock.value = false;
if (
!pendingNavTopKey.value ||
pendingNavTopKey.value === belongTopMenu.value ||
(pendingNavTopKey.value === MORE_MENU_KEY && isOverflowActive.value)
) {
pendingNavTopKey.value = '';
}
navPaintUnlockTimer = 0;
navGoingTo = '';
updateActiveIndicator();
}, 120);
});
}
/** 子菜单点击后跳转(先关弹层,路由变化不再等页面) */
const gotoFromSubmenu = (item: any) => {
paintNavThenGo(item);
};
const showBalanceNav = computed(() => rbacUserStore.isCustomerPortal());
const customerBalance = ref<number | null>(null);
const balanceRefreshing = ref(false);
let balanceInflight: Promise<void> | null = null;
const balanceDisplay = computed(() => {
const raw = customerBalance.value;
if (raw == null) {
return '0.00';
}
const parsed = Number(raw);
return Number.isFinite(parsed) ? parsed.toFixed(2) : '0.00';
});
async function fetchCustomerBalance() {
if (!rbacUserStore.isCustomerPortal() || !rbacUserStore.isLoggedIn) {
customerBalance.value = null;
return;
}
const mapId = getMapIdFromAccessToken(rbacUserStore.accessToken);
const account = rbacUserStore.userInfo?.account?.trim() || '';
// 跳过 session 缓存:F5 也要拿到当前余额,不能沿用登录时写入的旧值
const data = await resolveCurrentCustomer({ mapId, account, force: true });
const raw = data?.accountBalance ?? data?.balance;
if (raw == null || raw === '') {
customerBalance.value = 0;
return;
}
const parsed = Number(raw);
customerBalance.value = Number.isFinite(parsed) ? parsed : 0;
}
function loadCustomerBalance() {
if (!balanceInflight) {
balanceInflight = fetchCustomerBalance().finally(() => {
balanceInflight = null;
});
}
return balanceInflight;
}
async function onRefreshBalance() {
if (balanceRefreshing.value) return;
balanceRefreshing.value = true;
const previous = customerBalance.value;
try {
await loadCustomerBalance();
Message.success(t('nav.balance.refreshed'));
} catch (error) {
console.error('Failed to load customer balance', error);
customerBalance.value = previous;
Message.error(t('nav.balance.refreshFailed'));
} finally {
balanceRefreshing.value = false;
}
}
// 点击余额菜单项
const onBalanceMenuClick = (event: any) => {
const { key } = event;
if (key === 'recharge') {
router.push({ name: 'VipRechargeDeposit' });
} else if (key === 'rechargeRecord') {
router.push({ name: 'FinanceRechargeRecord' });
} else if (key === 'accountFlow') {
router.push({ name: 'FinanceAccountFlow' });
}
};
watch(
() => [rbacUserStore.isLoggedIn, rbacUserStore.loginPortalType, rbacUserStore.accessToken] as const,
() => {
void loadCustomerBalance().catch((error) => {
console.error('Failed to load customer balance', error);
if (customerBalance.value == null) customerBalance.value = 0;
});
},
{ immediate: true }
);
function handleCustomerBalanceChanged() {
void loadCustomerBalance().catch((error) => {
console.error('Failed to load customer balance', error);
});
}
watch(
() => [belongTopMenu.value, menuDataReady.value, visibleTopMenus.value.length] as const,
async () => {
if (
pendingNavTopKey.value &&
(pendingNavTopKey.value === belongTopMenu.value ||
(pendingNavTopKey.value === MORE_MENU_KEY && isOverflowActive.value))
) {
pendingNavTopKey.value = '';
}
await nextTick();
await recalcMenuOverflow();
},
{ flush: 'post' },
);
function onWindowResize() {
void recalcMenuOverflow();
}
onMounted(async () => {
window.addEventListener(CUSTOMER_BALANCE_CHANGED_EVENT, handleCustomerBalanceChanged);
window.addEventListener('resize', onWindowResize, { passive: true });
initHiprintClientState().catch(() => undefined);
await loadMenuTree();
await nextTick();
await recalcMenuOverflow();
});
onUnmounted(() => {
window.removeEventListener(CUSTOMER_BALANCE_CHANGED_EVENT, handleCustomerBalanceChanged);
window.removeEventListener('resize', onWindowResize);
if (navPaintUnlockTimer) {
window.clearTimeout(navPaintUnlockTimer);
navPaintUnlockTimer = 0;
}
});
</script>
<style lang="less" scoped>
@headerInsetTop: 6px;
@headerBarHeight: 52px;
@headerHeight: (@headerInsetTop + @headerBarHeight); // 58:容纳 44px 菜单坞
@headerTabNavHeight: 28px;
.top-nav {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: @headerHeight;
padding-top: @headerInsetTop;
box-sizing: border-box;
z-index: 100;
/* 透出全局固着浅雾,与主内容同一张底 */
background: transparent;
box-shadow: none;
border-bottom: none;
&.tabNavEnable {
height: (@headerHeight + @headerTabNavHeight);
}
.top-nav-header {
position: relative;
display: flex;
width: 100%;
height: @headerBarHeight;
padding: 0 12px;
box-sizing: border-box;
background: transparent !important;
background-color: transparent !important;
color: var(--color-text-1, #1d2129);
align-items: center;
gap: 12px;
/* 左对齐白坞:宽随内容,与页签左缘同起点 */
.top-nav-menu {
position: relative;
z-index: 1;
flex: 0 1 auto;
min-width: 0;
width: max-content;
max-width: calc(100% - 280px);
height: 44px;
margin-left: 4px;
padding: 0 12px 0 8px;
overflow: hidden;
overflow-x: auto;
display: flex;
align-items: center;
justify-content: flex-start;
scroll-behavior: smooth;
background: rgba(255, 255, 255, 0.94);
border-radius: 22px;
/* 单层短阴影 + 淡描边,避免多层发糊 */
border: 1px solid rgba(15, 23, 42, 0.06);
box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
.top-nav-logo {
position: relative;
z-index: 2;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
width: 32px;
height: 32px;
margin-right: 6px;
border-radius: 10px;
color: inherit;
text-decoration: none;
cursor: pointer;
img {
height: 28px;
width: 28px;
box-sizing: border-box;
object-fit: contain;
display: block;
background: transparent;
border: none;
border-radius: 0;
padding: 0;
}
}
.top-nav-menu-indicator {
position: absolute;
top: 50%;
left: 0;
z-index: 0;
height: 30px;
margin-top: -15px;
border-radius: 15px;
/* 选中态克制:约 9% 主色,偏状态感而非按钮 */
background-color: color-mix(
in srgb,
var(--app-primary-color, #054f74) 9%,
#fff
);
pointer-events: none;
will-change: transform, width;
opacity: 1;
&.is-ready {
/* 稳重缓动,少弹跳 */
transition:
transform 0.22s cubic-bezier(0.4, 0, 0.2, 1),
width 0.22s cubic-bezier(0.4, 0, 0.2, 1),
opacity 0.16s ease,
background-color 0.16s ease;
}
&.is-hover {
opacity: 1;
background-color: rgba(0, 0, 0, 0.035);
}
}
.top-nav-menu-item {
position: relative;
z-index: 1;
display: inline-flex;
align-items: center;
justify-content: center;
height: 30px;
padding: 0 14px;
line-height: 1;
text-decoration: none;
color: var(--color-text-2, #4e5969);
font-size: 13px;
border-radius: 15px;
white-space: nowrap;
margin: 0 3px;
cursor: pointer;
background-color: transparent;
transition: color 0.16s ease;
&:hover {
color: var(--color-text-1, #1d2129);
}
&:active {
opacity: 0.85;
}
&.active,
&.is-open {
color: var(--app-primary-color, #054f74);
font-weight: 600;
background-color: transparent;
}
}
.top-nav-menu-more {
flex-shrink: 0;
}
}
.top-nav-right {
position: relative;
z-index: 2;
display: flex;
align-items: center;
justify-content: flex-end;
flex: 0 0 auto;
gap: 0;
margin-left: auto;
padding-right: 8px;
height: @headerBarHeight;
white-space: nowrap;
.top-nav-right-cluster {
display: inline-flex;
align-items: center;
gap: 2px;
min-width: 0;
&--meta {
gap: 0;
}
&--user {
gap: 0;
padding-left: 2px;
}
}
.top-nav-right-sep {
flex-shrink: 0;
width: 1px;
height: 14px;
margin: 0 8px;
background: rgba(15, 23, 42, 0.1);
border-radius: 1px;
}
.top-nav-right-item {
display: flex;
align-items: center;
height: 100%;
padding: 0;
position: relative;
&--warehouse {
max-width: 180px;
}
}
.print-connection-trigger {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
width: 30px;
height: 30px;
border-radius: 9px;
color: var(--color-text-3, #86909c);
text-decoration: none;
cursor: pointer;
outline: none;
transition:
color 0.16s ease,
background-color 0.16s ease,
opacity 0.16s ease;
&:hover {
color: var(--color-text-1, #1d2129);
background-color: rgba(15, 23, 42, 0.045);
}
&.is-enabled {
color: var(--color-text-1, #1d2129);
}
&.is-loading {
opacity: 0.5;
pointer-events: none;
}
}
.print-connection-icon {
font-size: 15px;
}
.print-connection-dot {
position: absolute;
right: 5px;
bottom: 5px;
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--color-text-4, #c9cdd4);
box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.92);
}
.print-connection-trigger.is-enabled .print-connection-dot {
background: #22c55e;
}
.balance-dropdown-trigger {
display: inline-flex;
align-items: baseline;
gap: 6px;
height: 30px;
padding: 0 10px;
border-radius: 999px;
white-space: nowrap;
cursor: pointer;
color: inherit;
text-decoration: none;
transition: background-color 0.16s ease;
&:hover {
background-color: rgba(15, 23, 42, 0.045);
}
.balance-label {
font-size: 11px;
font-weight: 500;
letter-spacing: 0.04em;
color: var(--color-text-3, #86909c);
text-transform: uppercase;
}
.balance-value {
font-size: 13px;
font-weight: 600;
letter-spacing: -0.01em;
color: var(--color-text-1, #1d2129);
font-variant-numeric: tabular-nums;
}
}
.user-menu-item {
margin-left: 0;
padding-right: 2px;
}
/* 统一消息 / 语言触控态 */
:deep(.dropDown) {
width: 30px;
height: 30px;
min-width: 30px;
padding: 0;
border-radius: 9px;
color: var(--color-text-3, #86909c);
transition:
color 0.16s ease,
background-color 0.16s ease;
&:hover {
color: var(--color-text-1, #1d2129);
background-color: rgba(15, 23, 42, 0.045);
}
}
:deep(.message-dropdown-trigger) {
min-width: 30px;
height: 30px;
padding: 0 6px;
border-radius: 9px;
color: var(--color-text-3, #86909c);
transition:
color 0.16s ease,
background-color 0.16s ease;
&:hover {
color: var(--color-text-1, #1d2129);
background-color: rgba(15, 23, 42, 0.045);
}
}
:deep(.message-icon),
:deep(.lang-icon) {
font-size: 15px;
}
:deep(.message-count) {
font-size: 11px;
font-weight: 600;
letter-spacing: -0.02em;
opacity: 0.85;
}
/* 用户头像:右侧锚点,轻描边即可,不做坞 */
:deep(.user-dropdown-trigger.is-compact) {
width: 30px;
height: 30px;
border-radius: 50%;
&:hover {
background-color: transparent;
}
}
:deep(.user-avatar) {
width: 26px;
height: 26px;
box-shadow:
0 0 0 1px rgba(15, 23, 42, 0.08),
0 1px 2px rgba(15, 23, 42, 0.06);
transition: box-shadow 0.16s ease, transform 0.16s ease;
}
:deep(.user-dropdown-trigger:hover .user-avatar) {
box-shadow:
0 0 0 1px rgba(15, 23, 42, 0.12),
0 2px 6px rgba(15, 23, 42, 0.1);
transform: translateY(-0.5px);
}
}
}
.top-nav-tabs {
height: @headerTabNavHeight;
/* 与顶栏/页面同色,去掉分隔线,页签像浮在同一块底上 */
background: transparent;
border-bottom: none;
}
}
.nav-submenu-panel {
position: relative;
min-width: 600px;
max-width: 720px;
padding: 12px 16px 16px;
background: var(--app-elevated-bg, var(--app-card-bg));
border-radius: 8px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
/* 填补触发条与面板之间的空隙,鼠标移入二级时不会断 hover */
.nav-submenu-panel__bridge {
position: absolute;
top: -12px;
left: 0;
right: 0;
height: 12px;
}
.nav-submenu-panel__title {
margin-bottom: 10px;
padding-bottom: 8px;
border-bottom: 1px solid var(--color-border-2, var(--color-border-2));
font-size: 14px;
font-weight: 600;
color: var(--color-text-1, #1d2129);
}
.child-menu-item {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 8px 6px 10px;
border-radius: 4px;
cursor: pointer;
color: var(--color-text-1);
position: relative;
transition:
color 0.1s ease,
background-color 0.1s ease,
transform 0.1s ease;
&::before {
content: '';
position: absolute;
left: 0;
top: 20%;
bottom: 20%;
width: 2px;
border-radius: 1px;
background: transparent;
transition: background-color 0.1s ease;
}
&:hover {
color: var(--app-primary-color, rgb(var(--primary-6)));
background-color: var(--color-fill-2);
transform: translateX(2px);
&::before {
background: var(--app-primary-color, rgb(var(--primary-6)));
}
.child-menu-item__icon {
color: var(--app-primary-color, rgb(var(--primary-6)));
}
}
&.active {
color: var(--app-primary-color, rgb(var(--primary-6)));
background-color: var(--app-primary-color-light, var(--color-fill-2));
&::before {
background: var(--app-primary-color, rgb(var(--primary-6)));
}
.child-menu-item__icon {
color: var(--app-primary-color, rgb(var(--primary-6)));
}
}
&:active {
background-color: var(--color-fill-3);
transform: translateX(1px) scale(0.99);
}
&__icon {
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
width: 16px;
height: 16px;
font-size: 16px;
color: var(--color-text-3);
transition: color 0.1s ease;
}
&__text {
line-height: 1.4;
font-size: 14px;
word-break: break-all;
}
}
.nav-more-panel {
min-width: 220px;
max-width: 320px;
max-height: min(70vh, 520px);
overflow: auto;
padding: 8px;
background: var(--app-elevated-bg, var(--app-card-bg));
border-radius: 8px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
&--flat {
min-width: 180px;
.nav-more-item {
padding-left: 10px;
&::before {
display: none;
}
}
}
}
.nav-more-group {
padding: 4px 0 8px;
& + & {
border-top: 1px solid var(--color-border-2, var(--color-border-2));
margin-top: 4px;
padding-top: 8px;
}
&__title {
padding: 6px 10px;
font-size: 13px;
font-weight: 600;
color: var(--color-text-1, #1d2129);
border-radius: 6px;
cursor: pointer;
&:hover {
color: var(--app-primary-color, rgb(var(--primary-6)));
background: var(--color-fill-2);
}
&.active {
color: var(--app-primary-color, rgb(var(--primary-6)));
background: var(--app-primary-color-light, var(--color-fill-2));
}
}
}
.nav-more-item {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 10px 6px 18px;
border-radius: 6px;
cursor: pointer;
color: var(--color-text-2);
position: relative;
transition:
color 0.1s ease,
background-color 0.1s ease,
transform 0.1s ease;
&::before {
content: '';
position: absolute;
left: 8px;
top: 22%;
bottom: 22%;
width: 2px;
border-radius: 1px;
background: transparent;
transition: background-color 0.1s ease;
}
&:hover {
color: var(--app-primary-color, rgb(var(--primary-6)));
background: var(--color-fill-2);
transform: translateX(2px);
&::before {
background: var(--app-primary-color, rgb(var(--primary-6)));
}
}
&.active {
color: var(--app-primary-color, rgb(var(--primary-6)));
background: var(--app-primary-color-light, var(--color-fill-2));
&::before {
background: var(--app-primary-color, rgb(var(--primary-6)));
}
.nav-more-item__icon {
color: var(--app-primary-color, rgb(var(--primary-6)));
}
}
&:active {
transform: translateX(1px) scale(0.99);
}
&__icon {
display: inline-flex;
width: 14px;
height: 14px;
font-size: 14px;
color: var(--color-text-3);
}
&__text {
font-size: 13px;
line-height: 1.4;
}
}
.child-window {
width: 100%;
}
.child-window-item {
border-bottom: 1px dashed #eee;
padding-bottom: 1rem;
margin-bottom: 1rem;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 0.5rem 1rem;
&:last-child {
border-bottom: none;
margin-bottom: 0;
}
}
// 程序坞内隐藏滚动条,溢出靠「更多」与滚轮
.top-nav-menu {
scrollbar-width: none;
&::-webkit-scrollbar {
height: 0;
display: none;
}
}
</style>