@aquiferre/ui-kit 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  <template>
2
- <div class="table-container" :class="{ relative: loading }" :data-testid="baseTestId">
3
- <table class="table">
2
+ <div class="table-container" :class="{ relative: loading, 'overflow-x-auto': scrollable }" :data-testid="baseTestId">
3
+ <table class="table" :class="{ 'min-w-full': scrollable, 'w-full': !scrollable }">
4
4
  <thead class="table-header">
5
5
  <tr>
6
6
  <th v-if="selectable" class="table-header-cell w-8">
@@ -82,6 +82,7 @@ const props = withDefaults(defineProps<{
82
82
  sort?: { field: string; order: 'asc' | 'desc' } | null
83
83
  rowTestIdPrefix?: string
84
84
  testId?: string
85
+ scrollable?: boolean
85
86
  }>(), {
86
87
  loading: false,
87
88
  emptyText: '暂无数据',
@@ -90,6 +91,7 @@ const props = withDefaults(defineProps<{
90
91
  rowKey: 'id',
91
92
  sort: null,
92
93
  rowTestIdPrefix: undefined,
94
+ scrollable: false,
93
95
  })
94
96
 
95
97
  const attrs = useAttrs()
@@ -32,14 +32,12 @@
32
32
  下一页 →
33
33
  </button>
34
34
  <select
35
- :value="pageSize"
35
+ :value="selectedPageSize"
36
36
  class="select ml-2"
37
37
  :data-testid="baseTestId ? `${baseTestId}-size-select` : undefined"
38
38
  @change="changePageSize(Number(($event.target as HTMLSelectElement).value))"
39
39
  >
40
- <option :value="10">10条/页</option>
41
- <option :value="20">20条/页</option>
42
- <option :value="50">50条/页</option>
40
+ <option v-for="size in sizeOptions" :key="size" :value="size">{{ size }}条/页</option>
43
41
  </select>
44
42
  </div>
45
43
  </div>
@@ -49,12 +47,18 @@
49
47
  // @ts-nocheck
50
48
  import { computed, useAttrs } from 'vue'
51
49
 
52
- const props = defineProps<{
50
+ // 默认页容量选项(自定义值通过 pageSizeOptions 排在其前)
51
+ const DEFAULT_PAGE_SIZES = [20, 50, 100, 200, 500, 1000, 5000]
52
+
53
+ const props = withDefaults(defineProps<{
53
54
  page: number
54
55
  pageSize: number
55
56
  total: number
57
+ pageSizeOptions?: number[]
56
58
  testId?: string
57
- }>()
59
+ }>(), {
60
+ pageSizeOptions: () => [],
61
+ })
58
62
 
59
63
  const attrs = useAttrs()
60
64
  const baseTestId = computed<string | undefined>(() => props.testId ?? (attrs['data-testid'] as string | undefined))
@@ -65,6 +69,19 @@ const emit = defineEmits<{
65
69
  change: [page: number, pageSize: number]
66
70
  }>()
67
71
 
72
+ const sizeOptions = computed(() => {
73
+ const custom = (props.pageSizeOptions || []).filter(size => Number.isInteger(size) && size > 0)
74
+ const merged = [...custom]
75
+ for (const size of DEFAULT_PAGE_SIZES) {
76
+ if (!merged.includes(size)) merged.push(size)
77
+ }
78
+ return merged
79
+ })
80
+
81
+ const selectedPageSize = computed(() =>
82
+ sizeOptions.value.includes(props.pageSize) ? props.pageSize : sizeOptions.value[0]
83
+ )
84
+
68
85
  const totalPages = computed(() => Math.max(1, Math.ceil(props.total / props.pageSize)))
69
86
 
70
87
  const startItem = computed(() => (props.page - 1) * props.pageSize + 1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aquiferre/ui-kit",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "index.ts",