Files
health-mp/src/pages/stats/index.vue
2026-08-31 15:23:17 +08:00

267 lines
5.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="min-h-screen flex flex-col bg-gradient-to-b from-[#a78bfa] to-[#f3e8ff]">
<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 title="体重">
<qiun-data-charts
v-if="weightChartData.categories?.length"
type="line"
:opts="chartOpts"
:chartData="weightChartData"
/>
<wd-empty v-else icon="no-content" tip="暂无记录" />
</wd-card>
<wd-card title="睡眠">
<qiun-data-charts
v-if="sleepChartData.categories?.length"
type="line"
:opts="chartOpts"
:chartData="sleepChartData"
/>
<wd-empty v-else icon="no-content" tip="暂无记录" />
</wd-card>
<wd-card title="运动">
<qiun-data-charts
v-if="sportChartData.categories?.length"
type="line"
:opts="chartOpts"
:chartData="sportChartData"
/>
<wd-empty v-else icon="no-content" tip="暂无记录" />
</wd-card>
<wd-card title="血压">
<qiun-data-charts
v-if="bloodPressureChartData.categories?.length"
type="line"
:opts="chartOpts"
:chartData="bloodPressureChartData"
/>
<wd-empty v-else icon="no-content" tip="暂无记录" />
</wd-card>
<wd-card title="血糖">
<qiun-data-charts
v-if="bloodSugarChartData.categories?.length"
type="line"
:opts="chartOpts"
:chartData="bloodSugarChartData"
/>
<wd-empty v-else icon="no-content" tip="暂无记录" />
</wd-card>
<wd-card title="体温">
<qiun-data-charts
v-if="temperatureChartData.categories?.length"
type="line"
:opts="chartOpts"
:chartData="temperatureChartData"
/>
<wd-empty v-else icon="no-content" tip="暂无记录" />
</wd-card>
</view>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { getRecentRecords } from '@/utils/record'
import { onShow } from "@dcloudio/uni-app";
const weightChartData = ref({
categories: [] as string[],
series: [] as any[]
})
const sleepChartData = ref({
categories: [] as string[],
series: [] as any[]
})
const sportChartData = ref({
categories: [] as string[],
series: [] as any[]
})
const bloodPressureChartData = ref({
categories: [] as string[],
series: [] as any[]
})
const bloodSugarChartData = ref({
categories: [] as string[],
series: [] as any[]
})
const temperatureChartData = ref({
categories: [] as string[],
series: [] as any[]
})
// 图表配置
const chartOpts = {
color: ['#1890FF', '#EE6666', '#91CB74', '#FAC858', '#73C0DE'],
padding: [15, 10, 0, 15],
enableScroll: false,
legend: { show: true },
xAxis: { disableGrid: true },
yAxis: {
gridType: 'dash',
dashLength: 2,
data: [
{ min: 0, format: (val: number) => val.toFixed(1) }
]
},
extra: {
line: { type: 'straight', width: 2, activeType: 'hollow'},
},
}
function getWeightChartData() {
const list = getRecentRecords('weight', 7)
if (list.length) {
const categories = list.map((_, index) => String(index + 1))
weightChartData.value = {
categories,
series: [
{
name: '体重Kg',
data: list.map((r) => r.value),
},
],
}
} else {
weightChartData.value = {
categories: [], series: []
}
}
}
function getSleepChartData() {
const list = getRecentRecords('sleep', 7)
if (list.length) {
const categories = list.map((_, index) => String(index + 1))
sleepChartData.value = {
categories,
series: [
{
name: '睡眠(小时)',
data: list.map((r) => r.duration),
},
],
}
} else {
sleepChartData.value = {
categories: [], series: []
}
}
}
function getSportChartData() {
const list = getRecentRecords('sport', 7)
if (list.length) {
const categories = list.map((_, index) => String(index + 1))
sportChartData.value = {
categories,
series: [
{
name: '运动(分钟)',
data: list.map((r) => r.duration),
},
],
}
} else {
sportChartData.value = {
categories: [], series: []
}
}
}
function getBloodPressureChartData() {
const list = getRecentRecords('bloodPressure', 7)
if (list.length) {
const categories = list.map((_, index) => String(index + 1))
bloodPressureChartData.value = {
categories,
series: [
{ name: '收缩压mmHg', data: list.map((r) => r.systolic) },
{ name: '舒张压mmHg', data: list.map((r) => r.diastolic) },
],
}
} else {
bloodPressureChartData.value = {
categories: [], series: []
}
}
}
function getBloodSugarChartData() {
const list = getRecentRecords('bloodSugar', 7)
if (list.length) {
const categories = list.map((_, index) => String(index + 1))
bloodSugarChartData.value = {
categories,
series: [
{
name: '血糖mmol/L',
data: list.map((r) => r.value),
},
],
}
} else {
bloodSugarChartData.value = {
categories: [], series: []
}
}
}
function getTemperatureChartData() {
const list = getRecentRecords('temperature', 7)
if (list.length) {
const categories = list.map((_, index) => String(index + 1))
temperatureChartData.value = {
categories,
series: [
{
name: '体温(℃)',
data: list.map((r) => r.value),
},
],
}
} else {
temperatureChartData.value = {
categories: [], series: []
}
}
}
onShow(() => {
getWeightChartData()
getSleepChartData()
getSportChartData()
getBloodPressureChartData()
getBloodSugarChartData()
getTemperatureChartData()
})
</script>