Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | <script setup>
import { computed, ref } from 'vue'
import {
AudioWaveform,
Check,
ChevronsUpDown,
Command,
Component,
GalleryVerticalEnd,
LayoutGrid,
} from '@lucide/vue'
import { useAppStore } from '@/stores/app'
import { usePermissionStore } from '@/stores/permissions'
import { getIcon } from '@/utils/lucideIcons'
import { buildTree, sortTree } from '@/utils/tree'
import Dropdown from '@/components/ui/dropdown/dropdown.vue'
import NavMain from './NavMain.vue'
const appStore = useAppStore()
const permissionStore = usePermissionStore()
const collapsed = computed(() => appStore.sidebarCollapsed)
/* ---- 团队切换 ---- */
const teams = [
{ name: '金地集团', logo: GalleryVerticalEnd, plan: '企业版' },
{ name: '金地科技', logo: AudioWaveform, plan: '创业版' },
{ name: '测试公司', logo: Command, plan: '免费版' },
]
const activeTeam = ref(teams[0])
/* ---- 动态导航菜单(权限模块构建树) ---- */
const navMain = computed(() => {
const items = [
{ title: '工作台', url: '/dashboard', icon: LayoutGrid },
{ title: '组件库', url: '/demo', icon: Component },
]
// 测试页分组:方便演练 Tabs 导航(无权限依赖)
items.push({
title: '测试页面',
icon: LayoutGrid,
items: [
{ title: '列表', url: '/test/list' },
{ title: '表单', url: '/test/form' },
{ title: '详情', url: '/test/detail' },
{ title: '图表', url: '/test/chart' },
{ title: '表格', url: '/test/table' },
{ title: '设置', url: '/test/settings' },
],
})
const menuModules = permissionStore.modules.filter(
(m) => m.b_canmenu === 1 && m.b_canuse === 1 && ['directory', 'page'].includes(m.b_module_type),
)
if (!menuModules.length) return items
// 仅保留父节点(若有)也在菜单中的模块
const allowedIds = new Set(menuModules.map((m) => String(m.b_id)))
const valid = menuModules.filter(
(m) => m.b_parent_id == null || allowedIds.has(String(m.b_parent_id)),
)
const cloned = JSON.parse(JSON.stringify(valid))
const tree = buildTree(cloned)
sortTree(tree)
for (const node of tree) {
const item = toNavItem(node)
if (item) items.push(item)
}
return items
})
function toNavItem(node) {
const isDir = node.b_module_type === 'directory'
// 与旧系统一致:仅目录项读取图标,页面项只显示文字
const icon = isDir ? getIcon(node.b_icon) : null
const item = {
title: node.b_name || node.b_code,
url: node.b_route ? String(node.b_route) : `#${node.b_code}`,
}
if (icon) item.icon = icon
if (!isDir && node.b_code) item.moduleId = String(node.b_code)
if (node.children?.length) {
item.items = node.children.map((c) => toNavItem(c)).filter(Boolean)
}
return item
}
</script>
<template>
<div class="fms-sidebar-body" :class="{ 'is-collapsed': collapsed }">
<!-- 团队切换 -->
<div class="fms-team">
<Dropdown placement="bottom-start" :offset="4">
<template #trigger>
<button
class="fms-team-trigger"
type="button"
:title="collapsed ? activeTeam.name : undefined"
>
<span class="fms-team-logo"><component :is="activeTeam.logo" /></span>
<span v-if="!collapsed" class="fms-team-info">
<span class="fms-team-name">{{ activeTeam.name }}</span>
<span class="fms-team-plan">{{ activeTeam.plan }}</span>
</span>
<ChevronsUpDown v-if="!collapsed" class="fms-team-caret" aria-hidden="true" />
</button>
</template>
<template #menu="{ close }">
<div class="fms-team-menu">
<button
v-for="team in teams"
:key="team.name"
class="fms-team-menu-item"
type="button"
@click="((activeTeam = team), close())"
>
<span class="fms-team-menu-logo"><component :is="team.logo" /></span>
<span class="fms-team-menu-info">
<span class="fms-team-menu-name">{{ team.name }}</span>
<span class="fms-team-menu-plan">{{ team.plan }}</span>
</span>
<Check v-if="team === activeTeam" class="fms-team-menu-check" aria-hidden="true" />
</button>
</div>
</template>
</Dropdown>
</div>
<!-- 动态菜单 -->
<div class="fms-nav-scroll">
<NavMain :items="navMain" />
</div>
</div>
</template>
<style lang="scss" scoped>
/* ---- 侧栏容器 ---- */
.fms-sidebar-body {
display: flex;
flex-direction: column;
height: 100%;
min-width: 0;
}
/* 团队切换(对齐 SidebarHeader p-2 + TeamSwitcher h-12) */
.fms-team {
flex-shrink: 0;
padding: 4px;
}
/* Popover 默认把 trigger 包在行内 span(inline-flex),会让按钮收缩到内容宽度
导致卡片撑不满、caret 无法靠右;这里改为块级撑满。
注意:.popover-trigger 是子组件 Popover 渲染的元素,scoped 样式无法直接命中,
必须用 :deep() 穿透到它自己这一层 */
.fms-team :deep(.popover-trigger) {
display: block;
width: 100%;
}
.fms-team-trigger {
display: flex;
align-items: center;
gap: 8px;
width: 100%;
min-height: 48px;
padding: 0 8px;
border: none;
border-radius: var(--fms-control-radius);
background: transparent;
color: var(--fms-text);
font-family: inherit;
font-size: var(--fms-font-size);
text-align: left;
cursor: pointer;
transition: background 150ms ease;
&:hover {
background: var(--fms-secondary);
}
&:focus-visible {
outline: 2px solid var(--fms-primary);
outline-offset: 2px;
}
}
.fms-team-logo {
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
width: 32px;
height: 32px;
border-radius: 8px;
background: var(--fms-primary);
color: var(--fms-primary-text);
svg {
width: 18px;
height: 18px;
}
}
.fms-team-info {
display: flex;
flex: 1;
flex-direction: column;
align-items: flex-start;
min-width: 0;
}
.fms-team-name {
max-width: 100%;
overflow: hidden;
font-size: 14px;
font-weight: 600;
line-height: 20px;
text-overflow: ellipsis;
white-space: nowrap;
}
/* 必须与 name 一样强制单行 + 省略号:
* 折叠→展开瞬间面板仍为 48px 宽,团队信息区被压到近 0px,
* 若无 nowrap,"企业版"会逐字换行把团队块撑高,整个菜单被向下推一下再弹回 */
.fms-team-plan {
max-width: 100%;
overflow: hidden;
font-size: 12px;
line-height: 16px;
color: var(--fms-text-secondary);
text-overflow: ellipsis;
white-space: nowrap;
}
.fms-team-caret {
flex-shrink: 0;
width: 16px;
height: 16px;
margin-left: auto;
color: var(--fms-text-secondary);
}
/* 团队下拉菜单(#menu 插槽自定义内容) */
.fms-team-menu {
display: flex;
flex-direction: column;
gap: 2px;
min-width: 180px;
}
.fms-team-menu-item {
display: flex;
align-items: center;
gap: 10px;
padding: 6px 8px;
border: none;
border-radius: var(--fms-dropdown-item-radius);
background: transparent;
color: var(--fms-text);
font-family: inherit;
font-size: var(--fms-font-size);
text-align: left;
cursor: pointer;
transition: background 150ms ease;
&:hover {
background: var(--fms-secondary-hover);
}
}
.fms-team-menu-logo {
display: inline-flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
border-radius: 6px;
background: var(--fms-secondary-hover);
color: var(--fms-text);
svg {
width: 14px;
height: 14px;
}
}
.fms-team-menu-info {
display: flex;
flex-direction: column;
align-items: flex-start;
}
/* 当前选中团队的勾选图标:推到最右 */
.fms-team-menu-check {
flex-shrink: 0;
margin-left: auto;
width: 16px;
height: 16px;
color: var(--fms-primary);
}
.fms-team-menu-name {
font-size: 14px;
font-weight: 500;
}
.fms-team-menu-plan {
font-size: 12px;
color: var(--fms-text-secondary);
}
/* 菜单滚动区(对齐 SidebarContent + SidebarGroup p-2) */
.fms-nav-scroll {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: 0 8px 8px;
}
.fms-nav-scroll::-webkit-scrollbar {
width: 6px;
}
.fms-nav-scroll::-webkit-scrollbar-thumb {
border-radius: 3px;
background: var(--fms-border);
}
/* ---- 折叠态:仅图标,居中展示(对齐 size-8 icon 模式) ---- */
.fms-sidebar-body.is-collapsed {
.fms-team {
padding: 4px;
}
.fms-team-trigger {
justify-content: center;
padding: 0;
}
.fms-nav-scroll {
padding: 0 8px 8px;
}
}
</style>
|