2026-01-24 17:45:54 +03:30
|
|
|
<template>
|
2026-05-31 11:51:52 +03:30
|
|
|
<div
|
|
|
|
|
:class="[
|
|
|
|
|
prefixCls,
|
|
|
|
|
layoutStore.layout === 'top'
|
|
|
|
|
? 'top-menu-nav flex min-w-0 flex-1 items-center'
|
|
|
|
|
: `${layoutStore.layout}-menu`
|
|
|
|
|
]"
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
ref="menuScrollRef"
|
|
|
|
|
:class="[isTopMenu ? 'top-menu top-menu-scroll scroll-none min-w-0 flex-1' : '']"
|
|
|
|
|
@scroll="updateScrollArrows"
|
|
|
|
|
>
|
|
|
|
|
<AMenu
|
|
|
|
|
:mode="layoutStore.sideMenu.mode"
|
|
|
|
|
v-model:selectedKeys="selectedKeys"
|
|
|
|
|
:disabled-overflow="isTopMenu"
|
|
|
|
|
>
|
|
|
|
|
<template v-for="item in menu">
|
|
|
|
|
<BasicSubMenu
|
2026-01-24 17:45:54 +03:30
|
|
|
v-if="!item.meta?.hideChildren && item.children && item.children.length > 0"
|
|
|
|
|
:menu-item="item"
|
|
|
|
|
:key="item.name"
|
|
|
|
|
:level="1"
|
2026-05-31 11:51:52 +03:30
|
|
|
/>
|
|
|
|
|
<BaseMenuItem v-else :item="item" :key="item.name" />
|
|
|
|
|
</template>
|
|
|
|
|
</AMenu>
|
|
|
|
|
</div>
|
2026-01-24 17:45:54 +03:30
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
<button
|
|
|
|
|
v-if="isTopMenu"
|
|
|
|
|
v-show="showLeftArrow"
|
|
|
|
|
type="button"
|
|
|
|
|
class="top-menu-nav__btn top-menu-nav__btn--left"
|
|
|
|
|
aria-label="مشاهده ادامه منو"
|
|
|
|
|
@click="scrollMenu('left')"
|
|
|
|
|
>
|
|
|
|
|
<BaseIcon icon="vuesax-linear:arrow-left-1" size="18" />
|
|
|
|
|
</button>
|
2026-01-24 17:45:54 +03:30
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
<button
|
|
|
|
|
v-if="isTopMenu"
|
|
|
|
|
v-show="showRightArrow"
|
|
|
|
|
type="button"
|
|
|
|
|
class="top-menu-nav__btn top-menu-nav__btn--right"
|
|
|
|
|
aria-label="بازگشت در منو"
|
|
|
|
|
@click="scrollMenu('right')"
|
|
|
|
|
>
|
|
|
|
|
<BaseIcon icon="vuesax-linear:arrow-right-1" size="18" />
|
|
|
|
|
</button>
|
2026-01-24 17:45:54 +03:30
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2026-05-31 11:51:52 +03:30
|
|
|
import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
|
|
|
|
import type { ComputedRef } from 'vue'
|
|
|
|
|
import { sortBy } from 'lodash'
|
|
|
|
|
import { useResizeObserver } from '@vueuse/core'
|
|
|
|
|
import { usePrefix } from '@core/composable/usePrefix'
|
2026-01-24 17:45:54 +03:30
|
|
|
import BasicSubMenu from '@core/layouts/composnts/BasicSubMenu.vue'
|
2026-05-31 11:51:52 +03:30
|
|
|
import { useLayoutStore } from '@core/stores/layout'
|
2026-01-24 17:45:54 +03:30
|
|
|
import BaseMenuItem from '@core/layouts/composnts/BaseMenuItem.vue'
|
2026-05-31 11:51:52 +03:30
|
|
|
import type { RouteRecordName, RouteRecordRaw } from 'vue-router'
|
|
|
|
|
import { useRouterStore } from '@core/stores/router'
|
2026-01-24 17:45:54 +03:30
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
const SCROLL_STEP = 180
|
|
|
|
|
const EDGE_THRESHOLD = 2
|
|
|
|
|
|
|
|
|
|
const { prefixCls } = usePrefix('basic-menu')
|
2026-01-24 17:45:54 +03:30
|
|
|
const layoutStore = useLayoutStore()
|
|
|
|
|
const currentRoute = useRoute()
|
|
|
|
|
const selectedKeys = ref<(RouteRecordName | undefined)[]>([])
|
|
|
|
|
const routerStore = useRouterStore()
|
2026-05-31 11:51:52 +03:30
|
|
|
const menuScrollRef = ref<HTMLElement | null>(null)
|
|
|
|
|
const showLeftArrow = ref(false)
|
|
|
|
|
const showRightArrow = ref(false)
|
|
|
|
|
const rtlScrollMode = ref<'ltr' | 'negative' | 'positive'>('ltr')
|
2026-01-24 17:45:54 +03:30
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
const isTopMenu = computed(() => layoutStore.layout === 'top')
|
|
|
|
|
|
|
|
|
|
function detectRtlScrollMode(el: HTMLElement): 'ltr' | 'negative' | 'positive' {
|
|
|
|
|
if (getComputedStyle(el).direction !== 'rtl') return 'ltr'
|
|
|
|
|
|
|
|
|
|
const max = el.scrollWidth - el.clientWidth
|
|
|
|
|
if (max <= 0) return 'ltr'
|
|
|
|
|
|
|
|
|
|
const original = el.scrollLeft
|
|
|
|
|
el.scrollLeft = 1
|
|
|
|
|
const mode = el.scrollLeft === 0 ? 'positive' : 'negative'
|
|
|
|
|
el.scrollLeft = original
|
|
|
|
|
return mode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ensureRtlScrollMode(el: HTMLElement) {
|
|
|
|
|
if (rtlScrollMode.value !== 'ltr') return
|
|
|
|
|
rtlScrollMode.value = detectRtlScrollMode(el)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getNormalizedScroll(el: HTMLElement) {
|
|
|
|
|
const max = Math.max(0, el.scrollWidth - el.clientWidth)
|
|
|
|
|
if (max <= 1) return { max: 0, current: 0 }
|
|
|
|
|
|
|
|
|
|
ensureRtlScrollMode(el)
|
|
|
|
|
|
|
|
|
|
let current = el.scrollLeft
|
|
|
|
|
if (rtlScrollMode.value === 'negative') {
|
|
|
|
|
current = Math.abs(current)
|
|
|
|
|
} else if (rtlScrollMode.value === 'positive') {
|
|
|
|
|
current = max - current
|
2026-01-24 17:45:54 +03:30
|
|
|
}
|
|
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
return {
|
|
|
|
|
max,
|
|
|
|
|
current: Math.max(0, Math.min(max, current))
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-24 17:45:54 +03:30
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
function setNormalizedScroll(el: HTMLElement, normalized: number) {
|
|
|
|
|
const max = Math.max(0, el.scrollWidth - el.clientWidth)
|
|
|
|
|
const value = Math.max(0, Math.min(max, normalized))
|
|
|
|
|
|
|
|
|
|
if (rtlScrollMode.value === 'negative') {
|
|
|
|
|
el.scrollTo({ left: -value, behavior: 'smooth' })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rtlScrollMode.value === 'positive') {
|
|
|
|
|
el.scrollTo({ left: max - value, behavior: 'smooth' })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
el.scrollTo({ left: value, behavior: 'smooth' })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateScrollArrows() {
|
|
|
|
|
const el = menuScrollRef.value
|
|
|
|
|
if (!el || !isTopMenu.value) {
|
|
|
|
|
showLeftArrow.value = false
|
|
|
|
|
showRightArrow.value = false
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { max, current } = getNormalizedScroll(el)
|
|
|
|
|
if (max <= 1) {
|
|
|
|
|
showLeftArrow.value = false
|
|
|
|
|
showRightArrow.value = false
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showLeftArrow.value = current < max - EDGE_THRESHOLD
|
|
|
|
|
showRightArrow.value = current > EDGE_THRESHOLD
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function scrollMenu(side: 'left' | 'right') {
|
|
|
|
|
const el = menuScrollRef.value
|
|
|
|
|
if (!el) return
|
|
|
|
|
|
|
|
|
|
const { max, current } = getNormalizedScroll(el)
|
|
|
|
|
if (max <= 1) return
|
|
|
|
|
|
|
|
|
|
setNormalizedScroll(el, side === 'left' ? current + SCROLL_STEP : current - SCROLL_STEP)
|
|
|
|
|
scheduleArrowUpdate()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function scheduleArrowUpdate() {
|
|
|
|
|
window.setTimeout(updateScrollArrows, 350)
|
|
|
|
|
}
|
2026-01-24 17:45:54 +03:30
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
const path: (RouteRecordName | undefined)[] = []
|
|
|
|
|
|
|
|
|
|
function walkInRoutes(routes: RouteRecordRaw[]) {
|
|
|
|
|
for (const route of routes) {
|
|
|
|
|
if (route.name == currentRoute.name) {
|
|
|
|
|
path.push(route.name)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
if (route.children && route.children.length > 0) {
|
|
|
|
|
path.push(route.name)
|
|
|
|
|
const res = walkInRoutes(route.children)
|
|
|
|
|
if (!res) {
|
|
|
|
|
path.pop()
|
|
|
|
|
} else {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
walkInRoutes(routerStore.routes)
|
|
|
|
|
selectedKeys.value = path
|
|
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
nextTick(updateScrollArrows)
|
2026-01-24 17:45:54 +03:30
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const menu: ComputedRef<RouteRecordRaw[]> = computed(() => {
|
|
|
|
|
return sortBy(routerStore.routes, (item) => {
|
|
|
|
|
return item.meta?.order
|
|
|
|
|
}).filter((item) => !item.meta?.hideMenu)
|
|
|
|
|
})
|
2026-05-31 11:51:52 +03:30
|
|
|
|
|
|
|
|
watch(menu, () => nextTick(updateScrollArrows), { deep: true })
|
|
|
|
|
watch(isTopMenu, () => {
|
|
|
|
|
rtlScrollMode.value = 'ltr'
|
|
|
|
|
nextTick(updateScrollArrows)
|
|
|
|
|
})
|
|
|
|
|
watch(
|
|
|
|
|
() => currentRoute.name,
|
|
|
|
|
() => nextTick(updateScrollArrows)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
useResizeObserver(menuScrollRef, () => {
|
|
|
|
|
updateScrollArrows()
|
|
|
|
|
})
|
2026-01-24 17:45:54 +03:30
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="less">
|
|
|
|
|
@prefix: ~ '@{prefixCls}-basic-menu';
|
|
|
|
|
.@{prefix} {
|
2026-05-31 11:51:52 +03:30
|
|
|
&.top-menu-nav {
|
|
|
|
|
position: relative;
|
|
|
|
|
min-width: 0;
|
|
|
|
|
flex: 1;
|
|
|
|
|
}
|
2026-01-24 17:45:54 +03:30
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
.top-menu-nav__btn {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 50%;
|
|
|
|
|
z-index: 2;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
width: 30px;
|
|
|
|
|
height: 36px;
|
|
|
|
|
border: none;
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
background: #fff;
|
|
|
|
|
color: @primary-color;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
transform: translateY(-50%);
|
|
|
|
|
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
|
|
|
|
|
transition: background-color 0.2s ease;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
background: lighten(@primary-color, 53%);
|
2026-01-24 17:45:54 +03:30
|
|
|
}
|
|
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
&--left {
|
|
|
|
|
left: 0;
|
|
|
|
|
padding-right: 4px;
|
|
|
|
|
background: linear-gradient(to right, #fff 55%, rgba(255, 255, 255, 0.85));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&--right {
|
|
|
|
|
right: 0;
|
|
|
|
|
padding-left: 4px;
|
|
|
|
|
background: linear-gradient(to left, #fff 55%, rgba(255, 255, 255, 0.85));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&.top-menu,
|
|
|
|
|
.top-menu-scroll {
|
|
|
|
|
overflow-x: auto;
|
|
|
|
|
overflow-y: hidden;
|
|
|
|
|
flex: 1;
|
|
|
|
|
min-width: 0;
|
|
|
|
|
scrollbar-width: none;
|
|
|
|
|
|
|
|
|
|
&::-webkit-scrollbar {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-wrap: nowrap;
|
|
|
|
|
width: max-content;
|
|
|
|
|
border-bottom: none;
|
|
|
|
|
padding-top: 4px;
|
|
|
|
|
padding-bottom: 4px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-item,
|
|
|
|
|
.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-submenu {
|
2026-01-24 17:45:54 +03:30
|
|
|
padding: 0 5px;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
.ant-menu-horizontal > .ant-menu-item::after,
|
|
|
|
|
.ant-menu-horizontal > .ant-menu-submenu::after {
|
2026-01-24 17:45:54 +03:30
|
|
|
right: 0 !important;
|
|
|
|
|
left: 0 !important;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
.ant-menu-horizontal > .ant-menu-item-selected::after,
|
|
|
|
|
.ant-menu-horizontal > .ant-menu-submenu-selected::after {
|
2026-01-24 17:45:54 +03:30
|
|
|
position: absolute;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
border-bottom: 2px solid @primary-color;
|
|
|
|
|
transition: border-color 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
|
|
|
|
|
content: '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu-item-selected {
|
|
|
|
|
background-color: lighten(@primary-color, 53%);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu-item {
|
|
|
|
|
margin-left: 12px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
.ant-menu-item,
|
|
|
|
|
.ant-menu-submenu-title {
|
2026-01-24 17:45:54 +03:30
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
|
|
& .ant-menu-item-icon {
|
|
|
|
|
margin-right: unset !important;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** start style for horizontal menu */
|
|
|
|
|
|
|
|
|
|
.ant-menu-horizontal {
|
|
|
|
|
padding: 0 !important;
|
|
|
|
|
|
|
|
|
|
li {
|
|
|
|
|
padding: 5px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** end style for horizontal menu */
|
|
|
|
|
|
|
|
|
|
&-side-menu {
|
|
|
|
|
.ant-menu-item:not(.ant-menu-item-disabled):not(.ant-menu-item-selected):hover,
|
|
|
|
|
.ant-menu-submenu .ant-menu-submenu-title:not(.ant-menu-item-disabled):hover {
|
|
|
|
|
transition: background-color 0.9ms linear;
|
|
|
|
|
border-radius: var(--border-radius-base);
|
|
|
|
|
color: unset !important;
|
|
|
|
|
background-color: #f3f3f3 !important;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu {
|
|
|
|
|
padding: 10px;
|
|
|
|
|
user-select: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu-title-content {
|
|
|
|
|
font-size: 15px;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 11:51:52 +03:30
|
|
|
.ant-menu-item,
|
|
|
|
|
.ant-menu-submenu-title {
|
|
|
|
|
@apply px-2 !important;
|
2026-01-24 17:45:54 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu.ant-menu-inline-collapsed > .ant-menu-item .ant-menu-item-icon + span,
|
|
|
|
|
.ant-menu.ant-menu-inline-collapsed > .ant-menu-submenu .ant-menu-item-icon + span {
|
|
|
|
|
display: none !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu.ant-menu-inline-collapsed > .ant-menu-submenu > .ant-menu-submenu-title {
|
|
|
|
|
padding: 0 !important;
|
|
|
|
|
display: flex !important;
|
|
|
|
|
align-items: center !important;
|
|
|
|
|
justify-content: center !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu.ant-menu-inline-collapsed > .ant-menu-item {
|
|
|
|
|
padding: 0 !important;
|
|
|
|
|
display: flex !important;
|
|
|
|
|
align-items: center !important;
|
|
|
|
|
justify-content: center !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu-vertical > .ant-menu-submenu > .ant-menu-submenu-title {
|
|
|
|
|
height: 36px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu-item.ant-menu-item-selected {
|
|
|
|
|
&::after {
|
|
|
|
|
content: unset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu.ant-menu-sub.ant-menu-inline {
|
|
|
|
|
background-color: unset !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-menu-vertical > .ant-menu-submenu,
|
|
|
|
|
.ant-menu-vertical > .ant-menu-item {
|
|
|
|
|
height: 36px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|