feat(nav): collapse top menu into a local-only "More" menu and fix navbar icons

- top menu: compute available width via flex layout (fixed logo / right-menu),
  collapse the overflow into a "更多" sub menu with one item per line and
  right-side flyout for nested menus
- align menu item heights (remove el-sub-menu 2px border causing 3px offset),
  rotate the "更多" caret when opened
- add local svg icons: fullscreen / exit-fullscreen / time / message / email
  (were referenced but never added, so the toolbar icons rendered empty)
- navbar icons follow the light text color instead of inheriting dark gray
- replace the empty chat button image with the ChatDotRound icon
- drop the external IM redirect in AiChat: the panel now stays in-app
- localize the avatar fallback (was wpimg.wallstcn.com)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
liufumingren 2026-10-27 00:20:15 +08:00
parent bb92c720fd
commit e9c73ecd79
11 changed files with 279 additions and 56 deletions

View File

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64">
<rect width="64" height="64" fill="#d8dee9"/>
<circle cx="32" cy="24" r="11" fill="#f5f7fa"/>
<path d="M32 38c-10 0-18 6-18 14v12h36V52c0-8-8-14-18-14z" fill="#f5f7fa"/>
</svg>

After

Width:  |  Height:  |  Size: 267 B

4
src/icons/svg/email.svg Normal file
View File

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path fill-rule="evenodd" d="M3 4h18a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1zm1 2v12h16V6H4z"/>
<path d="M4.6 6.4 12 11.6l7.4-5.2 1.2 1.7-8.6 6-8.6-6z"/>
</svg>

After

Width:  |  Height:  |  Size: 249 B

View File

@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M9 9h4v2h-2v2H9V9z"/>
<path d="M15 9v4h-2v-2h-2V9h4z"/>
<path d="M9 11v4H5v-2h2v-2h2z"/>
<path d="M15 11h4v2h-2v2h-2v-4z"/>
</svg>

After

Width:  |  Height:  |  Size: 209 B

View File

@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M3 3h7v2H5v5H3V3z"/>
<path d="M14 3h7v7h-2V5h-5V3z"/>
<path d="M3 14h2v5h5v2H3v-7z"/>
<path d="M19 14h2v7h-7v-2h5v-5z"/>
</svg>

After

Width:  |  Height:  |  Size: 206 B

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M4 3h16a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-9l-5 4v-4H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"/>
</svg>

After

Width:  |  Height:  |  Size: 164 B

4
src/icons/svg/time.svg Normal file
View File

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path fill-rule="evenodd" d="M12 2a10 10 0 1 1 0 20 10 10 0 0 1 0-20zm0 2a8 8 0 1 0 0 16 8 8 0 0 0 0-16z"/>
<path d="M11 5h2v7.1l3.9 2.3-1 1.7L11 13.3V5z"/>
</svg>

After

Width:  |  Height:  |  Size: 229 B

View File

