in-out.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!-- 出入记录 -->
  2. <template>
  3. <view class="list">
  4. <view class="list-item" v-for="(item, index) in list" :key="index">
  5. <view class="list-item-left" :class="item.status === 1 ? 'in' : 'out'">
  6. {{ item.status === 1 ? '进' : '出' }}
  7. <!-- <image :src="item.status === 1 ? '/static/icon/in.png' : '/static/icon/out.png'" mode="widthFix"></image> -->
  8. </view>
  9. <view class="list-item-right">
  10. <text>校门</text>
  11. <text>{{ formatTime(item.createTime, 'MM月dd日 HH:mm:ss') }}</text>
  12. </view>
  13. </view>
  14. <!-- 加载状态 -->
  15. <view class="loading" v-if="loading">
  16. <text>加载中...</text>
  17. </view>
  18. <!-- 没有更多数据 -->
  19. <view class="no-more" v-if="finished && list.length">
  20. <text>没有更多数据了</text>
  21. </view>
  22. <!-- 空状态 -->
  23. <view class="empty" v-if="!loading && !list.length">
  24. <text>暂无数据</text>
  25. </view>
  26. </view>
  27. </template>
  28. <script setup>
  29. import { ref } from 'vue'
  30. import { formatTime } from '@/utils/util.js'
  31. import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
  32. import { userApi } from '@/api/user'
  33. const list = ref([])
  34. const loading = ref(false)
  35. const finished = ref(false)
  36. const page = ref(1)
  37. const pageSize = 10
  38. const studentId = ref(0)
  39. // 获取进出记录
  40. async function fetchData() {
  41. if (loading.value || finished.value) return
  42. loading.value = true
  43. try {
  44. const res = await userApi.getStudentRecordLog({
  45. studentId: studentId.value,
  46. index: page.value,
  47. size: pageSize
  48. })
  49. list.value = [...list.value, ...res.list]
  50. // 判断是否加载完所有数据
  51. if (list.value.length >= res.total) {
  52. finished.value = true
  53. }
  54. page.value++
  55. } catch (error) {
  56. console.error('获取进出记录失败:', error)
  57. uni.showToast({
  58. title: '获取数据失败',
  59. icon: 'none'
  60. })
  61. } finally {
  62. loading.value = false
  63. }
  64. }
  65. // 下拉刷新
  66. async function onRefresh() {
  67. // 重置状态
  68. page.value = 1
  69. list.value = []
  70. total.value = 0
  71. finished.value = false
  72. await fetchData()
  73. // 结束下拉刷新
  74. uni.stopPullDownRefresh()
  75. }
  76. // 初始加载
  77. onLoad((options) => {
  78. if (options && options.studentId) {
  79. studentId.value = options.studentId
  80. }
  81. fetchData()
  82. })
  83. // 定义下拉刷新
  84. onPullDownRefresh(() => {
  85. onRefresh()
  86. })
  87. // 触底加载更多
  88. onReachBottom(() => {
  89. fetchData()
  90. })
  91. </script>
  92. <style scoped lang="less">
  93. .list {
  94. .list-item {
  95. display: flex;
  96. justify-content:flex-start;
  97. width: 90%;
  98. margin: 30rpx auto;
  99. border: 2rpx solid #dcdcdc;
  100. background: #eeeeee;
  101. border-radius: 10rpx;
  102. align-items: center;
  103. .list-item-left {
  104. font-size: 48rpx;
  105. color: #999;
  106. width: 120rpx;
  107. height: 120rpx;
  108. display: flex;
  109. align-items: center;
  110. justify-content: center;
  111. image {
  112. width: 60rpx;
  113. height: 60rpx;
  114. }
  115. }
  116. .list-item-left.in {
  117. background: #ddf7d6;
  118. border-radius: 10rpx 0 0 10rpx;
  119. }
  120. .list-item-left.out {
  121. background: #f5f7d6;
  122. border-radius: 10rpx 0 0 10rpx;
  123. }
  124. .list-item-right {
  125. margin-left: 20rpx;
  126. display: flex;
  127. flex-direction: column;
  128. align-items: flex-start;
  129. font-size: 30rpx;
  130. color: #333333;
  131. line-height: 45rpx;
  132. }
  133. }
  134. }
  135. .loading, .no-more, .empty {
  136. text-align: center;
  137. padding: 0 30rpx 30rpx ;
  138. color: #999;
  139. }
  140. .empty{
  141. margin-top: 100rpx;
  142. }
  143. </style>