fix(home): 修复健康资讯搜索功能及咨询栏目加载逻辑

搜索框从 TextView 改为 EditText 以支持键盘输入和搜索键触发,
搜索回调携带关键字参数透传到 H5 搜索页。健康咨询栏目从硬编码
categoryId=2 改为从栏目列表动态读取第二个栏目 ID。新增新疆项目
H5 基础地址方法修正生产环境 URL,健康知识 H5 路径回归使用
getHealthNewsH5BaseUrl 避免丢失 healthnewsweb 路径层级。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
zhanglei
2026-06-30 09:22:07 +08:00
co-authored by Claude Opus 4.7
parent bb23c00e9c
commit c33c76f732
5 changed files with 83 additions and 25 deletions
@@ -522,7 +522,7 @@ class HomeFragment :
// 健康知识 - 搜索 // 健康知识 - 搜索
mBinding.healthKnowledgeView.setOnSearchClickListener { mBinding.healthKnowledgeView.setOnSearchClickListener {
navigateToHealthKnowledgeSearch() navigateToHealthKnowledgeSearch(it)
} }
@@ -545,7 +545,6 @@ class HomeFragment :
onSuccess = { token -> onSuccess = { token ->
mHealthToken = token mHealthToken = token
loadCategories(token) loadCategories(token)
loadConsultationArticles(token)
}, },
onFailure = { /* Token 获取失败,静默处理 */ } onFailure = { /* Token 获取失败,静默处理 */ }
) )
@@ -566,6 +565,9 @@ class HomeFragment :
if (mKnowledgeCategories.isNotEmpty()) { if (mKnowledgeCategories.isNotEmpty()) {
loadKnowledgeArticles(mKnowledgeCategories[0].categoryId) loadKnowledgeArticles(mKnowledgeCategories[0].categoryId)
} }
if (categories.isNotEmpty() && categories.size >= 2) {
loadConsultationArticles(categories[1].categoryId)
}
}, },
onFailure = { /* 栏目加载失败,静默处理 */ } onFailure = { /* 栏目加载失败,静默处理 */ }
) )
@@ -584,15 +586,17 @@ class HomeFragment :
} }
} }
/** 加载健康咨询文章列表(categoryId=2 */ /** 加载健康咨询文章列表(categoryId */
private fun loadConsultationArticles(token: String) { private fun loadConsultationArticles(categoryId: Int) {
mHealthInfoRequest?.fetchArticleList( mHealthToken?.let { token ->
token, 2, mHealthInfoRequest?.fetchArticleList(
onSuccess = { articles-> token, categoryId,
mBinding.healthConsultationView.setArticles(articles) onSuccess = { articles ->
}, mBinding.healthConsultationView.setArticles(articles)
onFailure = { /* 文章加载失败,静默处理 */ } },
) onFailure = { /* 文章加载失败,静默处理 */ }
)
}
} }
/** 跳转文章详情 H5 */ /** 跳转文章详情 H5 */
@@ -618,14 +622,14 @@ class HomeFragment :
requireContext().startWebActivity(url, isFull = true, myTitle = "健康知识", hideStatus = true) requireContext().startWebActivity(url, isFull = true, myTitle = "健康知识", hideStatus = true)
} }
/** 跳转健康知识 搜索 */ /** 跳转健康知识 搜索 */
private fun navigateToHealthKnowledgeSearch() { private fun navigateToHealthKnowledgeSearch(key: String) {
val param = mViewModel.enCryptInfoUrl.value val param = mViewModel.enCryptInfoUrl.value
if (param.isNullOrEmpty()) { if (param.isNullOrEmpty()) {
mViewModel.getSysEnCryptInfo(UrlConfig.getHomeBankH5Url()) mViewModel.getSysEnCryptInfo(UrlConfig.getHomeBankH5Url())
showToast("网络错误") showToast("网络错误")
return return
} }
val url = "${UrlConfig.getHealthNewsSearchH5Url()}?param=$param" val url = "${UrlConfig.getHealthNewsSearchH5Url()}?param=$param&searchVal=$key"
requireContext().startWebActivity(url, isFull = true, myTitle = "搜索", hideStatus = true) requireContext().startWebActivity(url, isFull = true, myTitle = "搜索", hideStatus = true)
} }
@@ -41,7 +41,6 @@ object UrlConfig {
//手机银行 //手机银行
const val SECRET_KEY = "XJp3EHpcnwReXc1A" const val SECRET_KEY = "XJp3EHpcnwReXc1A"
private const val TEST_HOME_BANK_IP = "https://gstest.superwx.cn/" private const val TEST_HOME_BANK_IP = "https://gstest.superwx.cn/"
private const val PRODUCT_HOME_BANK_IP = "https://api-jkglpt.iosp.ydpt.tech/"
val baseUrlType: BaseUrlType = BaseUrlType.PRODUCT val baseUrlType: BaseUrlType = BaseUrlType.PRODUCT
@@ -82,7 +81,7 @@ object UrlConfig {
} }
BaseUrlType.PRODUCT -> { BaseUrlType.PRODUCT -> {
PRODUCT_HOME_BANK_IP PRODUCT_DEFAULT_IP_ADDRESS_REMOTE
} }
} }
} }
@@ -103,6 +102,18 @@ object UrlConfig {
} }
} }
fun getH5BaseXjUrl(baseUrlType: BaseUrlType = BaseUrlType.PRODUCT): String {
return when (baseUrlType) {
BaseUrlType.DEBUG, BaseUrlType.TEST -> {
TEST_HOME_BANK_IP
}
BaseUrlType.PRODUCT -> {
"$PRODUCT_H5_ADDRESS_REMOTE/hb/"
}
}
}
fun getBankH5Url(baseUrlType: BaseUrlType = BaseUrlType.PRODUCT): String { fun getBankH5Url(baseUrlType: BaseUrlType = BaseUrlType.PRODUCT): String {
return when (baseUrlType) { return when (baseUrlType) {
BaseUrlType.DEBUG, BaseUrlType.TEST-> { BaseUrlType.DEBUG, BaseUrlType.TEST-> {
@@ -129,7 +140,7 @@ object UrlConfig {
* 健康资讯 H5 页面基础地址 * 健康资讯 H5 页面基础地址
*/ */
fun getHealthNewsH5BaseUrl(): String { fun getHealthNewsH5BaseUrl(): String {
return getDefaultBankBaseUrl() + "healthnewsweb/" return getH5BaseXjUrl() + "healthnewsweb/"
} }
/** /**
@@ -2,10 +2,14 @@ package com.xjjk.healthyclients.view
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.KeyEvent
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.RelativeLayout import android.widget.RelativeLayout
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.sw.healthyclients.view.CustomToast
import com.xjjk.healthyclients.R import com.xjjk.healthyclients.R
import com.xjjk.healthyclients.adapter.HealthKnowledgeAdapter import com.xjjk.healthyclients.adapter.HealthKnowledgeAdapter
import com.xjjk.healthyclients.bean.home.ArticleBean import com.xjjk.healthyclients.bean.home.ArticleBean
@@ -31,7 +35,7 @@ class HealthKnowledgeView(context: Context?, attrs: AttributeSet?) :
private var mOnTabSelectedListener: ((CategoryBean) -> Unit)? = null private var mOnTabSelectedListener: ((CategoryBean) -> Unit)? = null
private var mOnItemClickListener: ((ArticleBean) -> Unit)? = null private var mOnItemClickListener: ((ArticleBean) -> Unit)? = null
private var mOnMoreClickListener: (() -> Unit)? = null private var mOnMoreClickListener: (() -> Unit)? = null
private var mOnSearchClickListener: (() -> Unit)? = null private var mOnSearchClickListener: ((String) -> Unit)? = null
init { init {
mBinding.rvList.layoutManager = LinearLayoutManager(mContext) mBinding.rvList.layoutManager = LinearLayoutManager(mContext)
@@ -48,8 +52,33 @@ class HealthKnowledgeView(context: Context?, attrs: AttributeSet?) :
} }
// 健康知识 - 搜索 // 健康知识 - 搜索
mBinding.searchView.root.setOnClickListener { mBinding.searchView.customSearchTv.setOnClickListener {
mOnSearchClickListener?.invoke() val toString = mBinding.searchView.customSearchEt.text.toString()
if (toString.isEmpty()) {
CustomToast.makeText(context, "请输入搜索内容", CustomToast.LENGTH_SHORT).show()
return@setOnClickListener
}
mOnSearchClickListener?.invoke(toString)
}
// 键盘搜索键监听
mBinding.searchView.customSearchEt.setOnEditorActionListener { _, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH
|| (event != null && event.keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_DOWN)
) {
val keyword = mBinding.searchView.customSearchEt.text.toString()
if (keyword.isEmpty()) {
CustomToast.makeText(context, "请输入搜索内容", CustomToast.LENGTH_SHORT).show()
return@setOnEditorActionListener true
}
// 隐藏键盘
val imm = context?.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
imm?.hideSoftInputFromWindow(mBinding.searchView.customSearchEt.windowToken, 0)
mOnSearchClickListener?.invoke(keyword)
true
} else {
false
}
} }
} }
@@ -60,6 +89,14 @@ class HealthKnowledgeView(context: Context?, attrs: AttributeSet?) :
fun setupTabs(categories: MutableList<CategoryBean>) { fun setupTabs(categories: MutableList<CategoryBean>) {
mCategoryList.clear() mCategoryList.clear()
mCategoryList.addAll(categories) mCategoryList.addAll(categories)
if (categories.isEmpty()) {
mBinding.tabLayout.visibility = GONE
mBinding.tvEmpty.visibility = VISIBLE
return
}
mBinding.tabLayout.visibility = VISIBLE
mBinding.tvEmpty.visibility = GONE
mBinding.tabLayout.removeAllTabs() mBinding.tabLayout.removeAllTabs()
val array = Array<String>(categories.size) { val array = Array<String>(categories.size) {
@@ -103,7 +140,7 @@ class HealthKnowledgeView(context: Context?, attrs: AttributeSet?) :
mOnMoreClickListener = listener mOnMoreClickListener = listener
} }
fun setOnSearchClickListener(listener: () -> Unit) { fun setOnSearchClickListener(listener: (keyword: String) -> Unit) {
mOnSearchClickListener = listener mOnSearchClickListener = listener
} }
} }
@@ -25,19 +25,25 @@
android:layout_marginLeft="@dimen/dp_17" android:layout_marginLeft="@dimen/dp_17"
android:src="@mipmap/ic_search" /> android:src="@mipmap/ic_search" />
<TextView
<EditText
android:id="@+id/custom_search_et" android:id="@+id/custom_search_et"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/dp_38" android:layout_marginLeft="@dimen/dp_38"
android:gravity="center_vertical" android:background="@null"
android:text="请输入关键字进行搜索"
android:longClickable="false" android:longClickable="false"
android:gravity="center_vertical"
android:hint="@string/search_hint"
android:maxLines="1" android:maxLines="1"
android:textColor="#B6B6B6" android:imeOptions="actionSearch"
android:singleLine="true"
android:textColor="@color/text_black_33"
android:textColorHint="#B6B6B6"
android:textSize="@dimen/txt13" /> android:textSize="@dimen/txt13" />
<com.allen.library.shape.ShapeTextView <com.allen.library.shape.ShapeTextView
android:id="@+id/custom_search_tv" android:id="@+id/custom_search_tv"
android:layout_width="55dp" android:layout_width="55dp"
@@ -27,7 +27,7 @@
android:layout_marginLeft="15dp" android:layout_marginLeft="15dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:ellipsize="end" android:ellipsize="end"
android:text="健康咨询" android:text="健康资讯"
android:textColor="@color/text_black_33" android:textColor="@color/text_black_33"
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" /> android:textStyle="bold" />