diff --git a/pages/index/index.vue b/pages/index/index.vue index a8fb520..cb1ab02 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -3,9 +3,9 @@ - + 🔍 - + 输入关键词或粘贴商品标题 搜索 @@ -334,6 +334,11 @@ } }, methods: { + goSearch() { + uni.navigateTo({ + url: '/pages/search/search' + }); + }, getIndexData() { uni.request({ url: 'https://api.cmspro.haodanku.com/index/index?cid=qOstW90', diff --git a/pages/search/search.vue b/pages/search/search.vue index e8da74d..235da0c 100644 --- a/pages/search/search.vue +++ b/pages/search/search.vue @@ -7,10 +7,10 @@ - + 🔍 + confirm-type="search" @confirm="onSearch(keyword)" @focus="onInputFocus" :focus="true" /> 搜索 @@ -156,7 +156,7 @@ 热点资讯 - + {{ index + 1 }} {{ item.title }} @@ -204,14 +204,6 @@ } }, watch: { - keyword(val) { - // 清空输入框时回到默认视图 - if (!val) { - this.isSearching = false; - this.searchResults = []; - this.currentKeyword = ''; - } - }, activePlatform() { // 切换平台时若已有关键词,重新搜索 if (this.isSearching && this.currentKeyword) { @@ -277,6 +269,12 @@ } }); }, + onInputFocus() { + // 聚焦搜索框时切回推荐视图(保留已搜索结果与关键词,下次搜索仍可继续) + if (this.isSearching) { + this.isSearching = false; + } + }, onSearch(word) { if (!word || !word.trim()) { uni.showToast({ title: '请输入搜索内容', icon: 'none' }); @@ -396,6 +394,14 @@ url: `/pages/detail/detail?id=${id}` }); }, + onTopicClick(item) { + // 跳转到分类页:link 字段即 category_id(对应 category 页面的 cat_id) + const categoryId = item.link; + if (!categoryId) return; + uni.navigateTo({ + url: `/pages/category/category?cat_id=${categoryId}` + }); + }, clearHistory() { uni.showModal({ title: '提示',