import { Input, message } from 'ant-design-vue' export type ExampleTag = { label: string color: string } export interface ExampleTableRow { id: number text: string textWrap: string textList: string[] textListVertical: string[] imageSrc: string imageList: string[] tag: ExampleTag tagList: ExampleTag[] tagListRow: ExampleTag[] buttonAction: { label: string } linkAction: { label: string; to: string; target?: string } customInput: string customSlotCell: string status: '启用' | '禁用' | '待审核' createTime: string } /** * 初始化列配置:覆盖 text/link/tag/image/button/component/sort 等常见类型 */ export const createTableColumns = (options: { onDelete: (record: ExampleTableRow) => void }) => { return [ { key: 'id', title: 'ID', type: 'text', content: 'id', width: 80, fixed: 'left', group: '基础信息', // column 示例:开启 antd 排序(配合 example/index.vue 的 @change 打印 sort 日志) sorter: (a: any, b: any) => Number(a?.id ?? 0) - Number(b?.id ?? 0), sortDirections: ['ascend', 'descend'], }, { key: 'index', title: '序号', type: 'text', content: (record: any, index: number) => index + 1, width: 80, fixed: 'left', group: '基础信息', }, { key: 'text', title: '文本', type: 'text', content: 'text', width: 150, group: '内容字段', titleTooltip: '标题提示信息', }, { key: 'textWrap', title: '文本(自动换行)', type: 'text', content: 'textWrap', width: 180, ellipsis: false, group: '内容字段', titleTooltip: 'ellipsis: false 示例,关闭省略号自动换行', }, { key: 'textList', title: '文本列表', content: 'textList', width: 150, group: '内容字段', }, { key: 'textListVertical', title: '文本列表(竖向)', type: 'text', content: 'textListVertical', width: 180, maxCount: 2, group: '内容字段', flexDirection: 'column', }, { key: 'image', type: 'image', title: '图片', content: 'imageSrc', group: '媒体字段', }, { key: 'imageList', type: 'image', title: '图片列表', content: 'imageList', width: 200, visible: false, group: '媒体字段', expandItemProps: { span: 2, }, }, { key: 'tag', type: 'tag', title: '标签', width: 120, group: '内容字段', content: 'tag', }, { key: 'tagList', type: 'tag', title: '标签列表', width: 200, group: '内容字段', content: 'tagList', }, { key: 'tagListRow', type: 'tag', title: '标签列表(行折叠)', width: 200, maxRows: 1, group: '内容字段', content: 'tagListRow', }, { key: 'button', type: 'button', title: '按钮', align: 'center', group: '操作字段', content(record: ExampleTableRow) { return { label: record.buttonAction.label, onClick() { message.info(`触发动作:${record.buttonAction.label}(ID: ${record.id})`) }, } }, }, { key: 'link', type: 'link', title: '链接', group: '操作字段', content: 'linkAction', ellipsis: true, width: 180, }, { key: 'textListRow', title: '文本列表(行折叠)', type: 'text', content: 'textList', width: 220, maxRows: 2, group: '内容字段', }, { key: 'linkList', type: 'link', title: '链接列表', width: 220, group: '操作字段', content(record: ExampleTableRow) { return [ record.linkAction, { label: '帮助文档入口(示例)', to: location.href, target: '_blank' }, { label: '操作审计记录(示例)', to: location.href, target: '_blank' }, ] }, }, { key: 'custom', title: '自定义组件', type: 'component', component: Input, width: 200, group: '扩展字段', props: { placeholder: '示例输入框(component)', onChange() { console.log('change') }, }, }, { key: 'customSlotCell', title: '自定义插槽', type: 'text', content: 'customSlotCell', width: 180, slotName: 'customBodyCell', group: '扩展字段', }, { key: 'status', title: '状态', type: 'text', content: 'status', width: 100, fixed: 'right', group: '基础信息', }, { key: 'createTime', title: '创建时间', type: 'text', content: 'createTime', width: 180, fixed: 'right', group: '基础信息', }, { key: 'actions', type: 'button', title: '操作', fixed: 'right', width: 200, configurable: false, group: '操作字段', content(record: ExampleTableRow) { return [ { label: '编辑', onClick() { message.info(`编辑记录:${record.id}`) }, }, { label: '删除', onClick: options.onDelete, }, { label: '详情', onClick() { window.open(record.linkAction.to, '_blank') }, }, { label: '上线', disabled: record.status === '启用', }, { label: '下线', disabled: record.status === '禁用', }, ] }, }, ] }