Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galaxy-iOS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile-group
galaxy-iOS
Commits
1267b7ed
Commit
1267b7ed
authored
Apr 15, 2024
by
Steven杜宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
// 搜索
parent
9616fc14
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
30 deletions
+107
-30
YHSearchInfomationVC.swift
...axy/Classes/Modules/Home(首页)/C/YHSearchInfomationVC.swift
+56
-6
YHHomePageViewModel.swift
...axy/Classes/Modules/Home(首页)/VM/YHHomePageViewModel.swift
+51
-24
No files found.
galaxy/galaxy/Classes/Modules/Home(首页)/C/YHSearchInfomationVC.swift
View file @
1267b7ed
...
...
@@ -47,7 +47,7 @@ class YHSearchInfomationVC: YHBaseViewController {
searchStr
=
"香港身份"
self
.
searchBar
.
textField
.
text
=
"香港身份"
}
searchText
(
searchStr
)
searchText
()
if
searchStr
.
count
>
0
{
self
.
saveSearchHistory
(
searchStr
)
}
...
...
@@ -81,6 +81,12 @@ class YHSearchInfomationVC: YHBaseViewController {
tableView
.
backgroundColor
=
.
white
tableView
.
backgroundView
=
emptyDataTipsView
tableView
.
register
(
YHSearchInfoCell
.
self
,
forCellReuseIdentifier
:
YHSearchInfoCell
.
cellReuseIdentifier
)
tableView
.
es
.
addPullToRefresh
{
self
.
loadFirstData
()
}
tableView
.
es
.
addInfiniteScrolling
{
self
.
loadMoreData
()
}
return
tableView
}()
...
...
@@ -92,7 +98,8 @@ class YHSearchInfomationVC: YHBaseViewController {
guard
let
self
=
self
else
{
return
}
self
.
searchHistoryView
.
isHidden
=
true
self
.
searchBar
.
textField
.
text
=
text
searchText
(
text
)
self
.
searchStr
=
text
searchText
()
self
.
saveSearchHistory
(
text
)
}
return
view
...
...
@@ -167,14 +174,53 @@ class YHSearchInfomationVC: YHBaseViewController {
}
}
func
searchText
(
_
text
:
String
)
{
func
searchText
()
{
self
.
tableView
.
scrollToTop
()
YHHUD
.
show
(
.
progress
(
message
:
"搜索中..."
))
// 去除两端的空格
let
targetText
=
text
.
trimmingCharacters
(
in
:
.
whitespaces
)
self
.
viewModel
.
searchArticleList
(
targetText
)
{
viewModel
.
searchArticleList
(
self
.
searchStr
,
isFirstPage
:
true
)
{
[
weak
self
]
success
,
error
in
YHHUD
.
hide
()
guard
let
self
=
self
else
{
return
}
items
.
removeAll
()
if
let
arr
=
self
.
viewModel
.
arrHomeNewsData
{
items
.
append
(
contentsOf
:
arr
)
}
emptyDataTipsView
.
isHidden
=
(
items
.
count
>
0
)
searchHistoryView
.
isHidden
=
true
self
.
tableView
.
reloadData
()
tableView
.
es
.
stopPullToRefresh
()
if
self
.
viewModel
.
hasMoreForHomeNews
==
false
{
tableView
.
es
.
noticeNoMoreData
()
}
}
}
func
loadMoreData
()
{
viewModel
.
searchArticleList
(
self
.
searchStr
,
isFirstPage
:
false
)
{
[
weak
self
]
success
,
error
in
guard
let
self
=
self
else
{
return
}
items
.
removeAll
()
if
let
arr
=
self
.
viewModel
.
arrHomeNewsData
{
items
.
append
(
contentsOf
:
arr
)
}
emptyDataTipsView
.
isHidden
=
(
items
.
count
>
0
)
searchHistoryView
.
isHidden
=
true
self
.
tableView
.
reloadData
()
tableView
.
es
.
stopLoadingMore
()
if
self
.
viewModel
.
hasMoreForHomeNews
==
false
{
tableView
.
es
.
noticeNoMoreData
()
}
}
}
func
loadFirstData
()
{
viewModel
.
searchArticleList
(
self
.
searchStr
,
isFirstPage
:
true
)
{
[
weak
self
]
success
,
error
in
guard
let
self
=
self
else
{
return
}
items
.
removeAll
()
if
let
arr
=
self
.
viewModel
.
arrHomeNewsData
{
items
.
append
(
contentsOf
:
arr
)
...
...
@@ -182,6 +228,10 @@ class YHSearchInfomationVC: YHBaseViewController {
emptyDataTipsView
.
isHidden
=
(
items
.
count
>
0
)
searchHistoryView
.
isHidden
=
true
self
.
tableView
.
reloadData
()
tableView
.
es
.
stopPullToRefresh
()
if
self
.
viewModel
.
hasMoreForHomeNews
==
false
{
tableView
.
es
.
noticeNoMoreData
()
}
}
}
...
...
galaxy/galaxy/Classes/Modules/Home(首页)/VM/YHHomePageViewModel.swift
View file @
1267b7ed
...
...
@@ -255,34 +255,61 @@ extension YHHomePageViewModel {
}
// 搜索
func
searchArticleList
(
_
title
:
String
,
callBackBlock
:
@escaping
(
_
success
:
Bool
,
_
error
:
YHErrorModel
?)
->
())
{
let
params
:
[
String
:
Any
]
=
[
"page"
:
1
,
"page_size"
:
10
,
"title"
:
title
]
let
strUrl
=
YHBaseUrlManager
.
shared
.
curURL
()
+
YHAllApiName
.
Common
.
article
let
_
=
YHNetRequest
.
getRequest
(
url
:
strUrl
,
params
:
params
)
{
[
weak
self
]
json
,
code
in
guard
let
self
=
self
else
{
return
}
//1. json字符串 转 对象
if
json
.
code
==
200
{
let
dic
=
json
.
data
guard
let
result
=
YHHomeListTotalModel
.
deserialize
(
from
:
dic
as?
Dictionary
)
else
{
self
.
arrHomeNewsData
=
[]
callBackBlock
(
false
,
nil
)
return
}
for
item
in
result
.
data
{
item
.
calHeightParam
()
}
func
searchArticleList
(
_
title
:
String
,
isFirstPage
:
Bool
,
callBackBlock
:
@escaping
(
_
success
:
Bool
,
_
error
:
YHErrorModel
?)
->
())
{
var
params
:
[
String
:
Any
]
=
[:]
if
isFirstPage
{
curPageIndex
=
1
params
=
[
"page"
:
curPageIndex
,
"page_size"
:
10
,
"title"
:
title
]
}
else
{
params
=
[
"page"
:
curPageIndex
+
1
,
"page_size"
:
10
,
"title"
:
title
]
}
let
strUrl
=
YHBaseUrlManager
.
shared
.
curURL
()
+
YHAllApiName
.
Common
.
article
let
_
=
YHNetRequest
.
getRequest
(
url
:
strUrl
,
params
:
params
)
{
[
weak
self
]
json
,
code
in
guard
let
self
=
self
else
{
return
}
//1. json字符串 转 对象
if
json
.
code
==
200
{
let
dic
=
json
.
data
guard
let
result
=
YHHomeListTotalModel
.
deserialize
(
from
:
dic
as?
Dictionary
)
else
{
self
.
arrHomeNewsData
=
[]
callBackBlock
(
false
,
nil
)
return
}
for
item
in
result
.
data
{
item
.
calHeightParam
()
}
if
isFirstPage
{
self
.
totalCount
=
result
.
total
self
.
arrHomeNewsData
=
result
.
data
c
allBackBlock
(
true
,
nil
)
c
urPageIndex
=
1
}
else
{
let
error
:
YHErrorModel
=
YHErrorModel
(
errorCode
:
Int32
(
json
.
code
),
errorMsg
:
json
.
msg
)
callBackBlock
(
false
,
error
)
curPageIndex
=
curPageIndex
+
1
self
.
arrHomeNewsData
?
.
append
(
contentsOf
:
result
.
data
)
}
if
let
count
=
self
.
arrHomeNewsData
?
.
count
{
if
count
==
self
.
totalCount
{
self
.
hasMoreForHomeNews
=
false
}
else
{
self
.
hasMoreForHomeNews
=
true
}
}
}
failBlock
:
{
err
in
callBackBlock
(
true
,
nil
)
callBackBlock
(
false
,
err
)
}
else
{
self
.
arrHomeNewsData
=
[]
let
error
:
YHErrorModel
=
YHErrorModel
(
errorCode
:
Int32
(
json
.
code
),
errorMsg
:
json
.
msg
)
callBackBlock
(
false
,
error
)
}
}
failBlock
:
{
err
in
self
.
arrHomeNewsData
=
[]
callBackBlock
(
false
,
err
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment