完善任务流程、键盘适配与页面交互
This commit is contained in:
@ -100,11 +100,12 @@ struct TaskFileItem: Sendable, Equatable, Hashable, Identifiable {
|
||||
let id: String
|
||||
let source: TaskFileSource
|
||||
let cloudFile: CloudFile?
|
||||
let uploadFileName: String?
|
||||
var uploadFileName: String?
|
||||
let uploadFileType: Int
|
||||
let uploadTaskId: String?
|
||||
var uploadFileUrl: String?
|
||||
var uploadCoverUrl: String?
|
||||
var localPreviewData: Data?
|
||||
var remark: String
|
||||
var isUploading: Bool
|
||||
var uploadProgress: Int
|
||||
@ -117,6 +118,7 @@ struct TaskFileItem: Sendable, Equatable, Hashable, Identifiable {
|
||||
uploadFileName: String? = nil,
|
||||
uploadFileType: Int = 0,
|
||||
uploadCoverUrl: String? = nil,
|
||||
localPreviewData: Data? = nil,
|
||||
remark: String = "",
|
||||
uploadTaskId: String? = nil,
|
||||
isUploading: Bool = false,
|
||||
@ -137,6 +139,7 @@ struct TaskFileItem: Sendable, Equatable, Hashable, Identifiable {
|
||||
self.uploadFileName = uploadFileName
|
||||
self.uploadFileType = uploadFileType
|
||||
self.uploadCoverUrl = uploadCoverUrl
|
||||
self.localPreviewData = localPreviewData
|
||||
self.remark = remark
|
||||
self.uploadTaskId = uploadTaskId
|
||||
self.isUploading = isUploading
|
||||
|
||||
@ -57,11 +57,7 @@ final class TaskAddViewModel {
|
||||
/// 更新自定义优先级小时文本。
|
||||
func updateCustomUrgentHourText(_ text: String) {
|
||||
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard let hour = Int(trimmed), hour > 0 else {
|
||||
urgentHour = 1
|
||||
notifyStateChange()
|
||||
return
|
||||
}
|
||||
guard let hour = Int(trimmed), hour > 0 else { return }
|
||||
urgentHour = hour
|
||||
notifyStateChange()
|
||||
}
|
||||
@ -117,13 +113,38 @@ final class TaskAddViewModel {
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 本地文件读取完成后同步真实文件名与预览图。
|
||||
func prepareUpload(uploadTaskId: String, fileName: String, localPreviewData: Data?) {
|
||||
selectedFiles = selectedFiles.map { item in
|
||||
guard item.uploadTaskId == uploadTaskId else { return item }
|
||||
var updated = item
|
||||
updated.uploadFileName = fileName
|
||||
updated.localPreviewData = localPreviewData
|
||||
return updated
|
||||
}
|
||||
notifyStateChange()
|
||||
}
|
||||
|
||||
/// 上传成功后更新文件 URL。
|
||||
func markUploadSucceeded(uploadTaskId: String, fileURL: String, coverURL: String? = nil, autoRemarkWhenSingle: Bool) {
|
||||
func markUploadSucceeded(
|
||||
uploadTaskId: String,
|
||||
fileURL: String,
|
||||
fileName: String? = nil,
|
||||
coverURL: String? = nil,
|
||||
localPreviewData: Data? = nil,
|
||||
autoRemarkWhenSingle: Bool
|
||||
) {
|
||||
selectedFiles = selectedFiles.map { item in
|
||||
guard item.uploadTaskId == uploadTaskId else { return item }
|
||||
var updated = item
|
||||
updated.uploadFileUrl = fileURL
|
||||
if let fileName, !fileName.isEmpty {
|
||||
updated.uploadFileName = fileName
|
||||
}
|
||||
updated.uploadCoverUrl = coverURL
|
||||
if let localPreviewData {
|
||||
updated.localPreviewData = localPreviewData
|
||||
}
|
||||
updated.isUploading = false
|
||||
updated.uploadProgress = 100
|
||||
return updated
|
||||
|
||||
@ -1168,9 +1168,27 @@ final class WildReportRiskMapViewModel {
|
||||
)
|
||||
}
|
||||
|
||||
/// 生成线索分享提示。
|
||||
func shareSelectedClue() {
|
||||
_ = selectedClue
|
||||
/// 拉取当前选中举报线索的小程序分享载荷。
|
||||
func shareSelectedClue(api: any WildPhotographerReportServing) async -> WeChatMiniProgramSharePayload? {
|
||||
guard let marker = selectedMarker,
|
||||
marker.kind == .wildPhotographer || marker.kind == .processingClue,
|
||||
let reportID = reportID(fromMarkerID: marker.id)
|
||||
else {
|
||||
errorMessage = "请选择可分享的举报线索"
|
||||
notifyStateChange()
|
||||
return nil
|
||||
}
|
||||
|
||||
do {
|
||||
let shareData = try await api.reportShare(id: String(reportID))
|
||||
return shareData.payload
|
||||
} catch is CancellationError {
|
||||
return nil
|
||||
} catch {
|
||||
errorMessage = error.localizedDescription
|
||||
notifyStateChange()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
/// 生成图片预览提示。
|
||||
@ -1371,6 +1389,12 @@ final class WildReportRiskMapViewModel {
|
||||
)
|
||||
}
|
||||
|
||||
private func reportID(fromMarkerID markerID: String) -> Int? {
|
||||
let parts = markerID.split(separator: "-", maxSplits: 1).map(String.init)
|
||||
guard parts.count == 2, let id = Int(parts[1]), id >= 1 else { return nil }
|
||||
return id
|
||||
}
|
||||
|
||||
private func mergeDetail(_ detail: WildReportMarkerDetailResponse, intoMarkerID markerID: String) {
|
||||
guard let index = markers.firstIndex(where: { $0.id == markerID }),
|
||||
case .activeClue(let oldClue) = markers[index].detail
|
||||
|
||||
Reference in New Issue
Block a user