Skip to content

Commit

Permalink
v11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PGzxc committed Nov 30, 2023
1 parent a241657 commit 80268e9
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ ViewModel(MVVM设计模式):
* 导入[WrappingHStack](https://github.com/dkk/WrappingHStack)自动换行库
* 重构导航布局页面

### v11.0

* 添加置顶文章接口和界面开发
* ArticleItem界面更新(置顶标签、Title、content显示等)

## 五 开发任务

### 5.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 @@ -11,6 +11,7 @@
F30653422A2DEA5300AEB416 /* WanAndroid_SwiftUIApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = F30653412A2DEA5300AEB416 /* WanAndroid_SwiftUIApp.swift */; };
F30653462A2DEA5500AEB416 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F30653452A2DEA5500AEB416 /* Assets.xcassets */; };
F30653492A2DEA5500AEB416 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F30653482A2DEA5500AEB416 /* Preview Assets.xcassets */; };
F30A7B582B1851CF00284CBE /* ArticleTopModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F30A7B572B1851CF00284CBE /* ArticleTopModel.swift */; };
F39290322A3D961D00DCCFC9 /* ProjectModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F39290312A3D961D00DCCFC9 /* ProjectModel.swift */; };
F39290362A3D975800DCCFC9 /* ProjectViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F39290352A3D975800DCCFC9 /* ProjectViewModel.swift */; };
F39290382A3D9C4100DCCFC9 /* ProjectBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F39290372A3D9C4100DCCFC9 /* ProjectBuilder.swift */; };
Expand Down Expand Up @@ -67,6 +68,7 @@
F30653432A2DEA5300AEB416 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
F30653452A2DEA5500AEB416 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
F30653482A2DEA5500AEB416 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
F30A7B572B1851CF00284CBE /* ArticleTopModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleTopModel.swift; sourceTree = "<group>"; };
F39290312A3D961D00DCCFC9 /* ProjectModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectModel.swift; sourceTree = "<group>"; };
F39290352A3D975800DCCFC9 /* ProjectViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectViewModel.swift; sourceTree = "<group>"; };
F39290372A3D9C4100DCCFC9 /* ProjectBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectBuilder.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -243,6 +245,7 @@
F39290392A3DF6D200DCCFC9 /* ProjectSonModel.swift */,
F3DA090A2A419EC30089A7A6 /* CoinUserInfoModel.swift */,
F3DA09172A41F5830089A7A6 /* MessageModel.swift */,
F30A7B572B1851CF00284CBE /* ArticleTopModel.swift */,
);
path = model;
sourceTree = "<group>";
Expand Down Expand Up @@ -569,6 +572,7 @@
F3DA09212A42A04C0089A7A6 /* MessageItemUnReadBuilder.swift in Sources */,
F3BDCCE12A37078F00FC3CCD /* BannerModel.swift in Sources */,
F3B87C642A3B170D0072738D /* ImageCarouselView.swift in Sources */,
F30A7B582B1851CF00284CBE /* ArticleTopModel.swift in Sources */,
F3D56EA32A36CC4D008876F0 /* NavigationView.swift in Sources */,
F3B87C622A3B170D0072738D /* ArticleCellView.swift in Sources */,
F3BDCCEA2A37096900FC3CCD /* APIService.swift in Sources */,
Expand Down
19 changes: 13 additions & 6 deletions WanAndroid_SwiftUI/Content/Home/view/ArticleCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ struct ArticleCellView: View{
if(article.fresh!){
Text("")
.padding(EdgeInsets(top: 2, leading: 5, bottom: 2, trailing:5))
//.frame(width: 50,height: 25)
.background(.red)
.cornerRadius(2)
.shadow(color: Color.black.opacity(0.08), radius: 60, x: 0.0, y: 16)
Expand All @@ -48,7 +47,6 @@ struct ArticleCellView: View{
if(article.tags != nil && !article.tags!.isEmpty){
Text(article.tags?.first?.name ?? "")
.padding(EdgeInsets(top: 2, leading: 5, bottom: 2, trailing:5))
//.frame(width: 80,height: 25)
.background(.orange)
.cornerRadius(2)
.shadow(color: Color.black.opacity(0.08), radius: 60, x: 0.0, y: 16)
Expand Down Expand Up @@ -80,8 +78,8 @@ struct ArticleCellView: View{
//2-中间部分
HStack{
VStack(alignment:.leading){
Text(article.title ?? "")
Text(article.desc ?? "")
Text(article.title ?? "").lineLimit(2).font(.system(size: 18))
Text(article.desc ?? "").lineLimit(2).foregroundColor(.gray)
}
Spacer()
AnimatedImage(url: URL(string: article.envelopePic ?? ""))
Expand All @@ -94,17 +92,26 @@ struct ArticleCellView: View{
//3-分类、收藏
HStack{

if(article.isTop!){
Text("置顶")
.padding(EdgeInsets(top: 2, leading: 5, bottom: 2, trailing:5))
.background(.red)
.cornerRadius(2)
.shadow(color: Color.black.opacity(0.08), radius: 60, x: 0.0, y: 16)
.textFieldStyle(.roundedBorder)
.font(Font.system(size: 15))
}

Text(article.superChapterName ?? "")
.padding(EdgeInsets(top: 2, leading: 5, bottom: 2, trailing:5))
//.frame(width: 100,height: 25)
.background(.green)
.cornerRadius(2)
.shadow(color: Color.black.opacity(0.08), radius: 60, x: 0.0, y: 16)
.textFieldStyle(.roundedBorder)
.font(Font.system(size: 15))

Text(article.chapterName ?? "")
.padding(EdgeInsets(top: 2, leading: 5, bottom: 2, trailing:5))
//.frame(width: 80,height: 25)
.background(.orange)
.cornerRadius(2)
.shadow(color: Color.black.opacity(0.08), radius: 60, x: 0.0, y: 16)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct ArticleCellViewBuilder: View {
}
}
}.onAppear(){
vm.getArticleTop()
vm.getArticleModel(page: 0)
}
}
Expand Down
19 changes: 17 additions & 2 deletions WanAndroid_SwiftUI/Content/Home/viewmodel/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class HomeViewModel:ObservableObject{

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

@Published var banners:[Banner]? = []
@Published var articles:[Article]? = []
Expand All @@ -26,6 +27,7 @@ class HomeViewModel:ObservableObject{

}

//1-Banner轮播图
func getBannerModel(){

APIService.instance.getBanner(completion: {(bannerModel,error) in
Expand All @@ -38,15 +40,28 @@ class HomeViewModel:ObservableObject{

})
}

//2-置顶文章
func getArticleTop(){
APIService.instance.getArticleTop(completion: {(articleTopModel,error) in
if let error = error{
debugPrint(error)
return
}
// self.articleTopModel = articleTopModel
self.articles?.append(contentsOf: articleTopModel!.data!)

})
}
//3-文章列表
func getArticleModel(page:Int){
APIService.instance.getArticle(with: page, completion: {(articleModel,error) in
if let error = error{
debugPrint(error)
return
}
self.articleModel = articleModel
self.articles = articleModel?.data?.datas
//self.articles = articleModel?.data?.datas
self.articles?.append(contentsOf:articleModel!.data!.datas!)

})
}
Expand Down
10 changes: 9 additions & 1 deletion WanAndroid_SwiftUI/api/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ struct API {
///******************************************************************/

static var homeBanner = "/banner/json";


/// **********************1.3 首页-置顶******************************
/// 示例:https://www.wanandroid.com//article/top/json
/// 方法:GET
/// 参数:无
///******************************************************************/

static var homeArticleTop = "/article/top/json";

/// **********************1.3 常用网站******************************
/// 示例:https://www.wanandroid.com/friend/json
/// 方法:GET
Expand Down
18 changes: 18 additions & 0 deletions WanAndroid_SwiftUI/api/APIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ struct APIService {
}
}

func getArticleTop(completion:@escaping (ArticleTopModel?, Error?)->()){

Alamofire.request(Router.homeArticleTop).responseObject{(response: DataResponse<ArticleTopModel>) in

if let error = response.error{
completion(nil,error)
return
}
if let article = response.result.value {
article.data?.forEach({ article in
article.isTop = true
})
completion(article,nil)
return
}
}
}

func getArticle(with page: Int,completion:@escaping (ArticleModel?, Error?)->()){

Alamofire.request(Router.homeArticleList(page)).responseObject{(response: DataResponse<ArticleModel>) in
Expand Down
4 changes: 4 additions & 0 deletions WanAndroid_SwiftUI/api/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal extension APIService{
enum Router: URLRequestConvertible {
case homeArticleList(Int?) //首页文章列表
case homeBanner //首页轮播图
case homeArticleTop //置顶文章
case login(String,String) //用户登录
case collectList(Int?)
case tree //体系
Expand All @@ -32,6 +33,7 @@ internal extension APIService{
switch self {
case .homeBanner: return .get
case .homeArticleList: return .get
case .homeArticleTop: return .get
case .login: return .post
case .collectList: return .get
case .tree: return .get
Expand All @@ -48,6 +50,7 @@ internal extension APIService{
switch self {
case .homeBanner: return API.homeBanner
case .homeArticleList(let page): return String(format:API.homeArticleList, page ?? 0)
case .homeArticleTop: return API.homeArticleTop
case .login(_, _): return API.login
case .collectList(let index):return String(format: API.collectList, index ?? 0)
case .tree: return API.treeList
Expand All @@ -64,6 +67,7 @@ internal extension APIService{
switch self {
case .homeArticleList:return nil
case .homeBanner:return nil
case .homeArticleTop: return nil
case .login(let username, let password):
return ["username":username,"password":password]
case .collectList: return nil
Expand Down
2 changes: 2 additions & 0 deletions WanAndroid_SwiftUI/model/ArticleModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ArticleModelData: Mappable{
// MARK: - DataElement
class Article: Mappable,Identifiable {

var isTop: Bool? = false
var adminAdd: Bool?
var apkLink: String?
var audit: Int?
Expand Down Expand Up @@ -84,6 +85,7 @@ class Article: Mappable,Identifiable {

}
func mapping(map: ObjectMapper.Map) {
isTop <- map["isTop"]
adminAdd <- map["adminAdd"]
apkLink <- map["apkLink"]
audit <- map["audit"]
Expand Down
28 changes: 28 additions & 0 deletions WanAndroid_SwiftUI/model/ArticleTopModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// ArticleTopModel.swift
// WanAndroid_SwiftUI
//
// Created by zxc on 2023/11/30.
//

import Foundation
import Alamofire
import ObjectMapper

// MARK: - ArticleTopModel-置顶
class ArticleTopModel: Mappable{

var data: [Article]? = []
var errorCode: Int?
var errorMsg: String?
required init?(map:Map) {

}

func mapping(map: Map) {
data <- map["data"]
errorCode <- map["errorCode"]
errorMsg <- map["errorMsg"]
}
}

0 comments on commit 80268e9

Please sign in to comment.