-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
999 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
WanAndroid_SwiftUI/Content/Project/view/ProjectBuilder.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// ProjectBuilderView.swift | ||
// WanAndroid_SwiftUI | ||
// | ||
// Created by zxc on 2023/6/17. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ProjectBuilder: View { | ||
|
||
@Binding var vm: ProjectViewModel | ||
|
||
var body: some View { | ||
|
||
VStack(alignment: .center){ | ||
|
||
ScrollView{ | ||
|
||
//1-导航栏 | ||
//pickView | ||
//文章 | ||
//articleView() | ||
|
||
} | ||
} | ||
} | ||
|
||
var pickView: some View{ | ||
ScrollView(.horizontal){ | ||
HStack(spacing: 0){ | ||
Picker("Options",selection: $vm.options.first ?? $vm.options_first){ | ||
|
||
ForEach(vm.options,id: \.self) { option in | ||
Text(option).onAppear(){ | ||
vm.getProjectTreeArticle(page: 1, cid: vm.optionsDic[option] ?? 0) | ||
} | ||
} | ||
|
||
} | ||
.pickerStyle(SegmentedPickerStyle()) | ||
.shadow(color: .white, radius: 100) | ||
.shadow(color: Color.brown.opacity(0.8), radius: 5, x: 0, y: 2) | ||
.padding() | ||
} | ||
} | ||
|
||
} | ||
|
||
var articleView: some View{ | ||
ScrollView{ | ||
ForEach(vm.options,id: \.self) { option in | ||
let articleList = vm.projectDictionArticleDataList[vm.optionsDic[option]!] | ||
if(articleList != nil){ | ||
ForEach(articleList!){ article in | ||
ArticleCellView(article: .constant(article)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
struct ProjectBuilderView_Previews: PreviewProvider { | ||
|
||
static var previews: some View { | ||
let vm: ProjectViewModel = ProjectViewModel() | ||
ProjectBuilder(vm: .constant(vm)) | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
WanAndroid_SwiftUI/Content/Project/viewmodel/ProjectViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// ProjectViewModel.swift | ||
// WanAndroid_SwiftUI | ||
// | ||
// Created by zxc on 2023/6/17. | ||
// | ||
|
||
import Foundation | ||
|
||
class ProjectViewModel:ObservableObject{ | ||
|
||
@Published var projectModel:ProjectModel? = nil | ||
@Published var projectSonModel:ProjectSonModel? = nil | ||
@Published var projectDictionArticleDataList:Dictionary<Int,[Article]> = [:] | ||
|
||
var optionsDic:Dictionary<String,Int> = [:] | ||
var options:[String] = [] | ||
var options_first: String = "" | ||
|
||
init(){ | ||
|
||
getProjectModel() | ||
|
||
} | ||
|
||
//体系数据 | ||
func getProjectModel(){ | ||
APIService.instance.getProject(completion: {(projectModel,error) in | ||
if let error = error{ | ||
debugPrint(error) | ||
return | ||
} | ||
projectModel?.data.forEach({ project in | ||
self.options.append(project.name) | ||
self.optionsDic.updateValue(project.id, forKey: project.name) | ||
}) | ||
self.options_first = self.options.first ?? "" | ||
self.projectModel = projectModel | ||
}) | ||
} | ||
|
||
//知识体系下的文章 | ||
func getProjectTreeArticle(page:Int,cid:Int){ | ||
APIService.instance.getProjectArticle(with: page, andWith: cid,completion: {(projectSonModel,error) in | ||
if let error = error{ | ||
debugPrint(error) | ||
return | ||
} | ||
|
||
self.projectSonModel = projectSonModel | ||
self.projectDictionArticleDataList.updateValue(projectSonModel!.data.datas, forKey: cid) | ||
//self.projectSonModelDataList.append(projectSonModel!.data) | ||
}) | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.