Skip to content

Commit 4c7ef70

Browse files
committed
支持web预览
1 parent 43e7a97 commit 4c7ef70

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift

+17-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct EditInfoView: View {
2121
@State var cate:IOCategory? = nil
2222

2323
@State var urlContent = ""
24+
@State var selectedTab = 1
2425

2526
var body: some View {
2627
VStack {
@@ -102,13 +103,27 @@ struct EditInfoView: View {
102103
}
103104
}
104105

105-
Section(footer: Text("支持 markdown 格式的文本")) {
106+
Section(footer: Text("文本支持 markdown 格式")) {
106107
// TODO: markdown 获取图片链接,并能显示
107-
TabView {
108+
TabView(selection: $selectedTab) {
108109
TextEditor(text: $info.des)
109110
.tabItem { Label("文本", systemImage: "circle") }
111+
.tag(1)
110112
WebUIView(html: wrapperHtmlContent(content: MarkdownParser().html(from: info.des)), baseURLStr: "")
111113
.tabItem { Label("预览", systemImage: "circle") }
114+
.tag(2)
115+
if !info.url.isEmpty {
116+
WebUIView(urlStr: info.url)
117+
.tabItem { Label("网页", systemImage: "circle") }
118+
.tag(3)
119+
}
120+
}
121+
.onChange(of: info.url) { oldValue, newValue in
122+
if newValue.isEmpty {
123+
selectedTab = 0
124+
} else {
125+
selectedTab = 3
126+
}
112127
}
113128
}
114129
} // end form

SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct InfoListView: View {
1616

1717
@Query(IOCategory.allOrderByName) var cates: [IOCategory]
1818
@State private var filterCate = ""
19-
@State var limit: Int = 100
19+
@State var limit: Int = 300
2020
@State var filterStar: Bool = false
2121

2222
var body: some View {
@@ -33,7 +33,7 @@ struct InfoListView: View {
3333
Text("全部")
3434
}
3535
.tag("")
36-
36+
Divider()
3737
ForEach(cates) { cate in
3838
HStack {
3939
if cate.pin == 1 {

SwiftPamphletApp/InfoOrganizer/Info/InfoRowView.swift

+18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import SwiftUI
1010
struct InfoRowView: View {
1111
@State var info: IOInfo
1212
let selectedInfo: IOInfo?
13+
@State private var showAlert = false
1314

1415
var infoColor: Color {
1516
selectedInfo == info ? Color.white : Color.accentColor
@@ -25,23 +26,40 @@ struct InfoRowView: View {
2526
Text(info.category?.name ?? "")
2627
}
2728
Spacer()
29+
2830
}
2931
.foregroundColor(light: .secondary, dark: .secondary)
3032
Text(info.name)
33+
HStack {
34+
Text(dateString(date: info.updateDate))
35+
.font(.footnote)
36+
Spacer()
37+
}
38+
.foregroundColor(light: .secondary, dark: .secondary)
3139
}
3240
.swipeActions {
3341
Button(role: .destructive) {
3442
IOInfo.delete(info)
3543
} label: {
3644
Label("删除", systemImage: "trash")
3745
}
46+
3847
}
3948
.contextMenu {
4049
Button("删除") {
4150
IOInfo.delete(info)
4251
}
4352
}
4453
}
54+
55+
func dateString(date: Date) -> String {
56+
var re = ""
57+
if date.year != Date.now.year {
58+
re += date.year.description + "."
59+
}
60+
re += date.month.description + "." + date.day.description
61+
return re
62+
}
4563
}
4664

4765

SwiftPamphletApp/InfoOrganizer/Info/InfosView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct InfosView: View {
4545
.onAppear {
4646
if info == infos.last {
4747
if limit <= infos.count {
48-
limit += 100
48+
limit += 300
4949
}
5050
}
5151
}

0 commit comments

Comments
 (0)