2026-07-23 15:09:31 +08:00
|
|
|
|
import type { FormValues } from '@vben/common-ui';
|
2025-10-21 10:47:39 +08:00
|
|
|
|
import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';
|
|
|
|
|
|
|
2026-04-04 23:40:27 +08:00
|
|
|
|
import type { ComponentPropsMap, ComponentType } from './component';
|
|
|
|
|
|
|
2025-10-21 10:47:39 +08:00
|
|
|
|
import { h } from 'vue';
|
|
|
|
|
|
|
2026-04-04 23:40:27 +08:00
|
|
|
|
import {
|
|
|
|
|
|
setupVbenVxeTable,
|
|
|
|
|
|
useVbenVxeGrid as useGrid,
|
|
|
|
|
|
} from '@vben/plugins/vxe-table';
|
2025-10-21 10:47:39 +08:00
|
|
|
|
|
2025-11-06 14:35:50 +08:00
|
|
|
|
import { Button, Image } from 'tdesign-vue-next';
|
2025-10-21 10:47:39 +08:00
|
|
|
|
|
|
|
|
|
|
import { useVbenForm } from './form';
|
|
|
|
|
|
|
|
|
|
|
|
setupVbenVxeTable({
|
|
|
|
|
|
configVxeTable: (vxeUI) => {
|
|
|
|
|
|
vxeUI.setConfig({
|
|
|
|
|
|
grid: {
|
|
|
|
|
|
align: 'center',
|
|
|
|
|
|
border: false,
|
|
|
|
|
|
columnConfig: {
|
|
|
|
|
|
resizable: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
minHeight: 180,
|
|
|
|
|
|
formConfig: {
|
|
|
|
|
|
// 全局禁用vxe-table的表单配置,使用formOptions
|
|
|
|
|
|
enabled: false,
|
|
|
|
|
|
},
|
|
|
|
|
|
proxyConfig: {
|
|
|
|
|
|
autoLoad: true,
|
|
|
|
|
|
response: {
|
|
|
|
|
|
result: 'items',
|
|
|
|
|
|
total: 'total',
|
|
|
|
|
|
list: 'items',
|
|
|
|
|
|
},
|
|
|
|
|
|
showActiveMsg: true,
|
|
|
|
|
|
showResponseMsg: false,
|
|
|
|
|
|
},
|
|
|
|
|
|
round: true,
|
|
|
|
|
|
showOverflow: true,
|
|
|
|
|
|
size: 'small',
|
|
|
|
|
|
} as VxeTableGridOptions,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 表格配置项可以用 cellRender: { name: 'CellImage' },
|
|
|
|
|
|
vxeUI.renderer.add('CellImage', {
|
2025-12-06 10:12:58 +08:00
|
|
|
|
renderTableDefault(renderOpts, params) {
|
|
|
|
|
|
const { props } = renderOpts;
|
2025-10-21 10:47:39 +08:00
|
|
|
|
const { column, row } = params;
|
2025-12-06 10:12:58 +08:00
|
|
|
|
return h(Image, { src: row[column.field], ...props });
|
2025-10-21 10:47:39 +08:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 表格配置项可以用 cellRender: { name: 'CellLink' },
|
|
|
|
|
|
vxeUI.renderer.add('CellLink', {
|
|
|
|
|
|
renderTableDefault(renderOpts) {
|
|
|
|
|
|
const { props } = renderOpts;
|
|
|
|
|
|
return h(
|
|
|
|
|
|
Button,
|
2025-11-06 14:35:50 +08:00
|
|
|
|
{ size: 'small', theme: 'primary', variant: 'text' },
|
2025-10-21 10:47:39 +08:00
|
|
|
|
{ default: () => props?.text },
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化
|
|
|
|
|
|
// vxeUI.formats.add
|
|
|
|
|
|
},
|
2026-04-05 19:03:03 +08:00
|
|
|
|
useVbenForm,
|
2025-10-21 10:47:39 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-07-23 15:09:31 +08:00
|
|
|
|
export const useVbenVxeGrid = <
|
|
|
|
|
|
T extends Record<string, any>,
|
|
|
|
|
|
TFormValues extends FormValues = FormValues,
|
|
|
|
|
|
TSubmitValues extends FormValues = TFormValues,
|
|
|
|
|
|
>(
|
|
|
|
|
|
...rest: Parameters<
|
|
|
|
|
|
typeof useGrid<
|
|
|
|
|
|
T,
|
|
|
|
|
|
ComponentType,
|
|
|
|
|
|
ComponentPropsMap,
|
|
|
|
|
|
TFormValues,
|
|
|
|
|
|
TSubmitValues
|
|
|
|
|
|
>
|
|
|
|
|
|
>
|
|
|
|
|
|
) =>
|
|
|
|
|
|
useGrid<T, ComponentType, ComponentPropsMap, TFormValues, TSubmitValues>(
|
|
|
|
|
|
...rest,
|
|
|
|
|
|
);
|
2025-10-21 10:47:39 +08:00
|
|
|
|
|
|
|
|
|
|
export type * from '@vben/plugins/vxe-table';
|