feat: 增加血糖统计图类别
This commit is contained in:
@@ -1,115 +1,122 @@
|
||||
<template>
|
||||
<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="flex min-w-0 flex-col">
|
||||
<text class="truncate text-lg text-white font-semibold">
|
||||
最近7次趋势
|
||||
</text>
|
||||
<wd-config-provider :theme-vars="getTheme(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="flex min-w-0 flex-col">
|
||||
<text class="truncate text-lg text-white font-semibold">
|
||||
最近7次趋势
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('weight')" title="体重">
|
||||
<qiun-data-charts
|
||||
v-if="weightChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="weightChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="weightChartData.categories?.length"
|
||||
:avg="avgWeight" :min="minWeight" :max="maxWeight" />
|
||||
</wd-card>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('sleep')" title="睡眠">
|
||||
<qiun-data-charts
|
||||
v-if="sleepChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="sleepChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="sleepChartData.categories?.length"
|
||||
:avg="avgSleep" :min="minSleep" :max="maxSleep" />
|
||||
</wd-card>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('sport')" title="运动">
|
||||
<qiun-data-charts
|
||||
v-if="sportChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="sportChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="sportChartData.categories?.length"
|
||||
:avg="avgSport" :min="minSport" :max="maxSport" />
|
||||
</wd-card>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('bloodPressure')" title="血压">
|
||||
<qiun-data-charts
|
||||
v-if="bloodPressureChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="bloodPressureChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="bloodPressureChartData.categories?.length"
|
||||
:avg="avgSystolic" :min="minSystolic" :max="maxSystolic" />
|
||||
<summary-card v-if="bloodPressureChartData.categories?.length"
|
||||
:avg="avgDiastolic" :min="minDiastolic" :max="maxDiastolic" />
|
||||
</wd-card>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('bloodPressure')" title="心率">
|
||||
<qiun-data-charts
|
||||
v-if="heartRateChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="heartRateChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="heartRateChartData.categories?.length"
|
||||
:avg="avgHeartRate" :min="minHeartRate" :max="maxHeartRate" />
|
||||
</wd-card>
|
||||
|
||||
<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
|
||||
v-if="bloodSugarChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="bloodSugarChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="bloodSugarChartData.categories?.length"
|
||||
:avg="avgBloodSugar" :min="minBloodSugar" :max="maxBloodSugar" />
|
||||
</wd-card>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('temperature')" title="体温">
|
||||
<qiun-data-charts
|
||||
v-if="temperatureChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="temperatureChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="temperatureChartData.categories?.length"
|
||||
:avg="avgTemperature" :min="minTemperature" :max="maxTemperature" />
|
||||
</wd-card>
|
||||
|
||||
<view class="h-[10px]"></view>
|
||||
</view>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('weight')" title="体重">
|
||||
<qiun-data-charts
|
||||
v-if="weightChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="weightChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="weightChartData.categories?.length"
|
||||
:avg="avgWeight" :min="minWeight" :max="maxWeight" />
|
||||
</wd-card>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('sleep')" title="睡眠">
|
||||
<qiun-data-charts
|
||||
v-if="sleepChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="sleepChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="sleepChartData.categories?.length"
|
||||
:avg="avgSleep" :min="minSleep" :max="maxSleep" />
|
||||
</wd-card>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('sport')" title="运动">
|
||||
<qiun-data-charts
|
||||
v-if="sportChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="sportChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="sportChartData.categories?.length"
|
||||
:avg="avgSport" :min="minSport" :max="maxSport" />
|
||||
</wd-card>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('bloodPressure')" title="血压">
|
||||
<qiun-data-charts
|
||||
v-if="bloodPressureChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="bloodPressureChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="bloodPressureChartData.categories?.length"
|
||||
:avg="avgSystolic" :min="minSystolic" :max="maxSystolic" />
|
||||
<summary-card v-if="bloodPressureChartData.categories?.length"
|
||||
:avg="avgDiastolic" :min="minDiastolic" :max="maxDiastolic" />
|
||||
</wd-card>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('bloodPressure')" title="心率">
|
||||
<qiun-data-charts
|
||||
v-if="heartRateChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="heartRateChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="heartRateChartData.categories?.length"
|
||||
:avg="avgHeartRate" :min="minHeartRate" :max="maxHeartRate" />
|
||||
</wd-card>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('bloodSugar')" title="血糖">
|
||||
<qiun-data-charts
|
||||
v-if="bloodSugarChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="bloodSugarChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="bloodSugarChartData.categories?.length"
|
||||
:avg="avgBloodSugar" :min="minBloodSugar" :max="maxBloodSugar" />
|
||||
</wd-card>
|
||||
|
||||
<wd-card v-if="profileStore.statsList.includes('temperature')" title="体温">
|
||||
<qiun-data-charts
|
||||
v-if="temperatureChartData.categories?.length"
|
||||
type="line"
|
||||
:opts="chartOpts"
|
||||
:chartData="temperatureChartData"
|
||||
/>
|
||||
|
||||
<wd-empty v-else icon="no-content" tip="暂无记录" />
|
||||
|
||||
<summary-card v-if="temperatureChartData.categories?.length"
|
||||
:avg="avgTemperature" :min="minTemperature" :max="maxTemperature" />
|
||||
</wd-card>
|
||||
|
||||
<view class="h-[10px]"></view>
|
||||
</view>
|
||||
</wd-config-provider>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -119,12 +126,19 @@ import { onShow } from "@dcloudio/uni-app";
|
||||
import { useProfileStore } from '@/store/profile'
|
||||
import { useAppStore } from '@/store/app'
|
||||
import { getStats } from "@/utils/profile";
|
||||
import { getThemeStyle } from "@/utils/themes";
|
||||
import { getTheme, getThemeStyle } from "@/utils/themes";
|
||||
import SummaryCard from "@/components/Stats/SummaryCard.vue";
|
||||
|
||||
const profileStore = useProfileStore()
|
||||
const appStore = useAppStore()
|
||||
|
||||
const currentPeriod = ref('空腹')
|
||||
const periodColumns = [
|
||||
{ label: '空腹', value: '空腹' },
|
||||
{ label: '餐前', value: '餐前' },
|
||||
{ label: '餐后2h', value: '餐后2h' }
|
||||
]
|
||||
|
||||
const weightChartData = ref({
|
||||
categories: [] as string[],
|
||||
series: [] as any[]
|
||||
@@ -353,8 +367,7 @@ function getHeartRateChartData() {
|
||||
}
|
||||
|
||||
function getBloodSugarChartData() {
|
||||
const list = getRecentRecords('bloodSugar', 7)
|
||||
|
||||
const list = getRecentRecords(`bloodSugar_${currentPeriod.value}`, 7)
|
||||
if (list.length) {
|
||||
const categories = list.map((_, index) => String(index + 1))
|
||||
|
||||
@@ -420,4 +433,8 @@ onShow(() => {
|
||||
getBloodSugarChartData()
|
||||
getTemperatureChartData()
|
||||
})
|
||||
|
||||
function handleChangeBloodSugar() {
|
||||
getBloodSugarChartData()
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -84,7 +84,13 @@ function addRecord(type: string, data: Record<string, any>, timestamp: number) {
|
||||
* @param limit
|
||||
*/
|
||||
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) || []
|
||||
|
||||
// 正序:timestamp 小的在前
|
||||
@@ -105,10 +111,16 @@ function appendRecentRecord(type: string, record: any, limit = 7) {
|
||||
/**
|
||||
* 删除最近记录的数据
|
||||
* @param type 类型
|
||||
* @param record 记录
|
||||
* @param id id
|
||||
*/
|
||||
function removeFromRecentIndex(type: string, id: string) {
|
||||
const key = `recent_${type}`
|
||||
function removeFromRecentIndex(type: string, record: any, id: string) {
|
||||
let key = ''
|
||||
if (type === 'bloodSugar') {
|
||||
key = `recent_${type}_${record.period}`
|
||||
} else {
|
||||
key = `recent_${type}`
|
||||
}
|
||||
const recent = wx.getStorageSync(key) || []
|
||||
|
||||
const idx = recent.findIndex((item: any) => item.id === id)
|
||||
@@ -159,7 +171,7 @@ export function deleteRecordByDate(date: string, id: string) {
|
||||
wx.setStorageSync(key, all)
|
||||
}
|
||||
|
||||
removeFromRecentIndex(type, id)
|
||||
removeFromRecentIndex(type, record, id)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user