@ -9,6 +9,7 @@ export default {
"validity": "Validity",
"days": "Days",
"refresh": "Refresh",
"More": "More",
"Close": "Close",
"Close Other": "Close Other",
"Close All": "Close All"

View File

@ -9,6 +9,7 @@ export default {
"validity": "有效期",
"days": "天",
"refresh": "刷新",
"More": "更多",
"Close": "关闭",
"Close Other": "关闭其他",
"Close All": "全部关闭"

View File

@ -109,14 +109,12 @@ import { ref, nextTick, onMounted, watch } from 'vue'
import { useAiStore, AI_IDENTITIES } from '@/stores/modules/ai'
import { Plus, Clock, Close, UserFilled, Service, Position, ChatDotRound, Delete, ArrowDown } from '@element-plus/icons-vue'
import type { ElScrollbar } from 'element-plus'
import { loginToIm } from '@/api/index'
import dayjs from 'dayjs'
const aiStore = useAiStore()
const inputMessage = ref('')
const scrollbarRef = ref<InstanceType<typeof ElScrollbar>>()
const showHistory = ref(false)
const IM_LOGIN_URL = 'https://192.168.11.56:9096/'
const getIconComponent = (iconName: string) => {
const icons: Record<string, any> = { Service }
@ -185,18 +183,6 @@ const sendMessage = () => {
}, 1000)
}
const openImPage = async () => {
try {
const res = await loginToIm()
const imCode = res?.data?.code
if (!imCode) return
const openUrl = `${IM_LOGIN_URL}?token=${encodeURIComponent(imCode)}`
window.open(openUrl, '_blank')
} catch (error) {
console.error('Failed to login to IM:', error)
}
}
watch(() => aiStore.messages.length, () => {
if (!showHistory.value) {
scrollToBottom()
@ -205,19 +191,7 @@ watch(() => aiStore.messages.length, () => {
onMounted(() => {
scrollToBottom()
if (aiStore.isVisible) {
openImPage()
}
})
watch(
() => aiStore.isVisible,
isVisible => {
if (isVisible) {
openImPage()
}
}
)
</script>
<style lang="scss" scoped>

View File

@ -47,7 +47,7 @@
<el-dropdown class="avatar-container right-menu-item" trigger="click">
<div class="avatar-wrapper">
<span class="user-name">{{ user.employees_name || user.username }}</span>
<img :src="avatar || 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif'" class="user-avatar">
<img :src="avatar || defaultAvatar" class="user-avatar">
<svg-icon icon-class="eye" style="font-size: 10px; margin-left: 5px;" />
</div>
<template #dropdown>
@ -81,8 +81,8 @@
<!-- <div class="view-change" @click="toggleLayout">
<svg-icon :icon-class="layoutMode === 'sidebar' ? 'tree' : 'table'" style="font-size: 20px; color: white;" />
</div> -->
<div class="ai-btn" @click="toggleAi">
<img class="ai-img" />
<div class="ai-btn" title="AI 助手" @click="toggleAi">
<el-icon class="ai-icon"><ChatDotRound /></el-icon>
</div>
</div>
</div>
@ -91,6 +91,7 @@
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { ChatDotRound } from '@element-plus/icons-vue'
import { useAppStore } from '@/stores/modules/app'
import { useUserStore } from '@/stores/modules/user'
import { useSettingsStore } from '@/stores/modules/settings'
@ -104,6 +105,7 @@ import dayjs from 'dayjs'
import { useFullscreen } from '@vueuse/core'
import { tMenu } from '@/lang/index'
import { afterSaleWorkCount, afterSaleWorkList } from '@/api/aftersale/index'
import defaultAvatar from '@/assets/images/avatar-default.svg'
const { isFullscreen, toggle } = useFullscreen()
@ -243,11 +245,13 @@ onUnmounted(() => {
height: 45px;
overflow: hidden;
position: relative;
display: flex;
align-items: center;
background-color: #0C90FF;
//box-shadow: 0 1px 4px rgba(0, 21, 41, .08);
.logo {
float: left;
flex: 0 0 120px;
margin-left: 25px;
margin-right: 10px;
width: 120px;
@ -269,16 +273,18 @@ onUnmounted(() => {
}
.breadcrumb-container {
float: left;
flex: 0 0 auto;
height: 45px;
display: flex;
align-items: center;
}
.top-menu-wrapper {
float: left;
flex: 1 1 auto;
min-width: 0;
height: 45px;
margin-left: 10px;
overflow: hidden;
:deep(.top-menu-container) {
background-color: transparent !important;
@ -294,7 +300,8 @@ onUnmounted(() => {
}
.right-menu {
float: right;
flex: 0 0 auto;
margin-left: auto;
height: 45px;
display: flex;
align-items: center;
@ -314,6 +321,11 @@ onUnmounted(() => {
cursor: pointer;
transition: background .3s;
/* 顶栏为深色背景,图标统一跟随浅色文字,避免沿用侧边栏的深灰导致看不清 */
:deep(svg.svg-icon) {
color: aliceblue;
}
.day-text,
.validity-text {
color: aliceblue;
@ -416,8 +428,7 @@ onUnmounted(() => {
}
.view-change,
.ai-btn ,
.ai-img {
.ai-btn {
width: 32px;
height: 32px;
border-radius: 50%;
@ -428,6 +439,19 @@ onUnmounted(() => {
cursor: pointer;
}
.ai-btn {
transition: background-color .3s;
&:hover {
background-color: #66b1ff;
}
.ai-icon {
color: #fff;
font-size: 18px;
}
}
</style>

View File

@ -1,5 +1,5 @@
<template>
<div class="top-menu-container">
<div ref="containerRef" class="top-menu-container">
<el-menu
:default-active="activeMenu"
mode="horizontal"
@ -9,31 +9,76 @@
:ellipsis="false"
class="top-menu"
>
<sidebar-item
v-for="route in permission_routes"
:key="route.path"
:item="route"
:base-path="route.path"
<sidebar-item
v-for="menuRoute in visibleRoutes"
:key="menuRoute.path"
:item="menuRoute"
:base-path="menuRoute.path"
:is-horizontal="true"
/>
<el-sub-menu v-if="overflowRoutes.length" index="__top_menu_more__" class="top-menu-more">
<template #title>
<span class="more-title">{{ moreText }}</span>
<el-icon class="more-arrow"><ArrowDown /></el-icon>
</template>
<sidebar-item
v-for="menuRoute in overflowRoutes"
:key="menuRoute.path"
:item="menuRoute"
:base-path="menuRoute.path"
:is-horizontal="true"
:is-nest="true"
/>
</el-sub-menu>
</el-menu>
<!-- 隐藏测量层:用同一套菜单组件量取自然宽度,用于计算需要收纳的菜单数量 -->
<div ref="measureRef" class="top-menu-measure" aria-hidden="true">
<el-menu mode="horizontal" :ellipsis="false" class="top-menu">
<sidebar-item
v-for="menuRoute in routes"
:key="menuRoute.path"
:item="menuRoute"
:base-path="menuRoute.path"
:is-horizontal="true"
/>
<el-sub-menu index="__top_menu_more_measure__" class="top-menu-more">
<template #title>
<span class="more-title">{{ moreText }}</span>
<el-icon class="more-arrow"><ArrowDown /></el-icon>
</template>
</el-sub-menu>
</el-menu>
</div>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { ArrowDown } from '@element-plus/icons-vue'
import { usePermissionStore } from '@/stores/modules/permission'
import SidebarItem from './Sidebar/SidebarItem.vue'
import variables from '@/styles/variables.module.scss'
const route = useRoute()
const permissionStore = usePermissionStore()
const { t, locale } = useI18n()
const permission_routes = computed(() => {
// Filter out hidden routes
return permissionStore.routes.filter((route: any) => !(route as any).hidden)
})
const containerRef = ref<HTMLElement>()
const measureRef = ref<HTMLElement>()
/** 一级菜单:过滤 hidden,保证与测量层渲染出的节点一一对应 */
const routes = computed(() =>
permissionStore.routes.filter(item => {
const { hidden, meta } = item as RouteRecordRaw & { hidden?: boolean }
return !hidden && !(meta as { hidden?: boolean } | undefined)?.hidden
})
)
const moreText = computed(() => t('common.More'))
const activeMenu = computed(() => {
const { meta, path } = route
@ -42,39 +87,125 @@ const activeMenu = computed(() => {
}
return path
})
/** 展示的一级菜单数量:先全量渲染,测量完成后收敛,避免首帧空白 */
const visibleCount = ref(Number.MAX_SAFE_INTEGER)
/** 各一级菜单的右边界(相对菜单左边界),用于累计已占用宽度 */
const itemRightEdges = ref<number[]>([])
/** 「更多」及其左侧间距占用的宽度 */
const moreBlockWidth = ref(0)
const visibleRoutes = computed(() => routes.value.slice(0, visibleCount.value))
const overflowRoutes = computed(() => routes.value.slice(visibleCount.value))
const recalcVisibleCount = () => {
const container = containerRef.value
const edges = itemRightEdges.value
if (!container) return
if (!edges.length) {
visibleCount.value = routes.value.length
return
}
const available = container.clientWidth
if ((edges[edges.length - 1] ?? 0) <= available) {
visibleCount.value = routes.value.length
return
}
// 放不下:预留「更多」的宽度后,取能完整展示的最长前缀
const limit = available - moreBlockWidth.value
let count = 0
for (const edge of edges) {
if (edge > limit) break
count += 1
}
visibleCount.value = count
}
/** 借助隐藏测量层量取一级菜单实际宽度,并重算收纳数量 */
const measureItems = () => {
const menuEl = measureRef.value?.querySelector('.top-menu') as HTMLElement | null
if (!menuEl) return
const children = Array.from(menuEl.children) as HTMLElement[]
if (!children.length) {
itemRightEdges.value = []
moreBlockWidth.value = 0
recalcVisibleCount()
return
}
// 最后一个子节点固定是「更多」触发器,其余为一级菜单
const moreEl = children[children.length - 1]
if (!moreEl) return
const itemEls = children.slice(0, -1)
const menuRect = menuEl.getBoundingClientRect()
const itemRects = itemEls.map(el => el.getBoundingClientRect())
itemRightEdges.value = itemRects.map(rect => rect.right - menuRect.left)
const moreRect = moreEl.getBoundingClientRect()
const lastRect = itemRects[itemRects.length - 1]
// 间距取「最后一个菜单项 → 更多」的真实间距,避免与外边距重复计算
const gap = lastRect ? Math.max(moreRect.left - lastRect.right, 0) : 0
moreBlockWidth.value = gap + moreRect.width
recalcVisibleCount()
}
const refresh = async () => {
await nextTick()
measureItems()
}
let resizeObserver: ResizeObserver | null = null
onMounted(() => {
refresh()
if (typeof ResizeObserver !== 'undefined') {
resizeObserver = new ResizeObserver(() => recalcVisibleCount())
if (containerRef.value) resizeObserver.observe(containerRef.value)
}
// 字体加载完成后文字宽度会变化,需要重新测量
document.fonts?.ready.then(() => measureItems()).catch(() => {})
})
onUnmounted(() => {
resizeObserver?.disconnect()
resizeObserver = null
})
watch(routes, refresh)
// 切换语言后菜单文本宽度会变化,需要重新测量
watch(locale, refresh)
</script>
<style lang="scss" scoped>
.top-menu-container {
position: relative;
width: 100%;
height: 45px;
background-color: v-bind('variables.menuBg');
border-bottom: 1px solid #d8dce5;
.top-menu {
border-bottom: none;
height: 45px;
display: flex;
align-items: center;
justify-content: flex-start;
padding-left: 20px;
/* Prevent menu items from wrapping and allow horizontal scroll when overflow */
/* 保持单行,超出的部分由「更多」收纳后隐藏,不再出现横向滚动 */
flex-wrap: nowrap;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
white-space: nowrap;
/* Let the menu grow to its content so inner scroll works */
min-width: max-content;
overflow: hidden;
padding-left: 20px;
:deep(.el-menu-item), :deep(.el-sub-menu__title) {
height: 40px !important;
line-height: 40px !important;
margin: 0px 4px;
border-radius: 4px;
/* 统一去掉下边框,避免下拉项与普通菜单项出现 2px 的高差 */
border-bottom: none !important;
font-size: 14px;
padding: 0 8px !important;
display: inline-flex;
white-space: nowrap;
&:hover {
background-color: rgba(0, 0, 0, 0.05) !important;
}
@ -84,5 +215,69 @@ const activeMenu = computed(() => {
display: none !important;
}
}
/* 一级菜单的外层 div 不参与压缩,保证实际渲染宽度与测量结果一致 */
:deep(.top-menu > div) {
flex: 0 0 auto;
display: flex;
align-items: center;
/* 链接层也用 flex,去掉 inline-flex 菜单项带来的行盒下沉(约 3px) */
> a {
display: flex;
align-items: center;
}
}
/* 下拉型一级菜单(如「商品管理」)同样按 flex 排布,避免比普通菜单项高 3px */
:deep(.top-menu > div > li.el-sub-menu) {
display: flex;
align-items: center;
}
.top-menu-more {
flex: 0 0 auto;
:deep(.el-sub-menu__title) {
display: inline-flex;
align-items: center;
gap: 4px;
}
.more-title {
white-space: nowrap;
line-height: 1;
}
.more-arrow {
width: 12px;
height: 12px;
margin: 0;
font-size: 12px;
line-height: 1;
transition: transform .2s ease;
}
&.is-opened .more-arrow {
transform: rotate(180deg);
}
}
/* 测量层:不参与布局与交互,仅用于量取菜单宽度 */
.top-menu-measure {
position: absolute;
top: 0;
left: 0;
height: 0;
overflow: hidden;
visibility: hidden;
pointer-events: none;
.top-menu {
width: max-content;
min-width: max-content;
overflow: visible;
}
}
}
</style>
</style>