Sync migrated iOS modules
This commit is contained in:
@ -13,6 +13,9 @@ enum AppDesign {
|
||||
static let primarySoft = Color(hex: 0xEFF6FF)
|
||||
static let textPrimary = Color(hex: 0x1F2937)
|
||||
static let textSecondary = Color(hex: 0x6B7280)
|
||||
static let placeholder = Color(hex: 0xA8B2C1)
|
||||
static let success = Color(hex: 0x14964A)
|
||||
static let warning = Color(hex: 0xFF7B00)
|
||||
}
|
||||
|
||||
extension Color {
|
||||
@ -27,3 +30,16 @@ extension Color {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
/// 应用通用输入框背景、圆角和描边样式。
|
||||
func appInputFieldStyle(cornerRadius: CGFloat, minHeight: CGFloat) -> some View {
|
||||
padding(.horizontal, AppMetrics.Spacing.medium)
|
||||
.frame(minHeight: minHeight)
|
||||
.background(Color(hex: 0xF8FAFC), in: RoundedRectangle(cornerRadius: cornerRadius))
|
||||
.overlay {
|
||||
RoundedRectangle(cornerRadius: cornerRadius)
|
||||
.stroke(Color(hex: 0xE2E8F0), lineWidth: 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,6 +32,34 @@ struct ListPayload<T: Decodable>: Decodable {
|
||||
}
|
||||
}
|
||||
|
||||
/// 数据列表响应实体,表示后端常见的 total + data 分页结构,并兼容 list 字段。
|
||||
struct DataListPayload<T: Decodable>: Decodable {
|
||||
let total: Int
|
||||
let data: [T]
|
||||
|
||||
/// 数据列表响应的 JSON 字段映射。
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case total
|
||||
case data
|
||||
case list
|
||||
}
|
||||
|
||||
/// 创建数据列表响应,主要用于测试和本地兜底数据。
|
||||
init(total: Int, data: [T]) {
|
||||
self.total = total
|
||||
self.data = data
|
||||
}
|
||||
|
||||
/// 自定义解码,兼容 data/list 字段和 total 字符串。
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
total = try container.decodeLossyInt(forKey: .total) ?? 0
|
||||
data = try container.decodeIfPresent([T].self, forKey: .data)
|
||||
?? container.decodeIfPresent([T].self, forKey: .list)
|
||||
?? []
|
||||
}
|
||||
}
|
||||
|
||||
private extension KeyedDecodingContainer {
|
||||
/// 将 Int、Double 或数字字符串宽松解码为整数。
|
||||
func decodeLossyInt(forKey key: Key) throws -> Int? {
|
||||
|
||||
Reference in New Issue
Block a user