diff --git a/docs/src/_env/adapter/vxe-table.ts b/docs/src/_env/adapter/vxe-table.ts index 87fc65e29ae..1a0765a09fe 100644 --- a/docs/src/_env/adapter/vxe-table.ts +++ b/docs/src/_env/adapter/vxe-table.ts @@ -2,7 +2,7 @@ import { h } from 'vue'; import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table'; -import { Button } from 'ant-design-vue'; +import { Button, Image } from 'ant-design-vue'; import { useVbenForm } from './form'; @@ -32,13 +32,6 @@ setupVbenVxeTable({ }, }); - // const { theme } = useData(); - - // watch(theme.value, (t: string) => { - // console.log(t); - // // vxeUI.setTheme(t === 'dark' ? 'dark' : 'light'); - // }); - // 表格配置项可以用 cellRender: { name: 'CellImage' }, vxeUI.renderer.add('CellImage', { renderDefault(_renderOpts, params) { diff --git a/docs/src/components/common-ui/vben-vxe-table.md b/docs/src/components/common-ui/vben-vxe-table.md index f0792e533ea..26d568e261d 100644 --- a/docs/src/components/common-ui/vben-vxe-table.md +++ b/docs/src/components/common-ui/vben-vxe-table.md @@ -4,42 +4,109 @@ outline: deep # Vben Vxe Table 表格 -框架提供的Table 列表组件基于 [vxe-table](https://xuliangzhan.github.io/vxe-table/),结合`Vben Form表单`进行了二次封装。 +框架提供的Table 列表组件基于 [vxe-table](https://vxetable.cn/v4/#/grid/api?apiKey=grid),结合`Vben Form 表单`进行了二次封装。 其中,表头的 **表单搜索** 部分采用了`Vben Form表单`,表格主体部分使用了`vxe-grid`组件,支持表格的分页、排序、筛选等功能。 +> 如果文档内没有参数说明,可以尝试在在线示例或者在 [vxe-grid 官方API 文档](https://vxetable.cn/v4/#/grid/api?apiKey=grid) 内寻找 + +::: info 写在前面 + +如果你觉得现有组件的封装不够理想,或者不完全符合你的需求,大可以直接使用原生组件,亦或亲手封装一个适合的组件。框架提供的组件并非束缚,使用与否,完全取决于你的需求与自由。 + +::: + +::: tip README + +下方示例代码中的,存在一些国际化、主题色未适配问题,这些问题只在文档内会出现,实际使用并不会有这些问题,可忽略,不必纠结。 + +::: + ## 基础表格 +使用 `useVbenVxeGrid` 创建最基础的表格。 + ## 远程加载 +通过指定 `proxyConfig.ajax` 的 `query` 方法,可以实现远程加载数据。 + ## 树形表格 +树形表格,的数据源为扁平结构,可以指定`treeConfig`配置项,实现树形表格。 + +```typescript +treeConfig: { + transform: true, // 指定表格为树形表格 + parentField: 'parentId', // 父节点字段名 + rowField: 'id', // 行数据字段名 +}, +``` + ## 固定表头/列 +列固定可选参数: `'left' | 'right' | '' | null` + ## 自定义单元格 +自定义单元格有两种实现方式 + +- 通过 `slots` 插槽 +- 通过 `customCell` 自定义单元格,但是要先添加渲染器 + +```typescript +// 表格配置项可以用 cellRender: { name: 'CellImage' }, +vxeUI.renderer.add('CellImage', { + renderDefault(_renderOpts, params) { + const { column, row } = params; + return h(Image, { src: row[column.field] } as any); // 注意此处的Image 组件,来源于Antd,需要自行引入,否则会使用js的Image类 + }, +}); + +// 表格配置项可以用 cellRender: { name: 'CellLink' }, +vxeUI.renderer.add('CellLink', { + renderDefault(renderOpts) { + const { props } = renderOpts; + return h( + Button, + { size: 'small', type: 'link' }, + { default: () => props?.text }, + ); + }, +}); +``` + ## 搜索表单 +**表单搜索** 部分采用了`Vben Form 表单`,参考 [Vben Form 表单文档](/components/common-ui/vben-form)。 + ## 单元格编辑 +通过指定`editConfig.mode`为`cell`,可以实现单元格编辑。 + ## 行编辑 +通过指定`editConfig.mode`为`row`,可以实现行编辑。 + ## 虚拟滚动 +通过 scroll-y.enabled 与 scroll-y.gt 组合开启,其中 enabled 为总开关,gt 是指当总行数大于指定行数时自动开启。 + +> 参考 [vxe-table 官方文档 - 虚拟滚动](https://vxetable.cn/v4/#/component/grid/scroll/vertical)。 + diff --git a/docs/src/demos/vben-vxe-table/basic/index.vue b/docs/src/demos/vben-vxe-table/basic/index.vue index 963be8cfb17..4b6b5a632fd 100644 --- a/docs/src/demos/vben-vxe-table/basic/index.vue +++ b/docs/src/demos/vben-vxe-table/basic/index.vue @@ -66,8 +66,9 @@ function changeLoading() { - - + + + {{ showBorder ? '隐藏' : '显示' }}边框 diff --git a/docs/src/demos/vben-vxe-table/custom-cell/index.vue b/docs/src/demos/vben-vxe-table/custom-cell/index.vue index 9802f4b4fd7..4960a2bbe68 100644 --- a/docs/src/demos/vben-vxe-table/custom-cell/index.vue +++ b/docs/src/demos/vben-vxe-table/custom-cell/index.vue @@ -1,7 +1,7 @@ - - + + - + diff --git a/docs/src/demos/vben-vxe-table/edit-cell/index.vue b/docs/src/demos/vben-vxe-table/edit-cell/index.vue index 7ad296906af..711941de313 100644 --- a/docs/src/demos/vben-vxe-table/edit-cell/index.vue +++ b/docs/src/demos/vben-vxe-table/edit-cell/index.vue @@ -1,8 +1,6 @@ - + - + diff --git a/docs/src/demos/vben-vxe-table/edit-row/index.vue b/docs/src/demos/vben-vxe-table/edit-row/index.vue index 4bdc43ecd6c..f317f69d160 100644 --- a/docs/src/demos/vben-vxe-table/edit-row/index.vue +++ b/docs/src/demos/vben-vxe-table/edit-row/index.vue @@ -1,8 +1,6 @@ - + @@ -91,5 +88,5 @@ const cancelRowEvent = (_row: RowType) => { - + diff --git a/docs/src/demos/vben-vxe-table/fixed/index.vue b/docs/src/demos/vben-vxe-table/fixed/index.vue index 134ec4cd8d8..6067a5ebe7d 100644 --- a/docs/src/demos/vben-vxe-table/fixed/index.vue +++ b/docs/src/demos/vben-vxe-table/fixed/index.vue @@ -37,7 +37,6 @@ const gridOptions: VxeGridProps = { width: 120, }, ], - height: 'auto', pagerConfig: {}, proxyConfig: { ajax: { @@ -58,8 +57,8 @@ const [Grid] = useVbenVxeGrid({ gridOptions }); - - + + 编辑 diff --git a/docs/src/demos/vben-vxe-table/form/index.vue b/docs/src/demos/vben-vxe-table/form/index.vue index b7950086451..a5e8a547b8d 100644 --- a/docs/src/demos/vben-vxe-table/form/index.vue +++ b/docs/src/demos/vben-vxe-table/form/index.vue @@ -2,8 +2,6 @@ import type { VbenFormProps } from '#/adapter/form'; import type { VxeGridProps } from '#/adapter/vxe-table'; -import { Page } from '@vben/common-ui'; - import { message } from 'ant-design-vue'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; @@ -25,17 +23,26 @@ const formOptions: VbenFormProps = { schema: [ { component: 'Input', + componentProps: { + placeholder: 'Please enter category', + }, defaultValue: '1', fieldName: 'category', label: 'Category', }, { component: 'Input', + componentProps: { + placeholder: 'Please enter productName', + }, fieldName: 'productName', label: 'ProductName', }, { component: 'Input', + componentProps: { + placeholder: 'Please enter price', + }, fieldName: 'price', label: 'Price', }, @@ -66,6 +73,9 @@ const formOptions: VbenFormProps = { ], // 控制表单是否显示折叠按钮 showCollapseButton: true, + submitButtonOptions: { + content: '查询', + }, // 按下回车时是否提交表单 submitOnEnter: false, }; @@ -84,7 +94,6 @@ const gridOptions: VxeGridProps = { { field: 'price', title: 'Price' }, { field: 'releaseDate', formatter: 'formatDateTime', title: 'Date' }, ], - height: 'auto', keepSource: true, pagerConfig: {}, proxyConfig: { @@ -105,7 +114,7 @@ const [Grid] = useVbenVxeGrid({ formOptions, gridOptions }); - + - + diff --git a/docs/src/demos/vben-vxe-table/remote/index.vue b/docs/src/demos/vben-vxe-table/remote/index.vue index 9366dfbcf71..fc845270845 100644 --- a/docs/src/demos/vben-vxe-table/remote/index.vue +++ b/docs/src/demos/vben-vxe-table/remote/index.vue @@ -5,7 +5,8 @@ import { Button } from 'ant-design-vue'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; -import { getExampleTableApi } from '../mock-api'; +import { type DemoTableApi } from '../mock-api'; +import { MOCK_API_DATA } from '../table-data'; interface RowType { category: string; @@ -16,6 +17,43 @@ interface RowType { releaseDate: string; } +// 数据实例 +// const MOCK_TREE_TABLE_DATA = [ +// { +// date: '2020-08-01', +// id: 10_000, +// name: 'Test1', +// parentId: null, +// size: 1024, +// type: 'mp3', +// }, +// ] + +const sleep = (time = 1000) => { + return new Promise((resolve) => { + setTimeout(() => { + resolve(true); + }, time); + }); +}; + +/** + * 获取示例表格数据 + */ +async function getExampleTableApi(params: DemoTableApi.PageFetchParams) { + return new Promise<{ items: any; total: number }>((resolve) => { + const { page, pageSize } = params; + const items = MOCK_API_DATA.slice((page - 1) * pageSize, page * pageSize); + + sleep(1000).then(() => { + resolve({ + total: items.length, + items, + }); + }); + }); +} + const gridOptions: VxeGridProps = { checkboxConfig: { highlight: true, @@ -31,7 +69,7 @@ const gridOptions: VxeGridProps = { { field: 'releaseDate', formatter: 'formatDateTime', title: 'DateTime' }, ], exportConfig: {}, - height: 'auto', + // height: 'auto', // 如果设置为 auto,则必须确保存在父节点且不允许存在相邻元素,否则会出现高度闪动问题 keepSource: true, proxyConfig: { ajax: { @@ -59,7 +97,7 @@ const [Grid, gridApi] = useVbenVxeGrid({ - + gridApi.query()"> 刷新当前页面 diff --git a/docs/src/demos/vben-vxe-table/table-data.ts b/docs/src/demos/vben-vxe-table/table-data.ts index c951ab0b765..c37b88ade68 100644 --- a/docs/src/demos/vben-vxe-table/table-data.ts +++ b/docs/src/demos/vben-vxe-table/table-data.ts @@ -381,214 +381,4 @@ export const MOCK_API_DATA = [ tags: ['Handmade', 'Unbranded', 'Unbranded'], weight: 9.430_690_557_758_114, }, - { - available: false, - category: 'Sports', - color: 'lavender', - currency: 'XOF', - description: - 'The slim & simple Maple Gaming Keyboard from Dev Byte comes with a sleek body and 7- Color RGB LED Back-lighting for smart functionality', - id: '7b711e78-692e-4031-83f9-b08085d7dc27', - imageUrl: 'https://avatars.githubusercontent.com/u/96172031', - imageUrl2: 'https://avatars.githubusercontent.com/u/45856661', - inProduction: false, - open: false, - price: '833.85', - productName: 'Sleek Plastic Chicken', - quantity: 41, - rating: 4.369_176_254_671_247, - releaseDate: '2024-02-05T16:21:02.026Z', - status: 'error', - tags: ['Oriental', 'Rustic', 'Intelligent'], - weight: 3.211_361_088_265_749_5, - }, - { - available: true, - category: 'Outdoors', - color: 'gold', - currency: 'MVR', - description: - 'New ABC 13 9370, 13.3, 5th Gen CoreA5-8250U, 8GB RAM, 256GB SSD, power UHD Graphics, OS 10 Home, OS Office A & J 2016', - id: 'e46cee76-2d53-4481-a15e-59434579198b', - imageUrl: 'https://avatars.githubusercontent.com/u/75039120', - imageUrl2: 'https://avatars.githubusercontent.com/u/88852377', - inProduction: true, - open: true, - price: '123.59', - productName: 'Elegant Frozen Table', - quantity: 55, - rating: 1.149_023_048_729_307_8, - releaseDate: '2024-03-08T13:09:28.421Z', - status: 'error', - tags: ['Unbranded', 'Licensed', 'Oriental'], - weight: 8.646_435_587_749_05, - }, - { - available: false, - category: 'Beauty', - color: 'violet', - currency: 'SEK', - description: - 'The Nagasaki Lander is the trademarked name of several series of Nagasaki sport bikes, that started with the 1984 ABC800J', - id: 'cf3de0d0-0f50-46ef-9244-d30ea4cc98b8', - imageUrl: 'https://avatars.githubusercontent.com/u/65691100', - imageUrl2: 'https://avatars.githubusercontent.com/u/35362239', - inProduction: true, - open: true, - price: '303.49', - productName: 'Ergonomic Cotton Soap', - quantity: 81, - rating: 4.217_422_711_758_923, - releaseDate: '2024-06-09T02:39:00.969Z', - status: 'error', - tags: ['Elegant', 'Practical', 'Fantastic'], - weight: 6.018_255_461_739_438, - }, - { - available: true, - category: 'Movies', - color: 'gold', - currency: 'NZD', - description: - 'The Nagasaki Lander is the trademarked name of several series of Nagasaki sport bikes, that started with the 1984 ABC800J', - id: '14995e8d-3e0e-4684-80b1-f84e6df4420b', - imageUrl: 'https://avatars.githubusercontent.com/u/2227834', - imageUrl2: 'https://avatars.githubusercontent.com/u/51921236', - inProduction: false, - open: true, - price: '395.49', - productName: 'Awesome Soft Car', - quantity: 68, - rating: 3.114_702_440_124_858_6, - releaseDate: '2024-08-07T23:46:00.786Z', - status: 'error', - tags: ['Sleek', 'Incredible', 'Practical'], - weight: 1.002_350_512_236_772_6, - }, - { - available: false, - category: 'Movies', - color: 'cyan', - currency: 'BRL', - description: - 'The automobile layout consists of a front-engine design, with transaxle-type transmissions mounted at the rear of the engine and four wheel drive', - id: '581fa9b1-e784-47f9-9922-66aa21f46664', - imageUrl: 'https://avatars.githubusercontent.com/u/49456060', - imageUrl2: 'https://avatars.githubusercontent.com/u/47054539', - inProduction: true, - open: false, - price: '660.09', - productName: 'Oriental Rubber Fish', - quantity: 67, - rating: 3.783_115_267_908_933_3, - releaseDate: '2023-12-03T17:35:17.845Z', - status: 'warning', - tags: ['Refined', 'Intelligent', 'Bespoke'], - weight: 2.920_687_808_651_241, - }, - { - available: true, - category: 'Home', - color: 'red', - currency: 'DOP', - description: - 'The Apollotech B340 is an affordable wireless mouse with reliable connectivity, 12 months battery life and modern design', - id: 'bef03f92-ee7d-4299-8438-a95eb8872cb9', - imageUrl: 'https://avatars.githubusercontent.com/u/3917257', - imageUrl2: 'https://avatars.githubusercontent.com/u/71337756', - inProduction: true, - open: false, - price: '502.99', - productName: 'Bespoke Bronze Bike', - quantity: 13, - rating: 4.929_263_484_476_12, - releaseDate: '2024-10-17T12:50:42.635Z', - status: 'success', - tags: ['Generic', 'Small', 'Refined'], - weight: 7.679_653_789_364_19, - }, - { - available: true, - category: 'Movies', - color: 'orange', - currency: 'KHR', - description: - 'Carbonite web goalkeeper gloves are ergonomically designed to give easy fit', - id: '75d3c9e0-c7a0-44b1-b572-196518f036d4', - imageUrl: 'https://avatars.githubusercontent.com/u/71124558', - imageUrl2: 'https://avatars.githubusercontent.com/u/79487494', - inProduction: false, - open: true, - price: '515.69', - productName: 'Modern Frozen Computer', - quantity: 26, - rating: 2.853_653_354_649_052_3, - releaseDate: '2024-05-17T05:12:48.300Z', - status: 'warning', - tags: ['Luxurious', 'Rustic', 'Oriental'], - weight: 2.642_900_412_111_716_3, - }, - { - available: false, - category: 'Kids', - color: 'salmon', - currency: 'SCR', - description: - "Boston's most advanced compression wear technology increases muscle oxygenation, stabilizes active muscles", - id: '14e46b4b-0203-4c73-abed-a8100e0b539c', - imageUrl: 'https://avatars.githubusercontent.com/u/76342482', - imageUrl2: 'https://avatars.githubusercontent.com/u/29659498', - inProduction: true, - open: true, - price: '177.69', - productName: 'Elegant Cotton Fish', - quantity: 36, - rating: 2.726_620_373_572_253, - releaseDate: '2024-03-23T11:15:31.823Z', - status: 'success', - tags: ['Small', 'Modern', 'Gorgeous'], - weight: 6.910_916_953_867_159, - }, - { - available: false, - category: 'Movies', - color: 'black', - currency: 'MYR', - description: - 'Andy shoes are designed to keeping in mind durability as well as trends, the most stylish range of shoes & sandals', - id: '6908f557-a2cb-434d-b5d5-b8d982d5451b', - imageUrl: 'https://avatars.githubusercontent.com/u/5593260', - imageUrl2: 'https://avatars.githubusercontent.com/u/13907478', - inProduction: true, - open: true, - price: '892.15', - productName: 'Unbranded Rubber Pants', - quantity: 6, - rating: 1.044_369_861_681_574_2, - releaseDate: '2024-07-01T19:18:09.841Z', - status: 'error', - tags: ['Oriental', 'Recycled', 'Tasty'], - weight: 7.356_822_519_614_8, - }, - { - available: true, - category: 'Tools', - color: 'salmon', - currency: 'DOP', - description: - 'Ergonomic executive chair upholstered in bonded black leather and PVC padded seat and back for all-day comfort and support', - id: 'b53ef7fc-3e82-49ce-b765-bfbf6105b8eb', - imageUrl: 'https://avatars.githubusercontent.com/u/54968787', - imageUrl2: 'https://avatars.githubusercontent.com/u/61407293', - inProduction: false, - open: false, - price: '163.40', - productName: 'Recycled Concrete Car', - quantity: 79, - rating: 2.679_401_744_365_649, - releaseDate: '2024-01-12T15:02:30.337Z', - status: 'warning', - tags: ['Elegant', 'Practical', 'Elegant'], - weight: 2.094_519_890_837_731, - }, ]; diff --git a/docs/src/demos/vben-vxe-table/tree/index.vue b/docs/src/demos/vben-vxe-table/tree/index.vue index 6274e8fadd3..0024765a8ca 100644 --- a/docs/src/demos/vben-vxe-table/tree/index.vue +++ b/docs/src/demos/vben-vxe-table/tree/index.vue @@ -16,6 +16,26 @@ interface RowType { type: string; } +// 数据实例 +// const MOCK_TREE_TABLE_DATA = [ +// { +// date: '2020-08-01', +// id: 10_000, +// name: 'Test1', +// parentId: null, +// size: 1024, +// type: 'mp3', +// }, +// { +// date: '2021-04-01', +// id: 10_050, +// name: 'Test2', +// parentId: 10_000, +// size: 0, +// type: 'mp4', +// }, +// ]; + const gridOptions: VxeGridProps = { columns: [ { type: 'seq', width: 70 }, @@ -47,8 +67,8 @@ const collapseAll = () => { - - + + 展开全部 diff --git a/docs/src/demos/vben-vxe-table/virtual/index.vue b/docs/src/demos/vben-vxe-table/virtual/index.vue index f35a691b3df..81fa00af260 100644 --- a/docs/src/demos/vben-vxe-table/virtual/index.vue +++ b/docs/src/demos/vben-vxe-table/virtual/index.vue @@ -3,8 +3,6 @@ import type { VxeGridProps } from '#/adapter/vxe-table'; import { onMounted } from 'vue'; -import { Page } from '@vben/common-ui'; - import { useVbenVxeGrid } from '#/adapter/vxe-table'; interface RowType { @@ -60,7 +58,7 @@ onMounted(() => { - + - +