Эх сурвалжийг харах

feat :1.橙宝日志 喂养记录得页面新增。

suwenjiang 1 долоо хоног өмнө
parent
commit
315cd605d5

+ 2 - 2
src/components/feed-wd-popup/feed-wd-popup.vue

@@ -13,7 +13,7 @@
               :src="item?.img"
               :alt="item?.title"
               class="w-full h-full object-cover"
-              mode="scaleToFill"
+              mode="widthFix"
             />
           </view>
           <span class="text-sm text-gray-600">{{ item.title }}</span>
@@ -41,7 +41,7 @@
               :src="item?.img"
               :alt="item?.title"
               class="w-full h-full object-cover"
-              mode="scaleToFill"
+              mode="widthFix"
             />
           </view>
           <span class="text-sm text-gray-600">{{ item.title }}</span>

+ 1 - 1
src/components/height/height-item.vue

@@ -14,7 +14,7 @@
       </view>
     </view>
   </view>
-  <wd-divider></wd-divider>
+  <wd-divider color="#ccc"></wd-divider>
 </template>
 <script setup>
   defineOptions({

+ 53 - 18
src/components/height/r-echarts.vue

@@ -1,7 +1,7 @@
 <template>
   <view class="relative w-full box-border h-[604rpx] p-4">
-    <view class="absolute right-4 top-7 z-[10] text-xs text-[#333]">喂奶次数</view>
-    <view id="chart" class="w-full box-border" style="height: 100%"></view>
+    <slot name="default" />
+    <view :id="id" class="w-full box-border" style="height: 100%"></view>
   </view>
 </template>
 <script setup>
@@ -13,6 +13,29 @@
     name: 'REcharts',
   })
 
+  // 时间前七天
+  function getLastWeekDates() {
+    const datesArray = []
+
+    // 获取今天的日期
+    const today = new Date()
+
+    // 循环过去7天,包括今天
+    for (let i = 0; i < 7; i++) {
+      const currentDate = new Date(today)
+      currentDate.setDate(today.getDate() - i) // 设置为今天之前的第i天
+
+      // 获取当前日期的月份和日期
+      const month = currentDate.getMonth() + 1 // 月份从0开始,需加1
+      const date = currentDate.getDate()
+
+      // 组装成 [月.日] 格式,并推入数组
+      datesArray.unshift(`${month}.${date}`)
+    }
+
+    return datesArray
+  }
+
   const props = defineProps({
     yAxisData: {
       type: Array,
@@ -22,21 +45,20 @@
       type: Array,
       default: [],
     },
-    xAxisData: {
-      type: Array,
-      default: [],
-    },
     unit: {
       type: String,
       default: '(cm)',
     },
+    id: {
+      type: String,
+      required: true,
+    },
   })
-
+  const { unit, seriesData } = toRefs(props)
   const colorList = ['#FFAC78', '#FFAC78', '#FFAC78', '#FFAC78', '#FFAC78', '#FFAC78', '#F88842']
