DimensionTasks.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="section" v-if="displayTasks && displayTasks.length > 0">
  3. <view class="section-header">
  4. <text class="section-title">📋 今日任务</text>
  5. <text class="section-more" @click="$emit('moreTasks')">全部 ›</text>
  6. </view>
  7. <view class="task-list">
  8. <view class="task-card" v-for="task in displayTasks" :key="task.id" @click="$emit('taskClick', task)">
  9. <view class="task-left">
  10. <view class="task-check" :class="{ 'checked': task.status === 'completed' }">
  11. <text class="task-check-icon" v-if="task.status === 'completed'">✓</text>
  12. </view>
  13. </view>
  14. <view class="task-content">
  15. <text class="task-name" :class="{ 'done': task.status === 'completed' }">{{ task.title }}</text>
  16. <view class="task-meta">
  17. <text class="task-points" v-if="task.points">+{{ task.points }}分</text>
  18. <text class="task-penalty" v-if="task.penalty">-{{ task.penalty }}分</text>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import api from '@/utils/api.js'
  27. export default {
  28. props: {
  29. dimensionCode: { type: String, required: true },
  30. tasks: { type: Array, default: function() { return [] } },
  31. childId: { type: Number, default: null }
  32. },
  33. data: function() {
  34. return {
  35. tasksData: []
  36. }
  37. },
  38. computed: {
  39. displayTasks: function() {
  40. return this.tasksData.length > 0 ? this.tasksData : this.tasks
  41. }
  42. },
  43. created: function() {
  44. this.loadTasks()
  45. },
  46. methods: {
  47. loadTasks: function() {
  48. var self = this
  49. if (!self.childId) return
  50. api.getTodayTasksByCategory(self.childId, self.dimensionCode).then(function(res) {
  51. self.tasksData = res.data || []
  52. }).catch(function() {
  53. // silently fail
  54. })
  55. }
  56. }
  57. }
  58. </script>
  59. <style scoped>
  60. .section {
  61. margin: 20rpx 20rpx;
  62. }
  63. .section-header {
  64. display: flex;
  65. justify-content: space-between;
  66. align-items: center;
  67. margin-bottom: 20rpx;
  68. }
  69. .section-title {
  70. font-size: 30rpx;
  71. font-weight: bold;
  72. color: #333;
  73. }
  74. .section-more {
  75. font-size: 24rpx;
  76. color: #999;
  77. }
  78. .task-list {
  79. display: flex;
  80. flex-direction: column;
  81. }
  82. .task-card {
  83. display: flex;
  84. flex-direction: row;
  85. align-items: center;
  86. background: #fff;
  87. border-radius: 16rpx;
  88. padding: 24rpx 20rpx;
  89. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  90. margin-bottom: 16rpx;
  91. }
  92. .task-card:active { opacity: 0.8; }
  93. .task-left {
  94. margin-right: 20rpx;
  95. }
  96. .task-check {
  97. width: 44rpx;
  98. height: 44rpx;
  99. border-radius: 50%;
  100. border: 3rpx solid #ddd;
  101. display: flex;
  102. align-items: center;
  103. justify-content: center;
  104. background: #f9f9f9;
  105. }
  106. .task-check.checked {
  107. background: #22C55E;
  108. border-color: #22C55E;
  109. }
  110. .task-check-icon {
  111. font-size: 24rpx;
  112. color: #fff;
  113. font-weight: bold;
  114. }
  115. .task-content {
  116. flex: 1;
  117. display: flex;
  118. flex-direction: row;
  119. justify-content: space-between;
  120. align-items: center;
  121. }
  122. .task-name {
  123. font-size: 28rpx;
  124. color: #333;
  125. }
  126. .task-name.done {
  127. text-decoration: line-through;
  128. color: #999;
  129. }
  130. .task-meta {
  131. display: flex;
  132. flex-direction: row;
  133. align-items: center;
  134. }
  135. .task-points {
  136. font-size: 24rpx;
  137. color: #22C55E;
  138. margin-right: 12rpx;
  139. }
  140. .task-penalty {
  141. font-size: 24rpx;
  142. color: #EF4444;
  143. }
  144. </style>