|
| 1 | +<template> |
| 2 | + <ul class="nt-pagination"> |
| 3 | + <!-- 上一页切换按钮 --> |
| 4 | + <li class="nt-pagination-item"> |
| 5 | + <Button title="上一页" :disabled="currentPage === 1"> |
| 6 | + <ArrowLeft></ArrowLeft> |
| 7 | + </Button> |
| 8 | + </li> |
| 9 | + <!-- 首页按钮 --> |
| 10 | + <li class="nt-pagination-item"> |
| 11 | + <a href="javascript:void" title="1">1</a> |
| 12 | + </li> |
| 13 | + <!-- 上一页更多按钮 --> |
| 14 | + <li class="nt-pagination-item"> |
| 15 | + <a |
| 16 | + href="javascript:void" |
| 17 | + title="more" |
| 18 | + @mouseenter="handleMoreHover(1)" |
| 19 | + @mouseleave="handleMoreHover(0)" |
| 20 | + > |
| 21 | + <More v-if="moreFocus === 0"></More> |
| 22 | + <DArrowLeft v-else-if="moreFocus === 1"></DArrowLeft> |
| 23 | + </a> |
| 24 | + </li> |
| 25 | + <!-- 末尾页按钮 --> |
| 26 | + <li class="nt-pagination-item" v-if="totalPage > 1"> |
| 27 | + <a href="javascript:void" :title="totalPage + ''">{{ totalPage }}</a> |
| 28 | + </li> |
| 29 | + <!-- 下一页切换按钮 --> |
| 30 | + <li class="nt-pagination-item"> |
| 31 | + <Button title="下一页" :disabled="currentPage === totalPage"> |
| 32 | + <ArrowRight></ArrowRight> |
| 33 | + </Button> |
| 34 | + </li> |
| 35 | + </ul> |
| 36 | +</template> |
| 37 | +<script setup lang="ts"> |
| 38 | +import { computed, ref, watch } from 'vue'; |
| 39 | +import Button from './Button.vue'; |
| 40 | +import ArrowLeft from './icon/ArrowLeft.vue'; |
| 41 | +import ArrowRight from './icon/ArrowRight.vue'; |
| 42 | +import More from './icon/More.vue'; |
| 43 | +import DArrowLeft from './icon/DArrowLeft.vue'; |
| 44 | +import DArrowRight from './icon/DArrowRight.vue'; |
| 45 | +
|
| 46 | +const moreFocus = ref(0); |
| 47 | +
|
| 48 | +function handleMoreHover(n: number) { |
| 49 | + moreFocus.value = n; |
| 50 | +} |
| 51 | +
|
| 52 | +const props = withDefaults( |
| 53 | + defineProps<{ |
| 54 | + /** 数据总数 */ |
| 55 | + total?: number; |
| 56 | + /** 总页数 */ |
| 57 | + pageCount?: number; |
| 58 | + /** 每页显示条目个数 */ |
| 59 | + pageSize?: number; |
| 60 | + /** 页码 */ |
| 61 | + page?: number; |
| 62 | + /** 默认当前页码 */ |
| 63 | + defaultCurrentPage?: number; |
| 64 | + }>(), |
| 65 | + { |
| 66 | + pageSize: 10, |
| 67 | + defaultCurrentPage: 1, |
| 68 | + }, |
| 69 | +); |
| 70 | +
|
| 71 | +const emits = defineEmits(['update:page']); |
| 72 | +
|
| 73 | +const totalPage = computed(() => { |
| 74 | + let pageCount = props.pageCount; |
| 75 | + if (pageCount == null && props.total != null) { |
| 76 | + pageCount = Math.ceil(props.total / props.pageSize); |
| 77 | + } |
| 78 | + if (pageCount == null || pageCount <= 0) { |
| 79 | + pageCount = 1; |
| 80 | + } |
| 81 | + return pageCount; |
| 82 | +}); |
| 83 | +const currentPage = ref(props.page || props.defaultCurrentPage); |
| 84 | +
|
| 85 | +if (props.page == null) { |
| 86 | + emits('update:page', currentPage.value); |
| 87 | +} |
| 88 | +
|
| 89 | +watch( |
| 90 | + () => props.page, |
| 91 | + (page) => { |
| 92 | + currentPage.value = page || props.defaultCurrentPage; |
| 93 | + }, |
| 94 | +); |
| 95 | +</script> |
0 commit comments