Skip to content

Commit

Permalink
完善书签,完善图集选择
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed May 10, 2024
1 parent 0bc6935 commit 228bb1d
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 34 deletions.
6 changes: 6 additions & 0 deletions SwiftPamphletApp/Guide/Bookmark/Data/BookmarkModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ final class BookmarkModel {
context.delete(bm)
}
}

static func delBM(_ bm: BookmarkModel) {
if let context = bm.modelContext {
context.delete(bm)
}
}
}

@Model
Expand Down
20 changes: 15 additions & 5 deletions SwiftPamphletApp/Guide/Bookmark/View/BookmarkListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ struct BookmarkListView: View {
List {
ForEach(bms) { bm in
NavigationLink(destination: GuideDetailView(t: bm.name, plName: bm.pamphletName, limit: $limit, trigger: $trigger)) {
Text(bm.name)
Spacer()
Image(systemName: "bookmark")
.foregroundStyle(.secondary)
.font(.footnote)
HStack {
Text(bm.name)
Spacer()
Image(systemName: "bookmark")
.foregroundStyle(.secondary)
.font(.footnote)
}
}
.contextMenu {
Button("前移") {
bm.updateDate = Date.now
}
Button("删除") {
BookmarkModel.delBM(bm)
}
}
}
}
Expand Down
46 changes: 27 additions & 19 deletions SwiftPamphletApp/Guide/View/GuideListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ struct GuideListView: View {
var body: some View {
SPOutlineListView(d: listModel.filtered(), c: \.sub) { i in
NavigationLink(destination: GuideDetailView(t: i.t, plName: "ap", limit: $limit, trigger: $trigger)) {
HStack {
HStack(spacing:3) {
if i.icon.isEmpty == false {
Image(systemName: i.icon)
.foregroundStyle(i.sub == nil ? Color.secondary : .indigo)
} else if let sub = i.sub {
Image(systemName: "folder.fill")
.foregroundStyle(.gray)
}
Text(listModel.searchText.isEmpty == true ? GuideListModel.simpleTitle(i.t) : i.t)
Spacer()
if apBookmarks.contains(i.t) {
Expand Down Expand Up @@ -85,7 +92,7 @@ final class GuideListModel {
}

var lModel = [
L(t: "Swift语法", sub: [
L(t: "Swift语法", icon: "swift", sub: [
L(t: "语法基础", sub: [
L(t: "变量"),
L(t: "打印"),
Expand All @@ -96,7 +103,7 @@ final class GuideListModel {
L(t: "访问控制"),
L(t: "Regex")
]),
L(t: "基础类型",sub: [
L(t: "基础类型", sub: [
L(t: "数字"),
L(t: "布尔数"),
L(t: "字符串"),
Expand Down Expand Up @@ -147,7 +154,7 @@ final class GuideListModel {
L(t: "Swift规范"),
L(t: "Swift书单")
]),
L(t: "基础库", sub: [
L(t: "基础库", icon: "globe.asia.australia.fill", sub: [
L(t: "系统及设备", sub: [
L(t: "系统判断"),
L(t: "版本兼容"),
Expand All @@ -173,7 +180,7 @@ final class GuideListModel {
L(t: "随机"),
L(t: "UserDefaults")
]),
L(t: "SwiftUI",sub: [
L(t: "SwiftUI",icon: "heart.text.square.fill",sub: [
L(t: "介绍",sub: [
L(t: "SwiftUI是什么"),
L(t: "SwiftUI参考资料"),
Expand Down Expand Up @@ -226,7 +233,7 @@ final class GuideListModel {
]),
L(t: "SwiftUI数据流")
]),
L(t: "SwiftData",sub: [
L(t: "SwiftData", icon: "swiftdata", sub: [
L(t: "创建@Model模型"),
L(t: "SwiftData-模型关系"),
L(t: "容器配置modelContainer"),
Expand All @@ -238,17 +245,17 @@ final class GuideListModel {
L(t: "SwiftData-调试"),
L(t: "SwiftData-资料")
]),
L(t: "Widget小部件", sub: [
L(t: "Widget小部件", icon: "window.shade.open", sub: [
L(t: "Widget访问SwiftData")
]),
L(t: "系统能力",sub: [
L(t: "Swift-DocC")
L(t: "系统能力",icon: "apple.terminal",sub: [
L(t: "Swift-DocC", icon: "doc.append")
]),
L(t: "工程模式", sub: [
L(t: "工程模式",icon: "building.columns", sub: [
L(t: "单例"),
L(t: "程序入口点")
L(t: "程序入口点", icon: "door.right.hand.open")
]),
L(t: "多线程", sub: [
L(t: "多线程", icon: "text.line.first.and.arrowtriangle.forward", sub: [
L(t: "Swift Concurrency",sub: [
L(t: "Swift Concurrency是什么"),
L(t: "async await"),
Expand Down Expand Up @@ -289,37 +296,38 @@ final class GuideListModel {
])
]),
]),
L(t: "动画", sub: [
L(t: "布局动画")
L(t: "动画", icon: "moonphase.waning.gibbous.inverse", sub: [
L(t: "布局动画", icon: "squareshape.split.2x2.dotted")
]),
L(t: "网络",sub: [
L(t: "网络", icon:"point.3.connected.trianglepath.dotted", sub: [
L(t: "网络状态检查")
]),
L(t: "性能和构建", sub: [
L(t: "性能和构建",icon: "battery.100percent.bolt", sub: [
L(t: "性能技术演进"),
L(t: "内存管理"),
L(t: "调试"),
L(t: "链接器")
]),
L(t: "安全",sub: [
L(t: "安全", icon: "cross.case", sub: [
L(t: "Keychain")
]),
L(t: "macOS", sub: [
L(t: "macOS", icon: "macstudio", sub: [
L(t: "macOS技术演进"),
L(t: "macOS范例"),
L(t: "三栏结构"),
L(t: "全屏模式"),
L(t: "macOS共享菜单"),
L(t: "macOS剪贴板")
]),
L(t: "三方库使用",sub: [
L(t: "三方库使用", icon:"tray.2", sub: [
L(t: "SQLite.swift的使用")
])
]

struct L: Hashable, Identifiable {
var id = UUID()
var t: String
var icon: String = ""
var sub: [L]?
}

Expand Down
4 changes: 2 additions & 2 deletions SwiftPamphletApp/HomeUI/DataLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ struct DataLink: Identifiable {
extension DataLink {
static var dataLinks = [
DataLink(title: "开发手册", imageName: "", children: [
DataLink(title: "Apple技术", imageName: "p22"),
DataLink(title: "书签", imageName: "p24")
DataLink(title: "书签", imageName: "p24"),
DataLink(title: "Apple技术", imageName: "p22")
]),
DataLink(title: "资料整理", imageName: "", children: [
DataLink(title: "全部资料", imageName: "p7"),
Expand Down
6 changes: 6 additions & 0 deletions SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ struct EditInfoView: View {
tabSwitch()
isStopLoadingWeb = false
}
.onChange(of: info, { oldValue, newValue in
tabSwitch()
})
.onAppear {
tabSwitch()
}
Expand Down Expand Up @@ -466,6 +469,9 @@ struct EditInfoView: View {
func tabSwitch() {
if info.url.isEmpty {
selectedTab = 1
if info.imgs?.count ?? 0 > 0 || info.imageUrls.count > 0 {
selectedTab = 5
}
} else {
selectedTab = 4
}
Expand Down
1 change: 0 additions & 1 deletion SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ struct InfoListView: View {
}
}


// MARK: 自定义搜索
@ViewBuilder
func customSearchView() -> some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@ Wdiget target 访问主应用 target 的 SwiftData 数据步骤如下:
- SwiftData 的模型同时在主应用和 Widget 的 target 中。
- StaticConfiguration 或 AppIntentConfiguration 中添加 `modelContainer()` 修饰符,让 SwiftData 的容器可用。

SwiftData 数据变化后,小组件能够及时更新的方法

```swift
WidgetCenter.shared.reloadAllTimelines()
```
2 changes: 0 additions & 2 deletions SwiftPamphletApp/ViewComponet/ViewComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ struct SPOutlineView<D, Content>: View where D: RandomAccessCollection, D.Elemen
SPDisclosureGroup(content: SPOutlineView(d: sub, c: c, content: content), label: content(i))
} else {
content(i)
// .foregroundStyle(.secondary)
} // end if
} // end ForEach
} // end body
Expand All @@ -59,7 +58,6 @@ struct SPDisclosureGroup<C, L>: View where C: View, L: View {
}
} label: {
label
// .foregroundStyle(.primary)
}
.buttonStyle(.plain)
}
Expand Down

0 comments on commit 228bb1d

Please sign in to comment.