From 40c5796289f7e2fa6193fbde29805969cd15d4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E9=93=AD?= Date: Wed, 13 Mar 2024 01:28:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftPamphletApp/HomeUI/DataLink.swift | 2 +- .../InfoOrganizer/Info/EditInfoView.swift | 26 +++++--- .../InfoOrganizer/Info/InfoListView.swift | 61 +++++++++++-------- .../Info/InfosFilterWithCateView.swift | 7 ++- .../InfoOrganizer/Info/InfosView.swift | 6 +- .../InfoOrganizer/Model/InfoDataModel.swift | 5 ++ 6 files changed, 67 insertions(+), 40 deletions(-) diff --git a/SwiftPamphletApp/HomeUI/DataLink.swift b/SwiftPamphletApp/HomeUI/DataLink.swift index e9c19e36b..3849e64d6 100644 --- a/SwiftPamphletApp/HomeUI/DataLink.swift +++ b/SwiftPamphletApp/HomeUI/DataLink.swift @@ -49,7 +49,7 @@ struct DataLink: Identifiable { extension DataLink { static var dataLinks = [ - DataLink(title: "动态", imageName: "", children: [ + DataLink(title: "资料", imageName: "", children: [ DataLink(title: "资料整理", imageName: "p11") ]), // DataLink(title: "Github", imageName: "", children: [ diff --git a/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift b/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift index 90d1285cc..b5570e78c 100644 --- a/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift +++ b/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift @@ -8,19 +8,18 @@ import SwiftUI import SwiftData import SwiftSoup -import CodeEditor struct EditInfoView: View { @Environment(\.modelContext) var modelContext @Bindable var info: IOInfo - @Query(sort: [ - SortDescriptor(\IOCategory.updateDate, order: .reverse) - ]) var categories: [IOCategory] + @Query(IOCategory.all) var categories: [IOCategory] @State var isShowInspector = false @State var cate:IOCategory? = nil + @State var urlContent = "" + var body: some View { VStack { Form { @@ -36,8 +35,13 @@ struct EditInfoView: View { Button { gotoWebBrowser(urlStr: info.url) } label: { - Label("浏览器打开", systemImage: "safari") - } // end Button + Image(systemName: "safari") + } + Button { + info.des = urlContent + } label: { + Image(systemName: "square.and.arrow.down") + } } } @@ -63,11 +67,16 @@ struct EditInfoView: View { } Section("备注") { - TextEditor(text: $info.des) + TabView { + TextEditor(text: $info.des) + .tabItem { Label("文本", systemImage: "circle") } + WebUIView(html: info.des) + .tabItem { Label("预览", systemImage: "circle") } + } } } .navigationTitle("编辑资料") - .padding(30) + .padding(10) .inspector(isPresented: $isShowInspector) { EditCategoryView(cate: cate ?? IOCategory(name: "unavailable.com", createDate: Date.now, updateDate: Date.now)) } @@ -110,6 +119,7 @@ struct EditInfoView: View { title = soupTitle ?? "没找到标题" } info.name = title + urlContent = homepageHTML } } diff --git a/SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift b/SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift index 339ad9b2f..95d785f17 100644 --- a/SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift +++ b/SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift @@ -22,44 +22,51 @@ struct InfoListView: View { InfosView(searchString: searchText, selectInfo: $selectInfo, sortOrder: sortOrder) .navigationTitle("资料列表") .toolbar { - Menu("Sort", systemImage: "arrow.up.arrow.down") { - Picker("分类", selection: $filterCate) { - ForEach(cates) { cate in - Text(cate.name) - .tag(cate.name) + ToolbarItem(placement: .navigation) { + Button("添加资料", systemImage: "plus", action: addInfo) + } + ToolbarItem(placement: .navigation) { + Menu("Sort", systemImage: "tag") { + Picker("分类", selection: $filterCate) { + ForEach(cates) { cate in + Text(cate.name) + .tag(cate.name) + } + } + Picker("排序", selection: $sortOrder) { + Text("正序") + .tag([SortDescriptor(\IOInfo.updateDate)]) + Text("倒序") + .tag([SortDescriptor(\IOInfo.updateDate, order: .reverse)]) } - } - Picker("排序", selection: $sortOrder) { - Text("正序") - .tag([SortDescriptor(\IOInfo.updateDate)]) - Text("倒序") - .tag([SortDescriptor(\IOInfo.updateDate, order: .reverse)]) } } - Button("添加资料", systemImage: "plus", action: addInfo) - } .searchable(text: $searchText) } else { InfosFilterWithCateView(filterCateName: filterCate, selectInfo: $selectInfo, sortOrder: sortOrder) - .navigationTitle("资料列表") + .navigationTitle("分类 - \(filterCate)") .toolbar { - Menu("Sort", systemImage: "arrow.up.arrow.down") { - Picker("分类", selection: $filterCate) { - ForEach(cates) { cate in - Text(cate.name) - .tag(cate.name) + ToolbarItem(placement: .navigation) { + Button("添加资料", systemImage: "plus", action: addInfoWithCate) + } + ToolbarItem(placement: .navigation) { + Menu("Sort", systemImage: "tag") { + Picker("分类", selection: $filterCate) { + ForEach(cates) { cate in + Text(cate.name) + .tag(cate.name) + } } + Picker("排序", selection: $sortOrder) { + Text("正序") + .tag([SortDescriptor(\IOInfo.updateDate)]) + Text("倒序") + .tag([SortDescriptor(\IOInfo.updateDate, order: .reverse)]) + } + } - Picker("排序", selection: $sortOrder) { - Text("正序") - .tag([SortDescriptor(\IOInfo.updateDate)]) - Text("倒序") - .tag([SortDescriptor(\IOInfo.updateDate, order: .reverse)]) - } - } - Button("添加资料", systemImage: "plus", action: addInfoWithCate) } } diff --git a/SwiftPamphletApp/InfoOrganizer/Info/InfosFilterWithCateView.swift b/SwiftPamphletApp/InfoOrganizer/Info/InfosFilterWithCateView.swift index 3462bc898..0320006ac 100644 --- a/SwiftPamphletApp/InfoOrganizer/Info/InfosFilterWithCateView.swift +++ b/SwiftPamphletApp/InfoOrganizer/Info/InfosFilterWithCateView.swift @@ -14,13 +14,16 @@ struct InfosFilterWithCateView: View { @Binding var selectInfo: IOInfo? init(filterCateName: String = "", selectInfo: Binding, sortOrder: [SortDescriptor] = []) { - _infos = Query(filter: #Predicate { info in + + var fd = FetchDescriptor(predicate: #Predicate { info in if filterCateName.isEmpty { true } else { info.category?.name == filterCateName } - }, sort: sortOrder) + }, sortBy: sortOrder) + fd.fetchLimit = 1000 + _infos = Query(fd) self._selectInfo = selectInfo } diff --git a/SwiftPamphletApp/InfoOrganizer/Info/InfosView.swift b/SwiftPamphletApp/InfoOrganizer/Info/InfosView.swift index b47d68e3f..f747ac738 100644 --- a/SwiftPamphletApp/InfoOrganizer/Info/InfosView.swift +++ b/SwiftPamphletApp/InfoOrganizer/Info/InfosView.swift @@ -14,7 +14,7 @@ struct InfosView: View { @Binding var selectInfo: IOInfo? init(searchString: String = "", selectInfo: Binding, sortOrder: [SortDescriptor] = []) { - _infos = Query(filter: #Predicate { info in + var fd = FetchDescriptor(predicate: #Predicate { info in if searchString.isEmpty { true } else { @@ -22,7 +22,9 @@ struct InfosView: View { || info.url.localizedStandardContains(searchString) || info.des.localizedStandardContains(searchString) } - }, sort: sortOrder) + }, sortBy: sortOrder) + fd.fetchLimit = 1000 + _infos = Query(fd) self._selectInfo = selectInfo } diff --git a/SwiftPamphletApp/InfoOrganizer/Model/InfoDataModel.swift b/SwiftPamphletApp/InfoOrganizer/Model/InfoDataModel.swift index fa2cd9c40..59674edee 100644 --- a/SwiftPamphletApp/InfoOrganizer/Model/InfoDataModel.swift +++ b/SwiftPamphletApp/InfoOrganizer/Model/InfoDataModel.swift @@ -57,6 +57,11 @@ class IOCategory { self.updateDate = updateDate } + static var all: FetchDescriptor { + var fd = FetchDescriptor(sortBy: [SortDescriptor(\IOCategory.updateDate, order: .reverse)]) + return fd + } + static func delete(_ cate: IOCategory) { if let context = cate.modelContext { context.delete(cate)