daily-task-card.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <view class="daily-task-card" v-if="overview">
  3. <view class="daily-task-head">
  4. <text class="daily-task-title">今日任务</text>
  5. <text class="daily-task-date">{{ overview.date }}</text>
  6. </view>
  7. <view v-if="loading" class="daily-task-state">
  8. <text class="daily-task-state-text">加载中...</text>
  9. </view>
  10. <block v-else-if="error">
  11. <view class="daily-task-state" @click="loadOverview">
  12. <text class="daily-task-state-text">加载失败,点击重试</text>
  13. </view>
  14. </block>
  15. <block v-else>
  16. <!-- 打卡类 -->
  17. <view class="daily-task-group" v-if="overview.checkins && overview.checkins.length > 0">
  18. <view class="daily-task-group-title">打卡</view>
  19. <view class="daily-task-item" v-for="(item, ci) in overview.checkins" :key="ci" @click="go(item.route)">
  20. <text class="daily-task-item-label">{{ item.label }}</text>
  21. <text v-if="item.done" class="daily-task-done">✓</text>
  22. <text v-else class="daily-task-go">去完成</text>
  23. </view>
  24. </view>
  25. <!-- 任务类 -->
  26. <view class="daily-task-group" v-if="overview.tasks">
  27. <view class="daily-task-group-title">任务</view>
  28. <view class="daily-task-item" @click="go(overview.tasks.route)">
  29. <text class="daily-task-item-label">待完成 {{ overview.tasks.todoToday }} · 已完成 {{ overview.tasks.doneToday }}</text>
  30. <text v-if="overview.tasks.todoToday > 0" class="daily-task-go">去完成</text>
  31. <text v-else class="daily-task-done">✓</text>
  32. </view>
  33. </view>
  34. <!-- 阅读活动 -->
  35. <view class="daily-task-group" v-if="overview.activities">
  36. <view class="daily-task-group-title">阅读活动</view>
  37. <view class="daily-task-item" @click="go(overview.activities.articleRoute)">
  38. <text class="daily-task-item-label">今日已读 {{ overview.activities.articleReadToday }} 篇</text>
  39. <text v-if="overview.activities.articleReadToday > 0" class="daily-task-done">✓</text>
  40. <text v-else class="daily-task-go">去阅读</text>
  41. </view>
  42. </view>
  43. <!-- 测评报告 -->
  44. <view class="daily-task-group" v-if="overview.assessments">
  45. <view class="daily-task-group-title">测评报告</view>
  46. <view class="daily-task-item" @click="go(overview.assessments.route)">
  47. <text class="daily-task-item-label">进行中 {{ overview.assessments.ongoing }} · 待处理 {{ overview.assessments.reportPending }}</text>
  48. <text v-if="overview.assessments.ongoing > 0 || overview.assessments.reportPending > 0" class="daily-task-go">去处理</text>
  49. <text v-else class="daily-task-done">✓</text>
  50. </view>
  51. </view>
  52. <!-- 全部完成空态 -->
  53. <view class="daily-task-all" v-if="allDone()">
  54. <text class="daily-task-all-text">今日任务已全部完成 🎉</text>
  55. </view>
  56. </block>
  57. </view>
  58. </template>
  59. <script>
  60. import { getDailyTaskOverview } from '../utils/api.js'
  61. export default {
  62. name: 'DailyTaskCard',
  63. data() {
  64. return {
  65. overview: null,
  66. loading: false,
  67. error: false
  68. }
  69. },
  70. onShow() {
  71. if (!uni.getStorageSync('token')) return
  72. this.loadOverview()
  73. },
  74. methods: {
  75. loadOverview: function() {
  76. var self = this
  77. self.loading = true
  78. self.error = false
  79. getDailyTaskOverview().then(function(res) {
  80. self.loading = false
  81. if (res.code === 200 && res.data) {
  82. self.overview = res.data
  83. } else {
  84. self.overview = null
  85. self.error = true
  86. }
  87. }).catch(function() {
  88. self.loading = false
  89. self.overview = null
  90. self.error = true
  91. })
  92. },
  93. go: function(route) {
  94. if (!route) return
  95. uni.navigateTo({ url: route })
  96. },
  97. allDone: function() {
  98. var o = this.overview
  99. if (!o) return false
  100. var all = true
  101. if (o.checkins) {
  102. var i
  103. for (i = 0; i < o.checkins.length; i++) {
  104. if (!o.checkins[i].done) all = false
  105. }
  106. }
  107. if (o.tasks && o.tasks.todoToday > 0) all = false
  108. if (o.activities && o.activities.articleReadToday === 0) all = false
  109. if (o.assessments && (o.assessments.ongoing > 0 || o.assessments.reportPending > 0)) all = false
  110. return all
  111. }
  112. }
  113. }
  114. </script>
  115. <style scoped>
  116. .daily-task-card {
  117. margin: 24rpx 24rpx 0;
  118. padding: 28rpx;
  119. border-radius: 24rpx;
  120. background: #FFFFFF;
  121. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
  122. }
  123. .daily-task-head {
  124. display: flex;
  125. flex-direction: row;
  126. justify-content: space-between;
  127. align-items: center;
  128. margin-bottom: 20rpx;
  129. }
  130. .daily-task-title {
  131. font-size: 32rpx;
  132. font-weight: 600;
  133. color: #1F2937;
  134. }
  135. .daily-task-date {
  136. font-size: 24rpx;
  137. color: #9CA3AF;
  138. }
  139. .daily-task-state {
  140. display: flex;
  141. flex-direction: row;
  142. justify-content: center;
  143. align-items: center;
  144. padding: 24rpx 0;
  145. }
  146. .daily-task-state-text {
  147. font-size: 26rpx;
  148. color: #9CA3AF;
  149. }
  150. .daily-task-group {
  151. display: flex;
  152. flex-direction: column;
  153. margin-bottom: 16rpx;
  154. }
  155. .daily-task-group-title {
  156. font-size: 24rpx;
  157. color: #9CA3AF;
  158. margin-bottom: 8rpx;
  159. }
  160. .daily-task-item {
  161. display: flex;
  162. flex-direction: row;
  163. justify-content: space-between;
  164. align-items: center;
  165. padding: 18rpx 0;
  166. border-bottom: 1rpx solid #F3F4F6;
  167. }
  168. .daily-task-item:last-child {
  169. border-bottom: none;
  170. }
  171. .daily-task-item-label {
  172. font-size: 28rpx;
  173. color: #374151;
  174. }
  175. .daily-task-go {
  176. font-size: 26rpx;
  177. color: #F97316;
  178. font-weight: 500;
  179. }
  180. .daily-task-done {
  181. font-size: 26rpx;
  182. color: #10B981;
  183. font-weight: 600;
  184. }
  185. .daily-task-all {
  186. display: flex;
  187. flex-direction: row;
  188. justify-content: center;
  189. align-items: center;
  190. padding: 12rpx 0;
  191. }
  192. .daily-task-all-text {
  193. font-size: 28rpx;
  194. color: #10B981;
  195. font-weight: 500;
  196. }
  197. </style>