From dc634f7f3e0d8570f3b2d2e12f6fbc55bd339837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E9=93=AD?= Date: Sat, 23 Nov 2024 19:18:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BE=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E6=A0=8F=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftPamphletApp.xcodeproj/project.pbxproj | 4 +++ SwiftPamphletApp/HomeUI/DataLink.swift | 19 ++++++++++++ SwiftPamphletApp/HomeUI/HomeView.swift | 5 ++++ .../Setting/GithubAccessTokenView.swift | 23 ++++++++++----- .../Setting/SettingSidebarView.swift | 25 ++++++++++++++++ SwiftPamphletApp/Setting/SettingView.swift | 29 +++++-------------- 6 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 SwiftPamphletApp/Setting/SettingSidebarView.swift diff --git a/SwiftPamphletApp.xcodeproj/project.pbxproj b/SwiftPamphletApp.xcodeproj/project.pbxproj index d64c567e5..538e2cc15 100644 --- a/SwiftPamphletApp.xcodeproj/project.pbxproj +++ b/SwiftPamphletApp.xcodeproj/project.pbxproj @@ -216,6 +216,7 @@ 088F2C482C932A7900DCA64F /* 知识管理-输出(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 088F2C472C932A7900DCA64F /* 知识管理-输出(ap).md */; }; 088F2C4A2C932A8B00DCA64F /* 知识管理-目的导向工作流(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 088F2C492C932A8B00DCA64F /* 知识管理-目的导向工作流(ap).md */; }; 088F2C4C2C932C5800DCA64F /* 知识管理-PKM(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 088F2C4B2C932C5800DCA64F /* 知识管理-PKM(ap).md */; }; + 0891EACD2CF1EAC000597974 /* SettingSidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0891EACC2CF1EAC000597974 /* SettingSidebarView.swift */; }; 08A7FF312BEB02EA00E12E5A /* GithubAccessTokenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A7FF302BEB02EA00E12E5A /* GithubAccessTokenView.swift */; }; 08A9E1A22BC25D0700A73764 /* ViewComponentMarkdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E1A12BC25D0700A73764 /* ViewComponentMarkdown.swift */; }; 08AEAEF1277F09D000B969E2 /* IntroView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08AEAEF0277F09D000B969E2 /* IntroView.swift */; }; @@ -732,6 +733,7 @@ 088F2C472C932A7900DCA64F /* 知识管理-输出(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "知识管理-输出(ap).md"; sourceTree = ""; }; 088F2C492C932A8B00DCA64F /* 知识管理-目的导向工作流(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "知识管理-目的导向工作流(ap).md"; sourceTree = ""; }; 088F2C4B2C932C5800DCA64F /* 知识管理-PKM(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "知识管理-PKM(ap).md"; sourceTree = ""; }; + 0891EACC2CF1EAC000597974 /* SettingSidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingSidebarView.swift; sourceTree = ""; }; 08A7FF302BEB02EA00E12E5A /* GithubAccessTokenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GithubAccessTokenView.swift; sourceTree = ""; }; 08A9E1A12BC25D0700A73764 /* ViewComponentMarkdown.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewComponentMarkdown.swift; sourceTree = ""; }; 08AEAEF0277F09D000B969E2 /* IntroView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntroView.swift; sourceTree = ""; }; @@ -2260,6 +2262,7 @@ children = ( 08ED801B2B9D1EEC0069B7EC /* SettingView.swift */, 08A7FF302BEB02EA00E12E5A /* GithubAccessTokenView.swift */, + 0891EACC2CF1EAC000597974 /* SettingSidebarView.swift */, ); path = Setting; sourceTree = ""; @@ -2968,6 +2971,7 @@ files = ( 3A05B7C92CE57A5C00B2B30F /* TaskCaseLoadFile.swift in Sources */, 0871C61B2BA04D23000B620D /* CategoryRowView.swift in Sources */, + 0891EACD2CF1EAC000597974 /* SettingSidebarView.swift in Sources */, 08F14B442BBE2865005B46CC /* ViewComponentImage.swift in Sources */, 08069CAB2BDE01E800D48E24 /* GuideListView.swift in Sources */, 084417792B99BE720049297D /* DataLink.swift in Sources */, diff --git a/SwiftPamphletApp/HomeUI/DataLink.swift b/SwiftPamphletApp/HomeUI/DataLink.swift index cdafe72d7..4f69ccb10 100644 --- a/SwiftPamphletApp/HomeUI/DataLink.swift +++ b/SwiftPamphletApp/HomeUI/DataLink.swift @@ -28,6 +28,8 @@ struct DataLink: Identifiable { selectDevBindable: DeveloperModel?, selectGuideItem: Binding, selectGuideItemBindable: L?, + selectItem: Binding, + selectItemBindable: String?, limit: Binding, trigger: Binding, type: ShowType @@ -140,6 +142,20 @@ struct DataLink: Identifiable { ) } } + case "设置": + switch type { + case .content: + SettingSidebarView(selectedItem: selectItem) + case .detail: + switch selectItemBindable { + case "Github Token 设置": + GithubAccessTokenView() + case "自定义标签": + CustomSearch() + default: + IntroView() + } + } default: switch type { case .content: @@ -165,6 +181,9 @@ extension DataLink { DataLink(title: "未分类", imageName: "p6"), DataLink(title: "收藏", imageName: "p11"), DataLink(title: "归档", imageName: "p3") + ]), + DataLink(title: "工具", imageName: "", children: [ + DataLink(title: "设置", imageName: "p27") ]) ] static func dataLinksWithGithub() -> [DataLink] { diff --git a/SwiftPamphletApp/HomeUI/HomeView.swift b/SwiftPamphletApp/HomeUI/HomeView.swift index 62830d07d..27c19367a 100644 --- a/SwiftPamphletApp/HomeUI/HomeView.swift +++ b/SwiftPamphletApp/HomeUI/HomeView.swift @@ -20,6 +20,7 @@ struct HomeView: View { @State private var selectedGuideItem: L? = nil // 改为 L? 类型 @State private var limit: Int = 50 // 为 GuideDetailView 添加 @State private var trigger: Bool = false // 为 GuideDetailView 添加 + @State private var selectedItem: String? = nil var body: some View { #if os(macOS) @@ -38,6 +39,8 @@ struct HomeView: View { selectDevBindable: selectDev, selectGuideItem: $selectedGuideItem, selectGuideItemBindable: selectedGuideItem, + selectItem: $selectedItem, + selectItemBindable: selectedItem, limit: $limit, trigger: $trigger, type: .content @@ -60,6 +63,8 @@ struct HomeView: View { selectDevBindable: selectDev, selectGuideItem: $selectedGuideItem, selectGuideItemBindable: selectedGuideItem, + selectItem: $selectedItem, + selectItemBindable: selectedItem, limit: $limit, trigger: $trigger, type: .detail diff --git a/SwiftPamphletApp/Setting/GithubAccessTokenView.swift b/SwiftPamphletApp/Setting/GithubAccessTokenView.swift index 1128aa447..d5853964e 100644 --- a/SwiftPamphletApp/Setting/GithubAccessTokenView.swift +++ b/SwiftPamphletApp/Setting/GithubAccessTokenView.swift @@ -9,17 +9,24 @@ import SwiftUI import SMGitHub struct GithubAccessTokenView: View { + @AppStorage(SPC.isShowGithub) var isShowGithub = false @State private var tokenString: String = "" var body: some View { - Form { - Section { - Text("在这里写上 Github 的 access token 来访问内容") - TextField("", text: $tokenString, prompt: Text("输入 access token")) - .padding(10) - .onSubmit { - save() - } + VStack(alignment: .leading) { + Toggle("是否显示 Github", isOn: $isShowGithub) + .toggleStyle(.switch) + .padding(20) + Form { + Section { + Text("在这里写上 Github 的 access token 来访问内容") + TextField("", text: $tokenString, prompt: Text("输入 access token")) + .padding(10) + .onSubmit { + save() + } + } } + Spacer() } .onAppear(perform: { let ud = UserDefaults.standard diff --git a/SwiftPamphletApp/Setting/SettingSidebarView.swift b/SwiftPamphletApp/Setting/SettingSidebarView.swift new file mode 100644 index 000000000..c1d9b331a --- /dev/null +++ b/SwiftPamphletApp/Setting/SettingSidebarView.swift @@ -0,0 +1,25 @@ +// +// SettingSidebarView.swift +// SwiftPamphletApp +// +// Created by Ming Dai on 2024/11/23. +// + +import SwiftUI + +struct SettingSidebarView: View { + @Binding var selectedItem: String? + var body: some View { + List(selection: $selectedItem) { + item(title: "Github Token 设置", icon: "gearshape") + .tag("Github Token 设置") + item(title: "自定义标签", icon: "tag") + .tag("自定义标签") + } + } + + @ViewBuilder func item(title:String, icon:String) -> some View { + Label(title, systemImage: icon) + } +} + diff --git a/SwiftPamphletApp/Setting/SettingView.swift b/SwiftPamphletApp/Setting/SettingView.swift index 4eb99234e..69355ca93 100644 --- a/SwiftPamphletApp/Setting/SettingView.swift +++ b/SwiftPamphletApp/Setting/SettingView.swift @@ -11,11 +11,11 @@ struct SettingView: View { var body: some View { TabView { - accessTokenView() + GithubAccessTokenView() .tabItem { Label("设置", systemImage: "gearshape") } - customSearch() + CustomSearch() .tabItem { Label("自定义标签", systemImage: "mail.and.text.magnifyingglass") } @@ -23,11 +23,12 @@ struct SettingView: View { } .frame(minHeight: 400) } - - // MARK: custom search + +} + +struct CustomSearch: View { @AppStorage(SPC.customSearchTerm) var term = "" - @ViewBuilder - func customSearch() -> some View { + var body: some View { VStack { Text("输入自定义的标签,以换行作为间隔") TextEditor(text: $term) @@ -41,20 +42,4 @@ struct SettingView: View { } .padding(20) } - - // MARK: 是否显示 Github 内容 - @AppStorage(SPC.isShowGithub) var isShowGithub = false - - // MARK: token - @State private var tokenString = "" - @ViewBuilder - func accessTokenView() -> some View { - VStack(alignment: .leading) { - Toggle("是否显示 Github", isOn: $isShowGithub) - .toggleStyle(.switch) - .padding(20) - GithubAccessTokenView() - Spacer() - } - } }