mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-21 02:43:34 +08:00
fix(layout): refine navigation and shared styles
This commit is contained in:
parent
39d2e82439
commit
7f75de4b70
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -73,6 +73,7 @@
|
||||
"datetimerange",
|
||||
"depcheckrc",
|
||||
"domtoimage",
|
||||
"echart",
|
||||
"EDITMSG",
|
||||
"ianvs",
|
||||
"iife",
|
||||
@ -87,6 +88,8 @@
|
||||
"pharmacode",
|
||||
"Popselect",
|
||||
"precommit",
|
||||
"qrcode",
|
||||
"sider",
|
||||
"siderbar",
|
||||
"snapline",
|
||||
"stylelint",
|
||||
|
||||
29
__test__/app/global-provider.spec.ts
Normal file
29
__test__/app/global-provider.spec.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createPinia, disposePinia, setActivePinia } from 'pinia'
|
||||
import { nextTick } from 'vue'
|
||||
import GlobalProvider from '../../src/app-components/provider/AppNaiveGlobalProvider'
|
||||
import { piniaSettingStore } from '../../src/store/modules/setting'
|
||||
|
||||
it('reuses the global message instance across themes and removes its host on unmount', async () => {
|
||||
const pinia = createPinia()
|
||||
|
||||
setActivePinia(pinia)
|
||||
const originalChildren = new Set(document.body.children)
|
||||
const wrapper = mount(GlobalProvider, { global: { plugins: [pinia] } })
|
||||
const message = window.$message
|
||||
const hosts = () =>
|
||||
Array.from(document.body.children).filter((el) => !originalChildren.has(el))
|
||||
|
||||
try {
|
||||
expect(hosts()).toHaveLength(1)
|
||||
piniaSettingStore().updateSettingState('_appTheme', true)
|
||||
await nextTick()
|
||||
expect(window.$message).toBe(message)
|
||||
expect(hosts()).toHaveLength(1)
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
disposePinia(pinia)
|
||||
}
|
||||
|
||||
expect(hosts()).toHaveLength(0)
|
||||
})
|
||||
80
__test__/layout/sidebar-scroll.spec.ts
Normal file
80
__test__/layout/sidebar-scroll.spec.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createPinia, disposePinia, setActivePinia } from 'pinia'
|
||||
import { nextTick } from 'vue'
|
||||
import { useSiderScroll } from '../../src/hooks/template/useSiderScroll'
|
||||
import Menu from '../../src/layout/components/Menu'
|
||||
import { router } from '../../src/router'
|
||||
import { piniaMenuStore } from '../../src/store/modules/menu'
|
||||
import { piniaSettingStore } from '../../src/store/modules/setting'
|
||||
import { positionSelectedMenuItem } from '../../src/utils'
|
||||
|
||||
it.each([
|
||||
[true, '.n-layout-scroll-container'],
|
||||
[false, '.n-scrollbar-container'],
|
||||
])(
|
||||
'keeps the logo outside the menu scroll region (native: %s)',
|
||||
async (nativeScrollbar, selector) => {
|
||||
const pinia = createPinia()
|
||||
|
||||
setActivePinia(pinia)
|
||||
piniaSettingStore().updateSettingState('menuConfig', { nativeScrollbar })
|
||||
|
||||
const wrapper = mount(Menu, {
|
||||
global: { plugins: [router, pinia] },
|
||||
props: {
|
||||
options: [
|
||||
{
|
||||
name: 'selected',
|
||||
label: 'Selected',
|
||||
path: '/selected',
|
||||
fullPath: '/selected',
|
||||
key: '/selected',
|
||||
meta: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
try {
|
||||
piniaMenuStore().updateMenuState('menuKey', '/selected')
|
||||
await nextTick()
|
||||
const logo = wrapper.get('.r-menu__logo').element
|
||||
const scroller = wrapper.get<HTMLElement>(
|
||||
`.app-menu__scroll ${selector}`,
|
||||
).element
|
||||
const selected = wrapper.get('.n-menu-item-content--selected').element
|
||||
|
||||
expect(scroller.contains(logo)).toBe(false)
|
||||
expect(scroller.contains(selected)).toBe(true)
|
||||
|
||||
const scrollTo = vi
|
||||
.spyOn(scroller, 'scrollTo')
|
||||
.mockImplementation(() => {})
|
||||
|
||||
useSiderScroll()({ left: 0, top: 30 })
|
||||
expect(scrollTo).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ top: 30 }),
|
||||
)
|
||||
scrollTo.mockClear()
|
||||
|
||||
scroller.scrollTop = 80
|
||||
vi.spyOn(scroller, 'getBoundingClientRect').mockReturnValue(
|
||||
new DOMRect(0, 64, 272, 200),
|
||||
)
|
||||
const itemRect = vi.spyOn(selected, 'getBoundingClientRect')
|
||||
|
||||
itemRect.mockReturnValue(new DOMRect(0, 100, 272, 40))
|
||||
positionSelectedMenuItem()
|
||||
expect(scrollTo).not.toHaveBeenCalled()
|
||||
|
||||
itemRect.mockReturnValue(new DOMRect(0, 300, 272, 40))
|
||||
positionSelectedMenuItem()
|
||||
expect(scrollTo).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ top: 316, behavior: 'smooth' }),
|
||||
)
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
disposePinia(pinia)
|
||||
}
|
||||
},
|
||||
)
|
||||
@ -5,6 +5,7 @@
|
||||
## 主题与尺度
|
||||
|
||||
- 页面背景、卡片、分割线与文字优先使用 `src/styles/design-system.scss` 中的语义变量。Naive UI 的主题覆盖集中在 `src/app-config/design-config.ts`,保持同一色阶,避免页面单独拼出另一套主题。
|
||||
- `src/styles/base.scss` 是全局样式入口,`design-system.scss` 管理主题变量与基础焦点样式,`setting.scss` 管理布局尺度。`naive.scss` 仅维护模板通用的控件默认值;布局与组件内部规则放在对应组件目录,避免影响嵌套的 Naive UI 实例。
|
||||
- 控件通常为 8px 圆角、卡片为 12px;页面区块间距使用 20–28px。强调色用于选择与主要操作,正文、说明、眉题使用不同文字层级。
|
||||
- 顶栏、标签栏和侧栏使用轻分割线,不叠加区域阴影;少量内容卡片使用两层轻阴影。
|
||||
- 页面标题复用 `AppPageHeader`:眉题、一个主标题、简短说明与可选操作区。不要以大段说明或同等权重的卡片标题代替页面层级。
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
- `AppPageHeader` 统一页面眉题、主标题、说明与右侧操作区;页面正文保留各自布局,不在此封装业务内容。
|
||||
- `AppShareLink` 默认使用紧凑入口,工作台通过 `variant="cards"` 显示具名链接卡片,保留登录页的空间约束。
|
||||
- `AppAvatar` 从 signing Store 读取头像与名称;保留 Naive UI Avatar 相关 props。
|
||||
- `AppNaiveGlobalProvider` 提供 Naive UI 上下文以及 `window.$message`、`$notification`、`$dialog`、`$loadingBar`。Provider 初始化前不要调用这些对象;全局提示跟随应用的主题和语言。
|
||||
- `AppNaiveGlobalProvider` 提供 Naive UI 上下文以及 `window.$message`、`$notification`、`$dialog`、`$loadingBar`。离散提示实例随 Provider 初始化与卸载,并实时同步主题和语言;只在 Provider 挂载期间调用这些对象。
|
||||
- `AppWatermarkProvider` 为全局水印提供入口,显示与内容通过 `useWatermark` 调整。需要限制水印覆盖范围时,调整 Provider 的挂载位置。
|
||||
- `AppRequestCancelerProvider` 在路由更新前取消旧请求;默认布局内容负责挂载。自定义内容插槽时需保留所需的请求取消行为。
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
& .app-lock-screen__unlock__content-bg__wrapper {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgb(16, 16, 20);
|
||||
background-color: var(--r-canvas);
|
||||
}
|
||||
|
||||
& .app-lock-screen__unlock__content-bg {
|
||||
@ -43,7 +43,6 @@
|
||||
&.app-lock-screen__unlock__content-bg--smaller {
|
||||
& .left,
|
||||
& .right {
|
||||
padding: 0px;
|
||||
font-size: 90px;
|
||||
padding: 24px;
|
||||
border-radius: 4px;
|
||||
@ -54,7 +53,7 @@
|
||||
& .right {
|
||||
@include flexCenter;
|
||||
border-radius: 30px;
|
||||
background-color: #141313;
|
||||
background-color: var(--r-surface);
|
||||
font-weight: 700;
|
||||
padding: 80px;
|
||||
filter: blur(4px);
|
||||
@ -64,7 +63,7 @@
|
||||
|
||||
& .app-lock-screen__unlock__content-avatar {
|
||||
margin-top: 5px;
|
||||
color: #bababa;
|
||||
color: var(--r-text-secondary);
|
||||
font-weight: bolder;
|
||||
z-index: 1;
|
||||
}
|
||||
@ -92,16 +91,3 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.r-template--light {
|
||||
.app-lock-screen__unlock__content-bg__wrapper {
|
||||
background-color: #fff !important;
|
||||
}
|
||||
|
||||
.app-lock-screen__unlock__content-bg {
|
||||
& .left,
|
||||
& .right {
|
||||
background-color: rgba(244, 244, 245, 1) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,29 +25,22 @@ export default defineComponent({
|
||||
return getNaiveLocales(key)
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 在渲染作用域内创建全局提示实例,使离散提示与当前主题和语言保持一致。
|
||||
*/
|
||||
const discreteApi = () => {
|
||||
const { message, notification, dialog, loadingBar } = createDiscreteApi(
|
||||
['message', 'dialog', 'notification', 'loadingBar'],
|
||||
{
|
||||
configProviderProps: computed(() => ({
|
||||
theme: getAppTheme.value ? darkTheme : null,
|
||||
themeOverrides: getPrimaryColorOverride.value,
|
||||
locale: localePackage.value.locale,
|
||||
dateLocale: localePackage.value.dateLocal,
|
||||
})),
|
||||
},
|
||||
)
|
||||
// 离散 API 自行挂载 Vue 应用;配置响应式更新,切换主题时无需在 render 中重新挂载。
|
||||
const { message, notification, dialog, loadingBar, unmount } =
|
||||
createDiscreteApi(['message', 'dialog', 'notification', 'loadingBar'], {
|
||||
configProviderProps: computed(() => ({
|
||||
theme: getAppTheme.value ? darkTheme : null,
|
||||
themeOverrides: getPrimaryColorOverride.value,
|
||||
locale: localePackage.value.locale,
|
||||
dateLocale: localePackage.value.dateLocal,
|
||||
})),
|
||||
})
|
||||
|
||||
window.$dialog = dialog // 注入 `dialog`
|
||||
window.$message = message // 注入 `message`
|
||||
window.$loadingBar = loadingBar // 注入 `loadingBar`
|
||||
window.$notification = notification // 注入 `notification`
|
||||
}
|
||||
window.$dialog = dialog
|
||||
window.$message = message
|
||||
window.$loadingBar = loadingBar
|
||||
window.$notification = notification
|
||||
onScopeDispose(unmount)
|
||||
|
||||
expose()
|
||||
|
||||
@ -55,13 +48,11 @@ export default defineComponent({
|
||||
getPrimaryColorOverride,
|
||||
localePackage,
|
||||
getAppTheme,
|
||||
discreteApi,
|
||||
}
|
||||
},
|
||||
render() {
|
||||
const {
|
||||
$slots: { default: slotDefault },
|
||||
discreteApi,
|
||||
} = this
|
||||
const { getPrimaryColorOverride, getAppTheme, localePackage } = this
|
||||
|
||||
@ -79,7 +70,6 @@ export default defineComponent({
|
||||
<NNotificationProvider>
|
||||
<NGlobalStyle />
|
||||
{slotDefault?.()}
|
||||
{discreteApi()}
|
||||
</NNotificationProvider>
|
||||
</NModalProvider>
|
||||
</NDialogProvider>
|
||||
|
||||
@ -10,4 +10,6 @@
|
||||
- `RTable` 的列顺序配置以第一层列为单位,深层子列跟随根列;大量列数据的性能需按实际业务验证。
|
||||
- `RIcon.name` 为生成的完整分包路径类型,图标改动会在开发、HMR 和构建时同步;不要手工修改生成清单。
|
||||
|
||||
组件样式随组件入口加载。调整 Naive UI 内部元素时,使用当前组件的类名限定作用范围;组件需填满容器时由调用处或组件自身声明尺寸。全屏 `RModal` 的卡片正文仅在溢出时滚动,`RBarcode` 的加载区域随条码尺寸或响应式容器伸缩。
|
||||
|
||||
示例见 `src/views/demo`;Hooks 的独立交互示例与生命周期约定见 [Hooks 文档](../hooks/README.md)。新增或修改注释遵循 [注释规范](../../docs/comment-style.md),完整教程放在 README 与示例页。
|
||||
|
||||
@ -24,12 +24,12 @@
|
||||
|
||||
.r-barcode-spin,
|
||||
.r-barcode-spin .n-spin-content {
|
||||
width: max-content !important;
|
||||
height: max-content !important;
|
||||
width: max-content;
|
||||
height: max-content;
|
||||
}
|
||||
|
||||
.r-barcode-spin:has(.r-barcode-container),
|
||||
.r-barcode-spin:has(.r-barcode-container) .n-spin-content {
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
outline: none;
|
||||
text-align: center;
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: var(--r-icon-color);
|
||||
@ -14,6 +15,7 @@
|
||||
cursor: var(--r-icon-cursor);
|
||||
|
||||
& svg[RIconAttribute='r-icon'] {
|
||||
display: block;
|
||||
width: var(--r-icon-width);
|
||||
height: var(--r-icon-height);
|
||||
fill: currentColor;
|
||||
|
||||
@ -41,7 +41,7 @@ export default defineComponent({
|
||||
R_MODAL_CLASS,
|
||||
isFullscreenCardType ? FULLSCREEN_CARD_TYPE_CLASS : '',
|
||||
]}
|
||||
style={[cssVars, isFullscreenCardType ? `height: 100vh` : '']}
|
||||
style={cssVars}
|
||||
preset={preset}
|
||||
{...{
|
||||
id: uuidEl,
|
||||
|
||||
@ -1,14 +1,11 @@
|
||||
.r-modal.n-card.r-modal__preset-card--fullscreen {
|
||||
width: 100%;
|
||||
inline-size: 100%;
|
||||
block-size: 100dvh;
|
||||
|
||||
// 当设置全屏时,启用滚动
|
||||
& .n-card__content {
|
||||
overflow: scroll;
|
||||
max-height: calc(
|
||||
var(--html-height) - var(--n-padding-bottom) - var(
|
||||
--n-padding-bottom
|
||||
) - var(--n-padding-top)
|
||||
);
|
||||
> .n-card-content {
|
||||
min-block-size: 0;
|
||||
overflow: auto;
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
- `top`:完整顶部导航,Naive UI 处理横向溢出与子菜单。
|
||||
- `mixed`:顶部一级导航,侧栏显示当前一级菜单的可见子菜单;单页菜单不占侧栏空间。
|
||||
- ≤768px 自动使用完整菜单抽屉,不覆盖已保存的桌面模式。抽屉选中菜单后自动收起。
|
||||
- 侧栏与抽屉的 Logo 固定在菜单上方;滚动条从菜单区域开始。菜单设置中的原生滚动条开关只作用于菜单列表。
|
||||
- 内容支持流式铺满或定宽居中、640–2560px 最大宽度、0–48px 间距,以及顶栏/页脚固定或随内容滚动。标签和版权显隐沿用原设置。
|
||||
- 最大化内容区与页面、标签菜单共享 Pinia 状态,退出按钮和 Esc 可恢复。
|
||||
|
||||
@ -46,3 +47,7 @@ updateSettingState('layoutConfig', {
|
||||
插槽替换遵循当前模式与显隐设置:顶部导航模式无 sidebar,关闭标签/版权后不渲染相应区域。自定义内容需要自行处理请求取消与路由内容;未替换时沿用默认 Provider 和路由缓存。
|
||||
|
||||
布局的内容滚动引用仍为 `LAYOUT_CONTENT_REF`,侧栏引用为 `LAYOUT_SIDER_REF`;`useContentScroll` / `useSiderScroll` 在执行时读取当前引用,支持模式切换与组件重新挂载。
|
||||
|
||||
## 样式归属
|
||||
|
||||
`index.scss` 负责布局外壳、内容滚动与最大化。顶部导航、菜单、标签栏和内容加载状态的样式随各自组件维护。设置抽屉与布局实验室共用 `LayoutSettings` 和 `LayoutSettings.scss`。方形选项卡片内的缩略图标出导航位置,卡片下方说明当前模式的菜单行为。卡片组为键盘焦点外框留出空间,选中状态由 `aria-pressed` 表示。
|
||||
|
||||
151
src/layout/components/LayoutSettings.scss
Normal file
151
src/layout/components/LayoutSettings.scss
Normal file
@ -0,0 +1,151 @@
|
||||
.r-layout-settings {
|
||||
min-inline-size: 0;
|
||||
|
||||
.n-form-item {
|
||||
margin-block-end: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.r-layout-settings__hint {
|
||||
color: var(--r-text-muted);
|
||||
font-size: 12px;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.r-layout-presets {
|
||||
box-sizing: border-box;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
max-inline-size: 300px;
|
||||
padding: 6px;
|
||||
|
||||
> .r-layout-settings__hint {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
}
|
||||
|
||||
.r-layout-preset {
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
display: grid;
|
||||
grid-template-rows: minmax(0, 1fr) auto;
|
||||
place-items: center;
|
||||
align-self: start;
|
||||
gap: 3px;
|
||||
min-inline-size: 0;
|
||||
min-block-size: 0;
|
||||
inline-size: 100%;
|
||||
aspect-ratio: 1;
|
||||
padding: 6px 4px;
|
||||
border: 1px solid var(--r-line);
|
||||
border-radius: var(--r-radius);
|
||||
background: var(--r-surface-muted);
|
||||
color: var(--r-text-secondary);
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
line-height: 1.3;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition:
|
||||
border-color 0.18s var(--r-bezier),
|
||||
background-color 0.18s var(--r-bezier),
|
||||
color 0.18s var(--r-bezier);
|
||||
|
||||
&:hover {
|
||||
border-color: var(--r-theme-primary-color);
|
||||
background: var(--r-surface-hover);
|
||||
}
|
||||
|
||||
&[aria-pressed='true'] {
|
||||
border-color: var(--r-theme-primary-color);
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--r-theme-primary-color) 10%,
|
||||
var(--r-surface)
|
||||
);
|
||||
color: var(--r-selected-text);
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.r-layout-preview {
|
||||
box-sizing: border-box;
|
||||
display: grid;
|
||||
grid-template: minmax(0, 1fr) minmax(0, 3fr) / minmax(0, 1fr) minmax(0, 3fr);
|
||||
gap: 3px;
|
||||
block-size: min(100%, 42px);
|
||||
max-inline-size: 100%;
|
||||
aspect-ratio: 1;
|
||||
padding: 4px;
|
||||
border: 1px solid var(--r-line);
|
||||
border-radius: 8px;
|
||||
background: var(--r-surface);
|
||||
|
||||
> span {
|
||||
border-radius: 2px;
|
||||
background: currentColor;
|
||||
}
|
||||
|
||||
&__aside {
|
||||
grid-area: 1 / 1 / 3 / 2;
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
&__header {
|
||||
grid-area: 1 / 2 / 2 / 3;
|
||||
opacity: 0.28;
|
||||
}
|
||||
|
||||
&__body {
|
||||
grid-area: 2 / 2 / 3 / 3;
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
&--top {
|
||||
.r-layout-preview__aside {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.r-layout-preview__header,
|
||||
.r-layout-preview__body {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
}
|
||||
|
||||
&--top .r-layout-preview__header,
|
||||
&--mixed .r-layout-preview__header {
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
&--mixed .r-layout-preview__header {
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
currentColor 30%,
|
||||
transparent 30% 52%,
|
||||
currentColor 52%
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
.r-layout-preset__selected {
|
||||
position: absolute;
|
||||
inset-block-start: 4px;
|
||||
inset-inline-end: 5px;
|
||||
color: var(--r-selected-text);
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
@media (forced-colors: active) {
|
||||
.r-layout-preset[aria-pressed='true'] {
|
||||
border-color: Highlight;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.r-layout-preset {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
import './LayoutSettings.scss'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { useSettingActions, useSettingGetters } from '@/store'
|
||||
import { getDefaultSettingConfig } from '@/store/modules/setting/constant'
|
||||
@ -29,14 +30,13 @@ export default defineComponent({
|
||||
{props.showDescription ? (
|
||||
<p class="r-layout-settings__hint">{text('description')}</p>
|
||||
) : null}
|
||||
<NFlex wrap={false} class="r-layout-presets">
|
||||
<div class="r-layout-presets">
|
||||
{modes.map((mode) => (
|
||||
<NButton
|
||||
<button
|
||||
type="button"
|
||||
class="r-layout-preset"
|
||||
key={mode}
|
||||
aria-pressed={getLayoutConfig.value.mode === mode}
|
||||
type={getLayoutConfig.value.mode === mode ? 'primary' : 'default'}
|
||||
secondary
|
||||
onClick={() => update({ mode })}
|
||||
>
|
||||
<span
|
||||
@ -53,9 +53,12 @@ export default defineComponent({
|
||||
✓
|
||||
</span>
|
||||
) : null}
|
||||
</NButton>
|
||||
</button>
|
||||
))}
|
||||
</NFlex>
|
||||
<p class="r-layout-settings__hint">
|
||||
{text(`modeHint.${getLayoutConfig.value.mode}`)}
|
||||
</p>
|
||||
</div>
|
||||
<NForm labelPlacement="top" showFeedback={false}>
|
||||
<NFormItem label={text('contentWidth')}>
|
||||
<NSelect
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
.r-menu__logo {
|
||||
width: 100%;
|
||||
height: $layoutHeaderHeight;
|
||||
flex-shrink: 0;
|
||||
box-sizing: border-box;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--r-line);
|
||||
color: var(--r-text);
|
||||
background: inherit;
|
||||
background: transparent;
|
||||
font-size: 16px;
|
||||
text-align: left;
|
||||
padding: 0 18px 0 24px;
|
||||
@ -15,31 +15,28 @@
|
||||
align-items: center;
|
||||
gap: 8px 12px;
|
||||
font-weight: 650;
|
||||
overflow: hidden;
|
||||
|
||||
&.r-menu__logo-url {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
cursor: pointer;
|
||||
background-color: inherit;
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
&.r-menu__logo--collapsed {
|
||||
padding-inline: 8px;
|
||||
}
|
||||
|
||||
& .r-menu__logo-title {
|
||||
opacity: 0;
|
||||
display: none;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
@include overflowEllipsis;
|
||||
|
||||
&.r-menu__logo-title--open {
|
||||
opacity: 1;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.r-menu__logo-initial {
|
||||
color: var(--r-theme-primary-color);
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@ -5,8 +5,6 @@ import { useSettingGetters } from '@/store'
|
||||
import { isValueType, renderNode } from '@/utils'
|
||||
import { NEllipsis, NTooltip } from 'naive-ui'
|
||||
|
||||
export const SIDER_BAR_LOGO = shallowRef<HTMLElement>()
|
||||
|
||||
export default defineComponent({
|
||||
name: 'SiderBarLogo',
|
||||
props: {
|
||||
@ -67,9 +65,14 @@ export default defineComponent({
|
||||
<button
|
||||
type="button"
|
||||
disabled={!sideBarLogo?.url}
|
||||
class={['r-menu__logo', sideBarLogo?.url ? 'r-menu__logo-url' : null]}
|
||||
class={[
|
||||
'r-menu__logo',
|
||||
{
|
||||
'r-menu__logo-url': sideBarLogo.url,
|
||||
'r-menu__logo--collapsed': collapsed,
|
||||
},
|
||||
]}
|
||||
onClick={sideBarLogoClick.bind(this)}
|
||||
ref={SIDER_BAR_LOGO}
|
||||
>
|
||||
{sideBarLogo?.icon ? (
|
||||
collapsed ? (
|
||||
|
||||
@ -1,45 +1,64 @@
|
||||
.n-drawer.app-menu__drawer {
|
||||
width: auto !important;
|
||||
|
||||
& .n-layout-sider {
|
||||
height: 100%;
|
||||
}
|
||||
.app-menu__drawer .app-menu__sider {
|
||||
block-size: 100%;
|
||||
}
|
||||
|
||||
.app-menu__sider {
|
||||
--r-primary-text: var(--n-text-color);
|
||||
--r-selected-text: var(--n-text-color);
|
||||
|
||||
border-inline-end: 1px solid var(--r-line);
|
||||
box-shadow: none;
|
||||
|
||||
.app-menu__body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-inline-size: 0;
|
||||
}
|
||||
|
||||
.app-menu__scroll {
|
||||
flex: 1;
|
||||
min-block-size: 0;
|
||||
background: transparent;
|
||||
|
||||
:where(.n-layout-scroll-container, .n-scrollbar-container) {
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
}
|
||||
|
||||
.r-menu__logo {
|
||||
color: inherit;
|
||||
border-block-end: 1px solid var(--r-line);
|
||||
border-block-end-color: color-mix(in srgb, currentColor 15%, transparent);
|
||||
}
|
||||
|
||||
.n-menu-item-content {
|
||||
transition: color 0.18s ease;
|
||||
}
|
||||
}
|
||||
|
||||
.app-menu__sider .r-menu__logo {
|
||||
color: var(--n-text-color);
|
||||
border-bottom-color: color-mix(in oklab, currentColor 15%, transparent);
|
||||
}
|
||||
.r-menu--app {
|
||||
.n-menu-item-content-header {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
|
||||
.app-menu__sider .r-menu__logo.r-menu__logo-url {
|
||||
background-color: var(--n-color);
|
||||
}
|
||||
.n-ellipsis {
|
||||
min-inline-size: 0;
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.app-menu__sider .r-menu__logo-initial {
|
||||
color: inherit;
|
||||
}
|
||||
.n-menu-item-content-header__extra {
|
||||
flex-shrink: 0;
|
||||
margin-inline-end: 8px;
|
||||
}
|
||||
|
||||
.app-menu__sider {
|
||||
--r-primary-text: var(--n-text-color);
|
||||
--r-selected-text: var(--n-text-color);
|
||||
}
|
||||
|
||||
.r-menu--app .n-menu-item-content--selected .n-menu-item-content-header {
|
||||
font-weight: 600;
|
||||
.n-menu-item-content--selected .n-menu-item-content-header {
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
@media (forced-colors: active) {
|
||||
.r-menu--app .n-menu-item-content--selected,
|
||||
.menu-tag__btn.n-button--primary-type {
|
||||
.r-menu--app .n-menu-item-content--selected {
|
||||
outline: 1px solid Highlight;
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import {
|
||||
} from '@/store'
|
||||
import type { AppMenuOption, NaiveMenuOptions } from '@/types'
|
||||
import { positionSelectedMenuItem } from '@/utils'
|
||||
import { NDrawer, NLayoutSider, NMenu } from 'naive-ui'
|
||||
import { NDrawer, NLayoutContent, NLayoutSider, NMenu } from 'naive-ui'
|
||||
import type { MenuInst } from 'naive-ui'
|
||||
import type { PropType } from 'vue'
|
||||
import SiderBarLogo from './components/SiderBarLogo'
|
||||
@ -25,7 +25,7 @@ export default defineComponent({
|
||||
const menuRef = shallowRef<MenuInst | null>(null)
|
||||
const { changeMenuModelValue, collapsedMenu, updateMenuState } =
|
||||
useMenuActions()
|
||||
const { getMenuConfig } = useSettingGetters()
|
||||
const { getAppTheme, getMenuConfig } = useSettingGetters()
|
||||
const { getMenuOptions, getCollapsed, getMenuKey } = useMenuGetters()
|
||||
const { globalDrawerValue } = useRuntimeGetters()
|
||||
const { setRuntimeState } = useRuntimeActions()
|
||||
@ -35,6 +35,14 @@ export default defineComponent({
|
||||
else setRuntimeState('globalDrawerValue', false)
|
||||
},
|
||||
})
|
||||
const menuWidth = computed(() =>
|
||||
isTabletOrSmaller.value
|
||||
? Math.min(getMenuConfig.value.menuWidth, width.value - 32)
|
||||
: getMenuConfig.value.menuWidth,
|
||||
)
|
||||
const collapsed = computed(
|
||||
() => !isTabletOrSmaller.value && getCollapsed.value,
|
||||
)
|
||||
|
||||
watch(
|
||||
[getMenuKey, () => props.options, menuRef],
|
||||
@ -56,42 +64,56 @@ export default defineComponent({
|
||||
collapseMode={getMenuConfig.value.collapsedMode}
|
||||
collapsedWidth={getMenuConfig.value.collapsedWidth}
|
||||
onUpdateCollapsed={collapsedMenu}
|
||||
width={
|
||||
isTabletOrSmaller.value
|
||||
? Math.min(getMenuConfig.value.menuWidth, width.value - 32)
|
||||
: getMenuConfig.value.menuWidth
|
||||
}
|
||||
nativeScrollbar={getMenuConfig.value.nativeScrollbar}
|
||||
ref={LAYOUT_SIDER_REF}
|
||||
collapsed={isTabletOrSmaller.value ? false : getCollapsed.value}
|
||||
width={menuWidth.value}
|
||||
contentClass="app-menu__body"
|
||||
contentStyle={{ overflow: 'clip' }}
|
||||
collapsed={collapsed.value}
|
||||
inverted={getMenuConfig.value.inverted}
|
||||
>
|
||||
{props.showLogo && getMenuConfig.value.menuSiderBarLogo ? (
|
||||
<SiderBarLogo collapsed={getCollapsed.value} />
|
||||
<SiderBarLogo collapsed={collapsed.value} />
|
||||
) : null}
|
||||
<NMenu
|
||||
ref={menuRef}
|
||||
class="r-menu--app"
|
||||
keyField="fullPath"
|
||||
value={getMenuKey.value}
|
||||
options={
|
||||
(props.options ??
|
||||
getMenuOptions.value) as unknown as NaiveMenuOptions[]
|
||||
<NLayoutContent
|
||||
class="app-menu__scroll"
|
||||
nativeScrollbar={getMenuConfig.value.nativeScrollbar}
|
||||
themeOverrides={
|
||||
getMenuConfig.value.inverted && !getAppTheme.value
|
||||
? {
|
||||
peers: {
|
||||
Scrollbar: {
|
||||
color: 'rgb(255 255 255 / 30%)',
|
||||
colorHover: 'rgb(255 255 255 / 40%)',
|
||||
},
|
||||
},
|
||||
}
|
||||
: void 0
|
||||
}
|
||||
indent={getMenuConfig.value.collapsedIndent}
|
||||
collapsed={isTabletOrSmaller.value ? false : getCollapsed.value}
|
||||
collapsedIconSize={getMenuConfig.value.collapsedIconSize}
|
||||
collapsedWidth={getMenuConfig.value.collapsedWidth}
|
||||
onUpdateValue={(key, option) => {
|
||||
changeMenuModelValue(key, option as unknown as AppMenuOption)
|
||||
ref={LAYOUT_SIDER_REF}
|
||||
>
|
||||
<NMenu
|
||||
ref={menuRef}
|
||||
class="r-menu--app"
|
||||
keyField="fullPath"
|
||||
value={getMenuKey.value}
|
||||
options={
|
||||
(props.options ??
|
||||
getMenuOptions.value) as unknown as NaiveMenuOptions[]
|
||||
}
|
||||
indent={getMenuConfig.value.collapsedIndent}
|
||||
collapsed={collapsed.value}
|
||||
collapsedIconSize={getMenuConfig.value.collapsedIconSize}
|
||||
collapsedWidth={getMenuConfig.value.collapsedWidth}
|
||||
onUpdateValue={(key, option) => {
|
||||
changeMenuModelValue(key, option as unknown as AppMenuOption)
|
||||
|
||||
if (isTabletOrSmaller.value)
|
||||
setRuntimeState('globalDrawerValue', false)
|
||||
}}
|
||||
accordion={getMenuConfig.value.accordion}
|
||||
iconSize={getMenuConfig.value.iconSize}
|
||||
inverted={getMenuConfig.value.inverted}
|
||||
/>
|
||||
if (isTabletOrSmaller.value)
|
||||
setRuntimeState('globalDrawerValue', false)
|
||||
}}
|
||||
accordion={getMenuConfig.value.accordion}
|
||||
iconSize={getMenuConfig.value.iconSize}
|
||||
inverted={getMenuConfig.value.inverted}
|
||||
/>
|
||||
</NLayoutContent>
|
||||
</NLayoutSider>
|
||||
)
|
||||
|
||||
@ -99,6 +121,7 @@ export default defineComponent({
|
||||
isTabletOrSmaller.value ? (
|
||||
<NDrawer
|
||||
class="app-menu__drawer"
|
||||
width={menuWidth.value}
|
||||
show={globalDrawerValue.value}
|
||||
onUpdateShow={(value) => setRuntimeState('globalDrawerValue', value)}
|
||||
placement="left"
|
||||
|
||||
@ -5,10 +5,12 @@ $menuTagWrapperWidth: 76px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 6px 0;
|
||||
border-bottom: 1px solid var(--r-line);
|
||||
background: var(--r-surface);
|
||||
|
||||
& .menu-tag-space {
|
||||
width: calc(100% - $space * 2);
|
||||
padding: 0px 18px;
|
||||
padding: 0px $layoutRouterViewContainer;
|
||||
|
||||
& .menu-tag-wrapper {
|
||||
width: calc(100% - $space * 2 - $menuTagWrapperWidth);
|
||||
@ -24,6 +26,10 @@ $menuTagWrapperWidth: 76px;
|
||||
border-radius: 7px;
|
||||
font-weight: 500;
|
||||
|
||||
&.n-button--primary-type {
|
||||
color: var(--r-selected-text);
|
||||
}
|
||||
|
||||
.n-button__icon {
|
||||
width: var(--n-icon-size);
|
||||
height: var(--n-icon-size);
|
||||
@ -39,14 +45,11 @@ $menuTagWrapperWidth: 76px;
|
||||
}
|
||||
}
|
||||
|
||||
.r-template--light,
|
||||
.r-template--dark {
|
||||
.menu-tag__btn .menu-tag__btn-icon {
|
||||
border-radius: 2px;
|
||||
.menu-tag__btn .menu-tag__btn-icon {
|
||||
border-radius: 2px;
|
||||
|
||||
&:hover {
|
||||
background-color: var(--n-color-hover);
|
||||
}
|
||||
&:hover {
|
||||
background-color: var(--n-color-hover);
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,12 +65,13 @@ $menuTagWrapperWidth: 76px;
|
||||
animation: elementRotate 0.8s linear infinite;
|
||||
}
|
||||
|
||||
.menu-tag {
|
||||
border-bottom: 1px solid var(--r-line);
|
||||
box-shadow: none;
|
||||
background: var(--r-surface);
|
||||
}
|
||||
|
||||
.override-button__menu-tag {
|
||||
padding: 0 6px;
|
||||
}
|
||||
|
||||
@media (forced-colors: active) {
|
||||
.menu-tag__btn.n-button--primary-type {
|
||||
outline: 1px solid Highlight;
|
||||
outline-offset: -2px;
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ $globalSearchWidth: 650px;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
|
||||
& .n-card__content,
|
||||
> .n-card-content,
|
||||
& .n-spin-content {
|
||||
min-height: 90px;
|
||||
}
|
||||
|
||||
@ -3,15 +3,11 @@
|
||||
padding: 0 $layoutRouterViewContainer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-bottom: 1px solid var(--r-line);
|
||||
|
||||
> .layout-header__method {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.layout-header {
|
||||
border-bottom: 1px solid var(--r-line);
|
||||
box-shadow: none;
|
||||
|
||||
.n-breadcrumb {
|
||||
font-size: 13px;
|
||||
|
||||
17
src/layout/components/TopNavigation/index.scss
Normal file
17
src/layout/components/TopNavigation/index.scss
Normal file
@ -0,0 +1,17 @@
|
||||
.r-layout-top-navigation {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-inline-size: 0;
|
||||
padding-inline: 16px;
|
||||
border-block-end: 1px solid var(--r-line);
|
||||
background: var(--r-surface);
|
||||
|
||||
.r-menu__logo {
|
||||
inline-size: 200px;
|
||||
}
|
||||
|
||||
.n-menu {
|
||||
flex: 1;
|
||||
min-inline-size: 0;
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
import './index.scss'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { useMenuActions, useMenuGetters, useSettingGetters } from '@/store'
|
||||
import type { AppMenuOption, NaiveMenuOptions } from '@/types'
|
||||
|
||||
@ -1,5 +1,17 @@
|
||||
.layout-content-spin {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
> .n-spin-content {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 100%;
|
||||
|
||||
&[v-cloak] {
|
||||
display: none;
|
||||
@ -12,7 +24,3 @@
|
||||
right: 20px;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.r-layout-full__viewer-content {
|
||||
background-color: var(--r-canvas);
|
||||
}
|
||||
|
||||
@ -77,6 +77,7 @@ export default defineComponent({
|
||||
size="large"
|
||||
themeOverrides={themeOverridesSpin}
|
||||
class={[
|
||||
'layout-content-spin',
|
||||
layoutContentMaximize
|
||||
? 'r-layout-full__viewer-content--maximize'
|
||||
: null,
|
||||
|
||||
@ -8,49 +8,40 @@
|
||||
> .n-layout-scroll-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
overflow: clip;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.r-layout-header-region,
|
||||
.r-layout-tabs-region,
|
||||
.r-layout-footer-region {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.r-layout-full__viewer-content {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
background: var(--r-canvas);
|
||||
|
||||
> .n-scrollbar > .n-scrollbar-container {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.r-layout-content-scroll {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
.r-layout-content-inner {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
max-width: var(--layout-content-max-width);
|
||||
margin-inline: auto;
|
||||
padding: var(--layout-content-padding);
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.r-layout-top-navigation {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
padding-inline: 16px;
|
||||
|
||||
.r-menu__logo {
|
||||
flex-shrink: 0;
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.n-menu {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
@ -63,106 +54,14 @@
|
||||
height: 100dvh !important;
|
||||
}
|
||||
|
||||
.r-layout-settings {
|
||||
container-type: inline-size;
|
||||
|
||||
.n-form-item {
|
||||
margin-block-end: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.r-layout-presets .r-layout-preset {
|
||||
flex: 1;
|
||||
height: auto;
|
||||
padding: 10px 4px;
|
||||
|
||||
.n-button__content {
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.r-layout-preview {
|
||||
display: grid;
|
||||
grid-template: 10px 30px / 14px 42px;
|
||||
gap: 3px;
|
||||
width: 59px;
|
||||
|
||||
> span {
|
||||
border-radius: 2px;
|
||||
background: currentColor;
|
||||
opacity: 0.25;
|
||||
}
|
||||
|
||||
&__aside {
|
||||
grid-area: 1 / 1 / 3 / 2;
|
||||
opacity: 0.65 !important;
|
||||
}
|
||||
|
||||
&__header {
|
||||
grid-area: 1 / 2 / 2 / 3;
|
||||
}
|
||||
|
||||
&__body {
|
||||
grid-area: 2 / 2 / 3 / 3;
|
||||
}
|
||||
|
||||
&--top {
|
||||
.r-layout-preview__aside {
|
||||
display: none;
|
||||
}
|
||||
.r-layout-preview__header {
|
||||
grid-column: 1 / 3;
|
||||
}
|
||||
.r-layout-preview__body {
|
||||
grid-column: 1 / 3;
|
||||
}
|
||||
}
|
||||
|
||||
&--mixed .r-layout-preview__header {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
|
||||
@container (max-width: 240px) {
|
||||
.r-layout-presets {
|
||||
flex-wrap: wrap !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.r-layout-full .r-layout-content-inner {
|
||||
padding: min(var(--layout-content-padding), 16px);
|
||||
}
|
||||
}
|
||||
|
||||
.r-layout-settings__hint {
|
||||
color: var(--r-text-muted);
|
||||
font-size: 12px;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.r-layout-extension-description {
|
||||
margin-block-end: 18px;
|
||||
color: var(--r-text-secondary);
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.r-layout-presets .r-layout-preset {
|
||||
padding: 18px 8px 14px;
|
||||
border: 1px solid var(--r-line);
|
||||
border-radius: 10px;
|
||||
|
||||
&[aria-pressed='true'] {
|
||||
border-color: currentColor;
|
||||
box-shadow: 0 0 0 1px currentColor;
|
||||
}
|
||||
}
|
||||
|
||||
.r-layout-preset__selected {
|
||||
position: absolute;
|
||||
inset-block-start: 5px;
|
||||
inset-inline-end: 8px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@ -68,11 +68,15 @@ export default defineComponent({
|
||||
)
|
||||
const tabs = () =>
|
||||
getMenuTagSwitch.value ? (
|
||||
<div ref={tagsRef}>{slots.tabs?.() ?? <FeatureWrapper />}</div>
|
||||
<div ref={tagsRef} class="r-layout-tabs-region">
|
||||
{slots.tabs?.() ?? <FeatureWrapper />}
|
||||
</div>
|
||||
) : null
|
||||
const footer = () =>
|
||||
getCopyrightSwitch.value ? (
|
||||
<div ref={footerRef}>{slots.footer?.() ?? <FooterWrapper />}</div>
|
||||
<div ref={footerRef} class="r-layout-footer-region">
|
||||
{slots.footer?.() ?? <FooterWrapper />}
|
||||
</div>
|
||||
) : null
|
||||
|
||||
return () => {
|
||||
@ -128,6 +132,7 @@ export default defineComponent({
|
||||
: void 0
|
||||
}
|
||||
nativeScrollbar={false}
|
||||
contentClass="r-layout-content-scroll"
|
||||
>
|
||||
{!config.fixedHeader ? (
|
||||
<>
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
{
|
||||
"title": "Layout playground",
|
||||
"description": "Changes apply immediately and are saved automatically. Mixed navigation shows the current section’s children. Small screens use a drawer while retaining desktop preferences.",
|
||||
"description": "Changes apply immediately and are saved automatically. Small screens use a menu drawer and keep your desktop layout preference.",
|
||||
"side": "Sidebar",
|
||||
"top": "Top",
|
||||
"mixed": "Mixed",
|
||||
"modeHint": {
|
||||
"side": "All menus live in the sidebar. Expand a section to see its submenus.",
|
||||
"top": "All menus are available from the top bar. Submenus open in dropdowns.",
|
||||
"mixed": "The top bar shows first-level menus. The sidebar appears when the current section has visible submenus."
|
||||
},
|
||||
"contentWidth": "Content width",
|
||||
"fluid": "Fluid",
|
||||
"fixed": "Centered",
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
{
|
||||
"title": "布局实验室",
|
||||
"description": "配置即时生效并自动保存。混合导航显示当前一级菜单的子菜单;窄屏自动使用抽屉导航,保留桌面偏好。",
|
||||
"description": "配置即时生效并自动保存。窄屏使用菜单抽屉,保留桌面布局偏好。",
|
||||
"side": "侧边导航",
|
||||
"top": "顶部导航",
|
||||
"mixed": "混合导航",
|
||||
"modeHint": {
|
||||
"side": "各级菜单都在侧栏,展开分组即可查看子菜单。",
|
||||
"top": "各级菜单都从顶栏进入,子菜单在下拉菜单中打开。",
|
||||
"mixed": "顶栏显示一级菜单。有可见子菜单的分组会展开侧栏。"
|
||||
},
|
||||
"contentWidth": "内容宽度",
|
||||
"fluid": "流式铺满",
|
||||
"fixed": "定宽居中",
|
||||
|
||||
10
src/styles/animate.scss
vendored
10
src/styles/animate.scss
vendored
@ -106,3 +106,13 @@
|
||||
opacity: 0;
|
||||
transform: scale(0.85);
|
||||
}
|
||||
|
||||
@keyframes elementRotate {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
@use '@/styles/animate.scss' as *;
|
||||
@use '@/styles/root.scss' as *;
|
||||
@use '@/styles/naive.scss' as *;
|
||||
@use '@/styles/design-system.scss' as *;
|
||||
@use '@/styles/print-css.scss' as *;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
:root {
|
||||
--r-bezier: cubic-bezier(0.4, 0, 0.2, 1);
|
||||
--r-primary-text: var(--r-theme-primary-color);
|
||||
--r-selected-text: var(--r-theme-primary-color);
|
||||
--r-canvas: #f5f7fb;
|
||||
@ -64,8 +65,3 @@
|
||||
transition-duration: 0.01ms !important;
|
||||
}
|
||||
}
|
||||
|
||||
.r-template--dark .menu-tag .menu-tag__btn.n-button--primary-type,
|
||||
.r-template--dark .r-layout-settings .r-layout-preset[aria-pressed='true'] {
|
||||
color: var(--r-text);
|
||||
}
|
||||
|
||||
@ -12,38 +12,9 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
// 滚动条样式
|
||||
@mixin scrollStyle {
|
||||
::-webkit-scrollbar {
|
||||
// 改变纵向滚动条宽度
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
transition: background-color 0.2s var(--r-scrollbar-bezier);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
// 改变滚动条轨道颜色
|
||||
border-radius: 5px;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
// 改变滚动条滑轨相关的样式
|
||||
border-radius: 5px;
|
||||
background-color: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
// 移入鼠标效果
|
||||
border-radius: 5px;
|
||||
background-color: rgba(255, 255, 255, 0.3);
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
// 根据主题切换样式
|
||||
@mixin useAppTheme($theme) {
|
||||
html[class='r-template--#{$theme}'] & {
|
||||
html.r-template--#{$theme} & {
|
||||
@content;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,38 +1,5 @@
|
||||
// layout content 区域默认开启继承宽高,避免 global loading 丢失高度
|
||||
.r-layout-full__viewer-content .n-spin-container,
|
||||
.r-layout-full__viewer-content .n-spin-container .n-spin-content {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
// 手动设置 AppMenu Item Header 样式,兼容 extra 的情况
|
||||
.r-menu--app
|
||||
.n-menu-item-content.n-menu-item-content--selected
|
||||
.n-menu-item-content-header,
|
||||
.r-menu--app .n-menu-item-content .n-menu-item-content-header {
|
||||
display: flex;
|
||||
gap: 0 6px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
// 调整自定义 AppMenu 样式
|
||||
.r-menu--app {
|
||||
// 手动设置 label 宽度,兼容 extra 的情况
|
||||
.n-menu-item-content-header .n-ellipsis {
|
||||
width: calc(100% - 41px);
|
||||
}
|
||||
|
||||
.n-menu-item-content-header__extra {
|
||||
margin-right: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
// 手动设置 NDatePicker, NInputNumber 样式
|
||||
// 表单类控件沿用模板的铺满宽度约定,组件专属覆盖放在各自目录。
|
||||
.n-date-picker,
|
||||
.n-input-number {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.n-flex.flex-vertical {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
// css vars root
|
||||
:root {
|
||||
--r-bezier: cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
// animation root
|
||||
@keyframes elementRotate {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,2 @@
|
||||
$layoutRouterViewContainer: 18px;
|
||||
$layoutHeaderHeight: 64px;
|
||||
$layoutMenuHeight: 46px;
|
||||
// 内容区域背景色(dark)
|
||||
$layoutContentBackgroundColorDark: #101014;
|
||||
// 内容区域背景色(light)
|
||||
$layoutContentBackgroundColorLight: #f7f9f8;
|
||||
// 底部区域背景色(dark)
|
||||
$layoutFooterBackgroundColorDark: rgba(24, 24, 28, 1);
|
||||
// 底部区域背景色(light)
|
||||
$layoutFooterBackgroundColorLight: rgba(255, 255, 255, 1);
|
||||
// 区域阴影
|
||||
$layoutShadowColorLight: #0000001f;
|
||||
$layoutShadowColorDark: #000000b8;
|
||||
|
||||
@ -1,84 +1,49 @@
|
||||
import { LAYOUT_SIDER_REF } from '@/app-config'
|
||||
import { useSiderScroll } from '@/hooks'
|
||||
import { SIDER_BAR_LOGO } from '@/layout/components/Menu/components/SiderBarLogo'
|
||||
import { unrefElement } from '@/utils'
|
||||
|
||||
// 菜单激活样式 class name
|
||||
const MENU_ITEM_SELECTED = '.n-menu-item-content--selected'
|
||||
// 菜单项 class name
|
||||
const MENU_ITEM = '.n-menu-item'
|
||||
// 折叠菜单激活样式 class name
|
||||
const MENU_COLLAPSED_ITEM_SELECTED = '.n-menu-item-content--child-active'
|
||||
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 将 Sider 滚动条滚动到当前激活菜单项的位置。
|
||||
*
|
||||
* 但是,该方法目前存在一个问题,由于 NMenu 的渲染机制,默认不会渲染子菜单;
|
||||
* 所以导致一个问题,则是不能准确的获取到激活菜单项的元素。
|
||||
*
|
||||
* 有考虑过使用 setTimeout 来延迟执行,但是该渲染受到机器配置的影响,不是一个稳定的解决方案。
|
||||
* 将菜单滚动到当前已渲染的激活项,仅在其超出可视区域时滚动。
|
||||
* 调用方需要先展开父菜单并等待渲染,尚未挂载的子菜单项无法定位。
|
||||
*
|
||||
* @example
|
||||
* positionSelectedMenuItem() // 滚动到当前激活菜单项的位置
|
||||
*/
|
||||
export const positionSelectedMenuItem = () => {
|
||||
// 获取 Sider 元素
|
||||
const siderEl = unrefElement(LAYOUT_SIDER_REF as Ref<HTMLElement>)
|
||||
// 获取激活的菜单项元素
|
||||
const scrollEl = siderEl?.querySelector<HTMLElement>(
|
||||
'.n-layout-scroll-container, .n-scrollbar-container',
|
||||
)
|
||||
const selectedEl =
|
||||
siderEl?.querySelector<HTMLElement>(MENU_ITEM_SELECTED) ||
|
||||
siderEl?.querySelector<HTMLElement>(MENU_COLLAPSED_ITEM_SELECTED)
|
||||
// 获取 Sider 栏 Logo 元素
|
||||
const siderBarLogoEl = unrefElement(SIDER_BAR_LOGO)
|
||||
// Sider 栏 Logo 高度
|
||||
let siderBarLogoHeight: number = 0
|
||||
// 获取菜单项元素
|
||||
const menuItemEl = siderEl?.querySelector<HTMLElement>(MENU_ITEM)
|
||||
|
||||
// 获取 Sider 栏 Logo 高度
|
||||
if (siderBarLogoEl) {
|
||||
const { height } = siderBarLogoEl.getBoundingClientRect()
|
||||
if (!selectedEl || !scrollEl) return
|
||||
|
||||
siderBarLogoHeight = height
|
||||
}
|
||||
const selectedRect = selectedEl.getBoundingClientRect()
|
||||
const scrollRect = scrollEl.getBoundingClientRect()
|
||||
|
||||
// 如果激活的菜单项元素和 Sider 元素存在,则滚动 Sider 栏
|
||||
if (selectedEl && siderEl) {
|
||||
// 获取元素相对于视口的位置信息
|
||||
const selectedRect = selectedEl.getBoundingClientRect()
|
||||
const siderRect = siderEl.getBoundingClientRect()
|
||||
if (
|
||||
selectedRect.top >= scrollRect.top &&
|
||||
selectedRect.bottom <= scrollRect.bottom
|
||||
)
|
||||
return
|
||||
|
||||
// 检查 selectedEl 是否在 sider 的可视区域内
|
||||
const isInViewport =
|
||||
selectedRect.top >= siderRect.top + siderBarLogoHeight &&
|
||||
selectedRect.bottom <= siderRect.bottom
|
||||
const menuItemEl = selectedEl.closest('.n-menu-item')
|
||||
const marginTop = menuItemEl
|
||||
? parseFloat(window.getComputedStyle(menuItemEl).marginTop) || 0
|
||||
: 0
|
||||
|
||||
// 如果不在可视区域内,才执行滚动
|
||||
if (!isInViewport) {
|
||||
// 获取 Sider 滚动条
|
||||
const siderScroll = useSiderScroll()
|
||||
// 获取 Sider 元素当前滚动条的位置
|
||||
const siderScrollTop = siderEl.scrollTop
|
||||
// 获取菜单项元素的 margin-top 值,如果菜单项元素不存在,则使用默认值 6(测试得出 6px 是最佳值)
|
||||
const menuItemMarginTop = menuItemEl
|
||||
? parseInt(window.getComputedStyle(menuItemEl).marginTop)
|
||||
: 6
|
||||
|
||||
siderScroll({
|
||||
// 滚动到激活的菜单项位置,减去 Sider 栏 Logo 高度和菜单项的 margin-top 值
|
||||
top:
|
||||
selectedRect.top -
|
||||
siderRect.top +
|
||||
siderScrollTop -
|
||||
siderBarLogoHeight -
|
||||
menuItemMarginTop,
|
||||
// 水平滚动到 0 位置
|
||||
left: 0,
|
||||
// 平滑滚动
|
||||
behavior: 'smooth',
|
||||
})
|
||||
}
|
||||
}
|
||||
useSiderScroll()({
|
||||
top: scrollEl.scrollTop + selectedRect.top - scrollRect.top - marginTop,
|
||||
left: 0,
|
||||
behavior: 'smooth',
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user