AITaskCard.vue 4.8 KB

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