|
|
@@ -1,5 +1,3 @@
|
|
|
-const hotTagData = require('../../data/hotTagData.js')
|
|
|
-const hotBarData = require('../../data/hotBarData.js')
|
|
|
const util = require('../../utils/util.js')
|
|
|
|
|
|
Page({
|
|
|
@@ -12,6 +10,7 @@ Page({
|
|
|
toggleEnable: true,
|
|
|
searchEnable: false,
|
|
|
searchText: '',
|
|
|
+ searched: false,
|
|
|
hotTagData: [],
|
|
|
hotBarData: [],
|
|
|
pageToken: 0,
|
|
|
@@ -23,14 +22,17 @@ Page({
|
|
|
update: function (e) {
|
|
|
this.setData({
|
|
|
searchText: e.detail.value,
|
|
|
+ searched: false,
|
|
|
searchResult: []
|
|
|
})
|
|
|
},
|
|
|
|
|
|
focus: function () {
|
|
|
- if (!this.data.toggleEnable || this.data.searchEnable) return
|
|
|
- this.data.toggleEnable = false
|
|
|
+ if (!this.data.toggleEnable || this.data.searchEnable) {
|
|
|
+ return
|
|
|
+ }
|
|
|
this.setData({
|
|
|
+ toggleEnable: false,
|
|
|
searchEnable: true
|
|
|
})
|
|
|
this.animate('.cancel-button', [{
|
|
|
@@ -55,11 +57,15 @@ Page({
|
|
|
},
|
|
|
|
|
|
blur: function () {
|
|
|
- if (this.data.searchText !== '') return
|
|
|
- this.cancel()
|
|
|
+ if (this.data.searchText === '') {
|
|
|
+ this.cancel()
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
search: function () {
|
|
|
+ if (this.data.searchText === '') {
|
|
|
+ return
|
|
|
+ }
|
|
|
let history = this.data.searchHistory
|
|
|
if (history === undefined) history = []
|
|
|
const index = history.indexOf(this.data.searchText)
|
|
|
@@ -71,6 +77,7 @@ Page({
|
|
|
}
|
|
|
history.splice(0, 0, this.data.searchText)
|
|
|
this.setData({
|
|
|
+ searched: true,
|
|
|
searchHistory: history
|
|
|
})
|
|
|
wx.setStorage({
|
|
|
@@ -142,10 +149,11 @@ Page({
|
|
|
},
|
|
|
|
|
|
cancel: function () {
|
|
|
- if (!this.data.toggleEnable || !this.data.searchEnable) return
|
|
|
- this.data.toggleEnable = false
|
|
|
+ if (!this.data.toggleEnable || !this.data.searchEnable) {
|
|
|
+ return
|
|
|
+ }
|
|
|
this.setData({
|
|
|
- searchText: '',
|
|
|
+ toggleEnable: false,
|
|
|
})
|
|
|
this.animate('.cancel-button', [{
|
|
|
opacity: 1
|
|
|
@@ -165,6 +173,8 @@ Page({
|
|
|
this.setData({
|
|
|
toggleEnable: true,
|
|
|
searchEnable: false,
|
|
|
+ searchText: '',
|
|
|
+ searched: false,
|
|
|
searchResult: []
|
|
|
})
|
|
|
}.bind(this), 200)
|