You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
5.0 KiB
124 lines
5.0 KiB
import SwiftUI
|
|
|
|
// MARK: - 条形码验证信息显示组件
|
|
struct BarcodeValidationInfoView: View {
|
|
let validationResult: BarcodeValidator.ValidationResult?
|
|
let barcodeType: BarcodeType
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
if let result = validationResult {
|
|
// 验证状态指示器
|
|
HStack(spacing: 8) {
|
|
Image(systemName: result.isValid ? "checkmark.circle.fill" : "xmark.circle.fill")
|
|
.foregroundColor(result.isValid ? .green : .red)
|
|
|
|
Text(result.isValid ? NSLocalizedString("format_correct", comment: "Format correct") : NSLocalizedString("format_error", comment: "Format error"))
|
|
.font(.caption)
|
|
.foregroundColor(result.isValid ? .green : .red)
|
|
.fontWeight(.medium)
|
|
|
|
Spacer()
|
|
}
|
|
|
|
// 错误信息
|
|
if let errorMessage = result.errorMessage {
|
|
Text(errorMessage)
|
|
.font(.caption)
|
|
.foregroundColor(.red)
|
|
.padding(.leading, 24)
|
|
}
|
|
|
|
// 格式要求信息
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
if let expectedLength = result.expectedLength {
|
|
HStack {
|
|
Image(systemName: "number")
|
|
.foregroundColor(.blue)
|
|
.font(.caption)
|
|
Text(String(format: NSLocalizedString("length_requirement", comment: "Length requirement"), expectedLength))
|
|
.font(.caption)
|
|
.foregroundColor(.blue)
|
|
}
|
|
}
|
|
|
|
if let allowedCharacters = result.allowedCharacters {
|
|
HStack {
|
|
Image(systemName: "character")
|
|
.foregroundColor(.blue)
|
|
.font(.caption)
|
|
Text(String(format: NSLocalizedString("allowed_characters", comment: "Allowed characters"), allowedCharacters))
|
|
.font(.caption)
|
|
.foregroundColor(.blue)
|
|
}
|
|
}
|
|
}
|
|
.padding(.leading, 24)
|
|
|
|
// 格式化后的内容
|
|
if result.isValid && result.formattedContent != "" {
|
|
HStack {
|
|
Image(systemName: "textformat")
|
|
.foregroundColor(.green)
|
|
.font(.caption)
|
|
Text(String(format: NSLocalizedString("formatted_content", comment: "Formatted content"), result.formattedContent))
|
|
.font(.caption)
|
|
.foregroundColor(.green)
|
|
.fontWeight(.medium)
|
|
}
|
|
.padding(.leading, 24)
|
|
}
|
|
} else {
|
|
// 默认提示信息
|
|
HStack {
|
|
Image(systemName: "info.circle")
|
|
.foregroundColor(.blue)
|
|
.font(.caption)
|
|
Text(String(format: NSLocalizedString("please_enter_valid_format", comment: "Please enter valid format"), barcodeType.displayName))
|
|
.font(.caption)
|
|
.foregroundColor(.blue)
|
|
}
|
|
}
|
|
}
|
|
.padding(12)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 8)
|
|
.fill(Color(.systemGray6))
|
|
)
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
VStack(spacing: 20) {
|
|
// 有效格式示例
|
|
BarcodeValidationInfoView(
|
|
validationResult: BarcodeValidator.ValidationResult(
|
|
isValid: true,
|
|
formattedContent: "123 4567 8901 2",
|
|
errorMessage: nil,
|
|
expectedLength: 13,
|
|
allowedCharacters: NSLocalizedString("numbers_0_9", comment: "Numbers 0-9")
|
|
),
|
|
barcodeType: .ean13
|
|
)
|
|
|
|
// 无效格式示例
|
|
BarcodeValidationInfoView(
|
|
validationResult: BarcodeValidator.ValidationResult(
|
|
isValid: false,
|
|
formattedContent: "12345",
|
|
errorMessage: NSLocalizedString("ean_13_must_be_13_digits", comment: "EAN-13 must be 13 digits"),
|
|
expectedLength: 13,
|
|
allowedCharacters: NSLocalizedString("numbers_0_9", comment: "Numbers 0-9")
|
|
),
|
|
barcodeType: .ean13
|
|
)
|
|
|
|
// 默认状态示例
|
|
BarcodeValidationInfoView(
|
|
validationResult: nil,
|
|
barcodeType: .code39
|
|
)
|
|
}
|
|
.padding()
|
|
} |