Lower deployment target to iOS 16, replace @Observable with ObservableObject, add navigation and UI compatibility shims, and include login smoke UI tests. Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
876 B
Swift
31 lines
876 B
Swift
//
|
||
// MainTabBadgeViewModel.swift
|
||
// suixinkan
|
||
//
|
||
// Created by Codex on 2026/6/23.
|
||
//
|
||
|
||
import Foundation
|
||
import Combine
|
||
|
||
@MainActor
|
||
/// 主 Tab 角标 ViewModel,负责获取订单 Tab 待核销数量。
|
||
final class MainTabBadgeViewModel: ObservableObject {
|
||
@Published private(set) var pendingWriteOffCount: Int?
|
||
|
||
/// 刷新待核销订单数量,缺少景区或接口失败时清空角标。
|
||
func refreshPendingWriteOffCount(api: OrderServing, scenicId: Int?, storeId: Int?) async {
|
||
guard let scenicId, scenicId > 0 else {
|
||
pendingWriteOffCount = nil
|
||
return
|
||
}
|
||
|
||
do {
|
||
let result = try await api.writeOffList(scenicId: scenicId, storeId: storeId, page: 1, pageSize: 1)
|
||
pendingWriteOffCount = min(result.total, 99)
|
||
} catch {
|
||
pendingWriteOffCount = nil
|
||
}
|
||
}
|
||
}
|