mine.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <!--
  2. * @Author: wanglj wanglijie@dashoo.cn
  3. * @Date: 2025-03-17 13:36:58
  4. * @LastEditors: wanglj wanglijie@dashoo.cn
  5. * @LastEditTime: 2025-03-28 14:47:27
  6. * @FilePath: \labsop-h5\src\view\training\index.vue
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. -->
  9. <template>
  10. <div class="app-container">
  11. <van-list v-model:loading="state.loading" :finished="state.finished" finished-text="没有更多了" @load="onLoad" class="mt10">
  12. <van-cell v-for="(item, index) in state.list" :key="index" :center="true">
  13. <template #title>
  14. <div class="list" @click="onDetail(item)">
  15. <header class="flex justify-between">
  16. <van-text-ellipsis class="title" :content="item.name" />
  17. <span>次数:{{ item.examineCount }}/{{ item.totalCount }}</span>
  18. </header>
  19. <footer>
  20. {{ `${formatDate(new Date(item.startTime), 'YYYY-mm-dd HH:MM')}~${formatDate(new Date(item.endTime), 'YYYY-mm-dd HH:MM')}` }}
  21. </footer>
  22. </div>
  23. </template>
  24. </van-cell>
  25. </van-list>
  26. </div>
  27. </template>
  28. <script lang="ts" setup>
  29. import to from 'await-to-js'
  30. import { onMounted, reactive } from 'vue'
  31. import { useRouter } from 'vue-router'
  32. import { useTrainingApi } from '/@/api/training'
  33. import { formatDate } from '/@/utils/formatTime'
  34. import { useUserInfo } from '/@/stores/userInfo'
  35. import { showNotify } from 'vant'
  36. const props = defineProps({
  37. isAll: {
  38. type: String,
  39. default: '10'
  40. }
  41. })
  42. const trainingApi = useTrainingApi()
  43. const router = useRouter()
  44. const state = reactive({
  45. queryParams: {
  46. pageNum: 1,
  47. pageSize: 10,
  48. isAll: false
  49. },
  50. list: [] as any[],
  51. loading: false,
  52. finished: false
  53. })
  54. const onLoad = async () => {
  55. if (state.loading) return
  56. state.loading = true
  57. const params = JSON.parse(JSON.stringify(state.queryParams))
  58. params.userId = useUserInfo().userInfos.id
  59. const [err, res]: ToResponse = await to(trainingApi.getExamList(params))
  60. if (err) {
  61. state.loading = false
  62. return
  63. }
  64. const list = res?.data?.list || []
  65. for (const item of list) {
  66. state.list.push(item)
  67. }
  68. if (list.length < state.queryParams.pageSize) {
  69. state.finished = true
  70. }
  71. state.queryParams.pageNum++
  72. state.loading = false
  73. }
  74. const onDetail = (row: any) => {
  75. if(!row.lastExam) return
  76. router.push({
  77. path: '/exam/result',
  78. query: {
  79. id: row.lastExam.answerId
  80. }
  81. })
  82. }
  83. onMounted(() => {
  84. onLoad()
  85. })
  86. </script>
  87. <style lang="scss" scoped>
  88. .app-container {
  89. .van-cell {
  90. background-color: #fff;
  91. margin-top: 10px;
  92. header {
  93. color: #333;
  94. font-size: 16px;
  95. }
  96. footer {
  97. color: #969799;
  98. margin-top: 4px;
  99. white-space: nowrap;
  100. overflow: hidden;
  101. text-overflow: ellipsis;
  102. text-align: right;
  103. }
  104. .title {
  105. font-weight: bold;
  106. }
  107. .inst-title {
  108. color: #333;
  109. text-align: left;
  110. flex: 1;
  111. overflow: hidden;
  112. white-space: nowrap;
  113. text-overflow: ellipsis;
  114. margin-top: 4px;
  115. }
  116. .time {
  117. color: #f69a4d;
  118. }
  119. }
  120. }
  121. </style>