-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add vxe-table component (#4563)
* chore: wip vxe-table * feat: add table demo * chore: follow ci recommendations to adjust details * chore: add custom-cell demo * feat: add custom-cell table demo * feat: add table from demo
- Loading branch information
Showing
80 changed files
with
2,426 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { verifyAccessToken } from '~/utils/jwt-utils'; | ||
import { unAuthorizedResponse } from '~/utils/response'; | ||
|
||
function generateMockDataList(count: number) { | ||
const dataList = []; | ||
|
||
for (let i = 0; i < count; i++) { | ||
const dataItem = { | ||
id: faker.string.uuid(), | ||
imageUrl: faker.image.avatar(), | ||
imageUrl2: faker.image.avatar(), | ||
open: faker.datatype.boolean(), | ||
status: faker.helpers.arrayElement(['success', 'error', 'warning']), | ||
productName: faker.commerce.productName(), | ||
price: faker.commerce.price(), | ||
currency: faker.finance.currencyCode(), | ||
quantity: faker.number.int({ min: 1, max: 100 }), | ||
available: faker.datatype.boolean(), | ||
category: faker.commerce.department(), | ||
releaseDate: faker.date.past(), | ||
rating: faker.number.float({ min: 1, max: 5 }), | ||
description: faker.commerce.productDescription(), | ||
weight: faker.number.float({ min: 0.1, max: 10 }), | ||
color: faker.color.human(), | ||
inProduction: faker.datatype.boolean(), | ||
tags: Array.from({ length: 3 }, () => faker.commerce.productAdjective()), | ||
}; | ||
|
||
dataList.push(dataItem); | ||
} | ||
|
||
return dataList; | ||
} | ||
|
||
const mockData = generateMockDataList(100); | ||
|
||
export default eventHandler(async (event) => { | ||
const userinfo = verifyAccessToken(event); | ||
if (!userinfo) { | ||
return unAuthorizedResponse(event); | ||
} | ||
|
||
await sleep(600); | ||
|
||
const { page, pageSize } = getQuery(event); | ||
return usePageResponseSuccess(page as string, pageSize as string, mockData); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './form'; | ||
export * from './vxe-table'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { h } from 'vue'; | ||
|
||
import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table'; | ||
|
||
import { Button, Image } from 'ant-design-vue'; | ||
|
||
import { useVbenForm } from './form'; | ||
|
||
setupVbenVxeTable({ | ||
configVxeTable: (vxeUI) => { | ||
vxeUI.setConfig({ | ||
grid: { | ||
align: 'center', | ||
border: true, | ||
minHeight: 180, | ||
proxyConfig: { | ||
autoLoad: true, | ||
response: { | ||
result: 'items', | ||
total: 'total', | ||
list: 'items', | ||
}, | ||
showActiveMsg: true, | ||
showResponseMsg: false, | ||
}, | ||
round: true, | ||
size: 'small', | ||
}, | ||
}); | ||
|
||
// 表格配置项可以用 cellRender: { name: 'CellImage' }, | ||
vxeUI.renderer.add('CellImage', { | ||
renderDefault(_renderOpts, params) { | ||
const { column, row } = params; | ||
return h(Image, { src: row[column.field] }); | ||
}, | ||
}); | ||
|
||
// 表格配置项可以用 cellRender: { name: 'CellLink' }, | ||
vxeUI.renderer.add('CellLink', { | ||
renderDefault(renderOpts) { | ||
const { props } = renderOpts; | ||
return h( | ||
Button, | ||
{ size: 'small', type: 'link' }, | ||
{ default: () => props?.text }, | ||
); | ||
}, | ||
}); | ||
|
||
// 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化 | ||
// vxeUI.formats.add | ||
}, | ||
useVbenForm, | ||
}); | ||
|
||
export { useVbenVxeGrid }; | ||
|
||
export type * from '@vben/plugins/vxe-table'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './form'; | ||
export * from './vxe-table'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { h } from 'vue'; | ||
|
||
import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table'; | ||
|
||
import { ElButton, ElImage } from 'element-plus'; | ||
|
||
import { useVbenForm } from './form'; | ||
|
||
setupVbenVxeTable({ | ||
configVxeTable: (vxeUI) => { | ||
vxeUI.setConfig({ | ||
grid: { | ||
align: 'center', | ||
border: true, | ||
minHeight: 180, | ||
proxyConfig: { | ||
autoLoad: true, | ||
response: { | ||
result: 'items', | ||
total: 'total', | ||
list: 'items', | ||
}, | ||
showActiveMsg: true, | ||
showResponseMsg: false, | ||
}, | ||
round: true, | ||
size: 'small', | ||
}, | ||
}); | ||
|
||
// 表格配置项可以用 cellRender: { name: 'CellImage' }, | ||
vxeUI.renderer.add('CellImage', { | ||
renderDefault(_renderOpts, params) { | ||
const { column, row } = params; | ||
const src = row[column.field]; | ||
return h(ElImage, { src, previewSrcList: [src] }); | ||
}, | ||
}); | ||
|
||
// 表格配置项可以用 cellRender: { name: 'CellLink' }, | ||
vxeUI.renderer.add('CellLink', { | ||
renderDefault(renderOpts) { | ||
const { props } = renderOpts; | ||
return h( | ||
ElButton, | ||
{ size: 'small', link: true }, | ||
{ default: () => props?.text }, | ||
); | ||
}, | ||
}); | ||
|
||
// 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化 | ||
// vxeUI.formats.add | ||
}, | ||
useVbenForm, | ||
}); | ||
|
||
export { useVbenVxeGrid }; | ||
|
||
export type * from '@vben/plugins/vxe-table'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './form'; | ||
export * from './naive'; | ||
export * from './vxe-table'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { h } from 'vue'; | ||
|
||
import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table'; | ||
|
||
import { NButton, NImage } from 'naive-ui'; | ||
|
||
import { useVbenForm } from './form'; | ||
|
||
setupVbenVxeTable({ | ||
configVxeTable: (vxeUI) => { | ||
vxeUI.setConfig({ | ||
grid: { | ||
align: 'center', | ||
border: true, | ||
minHeight: 180, | ||
proxyConfig: { | ||
autoLoad: true, | ||
response: { | ||
result: 'items', | ||
total: 'total', | ||
list: 'items', | ||
}, | ||
showActiveMsg: true, | ||
showResponseMsg: false, | ||
}, | ||
round: true, | ||
size: 'small', | ||
}, | ||
}); | ||
|
||
// 表格配置项可以用 cellRender: { name: 'CellImage' }, | ||
vxeUI.renderer.add('CellImage', { | ||
renderDefault(_renderOpts, params) { | ||
const { column, row } = params; | ||
return h(NImage, { src: row[column.field] }); | ||
}, | ||
}); | ||
|
||
// 表格配置项可以用 cellRender: { name: 'CellLink' }, | ||
vxeUI.renderer.add('CellLink', { | ||
renderDefault(renderOpts) { | ||
const { props } = renderOpts; | ||
return h( | ||
NButton, | ||
{ size: 'small', type: 'primary', quaternary: true }, | ||
{ default: () => props?.text }, | ||
); | ||
}, | ||
}); | ||
|
||
// 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化 | ||
// vxeUI.formats.add | ||
}, | ||
useVbenForm, | ||
}); | ||
|
||
export { useVbenVxeGrid }; | ||
|
||
export type * from '@vben/plugins/vxe-table'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
"intlify", | ||
"mkdist", | ||
"mockjs", | ||
"vitejs", | ||
"noopener", | ||
"noreferrer", | ||
"nprogress", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { PluginOption } from 'vite'; | ||
|
||
import { lazyImport, VxeResolver } from 'vite-plugin-lazy-import'; | ||
|
||
async function viteVxeTableImportsPlugin(): Promise<PluginOption> { | ||
return [ | ||
lazyImport({ | ||
resolvers: [ | ||
VxeResolver({ | ||
libraryName: 'vxe-table', | ||
}), | ||
VxeResolver({ | ||
libraryName: 'vxe-pc-ui', | ||
}), | ||
], | ||
}), | ||
]; | ||
} | ||
|
||
export { viteVxeTableImportsPlugin }; |
Oops, something went wrong.