fix: resolve BasicTable component ts type error

pull/38/head
xingyu 2023-10-23 09:55:09 +08:00
parent 8e25a3aa09
commit b2ade25899
3 changed files with 21 additions and 11 deletions

View File

@ -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)
// useTableonChange
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(

View File

@ -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 (

View File

@ -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,