-  // const chart = ref(null)
   const option = ref({
     title: {
-      subtext: props.unit, // 图表标题下方显示单位
+      subtext: unit, // 图表标题下方显示单位
       // subtext: unit.value, // 图表标题下方显示单位
       subtextStyle: {
         fontSize: 12,
@@ -45,7 +67,7 @@
     },
     xAxis: {
       type: 'category',
-      data: ['3.1', '3.2', '3.3', '3.4', '3.5', '3.6', '3.7'],
+      data: getLastWeekDates(),
       axisLabel: {
         interval: 0, // 每隔一个标签显示一次
         show: true, // 显示 X 轴标签
@@ -72,7 +94,7 @@
     },
     series: [
       {
-        data: [120, 200, 150, 80, 70, 110, 130],
+        data: seriesData,
         type: 'bar',
         barWidth: 24, // 设置柱子的宽度为 30px
 
@@ -90,12 +112,14 @@
     grid: {
       right: 0,
       bottom: '10%',
-      // top: '10%',
     },
   })
   function initChart() {
+    console.log(props.id, 'props.id')
+
     // 获取 DOM 元素
-    const chartDom = document.getElementById('chart')
+    const chartDom = document.getElementById(props.id)
+
     // 初始化 Echarts 实例
     const myChart = echarts.init(chartDom)
     // 指定图表的配置项和数据
@@ -104,6 +128,21 @@
     myChart.setOption(option.value)
   }
 
+  watch(
+    props,
+    () => {
+      nextTick(() => {
+        // option.value.title.subtext = props.unit
+        // option.value.series.data = props.seriesData
+        initChart()
+      })
+    },
+    {
+      deep: true,
+      immediate: true,
+    },
+  )
+
   onLoad(() => {
     nextTick(() => {
       initChart()
@@ -111,8 +150,4 @@
   })
 </script>
 
-<style lang="scss" scoped>
-  .wd-divider {
-    margin: 0;
-  }
-</style>
+<style lang="scss" scoped></style>

+ 34 - 23
src/components/record-list/record-list.vue

@@ -1,30 +1,37 @@
 <template>
-  <view class="w-full mt-2 bg-white px-4">
-    <view
-      v-for="(item, index) in dataList"
-      :key="index"
-      class="w-full box-border py-4 last:border-b-0"
-    >
-      <view class="flex justify-between items-center">
-        <view style="border: 1px solid red" @click.stop="goToPage(item)">
-          <view class="text-xs text-gray-400">
-            <image class="w-[20rpx] h-[20rpx]" :src="oval" mode="widthFix" />
-            {{ item.time }}
-          </view>
-          <view class="mt-1 text-gray-800">{{ item.title }}</view>
-          <view class="mt-1 text-xs text-gray-500 line-clamp-1">
-            {{ item?.desc ? item?.desc : '无备注' }}
-            asdjaghjsdhgajsdgajhsdgahsdghsgdasdgajshgggggggggg
-          </view>
-          <view v-if="item?.recorder" class="mt-1 text-xs text-gray-400">
-            记录者:{{ item?.recorder }}
-          </view>
+  <view v-for="(item, index) in dataList" :key="index" class="w-full px-4 box-border">
+    <view class="w-full flex items-center justify-between box-border py-4 last:border-b-0">
+      <view
+        :style="{
+          width: item?.image ? `calc(100% - 200rpx)` : '100%',
+        }"
+        @click.stop="goToPage(item)"
+      >
+        <view class="w-full text-xs text-gray-400">
+          <image class="w-[20rpx] h-[20rpx]" :src="oval" mode="widthFix" />
+          {{ item.time }}
         </view>
-        <view v-if="item?.image" class="ml-4">
-          <img :src="item?.image" class="w-16 h-16 rounded-lg object-cover" alt="记录图片" />
+        <view class="w-full mt-1 text-gray-800">{{ item.title }}</view>
+        <view class="w-full mt-1 text-xs text-gray-500 line-clamp-1">
+          {{ item?.desc ? item?.desc : '无备注' }}
         </view>
+        <view v-if="item?.recorder" class="mt-1 text-xs text-gray-400">
+          记录者:{{ item?.recorder }}
+        </view>
+      </view>
+      <view v-if="item?.image" class="w-20 h-20 shrink-0 ml-4">
+        <wd-badge
+          :hidden="item.imageCount ? false : true"
+          :modelValue="item.imageCount"
+          type="primary"
+          max="99"
+          :right="10"
+        >
+          <img :src="item?.image" class="w-full h-full rounded-lg object-cover" alt="记录图片" />
+        </wd-badge>
       </view>
     </view>
+    <wd-divider class="w-full" color="#ccc"></wd-divider>
   </view>
 </template>
 
@@ -48,4 +55,8 @@
   }
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="scss" scoped>
+  .wd-divider {
+    margin: 0;
+  }
+</style>

+ 37 - 0
src/components/switch-btn/switch-btn.vue

@@ -0,0 +1,37 @@
+<template>
+  <view
+    class="flex bg-[#F2F2F2] justify-between gap-1 items-center box-border p-[4rpx] rounded-full"
+  >
+    <view
+      @click="(show = !show), emit('handleList')"
+      class="px-2 py-1 rounded-full box-border text-xs"
+      :class="`${show ? 'bg-transparent text-[#666]' : 'bg-white text-[#333]'}`"
+    >
+      {{ columns[0] }}
+    </view>
+    <view
+      @click="(show = !show), emit('handleList')"
+      class="px-2 py-1 rounded-full box-border text-xs"
+      :class="`${show ? 'bg-white text-[#333]' : 'bg-transparent text-[#666]'}`"
+    >
+      {{ columns[1] }}
+    </view>
+  </view>
+</template>
+
+<script setup>
+  defineOptions({
+    name: 'SwitchBtn',
+  })
+  const show = defineModel('show')
+  const props = defineProps({
+    columns: {
+      type: Array,
+      required: true,
+    },
+  }) // 定义事件
+
+  const emit = defineEmits('handleList')
+</script>
+
+<style scoped lang="scss"></style>

+ 0 - 14
src/pages/category/category.vue

@@ -1,14 +0,0 @@
-<route lang="json5">
-{
-  layout: 'tabbar',
-  style: {
-    navigationBarTitleText: '%tabbar.category%',
-  },
-}
-</route>
-<template>
-  <view>听歌页面</view>
-</template>
-
-<script lang="ts" setup></script>
-<style lang="scss" scoped></style>

+ 0 - 17
src/pages/community/community.vue

@@ -1,17 +0,0 @@
-<route lang="json5">
-{
-  layout: 'tabbar',
-  style: {
-    navigationBarTitleText: '%tabbar.community%',
-  },
-}
-</route>
-<!-- 代码已包含 CSS:使用 TailwindCSS , 安装 TailwindCSS 后方可看到布局样式效果 -->
-
-<template>
-  <view class="verification-container"></view>
-</template>
-
-<script lang="ts" setup></script>
-
-<style scoped></style>

+ 217 - 59
src/pages/feed-statistics/feed-statistics.vue

@@ -27,11 +27,25 @@
       @change="changeIndex"
       inactiveColor="#666666"
     >
-      <block class="h-full" v-for="(item, idnex) in tabList" :key="'tabs' + item.id">
+      <block class="h-full" v-for="(item, index) in tabList" :key="'tabs' + item.id">
         <wd-tab :title="item.title">
-          <template v-if="tabIndex === 0">
-            <REcharts :unit="unit" />
-          </template>
+          <REcharts :id="echartsItem.id + index" :seriesData="echartsItem?.seriesData" :unit="unit">
+            <template #default>
+              <view class="absolute right-4 top-7 z-[10] text-xs text-[#333]">
+                <template v-if="handleColumns(echartsItem?.columns)">
+                  <SwitchBtn
+                    v-model:show="show"
+                    :columns="echartsItem?.columns"
+                    :seriesData="echartsItem?.seriesData"
+                    @handleList="handleList"
+                  />
+                </template>
+                <template v-else>
+                  {{ echartsItem?.columns }}
+                </template>
+              </view>
+            </template>
+          </REcharts>
         </wd-tab>
       </block>
     </wd-tabs>
@@ -40,41 +54,33 @@
     <view
       class="mx-4 px-3 py-1 mb-3 rounded-full flex items-center text-sm bg-[#F88842]/[0.2] text-[#F88842]"
     >
-      过去 7 天平均每天喂奶 450ml
+      过去 7 天平均每天{{ informText }}
     </view>
 
     <!-- 数据统计区域 -->
-    <div class="grid grid-cols-3 gap-4 mx-4 mb-3">
-      <!-- 喂奶时长 -->
-      <div class="bg-white rounded-lg p-4 flex flex-col items-center justify-center shadow-sm">
-        <span class="text-2xl font-medium text-gray-900">45min</span>
-        <span class="text-sm text-gray-500 mt-1">母乳时长</span>
-      </div>
-
-      <!-- 母乳喂养量 -->
-      <div class="bg-white rounded-lg p-4 flex flex-col items-center justify-center shadow-sm">
-        <span class="text-2xl font-medium text-gray-900">450ml</span>
-        <span class="text-sm text-gray-500 mt-1">母乳喂养</span>
-      </div>
-
-      <!-- 配方奶喂养量 -->
-      <div class="bg-white rounded-lg p-4 flex flex-col items-center justify-center shadow-sm">
-        <span class="text-2xl font-medium text-gray-900">450ml</span>
-        <span class="text-sm text-gray-500 mt-1">配方奶</span>
-      </div>
-    </div>
-
-    <!-- <view v-else class="h-full flex items-center justify-center">
-                <Empty />
-              </view> -->
-    <!-- <wd-loadmore v-if="tabIndex == 0" :state="state" @reload="loadmore" /> -->
+    <view v-if="bannerList.length" class="flex justify-between items-center mx-4 mb-3">
+      <view
+        v-for="(item, index) in bannerList"
+        :key="'bannerList' + item.value"
+        class="bg-white px-4 flex flex-1 flex-col items-center justify-center shadow-sm"
+      >
+        <text class="text-base text-[#333]">{{ item.count }}</text>
+        <text class="text-xs text-[#666] mt-1">{{ item.label }}</text>
+      </view>
+    </view>
+
     <wd-gap bg-color="#F2F2F2"></wd-gap>
     <view class="p-4 flex justify-between items-center">
       <text class="text-base">2020年12月15日</text>
       <text class="text-xs text-[#666]">2岁4个月4天</text>
     </view>
 
-    <RecordList :dataList="records" />
+    <RecordList v-if="records.length" :dataList="records" />
+    <view v-else class="h-full flex items-center justify-center">
+      <Empty />
+    </view>
+    <!-- <wd-loadmore v-if="tabIndex == 0" :state="state" @reload="loadmore" /> -->
+
     <!-- 悬浮添加按钮 -->
     <view
       @click="goToPage('')"
@@ -86,25 +92,33 @@
   </view>
 </template>
 <script setup>
-  import HeightItem from '@/components/height/height-item.vue'
+  import { ref } from 'vue'
+  import { feedMethodList, cacationList } from '@/pages/record/data.js'
+  import { onLoad, onReachBottom } from '@dcloudio/uni-app'
+  import SwitchBtn from '@/components/switch-btn/switch-btn.vue'
   import REcharts from '@/components/height/r-echarts.vue'
   import data from '@/components/feed-wd-popup/data.json'
   import Empty from '@/components/empty/empty.vue'
-  import { ref } from 'vue'
-  import { onLoad, onReachBottom } from '@dcloudio/uni-app'
   import RecordList from '@/components/record-list/record-list.vue'
-  const hList = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
-  const wList = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
-  const tList = [0, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52]
 
-  const tabList = ref(data)
+  const ML = '(ml)'
+  const CI = '(次)'
+  const HOUR = '(小时)'
+  const MINUTE = '(分钟)'
+
+  const hList = [0, 1, 2, 3, 4, 5, 6]
 
+  const tabList = ref(data)
+  const bannerList = ref([])
+  const informText = ref('')
   const tabIndex = ref(0)
 
-  const xAxisData = ref(['1岁', '14个月', '16个月', '1岁半', '20个月', '2岁'])
+  // 图表上面的 按钮切换是否显示
+  const show = ref(false)
+
   const yAxisData = ref([])
-  // const seriesData = ref(['1岁', '14个月', '16个月', '1岁半', '20个月', '2岁'])
   const unit = ref('(cm)')
+  // 列表数据
   const records = ref([
     {
       id: '0',
@@ -112,9 +126,10 @@
       time: '13:00',
       title: '喂奶 200ml',
       desc: '宝宝今天胃口很好',
-
+      imageCount: 0,
       recorder: '妈妈 王小美',
       // image: 'https://ai-public.mastergo.com/ai/img_res/3a46635d73b74316cd39813502beb964.jpg',
+      image: 'https://ai-public.mastergo.com/ai/img_res/3d04b8dc21d0fe5f0f639f125fbd5c53.jpg',
     },
     {
       id: '1',
@@ -123,6 +138,7 @@
       title: '母乳喂养',
       desc: '持续了30分钟',
       recorder: '妈妈 王小美',
+      imageCount: 2,
       image: 'https://ai-public.mastergo.com/ai/img_res/3d04b8dc21d0fe5f0f639f125fbd5c53.jpg',
     },
     {
@@ -132,13 +148,19 @@
       title: '辅食 50ml',
       desc: '今天尝试了新的米糊,宝宝很喜欢',
       recorder: '妈妈 王小美',
+      imageCount: 0,
       image: '',
     },
   ])
-  // const parmas = ref({
-  //   pageSize: 10,
-  //   pageNum: 1,
-  // })
+
+  // 图表数组
+  const echartsItem = ref({
+    id: 'echarts',
+    columns: ['喂奶次数', '喂奶量'],
+    seriesData: [120, 200, 150, 80, 70, 110, 130],
+    yAxisData: [],
+    // unit
+  })
 
   const state = ref('')
   const num = ref(0)
@@ -154,6 +176,15 @@
     })
   }
 
+  // 是显示切换的按钮
+  function handleColumns(params) {
+    if (Array.isArray(params)) {
+      return true
+    } else {
+      return false
+    }
+  }
+
   const growthRecordList = ref([])
   // 获取生长记录
   async function getGrowthRecordList() {
@@ -332,6 +363,7 @@
     // http.post('/')
   }
 
+  // 懒加载
   function loadmore() {
     let data = [
       {
@@ -366,6 +398,7 @@
     }, 200)
   }
 
+  // 触底加载
   onReachBottom(() => {
     if (num.value > 45) {
       state.value = 'finished'
@@ -375,27 +408,152 @@
       state.value = 'finished'
     }
   })
+
+  //
+  function handleSwitch(index) {
+    let data = []
+    switch (index) {
+      case 0:
+        yAxisData.value = hList
+        informText.value = show.value ? '喂奶400ml' : '喂奶7次'
+        unit.value = show.value ? ML : CI
+
+        echartsItem.value = {}
+
+        if (show.value) {
+          data = ['40min', '4000ml', '400ml']
+          bannerList.value = feedMethodList.map((item, index) => ({
+            ...item,
+            count: data[index],
+          }))
+        } else {
+          data = ['1次', '4次', '2次']
+          bannerList.value = feedMethodList.map((item, index) => ({
+            ...item,
+            count: data[index],
+          }))
+        }
+
+        echartsItem.value = {
+          id: 'echarts',
+          columns: ['喂奶次数', '喂奶量'],
+          seriesData: [120, 200, 150, 80, 70, 110, 130],
+          yAxisData: [],
+          // unit
+        }
+
+        break
+      case 1:
+        yAxisData.value = hList
+        informText.value = show.value ? '睡眠20小时' : '睡眠5次'
+        unit.value = CI
+        unit.value = HOUR
+        echartsItem.value = {
+          id: 'echarts',
+          columns: ['睡眠次数', '睡眠时长'],
+          seriesData: [120, 200, 150, 80, 70, 110, 130],
+          yAxisData: [],
+          // unit
+        }
+        bannerList.value = []
+        break
+      case 2:
+        yAxisData.value = hList
+        unit.value = CI
+        informText.value = '换尿布3次'
+        data = ['1次', '2次']
+        bannerList.value = cacationList.map((item, index) => ({
+          ...item,
+          count: data[index],
+        }))
+
+        echartsItem.value = {
+          id: 'echarts',
+          columns: '换尿布次数',
+          seriesData: [120, 200, 150, 80, 70, 110, 130],
+          yAxisData: [],
+          // unit
+        }
+
+        break
+      case 3:
+        yAxisData.value = hList
+        unit.value = CI
+        informText.value = '辅食1次'
+        bannerList.value = []
+        echartsItem.value = {
+          id: 'echarts',
+          columns: '辅食次数',
+          seriesData: [120, 200, 150, 80, 70, 110, 130],
+          yAxisData: [],
+          // unit
+        }
+        break
+      case 4:
+        yAxisData.value = hList
+        unit.value = CI
+        unit.value = ML
+
+        informText.value = show.value ? '吸奶300ml' : '吸奶5次'
+        bannerList.value = []
+
+        echartsItem.value = {
+          id: 'echarts',
+          columns: ['吸奶次数', '吸奶量'],
+          seriesData: [120, 200, 150, 80, 70, 110, 130],
+          yAxisData: [],
+          // unit
+        }
+
+        break
+      case 5:
+        yAxisData.value = hList
+        unit.value = MINUTE
+        informText.value = '洗澡10分钟'
+        bannerList.value = []
+        echartsItem.value = {
+          id: 'echarts',
+          columns: '洗澡时间',
+          seriesData: [120, 200, 150, 80, 70, 110, 130],
+          yAxisData: [],
+          // unit
+        }
+
+        break
+      case 6:
+        yAxisData.value = hList
+        unit.value = MINUTE
+        informText.value = '游泳10分钟'
+        bannerList.value = []
+
+        echartsItem.value = {
+          id: 'echarts',
+          columns: '游泳时间',
+          seriesData: [120, 200, 150, 80, 70, 110, 130],
+          yAxisData: [],
+          // unit
+        }
+        break
+
+      default:
+        break
+    }
+  }
+
+  // tabs 切换
   function changeIndex({ index, name }) {
-    console.log('index: ', index)
+    handleSwitch(index)
     tabIndex.value = index
-    nextTick(() => {
-      if (index == 1) {
-        yAxisData.value = hList
-        unit.value = '(cm)'
-      }
-      if (index == 2) {
-        yAxisData.value = wList
-        unit.value = '(kg)'
-      }
-      if (index == 3) {
-        yAxisData.value = tList
-        unit.value = '(cm)'
-      }
-    })
+  }
+
+  // 图表的切换
+  function handleList() {
+    handleSwitch(tabIndex.value)
   }
 
   onLoad(() => {
     getGrowthRecordList()
+    handleList()
   })
 
   const { safeAreaInsets } = uni.getSystemInfoSync()

+ 4 - 2
src/pages/feed/feed.vue

@@ -138,9 +138,9 @@
       time: '13:00',
       title: '喂奶 200ml',
       desc: '宝宝今天胃口很好',
-
+      imageCount: 0,
       recorder: '妈妈 王小美',
-      // image: 'https://ai-public.mastergo.com/ai/img_res/3a46635d73b74316cd39813502beb964.jpg',
+      image: 'https://ai-public.mastergo.com/ai/img_res/3d04b8dc21d0fe5f0f639f125fbd5c53.jpg',
     },
     {
       id: '1',
@@ -149,6 +149,7 @@
       title: '母乳喂养',
       desc: '持续了30分钟',
       recorder: '妈妈 王小美',
+      imageCount: 2,
       image: 'https://ai-public.mastergo.com/ai/img_res/3d04b8dc21d0fe5f0f639f125fbd5c53.jpg',
     },
     {
@@ -158,6 +159,7 @@
       title: '辅食 50ml',
       desc: '今天尝试了新的米糊,宝宝很喜欢',
       recorder: '妈妈 王小美',
+      imageCount: 0,
       image: '',
     },
   ])

