feat: 新增 textValue 支持结构化字段内容展示
This commit is contained in:
parent
55d0f86392
commit
88f89cc918
|
|
@ -96,6 +96,26 @@ enum JSONValue: Decodable {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Display text for Feishu fields whose values are represented as
|
||||||
|
/// structured content, such as text fields (`[{"type": "text", "text": "..."}]`).
|
||||||
|
var textValue: String? {
|
||||||
|
switch self {
|
||||||
|
case let .string(value):
|
||||||
|
return value
|
||||||
|
case let .number(value):
|
||||||
|
return String(value)
|
||||||
|
case let .bool(value):
|
||||||
|
return String(value)
|
||||||
|
case let .array(items):
|
||||||
|
let text = items.compactMap(\.textValue).joined()
|
||||||
|
return text.isEmpty ? nil : text
|
||||||
|
case let .object(fields):
|
||||||
|
return fields["text"]?.textValue ?? fields["name"]?.textValue
|
||||||
|
case .null:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var firstUserName: String? {
|
var firstUserName: String? {
|
||||||
guard case let .array(items) = self else { return nil }
|
guard case let .array(items) = self else { return nil }
|
||||||
for item in items {
|
for item in items {
|
||||||
|
|
@ -142,21 +162,16 @@ enum BugMapper {
|
||||||
case let .number(number): return number
|
case let .number(number): return number
|
||||||
case let .bool(bool): return bool
|
case let .bool(bool): return bool
|
||||||
case let .array(array):
|
case let .array(array):
|
||||||
return array.compactMap { item -> String? in
|
return array.compactMap(\.textValue)
|
||||||
if case let .object(fields) = item {
|
|
||||||
return fields["name"]?.stringValue
|
|
||||||
}
|
|
||||||
return item.stringValue
|
|
||||||
}
|
|
||||||
case let .object(object):
|
case let .object(object):
|
||||||
return object["name"]?.stringValue ?? object["text"]?.stringValue
|
return object["name"]?.textValue ?? object["text"]?.textValue
|
||||||
case .null:
|
case .null:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func stringValue(in fields: [String: JSONValue], key: String) -> String? {
|
private static func stringValue(in fields: [String: JSONValue], key: String) -> String? {
|
||||||
fields[key]?.stringValue
|
fields[key]?.textValue
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func userName(in fields: [String: JSONValue], key: String) -> String? {
|
private static func userName(in fields: [String: JSONValue], key: String) -> String? {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue