AITaskCard.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view class="ai-task-card">
  3. <view class="card-header">
  4. <text class="card-title">{{ task.title }}</text>
  5. <view class="dimension-badge" :style="{ backgroundColor: dimensionColor }">
  6. <text class="dimension-text">{{ task.dimension }}</text>
  7. </view>
  8. </view>
  9. <view class="card-body">
  10. <text class="card-description">{{ task.description }}</text>
  11. </view>
  12. <view class="card-footer">
  13. <view class="reward-info">
  14. <text class="reward-label">奖励能量</text>
  15. <text class="reward-points">+{{ task.rewardPoints }}</text>
  16. </view>
  17. <button
  18. class="accept-btn"
  19. :loading="loading"
  20. :disabled="loading"
  21. @click="handleAccept"
  22. >
  23. <text class="btn-text">{{ loading ? '接受中...' : '接受任务' }}</text>
  24. </button>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. name: 'AITaskCard',
  31. props: {
  32. task: {
  33. type: Object,
  34. default: function() {
  35. return {
  36. title: '',
  37. description: '',
  38. dimension: '',
  39. rewardPoints: 0,
  40. id: null
  41. }
  42. }
  43. },
  44. conversationId: {
  45. type: String,
  46. default: ''
  47. }
  48. },
  49. data: function() {
  50. return {
  51. loading: false
  52. }
  53. },
  54. computed: {
  55. dimensionColor: function() {
  56. var colorMap = {
  57. '身': '#10B981',
  58. '心': '#F59E0B',
  59. '智': '#3B82F6',
  60. '行': '#8B5CF6',
  61. '富': '#F97316'
  62. }
  63. return colorMap[this.task.dimension] || '#F97316'
  64. }
  65. },
  66. methods: {
  67. handleAccept: function() {
  68. var self = this
  69. if (self.loading) {
  70. return
  71. }
  72. var token = uni.getStorageSync('token')
  73. if (!token) {
  74. uni.showToast({
  75. title: '请先登录',
  76. icon: 'none'
  77. })
  78. return
  79. }
  80. self.loading = true
  81. uni.request({
  82. url: self.$apiBase + '/api/growth-task/accept-dynamic',
  83. method: 'POST',
  84. header: {
  85. 'Authorization': 'Bearer ' + token,
  86. 'Content-Type': 'application/json'
  87. },
  88. data: {
  89. taskId: self.task.id,
  90. conversationId: self.conversationId
  91. },
  92. success: function(res) {
  93. if (res.statusCode === 200 && res.data && res.data.code === 200) {
  94. uni.showToast({
  95. title: '任务已接受',
  96. icon: 'success'
  97. })
  98. self.$emit('accepted', self.task)
  99. } else {
  100. var message = (res.data && res.data.message) || '接受失败'
  101. uni.showToast({
  102. title: message,
  103. icon: 'none'
  104. })
  105. }
  106. },
  107. fail: function() {
  108. uni.showToast({
  109. title: '网络请求失败',
  110. icon: 'none'
  111. })
  112. },
  113. complete: function() {
  114. self.loading = false
  115. }
  116. })
  117. }
  118. }
  119. }
  120. </script>
  121. <style scoped>
  122. .ai-task-card {
  123. background-color: #FFFFFF;
  124. border-radius: 16rpx;
  125. padding: 32rpx;
  126. margin: 24rpx;
  127. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
  128. }
  129. .card-header {
  130. display: flex;
  131. flex-direction: row;
  132. justify-content: space-between;
  133. align-items: center;
  134. margin-bottom: 24rpx;
  135. }
  136. .card-title {
  137. font-size: 32rpx;
  138. font-weight: 600;
  139. color: #1F2937;
  140. flex: 1;
  141. margin-right: 16rpx;
  142. }
  143. .dimension-badge {
  144. padding: 8rpx 20rpx;
  145. border-radius: 24rpx;
  146. flex-shrink: 0;
  147. }
  148. .dimension-text {
  149. font-size: 24rpx;
  150. font-weight: 500;
  151. color: #FFFFFF;
  152. }
  153. .card-body {
  154. margin-bottom: 32rpx;
  155. }
  156. .card-description {
  157. font-size: 28rpx;
  158. color: #6B7280;
  159. line-height: 44rpx;
  160. }
  161. .card-footer {
  162. display: flex;
  163. flex-direction: row;
  164. justify-content: space-between;
  165. align-items: center;
  166. padding-top: 24rpx;
  167. border-top: 1rpx solid #F3F4F6;
  168. }
  169. .reward-info {
  170. display: flex;
  171. flex-direction: row;
  172. align-items: center;
  173. }
  174. .reward-label {
  175. font-size: 26rpx;
  176. color: #9CA3AF;
  177. margin-right: 12rpx;
  178. }
  179. .reward-points {
  180. font-size: 32rpx;
  181. font-weight: 700;
  182. color: #F97316;
  183. }
  184. .accept-btn {
  185. background-color: #F97316;
  186. color: #FFFFFF;
  187. border: none;
  188. border-radius: 12rpx;
  189. padding: 20rpx 40rpx;
  190. font-size: 28rpx;
  191. font-weight: 500;
  192. line-height: 1.2;
  193. }
  194. .accept-btn:active {
  195. background-color: #EA580C;
  196. }
  197. .accept-btn:disabled {
  198. background-color: #FDBA74;
  199. }
  200. .btn-text {
  201. color: #FFFFFF;
  202. }
  203. </style>