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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | <script setup>
import { computed, ref, onMounted, onBeforeUnmount } from 'vue'
import {
BadgeCheck,
Bell,
Check,
CreditCard,
Languages,
LogOut,
Maximize,
Minimize,
Moon,
Palette,
PanelLeft,
Search,
Sun,
} from '@lucide/vue'
import { useRouter } from 'vue-router'
import { useAppStore } from '@/stores/app'
import { useAuthStore } from '@/stores/auth'
import { Message } from '@/components/ui/message/message-manager'
import { PRESETS } from '@/theme/presets'
import Dropdown from '@/components/ui/dropdown/dropdown.vue'
import Button from '@/components/ui/button/button.vue'
import Input from '@/components/ui/input/input.vue'
const router = useRouter()
const appStore = useAppStore()
const authStore = useAuthStore()
/* 深浅色切换:原 ThemeToggle 组件逻辑内联,按钮样式复用 .fms-icon-btn */
const isDark = computed(() => appStore.darkMode)
function toggleDark() {
appStore.toggleDark()
}
/* 主色选择:原 ColorThemePicker 组件逻辑内联,直接复用 .fms-icon-btn 风格 */
const activeColor = computed(() => appStore.primaryColor)
function pickColor(color) {
appStore.setPrimary(color)
}
const user = computed(() => ({
name: authStore.loginInfo.user?.name ?? '用户',
account: authStore.loginInfo.user?.account ?? '',
}))
async function logout() {
authStore.clearSession()
Message.info('已退出登录')
await router.replace('/login')
}
/* 用户下拉菜单:使用组件库标准 items 渲染(图标/危险色/分隔线/键盘导航均由库负责) */
const userOrg = computed(() => user.value.account || authStore.userInfo.orgId || '')
const userMenuItems = computed(() => [
{ key: 'profile', icon: BadgeCheck, label: '账号信息' },
{ key: 'billing', icon: CreditCard, label: '账单' },
{ key: 'notify', icon: Bell, label: '通知设置' },
{ divider: true },
{ key: 'logout', icon: LogOut, label: '退出登录', danger: true },
])
function onUserMenuClick({ key }) {
switch (key) {
case 'profile':
Message.info('账号信息(待实现)')
break
case 'billing':
Message.info('账单(待实现)')
break
case 'notify':
Message.info('通知设置(待实现)')
break
case 'logout':
logout()
break
}
}
/* ---- 全屏切换(Fullscreen API) ---- */
const isFullscreen = ref(false)
function syncFullscreen() {
isFullscreen.value = !!document.fullscreenElement
}
function toggleFullscreen() {
if (document.fullscreenElement) {
document.exitFullscreen?.()
} else {
document.documentElement.requestFullscreen?.().catch(() => {})
}
}
onMounted(() => document.addEventListener('fullscreenchange', syncFullscreen))
onBeforeUnmount(() => document.removeEventListener('fullscreenchange', syncFullscreen))
</script>
<template>
<header class="fms-topbar">
<!-- 左侧:折叠按钮 + 搜索框 -->
<div class="fms-topbar-left">
<Button
type="ghost"
class="fms-icon-btn"
:title="appStore.sidebarCollapsed ? '展开侧栏' : '折叠侧栏'"
@click="appStore.toggleSidebar()"
>
<PanelLeft />
</Button>
<span class="fms-separator" aria-hidden="true" />
<Input
class="fms-search"
disabled
model-value=""
placeholder="搜索功能、菜单…"
aria-label="全局搜索"
>
<template #prefix>
<Search />
</template>
</Input>
</div>
<!-- 右侧:语言 / 主题色板 / 深浅色 / 通知 / 用户 -->
<div class="fms-topbar-right">
<Button
type="ghost"
class="fms-icon-btn"
:title="appStore.locale === 'zh-CN' ? 'English' : '中文'"
@click="appStore.toggleLocale()"
>
<Languages />
</Button>
<!-- 主题色板 -->
<Dropdown placement="bottom-end" :offset="8">
<template #trigger>
<Button type="ghost" class="fms-icon-btn" title="主题色切换">
<Palette />
</Button>
</template>
<template #menu>
<div class="fms-topbar-scheme">
<div class="color-picker" role="group" aria-label="主题色">
<button
v-for="preset in PRESETS"
:key="preset.color"
class="swatch"
type="button"
:style="{ background: preset.color }"
:aria-label="preset.name"
:title="preset.name"
:aria-pressed="activeColor === preset.color"
@click="pickColor(preset.color)"
>
<Check v-if="activeColor === preset.color" class="check" />
</button>
</div>
</div>
</template>
</Dropdown>
<!-- 深浅色切换 -->
<Button
type="ghost"
class="fms-icon-btn"
:aria-label="isDark ? '切换到浅色模式' : '切换到深色模式'"
:title="isDark ? '浅色模式' : '深色模式'"
@click="toggleDark"
>
<component :is="isDark ? Moon : Sun" />
</Button>
<!-- 全屏切换 -->
<Button
type="ghost"
class="fms-icon-btn"
:title="isFullscreen ? '退出全屏' : '全屏'"
@click="toggleFullscreen"
>
<component :is="isFullscreen ? Minimize : Maximize" />
</Button>
<!-- 通知(占位) -->
<Button type="ghost" class="fms-icon-btn" title="通知">
<Bell />
</Button>
<span class="fms-separator" aria-hidden="true" />
<!-- 用户下拉:菜单项走组件库标准 items,不手写;富头部渲染头像+名字+组织 -->
<Dropdown placement="bottom-end" :offset="8" :items="userMenuItems" @click="onUserMenuClick">
<template #trigger>
<button class="fms-user-trigger" type="button" :title="user.name">
<span class="fms-avatar">{{ user.name.slice(0, 1) }}</span>
<span class="fms-user-name">{{ user.name }}</span>
</button>
</template>
<template #header>
<div class="fms-user-header">
<span class="fms-avatar fms-avatar-lg">{{ user.name.slice(0, 1) }}</span>
<div class="fms-user-meta">
<div class="fms-user-name fms-user-name-block">{{ user.name }}</div>
<div v-if="userOrg" class="fms-user-org">{{ userOrg }}</div>
</div>
</div>
</template>
</Dropdown>
</div>
</header>
</template>
<style lang="scss" scoped>
/* ---- 顶栏 ---- */
.fms-topbar {
display: flex;
align-items: center;
flex-shrink: 0;
gap: 8px;
height: 40px;
padding: 0 12px;
/* 顶栏独立成一块:与 .fms-main 同款白底 + 圆角 + 同款投影,与下方白卡并列分层 */
background: var(--fms-card);
border-radius: var(--fms-control-radius);
box-shadow: var(--fms-shadow);
}
.fms-topbar-left,
.fms-topbar-right {
display: flex;
align-items: center;
gap: 4px;
}
.fms-topbar-left {
flex-shrink: 0;
}
.fms-topbar-right {
margin-left: auto;
}
/* 顶栏图标按钮:复用组件库 Button type="ghost"(透明底/无边框/hover 高亮)。
用 .fms-topbar 前缀提高特异性,覆盖 ghost 的横向 padding / 次要文字色 / 图标尺寸,
使其保持 32×32 正方形、主文字色图标。hover 沿用 ghost 的 --fms-secondary。 */
.fms-topbar {
.fms-icon-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
padding: 0;
border: none;
border-radius: var(--fms-control-radius);
background: transparent;
color: var(--fms-text);
font-size: var(--fms-font-size);
line-height: var(--fms-line-height);
cursor: pointer;
transition:
background-color 150ms ease,
color 150ms ease;
svg {
width: 16px;
height: 16px;
}
&:focus-visible {
outline: 2px solid var(--fms-primary);
outline-offset: 2px;
}
}
}
/* 全局搜索框:基于组件库 Input,disabled 仅用于「不可聚焦/不可编辑」,
视觉上用 :deep() 还原为浅灰装饰框(覆盖库默认的禁用灰底 + not-allowed 光标) */
.fms-topbar-left .fms-search {
flex-shrink: 0;
width: 220px;
height: 28px;
min-height: 28px;
padding: 0 8px;
background: color-mix(in srgb, var(--fms-secondary-hover) 50%, var(--fms-card));
cursor: pointer;
transition: border-color 150ms ease;
/* 覆盖组件库禁用态:还原正常外观 + 手型光标 */
&.input-disabled {
background: color-mix(in srgb, var(--fms-secondary-hover) 50%, var(--fms-card));
border-color: var(--fms-border);
color: var(--fms-text-secondary);
cursor: pointer;
}
/* 前缀搜索图标尺寸 */
:deep(.input-prefix) {
margin-right: 6px;
}
:deep(.input-prefix svg) {
width: 16px;
height: 16px;
}
/* 内部输入框 */
:deep(.input) {
font-size: 12px;
cursor: pointer;
color: var(--fms-text);
&::placeholder {
color: var(--fms-text-secondary);
}
&:disabled {
cursor: pointer;
}
}
}
.fms-separator {
flex-shrink: 0;
width: 1px;
height: 16px;
margin: 0 6px;
background: var(--fms-border);
}
/* 主题色板浮层 */
.fms-topbar-scheme {
padding: 4px 8px 8px;
}
/* 色板(原 ColorThemePicker 组件内联) */
.color-picker {
display: flex;
flex-wrap: wrap;
gap: 8px;
align-items: center;
}
.swatch {
position: relative;
width: 22px;
height: 22px;
border: none;
border-radius: 50%;
padding: 0;
cursor: pointer;
outline: 2px solid transparent;
outline-offset: 1px;
transition:
outline-color 120ms ease,
transform 120ms ease;
&:hover {
transform: scale(1.1);
}
&:focus-visible {
outline-color: var(--fms-primary);
}
}
.check {
position: absolute;
inset: 0;
margin: auto;
width: 14px;
height: 14px;
color: var(--fms-primary-text);
}
/* 用户触发按钮 */
.fms-user-trigger {
display: flex;
align-items: center;
gap: 8px;
height: 32px;
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);
cursor: pointer;
transition: background 150ms ease;
&:hover {
background: var(--fms-secondary-hover);
}
&:focus-visible {
outline: 2px solid var(--fms-primary);
outline-offset: 2px;
}
}
/* 首字母头像 */
.fms-avatar {
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
width: 28px;
height: 28px;
border-radius: 8px;
background: color-mix(in srgb, var(--fms-primary) 12%, transparent);
color: var(--fms-primary);
font-size: 13px;
font-weight: 600;
user-select: none;
}
.fms-user-name {
max-width: 120px;
overflow: hidden;
font-size: 14px;
font-weight: 500;
text-overflow: ellipsis;
white-space: nowrap;
}
/* 下拉富头部:头像 + 名字 + 组织。
该内容经 Popover 的 <Teleport to="body"> 渲染到 body,但 scoped 的 data-v 属性随节点一并保留,
因此无需全局样式,scoped 规则 .fms-user-header[data-v-xxx] 可正常命中。 */
.fms-user-header {
display: flex;
align-items: center;
gap: 10px;
}
/* 头部大号头像(定义于基础 .fms-avatar 之后,优先覆盖尺寸为 32×32) */
.fms-avatar-lg {
width: 32px;
height: 32px;
border-radius: 9px;
font-size: 14px;
}
.fms-user-meta {
display: flex;
flex-direction: column;
gap: 2px;
min-width: 0;
}
/* 头部中的名字:块级、省略(自带省略属性,不依赖基础 .fms-user-name) */
.fms-user-name-block {
max-width: 180px;
overflow: hidden;
font-size: 14px;
font-weight: 600;
text-overflow: ellipsis;
white-space: nowrap;
}
.fms-user-org {
max-width: 180px;
overflow: hidden;
font-size: 12px;
color: var(--fms-text-secondary);
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
|