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.
95 lines
3.2 KiB
95 lines
3.2 KiB
import SwiftUI
|
|
|
|
// MARK: - 条形码字符提示组件
|
|
struct BarcodeCharacterHintView: View {
|
|
let barcodeType: BarcodeType
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
Text("字符类型:")
|
|
.font(.caption)
|
|
.foregroundColor(.secondary)
|
|
|
|
LazyVGrid(columns: [
|
|
GridItem(.adaptive(minimum: 80), spacing: 8)
|
|
], spacing: 6) {
|
|
ForEach(getCharacterTypes(), id: \.self) { charType in
|
|
HStack(spacing: 4) {
|
|
Image(systemName: charType.icon)
|
|
.font(.caption2)
|
|
.foregroundColor(charType.color)
|
|
|
|
Text(charType.name)
|
|
.font(.caption2)
|
|
.foregroundColor(charType.color)
|
|
}
|
|
.padding(.horizontal, 8)
|
|
.padding(.vertical, 4)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 6)
|
|
.fill(charType.color.opacity(0.1))
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func getCharacterTypes() -> [CharacterType] {
|
|
switch barcodeType {
|
|
case .ean13, .ean8, .upce, .itf14:
|
|
return [
|
|
CharacterType(name: "数字", icon: "number", color: .blue)
|
|
]
|
|
|
|
case .code39:
|
|
return [
|
|
CharacterType(name: "字母", icon: "character", color: .green),
|
|
CharacterType(name: "数字", icon: "number", color: .blue),
|
|
CharacterType(name: "特殊字符", icon: "textformat", color: .orange)
|
|
]
|
|
|
|
case .code128:
|
|
return [
|
|
CharacterType(name: "字母", icon: "character", color: .green),
|
|
CharacterType(name: "数字", icon: "number", color: .blue),
|
|
CharacterType(name: "符号", icon: "textformat", color: .purple),
|
|
CharacterType(name: "控制字符", icon: "command", color: .red)
|
|
]
|
|
|
|
case .pdf417:
|
|
return [
|
|
CharacterType(name: "字母", icon: "character", color: .green),
|
|
CharacterType(name: "数字", icon: "number", color: .blue),
|
|
CharacterType(name: "符号", icon: "textformat", color: .purple),
|
|
CharacterType(name: "所有ASCII", icon: "globe", color: .indigo)
|
|
]
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - 字符类型结构
|
|
struct CharacterType: Hashable {
|
|
let name: String
|
|
let icon: String
|
|
let color: Color
|
|
|
|
// 实现 Hashable 协议
|
|
func hash(into hasher: inout Hasher) {
|
|
hasher.combine(name)
|
|
hasher.combine(icon)
|
|
}
|
|
|
|
static func == (lhs: CharacterType, rhs: CharacterType) -> Bool {
|
|
return lhs.name == rhs.name && lhs.icon == rhs.icon
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
VStack(spacing: 20) {
|
|
BarcodeCharacterHintView(barcodeType: .ean13)
|
|
BarcodeCharacterHintView(barcodeType: .code39)
|
|
BarcodeCharacterHintView(barcodeType: .code128)
|
|
BarcodeCharacterHintView(barcodeType: .pdf417)
|
|
}
|
|
.padding()
|
|
} |