index.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <view class="diet-page">
  3. <view class="header">
  4. <text class="title">饮食记录</text>
  5. <button class="add-btn" size="mini" @click="goCreate">+ 记录</button>
  6. </view>
  7. <view class="list">
  8. <view class="item" v-for="item in list" :key="item.id">
  9. <view class="info">
  10. <text class="food">{{ item.foodName }}</text>
  11. <text class="meta">{{ item.mealType }} · {{ format(item.eatDate) }}</text>
  12. </view>
  13. <view class="cal">{{ item.calories }} kcal</view>
  14. </view>
  15. </view>
  16. <view class="empty" v-if="list.length === 0">
  17. <text>暂无饮食记录</text>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import { getDietList } from '../../utils/api.js'
  23. import { formatDate } from '../../utils/format.js'
  24. export default {
  25. data() {
  26. return {
  27. list: []
  28. }
  29. },
  30. onShow() {
  31. this.loadList()
  32. },
  33. methods: {
  34. loadList() {
  35. getDietList().then(res => {
  36. if (res.data) this.list = res.data
  37. })
  38. },
  39. goCreate() {
  40. uni.navigateTo({ url: '/pages/diet/create' })
  41. },
  42. format(date) {
  43. return formatDate(date)
  44. }
  45. }
  46. }
  47. </script>
  48. <style>
  49. .diet-page { padding: 30rpx; }
  50. .header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30rpx; }
  51. .title { font-size: 36rpx; font-weight: 600; }
  52. .add-btn { background: #F97316; color: #fff; border-radius: 40rpx; }
  53. .list { background: #fff; border-radius: 16rpx; overflow: hidden; }
  54. .item { display: flex; justify-content: space-between; align-items: center; padding: 30rpx; border-bottom: 1rpx solid #f5f5f5; }
  55. .info { display: flex; flex-direction: column; }
  56. .food { font-size: 30rpx; font-weight: 600; margin-bottom: 8rpx; }
  57. .meta { font-size: 24rpx; color: #666; }
  58. .cal { color: #F97316; font-weight: 600; }
  59. .empty { text-align: center; color: #999; padding: 60rpx; }
  60. </style>