This commit is contained in:
guochunsi
2026-01-06 16:39:57 +08:00
parent 7f91263205
commit 9e583c3c30
32 changed files with 2830 additions and 481 deletions

View File

@@ -0,0 +1,64 @@
<template>
<el-table-column
v-if="shouldShow"
v-bind="$attrs"
>
<template v-for="(_, name) in $slots" :key="name" #[name]="slotProps">
<slot :name="name" v-bind="slotProps" />
</template>
</el-table-column>
</template>
<script setup lang="ts">
import { computed, inject } from 'vue'
interface Props {
prop?: string
label?: string
// 其他 el-table-column 的所有属性都通过 $attrs 传递
}
const props = withDefaults(defineProps<Props>(), {
prop: '',
label: ''
})
// 从父组件注入 isColumnVisible 函数
const isColumnVisible = inject<(propOrLabel: string) => boolean>('isColumnVisible', () => true)
// 计算是否应该显示该列
const shouldShow = computed(() => {
// 优先使用 prop如果没有 prop 则使用 label
let key = props.prop || props.label || ''
if (!key) {
// 如果没有 prop 和 label默认显示可能是序号列等特殊列
return true
}
// 如果 key 是 label尝试通过 labelToPropMap 映射到 prop
// 这样可以确保与 useTableColumns 的提取逻辑一致
if (!props.prop && props.label) {
const labelToPropMap: Record<string, string> = {
'是否退休': 'tied',
'姓名/工号': 'nameNo',
'性别': 'sex',
'部门': 'deptName',
'学历学位': 'dgreeName',
'职称等级': 'professionalTitle',
'岗位级别': 'stationLevelName',
'职业资格等级': 'levelName',
'职业资格工种': 'workName',
'用工性质': 'employmentNatureName',
'手机': 'telPhone',
'家庭住址': 'homeAddress',
'授课类型': 'teacherCate',
'操作': 'action',
}
// 如果 label 在映射表中,使用映射后的 prop否则使用 label
key = labelToPropMap[props.label] || props.label
}
return isColumnVisible(key)
})
</script>