فهرست منبع

朋友搜索也加上历史搜索功能

bayi 2 سال پیش
والد
کامیت
c058bef3e1

+ 6 - 5
pages/childClassify/index.js

@@ -99,19 +99,20 @@ Page({
     })
     if (!this.data.historySearch.includes(this.data.text)) {
       this.setData({
-        historySearch: [...this.data.historySearch, this.data.text]
+        historySearch: [...this.data.historySearch, this.data.text].slice(-10)
       })
     }
     this.setData({
       list,
+      nullList: list.length == 0
     })
-    wx.setStorageSync('search', this.data.historySearch)
+    wx.setStorageSync('search', this.data.historySearch.slice(-10))
   },
   historySearch({
     currentTarget
   }) {
     this.setData({
-      text: currentTarget.dataset.text
+      text: currentTarget.dataset.text,
     })
     this.search()
   },
@@ -122,9 +123,9 @@ Page({
       return item != currentTarget.dataset.text
     })
     this.setData({
-      historySearch: newList
+      historySearch: newList.slice(-10)
     })
-    wx.setStorageSync('search', newList)
+    wx.setStorageSync('search', newList.slice(-10))
   },
   goRead({
     currentTarget

+ 1 - 1
pages/childClassify/index.wxml

@@ -53,5 +53,5 @@
       <view class="goRead">去朗读</view>
     </view>
   </scroll-view>
-  <!-- <emptyBg wx:if="{{type=='search'&&list.length==0}}" message="没有找到想要的内容~"></emptyBg> -->
+  <emptyBg wx:if="{{text!=''&&nullList}}" message="没有找到想要的内容~"></emptyBg>
 </view>

+ 39 - 5
pages/searchFriend/index.js

@@ -5,12 +5,13 @@ import reachBottom from '~/mixins/reachBottom'
 Page({
   behaviors: [reachBottom],
   data: {
-    text: ''
+    text: '',
+    historySearch: []
   },
-  onLoad(options) {
-    list: []
-  },
-  onShow(){
+  onShow() {
+    this.setData({
+      historySearch: wx.getStorageSync('userSearch')
+    })
     this.resetData()
   },
   setSearch({
@@ -20,6 +21,39 @@ Page({
       text: detail.value
     })
   },
+  searchUser({
+    currentTarget
+  }) {
+    if (currentTarget.dataset.text) {
+      this.setData({
+        text: currentTarget.dataset.text
+      })
+    }
+    if (!this.data.text) {
+      this.setData({
+        list: [],
+      })
+      return
+    }
+    this.resetData()
+    if (!this.data.historySearch.includes(this.data.text)) {
+      this.setData({
+        historySearch: [...this.data.historySearch, this.data.text].slice(-10)
+      })
+    }
+    wx.setStorageSync('userSearch', this.data.historySearch)
+  },
+  deleteHistory({
+    currentTarget
+  }) {
+    let newList = this.data.historySearch.filter(item => {
+      return item != currentTarget.dataset.text
+    })
+    this.setData({
+      historySearch: newList.slice(-10)
+    })
+    wx.setStorageSync('userSearch', newList.slice(-10))
+  },
   loadMore() {
     if (!this.data.text) {
       return

+ 31 - 0
pages/searchFriend/index.less

@@ -33,6 +33,37 @@
     }
   }
 
+  .historyList {
+    padding: 80rpx 30rpx 0rpx;
+
+    .notes {
+      display: flex;
+      align-items: center;
+      justify-content: space-between;
+      padding: 30rpx 0rpx 14rpx;
+      border-bottom: 1rpx solid #DDDDDD;
+
+      .left {
+        display: flex;
+        align-items: center;
+        font-size: 28rpx;
+
+        .clock {
+          width: 34rpx;
+          height: 34rpx;
+          margin-right: 16rpx;
+        }
+      }
+
+      .delete {
+        color: #A4A4A5;
+        font-size: 50rpx;
+        line-height: 40rpx;
+        padding: 0rpx 20rpx;
+      }
+    }
+  }
+
   .box {
     padding-bottom: 20rpx;
     margin-top: 100rpx;

+ 16 - 2
pages/searchFriend/index.wxml

@@ -1,10 +1,24 @@
+<wxs src="../../utils/filter.wxs" module="filters" />
+
 <view class="searchFriend">
   <view class="searchBox">
-    <input class="input" confirm-type='send' placeholder="查找昵称/学号/手机号" bindinput="setSearch" bindconfirm='resetData' />
-    <view class="searchBtn" catchtap="resetData">
+    <input class="input" confirm-type='send' placeholder="查找昵称/学号/手机号" bindinput="setSearch" bindconfirm='searchUser'
+      value="{{text}}" />
+    <view class="searchBtn" catchtap="searchUser">
       <image src="/static/search-2.png" class="img" />
     </view>
   </view>
+  <view class="historyList" wx:if="{{text==''&&list.length==0}}">
+    <view class="notes" wx:for="{{historySearch}}" wx:key="index" data-text="{{item}}" bindtap="searchUser">
+      <view class="left">
+        <image src="/static/clock.png" class="clock" />
+        {{item}}
+      </view>
+      <view class="delete" data-text="{{item}}" catchtap="deleteHistory">
+        ×
+      </view>
+    </view>
+  </view>
   <view class="box">
     <view class="follow" wx:for="{{list}}" wx:key="index" data-uid='{{item.uid}}' bindtap="setFans">
       <view class="left">

+ 26 - 0
pages/searchFriend/index.wxss

@@ -27,6 +27,32 @@
   width: 24rpx;
   height: 24rpx;
 }
+.searchFriend .historyList {
+  padding: 80rpx 30rpx 0rpx;
+}
+.searchFriend .historyList .notes {
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  padding: 30rpx 0rpx 14rpx;
+  border-bottom: 1rpx solid #DDDDDD;
+}
+.searchFriend .historyList .notes .left {
+  display: flex;
+  align-items: center;
+  font-size: 28rpx;
+}
+.searchFriend .historyList .notes .left .clock {
+  width: 34rpx;
+  height: 34rpx;
+  margin-right: 16rpx;
+}
+.searchFriend .historyList .notes .delete {
+  color: #A4A4A5;
+  font-size: 50rpx;
+  line-height: 40rpx;
+  padding: 0rpx 20rpx;
+}
 .searchFriend .box {
   padding-bottom: 20rpx;
   margin-top: 100rpx;