import { ScrollView, Text, View } from "@tarojs/components"; import Taro from "@tarojs/taro"; import type { CSSProperties } from "react"; import { useMemo, useState } from "react"; import { ReportChartCard } from "../../components/report/chart-card"; import { ReportChipGroup } from "../../components/report/chip-group"; import { ReportDaytimePrediction } from "../../components/report/daytime-prediction"; import { ReportDistributionCard } from "../../components/report/distribution-card"; import { ReportInsightList } from "../../components/report/insight-list"; import { ReportKvList } from "../../components/report/kv-list"; import { ReportMetricGrid } from "../../components/report/metric-grid"; import { ReportPageHeader } from "../../components/report/page-header"; import { ReportScoreOverview } from "../../components/report/score-overview"; import { ReportSummaryBlock } from "../../components/report/summary-block"; import { reportDimensions, reportOptions, reportRecords } from "./mock"; import { getSleepLevel, pickReportRecord } from "./report-utils"; import type { ReportDimension } from "./types"; import "./index.scss"; function getDefaultSelection(dimension: ReportDimension) { const options = reportOptions[dimension]; return { dateKey: options.dates[0].value, roomKey: options.rooms[0].value, deviceKey: options.devices[0].value }; } export default function ReportPage() { const [dimension, setDimension] = useState("daily"); const initialSelection = getDefaultSelection("daily"); const [dateKey, setDateKey] = useState(initialSelection.dateKey); const [roomKey, setRoomKey] = useState(initialSelection.roomKey); const [deviceKey, setDeviceKey] = useState(initialSelection.deviceKey); const currentOptions = reportOptions[dimension]; const currentRecord = useMemo( () => pickReportRecord(reportRecords[dimension], dateKey, roomKey, deviceKey), [dateKey, deviceKey, dimension, roomKey] ); const sleepLevel = getSleepLevel(currentRecord.score); const [selectedSleepTrend, setSelectedSleepTrend] = useState(currentRecord.sleepTrend[0].id); const [selectedScoreTrend, setSelectedScoreTrend] = useState(currentRecord.scoreTrend[0].id); const [selectedHeartRatePoint, setSelectedHeartRatePoint] = useState(currentRecord.heartRatePoints[0].id); const [selectedBreathingPoint, setSelectedBreathingPoint] = useState(currentRecord.breathingPoints[0].id); const [selectedEventPoint, setSelectedEventPoint] = useState(currentRecord.eventPoints[0].id); const resetSelections = (nextDimension: ReportDimension, nextDate: string, nextRoom: string, nextDevice: string) => { const record = pickReportRecord(reportRecords[nextDimension], nextDate, nextRoom, nextDevice); setSelectedSleepTrend(record.sleepTrend[0].id); setSelectedScoreTrend(record.scoreTrend[0].id); setSelectedHeartRatePoint(record.heartRatePoints[0].id); setSelectedBreathingPoint(record.breathingPoints[0].id); setSelectedEventPoint(record.eventPoints[0].id); }; const handleDimensionChange = (nextValue: string) => { const nextDimension = nextValue as ReportDimension; const nextSelection = getDefaultSelection(nextDimension); setDimension(nextDimension); setDateKey(nextSelection.dateKey); setRoomKey(nextSelection.roomKey); setDeviceKey(nextSelection.deviceKey); resetSelections(nextDimension, nextSelection.dateKey, nextSelection.roomKey, nextSelection.deviceKey); }; const handleDateChange = (nextDate: string) => { setDateKey(nextDate); resetSelections(dimension, nextDate, roomKey, deviceKey); }; const handleRoomChange = (nextRoom: string) => { setRoomKey(nextRoom); resetSelections(dimension, dateKey, nextRoom, deviceKey); }; const handleDeviceChange = (nextDevice: string) => { setDeviceKey(nextDevice); resetSelections(dimension, dateKey, roomKey, nextDevice); }; const pageStyle = { "--report-top-gap": `${(typeof Taro.getWindowInfo === "function" ? Taro.getWindowInfo().statusBarHeight : Taro.getSystemInfoSync().statusBarHeight) || 0}px` } as CSSProperties; return ( Taro.navigateBack({ delta: 1 })} onShare={() => Taro.showToast({ title: "分享功能待接入", icon: "none" }) } /> 日期 房间 设备 ); }