feat: BasicTable 组件 HeaderCell 新增 customHeaderRender
parent
4fbe0d686b
commit
afd2d946c5
|
@ -298,7 +298,9 @@ emit('register', tableAction, formActions)
|
||||||
<slot :name="item" v-bind="data || {}" />
|
<slot :name="item" v-bind="data || {}" />
|
||||||
</template>
|
</template>
|
||||||
<template #headerCell="{ column }">
|
<template #headerCell="{ column }">
|
||||||
<HeaderCell :column="column" />
|
<slot name="headerCell" v-bind="{ column }">
|
||||||
|
<HeaderCell :column="column" />
|
||||||
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
<!-- 增加对antdv3.x兼容 -->
|
<!-- 增加对antdv3.x兼容 -->
|
||||||
<template #bodyCell="data">
|
<template #bodyCell="data">
|
||||||
|
|
|
@ -7,7 +7,7 @@ defineProps({ title: { type: String, default: '' } })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<span>
|
<span class="edit-header-cell">
|
||||||
<slot />
|
<slot />
|
||||||
{{ title }}
|
{{ title }}
|
||||||
<FormOutlined />
|
<FormOutlined />
|
||||||
|
|
|
@ -1,41 +1,63 @@
|
||||||
<script lang="ts" setup>
|
<script lang="tsx">
|
||||||
import { computed } from 'vue'
|
import type { PropType } from 'vue'
|
||||||
|
import { computed, defineComponent } from 'vue'
|
||||||
import type { BasicColumn } from '../types/table'
|
import type { BasicColumn } from '../types/table'
|
||||||
|
import BasicHelp from '/@/components/Basic/src/BasicHelp.vue'
|
||||||
import EditTableHeaderCell from './EditTableHeaderIcon.vue'
|
import EditTableHeaderCell from './EditTableHeaderIcon.vue'
|
||||||
import BasicHelp from '@/components/Basic/src/BasicHelp.vue'
|
|
||||||
import { useDesign } from '@/hooks/web/useDesign'
|
import { useDesign } from '@/hooks/web/useDesign'
|
||||||
|
|
||||||
defineOptions({ name: 'TableHeaderCell' })
|
export default defineComponent({
|
||||||
|
name: 'TableHeaderCell',
|
||||||
|
components: {
|
||||||
|
EditTableHeaderCell,
|
||||||
|
BasicHelp,
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
column: {
|
||||||
|
type: Object as PropType<BasicColumn>,
|
||||||
|
default: () => ({}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
setup(props) {
|
||||||
|
const { prefixCls } = useDesign('basic-table-header-cell')
|
||||||
|
|
||||||
const props = defineProps({
|
const getIsEdit = computed(() => !!props.column?.edit)
|
||||||
column: {
|
const getTitle = computed(() => {
|
||||||
type: Object as PropType<BasicColumn>,
|
const column = props.column
|
||||||
default: () => ({}),
|
if (typeof column.customHeaderRender === 'function')
|
||||||
|
return column.customHeaderRender(props.column)
|
||||||
|
|
||||||
|
return props.column?.customTitle || props.column?.title
|
||||||
|
})
|
||||||
|
const getHelpMessage = computed(() => props.column?.helpMessage)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{getIsEdit.value
|
||||||
|
? (
|
||||||
|
<EditTableHeaderCell>{getTitle.value}</EditTableHeaderCell>
|
||||||
|
)
|
||||||
|
: (
|
||||||
|
<span class="default-header-cell">{getTitle.value}</span>
|
||||||
|
)}
|
||||||
|
{getHelpMessage.value && (
|
||||||
|
<BasicHelp text={getHelpMessage.value} class={`${prefixCls}__help`} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const { prefixCls } = useDesign('basic-table-header-cell')
|
|
||||||
|
|
||||||
const getIsEdit = computed(() => !!props.column?.edit)
|
|
||||||
const getTitle = computed(() => props.column?.customTitle || props.column?.title)
|
|
||||||
const getHelpMessage = computed(() => props.column?.helpMessage)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
|
||||||
<EditTableHeaderCell v-if="getIsEdit">
|
|
||||||
{{ getTitle }}
|
|
||||||
</EditTableHeaderCell>
|
|
||||||
<span v-else>{{ getTitle }}</span>
|
|
||||||
<BasicHelp v-if="getHelpMessage" :text="getHelpMessage" :class="`${prefixCls}__help`" />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
@prefix-cls: ~'@{namespace}-basic-table-header-cell';
|
@prefix-cls: ~'@{namespace}-basic-table-header-cell';
|
||||||
|
|
||||||
.@{prefix-cls} {
|
.@{prefix-cls} {
|
||||||
&__help {
|
&__help {
|
||||||
margin-left: 8px;
|
margin-left: 8px;
|
||||||
color: rgb(0 0 0 / 65%) !important;
|
color: rgb(0 0 0 / 65%) !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -418,6 +418,9 @@ export interface BasicColumn extends ColumnProps<Recordable> {
|
||||||
|
|
||||||
slots?: Recordable
|
slots?: Recordable
|
||||||
|
|
||||||
|
// 自定义header渲染
|
||||||
|
customHeaderRender?: (column: BasicColumn) => string | VNodeChild | JSX.Element
|
||||||
|
|
||||||
// Whether to hide the column by default, it can be displayed in the column configuration
|
// Whether to hide the column by default, it can be displayed in the column configuration
|
||||||
defaultHidden?: boolean
|
defaultHidden?: boolean
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue