|
@@ -57,9 +57,9 @@
|
|
|
// next ellipsis page array
|
|
// next ellipsis page array
|
|
|
let nextEllipsisPages = $state([]);
|
|
let nextEllipsisPages = $state([]);
|
|
|
|
|
|
|
|
- // 当页码变化时对一系列数据动态计算
|
|
|
|
|
- // Dynamic calculation of a series of data when the page number changes
|
|
|
|
|
$effect(() => {
|
|
$effect(() => {
|
|
|
|
|
+ // 当页码变化时对一系列数据动态计算
|
|
|
|
|
+ // Dynamic calculation of a series of data when the page number changes
|
|
|
if (showPreEllipsis && showNextEllipsis) {
|
|
if (showPreEllipsis && showNextEllipsis) {
|
|
|
if (maxShowPage === 5) {
|
|
if (maxShowPage === 5) {
|
|
|
middleShowPage = [current];
|
|
middleShowPage = [current];
|
|
@@ -73,6 +73,9 @@
|
|
|
} else {
|
|
} else {
|
|
|
middleShowPage = [];
|
|
middleShowPage = [];
|
|
|
}
|
|
}
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ $effect(() => {
|
|
|
// 当仅显示后省略号时
|
|
// 当仅显示后省略号时
|
|
|
// when only show next ellipsis
|
|
// when only show next ellipsis
|
|
|
if (!showPreEllipsis && showNextEllipsis) {
|
|
if (!showPreEllipsis && showNextEllipsis) {
|
|
@@ -80,6 +83,8 @@
|
|
|
// nextEllipsisPages is maxShowPage - 2 to total page - 1
|
|
// nextEllipsisPages is maxShowPage - 2 to total page - 1
|
|
|
nextEllipsisPages = Array.from({ length: totalPage }, (v, k) => k + 1).slice(maxShowPage - 2, totalPage - 1);
|
|
nextEllipsisPages = Array.from({ length: totalPage }, (v, k) => k + 1).slice(maxShowPage - 2, totalPage - 1);
|
|
|
}
|
|
}
|
|
|
|
|
+ });
|
|
|
|
|
+ $effect(() => {
|
|
|
// 当仅显示前省略号时
|
|
// 当仅显示前省略号时
|
|
|
// when only show pre ellipsis
|
|
// when only show pre ellipsis
|
|
|
if (showPreEllipsis && !showNextEllipsis) {
|
|
if (showPreEllipsis && !showNextEllipsis) {
|
|
@@ -87,6 +92,8 @@
|
|
|
// preEllipsisPages is 2 to total page - (maxShowPage-2)
|
|
// preEllipsisPages is 2 to total page - (maxShowPage-2)
|
|
|
preEllipsisPages = Array.from({ length: totalPage }, (v, k) => k + 1).slice(1, totalPage - (maxShowPage - 2));
|
|
preEllipsisPages = Array.from({ length: totalPage }, (v, k) => k + 1).slice(1, totalPage - (maxShowPage - 2));
|
|
|
}
|
|
}
|
|
|
|
|
+ });
|
|
|
|
|
+ $effect(() => {
|
|
|
// 当显示前后省略号时
|
|
// 当显示前后省略号时
|
|
|
// when show pre and next ellipsis
|
|
// when show pre and next ellipsis
|
|
|
if (showPreEllipsis && showNextEllipsis) {
|
|
if (showPreEllipsis && showNextEllipsis) {
|
|
@@ -102,9 +109,9 @@
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // 特殊情况处理
|
|
|
|
|
- // Special case handling
|
|
|
|
|
$effect(() => {
|
|
$effect(() => {
|
|
|
|
|
+ // 特殊情况处理
|
|
|
|
|
+ // Special case handling
|
|
|
if (totalPage <= maxShowPage) {
|
|
if (totalPage <= maxShowPage) {
|
|
|
showNextOmitPage = false;
|
|
showNextOmitPage = false;
|
|
|
}
|
|
}
|
|
@@ -128,7 +135,7 @@
|
|
|
|
|
|
|
|
// 页码改变的回调,参数是改变后的页码及每页条数
|
|
// 页码改变的回调,参数是改变后的页码及每页条数
|
|
|
// onChange
|
|
// onChange
|
|
|
- const onChange = () => {
|
|
|
|
|
|
|
+ const onChangeFn = () => {
|
|
|
showNextOmitPage = false;
|
|
showNextOmitPage = false;
|
|
|
showPreOmitPage = false;
|
|
showPreOmitPage = false;
|
|
|
onchange && onchange(current);
|
|
onchange && onchange(current);
|
|
@@ -140,7 +147,7 @@
|
|
|
if (current < totalPage) {
|
|
if (current < totalPage) {
|
|
|
current++;
|
|
current++;
|
|
|
onnext && onnext(current);
|
|
onnext && onnext(current);
|
|
|
- onChange();
|
|
|
|
|
|
|
+ onChangeFn();
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -150,7 +157,7 @@
|
|
|
if (current > 1) {
|
|
if (current > 1) {
|
|
|
current--;
|
|
current--;
|
|
|
onpre && onpre(current);
|
|
onpre && onpre(current);
|
|
|
- onChange();
|
|
|
|
|
|
|
+ onChangeFn();
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -158,16 +165,16 @@
|
|
|
// click page
|
|
// click page
|
|
|
const clickItemFunc = index => {
|
|
const clickItemFunc = index => {
|
|
|
current = index;
|
|
current = index;
|
|
|
- onChange();
|
|
|
|
|
|
|
+ onChangeFn();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 点击省略页码事件
|
|
// 点击省略页码事件
|
|
|
// click second page item event
|
|
// click second page item event
|
|
|
- const clickSecondPageItemFunc = e => {
|
|
|
|
|
- current = e.detail;
|
|
|
|
|
|
|
+ const clickSecondPageItemFunc = index => {
|
|
|
|
|
+ current = index;
|
|
|
showNextOmitPage = false;
|
|
showNextOmitPage = false;
|
|
|
showPreOmitPage = false;
|
|
showPreOmitPage = false;
|
|
|
- onChange();
|
|
|
|
|
|
|
+ onChangeFn();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 类型样式
|
|
// 类型样式
|
|
@@ -184,22 +191,19 @@
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<div class="py-1 bg-white dark:bg-black flex justify-between text-center text-sm relative {injClass}">
|
|
<div class="py-1 bg-white dark:bg-black flex justify-between text-center text-sm relative {injClass}">
|
|
|
- <!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
|
|
|
- <!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
|
|
|
- <div
|
|
|
|
|
|
|
+ <button
|
|
|
class="flex-1 py-2 border border-transparent transition-all {current > 1
|
|
class="flex-1 py-2 border border-transparent transition-all {current > 1
|
|
|
? 'text-primary dark:text-dark'
|
|
? 'text-primary dark:text-dark'
|
|
|
: 'text-primary/30 dark:text-dark/30'} {radiusClass[radius] || radiusClass.base} active:scale-75"
|
|
: 'text-primary/30 dark:text-dark/30'} {radiusClass[radius] || radiusClass.base} active:scale-75"
|
|
|
onclick={preFunc}
|
|
onclick={preFunc}
|
|
|
>
|
|
>
|
|
|
<Icon name="ri-arrow-left-s-line" size={18} />
|
|
<Icon name="ri-arrow-left-s-line" size={18} />
|
|
|
- </div>
|
|
|
|
|
|
|
+ </button>
|
|
|
{#if totalPage === 0}
|
|
{#if totalPage === 0}
|
|
|
<div class="flex-1 py-2 border border-transparent">{noDataText}</div>
|
|
<div class="flex-1 py-2 border border-transparent">{noDataText}</div>
|
|
|
{:else if totalPage === 1}
|
|
{:else if totalPage === 1}
|
|
|
<div class="flex-1 py-2 border border-transparent">{onePageText}</div>
|
|
<div class="flex-1 py-2 border border-transparent">{onePageText}</div>
|
|
|
{:else if totalPage > 1 && totalPage <= maxShowPage}
|
|
{:else if totalPage > 1 && totalPage <= maxShowPage}
|
|
|
- <!-- eslint-disable-next-line no-unused-vars -->
|
|
|
|
|
{#each new Array(totalPage) as item, index}
|
|
{#each new Array(totalPage) as item, index}
|
|
|
<Page active={current === index + 1} {type} {radius} onclick={() => !continuous && clickItemFunc(index + 1)}>
|
|
<Page active={current === index + 1} {type} {radius} onclick={() => !continuous && clickItemFunc(index + 1)}>
|
|
|
{index + 1}
|
|
{index + 1}
|
|
@@ -208,9 +212,7 @@
|
|
|
{:else}
|
|
{:else}
|
|
|
<Page active={current === 1} {type} {radius} onclick={() => !continuous && clickItemFunc(1)}>1</Page>
|
|
<Page active={current === 1} {type} {radius} onclick={() => !continuous && clickItemFunc(1)}>1</Page>
|
|
|
{#if showPreEllipsis}
|
|
{#if showPreEllipsis}
|
|
|
- <!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
|
|
|
- <!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
|
|
|
- <div
|
|
|
|
|
|
|
+ <button
|
|
|
class="flex-1 py-2 border {showPreOmitPage
|
|
class="flex-1 py-2 border {showPreOmitPage
|
|
|
? typeClass[type] || typeClass.border
|
|
? typeClass[type] || typeClass.border
|
|
|
: 'border-transparent' + (type === 'bold' ? ' opacity-50' : '')} {radiusClass[radius] || radiusClass.base}"
|
|
: 'border-transparent' + (type === 'bold' ? ' opacity-50' : '')} {radiusClass[radius] || radiusClass.base}"
|
|
@@ -221,10 +223,9 @@
|
|
|
{:else}
|
|
{:else}
|
|
|
<Icon name="ri-more-line" size={18} />
|
|
<Icon name="ri-more-line" size={18} />
|
|
|
{/if}
|
|
{/if}
|
|
|
- </div>
|
|
|
|
|
|
|
+ </button>
|
|
|
{/if}
|
|
{/if}
|
|
|
{#if !showPreEllipsis && current <= maxShowPage - 1}
|
|
{#if !showPreEllipsis && current <= maxShowPage - 1}
|
|
|
- <!-- eslint-disable-next-line no-unused-vars -->
|
|
|
|
|
{#each new Array(maxShowPage - 3) as item, index}
|
|
{#each new Array(maxShowPage - 3) as item, index}
|
|
|
<Page active={current === index + 2} {type} {radius} onclick={() => !continuous && clickItemFunc(index + 2)}>
|
|
<Page active={current === index + 2} {type} {radius} onclick={() => !continuous && clickItemFunc(index + 2)}>
|
|
|
{index + 2}
|
|
{index + 2}
|
|
@@ -239,7 +240,6 @@
|
|
|
{/each}
|
|
{/each}
|
|
|
{/if}
|
|
{/if}
|
|
|
{#if !showNextEllipsis && current > totalPage - (maxShowPage - 3)}
|
|
{#if !showNextEllipsis && current > totalPage - (maxShowPage - 3)}
|
|
|
- <!-- eslint-disable-next-line no-unused-vars -->
|
|
|
|
|
{#each new Array(maxShowPage - 3) as item, index}
|
|
{#each new Array(maxShowPage - 3) as item, index}
|
|
|
<Page
|
|
<Page
|
|
|
active={current === totalPage + index + 3 - maxShowPage}
|
|
active={current === totalPage + index + 3 - maxShowPage}
|
|
@@ -252,9 +252,7 @@
|
|
|
{/each}
|
|
{/each}
|
|
|
{/if}
|
|
{/if}
|
|
|
{#if showNextEllipsis}
|
|
{#if showNextEllipsis}
|
|
|
- <!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
|
|
|
- <!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
|
|
|
- <div
|
|
|
|
|
|
|
+ <button
|
|
|
class="flex-1 py-2 border {showNextOmitPage
|
|
class="flex-1 py-2 border {showNextOmitPage
|
|
|
? typeClass[type] || typeClass.border
|
|
? typeClass[type] || typeClass.border
|
|
|
: 'border-transparent' + (type === 'bold' ? ' opacity-50' : '')} {radiusClass[radius] || radiusClass.base}"
|
|
: 'border-transparent' + (type === 'bold' ? ' opacity-50' : '')} {radiusClass[radius] || radiusClass.base}"
|
|
@@ -265,20 +263,18 @@
|
|
|
{:else}
|
|
{:else}
|
|
|
<Icon name="ri-more-line" size={18} />
|
|
<Icon name="ri-more-line" size={18} />
|
|
|
{/if}
|
|
{/if}
|
|
|
- </div>
|
|
|
|
|
|
|
+ </button>
|
|
|
{/if}
|
|
{/if}
|
|
|
<Page active={current === totalPage} {type} {radius} onclick={() => !continuous && clickItemFunc(totalPage)}>{totalPage}</Page>
|
|
<Page active={current === totalPage} {type} {radius} onclick={() => !continuous && clickItemFunc(totalPage)}>{totalPage}</Page>
|
|
|
{/if}
|
|
{/if}
|
|
|
- <!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
|
|
|
- <!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
|
|
|
- <div
|
|
|
|
|
|
|
+ <button
|
|
|
class="flex-1 py-2 border border-transparent transition-all {current < totalPage
|
|
class="flex-1 py-2 border border-transparent transition-all {current < totalPage
|
|
|
? 'text-primary dark:text-dark'
|
|
? 'text-primary dark:text-dark'
|
|
|
: 'text-primary/30 dark:text-dark/30'} {radiusClass[radius] || radiusClass.base} active:scale-75"
|
|
: 'text-primary/30 dark:text-dark/30'} {radiusClass[radius] || radiusClass.base} active:scale-75"
|
|
|
onclick={nextFunc}
|
|
onclick={nextFunc}
|
|
|
>
|
|
>
|
|
|
<Icon name="ri-arrow-right-s-line" size={20} />
|
|
<Icon name="ri-arrow-right-s-line" size={20} />
|
|
|
- </div>
|
|
|
|
|
|
|
+ </button>
|
|
|
{#if showNextOmitPage}
|
|
{#if showNextOmitPage}
|
|
|
<SecondPageNext {pageCol} Pages={nextEllipsisPages} {type} {radius} onclickItem={clickSecondPageItemFunc} {maxShowPage} />
|
|
<SecondPageNext {pageCol} Pages={nextEllipsisPages} {type} {radius} onclickItem={clickSecondPageItemFunc} {maxShowPage} />
|
|
|
{/if}
|
|
{/if}
|