xuxueyang
2024-08-03 7a89892d6ac9c181febed610b62f1aeb8145099b
pages/home/components/home-search.vue
@@ -8,9 +8,15 @@
               </template>
            </u-input>
         </view>
      </view>
      <view class="m-t-12">
         <view class="title">搜索历史</view>
         <view class="title flex">
            <view class="m-l-0 m-r-a">搜索历史</view>
            <view class="bg-white desc-gray  text-center m-l-a m-r-0" @click.stop="clearHistory">
               一键清空
            </view>
         </view>
         <view class="m-t-12 flex flex-wrap-normal history-item-list">
            <view class="history-item" v-for="item of history" :key="item" @click="searchBy(item)">
               {{item}}
@@ -37,16 +43,25 @@
      },
      methods: {
         buttonSearchFlow() {
            var name = this.search_flow
            if (this.history.indexOf(name) >= 0) {
               this.history.splice(this.history.indexOf(name), 1)
            }
            this.history.unshift(name)
            if (this.history.length >= 10) {
               this.history.splice(this.history.length - 1, 1)
            }
            console.log('buttonSearchFlow')
            uni.navigateTo({
               url: '/sub_pages/customer/trade/list?name=' + this.search_flow
            })
         },
         async clearHistory() {
            await this.$message.confirm('是否清空历史记录')
            this.history = []
            this.$storage.setItem("cache_home_search", JSON.stringify(this.history))
         },
         searchBy(name) {
            if (this.history.indexOf(name) >= 0) {
               this.history.splice(this.history.indexOf(name), 1)