mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-22 11:33:35 +08:00
fix(ui): align account themes and stabilize menu tags
This commit is contained in:
parent
0e688a34bf
commit
8865bf7ae0
168
__test__/layout/menu-tag.spec.tsx
Normal file
168
__test__/layout/menu-tag.spec.tsx
Normal file
@ -0,0 +1,168 @@
|
||||
import MenuTag from '@/layout/components/MenuTag'
|
||||
import type { MenuTagOptions } from '@/types'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import type { VueWrapper } from '@vue/test-utils'
|
||||
import { NDropdown } from 'naive-ui'
|
||||
import { h, nextTick, ref } from 'vue'
|
||||
import type { Ref } from 'vue'
|
||||
import { createMemoryHistory, createRouter } from 'vue-router'
|
||||
import type { Router } from 'vue-router'
|
||||
|
||||
const state = vi.hoisted(() => ({
|
||||
tags: null as unknown as Ref<MenuTagOptions[]>,
|
||||
active: null as unknown as Ref<MenuTagOptions | null>,
|
||||
close: vi.fn(),
|
||||
navigate: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks', () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
useMaximize: () => ({ maximize: vi.fn() }),
|
||||
useSpinning: () => ({ reload: vi.fn() }),
|
||||
useSiderBar: () => ({
|
||||
close: state.close,
|
||||
closeForbiddenPage: vi.fn(),
|
||||
closeAll: vi.fn(),
|
||||
closeRight: vi.fn(),
|
||||
closeLeft: vi.fn(),
|
||||
closeOther: vi.fn(),
|
||||
checkCloseLeft: (index: number) => index > 0,
|
||||
checkCloseRight: (index: number) => index < state.tags.value.length - 1,
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock('@/store', () => ({
|
||||
useMenuGetters: () => ({
|
||||
getMenuTagOptions: state.tags,
|
||||
getCurrentMenuOption: state.active,
|
||||
}),
|
||||
useMenuActions: () => ({ changeMenuModelValue: state.navigate }),
|
||||
useRuntimeGetters: () => ({ globalMainLayoutLoad: ref(true) }),
|
||||
}))
|
||||
|
||||
let wrapper: VueWrapper
|
||||
let router: Router
|
||||
let host: HTMLElement
|
||||
let outside: HTMLButtonElement
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks()
|
||||
state.tags = ref(
|
||||
['Reports', 'Orders', 'Users'].map((label) => ({
|
||||
fullPath: `/${label.toLowerCase()}`,
|
||||
breadcrumbLabel: label,
|
||||
meta: {},
|
||||
})) as MenuTagOptions[],
|
||||
)
|
||||
state.active = ref(state.tags.value[0]!)
|
||||
router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [
|
||||
{ path: '/:pathMatch(.*)*', component: { render: () => h('div') } },
|
||||
],
|
||||
})
|
||||
await router.push('/reports')
|
||||
host = document.createElement('div')
|
||||
outside = document.createElement('button')
|
||||
document.body.append(host, outside)
|
||||
wrapper = mount(MenuTag, {
|
||||
attachTo: host,
|
||||
global: {
|
||||
plugins: [router],
|
||||
mocks: { $t: (key: string) => key },
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
wrapper.unmount()
|
||||
router.options.history.destroy()
|
||||
host.remove()
|
||||
outside.remove()
|
||||
})
|
||||
|
||||
const contextDropdown = () =>
|
||||
wrapper
|
||||
.findAllComponents(NDropdown)
|
||||
.find((menu) => menu.props('trigger') === 'manual')!
|
||||
|
||||
const mouse = (element: Element, type: string, button: number) => {
|
||||
element.dispatchEvent(
|
||||
new MouseEvent(type, {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
button,
|
||||
clientX: 120,
|
||||
clientY: 80,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
const openContextMenu = async (index: number) => {
|
||||
const tab = wrapper.findAll('.menu-tag__tab')[index]!.element
|
||||
|
||||
mouse(tab, 'mousedown', 2)
|
||||
mouse(tab, 'contextmenu', 2)
|
||||
await nextTick()
|
||||
await nextTick()
|
||||
mouse(tab, 'mouseup', 2)
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
it('keeps the context menu open while repeatedly right-clicking other tags', async () => {
|
||||
for (const index of [0, 1, 2, 0]) {
|
||||
await openContextMenu(index)
|
||||
expect(contextDropdown().props('show')).toBe(true)
|
||||
expect(document.querySelector('.menu-tag__dropdown')).not.toBeNull()
|
||||
}
|
||||
})
|
||||
|
||||
it('applies a context command to the most recently right-clicked tag', async () => {
|
||||
await openContextMenu(0)
|
||||
await openContextMenu(2)
|
||||
|
||||
const command = [
|
||||
...document.querySelectorAll('.n-dropdown-option-body'),
|
||||
].find((option) => option.textContent === 'closeCurrent')
|
||||
|
||||
expect(command).toBeDefined()
|
||||
mouse(command!, 'click', 0)
|
||||
await nextTick()
|
||||
expect(state.close).toHaveBeenCalledExactlyOnceWith(2)
|
||||
expect(contextDropdown().props('show')).toBe(false)
|
||||
})
|
||||
|
||||
it.each([0, 2])(
|
||||
'dismisses when mouse button %i is clicked outside the tags and menu',
|
||||
async (button) => {
|
||||
await openContextMenu(0)
|
||||
mouse(outside, 'mousedown', button)
|
||||
mouse(outside, 'mouseup', button)
|
||||
await nextTick()
|
||||
expect(contextDropdown().props('show')).toBe(false)
|
||||
},
|
||||
)
|
||||
|
||||
it('dismisses the context menu when selecting a different tag', async () => {
|
||||
await openContextMenu(0)
|
||||
const tab = wrapper.findAll('.menu-tag__tab')[1]!
|
||||
|
||||
mouse(tab.element, 'mousedown', 0)
|
||||
mouse(tab.element, 'mouseup', 0)
|
||||
await tab.trigger('click')
|
||||
expect(contextDropdown().props('show')).toBe(false)
|
||||
expect(state.navigate).toHaveBeenCalledExactlyOnceWith(
|
||||
'/orders',
|
||||
state.tags.value[1],
|
||||
)
|
||||
})
|
||||
|
||||
it('dismisses the context menu with Escape after switching tags', async () => {
|
||||
await openContextMenu(0)
|
||||
await openContextMenu(1)
|
||||
document.dispatchEvent(
|
||||
new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }),
|
||||
)
|
||||
await nextTick()
|
||||
expect(contextDropdown().props('show')).toBe(false)
|
||||
})
|
||||
6
apps/admin/src/layout/components/MenuTag/index.scss
Normal file
6
apps/admin/src/layout/components/MenuTag/index.scss
Normal file
@ -0,0 +1,6 @@
|
||||
.menu-tag__dropdown.n-dropdown-menu {
|
||||
min-inline-size: 188px;
|
||||
padding: 6px;
|
||||
border: 1px solid var(--r-line);
|
||||
border-radius: var(--r-radius);
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
import './index.scss'
|
||||
import { RIcon, RMoreDropdown } from '@/components'
|
||||
import { useI18n, useMaximize, useSiderBar, useSpinning } from '@/hooks'
|
||||
import { FORBIDDEN_ROUTE_PATH } from '@/router/constant'
|
||||
@ -248,13 +249,22 @@ export default defineComponent({
|
||||
e.preventDefault()
|
||||
|
||||
currentContextmenuIndex.value = idx
|
||||
actionState.actionDropdownShow = false
|
||||
actionState.x = e.clientX
|
||||
actionState.y = e.clientY
|
||||
actionState.actionDropdownShow = true
|
||||
}
|
||||
|
||||
nextTick(() => {
|
||||
actionState.x = e.clientX
|
||||
actionState.y = e.clientY
|
||||
actionState.actionDropdownShow = true
|
||||
})
|
||||
const dismissContextMenu = (event: MouseEvent | TouchEvent) => {
|
||||
// clickoutside 在 mouseup 触发;标签上的同一次右键抬起不能关闭刚切换的菜单。
|
||||
if (
|
||||
event instanceof MouseEvent &&
|
||||
event.button === 2 &&
|
||||
event.target instanceof Element &&
|
||||
tagsRef.value?.contains(event.target.closest('.menu-tag__item'))
|
||||
)
|
||||
return
|
||||
|
||||
actionState.actionDropdownShow = false
|
||||
}
|
||||
|
||||
const setCurrentContextmenuIndex = () => {
|
||||
@ -310,6 +320,7 @@ export default defineComponent({
|
||||
actionDropdownSelect,
|
||||
actionState,
|
||||
menuTagContextMenu,
|
||||
dismissContextMenu,
|
||||
setCurrentContextmenuIndex,
|
||||
maximize,
|
||||
reload,
|
||||
@ -336,14 +347,14 @@ export default defineComponent({
|
||||
options={this.moreOptions}
|
||||
x={this.actionState.x}
|
||||
y={this.actionState.y}
|
||||
keyboard={false}
|
||||
show={this.actionState.actionDropdownShow}
|
||||
trigger="manual"
|
||||
placement="bottom-start"
|
||||
onSelect={actionDropdownSelect}
|
||||
onClickoutside={() => {
|
||||
this.actionState.actionDropdownShow = false
|
||||
onUpdateShow={(show) => {
|
||||
this.actionState.actionDropdownShow = show
|
||||
}}
|
||||
onClickoutside={this.dismissContextMenu}
|
||||
/>
|
||||
<NFlex
|
||||
class="menu-tag-space"
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
.r-account-profile {
|
||||
container: account-profile / inline-size;
|
||||
display: grid;
|
||||
gap: 18px;
|
||||
gap: 24px;
|
||||
max-inline-size: 1160px;
|
||||
margin-inline: auto;
|
||||
padding-block: 10px 28px;
|
||||
@ -12,7 +12,6 @@
|
||||
}
|
||||
|
||||
&__summary,
|
||||
&__navigation,
|
||||
&__panel {
|
||||
min-inline-size: 0;
|
||||
border: 1px solid var(--r-line);
|
||||
@ -21,39 +20,11 @@
|
||||
box-shadow: var(--r-shadow-soft);
|
||||
}
|
||||
|
||||
&__cover {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
block-size: clamp(80px, 9.5cqi, 110px);
|
||||
border-radius: var(--r-radius) var(--r-radius) 0 0;
|
||||
background: linear-gradient(
|
||||
112deg,
|
||||
color-mix(in oklch, var(--r-theme-primary-color) 76%, var(--r-text)),
|
||||
var(--r-theme-primary-color) 48%,
|
||||
color-mix(in oklch, var(--r-theme-primary-color) 77%, var(--r-surface))
|
||||
);
|
||||
|
||||
&::after {
|
||||
position: absolute;
|
||||
inset-block: 0;
|
||||
inset-inline-end: 0;
|
||||
inline-size: min(56%, 520px);
|
||||
background: repeating-radial-gradient(
|
||||
ellipse at 79% 8%,
|
||||
transparent 0 17px,
|
||||
color-mix(in srgb, var(--r-surface) 24%, transparent) 18px 19px,
|
||||
transparent 20px 29px
|
||||
);
|
||||
mask-image: linear-gradient(90deg, transparent, black 43%);
|
||||
content: '';
|
||||
}
|
||||
}
|
||||
|
||||
&__summary-body {
|
||||
display: grid;
|
||||
align-items: center;
|
||||
gap: 16px 26px;
|
||||
padding: 14px clamp(16px, 3cqi, 24px) 16px;
|
||||
gap: 20px 24px;
|
||||
padding: clamp(16px, 3cqi, 24px);
|
||||
}
|
||||
|
||||
&__identity {
|
||||
@ -63,21 +34,8 @@
|
||||
min-inline-size: 0;
|
||||
}
|
||||
|
||||
&__avatar-frame {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: grid;
|
||||
flex: none;
|
||||
align-self: flex-start;
|
||||
margin-block-start: -42px;
|
||||
padding: 4px;
|
||||
border: 1px solid var(--r-line);
|
||||
border-radius: var(--r-radius);
|
||||
background: var(--r-surface);
|
||||
box-shadow: var(--r-shadow-soft);
|
||||
}
|
||||
|
||||
&__avatar.r-account-avatar {
|
||||
flex: none;
|
||||
border-radius: var(--r-control-radius);
|
||||
}
|
||||
|
||||
@ -86,7 +44,7 @@
|
||||
|
||||
h2 {
|
||||
color: var(--r-text);
|
||||
font-size: 23px;
|
||||
font-size: 21px;
|
||||
font-weight: 650;
|
||||
line-height: 1.28;
|
||||
letter-spacing: -0.02em;
|
||||
@ -105,22 +63,20 @@
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
align-items: stretch;
|
||||
gap: 8px;
|
||||
gap: 16px;
|
||||
margin: 0;
|
||||
padding-block-start: 20px;
|
||||
border-block-start: 1px solid var(--r-line);
|
||||
|
||||
> div {
|
||||
display: grid;
|
||||
align-content: start;
|
||||
gap: 4px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid var(--r-line);
|
||||
border-radius: var(--r-control-radius);
|
||||
background: var(--r-surface-muted);
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
dt {
|
||||
color: var(--r-text-muted);
|
||||
font-size: 11px;
|
||||
font-size: 12px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
@ -138,21 +94,21 @@
|
||||
&__workspace {
|
||||
display: grid;
|
||||
align-items: start;
|
||||
gap: 16px;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
&__navigation {
|
||||
display: grid;
|
||||
gap: 5px;
|
||||
padding: 7px;
|
||||
min-inline-size: 0;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
&__section {
|
||||
display: grid;
|
||||
grid-template-columns: 34px minmax(0, 1fr) auto;
|
||||
grid-template-columns: 22px minmax(0, 1fr) auto;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
padding: 9px 10px;
|
||||
gap: 12px;
|
||||
padding: 14px 12px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: var(--r-control-radius);
|
||||
background: transparent;
|
||||
@ -161,21 +117,13 @@
|
||||
text-align: start;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
&:hover:not([aria-selected='true']) {
|
||||
background: var(--r-surface-hover);
|
||||
}
|
||||
|
||||
&[aria-selected='true'] {
|
||||
border-color: color-mix(
|
||||
in srgb,
|
||||
var(--r-theme-primary-color) 26%,
|
||||
var(--r-line)
|
||||
);
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--r-theme-primary-color) 11%,
|
||||
var(--r-surface)
|
||||
);
|
||||
border-color: var(--r-control-border);
|
||||
background: var(--r-surface-muted);
|
||||
color: var(--r-selected-text);
|
||||
}
|
||||
}
|
||||
@ -183,16 +131,7 @@
|
||||
&__section-icon {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
inline-size: 34px;
|
||||
block-size: 34px;
|
||||
border-radius: var(--r-control-radius);
|
||||
background: var(--r-surface-muted);
|
||||
color: var(--r-text-secondary);
|
||||
}
|
||||
|
||||
&__section[aria-selected='true'] &__section-icon {
|
||||
background: var(--r-surface);
|
||||
color: var(--r-primary-text);
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
&__section-copy {
|
||||
@ -209,7 +148,7 @@
|
||||
|
||||
&__section-hint {
|
||||
color: var(--r-text-secondary);
|
||||
font-size: 11px;
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
@ -292,6 +231,13 @@
|
||||
grid-template-columns: minmax(0, 1fr) minmax(250px, 0.58fr);
|
||||
}
|
||||
|
||||
.r-account-profile__facts {
|
||||
padding-block-start: 0;
|
||||
padding-inline-start: 24px;
|
||||
border-block-start: 0;
|
||||
border-inline-start: 1px solid var(--r-line);
|
||||
}
|
||||
|
||||
.r-account-profile__workspace {
|
||||
grid-template-columns: 238px minmax(0, 1fr);
|
||||
}
|
||||
|
||||
@ -196,18 +196,15 @@ export default defineComponent({
|
||||
class="r-account-profile__summary"
|
||||
aria-label={t('details')}
|
||||
>
|
||||
<div class="r-account-profile__cover" aria-hidden="true" />
|
||||
<div class="r-account-profile__summary-body">
|
||||
<div class="r-account-profile__identity">
|
||||
<div class="r-account-profile__avatar-frame">
|
||||
<AccountAvatar
|
||||
class="r-account-profile__avatar"
|
||||
name={account.name}
|
||||
src={account.avatar || getSigningCallback.value.avatar}
|
||||
size={72}
|
||||
objectFit="cover"
|
||||
/>
|
||||
</div>
|
||||
<AccountAvatar
|
||||
class="r-account-profile__avatar"
|
||||
name={account.name}
|
||||
src={account.avatar || getSigningCallback.value.avatar}
|
||||
size={64}
|
||||
objectFit="cover"
|
||||
/>
|
||||
<div class="r-account-profile__identity-copy">
|
||||
<h2>{account.name}</h2>
|
||||
<p class="r-account-profile__handle">
|
||||
@ -227,12 +224,7 @@ export default defineComponent({
|
||||
<div>
|
||||
<dt>{t('role')}</dt>
|
||||
<dd>
|
||||
<NTag
|
||||
type="primary"
|
||||
size="small"
|
||||
round
|
||||
bordered={false}
|
||||
>
|
||||
<NTag type="primary" size="small" bordered={false}>
|
||||
{roleKey && te?.(roleKey)
|
||||
? translate(roleKey)
|
||||
: account.role}
|
||||
|
||||
@ -10,7 +10,7 @@ The template uses restrained blues and neutral colors. Refinement comes from con
|
||||
- Use accent colors for selection and primary actions; distinguish body text, descriptions, and eyebrow labels by color hierarchy. Page descriptions must remain readable: when a preset does not define a body-safe muted color, use the library's secondary text color rather than its weaker tertiary color.
|
||||
- Use subtle dividers between top bars, tab bars, and sidebars rather than layered shadows. A small number of content cards may use two-layer shadows.
|
||||
- Page surfaces use only the active preset's explicit soft shadow; library overlay shadows are not inherited by ordinary page cards. Naive's floating menus and dialogs retain their native elevation.
|
||||
- Page tabs normally show only their names. Reveal the close button on hover or focus; touch users can close the active tab directly.
|
||||
- Page tabs keep their close buttons visible and reserve the button width so hovering never expands a tab beyond the scroll viewport. Touch targets use the larger close-button width.
|
||||
- The preference drawer uses one or two field columns according to available width. Keep section navigation and reset actions in consistent positions.
|
||||
- When content is maximized, provide an exit control above the content, accessible by button or Esc.
|
||||
- Reuse `AppPageHeader` for page headings: an eyebrow, one main title, a short description, and optional actions. Do not replace page hierarchy with long descriptions or equally prominent card headings.
|
||||
|
||||
@ -82,16 +82,11 @@
|
||||
display: grid;
|
||||
flex: none;
|
||||
place-items: center;
|
||||
inline-size: 0;
|
||||
inline-size: 26px;
|
||||
block-size: 26px;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
border-radius: var(--r-control-radius);
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition:
|
||||
inline-size 160ms var(--r-bezier),
|
||||
opacity 120ms ease;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
@ -120,25 +115,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
.menu-tag__item:focus-within .menu-tag__close {
|
||||
inline-size: 26px;
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
.menu-tag__item:hover .menu-tag__close {
|
||||
inline-size: 26px;
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@media (hover: none) {
|
||||
.menu-tag__item--active .menu-tag__close {
|
||||
.menu-tag__close {
|
||||
inline-size: 32px;
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +200,6 @@
|
||||
animation: none;
|
||||
}
|
||||
|
||||
.menu-tag__close,
|
||||
.menu-tag__close::before {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user