Skip to content

Commit

Permalink
开发手册和资料的关联
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed May 1, 2024
1 parent e8d448c commit 7ba9efb
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 14 deletions.
1 change: 1 addition & 0 deletions SwiftPamphletApp/App/SwiftPamphletAppConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct SPC {
static let isFirstRun = "isFirstRun"
static let customSearchTerm = "customSearchTerm"
static let isShowInspector = "isShowInspector"
static let isShowPamphletInspector = "isShowPamphletInspector"
static let inspectorType = "inspectorType"

// static func loadCustomIssues(jsonFileName: String) -> [CustomIssuesModel] {
Expand Down
7 changes: 7 additions & 0 deletions SwiftPamphletApp/Core/FundationFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import SwiftUI
import Combine
import Network

// MARK: - 时间

func nowDateString() -> String {
let locale = Locale(identifier: "zh_Hans")
return Date.now.formatted(.dateTime.locale(locale))
}

// MARK: - Web
func wrapperHtmlContent(content: String, codeStyle: String = "lioshi.min") -> String {
let reStr = """
Expand Down
76 changes: 70 additions & 6 deletions SwiftPamphletApp/Guide/GuideDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,81 @@
import SwiftUI
import Ink
import SMFile
import SwiftData
import InfoOrganizer

struct GuideDetailView: View {
@Environment(\.modelContext) var modelContext
@State private var isShowInspector = false
@AppStorage(SPC.isShowPamphletInspector) var asIsShowPamphletInspector: Bool = false
var t: String
@State var selectInfo: IOInfo? = nil
@Query var infos: [IOInfo]
@Binding var limit: Int

init(t:String,limit: Binding<Int>) {
self.t = t
var fd = FetchDescriptor<IOInfo>(predicate: #Predicate { info in
info.relateName == t && info.isArchived == false
}, sortBy: [SortDescriptor(\IOInfo.updateDate, order: .reverse)])
fd.fetchLimit = limit.wrappedValue
_infos = Query(fd)
self._limit = limit
}

var body: some View {
HStack {
Spacer()
Text(t).font(.title)
Spacer()
VStack {
if selectInfo == nil {
HStack {
Spacer()
Text(t).font(.title)
Spacer()
Button("相关资料管理") {
isShowInspector.toggle()
}
}
.padding(EdgeInsets(top: 10, leading: 10, bottom: 2, trailing: 10))
WebUIView(html: wrapperHtmlContent(content: MarkdownParser().html(from: "\(SMFile.loadBundleString("\(t)" + ".md"))")), baseURLStr: "")
} else {
if let info = selectInfo {
EditInfoView(info: info)
} else {
EmptyView()
}
}
}
.inspector(isPresented: $isShowInspector) {
Button("添加资料") {
let info = IOInfo(name: "新增\(t)资料 - \(nowDateString())", url: "", des: "", relateName: t)
modelContext.insert(info)
selectInfo = info
}
.padding(5)
List(selection: $selectInfo) {
ForEach(infos) { info in
InfoRowView(info: info, selectedInfo: selectInfo)
.tag(info)
.onAppear {
if info == infos.last {
if limit <= infos.count {
limit += 50
}
}
}
}
}
}
.onAppear {
isShowInspector = asIsShowPamphletInspector
}
.onChange(of: t) { oldValue, newValue in
selectInfo = nil
}
.onChange(of: isShowInspector) { oldValue, newValue in
asIsShowPamphletInspector = newValue
}
.padding(EdgeInsets(top: 10, leading: 10, bottom: 2, trailing: 10))
WebUIView(html: wrapperHtmlContent(content: MarkdownParser().html(from: "\(SMFile.loadBundleString("\(t)" + ".md"))")), baseURLStr: "")
}


}

6 changes: 2 additions & 4 deletions SwiftPamphletApp/Guide/GuideListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import SwiftUI

struct GuideListView: View {
@State private var listModel = GuideListModel()
@State private var limit: Int = 50
var body: some View {
SPOutlineListView(d: listModel.filtered(), c: \.sub) { i in
NavigationLink(destination: GuideDetailView(t: i.t)) {
NavigationLink(destination: GuideDetailView(t: i.t, limit: $limit)) {
HStack {
Text(i.t)
Spacer()
Expand All @@ -32,9 +33,6 @@ final class GuideListModel {

func filtered() -> [L] {
guard !searchText.isEmpty else { return lModel }
// let flatModel = lModel.flatMap({ model in
// model
// })
let flatModel = flatLModel(lModel)
return flatModel.filter { model in
model.t.lowercased().contains(searchText.lowercased())
Expand Down
4 changes: 0 additions & 4 deletions SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ struct InfoListView: View {
modelContext.insert(info)
selectInfo = info
}
func nowDateString() -> String {
let locale = Locale(identifier: "zh_Hans")
return Date.now.formatted(.dateTime.locale(locale))
}

}

Expand Down

0 comments on commit 7ba9efb

Please sign in to comment.