Kaynağa Gözat

feat(search): 添加搜索历史记录去重逻辑并优化跳转功能

- 在点击搜索按钮时,避免重复添加相同的搜索关键词到历史记录中
- 增加点击搜索历史项直接触发搜索的功能
- 为商品项添加跳转至详情页的路由导航
- 修复搜索页面样式问题,提升用户体验
zhangtao 1 hafta önce
ebeveyn
işleme
e4310cbc08

+ 2 - 2
src/subPack-xsb/commonTab/components/classfiy.vue

@@ -133,7 +133,7 @@ onMounted(() => {
       fixed
     >
       <template #left>
-        <view class="flex items-center">
+        <view class="flex items-center" @click="router.push({ name: 'xsb-search' })">
           <view
             class="h60rpx w-474rpx flex items-center justify-between border-2rpx border-[var(--them-color)] rounded-40rpx border-solid bg-white pr6rpx"
           >
@@ -247,7 +247,7 @@ onMounted(() => {
         <scroll-view
           :lower-threshold="10"
           :refresher-triggered="isTopLoading" :scroll-top="scrollTop"
-          :style="{ height: `calc(100vh - ${navHeight} - 700rpx)` }" enable-passive scroll-y scroll-with-animation scroll-anchoring refresher-enabled :throttle="false"
+          :style="{ height: `calc(100vh - ${navHeight} - 700rpx)` }" enable-passive scroll-with-animation scroll-y scroll-anchoring refresher-enabled :throttle="false"
           @refresherrefresh="handleSrollTop" @scrolltolower="handlScrollBottom"
         >
           <view v-if="productList.length" class="p20rpx">

+ 11 - 3
src/subPack-xsb/search/index.vue

@@ -1,4 +1,6 @@
 <script setup lang="ts">
+import router from '@/router'
+
 definePage({
   name: 'xsb-search',
   islogin: false,
@@ -34,7 +36,9 @@ function handleSearch() {
   data.value = []
   isSearch.value = true
   send()
-  searchList.value.push(searchText.value)
+  if (!searchList.value.includes(searchText.value)) {
+    searchList.value.push(searchText.value)
+  }
 }
 watch(() => searchText.value, () => {
   if (!searchText.value) {
@@ -62,6 +66,10 @@ function handleClearnSeachLocaData() {
     },
   })
 }
+function handleSearchText(text: string) {
+  searchText.value = text
+  handleSearch()
+}
 </script>
 
 <template>
@@ -90,7 +98,7 @@ function handleClearnSeachLocaData() {
             <wd-icon name="delete-thin" size="22px" @click="handleClearnSeachLocaData" />
           </view>
           <view class="mt20rpx flex flex-wrap items-center">
-            <view v-for="item in searchList" :key="item" class="mr16rpx flex items-center justify-center rounded-30rpx bg-#F6F6F6 px24rpx py10rpx">
+            <view v-for="item in searchList" :key="item" class="mr16rpx box-border flex items-center justify-center rounded-30rpx bg-#F6F6F6 px24rpx py10rpx text-28rpx" @click="handleSearchText(item)">
               {{ item }}
             </view>
           </view>
@@ -110,7 +118,7 @@ function handleClearnSeachLocaData() {
       </view>
     </view>
     <view v-if="isSearch" class="px24rpx pt20rpx">
-      <view v-for="item in data" :key="item.id" class="mb20rpx box-border flex items-center justify-between rounded-16rpx bg-white p24rpx">
+      <view v-for="item in data" :key="item.id" class="mb20rpx box-border flex items-center justify-between rounded-16rpx bg-white p24rpx" @click="router.push({ name: 'xsb-goods', params: { id: item.id } })">
         <image
           :src="item.pic"
           class="h200rpx w200rpx flex-shrink-0 rounded-16rpx"