Преглед на файлове

FEAT

提升页面加载速度
RegMs If преди 4 години
родител
ревизия
91f0bb6e3b

+ 6 - 0
cloudfunctions/getFavorite/config.json

@@ -0,0 +1,6 @@
+{
+  "permissions": {
+    "openapi": [
+    ]
+  }
+}

+ 24 - 0
cloudfunctions/getFavorite/index.js

@@ -0,0 +1,24 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+const db = cloud.database()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  const {
+    OPENID
+  } = cloud.getWXContext()
+
+  const favorite = await db.collection('favorite')
+    .where({
+      user_id: OPENID,
+      msg_id: event.msg_id
+    })
+    .count()
+
+  return {
+    total: favorite.total,
+    status: 'OK'
+  }
+}

+ 14 - 0
cloudfunctions/getFavorite/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "getFavorite",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "wx-server-sdk": "~2.4.0"
+  }
+}

+ 0 - 6
cloudfunctions/getMessage/index.js

@@ -30,12 +30,6 @@ exports.main = async (event, context) => {
   }
 
   message.list[0].publisher = message.list[0].publisher[0]
-  message.list[0].favorite = (await db.collection('favorite')
-    .where({
-      user_id: OPENID,
-      msg_id: event.msg_id
-    })
-    .count()).total === 1
 
   await db.collection('read')
     .add({

+ 4 - 4
miniprogram/components/imagePicker/imagePicker.wxml

@@ -1,14 +1,14 @@
 <!--components/imagePicker/imagePicker.wxml-->
 <view class="image-list">
-  <label wx:for="{{value}}" wx:for-item="item" wx:key="*this">
+  <label wx:for="{{value}}" wx:for-item="img" wx:key="*this">
     <image class="image"
       style="position: relative; margin: {{imageMargin}}rpx; width: {{imageWidth}}rpx; height: {{imageHeight}}rpx;"
-      src="{{item}}" mode="aspectFill" data-url="{{item}}" catchtap="previewImage">
+      src="{{img}}" mode="aspectFill" data-url="{{img}}" catchtap="previewImage">
       <icon wx:if="{{!readonly}}" style="position: absolute; top: 0; left: 0;" type="cancel" size="20"
-        data-url="{{item}}" catchtap="removeImage"></icon>
+        data-url="{{img}}" catchtap="removeImage"></icon>
     </image>
   </label>
   <image wx:if="{{value.length < max && !readonly}}" class="image"
-    style="margin: {{imageMargin}}rpx; width: 150rpx; height: 150rpx;" src="/images/add.png" mode="aspectFill"
+    style="margin: {{imageMargin}}rpx; width: 145rpx; height: 145rpx;" src="/images/add.png" mode="aspectFill"
     catchtap="addImage"></image>
 </view>

+ 18 - 3
miniprogram/components/itemCard/itemCard.js

@@ -17,7 +17,7 @@ Component({
    * 组件的初始数据
    */
   data: {
-
+    show: true
   },
 
   /**
@@ -26,13 +26,28 @@ Component({
   methods: {
     getPublisherInfo: function () {
       wx.navigateTo({
-        url: '/pages/publisher/publisher?id=' + this.data.item.pub_id
+        url: '/pages/publisher/publisher',
+      }).then(res => {
+        res.eventChannel.emit('loadCommonData', {
+          data: this.data.item.publisher
+        })
       })
     },
 
     getActivityInfo: function () {
       wx.navigateTo({
-        url: '/pages/activity/activity?id=' + this.data.item._id
+        url: '/pages/activity/activity',
+        events: {
+          deleteMessage: () => {
+            this.setData({
+              show: false
+            })
+          }
+        }
+      }).then(res => {
+        res.eventChannel.emit('loadCommonData', {
+          data: this.data.item
+        })
       })
     },
 

+ 2 - 2
miniprogram/components/itemCard/itemCard.wxml

@@ -1,5 +1,5 @@
 <!-- 为首页消息通知的组件,数据在mainData.js -->
-<view class="card" bindtap="getActivityInfo">
+<view wx:if="{{show}}" class="card" bindtap="getActivityInfo">
   <view class="profile">
     <view class="avatar-name" catchtap="getPublisherInfo">
       <image class="publisher-avatar" src="{{item.publisher.avatar}}" mode="aspectFill"></image>
@@ -21,7 +21,7 @@
     image-height="{{item.photo.length === 1 ? 330 : item.photo.length <= 4 ? 330 : 220}}" readonly />
   <view class="bottom-line">
     <view class="tags primary-text-color">
-      <text class="tag" wx:for="{{item.tag}}" wx:for-item="tag" wx:key="_id" data-tag="{{tag}}"
+      <text class="tag" wx:for="{{item.tag}}" wx:for-item="tag" wx:key="*this" data-tag="{{tag}}"
         catchtap="filterTag">{{tag}}</text>
     </view>
     <view class="to-detail">

+ 82 - 46
miniprogram/pages/activity/activity.js

@@ -10,6 +10,7 @@ Page({
     messageId: '',
     activityInfo: {},
     like: false,
+    likeDisabled: true,
     showEdit: false,
     pageToken: 0,
     activityComment: [],
@@ -18,7 +19,11 @@ Page({
 
   getPublisherInfo: function () {
     wx.navigateTo({
-      url: '/pages/publisher/publisher?id=' + this.data.activityInfo.pub_id
+      url: '/pages/publisher/publisher',
+    }).then(res => {
+      res.eventChannel.emit('loadCommonData', {
+        data: this.data.item.publisher
+      })
     })
   },
 
@@ -52,10 +57,13 @@ Page({
               })
               return
             }
+            wx.navigateBack()
+            const eventChannel = this.getOpenerEventChannel()
+            eventChannel.emit('deleteMessage')
             wx.showToast({
               title: "删除成功",
+              icon: 'none'
             })
-            wx.navigateBack()
           })
         }
       }.bind(this)
@@ -63,6 +71,9 @@ Page({
   },
 
   toggleLike: function () {
+    if (this.data.likeDisabled) {
+      return
+    }
     wx.showLoading({
       title: this.data.like ? '取消收藏' : '收藏中'
     })
@@ -90,30 +101,55 @@ Page({
     })
   },
 
-  loadQuestionData: function () {
-    wx.showNavigationBarLoading()
-    wx.cloud.callFunction({
+  processCommonData: function (data) {
+    let edit = false
+    for (let i = 0; i < app.globalData.pubInfo.length; i++) {
+      if (data.pub_id === app.globalData.pubInfo[i].pub_id) {
+        edit = true
+      }
+    }
+    this.setData({
+      activityInfo: data,
+      showEdit: edit
+    })
+  },
+
+  loadExtraData: function () {
+    wx.showLoading({
+      title: '加载中'
+    })
+    const arr = []
+    arr.push(wx.cloud.callFunction({
       name: 'listQuestions',
       data: {
         msg_id: this.data.messageId,
         page_token: this.data.pageToken,
         page_size: 25
       }
-    }).then(res => {
-      wx.hideNavigationBarLoading()
-      if (res.result.status !== 'OK') {
+    }))
+    arr.push(wx.cloud.callFunction({
+      name: 'getFavorite',
+      data: {
+        msg_id: this.data.messageId
+      }
+    }))
+    Promise.all(arr).then(res => {
+      wx.hideLoading()
+      if (res[0].result.status !== 'OK' || res[1].result.status !== 'OK') {
         wx.showToast({
-          title: res.result.errMsg,
+          title: res[0].result.errMsg || res[1].result.errMsg,
           icon: 'none'
         })
         return
       }
-      for (let i = 0; i < res.result.list.length; i++) {
-        res.result.list[i].a_time = util.handleDate(res.result.list[i].a_time)
+      for (let i = 0; i < res[0].result.list.length; i++) {
+        res[0].result.list[i].a_time = util.handleDate(res[0].result.list[i].a_time)
       }
       this.setData({
-        activityComment: this.data.activityComment.concat(res.result.list),
-        pageToken: res.result.next_page_token
+        activityComment: this.data.activityComment.concat(res[0].result.list),
+        pageToken: res[0].result.next_page_token,
+        like: res[1].result.total === 1,
+        likeDisabled: false
       })
     })
   },
@@ -158,41 +194,41 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    this.setData({
-      messageId: options.id
-    })
-
-    wx.showLoading({
-      title: '加载中'
-    })
-    wx.cloud.callFunction({
-      name: 'getMessage',
-      data: {
-        msg_id: this.data.messageId
-      }
-    }).then(res => {
-      wx.hideLoading()
-      if (res.result.status !== 'OK') {
-        wx.showToast({
-          title: res.result.errMsg,
-          icon: 'none'
-        })
-        return
-      }
-      res.result.data = util.dbToMsg(res.result.data)
-      let edit = false
-      for (let i = 0; i < app.globalData.pubInfo.length; i++) {
-        if (res.result.data.pub_id === app.globalData.pubInfo[i].pub_id) {
-          edit = true
-        }
-      }
+    if (options.id) {
       this.setData({
-        activityInfo: res.result.data,
-        like: res.result.data.favorite,
-        showEdit: edit
+        messageId: options.id
       })
-      this.loadQuestionData()
-    })
+      wx.showLoading({
+        title: '加载中'
+      })
+      wx.cloud.callFunction({
+        name: 'getMessage',
+        data: {
+          msg_id: this.data.messageId
+        }
+      }).then(res => {
+        wx.hideLoading()
+        if (res.result.status !== 'OK') {
+          wx.showToast({
+            title: res.result.errMsg,
+            icon: 'none'
+          })
+          return
+        }
+        res.result.data = util.dbToMsg(res.result.data)
+        this.processCommonData(res.result.data)
+        this.loadExtraData()
+      })
+    } else {
+      const eventChannel = this.getOpenerEventChannel()
+      eventChannel.on('loadCommonData', res => {
+        this.setData({
+          messageId: res.data._id,
+        })
+        this.processCommonData(res.data)
+        this.loadExtraData()
+      })
+    }
   },
 
   /**

+ 4 - 4
miniprogram/pages/activity/activity.wxml

@@ -11,7 +11,7 @@
             <view class="publisher-name">{{activityInfo.publisher.name}}</view>
           </view>
           <view class="activity-attribute primary-background-color white-text-color">
-            {{activityInfo.type}}
+            {{activityInfo.type[0]}}
           </view>
         </view>
 
@@ -28,7 +28,7 @@
         <view wx:if="{{activityInfo.time}}" class="text">时间:{{activityInfo.time}}</view>
         <view wx:if="{{activityInfo.place}}" class="text">地点:{{activityInfo.place}}</view>
         <view wx:if="{{activityInfo.tag.length}}" class="text">活动提供:<text wx:for="{{activityInfo.tag}}"
-            wx:for-item="tag" wx:key="tag">{{tag}} </text></view>
+            wx:for-item="tag" wx:key="*this">{{tag}} </text></view>
         <view wx:if="{{activityInfo.orient}}" class="text">面向对象:{{activityInfo.orient}}</view>
         <view wx:if="{{activityInfo.contact}}" class="text">联系方式:{{activityInfo.contact}}</view>
         <view wx:if="{{activityInfo.link}}" class="text">链接:{{activityInfo.link}}</view>
@@ -52,8 +52,8 @@
     <view class="message-block">
       <view class="title2">{{activityComment.length == 0 ? "暂无问答" : "答疑区:"}}</view>
       <image class="like" src="/images/like/{{like ? 'heart' : 'hollowheart'}}.png" catchtap="toggleLike" />
-      <view class="card1" wx:for="{{activityComment}}" wx:for-item="item" wx:key="_id">
-        <itemActivityComment comment="{{item}}" />
+      <view class="card1" wx:for="{{activityComment}}" wx:for-item="comm" wx:key="_id">
+        <itemActivityComment comment="{{comm}}" />
       </view>
     </view>
   </scroll-view>

+ 2 - 2
miniprogram/pages/activityPublish/activityPublish.wxml

@@ -22,7 +22,7 @@
     <view class="block">
       <view class="cate" style="align-self: flex-start;">活动类型<span style="color: #FF0000">*</span></view>
       <checkbox-group class="checkbox-group" name="type">
-        <label wx:for="{{types1}}" wx:for-item="item" wx:key="item.value">
+        <label wx:for="{{types1}}" wx:for-item="item" wx:key="value">
           <checkbox class="checkbox" value="{{item.value}}" checked="{{item.checked}}" color="#469298">{{item.value}}
           </checkbox>
         </label>
@@ -49,7 +49,7 @@
     <view class="block">
       <view class="cate" style="align-self: flex-start;">活动提供</view>
       <checkbox-group class="checkbox-group" name="tag">
-        <label wx:for="{{types2}}" wx:for-item="item" wx:key="item.value">
+        <label wx:for="{{types2}}" wx:for-item="item" wx:key="value">
           <checkbox class="checkbox" value="{{item.value}}" checked="{{item.checked}}" color="#469298">
             {{item.value}}</checkbox>
         </label>

+ 10 - 10
miniprogram/pages/main/main.wxml

@@ -23,13 +23,13 @@
         <view class="filter-list-title primary-text-color">{{item.title}}</view>
         <view wx:for="{{item.children}}" wx:for-item="item" wx:key="title">
           <view wx:if="{{!item.children}}" class="filter-list-item secondary-text-color" data-filter-list="1"
-            data-filter-item="{{item}}" bindtap="toggleFilterItem">{{item}}<view wx:if="{{filterItem[1] == item}}">✔
+            data-filter-item="{{item}}" bindtap="toggleFilterItem">{{item}}<view wx:if="{{filterItem[1] === item}}">✔
             </view>
           </view>
-          <view class="filter-list-subtitle primary-text-color" wx:if="{{item.children}}">{{item.title}}</view>
+          <view wx:if="{{item.children}}" class="filter-list-subtitle primary-text-color">{{item.title}}</view>
           <view class="filter-list-item secondary-text-color" wx:for="{{item.children}}" wx:for-item="title"
-            wx:key="title" data-filter-list="1" data-filter-item="{{title}}" bindtap="toggleFilterItem">{{title}}<view
-              wx:if="{{filterItem[1] == title}}">✔</view>
+            wx:key="*this" data-filter-list="1" data-filter-item="{{title}}" bindtap="toggleFilterItem">{{title}}<view
+              wx:if="{{filterItem[1] === title}}">✔</view>
           </view>
         </view>
       </view>
@@ -37,21 +37,21 @@
     <view class="filter-list"></view>
     <view wx:if="{{filterList == 2}}" class="filter-list" id="list2">
       <view class="filter-list-item secondary-text-color" wx:for="{{filterName[2].children}}" wx:for-item="title"
-        wx:key="title" data-filter-list="2" data-filter-item="{{title}}" bindtap="toggleFilterItem">{{title}}<view
-          wx:if="{{filterItem[2] == title}}">✔</view>
+        wx:key="*this" data-filter-list="2" data-filter-item="{{title}}" bindtap="toggleFilterItem">{{title}}<view
+          wx:if="{{filterItem[2] === title}}">✔</view>
       </view>
     </view>
     <view class="filter-list"></view>
     <view wx:if="{{filterList == 3}}" class="filter-list" id="list3">
       <view class="filter-list-item secondary-text-color" wx:for="{{filterName[3].children}}" wx:for-item="title"
-        wx:key="title" data-filter-list="3" data-filter-item="{{title}}" bindtap="toggleFilterItem">{{title}}<view
-          wx:if="{{filterItem[3] == title}}">✔</view>
+        wx:key="*this" data-filter-list="3" data-filter-item="{{title}}" bindtap="toggleFilterItem">{{title}}<view
+          wx:if="{{filterItem[3] === title}}">✔</view>
       </view>
     </view>
   </view>
   <view style="margin-top: 60rpx;">
-    <view wx:for="{{mainDatas}}" wx:for-item="item" wx:key="_id">
-      <itemCard wx:if="{{item.show}}" item="{{item}}" bindfiltermsgtype="filterMsgType" bindfiltertag="filterTag" />
+    <view wx:for="{{mainDatas}}" wx:for-item="msg" wx:key="_id">
+      <itemCard wx:if="{{msg.show}}" item="{{msg}}" bindfiltermsgtype="filterMsgType" bindfiltertag="filterTag" />
     </view>
   </view>
 </view>

+ 2 - 2
miniprogram/pages/message/message.wxml

@@ -1,7 +1,7 @@
 <!-- 为消息的导航栏 两个component界面:“关注动态”followNews “我的消息”myNews-->
 <!-- 修改:将关注动态转移到首页,消息页面删除导航栏-->
 <view class="page">
-  <view class="card" wx:for="{{newNews}}" wx:for-item="item" wx:key="id" wx:index="index">
-    <itemmyNews item="{{item}}"/>
+  <view class="card" wx:for="{{newNews}}" wx:for-item="item" wx:key="_id" wx:index="index">
+    <itemmyNews item="{{item}}" />
   </view>
 </view>

+ 39 - 55
miniprogram/pages/publisher/publisher.js

@@ -20,8 +20,10 @@ Page({
     })
   },
 
-  loadMessageData: function () {
-    wx.showNavigationBarLoading()
+  loadExtraData: function () {
+    wx.showLoading({
+      title: '加载中'
+    })
     wx.cloud.callFunction({
       name: 'listMessages',
       data: {
@@ -30,7 +32,7 @@ Page({
         page_size: 25
       }
     }).then(res => {
-      wx.hideNavigationBarLoading()
+      wx.hideLoading()
       if (res.result.status !== 'OK') {
         wx.showToast({
           title: res.result.errMsg,
@@ -105,60 +107,42 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    this.setData({
-      publisherId: options.id
-    })
-
-    wx.showLoading({
-      title: "加载中"
-    })
-    wx.cloud.callFunction({
-      name: 'getPublisher',
-      data: {
-        pub_id: this.data.publisherId
-      }
-    }).then(res => {
-      wx.hideLoading()
-      if (res.result.status !== 'OK') {
-        wx.showToast({
-          title: res.result.errMsg,
-          icon: 'none'
-        })
-        return
-      }
+    if (options.id) {
       this.setData({
-        publisherInfo: res.result.data
+        publisherId: options.id
       })
-      this.loadMessageData()
-    })
-
-
-
-    // const db = wx.cloud.database()
-    // db.collection("publisherInfoData").doc(options.id).get({
-    //   success: function (res) {
-    //     this.setData({
-    //       publisherInfo: res.data
-    //     })
-    //     db.collection("mainData").where({
-    //       publisherName: this.data.publisherInfo.publisherName
-    //     }).orderBy("time", "desc").limit(20).get({
-    //       success: function (res) {
-    //         this.processData(0, res.data)
-    //       }.bind(this)
-    //     })
-    //   }.bind(this)
-    // })
-    // db.collection("likeData").where({
-    //   type: "publisher",
-    //   id: options.id
-    // }).get({
-    //   success: function (res) {
-    //     this.setData({
-    //       like: res.data.length
-    //     })
-    //   }.bind(this)
-    // })
+      wx.showLoading({
+        title: "加载中"
+      })
+      wx.cloud.callFunction({
+        name: 'getPublisher',
+        data: {
+          pub_id: this.data.publisherId
+        }
+      }).then(res => {
+        wx.hideLoading()
+        if (res.result.status !== 'OK') {
+          wx.showToast({
+            title: res.result.errMsg,
+            icon: 'none'
+          })
+          return
+        }
+        this.setData({
+          publisherInfo: res.result.data
+        })
+        this.loadExtraData()
+      })
+    } else {
+      const eventChannel = this.getOpenerEventChannel()
+      eventChannel.on('loadCommonData', res => {
+        this.setData({
+          publisherId: res.data._id,
+          publisherInfo: res.data
+        })
+        this.loadExtraData()
+      })
+    }
   },
 
   /**

+ 2 - 2
miniprogram/pages/publisher/publisher.wxml

@@ -18,6 +18,6 @@
   </view>
 </view>
 
-<view class="card" wx:for="{{mainDatas}}" wx:for-item="item" wx:key="_id">
-  <itemCard item="{{item}}" />
+<view class="card" wx:for="{{mainDatas}}" wx:for-item="msg" wx:key="_id">
+  <itemCard item="{{msg}}" />
 </view>

+ 4 - 4
miniprogram/pages/publisherLogin/publisherLogin.wxml

@@ -47,8 +47,8 @@
     <view class="block">
       <view class="cate" style="align-self: flex-start;">组织类型<span style="color: #FF0000">*</span></view>
       <radio-group class="radio-group" name="level">
-        <label wx:for="{{types}}" wx:for-item="item" wx:key="*this">
-          <radio class="radio" value="{{item}}" color="#469298">{{item}}</radio>
+        <label wx:for="{{types}}" wx:for-item="type" wx:key="*this">
+          <radio class="radio" value="{{type}}" color="#469298">{{type}}</radio>
         </label>
       </radio-group>
     </view>
@@ -94,8 +94,8 @@
     <view class="block">
       <view class="cate" style="align-self: flex-start;">社团星级<span style="color: #FF0000">*</span></view>
       <radio-group class="radio-group" name="level">
-        <label wx:for="{{stars}}" wx:for-item="item" wx:key="*this">
-          <radio class="radio" value="{{item}}" color="#469298">{{item}}</radio>
+        <label wx:for="{{stars}}" wx:for-item="star" wx:key="*this">
+          <radio class="radio" value="{{star}}" color="#469298">{{star}}</radio>
         </label>
       </radio-group>
     </view>

+ 5 - 1
miniprogram/pages/publisherPage/publisherPage.js

@@ -15,7 +15,11 @@ Page({
 
   publisherHome: function () {
     wx.navigateTo({
-      url: "/pages/publisher/publisher?id=" + this.data.pubInfo[this.data.pubIndex].pub_id,
+      url: '/pages/publisher/publisher',
+    }).then(res => {
+      res.eventChannel.emit('loadCommonData', {
+        data: this.data.pubInfo[this.data.pubIndex]
+      })
     })
   },
 

+ 11 - 11
miniprogram/pages/search/search.wxml

@@ -12,23 +12,23 @@
   <view class="hot-tag-block">
     <view class="hot-tag-title primary-text-color">历史搜索</view>
     <view class="hot-tags secondary-text-color">
-      <view class="hot-tag" wx:for="{{searchHistory}}" wx:key="*this" wx:for-item="item" data-search-tag="{{item}}"
-        bindtap="searchTag">{{item}}</view>
+      <view class="hot-tag" wx:for="{{searchHistory}}" wx:for-item="keyword" wx:key="*this"
+        data-search-tag="{{keyword}}" bindtap="searchTag">{{keyword}}</view>
     </view>
   </view>
 
   <view class="hot-tag-block">
     <view class="hot-tag-title primary-text-color">热门搜索</view>
     <view class="hot-tags secondary-text-color">
-      <view class="hot-tag" wx:for="{{hotTagData}}" wx:key="tag" wx:for-item="item" data-search-tag="{{item.tag}}"
+      <view class="hot-tag" wx:for="{{hotTagData}}" wx:for-item="item" wx:key="tag" data-search-tag="{{item.tag}}"
         bindtap="searchTag">{{item.tag}}</view>
     </view>
   </view>
 
   <view class="hot-bar-block">
     <text class="hot-bar-title primary-background-color white-text-color">实时热点</text>
-    <view class="hot-bar" wx:for="{{hotBarData}}" wx:key="rank" wx:for-item="item" data-activity-id="{{item.id}}"
-      bindtap="viewActivity">
+    <view class="hot-bar" wx:for="{{hotBarData}}" wx:key="rank" wx:for-item="item" wx:key="_id"
+      data-activity-id="{{item._id}}" bindtap="viewActivity">
       <view>
         <text class="primary-text-color" space="nbsp">{{item.rank}}{{" "}}{{" "}}{{" "}}</text><text
           class="secondary-text-color">{{item.title}}</text>
@@ -39,12 +39,12 @@
 </scroll-view>
 
 <scroll-view wx:if="{{searchEnable}}" class="search-block secondary-background-color" scroll-y bindtap="blur">
-  <view class="result-bar" wx:for="{{searchResult}}" wx:for-item="item" wx:key="_id">
-    <itemCard item="{{item}}" />
+  <view class="result-bar" wx:for="{{searchResult}}" wx:for-item="msg" wx:key="_id">
+    <itemCard item="{{msg}}" />
   </view>
-  <view wx:if="{{searchText == '' && searchResult.length == 0}}" wx:for="{{searchHistory}}" wx:for-item="item"
-    wx:key="*this" class="search-history" data-history="{{item}}" catchtap="searchAgain">
-    <view>{{item}}</view>
-    <view data-history="{{item}}" catchtap="removeHistory">×</view>
+  <view wx:if="{{searchText == '' && searchResult.length == 0}}" wx:for="{{searchHistory}}" wx:for-item="keyword"
+    wx:key="*this" class="search-history" data-history="{{keyword}}" catchtap="searchAgain">
+    <view>{{keyword}}</view>
+    <view data-history="{{keyword}}" catchtap="removeHistory">×</view>
   </view>
 </scroll-view>