98b7600797
对标安卓正式版、对接 app-server(8770)的 SwiftUI 客户端。iOS 无障碍受限、无比价核心,做自成一体:美团 CPS 导购 + 福利(签到/任务/金币)+ 查看(比价记录/省钱战绩)。 功能完整 M0-M5:脚手架、短信登录(JWT+Keychain+401 自动刷新)、首页券 feed 导购、比价记录+省钱战绩、福利、我的(资料/反馈/设置/注销)。 单 target、0 三方依赖、XcodeGen 生成工程;Debug/Release 双 plist 分流 ATS。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
85 lines
3.1 KiB
Swift
85 lines
3.1 KiB
Swift
import SwiftUI
|
|
import PhotosUI
|
|
|
|
/// 帮助与反馈:内容 + 联系方式 + 可选截图(≤3 张,压缩后上传)。
|
|
struct FeedbackView: View {
|
|
@Environment(\.dismiss) private var dismiss
|
|
@State private var content = ""
|
|
@State private var contact = ""
|
|
@State private var pickedItems: [PhotosPickerItem] = []
|
|
@State private var imageDatas: [Data] = []
|
|
@State private var submitting = false
|
|
@State private var toast: String?
|
|
private let service = FeedbackService()
|
|
|
|
var body: some View {
|
|
Form {
|
|
Section("反馈内容") {
|
|
TextField("说说你遇到的问题或建议…", text: $content, axis: .vertical)
|
|
.lineLimit(4...8)
|
|
}
|
|
Section("联系方式(选填)") {
|
|
TextField("手机号 / 微信,方便我们联系你", text: $contact)
|
|
}
|
|
Section("截图(选填)") {
|
|
PhotosPicker(selection: $pickedItems, maxSelectionCount: 3, matching: .images) {
|
|
Label("添加截图", systemImage: "photo.on.rectangle")
|
|
}
|
|
if !imageDatas.isEmpty {
|
|
Text("已选 \(imageDatas.count) 张").font(.caption).foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
Section {
|
|
Button {
|
|
Task { await submit() }
|
|
} label: {
|
|
Text(submitting ? "提交中…" : "提交反馈").frame(maxWidth: .infinity)
|
|
}
|
|
.disabled(submitting || content.isEmpty)
|
|
}
|
|
}
|
|
.navigationTitle("帮助与反馈")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.onChange(of: pickedItems) { _, items in
|
|
Task { await loadImages(items) }
|
|
}
|
|
.overlay(alignment: .bottom) { toastView }
|
|
}
|
|
|
|
@ViewBuilder private var toastView: some View {
|
|
if let toast {
|
|
Text(toast)
|
|
.font(.subheadline)
|
|
.padding(.horizontal, 16).padding(.vertical, 10)
|
|
.background(.black.opacity(0.8)).foregroundStyle(.white)
|
|
.clipShape(Capsule()).padding(.bottom, 30)
|
|
.task(id: toast) {
|
|
try? await Task.sleep(for: .milliseconds(1500))
|
|
if toast.contains("成功") { dismiss() } else { self.toast = nil }
|
|
}
|
|
}
|
|
}
|
|
|
|
private func loadImages(_ items: [PhotosPickerItem]) async {
|
|
var datas: [Data] = []
|
|
for item in items {
|
|
if let raw = try? await item.loadTransferable(type: Data.self),
|
|
let jpeg = ImageDownsampler.jpeg(raw) {
|
|
datas.append(jpeg)
|
|
}
|
|
}
|
|
imageDatas = datas
|
|
}
|
|
|
|
private func submit() async {
|
|
submitting = true
|
|
defer { submitting = false }
|
|
do {
|
|
_ = try await service.submit(content: content, contact: contact, images: imageDatas)
|
|
toast = "提交成功,感谢反馈"
|
|
} catch {
|
|
toast = (error as? LocalizedError)?.errorDescription ?? "提交失败,请重试"
|
|
}
|
|
}
|
|
}
|