pagination.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="page" @click="pageChange">
  3. <view :class="onfirst ? 'prev end' : 'prev'" id="prev">{{$t('user.pre')}}</view>
  4. <view class="info">{{curPageNum}}</view>
  5. <view :class="onlast ? 'next end' : 'next'" id="next" :style="{ backgroundColor: mainColor }">
  6. {{$t('user.next')}}</view>
  7. </view>
  8. </template>
  9. <script setup>
  10. import {
  11. onMounted,
  12. onUpdated,
  13. ref
  14. } from 'vue';
  15. import {
  16. useColortore
  17. } from '@/store/index.js';
  18. import {
  19. onShow
  20. } from "@dcloudio/uni-app";
  21. import {
  22. t
  23. } from '@/locale'
  24. const props = defineProps({
  25. curPageNum: {
  26. type: Number,
  27. default: 1
  28. },
  29. isEnd: {
  30. type: String,
  31. default: ''
  32. },
  33. });
  34. const curPageNum = ref(props.curPageNum)
  35. const isEnd = ref(props.isEnd)
  36. const onfirst = ref(true)
  37. const onlast = ref(false)
  38. const emit = defineEmits();
  39. const mainColor = ref('')
  40. onMounted(() => {
  41. const colorStore = useColortore()
  42. mainColor.value = colorStore.mainRed
  43. if (props.curPageNum != 1) onfirst.value = false
  44. })
  45. onUpdated(() => {
  46. if (props.isEnd == 'end') onlast.value = true
  47. })
  48. const pageChange = (e) => {
  49. if (e.target.id === 'prev') {
  50. if (curPageNum.value == 1) return
  51. curPageNum.value--
  52. } else if (e.target.id === 'next') {
  53. if (props.isEnd == 'end') return
  54. curPageNum.value++
  55. }
  56. if (curPageNum.value == 1) onfirst.value = true
  57. else onfirst.value = false
  58. if (props.isEnd == 'end') onlast.value = true
  59. else onlast.value = false
  60. emit('pageChange', curPageNum.value)
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. .page {
  65. display: flex;
  66. justify-content: space-around;
  67. align-items: center;
  68. font-size: 28rpx;
  69. padding-top: 30rpx;
  70. .prev,
  71. .next {
  72. color: #ffffff;
  73. font-size: 24rpx;
  74. border-radius: 10rpx;
  75. background-color: #219EFF;
  76. padding: 4rpx 16rpx;
  77. }
  78. }
  79. .end {
  80. background-color: #CCCCCC !important;
  81. }
  82. </style>