fix(shift): badge color contrast and dynamic calendar rows

- 角标文字色按背景类别配对:班=onPrimary,休=onError,起=onTertiary
- 迷你月历复用 getMonthGridInfo 动态算行数(4/5/6),不再固定 6 行
This commit is contained in:
xfy 2026-07-09 16:36:36 +08:00
parent f8df108bf3
commit 4b098442c4

View File

@ -69,9 +69,10 @@ fun ShiftCalendarGrid(
var viewYear by remember { mutableStateOf(today.year) }
var viewMonth by remember { mutableStateOf(today.month.number) }
val firstOfMonth = LocalDate(viewYear, Month(viewMonth), 1)
val daysInMonth = firstOfMonth.plus(DatePeriod(months = 1)).minus(DatePeriod(days = 1)).day
val firstWeekdayOffset = firstOfMonth.dayOfWeek.isoDayNumber - 1
// 复用主日历的网格计算(周一为首日,动态行数 4/5/6)
val gridInfo = remember(viewYear, viewMonth) { getMonthGridInfo(viewYear, viewMonth) }
val firstWeekdayOffset = gridInfo.offset
val rows = gridInfo.rows
Card(
modifier = modifier.fillMaxWidth(),
@ -115,12 +116,12 @@ fun ShiftCalendarGrid(
}
}
(0 until 6).forEach { row ->
(0 until rows).forEach { row ->
Row(Modifier.fillMaxWidth()) {
(0 until 7).forEach { col ->
val cellIndex = row * 7 + col
val dayNum = cellIndex - firstWeekdayOffset + 1
if (dayNum in 1..daysInMonth) {
if (dayNum in 1..gridInfo.daysInMonth) {
val date = LocalDate(viewYear, Month(viewMonth), dayNum)
ShiftDayCell(
date = date,
@ -209,12 +210,19 @@ private fun ShiftDayCell(
// rephaseFlip 的 rephaseFrom = 当天,表示该天为重排起点
val isRephaseStart = pattern.rephaseFlips.any { it.rephaseFrom == date }
// 背景色与文字色配对,保证对比度(对照 DayCell 的配色风格)
val badgeColor = when {
isRephaseStart -> MaterialTheme.colorScheme.tertiary
kind == ShiftKind.WORK -> MaterialTheme.colorScheme.primary
kind == ShiftKind.OFF -> MaterialTheme.colorScheme.error
else -> Color.Transparent
}
val badgeTextColor = when {
isRephaseStart -> MaterialTheme.colorScheme.onTertiary
kind == ShiftKind.WORK -> MaterialTheme.colorScheme.onPrimary
kind == ShiftKind.OFF -> MaterialTheme.colorScheme.onError
else -> Color.Transparent
}
val badgeText = when {
isRephaseStart -> ""
kind == ShiftKind.WORK -> ""
@ -243,7 +251,7 @@ private fun ShiftDayCell(
) {
Text(
text = badgeText,
color = MaterialTheme.colorScheme.onPrimary,
color = badgeTextColor,
fontSize = 8.sp,
fontWeight = FontWeight.Bold,
lineHeight = 8.sp