Skip to content

Commit

Permalink
分类和自定义搜索优化
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed Apr 10, 2024
1 parent 3505b76 commit e869c0d
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 16 deletions.
4 changes: 4 additions & 0 deletions SwiftPamphletApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -272,6 +273,7 @@
08026C422869B22E00792EF1 /* 176.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = 176.md; sourceTree = "<group>"; };
08026C502869B41B00792EF1 /* 190.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 190.md; sourceTree = "<group>"; };
0805F4952BAAABEA0008BB52 /* ViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewStyle.swift; sourceTree = "<group>"; };
0825E4862BC6596F00332378 /* EditCustomSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditCustomSearchView.swift; sourceTree = "<group>"; };
083554E02756503B0095E0EE /* AnimateLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimateLayout.swift; sourceTree = "<group>"; };
08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoDataModel.swift; sourceTree = "<group>"; };
08397E242B9EEE1300DFDD02 /* InfoListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoListView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1265,6 +1267,7 @@
08397E2E2B9F353B00DFDD02 /* CategoryListView.swift */,
0871C61A2BA04D23000B620D /* CategoryRowView.swift */,
08397E2C2B9F10AD00DFDD02 /* EditCategoryView.swift */,
0825E4862BC6596F00332378 /* EditCustomSearchView.swift */,
);
path = Category;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
23 changes: 17 additions & 6 deletions SwiftPamphletApp/InfoOrganizer/Category/EditCategoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
}


27 changes: 27 additions & 0 deletions SwiftPamphletApp/InfoOrganizer/Category/EditCustomSearchView.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
40 changes: 31 additions & 9 deletions SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 切换
Expand Down Expand Up @@ -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") {
Expand All @@ -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: 图集处理
Expand Down
24 changes: 23 additions & 1 deletion SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct InfoListView: View {
Text("自定检索")
.tag("")
ForEach(searchTerms, id: \.self) { term in
Text(term)
Text(customSearchLabel(term))
.tag(term)
}
}
Expand All @@ -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() {
Expand Down

0 comments on commit e869c0d

Please sign in to comment.