Skip to content

Commit 8ec1606

Browse files
committed
Custom-Alarm:improve:状态页面本月信息增加可休天数和剩余调班天数统计
1 parent b6cfa85 commit 8ec1606

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

Custom-Alarm/components/HomeView.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,21 +337,30 @@ export function HomeView() {
337337
}, [records, holidaySourceMap])
338338
const selectedHolidaySource = holidaySources.find((item) => item.id === DEFAULT_HOLIDAY_SOURCE_ID) ?? holidaySources[0] ?? null
339339
const currentMonthSummary = useMemo(() => {
340-
if (!selectedHolidaySource) return { off: 0, work: 0 }
340+
if (!selectedHolidaySource) return { totalOff: 0, remainingOff: 0, totalWork: 0, remainingWork: 0 }
341341

342342
const dayMap = buildHolidayDayMap(selectedHolidaySource)
343343
const now = new Date()
344344
const prefix = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-`
345-
let off = 0
346-
let work = 0
345+
const todayKey = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`
346+
let totalOff = 0
347+
let remainingOff = 0
348+
let totalWork = 0
349+
let remainingWork = 0
347350

348351
for (const [dateKey, info] of dayMap.entries()) {
349352
if (!dateKey.startsWith(prefix)) continue
350-
if (info.kind === "off") off += 1
351-
if (info.kind === "work") work += 1
353+
if (info.kind === "off") {
354+
totalOff += 1
355+
if (dateKey >= todayKey) remainingOff += 1
356+
}
357+
if (info.kind === "work") {
358+
totalWork += 1
359+
if (dateKey >= todayKey) remainingWork += 1
360+
}
352361
}
353362

354-
return { off, work }
363+
return { totalOff, remainingOff, totalWork, remainingWork }
355364
}, [selectedHolidaySource])
356365

357366
function saveStateSnapshot(
@@ -738,8 +747,10 @@ export function HomeView() {
738747
cleanupCandidateCount={cleanupCandidateAlarmIds.length}
739748
currentHolidayTitle={selectedHolidaySource?.title || ""}
740749
syncedHolidayCount={selectedHolidaySource?.holidayDates.length ?? 0}
741-
currentMonthOffCount={currentMonthSummary.off}
742-
currentMonthWorkCount={currentMonthSummary.work}
750+
currentMonthTotalOffCount={currentMonthSummary.totalOff}
751+
currentMonthRemainingOffCount={currentMonthSummary.remainingOff}
752+
currentMonthTotalWorkCount={currentMonthSummary.totalWork}
753+
currentMonthRemainingWorkCount={currentMonthSummary.remainingWork}
743754
lastSyncedAt={selectedHolidaySource?.lastSyncedAt ?? null}
744755
/>
745756
</NavigationStack>

Custom-Alarm/components/StatusView.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ export function StatusView(props: {
4242
cleanupCandidateCount: number
4343
currentHolidayTitle: string
4444
syncedHolidayCount: number
45-
currentMonthOffCount: number
46-
currentMonthWorkCount: number
45+
currentMonthTotalOffCount: number
46+
currentMonthRemainingOffCount: number
47+
currentMonthTotalWorkCount: number
48+
currentMonthRemainingWorkCount: number
4749
lastSyncedAt: number | null
4850
embedded?: boolean
4951
}) {
@@ -77,8 +79,10 @@ export function StatusView(props: {
7779
</Section>
7880

7981
<Section header={<Text>本月信息</Text>}>
80-
<MetricRow icon="sun.max.fill" title="可休假天数" value={String(props.currentMonthOffCount)} tint="#EA580C" />
81-
<MetricRow icon="briefcase.fill" title="调班天数" value={String(props.currentMonthWorkCount)} tint="#2563EB" />
82+
<MetricRow icon="calendar.badge.clock" title="总休假天数" value={String(props.currentMonthTotalOffCount)} tint="#F97316" />
83+
<MetricRow icon="sun.max.fill" title="可休假天数" value={String(props.currentMonthRemainingOffCount)} tint="#EA580C" />
84+
<MetricRow icon="calendar.badge.exclamationmark" title="总调班天数" value={String(props.currentMonthTotalWorkCount)} tint="#3B82F6" />
85+
<MetricRow icon="briefcase.fill" title="剩余调班天数" value={String(props.currentMonthRemainingWorkCount)} tint="#2563EB" />
8286
</Section>
8387

8488
{!props.embedded && (

0 commit comments

Comments
 (0)