Skip to content

Commit 80268e9

Browse files
committed
v11.0
1 parent a241657 commit 80268e9

File tree

10 files changed

+101
-9
lines changed

10 files changed

+101
-9
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ ViewModel(MVVM设计模式):
151151
* 导入[WrappingHStack](https://github.com/dkk/WrappingHStack)自动换行库
152152
* 重构导航布局页面
153153

154+
### v11.0
155+
156+
* 添加置顶文章接口和界面开发
157+
* ArticleItem界面更新(置顶标签、Title、content显示等)
158+
154159
## 五 开发任务
155160

156161
### 5.1 已完成

WanAndroid_SwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
F30653422A2DEA5300AEB416 /* WanAndroid_SwiftUIApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = F30653412A2DEA5300AEB416 /* WanAndroid_SwiftUIApp.swift */; };
1212
F30653462A2DEA5500AEB416 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F30653452A2DEA5500AEB416 /* Assets.xcassets */; };
1313
F30653492A2DEA5500AEB416 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F30653482A2DEA5500AEB416 /* Preview Assets.xcassets */; };
14+
F30A7B582B1851CF00284CBE /* ArticleTopModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F30A7B572B1851CF00284CBE /* ArticleTopModel.swift */; };
1415
F39290322A3D961D00DCCFC9 /* ProjectModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F39290312A3D961D00DCCFC9 /* ProjectModel.swift */; };
1516
F39290362A3D975800DCCFC9 /* ProjectViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F39290352A3D975800DCCFC9 /* ProjectViewModel.swift */; };
1617
F39290382A3D9C4100DCCFC9 /* ProjectBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F39290372A3D9C4100DCCFC9 /* ProjectBuilder.swift */; };
@@ -67,6 +68,7 @@
6768
F30653432A2DEA5300AEB416 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
6869
F30653452A2DEA5500AEB416 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
6970
F30653482A2DEA5500AEB416 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
71+
F30A7B572B1851CF00284CBE /* ArticleTopModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleTopModel.swift; sourceTree = "<group>"; };
7072
F39290312A3D961D00DCCFC9 /* ProjectModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectModel.swift; sourceTree = "<group>"; };
7173
F39290352A3D975800DCCFC9 /* ProjectViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectViewModel.swift; sourceTree = "<group>"; };
7274
F39290372A3D9C4100DCCFC9 /* ProjectBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectBuilder.swift; sourceTree = "<group>"; };
@@ -243,6 +245,7 @@
243245
F39290392A3DF6D200DCCFC9 /* ProjectSonModel.swift */,
244246
F3DA090A2A419EC30089A7A6 /* CoinUserInfoModel.swift */,
245247
F3DA09172A41F5830089A7A6 /* MessageModel.swift */,
248+
F30A7B572B1851CF00284CBE /* ArticleTopModel.swift */,
246249
);
247250
path = model;
248251
sourceTree = "<group>";
@@ -569,6 +572,7 @@
569572
F3DA09212A42A04C0089A7A6 /* MessageItemUnReadBuilder.swift in Sources */,
570573
F3BDCCE12A37078F00FC3CCD /* BannerModel.swift in Sources */,
571574
F3B87C642A3B170D0072738D /* ImageCarouselView.swift in Sources */,
575+
F30A7B582B1851CF00284CBE /* ArticleTopModel.swift in Sources */,
572576
F3D56EA32A36CC4D008876F0 /* NavigationView.swift in Sources */,
573577
F3B87C622A3B170D0072738D /* ArticleCellView.swift in Sources */,
574578
F3BDCCEA2A37096900FC3CCD /* APIService.swift in Sources */,

