feat: 增加删除记录功能

This commit is contained in:
2026-08-25 15:15:40 +08:00
parent e42d0854ec
commit 98d74918a0
11 changed files with 260 additions and 112 deletions

View File

@@ -1,16 +1,16 @@
<template>
<view class="min-h-screen flex flex-col gap-3 bg-[#f2f4f3]">
<view class="border-b border-gray-100 bg-white px-4 pb-3">
<view class="mt-2 flex items-center justify-between">
<view class="flex flex-col">
<text class="text-lg text-gray-800 font-semibold">
{{ greeting }}
</text>
<text class="mt-0.5 text-xs text-gray-400">
{{ today }}
</text>
</view>
<view class="bg-gradient-to-r from-[#7c3aed] to-[#c084fc] p-2 flex items-center justify-between text-white">
<view class="flex flex-col">
<text class="text-lg text-white font-semibold">
{{ greeting }}
</text>
<text class="mt-0.5 text-xs text-white">
{{ today }}
</text>
</view>
<wd-img :width="40" :height="40" :src="imgURL" />
</view>
<wd-card title="📊 今日概览" custom-class="!mx-2 !mb-0">
@@ -18,22 +18,16 @@
<view
v-for="item in overviewItems"
:key="item.label"
class="rounded-xl bg-[#f2f4f3] p-3 shadow-sm"
class="rounded-xl bg-[#f2f4f3] p-3 shadow-sm flex flex-col gap-1"
>
<view class="flex items-center gap-2">
<view class="h-8 w-8 flex items-center justify-center rounded-full" :class="item.bg">
<text class="text-sm">
{{ item.icon }}
</text>
</view>
<text class="text-xs text-gray-400">
{{ item.label }}
</text>
<text>{{ item.icon }}</text>
<text class="text-gray-400">{{ item.label }}</text>
</view>
<text class="mt-2 block text-xl text-gray-800 font-bold">
<text class="block text-xl text-gray-800 font-bold">
{{ item.value }}
</text>
<text class="mt-1 text-xs text-gray-400">
<text class="text-gray-400">
{{ item.sub }}
</text>
</view>
@@ -83,9 +77,14 @@ import GlucosePopup from "@/components/Home/GlucosePopup.vue";
import TempPopup from "@/components/Home/TempPopup.vue";
import { ref, computed, watch } from 'vue'
import { useRecordStore } from '@/store/record'
import { countRecordsByMonth, getDateStr, getDayRecords } from '@/utils/record'
import {getDateStr, getDayRecords, getTimeStr} from '@/utils/record'
import type { IHealthRecord } from "@/type/record";
import {onShow} from "@dcloudio/uni-app";
import { onShow } from "@dcloudio/uni-app";
import appLogo from '@/static/logo.png'
import {getOverview, getProfile} from "@/utils/profile";
import type {IOverview} from "@/type/profile";
const imgURL = appLogo
defineOptions({
name: 'Home',
@@ -130,43 +129,73 @@ const overviewItems = computed(() => {
// 体重:取最新一条
const weight = list.filter(r => r.type === 'weight').pop()
// 血压:取最新一条
const bp = list.filter(r => r.type === 'bloodPressure').pop()
const bloodPressure = list.filter(r => r.type === 'bloodPressure').pop()
// 睡眠:取最新一条
const sleep = list.filter(r => r.type === 'sleep').pop()
// 运动:全部累加
const sports = list.filter(r => r.type === 'sport')
const sportTotal = sports.reduce((sum, r) => sum + (r.duration || 0), 0)
// 血糖:取最新一条
const bloodSugar = list.filter(r => r.type === 'bloodSugar').pop()
// 体温:取最新一条
const temperature = list.filter(r => r.type === 'temperature').pop()
return [
{
icon: '⚖️',
label: '体重',
value: weight ? `${weight.value} kg` : '未记录',
sub: '',
bg: 'bg-[#E89E3A]',
},
{
icon: '😴',
label: '睡眠',
value: sleep ? `${sleep.duration}h` : '未记录',
sub: '',
bg: 'bg-[#2E5B8C]',
},
{
icon: '🏃',
label: '运动',
value: sportTotal > 0 ? `${sportTotal}min` : '0min',
sub: sportTotal >= 30 ? '已达标' : '目标 30min',
bg: 'bg-[#3A7C5B]',
},
{
icon: '❤️',
label: '血压',
value: bp ? `${bp.systolic}/${bp.diastolic}` : '未记录',
sub: '',
bg: 'bg-[#C04A3C]',
},
]
const overviewList = getOverview()
const result = [] as IOverview[]
overviewList.forEach((item) => {
if (item === 'weight') {
const profile = getProfile()
result.push({
icon: '⚖️',
label: '体重',
value: weight ? `${weight.value} kg` : '未记录',
sub: weight ? profile.height ? `BMI${(weight.value / Math.pow(profile.height / 100, 2)).toFixed(2)} ` : '身高未知' : '',
})
}
else if (item === 'sleep') {
result.push({
icon: '😴',
label: '睡眠',
value: sleep ? `${sleep.duration}h` : '未记录',
sub: sleep ? `${getTimeStr(sleep.startTime)} ~ ${getTimeStr(sleep.endTime)}` : '',
})
}
else if (item === 'sport') {
result.push({
icon: '🏃',
label: '运动',
value: sportTotal > 0 ? `${sportTotal}min` : '0min',
sub: sportTotal >= 30 ? '已达标' : '目标 30min',
})
}
else if (item === 'bloodPressure') {
result.push({
icon: '❤️',
label: '血压',
value: bloodPressure ? `${bloodPressure.systolic}/${bloodPressure.diastolic}` : '未记录',
sub: bloodPressure ? `心率:${bloodPressure.heartRate}` : '',
})
}
else if (item === 'bloodSugar') {
result.push({
icon: '🩸',
label: '血糖',
value: bloodSugar ? `${bloodSugar.value}mmol/L` : '未记录',
sub: bloodSugar ? `${bloodSugar.period}` : '',
})
}
else if (item === 'temperature') {
result.push({
icon: '🌡️',
label: '体温',
value: temperature ? `${temperature.value}` : '未记录',
sub: temperature ? `${temperature.location}` : '',
})
}
})
return result
})
// 今日计划