2024-10-04 23:05:28 +08:00
|
|
|
|
import { h } from 'vue';
|
|
|
|
|
|
|
|
|
|
|
|
import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table';
|
2025-03-26 19:30:54 +08:00
|
|
|
|
import { useDictStore } from '#/store';
|
2024-10-04 23:05:28 +08:00
|
|
|
|
|
2025-03-26 19:30:54 +08:00
|
|
|
|
import { Button, Image, Tag } from 'ant-design-vue';
|
2024-10-04 23:05:28 +08:00
|
|
|
|
|
|
|
|
|
|
import { useVbenForm } from './form';
|
|
|
|
|
|
|
|
|
|
|
|
setupVbenVxeTable({
|
|
|
|
|
|
configVxeTable: (vxeUI) => {
|
|
|
|
|
|
vxeUI.setConfig({
|
|
|
|
|
|
grid: {
|
|
|
|
|
|
align: 'center',
|
2024-10-24 22:51:04 +08:00
|
|
|
|
border: false,
|
|
|
|
|
|
columnConfig: {
|
|
|
|
|
|
resizable: true,
|
|
|
|
|
|
},
|
2024-10-04 23:05:28 +08:00
|
|
|
|
minHeight: 180,
|
2024-11-02 15:46:19 +08:00
|
|
|
|
formConfig: {
|
|
|
|
|
|
// 全局禁用vxe-table的表单配置,使用formOptions
|
|
|
|
|
|
enabled: false,
|
|
|
|
|
|
},
|
2025-03-26 07:36:12 +08:00
|
|
|
|
toolbarConfig: {
|
|
|
|
|
|
import: true,
|
|
|
|
|
|
export: true,
|
|
|
|
|
|
refresh: true,
|
|
|
|
|
|
print: true,
|
|
|
|
|
|
zoom: true,
|
|
|
|
|
|
custom: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
customConfig: {
|
|
|
|
|
|
mode: 'modal',
|
|
|
|
|
|
},
|
2024-10-04 23:05:28 +08:00
|
|
|
|
proxyConfig: {
|
|
|
|
|
|
autoLoad: true,
|
|
|
|
|
|
response: {
|
2025-03-24 21:14:41 +08:00
|
|
|
|
result: 'list',
|
2025-03-26 19:30:54 +08:00
|
|
|
|
total: 'total',
|
2024-10-04 23:05:28 +08:00
|
|
|
|
},
|
|
|
|
|
|
showActiveMsg: true,
|
|
|
|
|
|
showResponseMsg: false,
|
|
|
|
|
|
},
|
2025-03-26 07:36:12 +08:00
|
|
|
|
pagerConfig: {
|
|
|
|
|
|
enabled: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
sortConfig: {
|
|
|
|
|
|
multiple: true,
|
|
|
|
|
|
},
|
2024-10-04 23:05:28 +08:00
|
|
|
|
round: true,
|
2024-10-24 22:51:04 +08:00
|
|
|
|
showOverflow: true,
|
2024-10-04 23:05:28 +08:00
|
|
|
|
size: 'small',
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 表格配置项可以用 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 },
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-03-26 19:30:54 +08:00
|
|
|
|
// 表格配置项可以用 cellRender: { name: 'CellDict', props:{dictType: ''} },
|
|
|
|
|
|
// TODO @芋艿:后续研究下,看看有没优解
|
|
|
|
|
|
vxeUI.renderer.add('CellDict', {
|
|
|
|
|
|
renderTableDefault(renderOpts, params) {
|
|
|
|
|
|
const dictStore = useDictStore();
|
|
|
|
|
|
const { props } = renderOpts;
|
|
|
|
|
|
const { column, row } = params;
|
|
|
|
|
|
if (!props) {
|
|
|
|
|
|
return '';
|
|
|
|
|
|
}
|
|
|
|
|
|
const dict = dictStore.getDictData(props.type, row[column.field]);
|
|
|
|
|
|
// 转义
|
|
|
|
|
|
if (dict) {
|
|
|
|
|
|
if (`${dict.colorType}` === 'primary') dict.colorType = 'processing';
|
|
|
|
|
|
else if (`${dict.colorType}` === 'danger') dict.colorType = 'error';
|
|
|
|
|
|
else if (`${dict.colorType}` === 'info') dict.colorType = 'default';
|
|
|
|
|
|
else if (!dict.colorType) dict.colorType = 'default';
|
|
|
|
|
|
return h(
|
|
|
|
|
|
Tag,
|
|
|
|
|
|
{ color: dict.colorType },
|
|
|
|
|
|
{ default: () => dict.label },
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
return '';
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2024-10-04 23:05:28 +08:00
|
|
|
|
// 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化
|
|
|
|
|
|
// vxeUI.formats.add
|
|
|
|
|
|
},
|
|
|
|
|
|
useVbenForm,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
export { useVbenVxeGrid };
|
|
|
|
|
|
|
|
|
|
|
|
export type * from '@vben/plugins/vxe-table';
|