优化
This commit is contained in:
@@ -63,13 +63,13 @@ const props = withDefaults(defineProps<{
|
||||
total?: number
|
||||
pageSizes?: number[]
|
||||
preferenceKey?: string
|
||||
showColumnSettings?: boolean
|
||||
columnSettingsMode?: 'auto' | 'show' | 'hide'
|
||||
}>(), {
|
||||
loading: false,
|
||||
emptyText: '暂无数据',
|
||||
total: undefined,
|
||||
pageSizes: () => [10, 20, 50, 100],
|
||||
showColumnSettings: true,
|
||||
columnSettingsMode: 'auto',
|
||||
})
|
||||
|
||||
const page = defineModel<number>('page', { default: 1 })
|
||||
@@ -78,7 +78,6 @@ const slots = useSlots()
|
||||
const preferenceScope = inject(UI_PREFERENCE_SCOPE, computed(() => 'anonymous'))
|
||||
const preference = ref<LayoutPreferenceSnapshot>({ version: 1, order: [], hidden: [] })
|
||||
const tableRef = ref<{ doLayout: () => void }>()
|
||||
const preferenceEnabled = computed(() => Boolean(props.preferenceKey && props.showColumnSettings))
|
||||
|
||||
function columnId(column: DataTableColumn) {
|
||||
const value = column.key ?? column.columnKey ?? column.prop ?? column.property
|
||||
@@ -102,6 +101,12 @@ function columnHideable(column: DataTableColumn) {
|
||||
|
||||
const configurableColumns = computed(() => props.columns.filter((column) => columnId(column)))
|
||||
const columnKeys = computed(() => configurableColumns.value.map((column) => columnId(column) as string))
|
||||
const columnSettingsVisible = computed(() => (
|
||||
props.columnSettingsMode === 'auto'
|
||||
? configurableColumns.value.filter(columnHideable).length > 4
|
||||
: props.columnSettingsMode === 'show'
|
||||
))
|
||||
const preferenceEnabled = computed(() => Boolean(props.preferenceKey && columnSettingsVisible.value))
|
||||
|
||||
function anchorSystemColumns(order: readonly string[]) {
|
||||
const columnsByKey = new Map(configurableColumns.value.map((column) => [columnId(column) as string, column]))
|
||||
@@ -143,7 +148,7 @@ const orderedColumns = computed(() => {
|
||||
})
|
||||
const visibleColumns = computed(() => orderedColumns.value.filter((column) => {
|
||||
const id = columnId(column)
|
||||
return !id || !columnHideable(column) || !preference.value.hidden.includes(id)
|
||||
return !preferenceEnabled.value || !id || !columnHideable(column) || !preference.value.hidden.includes(id)
|
||||
}))
|
||||
const visibleHideableCount = computed(() => visibleColumns.value.filter(columnHideable).length)
|
||||
const preferenceItems = computed<LayoutPreferenceItem[]>(() => orderedColumns.value.flatMap((column) => {
|
||||
|
||||
Reference in New Issue
Block a user