Эх сурвалжийг харах

wip: Table component developing

陈凯龙 3 жил өмнө
parent
commit
7ef216c87e

+ 3 - 5
src/components/Table/src/Table.vue

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

+ 4 - 4
src/views/Components/Table/DefaultTable.vue

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

+ 4 - 4
types/componentType/table.d.ts

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