From 3505b76ed73a02f95e50e567229fcfad28c12a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E9=93=AD?= Date: Wed, 10 Apr 2024 11:30:55 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A3=80?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../App/SwiftPamphletAppApp.swift | 11 --- .../GitHubAPI/Developer/EditDeveloper.swift | 2 +- SwiftPamphletApp/HomeUI/HomeView.swift | 6 ++ .../InfoOrganizer/Info/EditInfoView.swift | 16 +++-- .../InfoOrganizer/Info/InfoListView.swift | 40 ++++++++++- SwiftPamphletApp/Setting/SettingView.swift | 67 ++++++++++++++----- 6 files changed, 105 insertions(+), 37 deletions(-) diff --git a/SwiftPamphletApp/App/SwiftPamphletAppApp.swift b/SwiftPamphletApp/App/SwiftPamphletAppApp.swift index d4d98b205..e4d1b858d 100644 --- a/SwiftPamphletApp/App/SwiftPamphletAppApp.swift +++ b/SwiftPamphletApp/App/SwiftPamphletAppApp.swift @@ -25,17 +25,6 @@ struct SwiftPamphletAppApp: App { } } -struct Demo: View { - var body: some View { - Group { -// PlayCanvas() - } - .frame(minWidth:300, maxWidth: .infinity, minHeight: 550, maxHeight: .infinity) - .onAppear { - - } - } -} diff --git a/SwiftPamphletApp/GitHubAPI/Developer/EditDeveloper.swift b/SwiftPamphletApp/GitHubAPI/Developer/EditDeveloper.swift index 2f126eab6..a5cb97160 100644 --- a/SwiftPamphletApp/GitHubAPI/Developer/EditDeveloper.swift +++ b/SwiftPamphletApp/GitHubAPI/Developer/EditDeveloper.swift @@ -96,7 +96,7 @@ struct EditDeveloper: View { dev.updateDate = formatter.date(from: iso8601String) ?? Date.now } }) - .padding(EdgeInsets(top: 20, leading: 10, bottom: 0, trailing: 10)) + .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10)) .onAppear { Task { await repoVM.updateAllData() diff --git a/SwiftPamphletApp/HomeUI/HomeView.swift b/SwiftPamphletApp/HomeUI/HomeView.swift index 5d79ec54d..939538726 100644 --- a/SwiftPamphletApp/HomeUI/HomeView.swift +++ b/SwiftPamphletApp/HomeUI/HomeView.swift @@ -51,5 +51,11 @@ struct HomeView: View { IntroView() } } + .task { + #if DEBUG + let sandboxDirectory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first! + print(sandboxDirectory.debugDescription) + #endif + } } } diff --git a/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift b/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift index 44021b8e4..277ea549f 100644 --- a/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift +++ b/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift @@ -135,12 +135,16 @@ struct EditInfoView: View { .tabItem { Label("预览", systemImage: "circle") } .tag(2) if let url = URL(string: info.url) { - WebUIViewWithSave( - urlStr: url.absoluteString, - savingDataTrigger: $savingDataTrigger, - savingData: $info.webArchive, - isStop: $isStopLoadingWeb - ) + VStack { + WebUIViewWithSave( + urlStr: url.absoluteString, + savingDataTrigger: $savingDataTrigger, + savingData: $info.webArchive, + isStop: $isStopLoadingWeb + ) + TextField(text: $info.des, prompt: Text("输入文本进行记录"), axis: .vertical) {} + .padding(5) + } .tabItem { Label("网页", systemImage: "circle") } .tag(4) } diff --git a/SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift b/SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift index f9ebb7c07..ffb4b60b6 100644 --- a/SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift +++ b/SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift @@ -45,6 +45,11 @@ struct InfoListView: View { } } } + if searchTerms.isEmpty == false { + ToolbarItem(placement: .navigation) { + customSearchView() + } + } if filterCate.isEmpty { ToolbarItem(placement: .navigation) { Toggle(isOn: $filterStar) { @@ -82,10 +87,43 @@ struct InfoListView: View { } } .searchable(text: $searchText) + .onAppear { + parseSearchTerms() + } + .onChange(of: term) { oldValue, newValue in + parseSearchTerms() + } + } + + + // MARK: 自定义搜索 + @ViewBuilder + func customSearchView() -> some View { + Picker("自定检索", selection: $searchText) { + Text("自定检索") + .tag("") + ForEach(searchTerms, id: \.self) { term in + Text(term) + .tag(term) + } + } + } + + @AppStorage("customSearchTerm") var term = "" + @State private var searchTerms: [String] = [String]() + func parseSearchTerms() { + let terms = term.trimmingCharacters(in: .whitespacesAndNewlines).split(separator: "\n") + searchTerms = [String]() + for t in terms { + if t.isEmpty == false { + searchTerms.append(String(t)) + } + } } + // MARK: 资料整理数据方面 func addInfo() { - let info = IOInfo(name: "简单记录 - \(nowDateString())", url: "", coverImage: nil, imageUrls: [String](), imgs: [IOImg](), des: "\n", star: false, webArchive: nil , createDate: Date.now, updateDate: Date.now) + let info = IOInfo(name: "简单记录 - \(nowDateString())", url: "", coverImage: nil, imageUrls: [String](), imgs: [IOImg](), des: "", star: false, webArchive: nil , createDate: Date.now, updateDate: Date.now) for cate in cates { if cate.name == filterCate { info.category = cate diff --git a/SwiftPamphletApp/Setting/SettingView.swift b/SwiftPamphletApp/Setting/SettingView.swift index b58b2a250..ec44886bc 100644 --- a/SwiftPamphletApp/Setting/SettingView.swift +++ b/SwiftPamphletApp/Setting/SettingView.swift @@ -8,31 +8,62 @@ import SwiftUI struct SettingView: View { - @State private var tokenString = "" + var body: some View { TabView { - Form { - Section { - Text("在这里写上 Github 的 access token") - TextField("", text: $tokenString) - .padding(10) - .onSubmit { - save() - } - Button("保存") { + accessTokenView() + .tabItem { + Label("设置", systemImage: "gearshape") + } + customSearch() + .tabItem { + Label("自定义搜索", systemImage: "mail.and.text.magnifyingglass") + } + + } + .frame(minHeight: 400) + } + + // MARK: custom search + @AppStorage("customSearchTerm") var term = "" + @ViewBuilder + func customSearch() -> some View { + VStack { + Text("输入自定义的搜索关键字,以换行作为间隔") + TextEditor(text: $term) + .overlay { + Rectangle() + .stroke(.secondary, lineWidth: 1) + .opacity(0.5) + .disableAutocorrection(true) + + } + } + .padding(20) + } + + // MARK: token + @State private var tokenString = "" + @ViewBuilder + func accessTokenView() -> some View { + Form { + Section { + Text("在这里写上 Github 的 access token") + TextField("", text: $tokenString) + .padding(10) + .onSubmit { save() } + Button("保存") { + save() } - .onAppear(perform: { - let ud = UserDefaults.standard - tokenString = ud.string(forKey: SPC.githubUDTokenKey) ?? "" - }) - } - .padding(20) - .tabItem { - Label("设置", systemImage: "gearshape") } + .onAppear(perform: { + let ud = UserDefaults.standard + tokenString = ud.string(forKey: SPC.githubUDTokenKey) ?? "" + }) } + .padding(20) } func save() {