From 241220a7c07b84419d417238d0d049c2b5ffd6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E9=93=AD?= Date: Wed, 20 Nov 2024 06:25:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B9=A6=E7=AD=BE=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bookmark/View/BookmarkListView.swift | 32 +++++++---------- .../Guide/View/GuideListView.swift | 2 +- SwiftPamphletApp/HomeUI/DataLink.swift | 12 +++++-- SwiftPamphletApp/HomeUI/HomeView.swift | 34 +++++++------------ 4 files changed, 35 insertions(+), 45 deletions(-) diff --git a/SwiftPamphletApp/Guide/Bookmark/View/BookmarkListView.swift b/SwiftPamphletApp/Guide/Bookmark/View/BookmarkListView.swift index a8d3c861..9f3c92ec 100644 --- a/SwiftPamphletApp/Guide/Bookmark/View/BookmarkListView.swift +++ b/SwiftPamphletApp/Guide/Bookmark/View/BookmarkListView.swift @@ -12,32 +12,24 @@ struct BookmarkListView: View { @Environment(\.modelContext) var modelContext @Query(BookmarkModel.all) var bms: [BookmarkModel] // var bms: [BookmarkModel] = [BookmarkModel]() // 测试空数据用 + @Binding var selectedItem: L? @State private var limit: Int = 50 @State private var trigger = false var body: some View { - List { + List(selection: $selectedItem) { ForEach(bms) { bm in - NavigationLink( - destination: GuideDetailView( - t: bm.name, - icon: bm.icon, - plName: bm.pamphletName, - limit: $limit, - trigger: $trigger - ) - ) { - HStack { - if bm.icon.isEmpty == false { - Image(systemName: bm.icon) - .foregroundStyle(Color.secondary) - } - Text(bm.name) - Spacer() - Image(systemName: "bookmark") - .foregroundStyle(.secondary) - .font(.footnote) + HStack { + if bm.icon.isEmpty == false { + Image(systemName: bm.icon) + .foregroundStyle(Color.secondary) } + Text(bm.name) + Spacer() + Image(systemName: "bookmark") + .foregroundStyle(.secondary) + .font(.footnote) } + .tag(L(t: bm.name, icon: bm.icon)) .contextMenu { Button("前移") { bm.updateDate = Date.now diff --git a/SwiftPamphletApp/Guide/View/GuideListView.swift b/SwiftPamphletApp/Guide/View/GuideListView.swift index 483b3cb8..6b420952 100644 --- a/SwiftPamphletApp/Guide/View/GuideListView.swift +++ b/SwiftPamphletApp/Guide/View/GuideListView.swift @@ -13,7 +13,7 @@ struct GuideListView: View { @Query(BookmarkModel.all) var bookmarks: [BookmarkModel] @State private var apBookmarks: [String] = [String]() @State var listModel: GuideListModel - @Binding var selectedItem: L? // 改为 L? 类型 + @Binding var selectedItem: L? @AppStorage(SPC.expandedGuideItems) private var expandedItemsString: String = "" @State private var expandedItems: Set = [] diff --git a/SwiftPamphletApp/HomeUI/DataLink.swift b/SwiftPamphletApp/HomeUI/DataLink.swift index 156c3479..cdafe72d 100644 --- a/SwiftPamphletApp/HomeUI/DataLink.swift +++ b/SwiftPamphletApp/HomeUI/DataLink.swift @@ -128,9 +128,17 @@ struct DataLink: Identifiable { case "书签": switch type { case .content: - BookmarkListView() + BookmarkListView(selectedItem: selectGuideItem) case .detail: - IntroView() + if let item = selectGuideItemBindable { + GuideDetailView( + t: item.t, + icon: item.icon, + plName: "ap", + limit: limit, + trigger: trigger + ) + } } default: switch type { diff --git a/SwiftPamphletApp/HomeUI/HomeView.swift b/SwiftPamphletApp/HomeUI/HomeView.swift index 2c9b1591..62830d07 100644 --- a/SwiftPamphletApp/HomeUI/HomeView.swift +++ b/SwiftPamphletApp/HomeUI/HomeView.swift @@ -52,28 +52,18 @@ struct HomeView: View { } } detail: { if !selectedDataLinkString.isEmpty { - if selectedDataLinkString == "Apple技术", let item = selectedGuideItem { - GuideDetailView( - t: item.t, - icon: item.icon, - plName: "ap", - limit: $limit, - trigger: $trigger - ) - } else { - DataLink.viewToShow( - for: selectedDataLinkString, - selectInfo: $selectInfo, - selectDev: $selectDev, - selectInfoBindable: selectInfo, - selectDevBindable: selectDev, - selectGuideItem: $selectedGuideItem, - selectGuideItemBindable: selectedGuideItem, - limit: $limit, - trigger: $trigger, - type: .detail - ) - } + DataLink.viewToShow( + for: selectedDataLinkString, + selectInfo: $selectInfo, + selectDev: $selectDev, + selectInfoBindable: selectInfo, + selectDevBindable: selectDev, + selectGuideItem: $selectedGuideItem, + selectGuideItemBindable: selectedGuideItem, + limit: $limit, + trigger: $trigger, + type: .detail + ) } else { IntroView() }