From e869c0d76e3959379dc65dd2f6d9eabcc514b404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E9=93=AD?= Date: Wed, 10 Apr 2024 13:41:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=92=8C=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=90=9C=E7=B4=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftPamphletApp.xcodeproj/project.pbxproj | 4 ++ .../Category/EditCategoryView.swift | 23 ++++++++--- .../Category/EditCustomSearchView.swift | 27 +++++++++++++ .../InfoOrganizer/Info/EditInfoView.swift | 40 ++++++++++++++----- .../InfoOrganizer/Info/InfoListView.swift | 24 ++++++++++- 5 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 SwiftPamphletApp/InfoOrganizer/Category/EditCustomSearchView.swift diff --git a/SwiftPamphletApp.xcodeproj/project.pbxproj b/SwiftPamphletApp.xcodeproj/project.pbxproj index 24f42c641..4fab93a5d 100644 --- a/SwiftPamphletApp.xcodeproj/project.pbxproj +++ b/SwiftPamphletApp.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ 08026C522869B43D00792EF1 /* 191.md in Resources */ = {isa = PBXBuildFile; fileRef = 08026C3E2869AD7800792EF1 /* 191.md */; }; 08026C532869B44400792EF1 /* 192.md in Resources */ = {isa = PBXBuildFile; fileRef = 08026C3F2869B00D00792EF1 /* 192.md */; }; 0805F4962BAAABEA0008BB52 /* ViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0805F4952BAAABEA0008BB52 /* ViewStyle.swift */; }; + 0825E4872BC6596F00332378 /* EditCustomSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0825E4862BC6596F00332378 /* EditCustomSearchView.swift */; }; 083554E12756503B0095E0EE /* AnimateLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 083554E02756503B0095E0EE /* AnimateLayout.swift */; }; 08397E232B9EE8F400DFDD02 /* InfoDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */; }; 08397E252B9EEE1300DFDD02 /* InfoListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E242B9EEE1300DFDD02 /* InfoListView.swift */; }; @@ -272,6 +273,7 @@ 08026C422869B22E00792EF1 /* 176.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = 176.md; sourceTree = ""; }; 08026C502869B41B00792EF1 /* 190.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 190.md; sourceTree = ""; }; 0805F4952BAAABEA0008BB52 /* ViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewStyle.swift; sourceTree = ""; }; + 0825E4862BC6596F00332378 /* EditCustomSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditCustomSearchView.swift; sourceTree = ""; }; 083554E02756503B0095E0EE /* AnimateLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimateLayout.swift; sourceTree = ""; }; 08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoDataModel.swift; sourceTree = ""; }; 08397E242B9EEE1300DFDD02 /* InfoListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoListView.swift; sourceTree = ""; }; @@ -1265,6 +1267,7 @@ 08397E2E2B9F353B00DFDD02 /* CategoryListView.swift */, 0871C61A2BA04D23000B620D /* CategoryRowView.swift */, 08397E2C2B9F10AD00DFDD02 /* EditCategoryView.swift */, + 0825E4862BC6596F00332378 /* EditCustomSearchView.swift */, ); path = Category; sourceTree = ""; @@ -1554,6 +1557,7 @@ 08F4BE6028609D8700733F12 /* PlayCharts.swift in Sources */, 08BE637227CC6F13002BC6A8 /* PlayScrollView.swift in Sources */, 08ED801C2B9D1EEC0069B7EC /* SettingView.swift in Sources */, + 0825E4872BC6596F00332378 /* EditCustomSearchView.swift in Sources */, 08CD61FE27758B8A008C0935 /* Lexer.swift in Sources */, 086A5F422744EDCE00FECE02 /* IssueVM.swift in Sources */, 08522BF027CF9FFA005FF059 /* PlayAnimation.swift in Sources */, diff --git a/SwiftPamphletApp/InfoOrganizer/Category/EditCategoryView.swift b/SwiftPamphletApp/InfoOrganizer/Category/EditCategoryView.swift index e65875366..379159b39 100644 --- a/SwiftPamphletApp/InfoOrganizer/Category/EditCategoryView.swift +++ b/SwiftPamphletApp/InfoOrganizer/Category/EditCategoryView.swift @@ -9,22 +9,33 @@ import SwiftUI import SwiftData struct EditCategoryView: View { - @Bindable var cate: IOCategory + @Environment(\.modelContext) var modelContext + @State var cate: String = "" var body: some View { VStack { - if cate.name != "unavailable.com" { - Form { - TextField("分类名", text: $cate.name) + HStack { + TextField("请填写新增的分类名", text: $cate) + .textFieldStyle(.roundedBorder) + .onSubmit { + add() + } + Button("添加") { + add() } - .navigationTitle("编辑分类") - .padding(30) } + .padding(5) CategoryListView() Spacer() } } + + func add() { + let cateModel = IOCategory(name: cate, pin: 0, createDate: Date.now, updateDate: Date.now) + modelContext.insert(cateModel) + cate = "" + } } diff --git a/SwiftPamphletApp/InfoOrganizer/Category/EditCustomSearchView.swift b/SwiftPamphletApp/InfoOrganizer/Category/EditCustomSearchView.swift new file mode 100644 index 000000000..d962b18ba --- /dev/null +++ b/SwiftPamphletApp/InfoOrganizer/Category/EditCustomSearchView.swift @@ -0,0 +1,27 @@ +// +// EditCustomSearch.swift +// SwiftPamphletApp +// +// Created by Ming Dai on 2024/4/10. +// + +import SwiftUI + +struct EditCustomSearchView: View { + @AppStorage("customSearchTerm") var term = "" + + var body: some View { + VStack { + Text("自定义的搜索关键字,以换行作为间隔") + TextEditor(text: $term) + .overlay { + Rectangle() + .stroke(.secondary, lineWidth: 1) + .opacity(0.5) + .disableAutocorrection(true) + + } + } + .padding(20) + } +} diff --git a/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift b/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift index 277ea549f..a459c7a52 100644 --- a/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift +++ b/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift @@ -17,9 +17,14 @@ struct EditInfoView: View { @Query(IOCategory.all) var categories: [IOCategory] + // Inspector @State var isShowInspector = false - @State var cate:IOCategory? = nil + enum InspectorType { + case category, customSearch + } + @State var inspectorType: InspectorType = .category + // Tab @State var selectedTab = 1 @State var isStopLoadingWeb = false @@ -113,8 +118,9 @@ struct EditInfoView: View { .onHover(perform: { hovering in info.category?.updateDate = Date.now }) - Button("添加分类", action: addCate) Button("管理分类", action: manageCate) + Button("管理自定检索", action: manageCustomSearch) + } } // MARK: Tab 切换 @@ -244,7 +250,13 @@ struct EditInfoView: View { } // end form .padding(10) .inspector(isPresented: $isShowInspector) { - EditCategoryView(cate: cate ?? IOCategory(name: "unavailable.com", pin: 0, createDate: Date.now, updateDate: Date.now)) + switch inspectorType { + case .category: + EditCategoryView() + case .customSearch: + EditCustomSearchView() + } + } .toolbar { Button("关闭", systemImage: "sidebar.right") { @@ -265,13 +277,23 @@ struct EditInfoView: View { selectedTab = 4 } } - func addCate() { - cate = IOCategory(name: "", pin: 0, createDate: Date.now, updateDate: Date.now) - modelContext.insert(cate!) - isShowInspector = true - } func manageCate() { - isShowInspector.toggle() + switch inspectorType { + case .category: + isShowInspector.toggle() + case .customSearch: + inspectorType = .category + isShowInspector = true + } + } + func manageCustomSearch() { + switch inspectorType { + case .category: + inspectorType = .customSearch + isShowInspector = true + case .customSearch: + isShowInspector.toggle() + } } // MARK: 图集处理 diff --git a/SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift b/SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift index ffb4b60b6..7b0532f0c 100644 --- a/SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift +++ b/SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift @@ -103,7 +103,7 @@ struct InfoListView: View { Text("自定检索") .tag("") ForEach(searchTerms, id: \.self) { term in - Text(term) + Text(customSearchLabel(term)) .tag(term) } } @@ -120,6 +120,28 @@ struct InfoListView: View { } } } + func customSearchLabel(_ string: String) -> String { + let strs = string.split(separator: "/") + if strs.count > 0 { + var reStr = "" + if strs.count == 1 { + if strs.first?.hasPrefix("《") == false { + reStr.append(" ") + } + } else { + for a in 1...(strs.count) { + reStr.append(" ") + } + } + if let last = strs.last { + reStr.append(String(last)) + } + + + return reStr + } + return string + } // MARK: 资料整理数据方面 func addInfo() {