2024-10-18 15:20:20 +08:00
|
|
|
|
import { h, type Ref } from 'vue';
|
2024-10-04 23:05:28 +08:00
|
|
|
|
|
2024-10-18 15:20:20 +08:00
|
|
|
|
import {
|
|
|
|
|
setupVbenVxeTable,
|
|
|
|
|
useVbenVxeGrid,
|
|
|
|
|
type VxeGridDefines,
|
|
|
|
|
} from '@vben/plugins/vxe-table';
|
2024-10-04 23:05:28 +08:00
|
|
|
|
|
|
|
|
|
import { Button, Image } from 'ant-design-vue';
|
|
|
|
|
|
|
|
|
|
import { useVbenForm } from './form';
|
|
|
|
|
|
|
|
|
|
setupVbenVxeTable({
|
|
|
|
|
configVxeTable: (vxeUI) => {
|
|
|
|
|
vxeUI.setConfig({
|
|
|
|
|
grid: {
|
|
|
|
|
align: 'center',
|
2024-10-07 13:21:19 +08:00
|
|
|
|
border: false,
|
2024-10-04 23:05:28 +08:00
|
|
|
|
minHeight: 180,
|
2024-11-02 15:46:19 +08:00
|
|
|
|
formConfig: {
|
|
|
|
|
// 全局禁用vxe-table的表单配置,使用formOptions
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
2024-10-04 23:05:28 +08:00
|
|
|
|
proxyConfig: {
|
|
|
|
|
autoLoad: true,
|
|
|
|
|
response: {
|
2024-10-05 12:12:14 +08:00
|
|
|
|
result: 'rows',
|
2024-10-04 23:05:28 +08:00
|
|
|
|
total: 'total',
|
2024-10-05 12:12:14 +08:00
|
|
|
|
list: 'rows',
|
2024-10-04 23:05:28 +08:00
|
|
|
|
},
|
|
|
|
|
showActiveMsg: true,
|
|
|
|
|
showResponseMsg: false,
|
|
|
|
|
},
|
2024-10-11 17:34:13 +08:00
|
|
|
|
// 溢出展示形式
|
|
|
|
|
showOverflow: true,
|
2024-10-07 13:21:19 +08:00
|
|
|
|
pagerConfig: {
|
2024-10-10 08:31:40 +08:00
|
|
|
|
// 默认条数
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
// 分页可选条数
|
|
|
|
|
pageSizes: [10, 20, 30, 40, 50],
|
2024-10-07 13:21:19 +08:00
|
|
|
|
},
|
|
|
|
|
rowConfig: {
|
|
|
|
|
// 鼠标移入行显示 hover 样式
|
|
|
|
|
isHover: true,
|
|
|
|
|
// 点击行高亮
|
|
|
|
|
isCurrent: true,
|
|
|
|
|
},
|
2024-10-05 20:46:31 +08:00
|
|
|
|
columnConfig: {
|
2024-10-07 13:21:19 +08:00
|
|
|
|
// 可拖拽列宽
|
2024-10-05 20:46:31 +08:00
|
|
|
|
resizable: true,
|
|
|
|
|
},
|
2024-10-07 13:21:19 +08:00
|
|
|
|
// 右上角工具栏
|
2024-10-05 20:46:31 +08:00
|
|
|
|
toolbarConfig: {
|
|
|
|
|
// 自定义列
|
2024-10-30 11:48:36 +08:00
|
|
|
|
custom: {
|
|
|
|
|
icon: 'vxe-icon-setting',
|
|
|
|
|
},
|
2024-10-05 20:46:31 +08:00
|
|
|
|
// 最大化
|
|
|
|
|
zoom: true,
|
|
|
|
|
// 刷新
|
2024-10-16 11:03:24 +08:00
|
|
|
|
refresh: {
|
|
|
|
|
// 默认为reload 修改为在当前页刷新
|
|
|
|
|
code: 'query',
|
|
|
|
|
},
|
2024-10-05 20:46:31 +08:00
|
|
|
|
},
|
2024-10-07 13:21:19 +08:00
|
|
|
|
// 圆角按钮
|
2024-10-04 23:05:28 +08:00
|
|
|
|
round: true,
|
2024-10-07 13:21:19 +08:00
|
|
|
|
// 表格尺寸
|
2024-10-05 12:12:14 +08:00
|
|
|
|
size: 'medium',
|
2024-10-10 09:13:50 +08:00
|
|
|
|
customConfig: {
|
|
|
|
|
// 表格右上角自定义列配置 是否保存到localStorage
|
|
|
|
|
// 必须存在id参数才能使用
|
|
|
|
|
storage: false,
|
|
|
|
|
},
|
2024-10-04 23:05:28 +08:00
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 表格配置项可以用 cellRender: { name: 'CellImage' },
|
|
|
|
|
vxeUI.renderer.add('CellImage', {
|
2024-11-05 11:25:57 +08:00
|
|
|
|
renderTableDefault(_renderOpts, params) {
|
2024-10-04 23:05:28 +08:00
|
|
|
|
const { column, row } = params;
|
|
|
|
|
return h(Image, { src: row[column.field] });
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 表格配置项可以用 cellRender: { name: 'CellLink' },
|
|
|
|
|
vxeUI.renderer.add('CellLink', {
|
2024-11-05 11:25:57 +08:00
|
|
|
|
renderTableDefault(renderOpts) {
|
2024-10-04 23:05:28 +08:00
|
|
|
|
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';
|
2024-10-18 15:20:20 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通用的表格复选框是否选中事件
|
2024-12-11 11:09:16 +08:00
|
|
|
|
* @deprecated 使用vxeCheckboxChecked代替
|
2024-10-18 15:20:20 +08:00
|
|
|
|
* @param checked 是否选中
|
|
|
|
|
* @returns function
|
|
|
|
|
*/
|
|
|
|
|
export function tableCheckboxEvent(checked: Ref<boolean>) {
|
|
|
|
|
const event: (params: VxeGridDefines.CheckboxChangeEventParams) => void = (
|
|
|
|
|
params,
|
|
|
|
|
) => {
|
|
|
|
|
checked.value = params.$table.getCheckboxRecords().length > 0;
|
|
|
|
|
};
|
|
|
|
|
return event;
|
|
|
|
|
}
|
2024-12-11 11:09:16 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断vxe-table的复选框是否选中
|
|
|
|
|
* @param tableApi api
|
|
|
|
|
* @returns boolean
|
|
|
|
|
*/
|
|
|
|
|
export function vxeCheckboxChecked(
|
|
|
|
|
tableApi: ReturnType<typeof useVbenVxeGrid>[1],
|
|
|
|
|
) {
|
|
|
|
|
return tableApi?.grid?.getCheckboxRecords?.()?.length > 0;
|
|
|
|
|
}
|
2024-12-11 15:46:45 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通用的vxe-table排序事件 支持单/多字段排序
|
|
|
|
|
* @param tableApi api
|
|
|
|
|
* @param sortParams 排序参数
|
|
|
|
|
*/
|
|
|
|
|
export function vxeSortEvent(
|
|
|
|
|
tableApi: ReturnType<typeof useVbenVxeGrid>[1],
|
|
|
|
|
sortParams: VxeGridDefines.SortChangeEventParams,
|
|
|
|
|
) {
|
|
|
|
|
const { sortList } = sortParams;
|
|
|
|
|
// 这里是排序取消 length为0 就不传参数了
|
|
|
|
|
if (sortList.length === 0) {
|
|
|
|
|
tableApi.query();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 支持单/多字段排序
|
|
|
|
|
const orderByColumn = sortList.map((item) => item.field).join(',');
|
|
|
|
|
const isAsc = sortList.map((item) => item.order).join(',');
|
|
|
|
|
tableApi.query({ orderByColumn, isAsc });
|
|
|
|
|
}
|