import { defineComponent, h, onUnmounted, inject, ref, Ref, PropType, provide, onMounted } from 'vue' import { XEColumnInstance, watchColumn, assemColumn, destroyColumn } from '../../table/src/util' import Cell from '../../table/src/cell' import { VxeTableConstructor, VxeTablePrivateMethods, VxeColumnPropTypes, VxeColumnProps } from '../../../types/all' export const columnProps = { // 列唯一主键 colId: [String, Number] as PropType, // 渲染类型 index,radio,checkbox,expand,html type: String as PropType, // 列字段名 field: String as PropType, // 列标题 title: String as PropType, // 列宽度 width: [Number, String] as PropType, // 列最小宽度,把剩余宽度按比例分配 minWidth: [Number, String] as PropType, // 列最大宽度 maxWidth: [Number, String] as PropType, // 是否允许拖动列宽调整大小 resizable: { type: Boolean as PropType, default: null }, // 将列固定在左侧或者右侧 fixed: String as PropType, // 列对其方式 align: String as PropType, // 表头对齐方式 headerAlign: String as PropType, // 表尾列的对齐方式 footerAlign: String as PropType, // 当内容过长时显示为省略号 showOverflow: { type: [Boolean, String] as PropType, default: null }, // 当表头内容过长时显示为省略号 showHeaderOverflow: { type: [Boolean, String] as PropType, default: null }, // 当表尾内容过长时显示为省略号 showFooterOverflow: { type: [Boolean, String] as PropType, default: null }, // 给单元格附加 className className: [String, Function] as PropType, // 给表头单元格附加 className headerClassName: [String, Function] as PropType, // 给表尾单元格附加 className footerClassName: [String, Function] as PropType, // 格式化显示内容 formatter: [Function, Array, String] as PropType>, // 是否允许排序 sortable: Boolean as PropType, // 自定义排序的属性 sortBy: [String, Function] as PropType, // 排序的字段类型,比如字符串转数值等 sortType: String as PropType, // 配置筛选条件数组 filters: { type: Array as PropType, default: null }, // 筛选是否允许多选 filterMultiple: { type: Boolean as PropType, default: true }, // 自定义筛选方法 filterMethod: Function as PropType>, // 筛选重置方法 filterResetMethod: Function as PropType, // 筛选复原方法 filterRecoverMethod: Function as PropType, // 筛选模板配置项 filterRender: Object as PropType, // 指定为树节点 treeNode: Boolean as PropType, // 是否可视 visible: { type: Boolean as PropType, default: null }, // 表头单元格数据导出方法 headerExportMethod: Function as PropType, // 单元格数据导出方法 exportMethod: Function as PropType, // 表尾单元格数据导出方法 footerExportMethod: Function as PropType, // 已废弃,被 titlePrefix 替换 titleHelp: Object as PropType, // 标题前缀图标配置项 titlePrefix: Object as PropType, // 标题后缀图标配置项 titleSuffix: Object as PropType, // 单元格值类型 cellType: String as PropType, // 单元格渲染配置项 cellRender: Object as PropType>, // 单元格编辑渲染配置项 editRender: Object as PropType, // 内容渲染配置项 contentRender: Object as PropType, // 额外的参数 params: Object as PropType } export default defineComponent({ name: 'VxeColumn', props: columnProps, setup (props, { slots }) { const refElem = ref() as Ref const $xetable = inject('$xetable', {} as VxeTableConstructor & VxeTablePrivateMethods) const colgroup = inject('xecolgroup', null as XEColumnInstance | null) const column = Cell.createColumn($xetable, props as VxeColumnProps) column.slots = slots provide('$xegrid', null) watchColumn($xetable, props, column) onMounted(() => { assemColumn($xetable, refElem.value, column, colgroup) }) onUnmounted(() => { destroyColumn($xetable, column) }) const renderVN = () => { return h('div', { ref: refElem }) } return renderVN } })