Skip to content

Commit

Permalink
v9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PGzxc committed Nov 29, 2023
1 parent 90cc1d3 commit a11498d
Show file tree
Hide file tree
Showing 32 changed files with 676 additions and 1,958 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ fastlane/test_output
iOSInjectionProject/
.DS_Store
*.lock
Podfile.lock
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
platform :ios, '16.0'

target 'WanAndroid_SwiftUI' do
# Comment the next line if you don't want to use dynamic frameworks
Expand Down
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ ViewModel(MVVM设计模式):

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

### v9.0

* 数据实体类(bean)由quicktype.io生成改为AlamofireObjectMapper
* 解决能够接收到数据,页面无法显示问题

## 四 开发任务

### 4.1 已完成
Expand Down Expand Up @@ -174,14 +179,14 @@ ViewModel(MVVM设计模式):
* swiftUI练手项目,可能存在代码不规范等错误,如有错误还望指正


[swift-waz-1]:https://cdn.staticaly.com/gh/PGzxc/CDN/master/blog-resume/swiftui-waz-home-1.png
[swift-waz-2]:https://cdn.staticaly.com/gh/PGzxc/CDN/master/blog-resume/swiftui-waz-detail-2.png
[swift-waz-3]:https://cdn.staticaly.com/gh/PGzxc/CDN/master/blog-resume/swiftui-waz-navigator-3.png
[swift-waz-4]:https://cdn.staticaly.com/gh/PGzxc/CDN/master/blog-resume/swiftui-waz-project-4.png
[swift-waz-5]:https://cdn.staticaly.com/gh/PGzxc/CDN/master/blog-resume/swiftui-waz-message-unread-5.png
[swift-waz-6]:https://cdn.staticaly.com/gh/PGzxc/CDN/master/blog-resume/swiftui-waz-message-read-6.png
[swift-waz-7]:https://cdn.staticaly.com/gh/PGzxc/CDN/master/blog-resume/swiftui-waz-message-info-7.png
[swift-waz-8]:https://cdn.staticaly.com/gh/PGzxc/CDN/master/blog-resume/swiftui-waz-me-info-8.png
[swift-waz-9]:https://cdn.staticaly.com/gh/PGzxc/CDN/master/blog-resume/swiftui-waz-me-info-no-9.png
[swift-waz-10]:https://cdn.staticaly.com/gh/PGzxc/CDN/master/blog-resume/swiftui-waz-login-10.png
[swift-waz-11]:https://cdn.staticaly.com/gh/PGzxc/CDN/master/blog-resume/swiftui-waz-register-11.png
[swift-waz-1]:https://jsd.onmicrosoft.cn/gh/PGzxc/CDN/blog-resume/swiftui-waz-home-1.png
[swift-waz-2]:https://jsd.onmicrosoft.cn/gh/PGzxc/CDN/blog-resume/swiftui-waz-detail-2.png
[swift-waz-3]:https://jsd.onmicrosoft.cn/gh/PGzxc/CDN/blog-resume/swiftui-waz-navigator-3.png
[swift-waz-4]:https://jsd.onmicrosoft.cn/gh/PGzxc/CDN/blog-resume/swiftui-waz-project-4.png
[swift-waz-5]:https://jsd.onmicrosoft.cn/gh/PGzxc/CDN/blog-resume/swiftui-waz-message-unread-5.png
[swift-waz-6]:https://jsd.onmicrosoft.cn/gh/PGzxc/CDN/blog-resume/swiftui-waz-message-read-6.png
[swift-waz-7]:https://jsd.onmicrosoft.cn/gh/PGzxc/CDN/blog-resume/swiftui-waz-message-info-7.png
[swift-waz-8]:https://jsd.onmicrosoft.cn/gh/PGzxc/CDN/blog-resume/swiftui-waz-me-info-8.png
[swift-waz-9]:https://jsd.onmicrosoft.cn/gh/PGzxc/CDN/blog-resume/swiftui-waz-me-info-no-9.png
[swift-waz-10]:https://jsd.onmicrosoft.cn/gh/PGzxc/CDN/blog-resume/swiftui-waz-login-10.png
[swift-waz-11]:https://jsd.onmicrosoft.cn/gh/PGzxc/CDN/blog-resume/swiftui-waz-register-11.png
8 changes: 8 additions & 0 deletions WanAndroid_SwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
F3BDCCE82A37094D00FC3CCD /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BDCCE72A37094D00FC3CCD /* Router.swift */; };
F3BDCCEA2A37096900FC3CCD /* APIService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BDCCE92A37096900FC3CCD /* APIService.swift */; };
F3BDCCED2A370A0800FC3CCD /* HomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BDCCEC2A370A0800FC3CCD /* HomeViewModel.swift */; };
F3CBED4F2B1701BE00D7E722 /* Const.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3CBED4E2B1701BE00D7E722 /* Const.swift */; };
F3D56EA22A36CC4D008876F0 /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3D56E972A36CC4D008876F0 /* HomeView.swift */; };
F3D56EA32A36CC4D008876F0 /* NavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3D56E992A36CC4D008876F0 /* NavigationView.swift */; };
F3D56EA42A36CC4D008876F0 /* TabBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3D56E9B2A36CC4D008876F0 /* TabBarView.swift */; };
Expand Down Expand Up @@ -86,6 +87,7 @@
F3BDCCE72A37094D00FC3CCD /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
F3BDCCE92A37096900FC3CCD /* APIService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIService.swift; sourceTree = "<group>"; };
F3BDCCEC2A370A0800FC3CCD /* HomeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewModel.swift; sourceTree = "<group>"; };
F3CBED4E2B1701BE00D7E722 /* Const.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Const.swift; sourceTree = "<group>"; };
F3D56E972A36CC4D008876F0 /* HomeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
F3D56E992A36CC4D008876F0 /* NavigationView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationView.swift; sourceTree = "<group>"; };
F3D56E9B2A36CC4D008876F0 /* TabBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabBarView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -223,6 +225,7 @@
isa = PBXGroup;
children = (
F3BDCCD52A3705B400FC3CCD /* Storage.swift */,
F3CBED4E2B1701BE00D7E722 /* Const.swift */,
);
path = utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -571,6 +574,7 @@
F3BDCCEA2A37096900FC3CCD /* APIService.swift in Sources */,
F3DA090B2A419EC30089A7A6 /* CoinUserInfoModel.swift in Sources */,
F3D5EE1A2A3C6A64000ACDFF /* NavigationSectionBuilder.swift in Sources */,
F3CBED4F2B1701BE00D7E722 /* Const.swift in Sources */,
F3BDCCE62A37092F00FC3CCD /* API.swift in Sources */,
F3BDCCE82A37094D00FC3CCD /* Router.swift in Sources */,
F3D6F7F12A57A44100D9801E /* SwiftUIView.swift in Sources */,
Expand Down Expand Up @@ -645,6 +649,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_KEY_WKRunsIndependentlyOfCompanionApp = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -699,6 +704,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_KEY_WKRunsIndependentlyOfCompanionApp = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand All @@ -718,6 +724,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"WanAndroid_SwiftUI/Preview Content\"";
DEVELOPMENT_TEAM = 34LPAHZG4A;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down Expand Up @@ -748,6 +755,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"WanAndroid_SwiftUI/Preview Content\"";
DEVELOPMENT_TEAM = 34LPAHZG4A;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
10 changes: 3 additions & 7 deletions WanAndroid_SwiftUI/Content/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ struct HomeView: View {

var body: some View {
ScrollView{
VStack{
VStackLayout {
//轮播图
ImageCarouseViewBuilder(vm:.constant(vm)).onAppear(){
vm.getBannerModel()
}
ImageCarouseViewBuilder()
//文章
ArticleCellViewBuilder(vm: .constant(vm)).onAppear(){
vm.getArticle(page: 0)
}
ArticleCellViewBuilder()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions WanAndroid_SwiftUI/Content/Home/view/ArticleCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import SwiftUI
import SDWebImageSwiftUI
import ObjectMapper

struct ArticleCellView: View{

Expand All @@ -23,7 +24,6 @@ struct ArticleCellView: View{
LoadingWebView(url: URL(string: article.link ?? ""))
}


//NavigationLink(destination: LoadingWebView(url: URL(string: article.link ?? "")), label: { articleView })

}
Expand Down Expand Up @@ -125,6 +125,6 @@ struct ArticleCellView: View{

struct ArticleCellView_Previews: PreviewProvider{
static var previews: some View{
ArticleCellView(article: .constant(Article(adminAdd: true, apkLink: "apkLink", audit: 1, author: "author", canEdit: true, chapterID: 1, chapterName: "chapterName", collect: true, courseID: 1, descMd: "descMd", envelopePic: "envelopePic", fresh: true, host: "host", id: 1, isAdminAdd: true, link: "link", desc: "desc", niceDate: "niceDate", niceShareDate: "niceShareDate", origin: "origin", dataPrefix: "dataPrefix", projectLink: "projectLink", publishTime: 1, realSuperChapterID: 1, selfVisible: 1, shareDate: 1, shareUser: "shareUser", superChapterID: 1, superChapterName: "superChapterName", tags: [Tag(name: "tag", url: nil)], title: "title", type: 1, userID: 1, visible: 1, zan: 1)))
return ArticleCellView(article: .constant(Const.shared.getArticle()))
}
}
18 changes: 11 additions & 7 deletions WanAndroid_SwiftUI/Content/Home/view/ArticleCellViewBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ import SwiftUI

struct ArticleCellViewBuilder: View {

@Binding var vm: HomeViewModel
@StateObject var vm: HomeViewModel = HomeViewModel()

var body: some View {

//let articles = vm.articleModel?.data?.datas
//let articles = Const.shared.getArticleModel().data?.datas //预览数据
let articles = vm.articles
VStack{
//article
let articles = vm.articleModel?.data?.datas
//List{
if(articles != nil){
ForEach(articles!){ article in ArticleCellView(article: .constant(article)) }
ForEach(articles!){
article in ArticleCellView(article: .constant(article))
}
}
// }
}.onAppear(){
vm.getArticleModel(page: 0)
}
}
}

struct ArticleCellViewBuilder_Previews: PreviewProvider {
static var previews: some View {
let vm: HomeViewModel = HomeViewModel()
ArticleCellViewBuilder(vm:.constant(vm))
ArticleCellViewBuilder(vm:vm)
}
}
53 changes: 26 additions & 27 deletions WanAndroid_SwiftUI/Content/Home/view/ImageCarouseViewBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,37 @@ import SDWebImageSwiftUI

struct ImageCarouseViewBuilder: View {

@Binding var vm: HomeViewModel
@StateObject var vm: HomeViewModel = HomeViewModel()
@State private var goToNewView: Bool = false
@State var banner:Banner? = nil
@State var isModalPresented = false


var body: some View {

let bannerDatas = vm.bannerModel?.data
if(bannerDatas != nil){

ImageCarouselView(numberOfImages: bannerDatas!.count){
ForEach(bannerDatas!){ banner in
AnimatedImage(url: URL(string: banner.imagePath))
.resizable()
.scaledToFill()
.aspectRatio(contentMode: .fit)
.frame(width: UIScreen.main.bounds.width,height: 250)
.clipped()
.onTapGesture {
self.banner = banner
self.isModalPresented.toggle()
//self.goToNewView.toggle()
}
.sheet(isPresented: $isModalPresented){
LoadingWebView(url: URL(string: self.banner?.url ?? ""))
}

}
}.frame(width: UIScreen.main.bounds.width, height: 250, alignment: .center)

}

ImageCarouselView(numberOfImages: vm.banners!.count){
ForEach(vm.banners!){ banner in
AnimatedImage(url: URL(string: banner.imagePath ?? ""))
.resizable()
.scaledToFill()
.aspectRatio(contentMode: .fit)
.frame(width: UIScreen.main.bounds.width,height: 250)
.clipped()
.onTapGesture {
self.banner = banner
self.isModalPresented.toggle()
//self.goToNewView.toggle()
}
.sheet(isPresented: $isModalPresented){
LoadingWebView(url: URL(string: self.banner?.url ?? ""))
}

}
}.frame(width: UIScreen.main.bounds.width, height: 250, alignment: .center)
.onAppear(){
vm.getBannerModel()
}

NavigationLink(destination: LoadingWebView(url: URL(string: self.banner?.url ?? "")), isActive: self.$goToNewView) { EmptyView() }
}
}
Expand All @@ -51,6 +49,7 @@ struct ImageCarouseViewBuilder_Previews: PreviewProvider {

static var previews: some View {
let vm: HomeViewModel = HomeViewModel()
ImageCarouseViewBuilder(vm: .constant(vm))
ImageCarouseViewBuilder(vm:vm)
//ImageCarouseViewBuilder(vm: .constant(vm))
}
}
24 changes: 16 additions & 8 deletions WanAndroid_SwiftUI/Content/Home/viewmodel/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class HomeViewModel:ObservableObject{

@Published var bannerModel:BannerModel? = nil
@Published var articleModel:ArticleModel? = nil

@Published var banners:[Banner]? = []
@Published var articles:[Article]? = []


@Published var userModel:UserModel? = nil
@Published var collectListModel:CollectListModel? = nil

Expand All @@ -22,43 +27,46 @@ class HomeViewModel:ObservableObject{
}

func getBannerModel(){

APIService.instance.getBanner(completion: {(bannerModel,error) in
if let error = error{
debugPrint(error)
return
}
self.bannerModel = bannerModel
self.banners = bannerModel?.data

})
}

func getArticle(page:Int){
APIService.instance.getArticle(with: page, completion: {(article,error) in
func getArticleModel(page:Int){
APIService.instance.getArticle(with: page, completion: {(articleModel,error) in
if let error = error{
debugPrint(error)
return
}
self.articleModel = article
self.articleModel = articleModel
self.articles = articleModel?.data?.datas

})
}
func userLogin(username:String, password:String){
APIService.instance.userLogin(with: username, with: password, completion: {(user,error) in
APIService.instance.userLogin(with: username, with: password, completion: {(userModel,error) in
if let error = error{
debugPrint(error)
return
}
self.userModel = user

self.userModel = userModel
})
}

func getCollectList(index:Int){
APIService.instance.getCollectList(with: index, completion: {(collectList,error) in
APIService.instance.getCollectList(with: index, completion: {(collectListModel,error) in
if let error = error{
debugPrint(error)
return
}
self.collectListModel = collectList
self.collectListModel = collectListModel

})
}
Expand Down
9 changes: 7 additions & 2 deletions WanAndroid_SwiftUI/Content/Me/view/MeBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ struct MeBuilder: View {
Image(systemName: "chevron.right")

}.onTapGesture {
isModalPresented.toggle()
if(!Storage.shared.isLogin){
isModalPresented.toggle()
}
}
.sheet(isPresented: $isModalPresented){
LoginView()

if(!Storage.shared.isLogin){
LoginView()
}
}
//2-显示信息
LazyVGrid(columns: headColumn, spacing: 30){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,34 @@ import SwiftUI

struct MessageItemReadBuilder: View {

@Binding var vm: MessageReadViewModel
@StateObject var vm: MessageReadViewModel = MessageReadViewModel()

var body: some View {
VStack{

let messages = vm.messageModel?.data?.datas
if(messages != nil){
//let messages = Const.shared.getMessageModel().data?.datas //预览数据
if(messages != nil && messages!.count > 0){
ForEach(messages!){ messages in
MessageItemView(message:.constant(messages))
}
}else {
VStack(alignment: .center){
Button("暂时没有数据哦,点击刷新"){
vm.getMessageRead(page: 1)
}
}
.frame(width: UIScreen.main.bounds.width,height:UIScreen.main.bounds.height)
}
}.onAppear(){
vm.getMessageRead(page: 1)
}
}
}

struct MessageItemBuilder_Previews: PreviewProvider {
static var previews: some View {
let vm: MessageReadViewModel = MessageReadViewModel()
MessageItemReadBuilder(vm: .constant(vm))
let vm: MessageReadViewModel = MessageReadViewModel()
MessageItemReadBuilder(vm:vm)
}
}
Loading

0 comments on commit a11498d

Please sign in to comment.