riku
2022-08-11 5656daeb79c6d4d3f9fc78f981c7faf96582d2f1
pages/module_consult/consultsearch/consultsearch.js
@@ -11,7 +11,7 @@
    placeholder: '搜索',
    value: '',
    histroy: [],
    history: [],
    hotTopic: [],
  },
@@ -69,13 +69,29 @@
      },
    })
    
    if (this.data.histroy.indexOf(this.data.value) == -1) {
      this.data.histroy.unshift(this.data.value)
    if (this.data.history.indexOf(this.data.value) == -1) {
      let h = this.data.history
      h.unshift(this.data.value)
      if (h.length > 10) {
        h = h.slice(0, 10)
      }
      this.setData({
        history: h
      })
      wx.setStorage({
        data: JSON.stringify(this.data.histroy),
        data: JSON.stringify(h),
        key: 'search_history',
      })
    }
  },
  selectHistory (e) {
    var i = e.currentTarget.dataset.index
    var kw = this.data.history[i]
    this.setData({
      value: kw
    })
    this.search()
  },
  /**
@@ -88,7 +104,7 @@
      success: (res) => {
        let h = JSON.parse(res.data)
        that.setData({
          histroy: h
          history: h
        })
      },
    })
@@ -107,4 +123,18 @@
      }
    })
  },
  gotoDetail (e) {
    var i = e.currentTarget.dataset.index
    var fileId = this.data.hotTopic[i].id
    wx.navigateTo({
      url: '/pages/module_consult/consultdetail/consultdetail',
      success: (res) => {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          fileId: fileId
        })
      },
    })
  }
})