fix: resolve BasicTable component ts type error
parent
8e25a3aa09
commit
b2ade25899
|
@ -113,12 +113,12 @@ const {
|
|||
emit,
|
||||
)
|
||||
|
||||
function handleTableChange(...args) {
|
||||
onTableChange.call(undefined, ...args)
|
||||
emit('change', ...args)
|
||||
function handleTableChange(pagination: any, filters: any, sorter: any, extra: any) {
|
||||
onTableChange(pagination, filters, sorter)
|
||||
emit('change', pagination, filters, sorter)
|
||||
// 解决通过useTable注册onChange时不起作用的问题
|
||||
const { onChange } = unref(getProps)
|
||||
onChange && isFunction(onChange) && onChange.call(undefined, ...args)
|
||||
onChange && isFunction(onChange) && onChange(pagination, filters, sorter, extra)
|
||||
}
|
||||
|
||||
const { getViewColumns, getColumns, setCacheColumnsByField, setCacheColumns, setColumns, getColumnsRef, getCacheColumns } = useColumns(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<script lang="tsx">
|
||||
import type { PropType } from 'vue'
|
||||
import { computed, defineComponent } from 'vue'
|
||||
import type { ColumnType } from 'ant-design-vue/lib/table/interface'
|
||||
import type { BasicColumn } from '../types/table'
|
||||
import BasicHelp from '/@/components/Basic/src/BasicHelp.vue'
|
||||
import EditTableHeaderCell from './EditTableHeaderIcon.vue'
|
||||
|
@ -14,22 +15,22 @@ export default defineComponent({
|
|||
},
|
||||
props: {
|
||||
column: {
|
||||
type: Object as PropType<BasicColumn>,
|
||||
type: Object as PropType<ColumnType<any>>,
|
||||
default: () => ({}),
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
const { prefixCls } = useDesign('basic-table-header-cell')
|
||||
|
||||
const getIsEdit = computed(() => !!props.column?.edit)
|
||||
const getIsEdit = computed(() => !!(props.column as BasicColumn)?.edit)
|
||||
const getTitle = computed(() => {
|
||||
const column = props.column
|
||||
const column = props.column as BasicColumn
|
||||
if (typeof column.customHeaderRender === 'function')
|
||||
return column.customHeaderRender(props.column)
|
||||
return column.customHeaderRender(column)
|
||||
|
||||
return props.column?.customTitle || props.column?.title
|
||||
return column?.customTitle || props.column?.title
|
||||
})
|
||||
const getHelpMessage = computed(() => props.column?.helpMessage)
|
||||
const getHelpMessage = computed(() => (props.column as BasicColumn)?.helpMessage)
|
||||
|
||||
return () => {
|
||||
return (
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import type { ComputedRef, Ref } from 'vue'
|
||||
import { computed, reactive, ref, toRaw, unref, watch } from 'vue'
|
||||
import { cloneDeep, isEqual } from 'lodash-es'
|
||||
import type { ColumnType } from 'ant-design-vue/es/table'
|
||||
import type { BasicColumn, BasicTableProps, CellFormat, GetColumnsParams } from '../types/table'
|
||||
import type { PaginationProps } from '../types/pagination'
|
||||
import { renderEditCell } from '../components/editable'
|
||||
|
@ -54,6 +55,7 @@ function handleIndexColumn(
|
|||
const indIndex = columns.findIndex(column => column.flag === INDEX_COLUMN_FLAG)
|
||||
if (showIndexColumn)
|
||||
pushIndexColumns = indIndex === -1
|
||||
|
||||
else if (!showIndexColumn && indIndex !== -1)
|
||||
columns.splice(indIndex, 1)
|
||||
})
|
||||
|
@ -147,7 +149,7 @@ export function useColumns(propsRef: ComputedRef<BasicTableProps>, getPagination
|
|||
if (!slots || !slots?.title)
|
||||
column.customTitle = column.title
|
||||
|
||||
const isDefaultAction = [INDEX_COLUMN_FLAG, ACTION_COLUMN_FLAG].includes(flag)
|
||||
const isDefaultAction = [INDEX_COLUMN_FLAG, ACTION_COLUMN_FLAG].includes(flag!)
|
||||
if (!customRender && format && !edit && !isDefaultAction) {
|
||||
column.customRender = ({ text, record, index }) => {
|
||||
return formatCell(text, format, record, index)
|
||||
|
@ -252,12 +254,19 @@ export function useColumns(propsRef: ComputedRef<BasicTableProps>, getPagination
|
|||
return
|
||||
cacheColumns = columns.filter(item => !item.flag)
|
||||
}
|
||||
/**
|
||||
* 拖拽列宽修改列的宽度
|
||||
*/
|
||||
function setColumnWidth(w: number, col: ColumnType<BasicColumn>) {
|
||||
col.width = w
|
||||
}
|
||||
|
||||
return {
|
||||
getColumnsRef,
|
||||
getCacheColumns,
|
||||
getColumns,
|
||||
setColumns,
|
||||
setColumnWidth,
|
||||
getViewColumns,
|
||||
setCacheColumnsByField,
|
||||
setCacheColumns,
|
||||
|
|
Loading…
Reference in New Issue