feat: table 类型VxeTableGridColumns替代VxeTableGridOptions['columns']魔法值写法

pull/340/MERGE
雪忆天堂 2026-03-23 10:06:35 +08:00
parent 5613dcef99
commit 6b3506f128
5 changed files with 13 additions and 7 deletions

View File

@ -1,5 +1,5 @@
export { setupVbenVxeTable } from './init'; export { setupVbenVxeTable } from './init';
export type { VxeTableGridOptions } from './types'; export type { VxeTableGridColumns, VxeTableGridOptions } from './types';
export * from './use-vxe-grid'; export * from './use-vxe-grid';
export { default as VbenVxeGrid } from './use-vxe-grid.vue'; export { default as VbenVxeGrid } from './use-vxe-grid.vue';

View File

@ -26,6 +26,8 @@ interface ToolbarConfigOptions extends VxeGridPropTypes.ToolbarConfig {
search?: boolean; search?: boolean;
} }
export type VxeTableGridColumns<T = any> = VxeTableGridOptions<T>['columns'];
export interface VxeTableGridOptions<T = any> extends VxeTableGridProps<T> { export interface VxeTableGridOptions<T = any> extends VxeTableGridProps<T> {
/** 工具栏配置 */ /** 工具栏配置 */
toolbarConfig?: ToolbarConfigOptions; toolbarConfig?: ToolbarConfigOptions;
@ -40,6 +42,10 @@ export interface VxeGridProps<
T extends Record<string, any> = any, T extends Record<string, any> = any,
D extends BaseFormComponentType = BaseFormComponentType, D extends BaseFormComponentType = BaseFormComponentType,
> { > {
/**
*
*/
tableData?: any[];
/** /**
* *
*/ */

View File

@ -1,4 +1,4 @@
import type { VxeTableGridOptions } from '@vben/plugins/vxe-table'; import type { VxeTableGridColumns } from '@vben/plugins/vxe-table';
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn } from '#/adapter/vxe-table'; import type { OnActionClickFn } from '#/adapter/vxe-table';
@ -76,7 +76,7 @@ export function useSchema(): VbenFormSchema[] {
*/ */
export function useColumns( export function useColumns(
onActionClick?: OnActionClickFn<SystemDeptApi.SystemDept>, onActionClick?: OnActionClickFn<SystemDeptApi.SystemDept>,
): VxeTableGridOptions<SystemDeptApi.SystemDept>['columns'] { ): VxeTableGridColumns<SystemDeptApi.SystemDept> {
return [ return [
{ {
align: 'left', align: 'left',

View File

@ -1,4 +1,4 @@
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; import type { OnActionClickFn, VxeTableGridColumns } from '#/adapter/vxe-table';
import type { SystemMenuApi } from '#/api/system/menu'; import type { SystemMenuApi } from '#/api/system/menu';
import { $t } from '#/locales'; import { $t } from '#/locales';
@ -23,7 +23,7 @@ export function getMenuTypeOptions() {
export function useColumns( export function useColumns(
onActionClick: OnActionClickFn<SystemMenuApi.SystemMenu>, onActionClick: OnActionClickFn<SystemMenuApi.SystemMenu>,
): VxeTableGridOptions<SystemMenuApi.SystemMenu>['columns'] { ): VxeTableGridColumns<SystemMenuApi.SystemMenu> {
return [ return [
{ {
align: 'left', align: 'left',

View File

@ -1,5 +1,5 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; import type { OnActionClickFn, VxeTableGridColumns } from '#/adapter/vxe-table';
import type { SystemRoleApi } from '#/api'; import type { SystemRoleApi } from '#/api';
import { $t } from '#/locales'; import { $t } from '#/locales';
@ -77,7 +77,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
export function useColumns<T = SystemRoleApi.SystemRole>( export function useColumns<T = SystemRoleApi.SystemRole>(
onActionClick: OnActionClickFn<T>, onActionClick: OnActionClickFn<T>,
onStatusChange?: (newStatus: any, row: T) => PromiseLike<boolean | undefined>, onStatusChange?: (newStatus: any, row: T) => PromiseLike<boolean | undefined>,
): VxeTableGridOptions['columns'] { ): VxeTableGridColumns {
return [ return [
{ {
field: 'name', field: 'name',