Commit 4c5fc6d0 authored by Steven杜宇's avatar Steven杜宇

Merge branch 'qrcode' into salon

parents 50404ff8 24773813
......@@ -34,6 +34,14 @@ struct YHScanType: OptionSet {
return "多功能扫码"
}
}
var prefixString: String {
if self == .checkIn {
return "SLQD_"
} else {
return ""
}
}
var instructionText: String? {
if self == .checkIn {
......@@ -50,28 +58,14 @@ struct YHScanType: OptionSet {
/// 从二维码内容识别类型
func recognizeType(from code: String) -> YHScanType? {
// 根据二维码内容规则识别类型
if contains(.checkIn) && code.hasPrefix("CHECKIN_") {
if contains(.checkIn) && code.hasPrefix(YHScanType.checkIn.prefixString) {
return .checkIn
}
if contains(.smartCabinet) && code.hasPrefix("CABINET_") {
return .smartCabinet
}
// if contains(.smartCabinet) && code.hasPrefix("CABINET_") {
// return .smartCabinet
// }
// 可以添加更多识别规则
// 示例: JSON 格式识别
if let data = code.data(using: .utf8),
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
let type = json["type"] as? String {
switch type {
case "checkin":
return contains(.checkIn) ? .checkIn : nil
case "cabinet":
return contains(.smartCabinet) ? .smartCabinet : nil
default:
break
}
}
// 如果只有一个类型,直接返回
if self == .checkIn {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment