|
@@ -1,17 +1,17 @@
|
|
|
-const hotTagData = require("../../data/hotTagData.js")
|
|
|
|
|
-const hotBarData = require("../../data/hotBarData.js")
|
|
|
|
|
|
|
+const hotTagData = require('../../data/hotTagData.js')
|
|
|
|
|
+const hotBarData = require('../../data/hotBarData.js')
|
|
|
const util = require('../../utils/util.js')
|
|
const util = require('../../utils/util.js')
|
|
|
|
|
|
|
|
Page({
|
|
Page({
|
|
|
options: {
|
|
options: {
|
|
|
- styleIsolation: "apply-shared"
|
|
|
|
|
|
|
+ styleIsolation: 'apply-shared'
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
// 页面的初始数据
|
|
// 页面的初始数据
|
|
|
data: {
|
|
data: {
|
|
|
toggleEnable: true,
|
|
toggleEnable: true,
|
|
|
searchEnable: false,
|
|
searchEnable: false,
|
|
|
- searchText: "",
|
|
|
|
|
|
|
+ searchText: '',
|
|
|
hotTagData: [],
|
|
hotTagData: [],
|
|
|
hotBarData: [],
|
|
hotBarData: [],
|
|
|
searchResult: [],
|
|
searchResult: [],
|
|
@@ -20,7 +20,7 @@ Page({
|
|
|
|
|
|
|
|
onLoad: function () {
|
|
onLoad: function () {
|
|
|
wx.getStorage({
|
|
wx.getStorage({
|
|
|
- key: "searchHistory",
|
|
|
|
|
|
|
+ key: 'searchHistory',
|
|
|
success: function (res) {
|
|
success: function (res) {
|
|
|
this.setData({
|
|
this.setData({
|
|
|
searchHistory: res.data
|
|
searchHistory: res.data
|
|
@@ -28,7 +28,7 @@ Page({
|
|
|
}.bind(this)
|
|
}.bind(this)
|
|
|
})
|
|
})
|
|
|
const db = wx.cloud.database()
|
|
const db = wx.cloud.database()
|
|
|
- db.collection("search").orderBy("time", "desc").limit(20).get({
|
|
|
|
|
|
|
+ db.collection('search').orderBy('time', 'desc').limit(20).get({
|
|
|
success: function (res) {
|
|
success: function (res) {
|
|
|
var count = {},
|
|
var count = {},
|
|
|
hotTag = []
|
|
hotTag = []
|
|
@@ -92,13 +92,13 @@ Page({
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
blur: function () {
|
|
blur: function () {
|
|
|
- if (this.data.searchText != "") return
|
|
|
|
|
|
|
+ if (this.data.searchText !== '') return
|
|
|
this.cancel()
|
|
this.cancel()
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
search: function () {
|
|
search: function () {
|
|
|
var history = this.data.searchHistory
|
|
var history = this.data.searchHistory
|
|
|
- if (history == undefined) history = []
|
|
|
|
|
|
|
+ if (history === undefined) history = []
|
|
|
for (let i = 0; i < history.length; i++) {
|
|
for (let i = 0; i < history.length; i++) {
|
|
|
if (history[i] == this.data.searchText) {
|
|
if (history[i] == this.data.searchText) {
|
|
|
history.splice(i, 1)
|
|
history.splice(i, 1)
|
|
@@ -113,44 +113,34 @@ Page({
|
|
|
searchHistory: history
|
|
searchHistory: history
|
|
|
})
|
|
})
|
|
|
wx.setStorage({
|
|
wx.setStorage({
|
|
|
- key: "searchHistory",
|
|
|
|
|
|
|
+ key: 'searchHistory',
|
|
|
data: history
|
|
data: history
|
|
|
})
|
|
})
|
|
|
wx.showLoading({
|
|
wx.showLoading({
|
|
|
- title: "搜索中"
|
|
|
|
|
|
|
+ title: '搜索中'
|
|
|
})
|
|
})
|
|
|
- const db = wx.cloud.database()
|
|
|
|
|
- const _ = db.command
|
|
|
|
|
- db.collection("search").add({
|
|
|
|
|
|
|
+ wx.cloud.callFunction({
|
|
|
|
|
+ name: 'listMessages',
|
|
|
data: {
|
|
data: {
|
|
|
- key: this.data.searchText,
|
|
|
|
|
- time: new Date()
|
|
|
|
|
- },
|
|
|
|
|
- success: function () {
|
|
|
|
|
- var reg = new RegExp(this.data.searchText, "i")
|
|
|
|
|
- db.collection("message").where(
|
|
|
|
|
- _.or([{
|
|
|
|
|
- title: reg
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- subTitle: reg
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- details: reg
|
|
|
|
|
- }
|
|
|
|
|
- ])
|
|
|
|
|
- ).orderBy("time", "desc").limit(20).get({
|
|
|
|
|
- success: function (res) {
|
|
|
|
|
- for (let i = 0; i < res.data.length; i++) {
|
|
|
|
|
- res.data[i].time = util.handleDate(res.data[i].time)
|
|
|
|
|
- }
|
|
|
|
|
- this.setData({
|
|
|
|
|
- searchResult: res.data
|
|
|
|
|
- })
|
|
|
|
|
- wx.hideLoading()
|
|
|
|
|
- }.bind(this)
|
|
|
|
|
|
|
+ keyword: this.data.searchText,
|
|
|
|
|
+ page_token: 0,
|
|
|
|
|
+ page_size: 25
|
|
|
|
|
+ }
|
|
|
|
|
+ }).then(res => {
|
|
|
|
|
+ wx.hideLoading()
|
|
|
|
|
+ if (res.result.status !== 'OK') {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: res.result.errMsg,
|
|
|
|
|
+ icon: 'none'
|
|
|
})
|
|
})
|
|
|
- }.bind(this)
|
|
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ for (let i = 0; i < res.result.list.length; i++) {
|
|
|
|
|
+ res.result.list[i] = util.dbToMsg(res.result.list[i])
|
|
|
|
|
+ }
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ searchResult: res.result.list
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -158,7 +148,7 @@ Page({
|
|
|
if (!this.data.toggleEnable || !this.data.searchEnable) return
|
|
if (!this.data.toggleEnable || !this.data.searchEnable) return
|
|
|
this.data.toggleEnable = false
|
|
this.data.toggleEnable = false
|
|
|
this.setData({
|
|
this.setData({
|
|
|
- searchText: "",
|
|
|
|
|
|
|
+ searchText: '',
|
|
|
})
|
|
})
|
|
|
this.animate('.cancel-button', [{
|
|
this.animate('.cancel-button', [{
|
|
|
opacity: 1
|
|
opacity: 1
|
|
@@ -201,7 +191,7 @@ Page({
|
|
|
|
|
|
|
|
removeHistory: function (e) {
|
|
removeHistory: function (e) {
|
|
|
var history = this.data.searchHistory
|
|
var history = this.data.searchHistory
|
|
|
- if (history == undefined) history = []
|
|
|
|
|
|
|
+ if (history === undefined) history = []
|
|
|
for (let i = 0; i < history.length; i++) {
|
|
for (let i = 0; i < history.length; i++) {
|
|
|
if (history[i] == e.target.dataset.history) {
|
|
if (history[i] == e.target.dataset.history) {
|
|
|
history.splice(i, 1)
|
|
history.splice(i, 1)
|
|
@@ -212,14 +202,14 @@ Page({
|
|
|
searchHistory: history
|
|
searchHistory: history
|
|
|
})
|
|
})
|
|
|
wx.setStorage({
|
|
wx.setStorage({
|
|
|
- key: "searchHistory",
|
|
|
|
|
|
|
+ key: 'searchHistory',
|
|
|
data: history
|
|
data: history
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
viewActivity: function (e) {
|
|
viewActivity: function (e) {
|
|
|
wx.navigateTo({
|
|
wx.navigateTo({
|
|
|
- url: "/pages/activity/activity?id=" + e.target.dataset.activityId
|
|
|
|
|
|
|
+ url: '/pages/activity/activity?id=' + e.target.dataset.activityId
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|