@aquiferre/ui-kit 0.4.4 → 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.
- package/components/Pagination.vue +23 -6
- package/package.json +1 -1
|
@@ -32,14 +32,12 @@
|
|
|
32
32
|
下一页 →
|
|
33
33
|
</button>
|
|
34
34
|
<select
|
|
35
|
-
:value="
|
|
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="
|
|
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
|
-
|
|
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)
|