+ 1 - 1
src/pages/height-details/height-details.vue

@@ -21,7 +21,7 @@
     >
       <template v-if="show" #right>
         <view @click="handleClickRight">
-          <image class="w-[40rpx] h-[40rpx]" :src="deleteSvg" mode="scaleToFill" />
+          <image class="w-[40rpx] h-[40rpx]" :src="deleteSvg" mode="widthFix" />
           <!-- <wd-icon name="delete" size="40rpx" color="#FB4848"></wd-icon> -->
         </view>
       </template>

+ 0 - 11
src/pages/person/person.vue

@@ -1,11 +0,0 @@
-<route lang="json5">
-{
-  layout: 'tabbar',
-  style: {
-    navigationBarTitleText: '%tabbar.person%',
-  },
-}
-</route>
-<template>
-  <view>个人中心</view>
-</template>

+ 1 - 1
src/pages/record/record.vue

@@ -20,7 +20,7 @@
     >
       <template v-if="show" #right>
         <view @click="handleClickRight">
-          <image class="w-[40rpx] h-[40rpx]" :src="deleteSvg" mode="scaleToFill" />
+          <image class="w-[40rpx] h-[40rpx]" :src="deleteSvg" mode="widthFix" />
 
           <!-- <wd-icon name="delete" size="40rpx" color="#FB4848"></wd-icon> -->
         </view>