11<script lang="ts" setup>
22import { ChevronLeftIcon , ChevronRightIcon } from " @heroicons/vue/20/solid"
33import { useThrottleFn } from " @vueuse/core"
4- import { ref , toRefs } from " vue"
4+ import { Ref , ref , toRefs } from " vue"
55
66const $props = withDefaults (
77 defineProps <{
@@ -32,6 +32,7 @@ const $props = withDefaults(
3232const { page, total, canJump, hasNext, hasPrev } = toRefs ($props )
3333const { pageUpdateFn } = $props
3434const innerPage = ref (page .value )
35+ const bar: Ref <HTMLElement | null > = ref (null )
3536
3637function getDisabledClass(bool : boolean ) {
3738 return bool ? " disabled" : null
@@ -46,14 +47,19 @@ function submitPageChange(change?: "plus" | "minus") {
4647}
4748const throttleSubmitPageChange = useThrottleFn ((change ? : " plus" | " minus" ) => {
4849 submitPageChange (change )
50+ bar .value ! .classList .remove (" active" )
4951}, 800 )
52+ const throttleSubmitPageChangeWithProgress = (change ? : " plus" | " minus" ) => {
53+ bar .value ! .classList .add (" active" )
54+ throttleSubmitPageChange (change )
55+ }
5056 </script >
5157
5258<template >
5359 <div class =" paganation" >
5460 <span
5561 :class =" ['prev', 'operation', getDisabledClass(!hasPrev)]"
56- @click =" throttleSubmitPageChange ('minus')"
62+ @click =" throttleSubmitPageChangeWithProgress ('minus')"
5763 >
5864 <ChevronLeftIcon class =" icon" />
5965 </span >
@@ -63,24 +69,25 @@ const throttleSubmitPageChange = useThrottleFn((change?: "plus" | "minus") => {
6369 v-if =" canJump && total && pageSize"
6470 type =" number"
6571 :min =" 1"
66- @keyup.enter =" throttleSubmitPageChange ()"
72+ @keyup.enter =" throttleSubmitPageChangeWithProgress ()"
6773 />
6874 <span v-else class =" page" >{{ page }}</span >
6975 <span
7076 :class =" ['next', 'operation', getDisabledClass(!hasNext)]"
71- @click =" throttleSubmitPageChange ('plus')"
77+ @click =" throttleSubmitPageChangeWithProgress ('plus')"
7278 >
7379 <ChevronRightIcon class =" icon" />
7480 </span >
7581 <span v-if =" canJump && total && pageSize" class =" append-text"
7682 >共 {{ Math.round(total / pageSize) }} 页</span
7783 >
84+ <span class =" progress-bar" ref =" bar" ></span >
7885 </div >
7986</template >
8087
8188<style lang="postcss" scoped>
8289.paganation {
83- @apply inline-flex justify-center items-center flex-wrap mt-4;
90+ @apply relative inline-flex justify-center items-center flex-wrap mt-4;
8491}
8592.operation {
8693 @apply inline-flex justify-center items-center px-0.5
@@ -115,4 +122,26 @@ const throttleSubmitPageChange = useThrottleFn((change?: "plus" | "minus") => {
115122 @apply inline-block mx-3
116123 text-sm font-semibold select-none;
117124}
125+
126+ .progress-bar {
127+ @apply absolute w-full max-w-[128px] h-0.5 bottom-0 left-0
128+ bg-green-400 translate-y-2;
129+ }
130+ .progress-bar.active {
131+ animation : linearProgress 0.5 s linear forwards;
132+ }
133+ </style >
134+
135+ <style lang="postcss">
136+ @keyframes linearProgress {
137+ 0 % {
138+ @apply bg-slate-400 w-0;
139+ }
140+ 50 % {
141+ @apply w-1/ 2 ;
142+ }
143+ 100 % {
144+ @apply bg-green-400 w-full;
145+ }
146+ }
118147 </style >
0 commit comments