wip: Table component developing

This commit is contained in:
陈凯龙 2022-02-08 15:49:23 +08:00
parent 7b7fcfef59
commit 7ef216c87e
3 changed files with 11 additions and 13 deletions

View File

@ -67,7 +67,7 @@ export default defineComponent({
const rnderTableColumn = (columns: TableColumn[]) => { const rnderTableColumn = (columns: TableColumn[]) => {
return (props.selection ? [renderTableSelection()] : []).concat( return (props.selection ? [renderTableSelection()] : []).concat(
columns.map((v, i) => { columns.map((v) => {
if (v.type === 'index') { if (v.type === 'index') {
return ( return (
<ElTableColumn <ElTableColumn
@ -89,11 +89,9 @@ export default defineComponent({
prop={v.field} prop={v.field}
> >
{{ {{
default: () => default: (data: TableSlotDefault) =>
// @ts-ignore // @ts-ignore
getSlot(slots, v.field, { row: props.data[i], field: v.field, index: i }) || getSlot(slots, v.field, data) || v?.formatter?.() || data.row[v.field],
v?.formatter?.() ||
props.data[i][v.field],
// @ts-ignore // @ts-ignore
header: getSlot(slots, `${v.field}-header`) header: getSlot(slots, `${v.field}-header`)
}} }}

View File

@ -77,7 +77,7 @@ const getTableList = async () => {
getTableList() getTableList()
const acitonFn = (data: TableColumnDefault) => { const acitonFn = (data: TableSlotDefault) => {
console.log(data) console.log(data)
} }
</script> </script>
@ -86,9 +86,9 @@ const acitonFn = (data: TableColumnDefault) => {
<ContentWrap :title="t('tableDemo.table')" :message="t('tableDemo.tableDes')"> <ContentWrap :title="t('tableDemo.table')" :message="t('tableDemo.tableDes')">
<Table :columns="columns" :data="tableDataList" :loading="loading"> <Table :columns="columns" :data="tableDataList" :loading="loading">
<template #action="data"> <template #action="data">
<ElButton @click="acitonFn(data as TableColumnDefault)">{{ <ElButton type="primary" @click="acitonFn(data as TableSlotDefault)">
t('tableDemo.action') {{ t('tableDemo.action') }}
}}</ElButton> </ElButton>
</template> </template>
</Table> </Table>
</ContentWrap> </ContentWrap>

View File

@ -3,8 +3,8 @@ declare type TableColumn = {
label?: string label?: string
} & Recordable } & Recordable
declare type TableColumnDefault = { declare type TableSlotDefault = {
row: Recordable row: Recordable
field: string column: TableColumn
index: number $index: number
} } & Recordable