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, emit,
) )
function handleTableChange(...args) { function handleTableChange(pagination: any, filters: any, sorter: any, extra: any) {
onTableChange.call(undefined, ...args) onTableChange(pagination, filters, sorter)
emit('change', ...args) emit('change', pagination, filters, sorter)
// useTableonChange // useTableonChange
const { onChange } = unref(getProps) 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( const { getViewColumns, getColumns, setCacheColumnsByField, setCacheColumns, setColumns, getColumnsRef, getCacheColumns } = useColumns(

View File

@ -1,6 +1,7 @@
<script lang="tsx"> <script lang="tsx">
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { ColumnType } from 'ant-design-vue/lib/table/interface'
import type { BasicColumn } from '../types/table' import type { BasicColumn } from '../types/table'
import BasicHelp from '/@/components/Basic/src/BasicHelp.vue' import BasicHelp from '/@/components/Basic/src/BasicHelp.vue'
import EditTableHeaderCell from './EditTableHeaderIcon.vue' import EditTableHeaderCell from './EditTableHeaderIcon.vue'
@ -14,22 +15,22 @@ export default defineComponent({
}, },
props: { props: {
column: { column: {
type: Object as PropType<BasicColumn>, type: Object as PropType<ColumnType<any>>,
default: () => ({}), default: () => ({}),
}, },
}, },
setup(props) { setup(props) {
const { prefixCls } = useDesign('basic-table-header-cell') 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 getTitle = computed(() => {
const column = props.column const column = props.column as BasicColumn
if (typeof column.customHeaderRender === 'function') 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 () => {
return ( return (

View File

@ -1,6 +1,7 @@
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { computed, reactive, ref, toRaw, unref, watch } from 'vue' import { computed, reactive, ref, toRaw, unref, watch } from 'vue'
import { cloneDeep, isEqual } from 'lodash-es' 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 { BasicColumn, BasicTableProps, CellFormat, GetColumnsParams } from '../types/table'
import type { PaginationProps } from '../types/pagination' import type { PaginationProps } from '../types/pagination'
import { renderEditCell } from '../components/editable' import { renderEditCell } from '../components/editable'
@ -54,6 +55,7 @@ function handleIndexColumn(
const indIndex = columns.findIndex(column => column.flag === INDEX_COLUMN_FLAG) const indIndex = columns.findIndex(column => column.flag === INDEX_COLUMN_FLAG)
if (showIndexColumn) if (showIndexColumn)
pushIndexColumns = indIndex === -1 pushIndexColumns = indIndex === -1
else if (!showIndexColumn && indIndex !== -1) else if (!showIndexColumn && indIndex !== -1)
columns.splice(indIndex, 1) columns.splice(indIndex, 1)
}) })
@ -147,7 +149,7 @@ export function useColumns(propsRef: ComputedRef<BasicTableProps>, getPagination
if (!slots || !slots?.title) if (!slots || !slots?.title)
column.customTitle = column.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) { if (!customRender && format && !edit && !isDefaultAction) {
column.customRender = ({ text, record, index }) => { column.customRender = ({ text, record, index }) => {
return formatCell(text, format, record, index) return formatCell(text, format, record, index)
@ -252,12 +254,19 @@ export function useColumns(propsRef: ComputedRef<BasicTableProps>, getPagination
return return
cacheColumns = columns.filter(item => !item.flag) cacheColumns = columns.filter(item => !item.flag)
} }
/**
*
*/
function setColumnWidth(w: number, col: ColumnType<BasicColumn>) {
col.width = w
}
return { return {
getColumnsRef, getColumnsRef,
getCacheColumns, getCacheColumns,
getColumns, getColumns,
setColumns, setColumns,
setColumnWidth,
getViewColumns, getViewColumns,
setCacheColumnsByField, setCacheColumnsByField,
setCacheColumns, setCacheColumns,