feat:新增 table 组件
This commit is contained in:
48
resources/admin/components/catchTable/ctcolumns.tsx
Normal file
48
resources/admin/components/catchTable/ctcolumns.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import { defineComponent } from 'vue'
|
||||
import { ElTableColumn } from 'element-plus'
|
||||
import { Column } from './ctable'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'DynamicTable',
|
||||
props: {
|
||||
columns: {
|
||||
type: Array<Column>,
|
||||
default: []
|
||||
},
|
||||
api: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const renderColumns = (columns: Array<Column>) => {
|
||||
return columns.map(column => {
|
||||
if (column.children) {
|
||||
return (
|
||||
<ElTableColumn label="{column.label}" key="{column.label}">
|
||||
{renderColumns(column.children)}
|
||||
</ElTableColumn>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<ElTableColumn label="{column.label}" prop="{column.prop}" key="{column.prop}">
|
||||
{{
|
||||
default: (row: any) => {
|
||||
// 使用默认插槽
|
||||
return row[column.prop as string]
|
||||
},
|
||||
customSlot: (row: any) => {
|
||||
// 使用具名插槽 customSlot
|
||||
return slots.customSlot ? slots.customSlot({ column, row }) : null
|
||||
}
|
||||
}}
|
||||
</ElTableColumn>
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return renderColumns(props.columns)
|
||||
// return () => <ElTable data="{props.data}">{renderColumns(props.columns)}</ElTable>
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user