WanAndroid_SwiftUI/Content/Home/view/ArticleCellView.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct ArticleCellView: View{
3636
if(article.fresh!){
3737
Text("")
3838
.padding(EdgeInsets(top: 2, leading: 5, bottom: 2, trailing:5))
39-
//.frame(width: 50,height: 25)
4039
.background(.red)
4140
.cornerRadius(2)
4241
.shadow(color: Color.black.opacity(0.08), radius: 60, x: 0.0, y: 16)
@@ -48,7 +47,6 @@ struct ArticleCellView: View{
4847
if(article.tags != nil && !article.tags!.isEmpty){
4948
Text(article.tags?.first?.name ?? "")
5049
.padding(EdgeInsets(top: 2, leading: 5, bottom: 2, trailing:5))
51-
//.frame(width: 80,height: 25)
5250
.background(.orange)
5351
.cornerRadius(2)
5452
.shadow(color: Color.black.opacity(0.08), radius: 60, x: 0.0, y: 16)
@@ -80,8 +78,8 @@ struct ArticleCellView: View{
8078
//2-中间部分
8179
HStack{
8280
VStack(alignment:.leading){
83-
Text(article.title ?? "")
84-
Text(article.desc ?? "")
81+
Text(article.title ?? "").lineLimit(2).font(.system(size: 18))
82+
Text(article.desc ?? "").lineLimit(2).foregroundColor(.gray)
8583
}
8684
Spacer()
8785
AnimatedImage(url: URL(string: article.envelopePic ?? ""))
@@ -94,17 +92,26 @@ struct ArticleCellView: View{
9492
//3-分类、收藏
9593
HStack{
9694

95+
if(article.isTop!){
96+
Text("置顶")
97+
.padding(EdgeInsets(top: 2, leading: 5, bottom: 2, trailing:5))
98+
.background(.red)
99+
.cornerRadius(2)
100+
.shadow(color: Color.black.opacity(0.08), radius: 60, x: 0.0, y: 16)
101+
.textFieldStyle(.roundedBorder)
102+
.font(Font.system(size: 15))
103+
}
104+
97105
Text(article.superChapterName ?? "")
98106
.padding(EdgeInsets(top: 2, leading: 5, bottom: 2, trailing:5))
99-
//.frame(width: 100,height: 25)
100107
.background(.green)
101108
.cornerRadius(2)
102109
.shadow(color: Color.black.opacity(0.08), radius: 60, x: 0.0, y: 16)
103110
.textFieldStyle(.roundedBorder)
104111
.font(Font.system(size: 15))
112+
105113
Text(article.chapterName ?? "")
106114
.padding(EdgeInsets(top: 2, leading: 5, bottom: 2, trailing:5))
107-
//.frame(width: 80,height: 25)
108115
.background(.orange)
109116
.cornerRadius(2)
110117
.shadow(color: Color.black.opacity(0.08), radius: 60, x: 0.0, y: 16)

WanAndroid_SwiftUI/Content/Home/view/ArticleCellViewBuilder.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct ArticleCellViewBuilder: View {
2323
}
2424
}
2525
}.onAppear(){
26+
vm.getArticleTop()
2627
vm.getArticleModel(page: 0)
2728
}
2829
}

WanAndroid_SwiftUI/Content/Home/viewmodel/HomeViewModel.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class HomeViewModel:ObservableObject{
1111

1212
@Published var bannerModel:BannerModel? = nil
1313
@Published var articleModel:ArticleModel? = nil
14+
@Published var articleTopModel:ArticleTopModel? = nil
1415

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

2728
}
2829

30+
//1-Banner轮播图
2931
func getBannerModel(){
3032

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

3941
})
4042
}
41-
43+
//2-置顶文章
44+
func getArticleTop(){
45+
APIService.instance.getArticleTop(completion: {(articleTopModel,error) in
46+
if let error = error{
47+
debugPrint(error)
48+
return
49+
}
50+
// self.articleTopModel = articleTopModel
51+
self.articles?.append(contentsOf: articleTopModel!.data!)
52+
53+
})
54+
}
55+
//3-文章列表
4256
func getArticleModel(page:Int){
4357
APIService.instance.getArticle(with: page, completion: {(articleModel,error) in
4458
if let error = error{
4559
debugPrint(error)
4660
return
4761
}
4862
self.articleModel = articleModel
49-
self.articles = articleModel?.data?.datas
63+
//self.articles = articleModel?.data?.datas
64+
self.articles?.append(contentsOf:articleModel!.data!.datas!)
5065

5166
})
5267
}

WanAndroid_SwiftUI/api/API.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ struct API {
3131
///******************************************************************/
3232

3333
static var homeBanner = "/banner/json";
34-
34+
35+
/// **********************1.3 首页-置顶******************************
36+
/// 示例:https://www.wanandroid.com//article/top/json
37+
/// 方法:GET
38+
/// 参数:无
39+
///******************************************************************/
40+
41+
static var homeArticleTop = "/article/top/json";
42+
3543
/// **********************1.3 常用网站******************************
3644
/// 示例:https://www.wanandroid.com/friend/json
3745
/// 方法:GET

WanAndroid_SwiftUI/api/APIService.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ struct APIService {
3333
}
3434
}
3535

36+
func getArticleTop(completion:@escaping (ArticleTopModel?, Error?)->()){
37+
38+
Alamofire.request(Router.homeArticleTop).responseObject{(response: DataResponse<ArticleTopModel>) in
39+
40+
if let error = response.error{
41+
completion(nil,error)
42+
return
43+
}
44+
if let article = response.result.value {
45+
article.data?.forEach({ article in
46+
article.isTop = true
47+
})
48+
completion(article,nil)
49+
return
50+
}
51+
}
52+
}
53+
3654
func getArticle(with page: Int,completion:@escaping (ArticleModel?, Error?)->()){
3755

3856
Alamofire.request(Router.homeArticleList(page)).responseObject{(response: DataResponse<ArticleModel>) in

WanAndroid_SwiftUI/api/Router.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internal extension APIService{
1414
enum Router: URLRequestConvertible {
1515
case homeArticleList(Int?) //首页文章列表
1616
case homeBanner //首页轮播图
17+
case homeArticleTop //置顶文章
1718
case login(String,String) //用户登录
1819
case collectList(Int?)
1920
case tree //体系
@@ -32,6 +33,7 @@ internal extension APIService{
3233
switch self {
3334
case .homeBanner: return .get
3435
case .homeArticleList: return .get
36+
case .homeArticleTop: return .get
3537
case .login: return .post
3638
case .collectList: return .get
3739
case .tree: return .get
@@ -48,6 +50,7 @@ internal extension APIService{
4850
switch self {
4951
case .homeBanner: return API.homeBanner
5052
case .homeArticleList(let page): return String(format:API.homeArticleList, page ?? 0)
53+
case .homeArticleTop: return API.homeArticleTop
5154
case .login(_, _): return API.login
5255
case .collectList(let index):return String(format: API.collectList, index ?? 0)
5356
case .tree: return API.treeList
@@ -64,6 +67,7 @@ internal extension APIService{
6467
switch self {
6568
case .homeArticleList:return nil
6669
case .homeBanner:return nil
70+
case .homeArticleTop: return nil
6771
case .login(let username, let password):
6872
return ["username":username,"password":password]
6973
case .collectList: return nil

WanAndroid_SwiftUI/model/ArticleModel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ArticleModelData: Mappable{
5151
// MARK: - DataElement
5252
class Article: Mappable,Identifiable {
5353

54+
var isTop: Bool? = false
5455
var adminAdd: Bool?
5556
var apkLink: String?
5657
var audit: Int?
@@ -84,6 +85,7 @@ class Article: Mappable,Identifiable {
8485

8586
}
8687
func mapping(map: ObjectMapper.Map) {
88+
isTop <- map["isTop"]
8789
adminAdd <- map["adminAdd"]
8890
apkLink <- map["apkLink"]
8991
audit <- map["audit"]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// ArticleTopModel.swift
3+
// WanAndroid_SwiftUI
4+
//
5+
// Created by zxc on 2023/11/30.
6+
//
7+
8+
import Foundation
9+
import Alamofire
10+
import ObjectMapper
11+
12+
// MARK: - ArticleTopModel-置顶
13+
class ArticleTopModel: Mappable{
14+
15+
var data: [Article]? = []
16+
var errorCode: Int?
17+
var errorMsg: String?
18+
required init?(map:Map) {
19+
20+
}
21+
22+
func mapping(map: Map) {
23+
data <- map["data"]
24+
errorCode <- map["errorCode"]
25+
errorMsg <- map["errorMsg"]
26+
}
27+
}
28+

0 commit comments

Comments
 (0)