HealthTips.vue 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view class="section" v-if="tips.length > 0">
  3. <view class="section-header">
  4. <text class="section-title">💡 健康小贴士</text>
  5. <text class="section-more" @click="goMore">更多 ›</text>
  6. </view>
  7. <view class="tip-list">
  8. <view class="tip-item" v-for="tip in tips" :key="tip.id" @click="goDetail(tip)">
  9. <text class="tip-icon">📋</text>
  10. <view class="tip-content">
  11. <text class="tip-title">{{ tip.title }}</text>
  12. <text class="tip-summary">{{ tip.summary }}</text>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import config from '@/config.js'
  20. export default {
  21. props: {
  22. dimension: { type: String, default: 'body' },
  23. limit: { type: Number, default: 4 }
  24. },
  25. data: function() {
  26. return { tips: [] }
  27. },
  28. created: function() {
  29. this.loadTips()
  30. },
  31. methods: {
  32. loadTips: function() {
  33. var self = this
  34. var token = uni.getStorageSync('token')
  35. uni.request({
  36. url: config.API_BASE_URL + '/api/articles/list',
  37. method: 'POST',
  38. data: {
  39. dimension: this.dimension,
  40. page: 1,
  41. size: this.limit
  42. },
  43. header: {
  44. 'Content-Type': 'application/json',
  45. 'Authorization': token ? 'Bearer ' + token : ''
  46. },
  47. success: function(res) {
  48. if (res.data && res.data.code === 200 && res.data.data && res.data.data.records) {
  49. var list = res.data.data.records
  50. self.tips = list.slice(0, self.limit)
  51. }
  52. },
  53. fail: function() {}
  54. })
  55. },
  56. goDetail: function(tip) {
  57. uni.navigateTo({ url: '/pages/mind/article-detail?id=' + tip.id })
  58. },
  59. goMore: function() {
  60. uni.navigateTo({ url: '/pages/mind-extra/articles?dimension=' + this.dimension })
  61. }
  62. }
  63. }
  64. </script>
  65. <style scoped>
  66. .section { margin: 20rpx 30rpx; }
  67. .section-header {
  68. display: flex;
  69. flex-direction: row;
  70. justify-content: space-between;
  71. align-items: center;
  72. margin-bottom: 16rpx;
  73. }
  74. .section-title { font-size: 30rpx; font-weight: bold; color: #333; }
  75. .section-more { font-size: 24rpx; color: #999; }
  76. .tip-list {
  77. background: #fff;
  78. border-radius: 20rpx;
  79. overflow: hidden;
  80. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  81. }
  82. .tip-item {
  83. display: flex;
  84. flex-direction: row;
  85. align-items: center;
  86. padding: 24rpx 20rpx;
  87. border-bottom: 1rpx solid #f5f5f5;
  88. }
  89. .tip-item:last-child { border-bottom: none; }
  90. .tip-item:active { background: #fafafa; }
  91. .tip-icon { font-size: 36rpx; margin-right: 16rpx; flex-shrink: 0; }
  92. .tip-content { flex: 1; }
  93. .tip-title { font-size: 28rpx; color: #333; font-weight: 500; display: block; }
  94. .tip-summary { font-size: 24rpx; color: #999; margin-top: 4rpx; display: block; }
  95. </style>