Skip to content

Commit dc634f7

Browse files
committed
增加设置的栏目
1 parent 174673b commit dc634f7

File tree

6 files changed

+75
-30
lines changed

6 files changed

+75
-30
lines changed

SwiftPamphletApp.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
088F2C482C932A7900DCA64F /* 知识管理-输出(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 088F2C472C932A7900DCA64F /* 知识管理-输出(ap).md */; };
217217
088F2C4A2C932A8B00DCA64F /* 知识管理-目的导向工作流(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 088F2C492C932A8B00DCA64F /* 知识管理-目的导向工作流(ap).md */; };
218218
088F2C4C2C932C5800DCA64F /* 知识管理-PKM(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 088F2C4B2C932C5800DCA64F /* 知识管理-PKM(ap).md */; };
219+
0891EACD2CF1EAC000597974 /* SettingSidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0891EACC2CF1EAC000597974 /* SettingSidebarView.swift */; };
219220
08A7FF312BEB02EA00E12E5A /* GithubAccessTokenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A7FF302BEB02EA00E12E5A /* GithubAccessTokenView.swift */; };
220221
08A9E1A22BC25D0700A73764 /* ViewComponentMarkdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E1A12BC25D0700A73764 /* ViewComponentMarkdown.swift */; };
221222
08AEAEF1277F09D000B969E2 /* IntroView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08AEAEF0277F09D000B969E2 /* IntroView.swift */; };
@@ -732,6 +733,7 @@
732733
088F2C472C932A7900DCA64F /* 知识管理-输出(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "知识管理-输出(ap).md"; sourceTree = "<group>"; };
733734
088F2C492C932A8B00DCA64F /* 知识管理-目的导向工作流(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "知识管理-目的导向工作流(ap).md"; sourceTree = "<group>"; };
734735
088F2C4B2C932C5800DCA64F /* 知识管理-PKM(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "知识管理-PKM(ap).md"; sourceTree = "<group>"; };
736+
0891EACC2CF1EAC000597974 /* SettingSidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingSidebarView.swift; sourceTree = "<group>"; };
735737
08A7FF302BEB02EA00E12E5A /* GithubAccessTokenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GithubAccessTokenView.swift; sourceTree = "<group>"; };
736738
08A9E1A12BC25D0700A73764 /* ViewComponentMarkdown.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewComponentMarkdown.swift; sourceTree = "<group>"; };
737739
08AEAEF0277F09D000B969E2 /* IntroView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntroView.swift; sourceTree = "<group>"; };
@@ -2260,6 +2262,7 @@
22602262
children = (
22612263
08ED801B2B9D1EEC0069B7EC /* SettingView.swift */,
22622264
08A7FF302BEB02EA00E12E5A /* GithubAccessTokenView.swift */,
2265+
0891EACC2CF1EAC000597974 /* SettingSidebarView.swift */,
22632266
);
22642267
path = Setting;
22652268
sourceTree = "<group>";
@@ -2968,6 +2971,7 @@
29682971
files = (
29692972
3A05B7C92CE57A5C00B2B30F /* TaskCaseLoadFile.swift in Sources */,
29702973
0871C61B2BA04D23000B620D /* CategoryRowView.swift in Sources */,
2974+
0891EACD2CF1EAC000597974 /* SettingSidebarView.swift in Sources */,
29712975
08F14B442BBE2865005B46CC /* ViewComponentImage.swift in Sources */,
29722976
08069CAB2BDE01E800D48E24 /* GuideListView.swift in Sources */,
29732977
084417792B99BE720049297D /* DataLink.swift in Sources */,

SwiftPamphletApp/HomeUI/DataLink.swift

+19
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ struct DataLink: Identifiable {
2828
selectDevBindable: DeveloperModel?,
2929
selectGuideItem: Binding<L?>,
3030
selectGuideItemBindable: L?,
31+
selectItem: Binding<String?>,
32+
selectItemBindable: String?,
3133
limit: Binding<Int>,
3234
trigger: Binding<Bool>,
3335
type: ShowType
@@ -140,6 +142,20 @@ struct DataLink: Identifiable {
140142
)
141143
}
142144
}
145+
case "设置":
146+
switch type {
147+
case .content:
148+
SettingSidebarView(selectedItem: selectItem)
149+
case .detail:
150+
switch selectItemBindable {
151+
case "Github Token 设置":
152+
GithubAccessTokenView()
153+
case "自定义标签":
154+
CustomSearch()
155+
default:
156+
IntroView()
157+
}
158+
}
143159
default:
144160
switch type {
145161
case .content:
@@ -165,6 +181,9 @@ extension DataLink {
165181
DataLink(title: "未分类", imageName: "p6"),
166182
DataLink(title: "收藏", imageName: "p11"),
167183
DataLink(title: "归档", imageName: "p3")
184+
]),
185+
DataLink(title: "工具", imageName: "", children: [
186+
DataLink(title: "设置", imageName: "p27")
168187
])
169188
]
170189
static func dataLinksWithGithub() -> [DataLink] {

SwiftPamphletApp/HomeUI/HomeView.swift

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct HomeView: View {
2020
@State private var selectedGuideItem: L? = nil // 改为 L? 类型
2121
@State private var limit: Int = 50 // 为 GuideDetailView 添加
2222
@State private var trigger: Bool = false // 为 GuideDetailView 添加
23+
@State private var selectedItem: String? = nil
2324

2425
var body: some View {
2526
#if os(macOS)
@@ -38,6 +39,8 @@ struct HomeView: View {
3839
selectDevBindable: selectDev,
3940
selectGuideItem: $selectedGuideItem,
4041
selectGuideItemBindable: selectedGuideItem,
42+
selectItem: $selectedItem,
43+
selectItemBindable: selectedItem,
4144
limit: $limit,
4245
trigger: $trigger,
4346
type: .content
@@ -60,6 +63,8 @@ struct HomeView: View {
6063
selectDevBindable: selectDev,
6164
selectGuideItem: $selectedGuideItem,
6265
selectGuideItemBindable: selectedGuideItem,
66+
selectItem: $selectedItem,
67+
selectItemBindable: selectedItem,
6368
limit: $limit,
6469
trigger: $trigger,
6570
type: .detail

SwiftPamphletApp/Setting/GithubAccessTokenView.swift

+15-8
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,24 @@ import SwiftUI
99
import SMGitHub
1010

1111
struct GithubAccessTokenView: View {
12+
@AppStorage(SPC.isShowGithub) var isShowGithub = false
1213
@State private var tokenString: String = ""
1314
var body: some View {
14-
Form {
15-
Section {
16-
Text("在这里写上 Github 的 access token 来访问内容")
17-
TextField("", text: $tokenString, prompt: Text("输入 access token"))
18-
.padding(10)
19-
.onSubmit {
20-
save()
21-
}
15+
VStack(alignment: .leading) {
16+
Toggle("是否显示 Github", isOn: $isShowGithub)
17+
.toggleStyle(.switch)
18+
.padding(20)
19+
Form {
20+
Section {
21+
Text("在这里写上 Github 的 access token 来访问内容")
22+
TextField("", text: $tokenString, prompt: Text("输入 access token"))
23+
.padding(10)
24+
.onSubmit {
25+
save()
26+
}
27+
}
2228
}
29+
Spacer()
2330
}
2431
.onAppear(perform: {
2532
let ud = UserDefaults.standard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// SettingSidebarView.swift
3+
// SwiftPamphletApp
4+
//
5+
// Created by Ming Dai on 2024/11/23.
6+
//
7+
8+
import SwiftUI
9+
10+
struct SettingSidebarView: View {
11+
@Binding var selectedItem: String?
12+
var body: some View {
13+
List(selection: $selectedItem) {
14+
item(title: "Github Token 设置", icon: "gearshape")
15+
.tag("Github Token 设置")
16+
item(title: "自定义标签", icon: "tag")
17+
.tag("自定义标签")
18+
}
19+
}
20+
21+
@ViewBuilder func item(title:String, icon:String) -> some View {
22+
Label(title, systemImage: icon)
23+
}
24+
}
25+

SwiftPamphletApp/Setting/SettingView.swift

+7-22
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,24 @@ struct SettingView: View {
1111

1212
var body: some View {
1313
TabView {
14-
accessTokenView()
14+
GithubAccessTokenView()
1515
.tabItem {
1616
Label("设置", systemImage: "gearshape")
1717
}
18-
customSearch()
18+
CustomSearch()
1919
.tabItem {
2020
Label("自定义标签", systemImage: "mail.and.text.magnifyingglass")
2121
}
2222

2323
}
2424
.frame(minHeight: 400)
2525
}
26-
27-
// MARK: custom search
26+
27+
}
28+
29+
struct CustomSearch: View {
2830
@AppStorage(SPC.customSearchTerm) var term = ""
29-
@ViewBuilder
30-
func customSearch() -> some View {
31+
var body: some View {
3132
VStack {
3233
Text("输入自定义的标签,以换行作为间隔")
3334
TextEditor(text: $term)
@@ -41,20 +42,4 @@ struct SettingView: View {
4142
}
4243
.padding(20)
4344
}
44-
45-
// MARK: 是否显示 Github 内容
46-
@AppStorage(SPC.isShowGithub) var isShowGithub = false
47-
48-
// MARK: token
49-
@State private var tokenString = ""
50-
@ViewBuilder
51-
func accessTokenView() -> some View {
52-
VStack(alignment: .leading) {
53-
Toggle("是否显示 Github", isOn: $isShowGithub)
54-
.toggleStyle(.switch)
55-
.padding(20)
56-
GithubAccessTokenView()
57-
Spacer()
58-
}
59-
}
6045
}

0 commit comments

Comments
 (0)