修复任务提交与弹窗交互问题
This commit is contained in:
@ -139,16 +139,6 @@ final class WildPhotographerReportSubmitViewModel {
|
||||
return "当前定位:\(reportLocation)"
|
||||
}
|
||||
|
||||
var locationSubtitleText: String {
|
||||
if isUpdatingLocation {
|
||||
return "正在更新定位,请稍候"
|
||||
}
|
||||
if locationConfirmed {
|
||||
return "已获取最新定位,如不准确请点击更新定位"
|
||||
}
|
||||
return "如位置不准确,请点击更新定位"
|
||||
}
|
||||
|
||||
init(
|
||||
homeViewModel: WildPhotographerReportHomeViewModel,
|
||||
locationProvider: any LocationProviding = LocationProvider.shared
|
||||
@ -358,12 +348,13 @@ final class WildPhotographerReportSubmitViewModel {
|
||||
let address = snapshot.address.isEmpty
|
||||
? String(format: "%.5f, %.5f", snapshot.latitude, snapshot.longitude)
|
||||
: snapshot.address
|
||||
let reportAddress = Self.simplifiedReportLocation(address)
|
||||
locationSnapshot = HomeLocationSnapshot(
|
||||
latitude: snapshot.latitude,
|
||||
longitude: snapshot.longitude,
|
||||
address: address
|
||||
address: reportAddress
|
||||
)
|
||||
reportLocation = address
|
||||
reportLocation = reportAddress
|
||||
locationConfirmed = true
|
||||
isUpdatingLocation = false
|
||||
notifyStateChange()
|
||||
@ -393,6 +384,40 @@ final class WildPhotographerReportSubmitViewModel {
|
||||
return types.filter { seen.insert($0.value).inserted }
|
||||
}
|
||||
|
||||
private static func simplifiedReportLocation(_ address: String) -> String {
|
||||
let trimmed = address.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else { return trimmed }
|
||||
let detail = WildReportLocationParser.split(trimmed).detail
|
||||
let simplified = removeAdministrativePrefix(from: detail)
|
||||
return simplified.isEmpty ? trimmed : simplified
|
||||
}
|
||||
|
||||
private static func removeAdministrativePrefix(from address: String) -> String {
|
||||
var text = address
|
||||
removeLeadingRegion(from: &text, matches: [
|
||||
"北京市", "天津市", "上海市", "重庆市",
|
||||
"内蒙古自治区", "广西壮族自治区", "西藏自治区", "宁夏回族自治区", "新疆维吾尔自治区"
|
||||
])
|
||||
removeLeadingRegion(from: &text, suffixes: ["省"], maxLength: 8)
|
||||
removeLeadingRegion(from: &text, suffixes: ["自治州", "地区", "盟", "市"], maxLength: 12)
|
||||
removeLeadingRegion(from: &text, suffixes: ["自治县", "新区", "区", "县", "旗", "市"], maxLength: 12)
|
||||
return text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
|
||||
private static func removeLeadingRegion(from text: inout String, matches: [String]) {
|
||||
guard let match = matches.first(where: { text.hasPrefix($0) }) else { return }
|
||||
text.removeFirst(match.count)
|
||||
}
|
||||
|
||||
private static func removeLeadingRegion(from text: inout String, suffixes: [String], maxLength: Int) {
|
||||
guard let match = suffixes.compactMap({ suffix -> String? in
|
||||
guard let range = text.range(of: suffix) else { return nil }
|
||||
let prefix = String(text[..<range.upperBound])
|
||||
return prefix.count <= maxLength ? prefix : nil
|
||||
}).min(by: { $0.count < $1.count }) else { return }
|
||||
text.removeFirst(match.count)
|
||||
}
|
||||
|
||||
private var evidenceCount: Int {
|
||||
images.count + videos.count
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user