Skip to content

Commit

Permalink
v8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PGzxc committed Jul 7, 2023
1 parent 00c92e3 commit 66588ed
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 21 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ ViewModel(MVVM设计模式):
* 消息 -未读
* 消息item(点击)-详情页

### v8.0-项目(点击标签切换到对应的视图—修改v5.0bug)

* 通过onReceive方法,监听标签的切换,显示相应的视图

## 四 开发任务

### 4.1 已完成
Expand Down
4 changes: 4 additions & 0 deletions WanAndroid_SwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
F3D5EE152A3C5687000ACDFF /* NavigationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3D5EE142A3C5687000ACDFF /* NavigationViewModel.swift */; };
F3D5EE172A3C5748000ACDFF /* TreeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3D5EE162A3C5748000ACDFF /* TreeModel.swift */; };
F3D5EE1A2A3C6A64000ACDFF /* NavigationSectionBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3D5EE192A3C6A64000ACDFF /* NavigationSectionBuilder.swift */; };
F3D6F7F12A57A44100D9801E /* SwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3D6F7F02A57A44100D9801E /* SwiftUIView.swift */; };
F3DA08FE2A3FE9E80089A7A6 /* MeBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3DA08FD2A3FE9E80089A7A6 /* MeBuilder.swift */; };
F3DA09032A403FCB0089A7A6 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3DA09022A403FCB0089A7A6 /* LoginView.swift */; };
F3DA09052A40A05A0089A7A6 /* LoginBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3DA09042A40A05A0089A7A6 /* LoginBuilder.swift */; };
Expand Down Expand Up @@ -94,6 +95,7 @@
F3D5EE142A3C5687000ACDFF /* NavigationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationViewModel.swift; sourceTree = "<group>"; };
F3D5EE162A3C5748000ACDFF /* TreeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TreeModel.swift; sourceTree = "<group>"; };
F3D5EE192A3C6A64000ACDFF /* NavigationSectionBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationSectionBuilder.swift; sourceTree = "<group>"; };
F3D6F7F02A57A44100D9801E /* SwiftUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIView.swift; sourceTree = "<group>"; };
F3DA08FD2A3FE9E80089A7A6 /* MeBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeBuilder.swift; sourceTree = "<group>"; };
F3DA09022A403FCB0089A7A6 /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
F3DA09042A40A05A0089A7A6 /* LoginBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginBuilder.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -184,6 +186,7 @@
isa = PBXGroup;
children = (
F39290372A3D9C4100DCCFC9 /* ProjectBuilder.swift */,
F3D6F7F02A57A44100D9801E /* SwiftUIView.swift */,
);
path = view;
sourceTree = "<group>";
Expand Down Expand Up @@ -570,6 +573,7 @@
F3D5EE1A2A3C6A64000ACDFF /* NavigationSectionBuilder.swift in Sources */,
F3BDCCE62A37092F00FC3CCD /* API.swift in Sources */,
F3BDCCE82A37094D00FC3CCD /* Router.swift in Sources */,
F3D6F7F12A57A44100D9801E /* SwiftUIView.swift in Sources */,
F3BDCCDB2A37060500FC3CCD /* ModelProtocol.swift in Sources */,
F3D56EA42A36CC4D008876F0 /* TabBarView.swift in Sources */,
F392903A2A3DF6D200DCCFC9 /* ProjectSonModel.swift in Sources */,
Expand Down
11 changes: 6 additions & 5 deletions WanAndroid_SwiftUI/Content/Project/ProjectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import SwiftUI
struct ProjectView: View {
@StateObject private var vm: ProjectViewModel = ProjectViewModel()
var body: some View {
ProjectBuilder(vm: .constant(vm)).pickView
ProjectBuilder(vm: .constant(vm)).articleView
// ProjectBuilder(vm: .constant(vm)).onAppear(){
// vm.getProjectModel()
// }
//SwiftUIView()
// ProjectBuilder(vm: .constant(vm)).pickView
//ProjectBuilder(vm: .constant(vm)).articleView
ProjectBuilder(vm: .constant(vm)).onAppear(){
vm.getProjectModel()
}

}
}
Expand Down
54 changes: 38 additions & 16 deletions WanAndroid_SwiftUI/Content/Project/view/ProjectBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,77 @@ import SwiftUI
struct ProjectBuilder: View {

@Binding var vm: ProjectViewModel
@State var selectedOptionIndex = 0


var body: some View {

VStack(alignment: .center){

ScrollView{

//1-导航栏
//pickView
pickView
//文章
//articleView()
articleView

}
}
}

var pickView: some View{
ScrollView(.horizontal){
HStack(spacing: 0){
Picker("Options",selection: $vm.options.first ?? $vm.options_first){
// if vm.options.isEmpty{
// Text("Loading")
// }else {
HStack(spacing: 0){

ForEach(vm.options,id: \.self) { option in
Text(option).onAppear(){
vm.getProjectTreeArticle(page: 1, cid: vm.optionsDic[option] ?? 0)
Picker("Options",selection: $selectedOptionIndex){
ForEach(0..<vm.options.count,id: \.self){ index in
Text(vm.options[index]).tag(index)
}
} .pickerStyle(SegmentedPickerStyle())
.shadow(color: .white, radius: 100)
.shadow(color: Color.brown.opacity(0.8), radius: 5, x: 0, y: 2)
.padding()
}.onReceive([self.selectedOptionIndex].publisher.first()) { value in
// 当选择值发生变化时执行操作
if(!vm.options.isEmpty ){
var option = vm.options[value]
vm.getProjectTreeArticle(page: 1, cid: vm.optionsDic[option] ?? 0)
print("Selected option: \(value)")
}

}
.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(!vm.options.isEmpty){
//var bb = self.selectedOptionIndex
let name = vm.options[self.selectedOptionIndex]
let articleList = vm.projectDictionArticleDataList[vm.optionsDic[name]!]
if(articleList != nil){
ForEach(articleList!){ article in
ArticleCellView(article: .constant(article))
}
}
}

}

// 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))
// }
// }
// }
// }

}
}

Expand Down
38 changes: 38 additions & 0 deletions WanAndroid_SwiftUI/Content/Project/view/SwiftUIView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// SwiftUIView.swift
// WanAndroid_SwiftUI
//
// Created by zxc on 2023/7/7.
//

import SwiftUI

struct SwiftUIView: View {
@State var selectedOption = 0
var options:[String] = ["0","1","2"]

var body: some View {
VStack {
Picker("Options", selection: $selectedOption) {
// Text("Option 1").tag(0)
// Text("Option 2").tag(1)
// Text("Option 3").tag(2)
ForEach(0..<options.count,id:\.self){ index in
Text(options[index]).tag(index)
}
}
.pickerStyle(SegmentedPickerStyle())
}
.onReceive([self.selectedOption].publisher.first()) { value in
// 当选择值发生变化时执行操作
print("Selected option: \(value)")

}
}
}

struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIView()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ProjectViewModel:ObservableObject{
var optionsDic:Dictionary<String,Int> = [:]
var options:[String] = []
var options_first: String = ""
var selectedOptionIndex = 0 //用于存储选中的选项索引

init(){

Expand Down

0 comments on commit 66588ed

Please sign in to comment.