feat: add wild photographer report mock flow
This commit is contained in:
@ -28,6 +28,7 @@ enum HomeMenuCatalog {
|
||||
HomeMenuItem(uri: "pm", title: "项目管理", iconName: "folder"),
|
||||
HomeMenuItem(uri: "pm_manager", title: "项目管理", iconName: "folder"),
|
||||
HomeMenuItem(uri: "location_report", title: "位置上报", iconName: "location"),
|
||||
HomeMenuItem(uri: "report_photographer", title: "举报摄影师", iconName: "exclamationmark.shield"),
|
||||
HomeMenuItem(uri: "registration_invitation", title: "注册邀请", iconName: "person.badge.plus"),
|
||||
HomeMenuItem(uri: "photographer_invite", title: "邀请摄影师", iconName: "person.badge.plus"),
|
||||
HomeMenuItem(uri: "invite_record", title: "邀请记录", iconName: "calendar.badge.clock"),
|
||||
|
||||
@ -50,6 +50,8 @@ enum HomeRouteHandler {
|
||||
viewController.navigationController?.pushViewController(CooperationOrderListViewController(), animated: true)
|
||||
case "location_report":
|
||||
viewController.navigationController?.pushViewController(LocationReportViewController(), animated: true)
|
||||
case "report_photographer":
|
||||
viewController.navigationController?.pushViewController(WildPhotographerReportHomeViewController(), animated: true)
|
||||
case "registration_invitation", "photographer_invite":
|
||||
viewController.navigationController?.pushViewController(PhotographerInviteViewController(), animated: true)
|
||||
case "invite_record":
|
||||
|
||||
@ -0,0 +1,349 @@
|
||||
//
|
||||
// WildPhotographerReportModels.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import CoreLocation
|
||||
import Foundation
|
||||
import MapKit
|
||||
import UIKit
|
||||
|
||||
/// 举报摄影师页面状态,用于演示加载、空态和异常态。
|
||||
enum WildReportPageState: String, CaseIterable, Hashable {
|
||||
case normal
|
||||
case loading
|
||||
case empty
|
||||
case error
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .normal: return "正常"
|
||||
case .loading: return "加载"
|
||||
case .empty: return "空状态"
|
||||
case .error: return "异常"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 举报附件类型,区分现场图片、视频和支付截图。
|
||||
enum WildReportAttachmentKind: Hashable {
|
||||
case image
|
||||
case video
|
||||
case payment
|
||||
}
|
||||
|
||||
/// 举报类型,用于提交页单选并写入 Mock 举报记录。
|
||||
enum WildReportType: String, CaseIterable, Hashable {
|
||||
case suspectedWild = "疑似打野"
|
||||
case noWorkBadge = "未戴工牌"
|
||||
case other = "其他"
|
||||
|
||||
var iconName: String {
|
||||
switch self {
|
||||
case .suspectedWild: return "person.crop.circle.badge.exclamationmark"
|
||||
case .noWorkBadge: return "lanyardcard"
|
||||
case .other: return "ellipsis.circle"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 举报附件实体,表示一条演示用的上传项。
|
||||
struct WildReportAttachment: Hashable {
|
||||
let id: UUID
|
||||
let kind: WildReportAttachmentKind
|
||||
let title: String
|
||||
|
||||
init(id: UUID = UUID(), kind: WildReportAttachmentKind, title: String) {
|
||||
self.id = id
|
||||
self.kind = kind
|
||||
self.title = title
|
||||
}
|
||||
}
|
||||
|
||||
/// 举报处理状态。
|
||||
enum WildReportStatus: String, Hashable, CaseIterable {
|
||||
case pending = "待处理"
|
||||
case processing = "处理中"
|
||||
case processed = "已处理"
|
||||
|
||||
var displayColor: UIColor {
|
||||
switch self {
|
||||
case .pending: return AppColor.warning
|
||||
case .processing: return AppColor.primary
|
||||
case .processed: return AppColor.success
|
||||
}
|
||||
}
|
||||
|
||||
var backgroundColor: UIColor {
|
||||
switch self {
|
||||
case .pending: return AppColor.warningBackground
|
||||
case .processing: return AppColor.infoBackground
|
||||
case .processed: return AppColor.successBackground
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 我的举报列表筛选条件。
|
||||
enum WildReportListFilter: String, CaseIterable, Hashable {
|
||||
case all = "全部"
|
||||
case pending = "待处理"
|
||||
case processing = "处理中"
|
||||
case processed = "已处理"
|
||||
}
|
||||
|
||||
/// 补充证据记录实体。
|
||||
struct WildReportSupplementaryEvidence: Hashable {
|
||||
let id: String
|
||||
let submitTime: String
|
||||
let text: String
|
||||
let imageCount: Int
|
||||
let videoCount: Int
|
||||
|
||||
var summaryText: String {
|
||||
var parts: [String] = []
|
||||
if !text.isEmpty { parts.append(text) }
|
||||
if imageCount > 0 { parts.append("\(imageCount)张图片") }
|
||||
if videoCount > 0 { parts.append("\(videoCount)段视频") }
|
||||
return parts.isEmpty ? "补充证据" : parts.joined(separator: " · ")
|
||||
}
|
||||
}
|
||||
|
||||
/// 举报位置解析工具。
|
||||
enum WildReportLocationParser {
|
||||
/// 将「景区 · 详细地址」拆成两段展示文案。
|
||||
static func split(_ location: String) -> (scenic: String, detail: String) {
|
||||
let parts = location
|
||||
.components(separatedBy: " · ")
|
||||
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
|
||||
.filter { !$0.isEmpty }
|
||||
if parts.count >= 2 {
|
||||
return (parts[0], parts[1])
|
||||
}
|
||||
return (location, location)
|
||||
}
|
||||
}
|
||||
|
||||
/// 附近风险点实体。
|
||||
struct WildReportRiskPoint: Hashable {
|
||||
let id: Int
|
||||
let title: String
|
||||
let location: String
|
||||
let distance: String
|
||||
let riskLevel: String
|
||||
let evidenceCount: Int
|
||||
let latestTime: String
|
||||
let description: String
|
||||
}
|
||||
|
||||
/// 举报记录实体。
|
||||
struct WildReportRecord: Hashable {
|
||||
let id: String
|
||||
let title: String
|
||||
let reportType: WildReportType
|
||||
let status: WildReportStatus
|
||||
let location: String
|
||||
let submitTime: String
|
||||
let description: String
|
||||
let wechatID: String
|
||||
let phoneNumber: String
|
||||
let imageCount: Int
|
||||
let videoCount: Int
|
||||
let handlerInfo: WildReportHandlerInfo?
|
||||
|
||||
var contactDisplayText: String {
|
||||
switch (wechatID.isEmpty, phoneNumber.isEmpty) {
|
||||
case (true, true): return "未填写"
|
||||
case (false, false): return "\(wechatID) / \(phoneNumber)"
|
||||
case (false, true): return wechatID
|
||||
case (true, false): return phoneNumber
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 处理完成后的媒体项。
|
||||
struct WildReportCompletionMediaItem: Hashable {
|
||||
enum Kind: Hashable {
|
||||
case image
|
||||
case video
|
||||
}
|
||||
|
||||
let id: String
|
||||
let kind: Kind
|
||||
let coverURL: String
|
||||
let duration: String?
|
||||
}
|
||||
|
||||
/// 举报处理人信息实体。
|
||||
struct WildReportHandlerInfo: Hashable {
|
||||
let handlerName: String
|
||||
let handlerPhone: String
|
||||
let processingAt: String
|
||||
let processedAt: String
|
||||
let processOpinion: String
|
||||
let completionMedia: [WildReportCompletionMediaItem]
|
||||
|
||||
var maskedHandlerPhone: String {
|
||||
guard handlerPhone.count == 11, handlerPhone.allSatisfy(\.isNumber) else { return handlerPhone }
|
||||
return "\(handlerPhone.prefix(3))****\(handlerPhone.suffix(4))"
|
||||
}
|
||||
|
||||
var completionMediaSummary: String {
|
||||
let imageCount = completionMedia.filter { $0.kind == .image }.count
|
||||
let videoCount = completionMedia.filter { $0.kind == .video }.count
|
||||
switch (imageCount, videoCount) {
|
||||
case (0, 0): return "0项"
|
||||
case (_, 0): return "\(imageCount)张"
|
||||
case (0, _): return "\(videoCount)段"
|
||||
default: return "\(imageCount)张 \(videoCount)段"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 举报进度节点状态。
|
||||
enum WildReportProgressStepState: Hashable {
|
||||
case completed
|
||||
case current
|
||||
case pending
|
||||
}
|
||||
|
||||
/// 举报进度时间轴节点。
|
||||
struct WildReportProgressStep: Hashable {
|
||||
let id: String
|
||||
let title: String
|
||||
let timeText: String
|
||||
let state: WildReportProgressStepState
|
||||
}
|
||||
|
||||
/// 举报人材料预览项。
|
||||
enum WildReportReporterMediaItem: Hashable {
|
||||
case image(index: Int)
|
||||
case video(index: Int)
|
||||
|
||||
var id: String {
|
||||
switch self {
|
||||
case .image(let index): return "reporter-image-\(index)"
|
||||
case .video(let index): return "reporter-video-\(index)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 举报提交结果,用于成功页展示。
|
||||
struct WildReportSubmitResult: Hashable {
|
||||
let record: WildReportRecord
|
||||
let imageCount: Int
|
||||
let videoCount: Int
|
||||
}
|
||||
|
||||
/// 风险地图标记类型。
|
||||
enum WildReportMapMarkerKind: Hashable {
|
||||
case selfLocation
|
||||
case wildPhotographer
|
||||
case processingClue
|
||||
case peerPhotographer
|
||||
|
||||
var color: UIColor {
|
||||
switch self {
|
||||
case .selfLocation: return AppColor.primary
|
||||
case .wildPhotographer: return AppColor.danger
|
||||
case .processingClue: return AppColor.warning
|
||||
case .peerPhotographer: return AppColor.success
|
||||
}
|
||||
}
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .selfLocation: return "我的位置"
|
||||
case .wildPhotographer: return "疑似打野"
|
||||
case .processingClue: return "处理中线索"
|
||||
case .peerPhotographer: return "内部摄影师"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 雷达地图标记颜色类型。
|
||||
enum WildReportRadarMarkerType: String, Hashable {
|
||||
case blue
|
||||
case green
|
||||
case red
|
||||
}
|
||||
|
||||
/// 雷达线索举报内容条目。
|
||||
struct WildReportRadarReportContent: Hashable {
|
||||
let time: String
|
||||
let content: String
|
||||
}
|
||||
|
||||
/// 雷达线索处理记录。
|
||||
struct WildReportRadarProcessRecord: Hashable {
|
||||
let handlerName: String
|
||||
let phone: String
|
||||
let maskedPhone: String
|
||||
let statusText: String
|
||||
let processResult: String
|
||||
let processedAt: String?
|
||||
let processingAt: String?
|
||||
}
|
||||
|
||||
/// 雷达线索处理时间轴节点。
|
||||
struct WildReportRadarProcessingTimelineItem: Hashable {
|
||||
let title: String
|
||||
let time: String
|
||||
let status: String
|
||||
}
|
||||
|
||||
/// 雷达地图活动线索详情。
|
||||
struct WildReportRadarActiveClue: Hashable {
|
||||
let id: String
|
||||
let type: WildReportRadarMarkerType
|
||||
let displayTitle: String
|
||||
let statusText: String
|
||||
let actionText: String
|
||||
let nearestAbnormalText: String?
|
||||
let distance: String?
|
||||
let direction: String?
|
||||
let updatedAt: String?
|
||||
let name: String?
|
||||
let storeName: String?
|
||||
let avatar: String?
|
||||
let summary: String?
|
||||
let detail: String?
|
||||
let distanceText: String?
|
||||
let reporterName: String?
|
||||
let reporterPhone: String?
|
||||
let maskedReporterPhone: String?
|
||||
let reportContents: [WildReportRadarReportContent]
|
||||
let images: [String]
|
||||
let processingStarted: Bool
|
||||
let completed: Bool
|
||||
let record: WildReportRadarProcessRecord?
|
||||
let processingTimeline: [WildReportRadarProcessingTimelineItem]
|
||||
let completionPhoto: String?
|
||||
}
|
||||
|
||||
/// 风险地图标记详情。
|
||||
enum WildReportMapMarkerDetail: Hashable {
|
||||
case activeClue(WildReportRadarActiveClue)
|
||||
}
|
||||
|
||||
/// 风险地图标记实体。
|
||||
struct WildReportMapMarker: Hashable {
|
||||
let id: String
|
||||
let title: String
|
||||
let coordinate: CLLocationCoordinate2D
|
||||
let kind: WildReportMapMarkerKind
|
||||
let detail: WildReportMapMarkerDetail
|
||||
|
||||
static func == (lhs: WildReportMapMarker, rhs: WildReportMapMarker) -> Bool {
|
||||
lhs.id == rhs.id
|
||||
}
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(id)
|
||||
}
|
||||
}
|
||||
|
||||
extension CLLocationCoordinate2D: @retroactive Equatable {
|
||||
public static func == (lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool {
|
||||
lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,604 @@
|
||||
//
|
||||
// WildPhotographerReportMockStore.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import CoreLocation
|
||||
import Foundation
|
||||
import MapKit
|
||||
|
||||
/// 举报摄影师 Mock 数据仓库,统一管理演示种子数据和地图标记构建。
|
||||
enum WildPhotographerReportMockStore {
|
||||
static let fallbackLocation = "黄山风景区 · 光明顶景区"
|
||||
|
||||
static let initialImages = [
|
||||
WildReportAttachment(kind: .image, title: "现场图片1")
|
||||
]
|
||||
|
||||
static let initialVideos = [
|
||||
WildReportAttachment(kind: .video, title: "现场视频1")
|
||||
]
|
||||
|
||||
static let seedRiskPoints = [
|
||||
WildReportRiskPoint(
|
||||
id: 1,
|
||||
title: "光明顶观景台附近",
|
||||
location: "黄山风景区 · 光明顶景区",
|
||||
distance: "120m",
|
||||
riskLevel: "高",
|
||||
evidenceCount: 6,
|
||||
latestTime: "10分钟前",
|
||||
description: "多名游客反馈有疑似未备案摄影师主动揽客,集中在观景台东侧步道附近。"
|
||||
),
|
||||
WildReportRiskPoint(
|
||||
id: 2,
|
||||
title: "迎客松游客出口",
|
||||
location: "黄山风景区 · 玉屏景区",
|
||||
distance: "860m",
|
||||
riskLevel: "中",
|
||||
evidenceCount: 3,
|
||||
latestTime: "32分钟前",
|
||||
description: "疑似人员以低价加急出片为话术引导游客线下付款,建议现场核查。"
|
||||
),
|
||||
WildReportRiskPoint(
|
||||
id: 3,
|
||||
title: "云谷索道排队区",
|
||||
location: "黄山风景区 · 云谷景区",
|
||||
distance: "1.4km",
|
||||
riskLevel: "低",
|
||||
evidenceCount: 2,
|
||||
latestTime: "1小时前",
|
||||
description: "排队区附近存在疑似私下拉客行为,已收到图片和位置线索。"
|
||||
)
|
||||
]
|
||||
|
||||
static let seedReports = [
|
||||
WildReportRecord(
|
||||
id: "JB20260618001",
|
||||
title: "摄影师举报",
|
||||
reportType: .suspectedWild,
|
||||
status: .processing,
|
||||
location: "那拉提景区 · 空中草原入口附近",
|
||||
submitTime: "2026-06-18 10:24",
|
||||
description: "疑似人员在观景台附近主动向游客售卖拍摄服务,并引导线下转账。",
|
||||
wechatID: "wx_photographer_01",
|
||||
phoneNumber: "13812345678",
|
||||
imageCount: 3,
|
||||
videoCount: 1,
|
||||
handlerInfo: nil
|
||||
),
|
||||
WildReportRecord(
|
||||
id: "JB20260617008",
|
||||
title: "摄影师举报",
|
||||
reportType: .suspectedWild,
|
||||
status: .processed,
|
||||
location: "那拉提景区 · 河谷草原游客中心",
|
||||
submitTime: "2026-06-17 16:42",
|
||||
description: "现场发现疑似未备案摄影师持续向游客推销旅拍套餐。",
|
||||
wechatID: "nalati_photo",
|
||||
phoneNumber: "",
|
||||
imageCount: 2,
|
||||
videoCount: 1,
|
||||
handlerInfo: processedHandlerInfo(
|
||||
handlerName: "赵强",
|
||||
handlerPhone: "15938267120",
|
||||
processingAt: "2026-06-17 17:10",
|
||||
processedAt: "2026-06-17 18:26",
|
||||
processOpinion: "已到场核查并完成劝离,处理结果已同步景区公安。",
|
||||
imageSeedPrefix: "handler-jb008"
|
||||
)
|
||||
),
|
||||
WildReportRecord(
|
||||
id: "JB20260616003",
|
||||
title: "摄影师举报",
|
||||
reportType: .noWorkBadge,
|
||||
status: .pending,
|
||||
location: "那拉提景区 · 盘龙古道停车区",
|
||||
submitTime: "2026-06-16 09:15",
|
||||
description: "停车区附近有摄影师未佩戴工牌开展拍摄服务,已收到图片和位置线索。",
|
||||
wechatID: "",
|
||||
phoneNumber: "13987654321",
|
||||
imageCount: 1,
|
||||
videoCount: 0,
|
||||
handlerInfo: nil
|
||||
),
|
||||
WildReportRecord(
|
||||
id: "JB20260615002",
|
||||
title: "摄影师举报",
|
||||
reportType: .other,
|
||||
status: .processed,
|
||||
location: "那拉提景区 · 雪莲谷步道",
|
||||
submitTime: "2026-06-15 14:30",
|
||||
description: "举报线索经核查未发现异常摄影师服务行为,已归档。",
|
||||
wechatID: "grassland_cam",
|
||||
phoneNumber: "13600001111",
|
||||
imageCount: 1,
|
||||
videoCount: 0,
|
||||
handlerInfo: processedHandlerInfo(
|
||||
handlerName: "李娜",
|
||||
handlerPhone: "18674598210",
|
||||
processingAt: "2026-06-15 15:05",
|
||||
processedAt: "2026-06-15 16:55",
|
||||
processOpinion: "现场核查未发现未备案摄影师,已归档处理。",
|
||||
imageSeedPrefix: "handler-jb002",
|
||||
includeVideo: false
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
static let seedSupplementaryEvidences: [String: [WildReportSupplementaryEvidence]] = [
|
||||
"JB20260618001": [
|
||||
WildReportSupplementaryEvidence(
|
||||
id: "SE001",
|
||||
submitTime: "2026-06-18 14:20",
|
||||
text: "补充现场视频,对方仍在揽客。",
|
||||
imageCount: 1,
|
||||
videoCount: 1
|
||||
)
|
||||
]
|
||||
]
|
||||
|
||||
static let reportDateFormatter: DateFormatter = {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "yyyyMMdd"
|
||||
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||
return formatter
|
||||
}()
|
||||
|
||||
static let submitTimeFormatter: DateFormatter = {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "yyyy-MM-dd HH:mm"
|
||||
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||
return formatter
|
||||
}()
|
||||
|
||||
static let nalatiCenter = CLLocationCoordinate2D(latitude: 43.382, longitude: 84.032)
|
||||
|
||||
private static let clueID1 = "2026年6月22日-0001"
|
||||
private static let clueID2 = "2026年6月22日-0002"
|
||||
private static let clueID3 = "2026年6月22日-0003"
|
||||
private static let initialProcessingClueIDs: Set<String> = [clueID2]
|
||||
|
||||
/// 构建已处理举报的处理人信息 Mock 数据。
|
||||
static func processedHandlerInfo(
|
||||
handlerName: String,
|
||||
handlerPhone: String,
|
||||
processingAt: String,
|
||||
processedAt: String,
|
||||
processOpinion: String,
|
||||
imageSeedPrefix: String,
|
||||
includeVideo: Bool = true
|
||||
) -> WildReportHandlerInfo {
|
||||
var media: [WildReportCompletionMediaItem] = [
|
||||
WildReportCompletionMediaItem(
|
||||
id: "\(imageSeedPrefix)-img-1",
|
||||
kind: .image,
|
||||
coverURL: "https://picsum.photos/seed/\(imageSeedPrefix)-1/640/480",
|
||||
duration: nil
|
||||
),
|
||||
WildReportCompletionMediaItem(
|
||||
id: "\(imageSeedPrefix)-img-2",
|
||||
kind: .image,
|
||||
coverURL: "https://picsum.photos/seed/\(imageSeedPrefix)-2/640/480",
|
||||
duration: nil
|
||||
)
|
||||
]
|
||||
if includeVideo {
|
||||
media.append(
|
||||
WildReportCompletionMediaItem(
|
||||
id: "\(imageSeedPrefix)-vid-1",
|
||||
kind: .video,
|
||||
coverURL: "https://picsum.photos/seed/\(imageSeedPrefix)-video/640/480",
|
||||
duration: "00:18"
|
||||
)
|
||||
)
|
||||
}
|
||||
return WildReportHandlerInfo(
|
||||
handlerName: handlerName,
|
||||
handlerPhone: handlerPhone,
|
||||
processingAt: processingAt,
|
||||
processedAt: processedAt,
|
||||
processOpinion: processOpinion,
|
||||
completionMedia: media
|
||||
)
|
||||
}
|
||||
|
||||
/// 从已有举报编号中提取最大序号,供新编号递增。
|
||||
static func maxSequence(from reports: [WildReportRecord]) -> Int {
|
||||
reports.compactMap { record in
|
||||
guard record.id.count >= 3 else { return nil }
|
||||
return Int(record.id.suffix(3))
|
||||
}.max() ?? 0
|
||||
}
|
||||
|
||||
/// 解析联系方式,区分微信号和手机号。
|
||||
static func parseContact(_ contact: String?) -> (wechat: String, phone: String) {
|
||||
guard let contact else { return ("", "") }
|
||||
let trimmed = contact.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else { return ("", "") }
|
||||
|
||||
let digits = trimmed.filter(\.isNumber)
|
||||
if digits.count >= 7, trimmed.filter({ $0.isNumber || "+-() ".contains($0) }).count == trimmed.count {
|
||||
return ("", trimmed)
|
||||
}
|
||||
return (trimmed, "")
|
||||
}
|
||||
|
||||
/// 根据线索状态返回地图标记类型。
|
||||
static func markerKind(for clue: WildReportRadarActiveClue) -> WildReportMapMarkerKind {
|
||||
switch clue.type {
|
||||
case .blue:
|
||||
return .selfLocation
|
||||
case .green:
|
||||
return .peerPhotographer
|
||||
case .red:
|
||||
if clue.processingStarted && !clue.completed {
|
||||
return .processingClue
|
||||
}
|
||||
return .wildPhotographer
|
||||
}
|
||||
}
|
||||
|
||||
/// 构建风险地图全部标记点。
|
||||
static func buildMarkers(record: WildReportRecord, riskPoints: [WildReportRiskPoint]) -> [WildReportMapMarker] {
|
||||
_ = record
|
||||
_ = riskPoints
|
||||
|
||||
let blueCoordinate = CLLocationCoordinate2D(latitude: 43.3779, longitude: 84.0217)
|
||||
let redSeeds: [(id: String, name: String, coordinate: CLLocationCoordinate2D, clue: WildReportRadarActiveClue)] = [
|
||||
redSeed(
|
||||
id: clueID1,
|
||||
name: "空中草原观景道",
|
||||
coordinate: CLLocationCoordinate2D(latitude: 43.4068, longitude: 84.0582),
|
||||
updatedAt: "5分钟前",
|
||||
distanceText: "320米",
|
||||
reporterName: "张三",
|
||||
reporterPhone: "13333333333",
|
||||
contents: [
|
||||
"多人结伴揽客,疑似无资质摄影团队,携带专业器材在观景道附近活动。",
|
||||
"补充证据:对方仍在向游客推销拍照套餐,并拒绝出示相关资质。"
|
||||
],
|
||||
imageSeeds: ["nalati-radar-1", "nalati-radar-2", "nalati-radar-3"]
|
||||
),
|
||||
redSeed(
|
||||
id: clueID2,
|
||||
name: "塔吾萨尼步道",
|
||||
coordinate: CLLocationCoordinate2D(latitude: 43.3652, longitude: 84.0385),
|
||||
updatedAt: "18分钟前",
|
||||
distanceText: "780米",
|
||||
reporterName: "李四",
|
||||
reporterPhone: "18674598210",
|
||||
contents: [
|
||||
"疑似二次转移,仍在塔吾萨尼步道附近揽客拍照。",
|
||||
"补充:对方穿黑色外套,携带三脚架,在步道入口反复搭讪游客。"
|
||||
],
|
||||
imageSeeds: ["nalati-radar-4", "nalati-radar-5"]
|
||||
),
|
||||
redSeed(
|
||||
id: clueID3,
|
||||
name: "河谷草原西南侧",
|
||||
coordinate: CLLocationCoordinate2D(latitude: 43.3546, longitude: 84.0136),
|
||||
updatedAt: "昨天17:45",
|
||||
distanceText: "910米",
|
||||
reporterName: "王五",
|
||||
reporterPhone: "15938267120",
|
||||
contents: ["游客反馈有人在步道旁揽客拍照,行为较为可疑。"],
|
||||
imageSeeds: ["nalati-radar-8"]
|
||||
)
|
||||
]
|
||||
|
||||
let nearestText = nearestAbnormalText(
|
||||
blueCoordinate: blueCoordinate,
|
||||
redCoordinates: redSeeds.map(\.coordinate)
|
||||
)
|
||||
|
||||
var markers: [WildReportMapMarker] = [
|
||||
WildReportMapMarker(
|
||||
id: "ME",
|
||||
title: "河谷草原入口",
|
||||
coordinate: blueCoordinate,
|
||||
kind: .selfLocation,
|
||||
detail: .activeClue(
|
||||
WildReportRadarActiveClue(
|
||||
id: "ME",
|
||||
type: .blue,
|
||||
displayTitle: "当前位置:河谷草原入口",
|
||||
statusText: "当前位置",
|
||||
actionText: "刷新定位",
|
||||
nearestAbnormalText: nearestText,
|
||||
distance: "0 米",
|
||||
direction: "蓝色基准点",
|
||||
updatedAt: "实时定位",
|
||||
name: "河谷草原入口",
|
||||
storeName: nil,
|
||||
avatar: nil,
|
||||
summary: "蓝色标记为当前位置,可对比周边摄影师风险点位距离。",
|
||||
detail: "当前定位在河谷草原入口附近,建议优先关注 800 米内的异常点位。",
|
||||
distanceText: nil,
|
||||
reporterName: nil,
|
||||
reporterPhone: nil,
|
||||
maskedReporterPhone: nil,
|
||||
reportContents: [],
|
||||
images: [],
|
||||
processingStarted: false,
|
||||
completed: false,
|
||||
record: nil,
|
||||
processingTimeline: [],
|
||||
completionPhoto: nil
|
||||
)
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
for seed in redSeeds {
|
||||
let processingStarted = initialProcessingClueIDs.contains(seed.id)
|
||||
let clue = enrichClue(seed.clue, processingStarted: processingStarted)
|
||||
markers.append(
|
||||
WildReportMapMarker(
|
||||
id: seed.id,
|
||||
title: seed.name,
|
||||
coordinate: seed.coordinate,
|
||||
kind: markerKind(for: clue),
|
||||
detail: .activeClue(clue)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
markers.append(contentsOf: greenMarkers())
|
||||
return markers
|
||||
}
|
||||
|
||||
/// 根据全部标记计算地图可视区域。
|
||||
static func region(for markers: [WildReportMapMarker]) -> MKCoordinateRegion {
|
||||
guard let first = markers.first else {
|
||||
return MKCoordinateRegion(
|
||||
center: nalatiCenter,
|
||||
span: MKCoordinateSpan(latitudeDelta: 0.025, longitudeDelta: 0.025)
|
||||
)
|
||||
}
|
||||
|
||||
var minLat = first.coordinate.latitude
|
||||
var maxLat = first.coordinate.latitude
|
||||
var minLon = first.coordinate.longitude
|
||||
var maxLon = first.coordinate.longitude
|
||||
|
||||
for marker in markers {
|
||||
minLat = min(minLat, marker.coordinate.latitude)
|
||||
maxLat = max(maxLat, marker.coordinate.latitude)
|
||||
minLon = min(minLon, marker.coordinate.longitude)
|
||||
maxLon = max(maxLon, marker.coordinate.longitude)
|
||||
}
|
||||
|
||||
let center = CLLocationCoordinate2D(
|
||||
latitude: (minLat + maxLat) / 2,
|
||||
longitude: (minLon + maxLon) / 2
|
||||
)
|
||||
let span = MKCoordinateSpan(
|
||||
latitudeDelta: max(0.022, (maxLat - minLat) * 1.8),
|
||||
longitudeDelta: max(0.022, (maxLon - minLon) * 1.8)
|
||||
)
|
||||
return MKCoordinateRegion(center: center, span: span)
|
||||
}
|
||||
|
||||
private static func redSeed(
|
||||
id: String,
|
||||
name: String,
|
||||
coordinate: CLLocationCoordinate2D,
|
||||
updatedAt: String,
|
||||
distanceText: String,
|
||||
reporterName: String,
|
||||
reporterPhone: String,
|
||||
contents: [String],
|
||||
imageSeeds: [String]
|
||||
) -> (id: String, name: String, coordinate: CLLocationCoordinate2D, clue: WildReportRadarActiveClue) {
|
||||
let reportContents = contents.enumerated().map { index, content in
|
||||
WildReportRadarReportContent(time: index == 0 ? "14:32:18" : "14:45:06", content: content)
|
||||
}
|
||||
return (
|
||||
id,
|
||||
name,
|
||||
coordinate,
|
||||
WildReportRadarActiveClue(
|
||||
id: id,
|
||||
type: .red,
|
||||
displayTitle: "线索 ID:\(id)",
|
||||
statusText: "疑似打野",
|
||||
actionText: "导航到此",
|
||||
nearestAbnormalText: nil,
|
||||
distance: nil,
|
||||
direction: nil,
|
||||
updatedAt: updatedAt,
|
||||
name: name,
|
||||
storeName: nil,
|
||||
avatar: nil,
|
||||
summary: nil,
|
||||
detail: nil,
|
||||
distanceText: distanceText,
|
||||
reporterName: reporterName,
|
||||
reporterPhone: reporterPhone,
|
||||
maskedReporterPhone: maskPhone(reporterPhone),
|
||||
reportContents: reportContents,
|
||||
images: imageSeeds.map { "https://picsum.photos/seed/\($0)/640/480" },
|
||||
processingStarted: false,
|
||||
completed: false,
|
||||
record: nil,
|
||||
processingTimeline: [],
|
||||
completionPhoto: nil
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private static func greenMarkers() -> [WildReportMapMarker] {
|
||||
let seeds: [(id: String, coordinate: CLLocationCoordinate2D, name: String, store: String, detail: String)] = [
|
||||
("PG20240618001", CLLocationCoordinate2D(latitude: 43.4042, longitude: 84.0186), "阿依达娜", "空中草原旅拍店", "当前在空中草原区域服务游客拍摄。"),
|
||||
("PG20240618002", CLLocationCoordinate2D(latitude: 43.3985, longitude: 84.0408), "波拉提", "天界台摄影服务点", "当前在天界台附近接待预约游客。"),
|
||||
("PG20240618003", CLLocationCoordinate2D(latitude: 43.3828, longitude: 84.0794), "米热丽", "塔吾萨尼影像馆", "当前在塔吾萨尼步道附近提供旅拍服务。")
|
||||
]
|
||||
|
||||
return seeds.map { seed in
|
||||
let clue = WildReportRadarActiveClue(
|
||||
id: seed.id,
|
||||
type: .green,
|
||||
displayTitle: "认证摄影师",
|
||||
statusText: "认证摄影师",
|
||||
actionText: "导航到此",
|
||||
nearestAbnormalText: nil,
|
||||
distance: "430 米",
|
||||
direction: "景区内",
|
||||
updatedAt: "在线",
|
||||
name: seed.name,
|
||||
storeName: seed.store,
|
||||
avatar: "person.crop.circle.fill",
|
||||
summary: "绿色标记为已认证摄影师,可与红色摄影师风险点位区分。",
|
||||
detail: seed.detail,
|
||||
distanceText: nil,
|
||||
reporterName: nil,
|
||||
reporterPhone: nil,
|
||||
maskedReporterPhone: nil,
|
||||
reportContents: [],
|
||||
images: [],
|
||||
processingStarted: false,
|
||||
completed: false,
|
||||
record: nil,
|
||||
processingTimeline: [],
|
||||
completionPhoto: nil
|
||||
)
|
||||
return WildReportMapMarker(
|
||||
id: seed.id,
|
||||
title: seed.name,
|
||||
coordinate: seed.coordinate,
|
||||
kind: .peerPhotographer,
|
||||
detail: .activeClue(clue)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private static func processRecord(for clueID: String) -> WildReportRadarProcessRecord? {
|
||||
switch clueID {
|
||||
case clueID1:
|
||||
return WildReportRadarProcessRecord(
|
||||
handlerName: "王磊",
|
||||
phone: "13812346721",
|
||||
maskedPhone: maskPhone("13812346721"),
|
||||
statusText: "待处理",
|
||||
processResult: "待现场核查,请前往空中草原观景道确认摄影师线索。",
|
||||
processedAt: nil,
|
||||
processingAt: nil
|
||||
)
|
||||
case clueID2:
|
||||
return WildReportRadarProcessRecord(
|
||||
handlerName: "李娜",
|
||||
phone: "18674598210",
|
||||
maskedPhone: maskPhone("18674598210"),
|
||||
statusText: "处理中",
|
||||
processResult: "待现场核查,请前往塔吾萨尼步道确认摄影师线索。",
|
||||
processedAt: nil,
|
||||
processingAt: "2024-05-18 10:35"
|
||||
)
|
||||
case clueID3:
|
||||
return WildReportRadarProcessRecord(
|
||||
handlerName: "赵强",
|
||||
phone: "15938267120",
|
||||
maskedPhone: maskPhone("15938267120"),
|
||||
statusText: "已处理",
|
||||
processResult: "已到场核查并完成劝离,处理结果已同步景区公安。",
|
||||
processedAt: "2024-05-17 18:26",
|
||||
processingAt: "2024-05-17 17:45"
|
||||
)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
private static func buildProcessingTimeline(
|
||||
record: WildReportRadarProcessRecord,
|
||||
completed: Bool
|
||||
) -> [WildReportRadarProcessingTimelineItem] {
|
||||
let startedAt = record.processingAt ?? "2024-05-18 10:35"
|
||||
return [
|
||||
WildReportRadarProcessingTimelineItem(title: "处理时间", time: startedAt, status: "done"),
|
||||
WildReportRadarProcessingTimelineItem(
|
||||
title: "处理完成时间",
|
||||
time: completed ? (record.processedAt ?? "刚刚") : "待完成",
|
||||
status: completed ? "done" : "current"
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
private static func enrichClue(
|
||||
_ base: WildReportRadarActiveClue,
|
||||
processingStarted: Bool,
|
||||
completed: Bool = false,
|
||||
completionPhoto: String? = nil
|
||||
) -> WildReportRadarActiveClue {
|
||||
let record = processRecord(for: base.id)
|
||||
let isProcessing = processingStarted && !completed
|
||||
let timeline = (isProcessing || completed) && record != nil
|
||||
? buildProcessingTimeline(record: record!, completed: completed)
|
||||
: []
|
||||
|
||||
return WildReportRadarActiveClue(
|
||||
id: base.id,
|
||||
type: base.type,
|
||||
displayTitle: base.displayTitle,
|
||||
statusText: completed ? "已处理" : (isProcessing ? "正在处理中" : base.statusText),
|
||||
actionText: base.actionText,
|
||||
nearestAbnormalText: base.nearestAbnormalText,
|
||||
distance: base.distance,
|
||||
direction: base.direction,
|
||||
updatedAt: completed ? (record?.processedAt ?? "刚刚") : base.updatedAt,
|
||||
name: base.name,
|
||||
storeName: base.storeName,
|
||||
avatar: base.avatar,
|
||||
summary: base.summary,
|
||||
detail: base.detail,
|
||||
distanceText: base.distanceText,
|
||||
reporterName: base.reporterName,
|
||||
reporterPhone: base.reporterPhone,
|
||||
maskedReporterPhone: base.maskedReporterPhone,
|
||||
reportContents: base.reportContents,
|
||||
images: base.images,
|
||||
processingStarted: processingStarted || completed,
|
||||
completed: completed,
|
||||
record: (isProcessing || completed) ? record : nil,
|
||||
processingTimeline: timeline,
|
||||
completionPhoto: completionPhoto
|
||||
)
|
||||
}
|
||||
|
||||
private static func maskPhone(_ phone: String) -> String {
|
||||
guard phone.count == 11, phone.allSatisfy(\.isNumber) else { return phone }
|
||||
return "\(phone.prefix(3))****\(phone.suffix(4))"
|
||||
}
|
||||
|
||||
private static func nearestAbnormalText(
|
||||
blueCoordinate: CLLocationCoordinate2D,
|
||||
redCoordinates: [CLLocationCoordinate2D]
|
||||
) -> String {
|
||||
guard !redCoordinates.isEmpty else { return "距离最近的异常点位0.00KM" }
|
||||
let minKm = redCoordinates.map {
|
||||
calcDistanceKm(
|
||||
lat1: blueCoordinate.latitude,
|
||||
lon1: blueCoordinate.longitude,
|
||||
lat2: $0.latitude,
|
||||
lon2: $0.longitude
|
||||
)
|
||||
}.min() ?? 0
|
||||
return String(format: "距离最近的异常点位%.2fKM", minKm)
|
||||
}
|
||||
|
||||
private static func calcDistanceKm(
|
||||
lat1: Double,
|
||||
lon1: Double,
|
||||
lat2: Double,
|
||||
lon2: Double
|
||||
) -> Double {
|
||||
let earthRadiusKm = 6371.0
|
||||
let toRad = { (deg: Double) in deg * .pi / 180 }
|
||||
let dLat = toRad(lat2 - lat1)
|
||||
let dLon = toRad(lon2 - lon1)
|
||||
let a = sin(dLat / 2) * sin(dLat / 2)
|
||||
+ cos(toRad(lat1)) * cos(toRad(lat2)) * sin(dLon / 2) * sin(dLon / 2)
|
||||
return earthRadiusKm * 2 * atan2(sqrt(a), sqrt(1 - a))
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,685 @@
|
||||
//
|
||||
// WildPhotographerReportViewModels.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MapKit
|
||||
import UIKit
|
||||
|
||||
/// 举报摄影师首页 ViewModel,持有 Mock 举报数据并供子页面共享。
|
||||
final class WildPhotographerReportHomeViewModel {
|
||||
private(set) var pageState: WildReportPageState = .normal
|
||||
private(set) var reports: [WildReportRecord] = []
|
||||
private(set) var riskPoints: [WildReportRiskPoint] = []
|
||||
private(set) var supplementaryEvidenceMap: [String: [WildReportSupplementaryEvidence]] = [:]
|
||||
|
||||
var onStateChange: (() -> Void)?
|
||||
|
||||
private var nextSequence = 0
|
||||
private var nextSupplementSequence = 0
|
||||
|
||||
init() {
|
||||
resetDemoData(notify: false)
|
||||
}
|
||||
|
||||
var emptyTitle: String { "暂无举报服务" }
|
||||
var emptyMessage: String { "当前景区暂未开放举报摄影师演示入口。" }
|
||||
|
||||
/// 恢复演示数据并回到正常状态。
|
||||
func restoreDemoData() {
|
||||
resetDemoData(notify: false)
|
||||
pageState = .normal
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 模拟错误后重新加载。
|
||||
func retryLoadAfterError() {
|
||||
pageState = .loading
|
||||
notifyStateChange()
|
||||
Task {
|
||||
try? await Task.sleep(nanoseconds: 450_000_000)
|
||||
pageState = .normal
|
||||
notifyStateChange()
|
||||
}
|
||||
}
|
||||
|
||||
/// 切换页面演示状态。
|
||||
func setPageState(_ state: WildReportPageState) {
|
||||
pageState = state
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 提交举报并写入 Mock 列表,返回新记录。
|
||||
@discardableResult
|
||||
func submitReport(
|
||||
reportType: WildReportType,
|
||||
description: String,
|
||||
location: String,
|
||||
contact: String?,
|
||||
imageCount: Int,
|
||||
videoCount: Int
|
||||
) -> WildReportRecord {
|
||||
let trimmedDescription = description.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let parsedContact = WildPhotographerReportMockStore.parseContact(contact)
|
||||
let record = WildReportRecord(
|
||||
id: nextReportID(),
|
||||
title: "摄影师举报",
|
||||
reportType: reportType,
|
||||
status: .pending,
|
||||
location: location,
|
||||
submitTime: WildPhotographerReportMockStore.submitTimeFormatter.string(from: Date()),
|
||||
description: trimmedDescription,
|
||||
wechatID: parsedContact.wechat,
|
||||
phoneNumber: parsedContact.phone,
|
||||
imageCount: imageCount,
|
||||
videoCount: videoCount,
|
||||
handlerInfo: nil
|
||||
)
|
||||
reports.insert(record, at: 0)
|
||||
notifyStateChange()
|
||||
return record
|
||||
}
|
||||
|
||||
/// 读取指定举报的补充证据列表。
|
||||
func supplementaryEvidences(for reportID: String) -> [WildReportSupplementaryEvidence] {
|
||||
supplementaryEvidenceMap[reportID] ?? []
|
||||
}
|
||||
|
||||
/// 追加一条补充证据记录。
|
||||
func appendSupplementaryEvidence(
|
||||
reportID: String,
|
||||
text: String,
|
||||
imageCount: Int,
|
||||
videoCount: Int
|
||||
) {
|
||||
let item = WildReportSupplementaryEvidence(
|
||||
id: nextSupplementID(),
|
||||
submitTime: WildPhotographerReportMockStore.submitTimeFormatter.string(from: Date()),
|
||||
text: text.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||
imageCount: imageCount,
|
||||
videoCount: videoCount
|
||||
)
|
||||
var items = supplementaryEvidenceMap[reportID] ?? []
|
||||
items.insert(item, at: 0)
|
||||
supplementaryEvidenceMap[reportID] = items
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 重置为种子 Mock 数据。
|
||||
func resetDemoData(notify: Bool = true) {
|
||||
reports = WildPhotographerReportMockStore.seedReports
|
||||
riskPoints = WildPhotographerReportMockStore.seedRiskPoints
|
||||
supplementaryEvidenceMap = WildPhotographerReportMockStore.seedSupplementaryEvidences
|
||||
nextSequence = WildPhotographerReportMockStore.maxSequence(from: WildPhotographerReportMockStore.seedReports) + 1
|
||||
nextSupplementSequence = 100
|
||||
if notify { notifyStateChange() }
|
||||
}
|
||||
|
||||
private func nextSupplementID() -> String {
|
||||
defer { nextSupplementSequence += 1 }
|
||||
return String(format: "SE%03d", nextSupplementSequence)
|
||||
}
|
||||
|
||||
private func nextReportID() -> String {
|
||||
let datePart = WildPhotographerReportMockStore.reportDateFormatter.string(from: Date())
|
||||
defer { nextSequence += 1 }
|
||||
return String(format: "JB\(datePart)%03d", nextSequence)
|
||||
}
|
||||
|
||||
private func notifyStateChange() {
|
||||
onStateChange?()
|
||||
}
|
||||
}
|
||||
|
||||
/// 提交举报页 ViewModel,负责表单校验和前台定位。
|
||||
final class WildPhotographerReportSubmitViewModel {
|
||||
private(set) var pageState: WildReportPageState = .normal
|
||||
private(set) var images: [WildReportAttachment]
|
||||
private(set) var videos: [WildReportAttachment]
|
||||
private(set) var paymentImages: [WildReportAttachment] = []
|
||||
private(set) var selectedReportType: WildReportType = .suspectedWild
|
||||
private(set) var description = ""
|
||||
private(set) var contact = ""
|
||||
private(set) var reportLocation = ""
|
||||
private(set) var isUpdatingLocation = false
|
||||
private(set) var locationConfirmed = false
|
||||
private(set) var submitResult: WildReportSubmitResult?
|
||||
private(set) var validationMessage: String?
|
||||
|
||||
var onStateChange: (() -> Void)?
|
||||
var onShowMessage: ((String) -> Void)?
|
||||
var onSubmitSuccess: ((WildReportSubmitResult) -> Void)?
|
||||
|
||||
private let homeViewModel: WildPhotographerReportHomeViewModel
|
||||
private let locationProvider: any LocationProviding
|
||||
private var hasRequestedInitialLocation = false
|
||||
|
||||
var locationTitleText: String {
|
||||
if reportLocation.isEmpty || isUpdatingLocation {
|
||||
return "正在获取当前位置..."
|
||||
}
|
||||
return "当前定位:\(reportLocation)"
|
||||
}
|
||||
|
||||
var locationSubtitleText: String {
|
||||
if isUpdatingLocation {
|
||||
return "正在更新定位,请稍候"
|
||||
}
|
||||
if locationConfirmed {
|
||||
return "已获取最新定位,如不准确请点击更新定位"
|
||||
}
|
||||
return "如位置不准确,请点击更新定位"
|
||||
}
|
||||
|
||||
init(
|
||||
homeViewModel: WildPhotographerReportHomeViewModel,
|
||||
locationProvider: any LocationProviding = LocationProvider.shared
|
||||
) {
|
||||
self.homeViewModel = homeViewModel
|
||||
self.locationProvider = locationProvider
|
||||
self.images = WildPhotographerReportMockStore.initialImages
|
||||
self.videos = WildPhotographerReportMockStore.initialVideos
|
||||
}
|
||||
|
||||
/// 首次进入页面时自动请求定位。
|
||||
func loadInitialLocationIfNeeded() {
|
||||
guard !hasRequestedInitialLocation else { return }
|
||||
hasRequestedInitialLocation = true
|
||||
refreshCurrentLocation()
|
||||
}
|
||||
|
||||
/// 选择举报类型。
|
||||
func selectReportType(_ type: WildReportType) {
|
||||
selectedReportType = type
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 限制举报说明最多 500 字。
|
||||
func updateDescription(_ newValue: String) {
|
||||
description = String(newValue.prefix(500))
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 更新联系方式。
|
||||
func updateContact(_ value: String) {
|
||||
contact = String(value.prefix(80))
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 添加演示用现场图片。
|
||||
func addImage() {
|
||||
images.append(WildReportAttachment(kind: .image, title: "现场图片\(images.count + 1)"))
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 添加演示用现场视频。
|
||||
func addVideo() {
|
||||
videos.append(WildReportAttachment(kind: .video, title: "现场视频\(videos.count + 1)"))
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 添加演示用支付截图。
|
||||
func addPaymentImage() {
|
||||
guard paymentImages.count < 3 else {
|
||||
onShowMessage?("支付截图最多上传3张")
|
||||
return
|
||||
}
|
||||
paymentImages.append(WildReportAttachment(kind: .payment, title: "支付截图\(paymentImages.count + 1)"))
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 删除指定附件。
|
||||
func removeAttachment(_ attachment: WildReportAttachment) {
|
||||
images.removeAll { $0.id == attachment.id }
|
||||
videos.removeAll { $0.id == attachment.id }
|
||||
paymentImages.removeAll { $0.id == attachment.id }
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 使用前台定位 Provider 刷新当前位置。
|
||||
func refreshCurrentLocation() {
|
||||
guard !isUpdatingLocation else { return }
|
||||
isUpdatingLocation = true
|
||||
locationConfirmed = false
|
||||
reportLocation = "正在获取当前位置..."
|
||||
notifyStateChange()
|
||||
|
||||
Task {
|
||||
do {
|
||||
let snapshot = try await locationProvider.requestSnapshot()
|
||||
let address = snapshot.address.isEmpty
|
||||
? String(format: "%.5f, %.5f", snapshot.latitude, snapshot.longitude)
|
||||
: snapshot.address
|
||||
applyResolvedLocation(address)
|
||||
} catch {
|
||||
applyResolvedLocation(WildPhotographerReportMockStore.fallbackLocation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 清除提交结果,用于导航返回。
|
||||
func clearSubmitResult() {
|
||||
submitResult = nil
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 校验表单并提交举报。
|
||||
func submitReport() {
|
||||
validationMessage = nil
|
||||
guard !images.isEmpty || !videos.isEmpty else {
|
||||
setValidationMessage("请至少上传一项现场证据。")
|
||||
return
|
||||
}
|
||||
guard !description.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
||||
setValidationMessage("请填写举报说明。")
|
||||
return
|
||||
}
|
||||
guard !isUpdatingLocation else {
|
||||
setValidationMessage("正在获取定位,请稍后再提交。")
|
||||
return
|
||||
}
|
||||
guard locationConfirmed, !reportLocation.isEmpty, reportLocation != "正在获取当前位置..." else {
|
||||
setValidationMessage("请先更新举报位置后再提交举报。")
|
||||
return
|
||||
}
|
||||
|
||||
let record = homeViewModel.submitReport(
|
||||
reportType: selectedReportType,
|
||||
description: description,
|
||||
location: reportLocation,
|
||||
contact: contact.isEmpty ? nil : contact,
|
||||
imageCount: images.count,
|
||||
videoCount: videos.count
|
||||
)
|
||||
let result = WildReportSubmitResult(
|
||||
record: record,
|
||||
imageCount: images.count,
|
||||
videoCount: videos.count
|
||||
)
|
||||
submitResult = result
|
||||
notifyStateChange()
|
||||
onSubmitSuccess?(result)
|
||||
}
|
||||
|
||||
/// 重置表单到初始状态。
|
||||
func resetForm() {
|
||||
images = WildPhotographerReportMockStore.initialImages
|
||||
videos = WildPhotographerReportMockStore.initialVideos
|
||||
paymentImages = []
|
||||
selectedReportType = .suspectedWild
|
||||
description = ""
|
||||
contact = ""
|
||||
reportLocation = ""
|
||||
locationConfirmed = false
|
||||
isUpdatingLocation = false
|
||||
hasRequestedInitialLocation = false
|
||||
submitResult = nil
|
||||
validationMessage = nil
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
func applyResolvedLocation(_ location: String) {
|
||||
reportLocation = location
|
||||
locationConfirmed = true
|
||||
isUpdatingLocation = false
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
private func setValidationMessage(_ message: String) {
|
||||
validationMessage = message
|
||||
notifyStateChange()
|
||||
onShowMessage?(message)
|
||||
}
|
||||
|
||||
private func notifyStateChange() {
|
||||
onStateChange?()
|
||||
}
|
||||
}
|
||||
|
||||
/// 举报成功页 ViewModel。
|
||||
final class WildPhotographerReportSuccessViewModel {
|
||||
let result: WildReportSubmitResult
|
||||
let progressSteps = ["已提交", "现场核查中", "处理结果反馈"]
|
||||
|
||||
init(result: WildReportSubmitResult) {
|
||||
self.result = result
|
||||
}
|
||||
|
||||
var uploadSummary: String {
|
||||
var parts: [String] = []
|
||||
if result.imageCount > 0 { parts.append("\(result.imageCount)张图片") }
|
||||
if result.videoCount > 0 { parts.append("\(result.videoCount)段视频") }
|
||||
return parts.isEmpty ? "暂无" : parts.joined(separator: " ")
|
||||
}
|
||||
|
||||
/// 复制举报编号到剪贴板。
|
||||
@MainActor
|
||||
func copyReportID() -> String {
|
||||
UIPasteboard.general.string = result.record.id
|
||||
return result.record.id
|
||||
}
|
||||
}
|
||||
|
||||
/// 举报详情页 ViewModel。
|
||||
final class WildPhotographerReportDetailViewModel {
|
||||
let record: WildReportRecord
|
||||
private let homeViewModel: WildPhotographerReportHomeViewModel?
|
||||
|
||||
private(set) var actionMessage: String?
|
||||
var onStateChange: (() -> Void)?
|
||||
var onShowMessage: ((String) -> Void)?
|
||||
|
||||
init(record: WildReportRecord, homeViewModel: WildPhotographerReportHomeViewModel? = nil) {
|
||||
self.record = record
|
||||
self.homeViewModel = homeViewModel
|
||||
}
|
||||
|
||||
var heroTitle: String { record.title.isEmpty ? "摄影师举报" : record.title }
|
||||
var scenicAreaName: String { WildReportLocationParser.split(record.location).scenic }
|
||||
var detailAddress: String {
|
||||
let detail = WildReportLocationParser.split(record.location).detail
|
||||
return detail.contains("附近") ? detail : "\(detail)附近"
|
||||
}
|
||||
|
||||
var displayStatusText: String { record.status.rawValue }
|
||||
var descriptionText: String { record.description }
|
||||
var contactText: String { record.contactDisplayText }
|
||||
var supplementaryEvidences: [WildReportSupplementaryEvidence] {
|
||||
homeViewModel?.supplementaryEvidences(for: record.id) ?? []
|
||||
}
|
||||
var reporterMediaSummary: String {
|
||||
switch (record.imageCount, record.videoCount) {
|
||||
case (0, 0): return "0项"
|
||||
case (_, 0): return "\(record.imageCount)张"
|
||||
case (0, _): return "\(record.videoCount)段"
|
||||
default: return "\(record.imageCount)张 \(record.videoCount)段"
|
||||
}
|
||||
}
|
||||
var progressSteps: [WildReportProgressStep] { Self.buildProgressSteps(for: record) }
|
||||
var showHandlerInfo: Bool { record.status == .processed && record.handlerInfo != nil }
|
||||
var handlerInfo: WildReportHandlerInfo? { record.handlerInfo }
|
||||
|
||||
/// 展示媒体预览提示。
|
||||
func showMediaPreview(kind: String) {
|
||||
showActionMessage("演示环境暂不支持预览\(kind),可在提交页查看上传内容。")
|
||||
}
|
||||
|
||||
/// 展示位置预览提示。
|
||||
func showLocationPreview() {
|
||||
showActionMessage("举报位置:\(record.location)")
|
||||
}
|
||||
|
||||
/// 生成分享提示文案。
|
||||
func shareReport() {
|
||||
showActionMessage("已生成举报 \(record.id) 的分享信息,可发送给景区处理人员查看进度。")
|
||||
}
|
||||
|
||||
private func showActionMessage(_ message: String) {
|
||||
actionMessage = message
|
||||
onShowMessage?(message)
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
private static func buildProgressSteps(for record: WildReportRecord) -> [WildReportProgressStep] {
|
||||
let baseDate = submitDate(from: record.submitTime) ?? Date()
|
||||
let expectedFeedback = formatDate(baseDate.addingTimeInterval(8 * 3_600))
|
||||
|
||||
switch record.status {
|
||||
case .pending, .processing:
|
||||
return [
|
||||
makeStep(id: "1", title: "已提交", date: baseDate, state: .completed),
|
||||
makeStep(id: "2", title: "已派工作人员前往", date: baseDate.addingTimeInterval(22 * 60), state: .completed),
|
||||
makeStep(id: "3", title: "现场核查中", date: baseDate.addingTimeInterval(57 * 60), state: .current),
|
||||
makeStep(id: "4", title: "待结果反馈", date: nil, state: .pending, pendingText: "预计 \(expectedFeedback) 前")
|
||||
]
|
||||
case .processed:
|
||||
return [
|
||||
makeStep(id: "1", title: "已提交", date: baseDate, state: .completed),
|
||||
makeStep(id: "2", title: "已派工作人员前往", date: baseDate.addingTimeInterval(22 * 60), state: .completed),
|
||||
makeStep(id: "3", title: "现场核查中", date: baseDate.addingTimeInterval(57 * 60), state: .completed),
|
||||
makeStep(id: "4", title: "已反馈核查结果", date: baseDate.addingTimeInterval(3 * 3_600), state: .completed)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
private static func makeStep(
|
||||
id: String,
|
||||
title: String,
|
||||
date: Date?,
|
||||
state: WildReportProgressStepState,
|
||||
pendingText: String? = nil
|
||||
) -> WildReportProgressStep {
|
||||
WildReportProgressStep(
|
||||
id: id,
|
||||
title: title,
|
||||
timeText: pendingText ?? (date.map(formatDate) ?? ""),
|
||||
state: state
|
||||
)
|
||||
}
|
||||
|
||||
private static func submitDate(from text: String) -> Date? {
|
||||
WildPhotographerReportMockStore.submitTimeFormatter.date(from: text)
|
||||
}
|
||||
|
||||
private static func formatDate(_ date: Date) -> String {
|
||||
WildPhotographerReportMockStore.submitTimeFormatter.string(from: date)
|
||||
}
|
||||
|
||||
private func notifyStateChange() {
|
||||
onStateChange?()
|
||||
}
|
||||
}
|
||||
|
||||
/// 我的举报列表 ViewModel。
|
||||
final class WildPhotographerReportListViewModel {
|
||||
private(set) var selectedFilter: WildReportListFilter = .all
|
||||
private(set) var shareMessage: String?
|
||||
|
||||
let homeViewModel: WildPhotographerReportHomeViewModel
|
||||
var onStateChange: (() -> Void)?
|
||||
var onShowMessage: ((String) -> Void)?
|
||||
|
||||
init(homeViewModel: WildPhotographerReportHomeViewModel) {
|
||||
self.homeViewModel = homeViewModel
|
||||
}
|
||||
|
||||
var filteredReports: [WildReportRecord] {
|
||||
let reports = homeViewModel.reports
|
||||
switch selectedFilter {
|
||||
case .all: return reports
|
||||
case .pending: return reports.filter { $0.status == .pending }
|
||||
case .processing: return reports.filter { $0.status == .processing }
|
||||
case .processed: return reports.filter { $0.status == .processed }
|
||||
}
|
||||
}
|
||||
|
||||
var footerTip: String { "温馨提示:为保障处理效率,请如实举报并提供有效证据" }
|
||||
|
||||
/// 切换列表筛选标签。
|
||||
func selectFilter(_ filter: WildReportListFilter) {
|
||||
selectedFilter = filter
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 生成分享提示文案。
|
||||
func shareReport(_ record: WildReportRecord) {
|
||||
shareMessage = "已生成举报 \(record.id) 的分享信息,可发送给景区处理人员查看进度。"
|
||||
onShowMessage?(shareMessage ?? "")
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
private func notifyStateChange() {
|
||||
onStateChange?()
|
||||
}
|
||||
}
|
||||
|
||||
/// 补充证据页 ViewModel。
|
||||
final class WildReportSupplementEvidenceViewModel {
|
||||
private(set) var text = ""
|
||||
private(set) var images: [WildReportAttachment] = []
|
||||
private(set) var videos: [WildReportAttachment] = []
|
||||
private(set) var validationMessage: String?
|
||||
private(set) var didSubmit = false
|
||||
|
||||
let reportID: String
|
||||
var onStateChange: (() -> Void)?
|
||||
var onShowMessage: ((String) -> Void)?
|
||||
var onSubmitSuccess: (() -> Void)?
|
||||
|
||||
private let homeViewModel: WildPhotographerReportHomeViewModel
|
||||
|
||||
init(reportID: String, homeViewModel: WildPhotographerReportHomeViewModel) {
|
||||
self.reportID = reportID
|
||||
self.homeViewModel = homeViewModel
|
||||
}
|
||||
|
||||
/// 限制补充说明最多 500 字。
|
||||
func updateText(_ newValue: String) {
|
||||
text = String(newValue.prefix(500))
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 添加演示用补充图片。
|
||||
func addImage() {
|
||||
guard images.count < 9 else {
|
||||
onShowMessage?("补充图片最多上传9张")
|
||||
return
|
||||
}
|
||||
images.append(WildReportAttachment(kind: .image, title: "补充图片\(images.count + 1)"))
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 添加演示用补充视频。
|
||||
func addVideo() {
|
||||
guard videos.count < 3 else {
|
||||
onShowMessage?("补充视频最多上传3段")
|
||||
return
|
||||
}
|
||||
videos.append(WildReportAttachment(kind: .video, title: "补充视频\(videos.count + 1)"))
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 删除指定附件。
|
||||
func removeAttachment(_ attachment: WildReportAttachment) {
|
||||
images.removeAll { $0.id == attachment.id }
|
||||
videos.removeAll { $0.id == attachment.id }
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 校验并提交补充证据。
|
||||
func submit() {
|
||||
validationMessage = nil
|
||||
let trimmedText = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmedText.isEmpty || !images.isEmpty || !videos.isEmpty else {
|
||||
validationMessage = "请至少填写补充说明或上传一项证据。"
|
||||
onShowMessage?(validationMessage ?? "")
|
||||
notifyStateChange()
|
||||
return
|
||||
}
|
||||
|
||||
homeViewModel.appendSupplementaryEvidence(
|
||||
reportID: reportID,
|
||||
text: trimmedText,
|
||||
imageCount: images.count,
|
||||
videoCount: videos.count
|
||||
)
|
||||
didSubmit = true
|
||||
notifyStateChange()
|
||||
onSubmitSuccess?()
|
||||
}
|
||||
|
||||
private func notifyStateChange() {
|
||||
onStateChange?()
|
||||
}
|
||||
}
|
||||
|
||||
/// 附近风险地图 ViewModel。
|
||||
final class WildReportRiskMapViewModel {
|
||||
private(set) var region: MKCoordinateRegion
|
||||
private(set) var markers: [WildReportMapMarker]
|
||||
let scenicAreaName: String
|
||||
private(set) var selectedMarkerID: String?
|
||||
private(set) var toastMessage: String?
|
||||
|
||||
var onStateChange: (() -> Void)?
|
||||
var onShowMessage: ((String) -> Void)?
|
||||
|
||||
init(record: WildReportRecord, riskPoints: [WildReportRiskPoint]) {
|
||||
let markers = WildPhotographerReportMockStore.buildMarkers(record: record, riskPoints: riskPoints)
|
||||
self.markers = markers
|
||||
self.region = WildPhotographerReportMockStore.region(for: markers)
|
||||
self.scenicAreaName = "那拉提景区"
|
||||
self.selectedMarkerID = markers.first(where: { $0.kind == .selfLocation })?.id
|
||||
}
|
||||
|
||||
var selectedMarker: WildReportMapMarker? {
|
||||
guard let selectedMarkerID else { return nil }
|
||||
return markers.first { $0.id == selectedMarkerID }
|
||||
}
|
||||
|
||||
var selectedClue: WildReportRadarActiveClue? {
|
||||
guard let marker = selectedMarker,
|
||||
case .activeClue(let clue) = marker.detail else { return nil }
|
||||
return clue
|
||||
}
|
||||
|
||||
/// 选中地图标记。
|
||||
func selectMarker(_ marker: WildReportMapMarker) {
|
||||
selectedMarkerID = marker.id
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 导航到选中标记或刷新蓝点定位。
|
||||
func navigateToSelectedMarker() {
|
||||
guard let marker = selectedMarker,
|
||||
case .activeClue(let clue) = marker.detail else { return }
|
||||
|
||||
if clue.type == .blue {
|
||||
refreshLocation()
|
||||
return
|
||||
}
|
||||
|
||||
showToast("已切换到该点位")
|
||||
region = MKCoordinateRegion(
|
||||
center: marker.coordinate,
|
||||
span: MKCoordinateSpan(latitudeDelta: 0.018, longitudeDelta: 0.018)
|
||||
)
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 将地图居中到当前位置标记。
|
||||
func refreshLocation() {
|
||||
guard let blueMarker = markers.first(where: { $0.kind == .selfLocation }) else { return }
|
||||
selectedMarkerID = blueMarker.id
|
||||
region = MKCoordinateRegion(
|
||||
center: blueMarker.coordinate,
|
||||
span: MKCoordinateSpan(latitudeDelta: 0.018, longitudeDelta: 0.018)
|
||||
)
|
||||
showToast("已定位到当前位置")
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 生成线索分享提示。
|
||||
func shareSelectedClue() {
|
||||
guard let clue = selectedClue else { return }
|
||||
let title = clue.type == .red ? "线索 ID:\(clue.id)" : clue.displayTitle
|
||||
showToast("已生成\(title)的分享信息,可发送给他人查看。")
|
||||
}
|
||||
|
||||
/// 生成图片预览提示。
|
||||
func showImagePreview(_ url: String) {
|
||||
_ = url
|
||||
showToast("演示环境暂不支持预览图片")
|
||||
}
|
||||
|
||||
private func showToast(_ message: String) {
|
||||
toastMessage = message
|
||||
onShowMessage?(message)
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
private func notifyStateChange() {
|
||||
onStateChange?()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user