feat: BasicTable 组件 HeaderCell 新增 customHeaderRender
							parent
							
								
									4fbe0d686b
								
							
						
					
					
						commit
						afd2d946c5
					
				|  | @ -298,7 +298,9 @@ emit('register', tableAction, formActions) | |||
|         <slot :name="item" v-bind="data || {}" /> | ||||
|       </template> | ||||
|       <template #headerCell="{ column }"> | ||||
|         <HeaderCell :column="column" /> | ||||
|         <slot name="headerCell" v-bind="{ column }"> | ||||
|           <HeaderCell :column="column" /> | ||||
|         </slot> | ||||
|       </template> | ||||
|       <!-- 增加对antdv3.x兼容 --> | ||||
|       <template #bodyCell="data"> | ||||
|  |  | |||
|  | @ -7,7 +7,7 @@ defineProps({ title: { type: String, default: '' } }) | |||
| </script> | ||||
| 
 | ||||
| <template> | ||||
|   <span> | ||||
|   <span class="edit-header-cell"> | ||||
|     <slot /> | ||||
|     {{ title }} | ||||
|     <FormOutlined /> | ||||
|  |  | |||
|  | @ -1,41 +1,63 @@ | |||
| <script lang="ts" setup> | ||||
| import { computed } from 'vue' | ||||
| <script lang="tsx"> | ||||
| import type { PropType } from 'vue' | ||||
| import { computed, defineComponent } from 'vue' | ||||
| import type { BasicColumn } from '../types/table' | ||||
| import BasicHelp from '/@/components/Basic/src/BasicHelp.vue' | ||||
| import EditTableHeaderCell from './EditTableHeaderIcon.vue' | ||||
| import BasicHelp from '@/components/Basic/src/BasicHelp.vue' | ||||
| 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({ | ||||
|   column: { | ||||
|     type: Object as PropType<BasicColumn>, | ||||
|     default: () => ({}), | ||||
|     const getIsEdit = computed(() => !!props.column?.edit) | ||||
|     const getTitle = computed(() => { | ||||
|       const column = props.column | ||||
|       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> | ||||
| 
 | ||||
| <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"> | ||||
| @prefix-cls: ~'@{namespace}-basic-table-header-cell'; | ||||
|   @prefix-cls: ~'@{namespace}-basic-table-header-cell'; | ||||
| 
 | ||||
| .@{prefix-cls} { | ||||
|   &__help { | ||||
|     margin-left: 8px; | ||||
|     color: rgb(0 0 0 / 65%) !important; | ||||
|   .@{prefix-cls} { | ||||
|     &__help { | ||||
|       margin-left: 8px; | ||||
|       color: rgb(0 0 0 / 65%) !important; | ||||
|     } | ||||
|   } | ||||
| } | ||||
| </style> | ||||
|  |  | |||
|  | @ -418,6 +418,9 @@ export interface BasicColumn extends ColumnProps<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
 | ||||
|   defaultHidden?: boolean | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 xingyu
						xingyu