WEB/src/layout/component/Navbar.vue
liufumingren e9c73ecd79 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>
2026-10-27 00:20:15 +08:00

458 lines
12 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 class="navbar">
<img :src="mainLogo" alt="logo" class="logo">
<breadcrumb v-if="layoutMode !== 'top-bottom'" class="breadcrumb-container" />
<div v-if="layoutMode === 'top-bottom'" class="top-menu-wrapper">
<top-menu />
</div>
<div class="right-menu">
<template v-if="device !== 'mobile'">
<!-- Validity indicator -->
<el-tooltip
v-if="userStore.checkPermission('dashboard.auth') && activeWarehouse"
class="item"
effect="dark"
:content="validityTooltip"
placement="bottom"
>
<div class="right-menu-item validity-item" :class="validityClass" @click="handleValidityClick">
<svg-icon icon-class="time" class="validity-icon" />
<span class="validity-text">{{ $t('common.validity') === 'common.validity' ? '有效期' : $t('common.validity') }}</span>
<span class="remaining-days" :class="daysClass">{{ remainingDays }}</span>
<span class="day-text">{{ $t('common.days') === 'common.days' ? '天' : $t('common.days') }}</span>
</div>
</el-tooltip>
<!-- Full Screen -->
<div class="right-menu-item" @click="toggle">
<svg-icon :icon-class="isFullscreen ? 'exit-fullscreen' : 'fullscreen'" />
</div>
<!-- WorkOrder -->
<router-link to="/workorder" class="right-menu-item workorder-item">
<el-badge :value="workOrderBadgeCount" :max="99" :hidden="!workOrderBadgeCount">
<div class="menu-item-content">
<svg-icon icon-class="message" />
<span class="menu-text">{{ tMenu('WorkOrder') }}</span>
</div>
</el-badge>
</router-link>
<!-- Language Select -->
<lang-select class="right-menu-item" />
</template>
<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 || defaultAvatar" class="user-avatar">
<svg-icon icon-class="eye" style="font-size: 10px; margin-left: 5px;" />
</div>
<template #dropdown>
<el-dropdown-menu class="user-dropdown">
<!-- Role Switching:无论几个身份都展示,便于确认当前所在身份/仓库 -->
<template v-if="user.employees && user.employees.length">
<el-dropdown-item
v-for="role in user.employees"
:key="role.id"
:class="role.is_primary == 1 ? 'on current-role' : 'other-role'"
@click="changeRole(role.id)"
>
{{ role.store_name }} | {{ role.real_name }}
</el-dropdown-item>
<el-dropdown-item divided />
</template>
<router-link to="/profile">
<el-dropdown-item>
{{ tMenu('Profile') }}
</el-dropdown-item>
</router-link>
<el-dropdown-item divided @click="logout">
<span style="display:block;">{{ $t('login.logOut') || 'Log Out' }}</span>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<div class="view-btn">
<!-- <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" title="AI 助手" @click="toggleAi">
<el-icon class="ai-icon"><ChatDotRound /></el-icon>
</div>
</div>
</div>
</div>
</template>
<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'
import { useFrontBrandStore } from '@/stores/modules/frontBrand'
import { useAiStore } from '@/stores/modules/ai'
import { useRouter, useRoute } from 'vue-router'
import Breadcrumb from '@/components/Breadcrumb/index.vue'
import LangSelect from '@/components/LangSelect/index.vue'
import TopMenu from './TopMenu.vue'
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()
const appStore = useAppStore()
const userStore = useUserStore()
const settingsStore = useSettingsStore()
const aiStore = useAiStore()
const router = useRouter()
const route = useRoute()
const sidebar = computed(() => appStore.sidebar)
const user = computed(() => userStore.user)
const avatar = computed(() => userStore.avatar)
// 主页面/顶栏 logo:优先主题约定 mainLogoUrl(theme.mainLogoUrl),缺省用默认图片
const frontBrandStore = useFrontBrandStore()
const mainLogo = computed(() => frontBrandStore.themeMainLogoUrl || '/logo/1.png')
const device = computed(() => appStore.device)
const layoutMode = computed(() => settingsStore.layoutMode)
const remainingDays = ref(0)
const isExpired = ref(false)
// ==================== 工单角标 ====================
const workOrderBadgeCount = ref(0)
let badgeTimer: ReturnType<typeof setInterval> | null = null
async function fetchWorkOrderBadge() {
try {
const res: any = await afterSaleWorkCount()
if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) {
workOrderBadgeCount.value = res.count ?? res.data?.count ?? 0
return
}
} catch { /* 接口未就绪,降级使用列表接口 */ }
// 降级:用 workList pageSize=1 获取总数
try {
const res: any = await afterSaleWorkList({
pagination: { page: 1, pageSize: 1 },
where: { status: { operator: 'in', value: ['pending', 'processing'] } },
})
if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) {
const data = res.data ?? res
workOrderBadgeCount.value = data.total ?? (data.pagination?.total ?? 0)
}
} catch { /* 静默失败 */ }
}
const activeWarehouse = computed(() => {
const employees = user.value.employees
if (!employees || !Array.isArray(employees)) return null
const primaryRole = employees.find((role: any) => role.is_primary == 1)
return primaryRole ? {
store_id: primaryRole.store_id,
auth_end: primaryRole.auth_end
} : null
})
const validityTooltip = computed(() => {
if (isExpired.value) {
return '已过期,只保留数据查询导出能力,点击跳转续费'
}
if (remainingDays.value <= 0) {
return '今天到期,点击跳转续费'
} else if (remainingDays.value <= 3) {
return `即将过期(剩余${remainingDays.value}天),点击跳转续费`
} else if (remainingDays.value <= 7) {
return `剩余${remainingDays.value}天,建议提前续费`
} else {
return `剩余${remainingDays.value}天有效期`
}
})
const validityClass = computed(() => {
if (isExpired.value) return 'is-expired'
if (remainingDays.value <= 7) return 'is-warning'
return ''
})
const daysClass = computed(() => {
if (remainingDays.value <= 3) return 'text-danger'
if (remainingDays.value <= 7) return 'text-warning'
return 'text-success'
})
const calculateDays = () => {
if (activeWarehouse.value && activeWarehouse.value.auth_end) {
const end = dayjs(activeWarehouse.value.auth_end)
const now = dayjs()
const diff = end.diff(now, 'day')
remainingDays.value = diff
isExpired.value = diff < 0
}
}
const toggleAi = () => {
aiStore.toggleAiContainer()
}
const toggleLayout = () => {
const newMode = layoutMode.value === 'sidebar' ? 'top-bottom' : 'sidebar'
settingsStore.changeSetting({ key: 'layoutMode', value: newMode })
}
const changeRole = async (roleId: number) => {
await userStore.changeRole(roleId)
location.reload()
}
const handleValidityClick = () => {
// Logic to redirect to renewal page if needed
router.push('/auth/approve')
}
const logout = async () => {
await userStore.logout()
router.push(`/login?redirect=${route.fullPath}`)
}
onMounted(() => {
calculateDays()
fetchWorkOrderBadge()
// 每 30 秒刷新一次工单角标
badgeTimer = setInterval(fetchWorkOrderBadge, 30000)
})
onUnmounted(() => {
if (badgeTimer) {
clearInterval(badgeTimer)
badgeTimer = null
}
})
</script>
<style lang="scss" scoped>
.navbar {
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 {
flex: 0 0 120px;
margin-left: 25px;
margin-right: 10px;
width: 120px;
height: 45px;
}
.hamburger-container {
height: 45px;
display: flex;
align-items: center;
float: left;
cursor: pointer;
transition: background .3s;
-webkit-tap-highlight-color: transparent;
&:hover {
background: rgba(0, 0, 0, .025)
}
}
.breadcrumb-container {
flex: 0 0 auto;
height: 45px;
display: flex;
align-items: center;
}
.top-menu-wrapper {
flex: 1 1 auto;
min-width: 0;
height: 45px;
margin-left: 10px;
overflow: hidden;
:deep(.top-menu-container) {
background-color: transparent !important;
border-bottom: none !important;
.top-menu {
height: 45px !important;
background-color: transparent !important;
display: flex;
align-items: center;
}
}
}
.right-menu {
flex: 0 0 auto;
margin-left: auto;
height: 45px;
display: flex;
align-items: center;
margin-right: 20px;
&:focus {
outline: none;
}
.right-menu-item {
display: inline-flex;
align-items: center;
padding: 0 12px;
height: 45px;
font-size: 14px;
color: #5a5e66;
vertical-align: text-bottom;
cursor: pointer;
transition: background .3s;
/* 顶栏为深色背景,图标统一跟随浅色文字,避免沿用侧边栏的深灰导致看不清 */
:deep(svg.svg-icon) {
color: aliceblue;
}
.day-text,
.validity-text {
color: aliceblue;
}
&:hover {
background: rgba(0, 0, 0, .025)
}
&.validity-item {
font-size: 12px;
.validity-icon {
margin-right: 4px;
}
.remaining-days {
font-weight: bold;
margin: 0 2px;
font-size: 14px;
}
&.is-warning {
color: #e6a23c;
}
&.is-expired {
color: #f56c6c;
}
}
.menu-item-content {
display: flex;
align-items: center;
.menu-text {
color: aliceblue;
margin-left: 4px;
}
}
}
.workorder-item {
overflow: visible;
:deep(.el-badge__content) {
top: 6px;
right: 4px;
}
}
.avatar-container {
.avatar-wrapper {
display: flex;
align-items: center;
position: relative;
.user-name {
color: aliceblue;
margin-right: 8px;
font-weight: 500;
}
.user-avatar {
width: 32px;
height: 32px;
border-radius: 50%;
}
.el-icon-caret-bottom {
cursor: pointer;
position: absolute;
right: -16px;
top: 50%;
transform: translateY(-50%);
font-size: 12px;
}
}
}
}
}
.text-danger { color: #f56c6c; }
.text-warning { color: #e6a23c; }
.text-success { color: #67c23a; }
.user-dropdown {
:deep(.current-role) {
background-color: rgba(0, 0, 0, .025) !important;
color: #409EFF !important;
font-weight: bold;
cursor: default;
}
:deep(.other-role) {
&:hover {
background-color: transparent !important;
color: inherit !important;
}
}
}
.view-btn {
display: flex;
flex-direction: row;
gap: 12px;
}
.view-change,
.ai-btn {
width: 32px;
height: 32px;
border-radius: 50%;
background-color: #409EFF;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
.ai-btn {
transition: background-color .3s;
&:hover {
background-color: #66b1ff;
}
.ai-icon {
color: #fff;
font-size: 18px;
}
}
</style>