diff --git a/README.md b/README.md index 2fd3df65..09b8cc81 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ Ray Template is an open-source frontend template for admin dashboards, operation [![The complete Ray Admin welcome page in the default Modern light style with side navigation](docs/assets/readme/welcome-modern-light.png)](https://xiaodaigua-ray.github.io/ray-template/#/dashboard) -[![The complete Ray Admin welcome page in the default Modern light style with side navigation](docs/assets/readme/table-modern-light.png)](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height) +[![TablePro with automatic height, search, pagination, and toolbar actions in Modern light mode](docs/assets/readme/table-modern-light.png)](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height) -_The complete welcome page · Default Modern style · Light mode._ +_Welcome page and TablePro · Default Modern style · Light mode._ ## Choose your look and layout @@ -29,9 +29,9 @@ Styles cover the shell, controls, tables, and chart themes. Each supports light ![The complete Ray Admin welcome page in Modern dark mode, using the same layout as the light version](docs/assets/readme/welcome-modern-dark.png) -[![The complete Ray Admin welcome page in the default Modern light style with side navigation](docs/assets/readme/table-modern-dark.png)](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height) +[![TablePro with automatic height, search, pagination, and toolbar actions in Modern dark mode](docs/assets/readme/table-modern-dark.png)](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height) -_The same welcome page in Modern dark mode._ +_The same welcome page and TablePro in Modern dark mode._ ### Five ways to organize the workspace @@ -142,7 +142,7 @@ Default deployment paths are `/ray-template/` for the admin and `/ray-template/d **v6 introduces the monorepo architecture.** It does not provide an in-place upgrade from v5 or guarantee compatibility with v5 imports, APIs, deployment settings, or browser data. -Existing projects can stay on [legacy/v5](https://github.com/XiaoDaiGua-Ray/ray-template/tree/legacy/v5), the final v5 main snapshot `6f095b7` with manifest version `5.2.5`, or use the [v5.2.4 tag](https://github.com/XiaoDaiGua-Ray/ray-template/tree/v5.2.4). Read the [migration notes](apps/docs/migration.md) before adopting v6. +Existing projects can stay on [legacy/v5](https://github.com/XiaoDaiGua-Ray/ray-template/tree/legacy/v5), the final v5 main snapshot `6f095b7` with manifest version `5.2.5`, or use the matching [v5.2.5 tag](https://github.com/XiaoDaiGua-Ray/ray-template/tree/v5.2.5). Read the [migration notes](apps/docs/migration.md) before adopting v6. --- diff --git a/README.zh-CN.md b/README.zh-CN.md index 026f8af6..5078b7b5 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -10,9 +10,9 @@ Ray Template 是基于 Vue 3、TypeScript / TSX 和 Naive UI 的开源中后台 [![默认 Modern 浅色风格的完整欢迎页,展示侧边导航和工作空间概览](docs/assets/readme/welcome-modern-light.png)](https://xiaodaigua-ray.github.io/ray-template/#/dashboard) -[![The complete Ray Admin welcome page in the default Modern light style with side navigation](docs/assets/readme/table-modern-light.png)](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height) +[![Modern 浅色主题下的 TablePro,展示自适应高度、搜索、分页与工具栏操作](docs/assets/readme/table-modern-light.png)](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height) -_完整欢迎页 · 默认 Modern 风格 · 浅色主题。_ +_欢迎页与 TablePro · 默认 Modern 风格 · 浅色主题。_ ## 风格与布局 @@ -29,9 +29,9 @@ _完整欢迎页 · 默认 Modern 风格 · 浅色主题。_ ![Modern 深色主题下的完整欢迎页,与浅色版本使用相同布局](docs/assets/readme/welcome-modern-dark.png) -[![The complete Ray Admin welcome page in the default Modern light style with side navigation](docs/assets/readme/table-modern-dark.png)](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height) +[![Modern 深色主题下的 TablePro,展示自适应高度、搜索、分页与工具栏操作](docs/assets/readme/table-modern-dark.png)](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height) -_相同的欢迎页与布局,切换至 Modern 深色主题。_ +_相同的欢迎页与 TablePro,切换至 Modern 深色主题。_ ### 五种导航,适配不同工作方式 @@ -142,7 +142,7 @@ CI 配置覆盖 **Linux、Windows 和 macOS**。[任务索引](llms.txt)与 [AI **v6 启用 Monorepo 架构。** 不提供 v5 原地升级,也不保证兼容 v5 的内部导入、接口、部署配置或浏览器数据。 -已有项目可以继续使用 [legacy/v5](https://github.com/XiaoDaiGua-Ray/ray-template/tree/legacy/v5)(最后的 v5 主线快照 `6f095b7`,清单版本 `5.2.5`),或使用 [v5.2.4 标签](https://github.com/XiaoDaiGua-Ray/ray-template/tree/v5.2.4)。采用 v6 前请先阅读[迁移说明](apps/docs/migration.md)。 +已有项目可以继续使用 [legacy/v5](https://github.com/XiaoDaiGua-Ray/ray-template/tree/legacy/v5)(最后的 v5 主线快照 `6f095b7`,清单版本 `5.2.5`),或使用对应的 [v5.2.5 标签](https://github.com/XiaoDaiGua-Ray/ray-template/tree/v5.2.5)。采用 v6 前请先阅读[迁移说明](apps/docs/migration.md)。 --- diff --git a/__test__/components/table-pro-toolbar.spec.tsx b/__test__/components/table-pro-toolbar.spec.tsx index 6e1e1e35..47c72c7b 100644 --- a/__test__/components/table-pro-toolbar.spec.tsx +++ b/__test__/components/table-pro-toolbar.spec.tsx @@ -1,5 +1,6 @@ -import { flushPromises, mount } from '@vue/test-utils' +import { DOMWrapper, flushPromises, mount } from '@vue/test-utils' import { NDataTable, NDropdown } from 'naive-ui' +import type { DropdownOption } from 'naive-ui' import { RTablePro } from '../../packages/ui/src/RTablePro' import type { TableProRequest } from '../../packages/ui/src/RTablePro' import * as csv from '../../packages/ui/src/RTablePro/src/csv' @@ -10,6 +11,31 @@ const data = [{ id: 1, name: 'Ray' }] afterEach(() => vi.restoreAllMocks()) +it.each([void 0, 'small', 'medium', 'large'] as const)( + 'checks the effective density before any interaction when size is %s', + (size) => { + const wrapper = mount(RTablePro, { props: { columns, data, size } }) + + try { + const density = wrapper + .getComponent(NDropdown) + .props('options') + ?.find((option) => option.key === 'density') as DropdownOption + const choices = density.children as DropdownOption[] + const expected = size ?? 'medium' + + expect(wrapper.getComponent(NDataTable).props('size')).toBe(expected) + expect( + choices + .filter((option) => option.props?.['aria-checked']) + .map((option) => option.key), + ).toEqual([`density:${expected}`]) + } finally { + wrapper.unmount() + } + }, +) + it('hides print by default and groups secondary actions under one menu', async () => { const wrapper = mount(RTablePro, { props: { columns, data } }) @@ -100,6 +126,80 @@ it('updates density and appearance without changing caller defaults', async () = }) await wrapper.setProps({ size: 'large' }) expect(wrapper.getComponent(NDataTable).props('size')).toBe('large') + await wrapper.setProps({ size: void 0 }) + expect(wrapper.getComponent(NDataTable).props('size')).toBe('medium') + const density = menu + .props('options') + ?.find((option) => option.key === 'density') as DropdownOption + + expect( + (density.children as DropdownOption[]) + .filter((option) => option.props?.['aria-checked']) + .map((option) => option.key), + ).toEqual(['density:medium']) + } finally { + wrapper.unmount() + } +}) + +it('keeps appearance icons visible when checked or unchecked', async () => { + const wrapper = mount(RTablePro, { + props: { + columns, + data, + size: 'medium', + striped: false, + bordered: true, + showPrint: true, + }, + }) + const page = new DOMWrapper(document.body) + const openMenu = async () => { + await wrapper.get('[aria-label="More actions"]').trigger('click') + await vi.dynamicImportSettled() + await flushPromises() + } + const appearanceOption = (label: string) => + page + .findAll('[role="menuitemcheckbox"]') + .find((option) => option.text().includes(label))! + + try { + await openMenu() + + for (const label of ['Table density', 'Export CSV', 'Print table']) { + const option = page + .findAll('.n-dropdown-option-body') + .find((option) => option.text().includes(label))! + + expect(option.get('svg').html()).toContain(' ( 实例还提供 `setPage`、`setPageSize`、`getCurrentPageData`、`downloadCsv`、`print`、`copyImage` 和 `getTableInstance`。扩展表格区域可用 `title`、`toolbar`、`tableFooter`、`tableAction`;错误区域用 `error` 插槽。 -工具栏分为业务操作与内置工具两组。`request` 模式提供刷新,列设置、复制图片和全屏为直接入口;密度、斑马纹、边框和 CSV 收入「更多操作」。打印默认不显示,设置 `showPrint` 后才加入菜单。`tool={false}` 隐藏内置工具,保留自定义 `toolbar` 插槽。 +工具栏分为业务操作与内置工具两组。`request` 模式提供刷新,列设置、复制图片和全屏为直接入口;密度、斑马纹、边框和 CSV 收入「更多操作」。斑马纹和边框的功能图标始终显示,选中状态在文字右侧单独标记;密度子菜单只保留文字和选中标记。TablePro 的 `size` 默认是 `medium`(标准),菜单与表格共用该值;传入 `small` 或 `large` 时分别选中紧凑或宽松。打印默认不显示,设置 `showPrint` 后才加入菜单。`tool={false}` 隐藏内置工具,保留自定义 `toolbar` 插槽。 ### `useTablePro` diff --git a/packages/icons/ICON-SOURCES.md b/packages/icons/ICON-SOURCES.md index e612c590..e7d57c26 100644 --- a/packages/icons/ICON-SOURCES.md +++ b/packages/icons/ICON-SOURCES.md @@ -2,7 +2,7 @@ 操作、方向、导航、状态和系统图标来自 [Iconfont · 迈鼎icon](https://www.iconfont.cn/collections/detail?cid=51731) 的 IconPark 线性图形。原作者为 [ByteDance IconPark](https://github.com/bytedance/IconPark),Copyright 2019-present Bytedance Inc.;开源许可见 [Apache 2.0](LICENSE-ICONPARK)。表内 ID 对应该合辑的具体条目。入包时保留原始绘制路径,去掉透明画布路径和导出属性。按实际图形边界重设正方形视图框,让常规图标的主体约占八成半;省略号和展开箭头保留更多留白。轮廓补少量描边,使小尺寸下的线条更清楚,填充和描边均使用 `currentColor`。 -`action/close_all` 是本仓库绘制的叠页关闭图标。 +The `action/close_all`, `action/table-striped`, and `action/table-bordered` icons are original artwork in this repository, covered by its MIT license. 品牌标识沿用仓库已有的 SVG。不要将品牌标识与这批通用线性图标的来源或许可混用。 diff --git a/packages/icons/src/action/table-bordered.svg b/packages/icons/src/action/table-bordered.svg new file mode 100644 index 00000000..1b92360c --- /dev/null +++ b/packages/icons/src/action/table-bordered.svg @@ -0,0 +1,3 @@ + + + diff --git a/packages/icons/src/action/table-striped.svg b/packages/icons/src/action/table-striped.svg new file mode 100644 index 00000000..00ec8c83 --- /dev/null +++ b/packages/icons/src/action/table-striped.svg @@ -0,0 +1,4 @@ + + + + diff --git a/packages/icons/src/manifest.ts b/packages/icons/src/manifest.ts index a1756485..afd57ec2 100644 --- a/packages/icons/src/manifest.ts +++ b/packages/icons/src/manifest.ts @@ -27,6 +27,8 @@ export const iconNames = [ 'action/search', 'action/setting', 'action/shared', + 'action/table-bordered', + 'action/table-striped', 'action/upload', 'directional/enter', 'directional/expanded', diff --git a/packages/ui/src/RTablePro/README.md b/packages/ui/src/RTablePro/README.md index 09aac4f9..e7bf9fb0 100644 --- a/packages/ui/src/RTablePro/README.md +++ b/packages/ui/src/RTablePro/README.md @@ -27,7 +27,7 @@ import { RTablePro } from '@/components' - `autoHeight` 默认使用当前布局的可用高度,宿主外部使用视口高度;嵌入特定区域时可以用 CSS 变量 `--r-table-height` 覆盖。较短的屏幕保留表格的最小操作高度。 - 只接收最新的请求结果。切换请求源或有效筛选条件会立即清空旧行和总数;切页或修改每页条数会隐藏旧行并保留同一范围的总数。当前页未加载时,实例取数返回空、底层实例返回 `null`,CSV 和打印不会启动。请求失败后显示空态并清空总数,通过宿主 Toast 提醒。可用 `onRequestError` 接收详情、用实例 `reload()` 重试,或显式提供 `error` 插槽接管提示。 - 需要实例时使用 `shallowRef()`。实例提供 `reload(resetPage?)`、`setPage`、`setPageSize`、`getCurrentPageData`、`downloadCsv`、`print`、`copyImage` 和 `getTableInstance`。额外区域可用 `toolbar`、`tableFooter`、`tableAction` 插槽。 -- 工具栏将业务 `toolbar` 插槽与内置工具分组。`request` 模式提供刷新,列设置、复制图片和全屏保持直接入口;「更多操作」统一收纳密度、斑马纹、边框与 CSV。打印默认隐藏,设置 `showPrint` 后出现在该菜单。`tool={false}` 隐藏全部内置工具,仍保留业务插槽。 +- 工具栏将业务 `toolbar` 插槽与内置工具分组。`request` 模式提供刷新,列设置、复制图片和全屏保持直接入口;「更多操作」统一收纳密度、斑马纹、边框与 CSV。斑马纹和边框的功能图标始终显示,选中状态在文字右侧单独标记;密度子菜单只保留文字和选中标记。TablePro 的 `size` 默认是 `medium`(标准),菜单与表格共用该值;传入 `small` 或 `large` 时分别选中紧凑或宽松。打印默认隐藏,设置 `showPrint` 后出现在该菜单。`tool={false}` 隐藏全部内置工具,仍保留业务插槽。 ## 注册 Hook diff --git a/packages/ui/src/RTablePro/src/TablePanel.tsx b/packages/ui/src/RTablePro/src/TablePanel.tsx index 684dc198..2534da96 100644 --- a/packages/ui/src/RTablePro/src/TablePanel.tsx +++ b/packages/ui/src/RTablePro/src/TablePanel.tsx @@ -336,6 +336,15 @@ export default defineComponent({ } } + const renderCheckedActionLabel = (label: string, checked: boolean) => ( + + {label} + + + ) + const actionOptions = computed>( () => [ { @@ -363,8 +372,8 @@ export default defineComponent({ return { key, - label: t(key), - icon: () => , + label: () => renderCheckedActionLabel(t(key), !!checked), + icon: () => , props: { role: 'menuitemcheckbox', 'aria-checked': checked }, } }), diff --git a/packages/ui/src/RTablePro/src/index.scss b/packages/ui/src/RTablePro/src/index.scss index 18a0d4b2..07e496e2 100644 --- a/packages/ui/src/RTablePro/src/index.scss +++ b/packages/ui/src/RTablePro/src/index.scss @@ -111,6 +111,18 @@ } } +.r-table-action-label { + display: flex; + align-items: center; + justify-content: space-between; + gap: 16px; + + &__check { + inline-size: 1em; + flex: none; + } +} + .r-table-search { display: flex; flex-wrap: wrap; diff --git a/packages/ui/src/RTablePro/src/props.ts b/packages/ui/src/RTablePro/src/props.ts index 9933ea78..55fd14d9 100644 --- a/packages/ui/src/RTablePro/src/props.ts +++ b/packages/ui/src/RTablePro/src/props.ts @@ -39,6 +39,7 @@ const panelControls = { export const tablePanelProps = { ...omit(dataTableProps, ['onPageChange', 'onPageSizeChange']), + size: { type: dataTableProps.size, default: 'medium' }, ...panelControls, rowActionsDisabled: Boolean, /** 由查询层提供;手动 data 模式通过自定义工具栏提供刷新 */