diff --git a/.zed/settings.json b/.zed/settings.json new file mode 100644 index 00000000..9f14ace2 --- /dev/null +++ b/.zed/settings.json @@ -0,0 +1,98 @@ +{ + "languages": { + "TypeScript": { + "formatter": "prettier", + "format_on_save": "on", + "language_servers": ["vtsls", "eslint", "!intl-lens", "..."] + }, + "TSX": { + "formatter": "prettier", + "format_on_save": "on", + "language_servers": ["vtsls", "eslint", "!intl-lens", "..."] + }, + "JavaScript": { + "formatter": "prettier", + "format_on_save": "on", + "language_servers": ["vtsls", "eslint", "!intl-lens", "..."] + }, + "JSX": { + "formatter": "prettier", + "format_on_save": "on", + "language_servers": ["vtsls", "eslint", "!intl-lens", "..."] + }, + "Vue.js": { + "formatter": "prettier", + "format_on_save": "on", + "language_servers": ["!intl-lens", "..."] + }, + "JSON": { + "formatter": "prettier", + "format_on_save": "on" + }, + "SCSS": { + "formatter": "prettier", + "format_on_save": "on" + }, + "CSS": { + "formatter": "prettier", + "format_on_save": "on" + }, + "HTML": { + "formatter": "prettier", + "format_on_save": "on", + "language_servers": ["!intl-lens", "..."] + }, + "Markdown": { + "formatter": "prettier", + "format_on_save": "on" + } + }, + "lsp": { + "cspell": { + "initialization_options": { + "defaultSettings": { + "words": [ + "baomitu", + "bezier", + "Cascader", + "Clickoutside", + "codabar", + "commitmsg", + "crossorigin", + "daterange", + "datetimerange", + "depcheckrc", + "domtoimage", + "echart", + "EDITMSG", + "ianvs", + "iife", + "internalkey", + "jsbarcode", + "linebreak", + "logicflow", + "macarons", + "menutag", + "ndata", + "persistedstate", + "pharmacode", + "Popselect", + "precommit", + "qrcode", + "rgba", + "sider", + "siderbar", + "snapline", + "stylelint", + "unocss", + "VITE", + "vitepress", + "vueuse", + "WUJIE", + "zlevel" + ] + } + } + } + } +} diff --git a/__test__/components/table-pro-search.spec.ts b/__test__/components/table-pro-search.spec.ts index 728564bb..e4f1c242 100644 --- a/__test__/components/table-pro-search.spec.ts +++ b/__test__/components/table-pro-search.spec.ts @@ -6,7 +6,7 @@ import type { TableProSearchOptions, } from '@ray-template/ui/table-pro' import { flushPromises, mount } from '@vue/test-utils' -import { NDataTable, NDatePicker, NSelect } from 'naive-ui' +import { NDataTable, NDatePicker, NGrid, NSelect } from 'naive-ui' import { defineComponent, h, nextTick, shallowRef } from 'vue' const columns = [{ key: 'name', title: 'Name' }] @@ -15,6 +15,69 @@ const statusOptions = [ { label: 'Closed', value: 'closed' }, ] +it('applies the latest measured search column count on the next frame', async () => { + let resizeSearch: ((width: number) => void) | undefined + + vi.useFakeTimers({ + toFake: ['requestAnimationFrame', 'cancelAnimationFrame'], + }) + vi.stubGlobal( + 'ResizeObserver', + class { + readonly callback: ResizeObserverCallback + + constructor(callback: ResizeObserverCallback) { + this.callback = callback + } + + observe(target: Element) { + if (target.matches('.r-table-search-shell')) + resizeSearch = (width) => + this.callback( + [ + { + target, + contentRect: new DOMRect(0, 0, width, 200), + } as ResizeObserverEntry, + ], + this, + ) + } + + disconnect() {} + unobserve() {} + }, + ) + + const wrapper = mount(RTablePro, { + props: { columns, search: { fields: [{ key: 'name', label: 'Name' }] } }, + }) + + try { + await nextTick() + const grid = wrapper.getComponent(NGrid) + + expect(resizeSearch).toBeTypeOf('function') + expect(grid.props('cols')).toBe(1) + + resizeSearch?.(864) + await nextTick() + expect(grid.props('cols')).toBe(1) + + resizeSearch?.(1310) + await nextTick() + expect(grid.props('cols')).toBe(1) + + vi.advanceTimersToNextFrame() + await nextTick() + expect(grid.props('cols')).toBe(3) + } finally { + wrapper.unmount() + vi.unstubAllGlobals() + vi.useRealTimers() + } +}) + it('labels compound picker triggers and both endpoints of a date range', async () => { const fields: TableProSearchOptions['fields'] = [ { key: 'created', type: 'dateRange', label: 'Created' }, diff --git a/__test__/layout/menu-tag.spec.tsx b/__test__/layout/menu-tag.spec.tsx index 82621bb7..d3c05591 100644 --- a/__test__/layout/menu-tag.spec.tsx +++ b/__test__/layout/menu-tag.spec.tsx @@ -2,7 +2,7 @@ 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 { NDropdown, NTag } from 'naive-ui' import { h, nextTick, ref } from 'vue' import type { Ref } from 'vue' import { createMemoryHistory, createRouter } from 'vue-router' @@ -11,6 +11,7 @@ import type { Router } from 'vue-router' const state = vi.hoisted(() => ({ tags: null as unknown as Ref, active: null as unknown as Ref, + round: null as unknown as Ref, close: vi.fn(), navigate: vi.fn(), })) @@ -38,6 +39,7 @@ vi.mock('@/store', () => ({ }), useMenuActions: () => ({ changeMenuModelValue: state.navigate }), useRuntimeGetters: () => ({ globalMainLayoutLoad: ref(true) }), + useSettingGetters: () => ({ getMenuTagRound: state.round }), })) let wrapper: VueWrapper @@ -55,6 +57,7 @@ beforeEach(async () => { })) as MenuTagOptions[], ) state.active = ref(state.tags.value[0]!) + state.round = ref(false) router = createRouter({ history: createMemoryHistory(), routes: [ @@ -69,7 +72,10 @@ beforeEach(async () => { attachTo: host, global: { plugins: [router], - mocks: { $t: (key: string) => key }, + mocks: { + $t: (key: string, params?: { name: string }) => + params ? `${key}:${params.name}` : key, + }, }, }) }) @@ -109,6 +115,74 @@ const openContextMenu = async (index: number) => { await flushPromises() } +it('closes with the named native tag button without selecting the page', async () => { + const closeButton = wrapper.get( + 'button.n-tag__close[aria-label="menuTag.closeNamed:Orders"]', + ) + + await closeButton.trigger('click', { detail: 1 }) + + expect(state.close).toHaveBeenCalledExactlyOnceWith(1) + expect(state.navigate).not.toHaveBeenCalled() +}) + +it('updates the native close label when the tag is renamed', async () => { + const closeButton = wrapper.get('.n-tag__close') + + expect(closeButton.attributes('aria-label')).toBe( + 'menuTag.closeNamed:Reports', + ) + state.tags.value[0]!.breadcrumbLabel = 'Summary' + await nextTick() + expect(closeButton.attributes('aria-label')).toBe( + 'menuTag.closeNamed:Summary', + ) +}) + +it.each(['button', 'Delete'])( + 'restores focus after closing by keyboard (%s)', + async (method) => { + state.close.mockImplementationOnce((index: number) => { + state.tags.value.splice(index, 1) + }) + const tab = wrapper.get('.menu-tag__tab[title="Orders"]') + const closeButton = wrapper.get( + 'button.n-tag__close[aria-label="menuTag.closeNamed:Orders"]', + ) + + if (method === 'Delete') { + tab.element.focus() + await tab.trigger('keydown', { key: 'Delete' }) + } else { + closeButton.element.focus() + await closeButton.trigger('click', { detail: 0 }) + } + + expect(state.close).toHaveBeenCalledExactlyOnceWith(1) + expect(state.navigate).not.toHaveBeenCalled() + expect(document.activeElement?.textContent).toBe('Users') + }, +) + +it('uses the native primary type only for the current page', async () => { + const tagTypes = () => + wrapper.findAllComponents(NTag).map((tag) => tag.props('type')) + + expect(tagTypes()).toEqual(['primary', 'default', 'default']) + state.active.value = state.tags.value[1]! + await nextTick() + expect(tagTypes()).toEqual(['default', 'primary', 'default']) +}) + +it('applies the native round style to open tags when the preference changes', async () => { + const tag = wrapper.get('.menu-tag__item') + + expect(tag.classes('n-tag--round')).toBe(false) + state.round.value = true + await nextTick() + expect(tag.classes('n-tag--round')).toBe(true) +}) + it('keeps the context menu open while repeatedly right-clicking other tags', async () => { for (const index of [0, 1, 2, 0]) { await openContextMenu(index) diff --git a/__test__/layout/preferences.spec.ts b/__test__/layout/preferences.spec.ts index 78ef21c8..3a53dee8 100644 --- a/__test__/layout/preferences.spec.ts +++ b/__test__/layout/preferences.spec.ts @@ -132,6 +132,7 @@ describe('layout preferences', () => { }) expect(store.localeLanguage).toBe('en-US') expect(store.menuTagSwitch).toBe(false) + expect(store.menuTagRound).toBe(false) expect(store.menuConfig).toMatchObject({ iconSize: 20, collapsedIconSize: 22, @@ -186,6 +187,7 @@ describe('layout preferences', () => { store.updateSettingState('layoutConfig', { mode: 'right' }) store.updateSettingState('appTheme', 'dark') store.updateSettingState('themeStyle', 'material') + store.updateSettingState('menuTagRound', true) store.updateSettingState('watermarkConfig', { content: 'Portable' }) store.updateSettingState('keepAliveConfig', { keepAliveExclude: ['Page'], @@ -195,6 +197,7 @@ describe('layout preferences', () => { store.updateSettingState('layoutConfig', { mode: 'top' }) store.updateSettingState('appTheme', 'light') + store.updateSettingState('menuTagRound', false) store.updateSettingState('appRootRoute', { path: '/custom-home' }) store.changePrimaryColor('#000000') store.updateSettingState('themeStyle', 'plain') @@ -202,6 +205,7 @@ describe('layout preferences', () => { await nextTick() expect(store.exportPreferences()).toEqual(file) + expect(store.menuTagRound).toBe(true) expect(store._appTheme).toBe(true) expect(store.themeOverrides.common?.primaryColor).toBe('#3468db') expect(store.themeOverrides.Card?.borderRadius).toBe('20px') @@ -216,6 +220,7 @@ describe('layout preferences', () => { layoutConfig: { mode: 'right' }, appTheme: 'dark', themeStyle: 'material', + menuTagRound: true, }) } finally { app.unmount() @@ -232,12 +237,18 @@ describe('layout preferences', () => { try { store.updateSettingState('themeStyle', 'material') + store.updateSettingState('menuTagRound', true) store.changePrimaryColor('#3468db') const { preferences, ...file } = store.exportPreferences() - const { themeStyle: _style, ...legacy } = preferences + const { + themeStyle: _style, + menuTagRound: _round, + ...legacy + } = preferences store.importPreferences(JSON.stringify({ ...file, preferences: legacy })) expect(store.themeStyle).toBe('modern') + expect(store.menuTagRound).toBe(false) expect(store.themeOverrides.Card?.borderRadius).toBe('12px') expect(store.themeOverrides.common?.primaryColor).toBe('#3468db') diff --git a/__test__/layout/workspace-settings.spec.tsx b/__test__/layout/workspace-settings.spec.tsx index b5ec0c36..7676a47c 100644 --- a/__test__/layout/workspace-settings.spec.tsx +++ b/__test__/layout/workspace-settings.spec.tsx @@ -133,17 +133,26 @@ describe('workspace preference shortcuts', () => { .trigger('click') try { + const pillToggle = wrapper.get( + '[role="switch"][aria-label="preferences.appearance.menuTagRound"]', + ) + + expect(pillToggle.attributes('aria-checked')).toBe('false') + await pillToggle.trigger('click') + expect(store.menuTagRound).toBe(true) await click('appearance.minimal') expect([ store.breadcrumbSwitch, store.menuTagSwitch, store.copyrightSwitch, ]).toEqual([false, false, false]) + expect(store.menuTagRound).toBe(true) await click('appearance.reset') expect(store.contentTransition).toBe( getDefaultSettingConfig().contentTransition, ) expect(store.menuTagSwitch).toBe(getDefaultSettingConfig().menuTagSwitch) + expect(store.menuTagRound).toBe(false) expect(store.themeStyle).toBe(getDefaultSettingConfig().themeStyle) expect(store.primaryColorOverride).toEqual({}) expect(store.appTheme).toBe('auto') diff --git a/apps/admin/src/layout/components/Menu/index.tsx b/apps/admin/src/layout/components/Menu/index.tsx index bf903742..5aa7d434 100644 --- a/apps/admin/src/layout/components/Menu/index.tsx +++ b/apps/admin/src/layout/components/Menu/index.tsx @@ -17,6 +17,8 @@ import type { MenuInst } from 'naive-ui' import type { PropType } from 'vue' import SiderBarLogo from './components/SiderBarLogo' +const triggerStyle = { top: 'max(24px, calc(50% - 240px))' } + export default defineComponent({ name: 'AppMenu', props: { @@ -72,6 +74,8 @@ export default defineComponent({ class={['app-menu__sider', { 'app-menu__sider--end': props.end }]} {...{ inert: props.inert }} showTrigger={!isTabletOrSmaller.value} + triggerStyle={triggerStyle} + collapsedTriggerStyle={triggerStyle} collapseMode={getMenuConfig.value.collapsedMode} collapsedWidth={getMenuConfig.value.collapsedWidth} onUpdateCollapsed={collapsedMenu} diff --git a/apps/admin/src/layout/components/MenuTag/index.tsx b/apps/admin/src/layout/components/MenuTag/index.tsx index cd368c2a..0f0c20a7 100644 --- a/apps/admin/src/layout/components/MenuTag/index.tsx +++ b/apps/admin/src/layout/components/MenuTag/index.tsx @@ -1,7 +1,12 @@ import './index.scss' import { useI18n, useMaximize, useSiderBar, useSpinning } from '@/hooks' import { FORBIDDEN_ROUTE_PATH } from '@/router/constant' -import { useMenuActions, useMenuGetters, useRuntimeGetters } from '@/store' +import { + useMenuActions, + useMenuGetters, + useRuntimeGetters, + useSettingGetters, +} from '@/store' import type { AppMenuOption, MenuTagOptions } from '@/types' import { ShellTab } from '@ray-template/admin-shell' import { RIcon } from '@ray-template/ui/icon' @@ -29,6 +34,7 @@ export default defineComponent({ const showingForbidden = computed(() => route.path === FORBIDDEN_ROUTE_PATH) const { t } = useI18n('menuTag') const { getCurrentMenuOption, getMenuTagOptions } = useMenuGetters() + const { getMenuTagRound } = useSettingGetters() const getMenuKey = computed( () => getCurrentMenuOption.value?.fullPath ?? null, ) @@ -305,7 +311,12 @@ export default defineComponent({ } watch( - [getMenuKey, () => getMenuTagOptions.value.length, tagsRef], + [ + getMenuKey, + () => getMenuTagOptions.value.length, + getMenuTagRound, + tagsRef, + ], positionMenuTag, { flush: 'post' }, ) @@ -314,6 +325,7 @@ export default defineComponent({ return { getMenuTagOptions, + getMenuTagRound, canClose, closeCurrentMenuTag, getMenuKey, @@ -407,6 +419,7 @@ export default defineComponent({ key={curr.fullPath} label={label} active={active} + round={this.getMenuTagRound} select={() => menuTagClick(curr)} closeLabel={$t('menuTag.closeNamed', { name: label })} close={ diff --git a/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/segment-views/Appearance.tsx b/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/segment-views/Appearance.tsx index 1f0c8db7..e69a2489 100644 --- a/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/segment-views/Appearance.tsx +++ b/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/segment-views/Appearance.tsx @@ -38,6 +38,7 @@ export default defineComponent({ getDrawerPlacement, getContentTransition, getMenuTagSwitch, + getMenuTagRound, getBreadcrumbSwitch, getCopyrightSwitch, getColorWeakness, @@ -79,6 +80,7 @@ export default defineComponent({ const switches = [ ['breadcrumbSwitch', getBreadcrumbSwitch], ['menuTagSwitch', getMenuTagSwitch], + ['menuTagRound', getMenuTagRound], ['copyrightSwitch', getCopyrightSwitch], ['colorWeakness', getColorWeakness], ] as const diff --git a/apps/admin/src/locales/lang/en-US/preferences.json b/apps/admin/src/locales/lang/en-US/preferences.json index b80fd8a5..2a357487 100644 --- a/apps/admin/src/locales/lang/en-US/preferences.json +++ b/apps/admin/src/locales/lang/en-US/preferences.json @@ -43,6 +43,7 @@ "display": "Interface display", "breadcrumbSwitch": "Breadcrumbs", "menuTagSwitch": "Page tabs", + "menuTagRound": "Pill-shaped page tabs", "copyrightSwitch": "Footer", "colorWeakness": "Color vision mode", "displayHint": "Show or hide breadcrumbs, page tabs, and the footer together, or adjust each below.", diff --git a/apps/admin/src/locales/lang/zh-CN/preferences.json b/apps/admin/src/locales/lang/zh-CN/preferences.json index dd456bf5..f0b30ebe 100644 --- a/apps/admin/src/locales/lang/zh-CN/preferences.json +++ b/apps/admin/src/locales/lang/zh-CN/preferences.json @@ -43,6 +43,7 @@ "display": "界面显示", "breadcrumbSwitch": "面包屑导航", "menuTagSwitch": "页面标签", + "menuTagRound": "胶囊形页面标签", "copyrightSwitch": "页脚信息", "colorWeakness": "色弱模式", "displayHint": "批量调整面包屑、页面标签和页脚,也可继续逐项设置。", diff --git a/apps/admin/src/store/hooks/useSettingStore.ts b/apps/admin/src/store/hooks/useSettingStore.ts index 2ca5e98f..7087029a 100644 --- a/apps/admin/src/store/hooks/useSettingStore.ts +++ b/apps/admin/src/store/hooks/useSettingStore.ts @@ -38,6 +38,7 @@ export const useSettingGetters = () => { * 获取菜单标签开关。 */ const getMenuTagSwitch = computed(() => variable.menuTagSwitch) + const getMenuTagRound = computed(() => variable.menuTagRound) /** * * @description @@ -132,6 +133,7 @@ export const useSettingGetters = () => { getThemeStyle, getAppTheme, getMenuTagSwitch, + getMenuTagRound, getBreadcrumbSwitch, getLocaleLanguage, getLockScreenSwitch, diff --git a/apps/admin/src/store/modules/setting/constant.ts b/apps/admin/src/store/modules/setting/constant.ts index 6330c6d9..b274ab6b 100644 --- a/apps/admin/src/store/modules/setting/constant.ts +++ b/apps/admin/src/store/modules/setting/constant.ts @@ -10,6 +10,7 @@ type OmitKeys = | 'keepAliveConfig' | 'menuConfig' | 'menuTagSwitch' + | 'menuTagRound' | 'breadcrumbSwitch' | 'copyrightSwitch' | 'drawerPlacement' @@ -57,6 +58,7 @@ const defaultSettingConfig: Readonly = { }, // 多标签页开关 menuTagSwitch: true, + menuTagRound: false, // 面包屑开关 breadcrumbSwitch: true, // 底部区域开关 diff --git a/apps/admin/src/store/modules/setting/preference-file.ts b/apps/admin/src/store/modules/setting/preference-file.ts index 1480fd3e..6a179131 100644 --- a/apps/admin/src/store/modules/setting/preference-file.ts +++ b/apps/admin/src/store/modules/setting/preference-file.ts @@ -62,6 +62,7 @@ const preferences = v.strictObject({ drawerPlacement: v.picklist(['left', 'right']), breadcrumbSwitch: flag, menuTagSwitch: flag, + menuTagRound: v.optional(flag, false), copyrightSwitch: flag, colorWeakness: flag, menuConfig: v.strictObject({ diff --git a/apps/admin/src/store/modules/setting/types.ts b/apps/admin/src/store/modules/setting/types.ts index 9092f43c..4152c24c 100644 --- a/apps/admin/src/store/modules/setting/types.ts +++ b/apps/admin/src/store/modules/setting/types.ts @@ -37,6 +37,7 @@ export interface SettingState { appTheme: 'dark' | 'light' | 'auto' _appTheme: boolean menuTagSwitch: boolean + menuTagRound: boolean breadcrumbSwitch: boolean localeLanguage: string lockScreenSwitch: boolean diff --git a/apps/docs/guide/appearance.md b/apps/docs/guide/appearance.md index e1c565fe..d3fe9781 100644 --- a/apps/docs/guide/appearance.md +++ b/apps/docs/guide/appearance.md @@ -135,6 +135,8 @@ TSX 使用相同的 class 和 CSS,样式放在组件旁并从入口 `import '. 修改 Naive 控件优先用 props、插槽或 `themeOverrides`;必要的内部选择器必须限定在自己的组件 class 下。检查实际受影响的风格、明暗模式和窄屏,不必为纯文档修改重跑整站视觉矩阵。 +大屏页面确需按设计稿等比缩放时,在根目录 `postcss.config.cjs` 的 `viewportIncludeFiles` 中加入目标样式的路径规则,例如 `[/[/\\]large-screen[/\\]/]`。留空时不启用 `postcss-px-conversion`。启用后,匹配的后台样式以 `1920px` 为基准换算成 `vw`,不转换第三方依赖、`.ignore` 选择器及媒体查询或容器查询中的样式。 + ## 中英文同时维护 把页面文案放进 `apps/admin/src/locales/lang/zh-CN` 和 `apps/admin/src/locales/lang/en-US` 的对应 JSON;同一语言内的命名空间要唯一。新增语言时同时补 `apps/admin/src/locales/lang/.ts` 与应用的语言配置。 diff --git a/apps/docs/guide/layout.md b/apps/docs/guide/layout.md index 508362b0..486a896c 100644 --- a/apps/docs/guide/layout.md +++ b/apps/docs/guide/layout.md @@ -39,6 +39,8 @@ updateSettingState('layoutConfig', { 外观页可批量显示或隐藏面包屑、页面标签和页脚,页面切换动画在「窗口与动效」中选择。各效果进入用时 240ms,退出用时 190ms,完整退出后再进入,并保留小幅位移和缩放。系统偏好减少动态效果时直接切换。恢复外观默认只重置外观选项,保留当前明暗模式。水印页提供疏朗、紧凑和水平预设、独立局部预览,以及应用标题和账户昵称快捷填入;无需开启全屏水印即可调试样式,预设保留已有文本和显隐状态。各模块的恢复按钮只作用于对应模块。 +在「偏好设置 → 外观 → 界面显示」开启「胶囊形页面标签」可切换标签形状。默认关闭;刷新后保留,也可随偏好文件导出和导入。 + ## 菜单图标 展开侧栏、移动端抽屉和顶部导航默认使用 20 px 的图标;折叠侧栏默认 22 px,方便只凭图形辨认菜单。线性图标跟随菜单状态和明暗主题变色。可在「偏好设置 → 菜单」调整「图标尺寸」与「折叠图标尺寸」,修改即时生效。紧凑和舒适预设只调整宽度、缩进和图标尺寸;折叠方式、侧栏折叠/展开、回到菜单顶部和刷新菜单也可直接操作。当前布局没有桌面侧栏时,侧栏快捷操作禁用,已配置的尺寸仍会保留。 diff --git a/package.json b/package.json index 1889e21c..d4b09103 100644 --- a/package.json +++ b/package.json @@ -124,7 +124,7 @@ "husky": "9.1.7", "lint-staged": "17.6.0", "postcss": "8.5.32", - "postcss-px-to-viewport-8-with-include": "1.2.2", + "postcss-px-conversion": "1.0.0", "prettier": "3.9.10", "rollup-plugin-gzip": "4.2.1", "sass": "1.107.1", diff --git a/packages/admin-shell/src/ShellTab.tsx b/packages/admin-shell/src/ShellTab.tsx index de079f43..2d8aa2b5 100644 --- a/packages/admin-shell/src/ShellTab.tsx +++ b/packages/admin-shell/src/ShellTab.tsx @@ -1,13 +1,14 @@ import './Tabs.scss' -import { RIcon } from '@ray-template/ui/icon' +import { NTag } from 'naive-ui' import { defineComponent } from 'vue' -import type { PropType } from 'vue' +import type { PropType, VNode } from 'vue' export const ShellTab = defineComponent({ name: 'ShellTab', props: { label: { type: String, required: true }, active: Boolean, + round: Boolean, closeLabel: { type: String, default: '' }, select: { type: Function as PropType<() => void>, required: true }, close: { @@ -20,17 +21,36 @@ export const ShellTab = defineComponent({ }, }, setup(props) { + const setNativeCloseLabel = ({ el }: VNode) => { + if (!(el instanceof HTMLElement)) return + + el.querySelector('.n-tag__close')?.setAttribute( + 'aria-label', + props.closeLabel || 'close', + ) + } + return () => ( -
props.close?.(event.detail === 0)} > - {props.close ? ( - - ) : null} -
+ ) }, }) diff --git a/packages/admin-shell/src/Tabs.scss b/packages/admin-shell/src/Tabs.scss index 224eca24..08922252 100644 --- a/packages/admin-shell/src/Tabs.scss +++ b/packages/admin-shell/src/Tabs.scss @@ -24,41 +24,35 @@ } .menu-tag__item { - display: inline-flex; flex: none; - align-items: center; - min-height: 28px; - overflow: hidden; - border: 1px solid transparent; - border-radius: var(--r-control-radius); - background: var(--r-surface-muted); - color: var(--r-text-secondary); &:hover { - background: var(--r-surface-hover); + cursor: pointer; } - &--active { - border-color: color-mix( - in srgb, - var(--r-theme-primary-color) 28%, - var(--r-line) - ); - background: color-mix( - in srgb, - var(--r-theme-primary-color) 11%, - var(--r-surface) - ); - color: var(--r-selected-text); + .n-tag__close { + flex: none; + min-inline-size: 24px; + min-block-size: 24px; + + &:focus-visible { + outline: 2px solid var(--r-theme-primary-color); + outline-offset: -2px; + } } } -.menu-tag__tab, -.menu-tag__close { +.menu-tag__tab { + max-inline-size: clamp(7rem, 24vw, 14rem); + min-block-size: 28px; + padding: 0; + overflow: hidden; border: 0; background: transparent; color: inherit; font: inherit; + text-overflow: ellipsis; + white-space: nowrap; cursor: pointer; &:focus-visible { @@ -66,62 +60,9 @@ } } -.menu-tag__tab { - max-inline-size: clamp(7rem, 24vw, 14rem); - min-height: 28px; - padding-inline: 10px; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - font-size: 13px; -} - -.menu-tag__item:has(> .menu-tag__close) > .menu-tag__tab { - padding-inline-end: 2px; -} - -.menu-tag__close { - position: relative; - isolation: isolate; - display: grid; - flex: none; - place-items: center; - inline-size: 26px; - block-size: 26px; - padding: 0; - overflow: hidden; - border-radius: var(--r-control-radius); - - &::before { - content: ''; - position: absolute; - z-index: -1; - inset: 3px; - border-radius: var(--r-control-radius); - background: currentColor; - opacity: 0; - transition: - opacity 120ms ease, - transform 120ms var(--r-bezier); - } - - &:is(:hover, :active) { - color: var(--r-text); - } - - &:hover::before { - opacity: 0.14; - } - - &:active::before { - opacity: 0.24; - transform: scale(0.88); - } -} - @media (hover: none) { - .menu-tag__close { - inline-size: 32px; + .menu-tag__item .n-tag__close { + min-inline-size: 32px; } } @@ -188,15 +129,9 @@ opacity: 1; } - .menu-tag__item--active { + .menu-tag__item--active .n-tag__border { border-color: Highlight; } - - .menu-tag__close:is(:hover, :active)::before { - border: 1px solid ButtonText; - background: transparent; - opacity: 1; - } } @media (prefers-reduced-motion: reduce) { @@ -204,7 +139,8 @@ animation: none; } - .menu-tag__close::before { + .menu-tag__item, + .menu-tag__item :is(.n-tag__close, .n-tag__border) { transition: none; } } diff --git a/packages/ui/src/RTablePro/src/components/Search.tsx b/packages/ui/src/RTablePro/src/components/Search.tsx index 81722354..7a626ee6 100644 --- a/packages/ui/src/RTablePro/src/components/Search.tsx +++ b/packages/ui/src/RTablePro/src/components/Search.tsx @@ -1,4 +1,4 @@ -import { useElementSize } from '@vueuse/core' +import { useElementSize, useRafFn } from '@vueuse/core' import { NButton, NForm, NFormItem, NGrid, NGridItem } from 'naive-ui' import type { FormInst } from 'naive-ui' import { @@ -8,6 +8,7 @@ import { ref, useId, useTemplateRef, + watch, } from 'vue' import type { PropType, VNode } from 'vue' import { useTableLocale } from '../locale' @@ -67,7 +68,7 @@ export default defineComponent({ const form = useTemplateRef('form') const { width } = useElementSize(wrapper) const collapsed = ref(props.options?.defaultCollapsed ?? false) - const columns = computed(() => + const measuredColumns = computed(() => Math.min( gridSize(props.options?.maxColumns, 4), width.value >= 1320 @@ -79,6 +80,16 @@ export default defineComponent({ : 1, ), ) + const columns = ref(measuredColumns.value) + const { resume: scheduleColumnUpdate } = useRafFn( + () => { + columns.value = measuredColumns.value + }, + { immediate: false, once: true }, + ) + + watch(measuredColumns, scheduleColumnUpdate) + const collapsedRows = computed(() => gridSize(props.options?.collapsedRows, 1), ) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c0bb96d5..e533ac7c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -353,9 +353,9 @@ importers: postcss: specifier: 8.5.32 version: 8.5.32 - postcss-px-to-viewport-8-with-include: - specifier: 1.2.2 - version: 1.2.2 + postcss-px-conversion: + specifier: 1.0.0 + version: 1.0.0(postcss@8.5.32) prettier: specifier: 3.9.10 version: 3.9.10 @@ -4752,8 +4752,11 @@ packages: pkg-types@2.4.0: resolution: {integrity: sha512-07Fys7iVx0X6TcviMOgogM1Lk33ZyqOezMnU79S+kffWqwolG/5W9V8EgQSeYCIfFTYVgssRbnH630Oa2+soBA==} - postcss-px-to-viewport-8-with-include@1.2.2: - resolution: {integrity: sha512-UFegTU9a1IsLsst+qpqH2uEBBlGB5NRFVouaj4ci9HJcCdpBDdhLPf4Z7rtXfMrFfi2MUQTpJu9xjfmz9S07Tg==} + postcss-px-conversion@1.0.0: + resolution: {integrity: sha512-/vicAqWK/4IzfjVstRcnkVBf+915wBDqYDqEvJAe/S1LIbY9jWvR5UUv8qejH9qBXZI6qVsW78+FWlFCQXiOSQ==} + engines: {node: '>=16'} + peerDependencies: + postcss: ^8.0.0 postcss-selector-parser@7.1.7: resolution: {integrity: sha512-wWBro/7hJ40ye6TPiXkUQoXKCw23xSsjriUvqd7Uls9Sso3oLiON1flc18cCdnjgCRXw4fBVqUJJeOdDTh3P3g==} @@ -9682,9 +9685,9 @@ snapshots: exsolve: 1.2.0 pathe: 2.0.3 - postcss-px-to-viewport-8-with-include@1.2.2: + postcss-px-conversion@1.0.0(postcss@8.5.32): dependencies: - object-assign: 4.1.1 + postcss: 8.5.32 postcss-selector-parser@7.1.7: dependencies: diff --git a/postcss.config.cjs b/postcss.config.cjs index f885d73a..68a6860c 100644 --- a/postcss.config.cjs +++ b/postcss.config.cjs @@ -1,3 +1,5 @@ +const viewportIncludeFiles = [] + module.exports = { plugins: { autoprefixer: { @@ -9,28 +11,17 @@ module.exports = { 'iOS >= 16.4', ], }, - // 为了适配 postcss8.x 版本的转换库 - 'postcss-px-to-viewport-8-with-include': { - // 横屏时使用的视口宽度 - landscapeWidth: 1920, - // 视窗的宽度(设计稿的宽度) + 'postcss-px-conversion': viewportIncludeFiles.length > 0 && { viewportWidth: 1920, - // 指定 px 转换为视窗单位值的小数位数 unitPrecision: 3, - // 指定需要转换成的视窗单位 viewportUnit: 'vw', - // 制定字体转换单位 fontViewportUnit: 'vw', - // 指定不转换为视窗单位的类 - selectorBlackList: ['.ignore'], - // 小于或等于 1px 不转换为视窗单位 + selectorBlacklist: ['.ignore'], minPixelValue: 1, - // 允许在媒体查询中转换 px - mediaQuery: false, - // 忽略某些文件夹下的文件或特定文件,例如 'node_modules' 下的文件 - exclude: /node_modules/, - // 指定一个空的文件夹,避免影响到无需转换的文件 - include: [], + allowMediaQuery: false, + enablePerFileConfig: false, + includeFiles: viewportIncludeFiles, + excludeFiles: [/[/\\]node_modules[/\\]/], }, }, }