mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-20 18:34:13 +08:00
fix(table-pro): restore menu icons and default density
Keep striped and bordered action icons visible with separate selection marks. Default TablePro density to medium and cover initial and updated selection states. Correct bilingual README screenshot descriptions and the legacy version link.
This commit is contained in:
parent
22c9f55f27
commit
b5c24a612c
10
README.md
10
README.md
@ -10,9 +10,9 @@ Ray Template is an open-source frontend template for admin dashboards, operation
|
||||
|
||||
[](https://xiaodaigua-ray.github.io/ray-template/#/dashboard)
|
||||
|
||||
[](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height)
|
||||
[](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
|
||||
|
||||

|
||||
|
||||
[](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height)
|
||||
[](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.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -10,9 +10,9 @@ Ray Template 是基于 Vue 3、TypeScript / TSX 和 Naive UI 的开源中后台
|
||||
|
||||
[](https://xiaodaigua-ray.github.io/ray-template/#/dashboard)
|
||||
|
||||
[](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height)
|
||||
[](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height)
|
||||
|
||||
_完整欢迎页 · 默认 Modern 风格 · 浅色主题。_
|
||||
_欢迎页与 TablePro · 默认 Modern 风格 · 浅色主题。_
|
||||
|
||||
## 风格与布局
|
||||
|
||||
@ -29,9 +29,9 @@ _完整欢迎页 · 默认 Modern 风格 · 浅色主题。_
|
||||
|
||||

|
||||
|
||||
[](https://xiaodaigua-ray.github.io/ray-template/#/tables/auto-height)
|
||||
[](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)。
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -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('<path')
|
||||
}
|
||||
|
||||
for (const [label, initial] of [
|
||||
['Striped rows', false],
|
||||
['Table border', true],
|
||||
] as const) {
|
||||
const option = appearanceOption(label)
|
||||
const icon = option.get('.n-dropdown-option-body__prefix svg').html()
|
||||
|
||||
expect(icon).toContain('<path')
|
||||
expect(option.attributes('aria-checked')).toBe(String(initial))
|
||||
expect(option.get('.r-table-action-label__check').text()).toBe(
|
||||
initial ? '✓' : '',
|
||||
)
|
||||
await option.trigger('click')
|
||||
await flushPromises()
|
||||
await openMenu()
|
||||
const updated = appearanceOption(label)
|
||||
|
||||
expect(updated.attributes('aria-checked')).toBe(String(!initial))
|
||||
expect(updated.get('.r-table-action-label__check').text()).toBe(
|
||||
initial ? '' : '✓',
|
||||
)
|
||||
expect(updated.get('.n-dropdown-option-body__prefix svg').html()).toBe(
|
||||
icon,
|
||||
)
|
||||
}
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ const renderTable = () => (
|
||||
|
||||
实例还提供 `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`
|
||||
|
||||
|
||||
@ -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。不要将品牌标识与这批通用线性图标的来源或许可混用。
|
||||
|
||||
|
||||
3
packages/icons/src/action/table-bordered.svg
Normal file
3
packages/icons/src/action/table-bordered.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<path d="M3 3h18v18H3zM3 9h18M3 15h18M9 3v18M15 3v18" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linejoin="round" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 205 B |
4
packages/icons/src/action/table-striped.svg
Normal file
4
packages/icons/src/action/table-striped.svg
Normal file
@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<path d="M3 4h18v4H3zM3 16h18v4H3z" fill="currentColor" />
|
||||
<path d="M3 12h18" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 230 B |
@ -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',
|
||||
|
||||
@ -27,7 +27,7 @@ import { RTablePro } from '@/components'
|
||||
- `autoHeight` 默认使用当前布局的可用高度,宿主外部使用视口高度;嵌入特定区域时可以用 CSS 变量 `--r-table-height` 覆盖。较短的屏幕保留表格的最小操作高度。
|
||||
- 只接收最新的请求结果。切换请求源或有效筛选条件会立即清空旧行和总数;切页或修改每页条数会隐藏旧行并保留同一范围的总数。当前页未加载时,实例取数返回空、底层实例返回 `null`,CSV 和打印不会启动。请求失败后显示空态并清空总数,通过宿主 Toast 提醒。可用 `onRequestError` 接收详情、用实例 `reload()` 重试,或显式提供 `error` 插槽接管提示。
|
||||
- 需要实例时使用 `shallowRef<TableProInst>()`。实例提供 `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
|
||||
|
||||
|
||||
@ -336,6 +336,15 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
|
||||
const renderCheckedActionLabel = (label: string, checked: boolean) => (
|
||||
<span class="r-table-action-label">
|
||||
<span>{label}</span>
|
||||
<span class="r-table-action-label__check" aria-hidden="true">
|
||||
{checked ? '✓' : ''}
|
||||
</span>
|
||||
</span>
|
||||
)
|
||||
|
||||
const actionOptions = computed<NonNullable<DropdownProps['options']>>(
|
||||
() => [
|
||||
{
|
||||
@ -363,8 +372,8 @@ export default defineComponent({
|
||||
|
||||
return {
|
||||
key,
|
||||
label: t(key),
|
||||
icon: () => <span aria-hidden="true">{checked ? '✓' : ''}</span>,
|
||||
label: () => renderCheckedActionLabel(t(key), !!checked),
|
||||
icon: () => <RIcon name={`action/table-${key}`} size={16} />,
|
||||
props: { role: 'menuitemcheckbox', 'aria-checked': checked },
|
||||
}
|
||||
}),
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -39,6 +39,7 @@ const panelControls = {
|
||||
|
||||
export const tablePanelProps = {
|
||||
...omit(dataTableProps, ['onPageChange', 'onPageSizeChange']),
|
||||
size: { type: dataTableProps.size, default: 'medium' },
|
||||
...panelControls,
|
||||
rowActionsDisabled: Boolean,
|
||||
/** 由查询层提供;手动 data 模式通过自定义工具栏提供刷新 */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user