SearchPage.js 1.84 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
//index.js
//获取应用实例
var app = getApp()
Page({
data: {
selectHide: false,
inputValue: '',
getSearch: [],
modalHidden: true,
searching:false
},
onLoad: function () {
},
onShow: function () {
var getSearch = wx.getStorageSync('searchData');
this.setData({
getSearch: getSearch,
inputValue: ''
})
console.log('search is onshow', getSearch)
},
/*-------------------- 交互----------*/
// 设置缓存
setSearchStorage: function () {
let data;
let localStorageValue = [];
if (this.data.inputValue != '') {
//调用API从本地缓存中获取数据
var searchData = wx.getStorageSync('searchData') || []
searchData.push(this.data.inputValue)
wx.setStorageSync('searchData', searchData)
this.setData({
getSearch: searchData,
})
} else {
console.log('空白')
}
},
// 加载数据
loadData(){

},
/*-------------------- 交互----------*/
// 返回
back: function () {
wx.navigateBack({
})
},
// 清除输入框
clearInput: function () {
this.setData({
inputValue: ''
})
},
// 输入完成
inputEnd:function(e){
this.setData({
inputValue: e.detail.value,
searching: true
})
this.setSearchStorage()
},
// 清除所有历史
clearAll: function () {
wx.setStorageSync('searchData', [])
this.setData({
getSearch: [],
})
},
// 选择该项历史
selectThis: function (e) {
},
// 删除该项历史
deletThis: function (e) {
console.log(e)
var data = this.data.getSearch
data.splice(e.currentTarget.dataset.index,1)
this.setData({
getSearch: data
})
},
bindInput: function (e) {
this.setData({
inputValue: e.detail.value
})
console.log('bindInput' + this.data.inputValue)
}
})