feat: 优化线下收款日历交互与选中态

This commit is contained in:
2026-08-26 14:19:02 +08:00
parent 4351c26e74
commit 9fce6ef713
5 changed files with 262 additions and 58 deletions
@@ -56,6 +56,28 @@ struct OfflineCollectionCalendarState: Sendable, Equatable {
return selectedDate
}
/// 判断指定方向是否存在不晚于服务端今日的周或月页面。
func canMovePage(_ offset: Int) -> Bool {
guard offset != 0 else { return false }
if offset < 0 { return true }
switch mode {
case .week:
guard let candidate = calendar.date(byAdding: .day, value: offset * 7, to: selectedDate) else { return false }
let weekday = calendar.component(.weekday, from: candidate)
let daysFromMonday = (weekday + 5) % 7
let targetMonday = calendar.date(byAdding: .day, value: -daysFromMonday, to: candidate) ?? candidate
return calendar.startOfDay(for: targetMonday) <= maximumDate
case .month:
let current = calendar.dateComponents([.year, .month], from: selectedDate)
guard let monthStart = calendar.date(from: current),
let targetMonth = calendar.date(byAdding: .month, value: offset, to: monthStart) else { return false }
let maximumMonth = calendar.date(
from: calendar.dateComponents([.year, .month], from: maximumDate)
) ?? maximumDate
return targetMonth <= maximumMonth
}
}
/// 当前周的周一至周日。
var weekDates: [Date] {
let weekday = calendar.component(.weekday, from: selectedDate)
@@ -74,6 +96,12 @@ struct OfflineCollectionCalendarState: Sendable, Equatable {
return (0 ..< 42).compactMap { calendar.date(byAdding: .day, value: $0, to: start) }
}
/// 当前选中日期所在周在固定六行月历中的零基行号。
var selectedWeekRowIndex: Int {
let index = monthDates.firstIndex { calendar.isDate($0, inSameDayAs: selectedDate) } ?? 0
return index / 7
}
/// 当前选中月份标题。
var monthTitle: String {
let parts = calendar.dateComponents([.year, .month], from: selectedDate)