chart.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <view class="chart-page">
  3. <view class="title">体重趋势</view>
  4. <view class="empty" v-if="list.length === 0">
  5. <text>暂无数据,先去记录体重吧</text>
  6. </view>
  7. <view class="tip" v-else>体重变化趋势(最近记录)</view>
  8. <view class="list">
  9. <view class="item" v-for="item in sortedList" :key="item.id">
  10. <text class="date">{{ format(item.measureDate || item.createTime) }}</text>
  11. <text class="weight">{{ item.weight }} kg</text>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import { getWeightList } from '../../utils/api.js'
  18. import { formatDate } from '../../utils/format.js'
  19. export default {
  20. data() {
  21. return {
  22. list: []
  23. }
  24. },
  25. computed: {
  26. sortedList() {
  27. return [...this.list].sort((a,b) => {
  28. var ta = new Date(a.measureDate || a.createTime).getTime()
  29. var tb = new Date(b.measureDate || b.createTime).getTime()
  30. return ta - tb
  31. })
  32. }
  33. },
  34. onShow() {
  35. this.load()
  36. },
  37. methods: {
  38. load() {
  39. getWeightList().then(res => {
  40. if (res.data) this.list = res.data
  41. })
  42. },
  43. format(date) {
  44. return formatDate(date)
  45. }
  46. }
  47. }
  48. </script>
  49. <style>
  50. .chart-page { padding: 30rpx; }
  51. .title { font-size: 36rpx; font-weight: 600; margin-bottom: 30rpx; }
  52. .empty { text-align: center; color: #999; padding: 60rpx; }
  53. .tip { color: #666; margin-bottom: 20rpx; }
  54. .list { background: #fff; border-radius: 16rpx; }
  55. .item { display: flex; justify-content: space-between; padding: 30rpx; border-bottom: 1rpx solid #f5f5f5; }
  56. .date { color: #666; }
  57. .weight { font-weight: 600; color: #F97316; }
  58. </style>