AITaskCard.vue 4.5 KB

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