HealthLikeButton.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <view class="like-btn" :class="{ liked: isLikedVal }" @click="handleClick">
  3. <text class="like-icon">{{ isLikedVal ? '❤️' : '🤍' }}</text>
  4. <text class="like-count">{{ count }}</text>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. props: {
  10. actionType: { type: String, default: '' },
  11. actionId: { type: [Number, String], default: '' },
  12. toUserId: { type: [Number, String], default: '' },
  13. isLiked: { type: Boolean, default: false },
  14. count: { type: Number, default: 0 }
  15. },
  16. data() {
  17. return {
  18. isLikedVal: this.isLiked
  19. }
  20. },
  21. watch: {
  22. isLiked: function(val) {
  23. this.isLikedVal = val
  24. }
  25. },
  26. methods: {
  27. handleClick: function() {
  28. if (this.isLikedVal) return
  29. this.isLikedVal = true
  30. this.$emit('like', {
  31. actionType: this.actionType,
  32. actionId: this.actionId,
  33. toUserId: this.toUserId
  34. })
  35. }
  36. }
  37. }
  38. </script>
  39. <style scoped>
  40. .like-btn {
  41. display: inline-flex;
  42. align-items: center;
  43. gap: 6rpx;
  44. padding: 8rpx 16rpx;
  45. border-radius: 999rpx;
  46. border: 1rpx solid #E2E8F0;
  47. background: #FAFAFA;
  48. transition: all 0.2s;
  49. }
  50. .like-btn.liked {
  51. border-color: #FECDD3;
  52. background: #FFF1F2;
  53. }
  54. .like-icon { font-size: 24rpx; }
  55. .like-count {
  56. font-size: 22rpx;
  57. color: #64748B;
  58. min-width: 20rpx;
  59. text-align: center;
  60. }
  61. .liked .like-count { color: #E11D48; }
  62. </style>