|
|
@@ -18,45 +18,6 @@ Page({
|
|
|
searchHistory: []
|
|
|
},
|
|
|
|
|
|
- onLoad: function () {
|
|
|
- wx.getStorage({
|
|
|
- key: 'searchHistory',
|
|
|
- success: function (res) {
|
|
|
- this.setData({
|
|
|
- searchHistory: res.data
|
|
|
- })
|
|
|
- }.bind(this)
|
|
|
- })
|
|
|
- const db = wx.cloud.database()
|
|
|
- db.collection('search').orderBy('time', 'desc').limit(20).get({
|
|
|
- success: function (res) {
|
|
|
- var count = {},
|
|
|
- hotTag = []
|
|
|
- for (let j = 0; j < res.data.length; j++) {
|
|
|
- if (count[res.data[j].key] == undefined) {
|
|
|
- count[res.data[j].key] = 0
|
|
|
- }
|
|
|
- count[res.data[j].key]++
|
|
|
- }
|
|
|
- for (let key in count) {
|
|
|
- hotTag.push({
|
|
|
- tag: key
|
|
|
- })
|
|
|
- }
|
|
|
- hotTag.sort(function (a, b) {
|
|
|
- return count[b] - count[a]
|
|
|
- })
|
|
|
- hotTag.splice(10)
|
|
|
- this.setData({
|
|
|
- hotTagData: hotTag
|
|
|
- })
|
|
|
- }.bind(this)
|
|
|
- })
|
|
|
- this.setData({
|
|
|
- hotBarData: hotBarData.hotBarData
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
update: function (e) {
|
|
|
this.setData({
|
|
|
searchText: e.detail.value,
|
|
|
@@ -97,18 +58,16 @@ Page({
|
|
|
},
|
|
|
|
|
|
search: function () {
|
|
|
- var history = this.data.searchHistory
|
|
|
+ let history = this.data.searchHistory
|
|
|
if (history === undefined) history = []
|
|
|
- for (let i = 0; i < history.length; i++) {
|
|
|
- if (history[i] == this.data.searchText) {
|
|
|
- history.splice(i, 1)
|
|
|
- break
|
|
|
- }
|
|
|
+ const index = history.indexOf(this.data.searchText)
|
|
|
+ if (index !== -1) {
|
|
|
+ history.splice(index, 1)
|
|
|
}
|
|
|
if (history.length > 9) {
|
|
|
history.splice(9, history.length - 9)
|
|
|
}
|
|
|
- history = [this.data.searchText].concat(history)
|
|
|
+ history.splice(0, 0, this.data.searchText)
|
|
|
this.setData({
|
|
|
searchHistory: history
|
|
|
})
|
|
|
@@ -175,28 +134,18 @@ Page({
|
|
|
|
|
|
searchTag: function (e) {
|
|
|
this.setData({
|
|
|
- searchText: e.target.dataset.searchTag
|
|
|
- })
|
|
|
- this.focus()
|
|
|
- this.search()
|
|
|
- },
|
|
|
-
|
|
|
- searchAgain: function (e) {
|
|
|
- this.setData({
|
|
|
- searchText: e.target.dataset.history
|
|
|
+ searchText: e.currentTarget.dataset.searchTag
|
|
|
})
|
|
|
this.focus()
|
|
|
this.search()
|
|
|
},
|
|
|
|
|
|
removeHistory: function (e) {
|
|
|
- var history = this.data.searchHistory
|
|
|
+ let history = this.data.searchHistory
|
|
|
if (history === undefined) history = []
|
|
|
- for (let i = 0; i < history.length; i++) {
|
|
|
- if (history[i] == e.target.dataset.history) {
|
|
|
- history.splice(i, 1)
|
|
|
- break
|
|
|
- }
|
|
|
+ const index = history.indexOf(e.currentTarget.dataset.searchTag)
|
|
|
+ if (index !== -1) {
|
|
|
+ history.splice(index, 1)
|
|
|
}
|
|
|
this.setData({
|
|
|
searchHistory: history
|
|
|
@@ -209,7 +158,56 @@ Page({
|
|
|
|
|
|
viewActivity: function (e) {
|
|
|
wx.navigateTo({
|
|
|
- url: '/pages/activity/activity?id=' + e.target.dataset.activityId
|
|
|
+ url: '/pages/activity/activity'
|
|
|
+ }).then(res => {
|
|
|
+ res.eventChannel.emit('loadCommonData', {
|
|
|
+ data: e.currentTarget.dataset.activity
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ loadHotData: function () {
|
|
|
+ wx.showNavigationBarLoading()
|
|
|
+ const arr = []
|
|
|
+ arr.push(wx.cloud.callFunction({
|
|
|
+ name: 'listSearches'
|
|
|
+ }))
|
|
|
+ arr.push(wx.cloud.callFunction({
|
|
|
+ name: 'listMessages',
|
|
|
+ data: {
|
|
|
+ hot: true
|
|
|
+ }
|
|
|
+ }))
|
|
|
+ Promise.all(arr).then(res => {
|
|
|
+ wx.hideNavigationBarLoading()
|
|
|
+ if (res[0].result.status !== 'OK' || res[1].result.status !== 'OK') {
|
|
|
+ wx.showToast({
|
|
|
+ title: res[0].result.errMsg || res[1].result.errMsg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for (let i = 0; i < res[1].result.list.length; i++) {
|
|
|
+ res[1].result.list[i].message = util.dbToMsg(res[1].result.list[i].message)
|
|
|
+ const name = res[1].result.list[i].message.name
|
|
|
+ res[1].result.list[i].message.hot_name = name.substr(0, 20) + (name.length > 20 ? '...' : '')
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ hotTagData: res[0].result.list,
|
|
|
+ hotBarData: res[1].result.list
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ onLoad: function () {
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'searchHistory',
|
|
|
+ success: function (res) {
|
|
|
+ this.setData({
|
|
|
+ searchHistory: res.data
|
|
|
+ })
|
|
|
+ }.bind(this)
|
|
|
})
|
|
|
+ this.loadHotData()
|
|
|
}
|
|
|
});
|