feat: 增加血糖统计图类别

This commit is contained in:
2026-09-01 16:19:47 +08:00
parent 1592d5adaa
commit 973b2c0705
2 changed files with 145 additions and 116 deletions

View File

@@ -1,4 +1,5 @@
<template> <template>
<wd-config-provider :theme-vars="getTheme(appStore.themeColor)">
<view class="min-h-screen flex flex-col" :style="getThemeStyle[appStore.themeColor]"> <view class="min-h-screen flex flex-col" :style="getThemeStyle[appStore.themeColor]">
<view class="self-center py-3 flex items-center gap-2 text-gray-800"> <view class="self-center py-3 flex items-center gap-2 text-gray-800">
<view class="flex min-w-0 flex-col"> <view class="flex min-w-0 flex-col">
@@ -81,6 +82,11 @@
</wd-card> </wd-card>
<wd-card v-if="profileStore.statsList.includes('bloodSugar')" title="血糖"> <wd-card v-if="profileStore.statsList.includes('bloodSugar')" title="血糖">
<wd-segmented :options="periodColumns" v-model:value="currentPeriod" theme="outline"
@change="handleChangeBloodSugar"></wd-segmented>
<view class="h-[5px]"></view>
<qiun-data-charts <qiun-data-charts
v-if="bloodSugarChartData.categories?.length" v-if="bloodSugarChartData.categories?.length"
type="line" type="line"
@@ -110,6 +116,7 @@
<view class="h-[10px]"></view> <view class="h-[10px]"></view>
</view> </view>
</wd-config-provider>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@@ -119,12 +126,19 @@ import { onShow } from "@dcloudio/uni-app";
import { useProfileStore } from '@/store/profile' import { useProfileStore } from '@/store/profile'
import { useAppStore } from '@/store/app' import { useAppStore } from '@/store/app'
import { getStats } from "@/utils/profile"; import { getStats } from "@/utils/profile";
import { getThemeStyle } from "@/utils/themes"; import { getTheme, getThemeStyle } from "@/utils/themes";
import SummaryCard from "@/components/Stats/SummaryCard.vue"; import SummaryCard from "@/components/Stats/SummaryCard.vue";
const profileStore = useProfileStore() const profileStore = useProfileStore()
const appStore = useAppStore() const appStore = useAppStore()
const currentPeriod = ref('空腹')
const periodColumns = [
{ label: '空腹', value: '空腹' },
{ label: '餐前', value: '餐前' },
{ label: '餐后2h', value: '餐后2h' }
]
const weightChartData = ref({ const weightChartData = ref({
categories: [] as string[], categories: [] as string[],
series: [] as any[] series: [] as any[]
@@ -353,8 +367,7 @@ function getHeartRateChartData() {
} }
function getBloodSugarChartData() { function getBloodSugarChartData() {
const list = getRecentRecords('bloodSugar', 7) const list = getRecentRecords(`bloodSugar_${currentPeriod.value}`, 7)
if (list.length) { if (list.length) {
const categories = list.map((_, index) => String(index + 1)) const categories = list.map((_, index) => String(index + 1))
@@ -420,4 +433,8 @@ onShow(() => {
getBloodSugarChartData() getBloodSugarChartData()
getTemperatureChartData() getTemperatureChartData()
}) })
function handleChangeBloodSugar() {
getBloodSugarChartData()
}
</script> </script>

View File

@@ -84,7 +84,13 @@ function addRecord(type: string, data: Record<string, any>, timestamp: number) {
* @param limit * @param limit
*/ */
function appendRecentRecord(type: string, record: any, limit = 7) { function appendRecentRecord(type: string, record: any, limit = 7) {
const key = `recent_${type}` let key = ''
if (type === 'bloodSugar') {
key = `recent_${type}_${record.period}`
} else {
key = `recent_${type}`
}
const recent = wx.getStorageSync(key) || [] const recent = wx.getStorageSync(key) || []
// 正序timestamp 小的在前 // 正序timestamp 小的在前
@@ -105,10 +111,16 @@ function appendRecentRecord(type: string, record: any, limit = 7) {
/** /**
* 删除最近记录的数据 * 删除最近记录的数据
* @param type 类型 * @param type 类型
* @param record 记录
* @param id id * @param id id
*/ */
function removeFromRecentIndex(type: string, id: string) { function removeFromRecentIndex(type: string, record: any, id: string) {
const key = `recent_${type}` let key = ''
if (type === 'bloodSugar') {
key = `recent_${type}_${record.period}`
} else {
key = `recent_${type}`
}
const recent = wx.getStorageSync(key) || [] const recent = wx.getStorageSync(key) || []
const idx = recent.findIndex((item: any) => item.id === id) const idx = recent.findIndex((item: any) => item.id === id)
@@ -159,7 +171,7 @@ export function deleteRecordByDate(date: string, id: string) {
wx.setStorageSync(key, all) wx.setStorageSync(key, all)
} }
removeFromRecentIndex(type, id) removeFromRecentIndex(type, record, id)
} }
/** /**