mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-21 12:59:23 +00:00
新建/编辑两个表单面此前各持 8 个 @State 字段、逐字复制的密码 reveal、 column helper 与字段 ↔ ServerEditDraft 映射;收进 App/ServerFormFields.swift (草稿 ObservableObject + 表单栅格视图),caller 只剩 load(from:)/draft。 订阅只读禁用、集外加密追加与插件区 facts 参数化;methodChoices 统一后 新建面行为等价(初值恒在集内)。CONTEXT.md 补 Server form draft 术语。
186 lines
5.5 KiB
Swift
186 lines
5.5 KiB
Swift
import SwiftUI
|
|
|
|
/// 服务器详情表单(issue #32/#38/#41,地图 #52 票 #55):按原型重排为详情头
|
|
/// (图标 + 名称 + 来源说明)+ 两列表单栅格(地址/端口、加密/备注、密码全宽、
|
|
/// 插件区)+ 底部操作区(取消恢复草稿 / 保存)。表单状态经工作流的显式编辑
|
|
/// 命令解析(凭据明文仅在编辑动作中出现);插件区为受管选择器(D10)——
|
|
/// 「无」+ 受管列表,选中受管项才显示参数输入;集外引用以显式「本版本未
|
|
/// 提供」呈现并原样保留;分享区(二维码 + 复制 ss://,显式分享命令)。
|
|
/// 订阅服务器整表只读(无底部操作区,横幅说明)。
|
|
struct ServerDetailView: View {
|
|
let workflow: CatalogWorkflow
|
|
let serverID: NodeID
|
|
/// 运行时事实(活动目标标记):由父视图从既有接缝传入,详情面不持控制器。
|
|
let isActiveTarget: Bool
|
|
let errors: ErrorAlertPresenter
|
|
let clipboard: any TextClipboard
|
|
|
|
/// 连接字段草稿由共享 module 持有(与新建表单同一 interface),经显式
|
|
/// 编辑命令装载(凭据明文仅在编辑动作中出现)。
|
|
@StateObject private var fields = ServerFormFields()
|
|
// 分享/二维码状态由同 module 的 ServerDetailView+Share.swift 扩展驱动。
|
|
@State var showQR = false
|
|
@State var qrImage: NSImage?
|
|
|
|
private var formState: ServerEditForm? {
|
|
workflow.serverEditForm(for: serverID)
|
|
}
|
|
|
|
private var isEditable: Bool {
|
|
formState?.isEditable ?? false
|
|
}
|
|
|
|
private var node: CatalogTreeNode? {
|
|
workflow.tree.node(withID: serverID)
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
ScrollView {
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
detailHeader
|
|
formContent
|
|
}
|
|
.padding(.leading, 28)
|
|
.padding(.trailing, 32)
|
|
.padding(.top, 20)
|
|
.padding(.bottom, 24)
|
|
}
|
|
if isEditable {
|
|
detailFooter
|
|
}
|
|
}
|
|
.popover(isPresented: $showQR) {
|
|
qrPopover
|
|
}
|
|
.onAppear(perform: loadForm)
|
|
.onChange(of: serverID) { _, _ in loadForm() }
|
|
}
|
|
|
|
// MARK: - 详情头与表单
|
|
|
|
private var detailHeader: some View {
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
HStack(alignment: .center, spacing: 12) {
|
|
ZStack {
|
|
RoundedRectangle(cornerRadius: 10, style: .continuous)
|
|
.fill(Color.accentColor.opacity(0.12))
|
|
Image(systemName: "server.rack")
|
|
.font(.system(size: 16, weight: .medium))
|
|
.foregroundStyle(.tint)
|
|
}
|
|
.frame(width: 38, height: 38)
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text(workflow.displayName(for: serverID))
|
|
.font(.title2.weight(.semibold))
|
|
.lineLimit(1)
|
|
Text(sourceDescription)
|
|
.font(.subheadline)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
Spacer(minLength: 0)
|
|
if let node, node.isInvalid {
|
|
Image(systemName: "exclamationmark.triangle.fill")
|
|
.foregroundStyle(.orange)
|
|
.help("该服务器存在已知阻塞问题,激活会被点名拒绝")
|
|
}
|
|
}
|
|
.padding(.bottom, 16)
|
|
Divider()
|
|
}
|
|
}
|
|
|
|
private var sourceDescription: String {
|
|
guard let node else { return "" }
|
|
if node.source == .subscription {
|
|
return "订阅节点 · 远端管理"
|
|
}
|
|
return isActiveTarget ? "手动服务器 · 活动目标" : "手动服务器"
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var formContent: some View {
|
|
if let node, node.isInvalid {
|
|
invalidBanner(node)
|
|
}
|
|
if !isEditable {
|
|
Label("订阅节点由远端管理:连接字段只读。", systemImage: "info.circle")
|
|
.font(.footnote)
|
|
.foregroundStyle(.secondary)
|
|
.padding(.top, 16)
|
|
}
|
|
ServerFormFieldsGrid(
|
|
fields: fields, plugin: formState?.plugin, isEditable: isEditable
|
|
)
|
|
.padding(.top, 20)
|
|
|
|
shareSection
|
|
.padding(.top, 24)
|
|
}
|
|
|
|
private func invalidBanner(_ node: CatalogTreeNode) -> some View {
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
ForEach(Array(node.invalidReasons.enumerated()), id: \.offset) { _, reason in
|
|
Label(
|
|
AppPresentation.message(
|
|
for: ActivationFailure.invalidLeaf(node: node.id, reason: reason)),
|
|
systemImage: "exclamationmark.triangle.fill"
|
|
)
|
|
.font(.footnote)
|
|
.foregroundStyle(.orange)
|
|
}
|
|
}
|
|
.padding(.top, 16)
|
|
}
|
|
|
|
private var shareSection: some View {
|
|
HStack(spacing: 10) {
|
|
Button {
|
|
copySsUri()
|
|
} label: {
|
|
Label("复制 ss:// 链接", systemImage: "doc.on.doc")
|
|
}
|
|
Button {
|
|
generateQR()
|
|
} label: {
|
|
Label("二维码…", systemImage: "qrcode")
|
|
}
|
|
.disabled(qrPayload() == nil)
|
|
Spacer(minLength: 0)
|
|
}
|
|
}
|
|
|
|
/// 底部操作区:取消恢复已保存值,保存提交草稿。
|
|
private var detailFooter: some View {
|
|
VStack(spacing: 0) {
|
|
Divider()
|
|
HStack {
|
|
Spacer(minLength: 0)
|
|
Button("取消") { loadForm() }
|
|
Button("保存") { save() }
|
|
.keyboardShortcut(.defaultAction)
|
|
}
|
|
.padding(.horizontal, 32)
|
|
.padding(.vertical, 12)
|
|
}
|
|
.background(.bar)
|
|
}
|
|
|
|
// MARK: - 表单装载与提交
|
|
|
|
private func loadForm() {
|
|
guard let state = formState else { return }
|
|
fields.load(from: state)
|
|
}
|
|
|
|
private func save() {
|
|
Task {
|
|
do {
|
|
try await workflow.updateServer(serverID, draft: fields.draft)
|
|
} catch {
|
|
errors.present(error)
|
|
}
|
|
}
|
|
}
|
|
}
|