fix: 修复Table插槽传参错误

This commit is contained in:
kailong321200875 2023-08-11 17:48:50 +08:00
parent dce76f042d
commit 97344e68f5
10 changed files with 29 additions and 29 deletions

View File

@ -362,7 +362,7 @@ export default defineComponent({
return children && children.length return children && children.length
? renderTreeTableColumn(children) ? renderTreeTableColumn(children)
: props?.slots?.default : props?.slots?.default
? props.slots.default(args) ? props.slots.default(...args)
: v?.formatter : v?.formatter
? v?.formatter?.(data.row, data.column, get(data.row, v.field), data.$index) ? v?.formatter?.(data.row, data.column, get(data.row, v.field), data.$index)
: isImageUrl : isImageUrl
@ -459,7 +459,7 @@ export default defineComponent({
return children && children.length return children && children.length
? renderTreeTableColumn(children) ? renderTreeTableColumn(children)
: props?.slots?.default : props?.slots?.default
? props.slots.default(args) ? props.slots.default(...args)
: v?.formatter : v?.formatter
? v?.formatter?.(data.row, data.column, get(data.row, v.field), data.$index) ? v?.formatter?.(data.row, data.column, get(data.row, v.field), data.$index)
: isImageUrl : isImageUrl

View File

@ -85,7 +85,7 @@ const crudSchemas = reactive<CrudSchema[]>([
table: { table: {
slots: { slots: {
default: (data: any) => { default: (data: any) => {
return <>{data[0].row.departmentName}</> return <>{data.row.departmentName}</>
} }
} }
}, },
@ -119,7 +119,7 @@ const crudSchemas = reactive<CrudSchema[]>([
table: { table: {
slots: { slots: {
default: (data: any) => { default: (data: any) => {
const status = data[0].row.status const status = data.row.status
return ( return (
<> <>
<ElTag type={status === 0 ? 'danger' : 'success'}> <ElTag type={status === 0 ? 'danger' : 'success'}>
@ -215,13 +215,13 @@ const crudSchemas = reactive<CrudSchema[]>([
default: (data: any) => { default: (data: any) => {
return ( return (
<> <>
<ElButton type="primary" onClick={() => action(data[0].row, 'edit')}> <ElButton type="primary" onClick={() => action(data.row, 'edit')}>
{t('exampleDemo.edit')} {t('exampleDemo.edit')}
</ElButton> </ElButton>
<ElButton type="success" onClick={() => action(data[0].row, 'detail')}> <ElButton type="success" onClick={() => action(data.row, 'detail')}>
{t('exampleDemo.detail')} {t('exampleDemo.detail')}
</ElButton> </ElButton>
<ElButton type="danger" onClick={() => delData(data[0].row)}> <ElButton type="danger" onClick={() => delData(data.row)}>
{t('exampleDemo.del')} {t('exampleDemo.del')}
</ElButton> </ElButton>
</> </>

View File

@ -41,7 +41,7 @@ const tableColumns = reactive<TableColumn[]>([
label: t('menu.icon'), label: t('menu.icon'),
slots: { slots: {
default: (data: any) => { default: (data: any) => {
const icon = data[0].row.meta.icon const icon = data.row.meta.icon
if (icon) { if (icon) {
return ( return (
<> <>
@ -59,7 +59,7 @@ const tableColumns = reactive<TableColumn[]>([
label: t('menu.permission'), label: t('menu.permission'),
slots: { slots: {
default: (data: any) => { default: (data: any) => {
const permission = data[0].row.meta.permission const permission = data.row.meta.permission
return permission ? <>{permission.join(', ')}</> : null return permission ? <>{permission.join(', ')}</> : null
} }
} }
@ -69,7 +69,7 @@ const tableColumns = reactive<TableColumn[]>([
label: t('menu.component'), label: t('menu.component'),
slots: { slots: {
default: (data: any) => { default: (data: any) => {
const component = data[0].row.component const component = data.row.component
return <>{component === '#' ? '顶级目录' : component === '##' ? '子目录' : component}</> return <>{component === '#' ? '顶级目录' : component === '##' ? '子目录' : component}</>
} }
} }
@ -85,8 +85,8 @@ const tableColumns = reactive<TableColumn[]>([
default: (data: any) => { default: (data: any) => {
return ( return (
<> <>
<ElTag type={data[0].row.status === 0 ? 'danger' : 'success'}> <ElTag type={data.row.status === 0 ? 'danger' : 'success'}>
{data[0].row.status === 1 ? t('userDemo.enable') : t('userDemo.disable')} {data.row.status === 1 ? t('userDemo.enable') : t('userDemo.disable')}
</ElTag> </ElTag>
</> </>
) )
@ -99,7 +99,7 @@ const tableColumns = reactive<TableColumn[]>([
width: 240, width: 240,
slots: { slots: {
default: (data: any) => { default: (data: any) => {
const row = data[0].row const row = data.row
return ( return (
<> <>
<ElButton type="primary" onClick={() => action(row, 'edit')}> <ElButton type="primary" onClick={() => action(row, 'edit')}>

View File

@ -47,8 +47,8 @@ const tableColumns = reactive<TableColumn[]>([
default: (data: any) => { default: (data: any) => {
return ( return (
<> <>
<ElTag type={data[0].row.status === 0 ? 'danger' : 'success'}> <ElTag type={data.row.status === 0 ? 'danger' : 'success'}>
{data[0].row.status === 1 ? t('userDemo.enable') : t('userDemo.disable')} {data.row.status === 1 ? t('userDemo.enable') : t('userDemo.disable')}
</ElTag> </ElTag>
</> </>
) )
@ -69,7 +69,7 @@ const tableColumns = reactive<TableColumn[]>([
width: 240, width: 240,
slots: { slots: {
default: (data: any) => { default: (data: any) => {
const row = data[0].row const row = data.row
return ( return (
<> <>
<ElButton type="primary" onClick={() => action(row, 'edit')}> <ElButton type="primary" onClick={() => action(row, 'edit')}>

View File

@ -150,7 +150,7 @@ const crudSchemas = reactive<CrudSchema[]>([
width: 240, width: 240,
slots: { slots: {
default: (data: any) => { default: (data: any) => {
const row = data[0].row as DepartmentUserItem const row = data.row as DepartmentUserItem
return ( return (
<> <>
<ElButton type="primary" onClick={() => action(row, 'edit')}> <ElButton type="primary" onClick={() => action(row, 'edit')}>

View File

@ -1,7 +1,7 @@
<script setup lang="tsx"> <script setup lang="tsx">
import { ContentWrap } from '@/components/ContentWrap' import { ContentWrap } from '@/components/ContentWrap'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { Table, TableColumn, TableSlotDefault } from '@/components/Table' import { Table, TableColumn } from '@/components/Table'
import { getTableListApi } from '@/api/table' import { getTableListApi } from '@/api/table'
import { TableData } from '@/api/table/types' import { TableData } from '@/api/table/types'
import { ref, h } from 'vue' import { ref, h } from 'vue'
@ -87,7 +87,7 @@ const getTableList = async (params?: Params) => {
getTableList() getTableList()
const actionFn = (data: TableSlotDefault) => { const actionFn = (data: any) => {
console.log(data) console.log(data)
} }
</script> </script>

View File

@ -1,7 +1,7 @@
<script setup lang="tsx"> <script setup lang="tsx">
import { ContentWrap } from '@/components/ContentWrap' import { ContentWrap } from '@/components/ContentWrap'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { Table, TableColumn, TableSlotDefault } from '@/components/Table' import { Table, TableColumn } from '@/components/Table'
import { getTreeTableListApi } from '@/api/table' import { getTreeTableListApi } from '@/api/table'
import { reactive, unref } from 'vue' import { reactive, unref } from 'vue'
import { ElTag, ElButton } from 'element-plus' import { ElTag, ElButton } from 'element-plus'
@ -86,7 +86,7 @@ const columns = reactive<TableColumn[]>([
} }
]) ])
const actionFn = (data: TableSlotDefault) => { const actionFn = (data) => {
console.log(data) console.log(data)
} }
</script> </script>

View File

@ -30,8 +30,8 @@ const columns = reactive<TableColumn[]>([
field: 'expand', field: 'expand',
type: 'expand', type: 'expand',
slots: { slots: {
default: (data: TableSlotDefault[]) => { default: (data: TableSlotDefault) => {
const { row } = data[0] const { row } = data
return ( return (
<div class="ml-30px"> <div class="ml-30px">
<div> <div>

View File

@ -212,13 +212,13 @@ const crudSchemas = reactive<CrudSchema[]>([
default: (data: any) => { default: (data: any) => {
return ( return (
<> <>
<ElButton type="primary" onClick={() => action(data[0].row, 'edit')}> <ElButton type="primary" onClick={() => action(data.row, 'edit')}>
{t('exampleDemo.edit')} {t('exampleDemo.edit')}
</ElButton> </ElButton>
<ElButton type="success" onClick={() => action(data[0].row, 'detail')}> <ElButton type="success" onClick={() => action(data.row, 'detail')}>
{t('exampleDemo.detail')} {t('exampleDemo.detail')}
</ElButton> </ElButton>
<ElButton type="danger" onClick={() => delData(data[0].row)}> <ElButton type="danger" onClick={() => delData(data.row)}>
{t('exampleDemo.del')} {t('exampleDemo.del')}
</ElButton> </ElButton>
</> </>

View File

@ -229,13 +229,13 @@ const crudSchemas = reactive<CrudSchema[]>([
default: (data: any) => { default: (data: any) => {
return ( return (
<> <>
<ElButton type="primary" onClick={() => action(data[0].row, 'edit')}> <ElButton type="primary" onClick={() => action(data.row, 'edit')}>
{t('exampleDemo.edit')} {t('exampleDemo.edit')}
</ElButton> </ElButton>
<ElButton type="success" onClick={() => action(data[0].row, 'detail')}> <ElButton type="success" onClick={() => action(data.row, 'detail')}>
{t('exampleDemo.detail')} {t('exampleDemo.detail')}
</ElButton> </ElButton>
<ElButton type="danger" onClick={() => delData(data[0].row)}> <ElButton type="danger" onClick={() => delData(data.row)}>
{t('exampleDemo.del')} {t('exampleDemo.del')}
</ElButton> </ElButton>
</> </>