WisdomTips.vue 2.9 KB

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