fix paging

This commit is contained in:
samunohito 2024-02-06 20:42:43 +09:00
parent a655cece33
commit 3a4a5dc6f0
1 changed files with 8 additions and 3 deletions

View File

@ -43,14 +43,19 @@ const props = defineProps<{
buttonCount: number; buttonCount: number;
}>(); }>();
const { current, max, buttonCount } = toRefs(props); const { current, max } = toRefs(props);
const buttonCount = computed(() => Math.min(max.value, props.buttonCount));
const buttonCountHalf = computed(() => Math.floor(buttonCount.value / 2)); const buttonCountHalf = computed(() => Math.floor(buttonCount.value / 2));
const buttonCountStart = computed(() => Math.min(Math.max(min, current.value - buttonCountHalf.value), max.value - buttonCount.value + 1)); const buttonCountStart = computed(() => Math.min(Math.max(min, current.value - buttonCountHalf.value), max.value - buttonCount.value + 1));
const buttonRanges = computed(() => Array.from({ length: buttonCount.value }, (_, i) => buttonCountStart.value + i)); const buttonRanges = computed(() => Array.from({ length: buttonCount.value }, (_, i) => buttonCountStart.value + i));
const prevDotVisible = computed(() => (current.value - 1 > buttonCountHalf.value) || (max.value < buttonCount.value)); const prevDotVisible = computed(() => (current.value - 1 > buttonCountHalf.value) && (max.value > buttonCount.value));
const nextDotVisible = computed(() => (current.value < max.value - buttonCountHalf.value) || (max.value < buttonCount.value)); const nextDotVisible = computed(() => (current.value < max.value - buttonCountHalf.value) && (max.value > buttonCount.value));
console.log(current.value, max.value, buttonCount.value, buttonCountHalf.value);
console.log(current.value < max.value - buttonCountHalf.value);
console.log(max.value > buttonCount.value);
function onNumberButtonClicked(pageNumber: number) { function onNumberButtonClicked(pageNumber: number) {
emit('pageChanged', pageNumber); emit('pageChanged', pageNumber);