useTableColumnSet.ts 595 B

123456789101112131415161718192021222324
  1. import type {
  2. KeyType,
  3. TableColumn,
  4. TableColumnInGroup,
  5. } from '../components/ColumnSet/index.vue'
  6. import { Ref } from 'vue'
  7. export default function useTableColumnSet(
  8. tableColumns: Ref<TableColumnInGroup[] | TableColumn[]>
  9. ) {
  10. const filterColumnKeys = ref<KeyType[]>([])
  11. const filteredColumns = computed(() =>
  12. tableColumns.value.filter(({ dataKey }) =>
  13. filterColumnKeys.value.includes(dataKey)
  14. )
  15. )
  16. const columnChecked = (checkedColumnKeys: string[]) => {
  17. filterColumnKeys.value = checkedColumnKeys
  18. }
  19. return {
  20. columnChecked,
  21. filteredColumns,
  22. }
  23. }