|
@@ -22,7 +22,7 @@ Page({
|
|
|
text: '',
|
|
|
currentId: '',
|
|
|
navBarTitle: '',
|
|
|
- historySearch: wx.getStorageSync('search')
|
|
|
+ historySearch: []
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
@@ -46,6 +46,7 @@ Page({
|
|
|
})
|
|
|
this.setData({
|
|
|
type: options.type,
|
|
|
+ historySearch: wx.getStorageSync('search'),
|
|
|
navBarTitle: options.title
|
|
|
})
|
|
|
this.storeBindings = createStoreBindings(this, {
|
|
@@ -87,19 +88,44 @@ Page({
|
|
|
},
|
|
|
async search() {
|
|
|
if (!this.data.text) {
|
|
|
+ this.setData({
|
|
|
+ list: []
|
|
|
+ })
|
|
|
return
|
|
|
}
|
|
|
let list = await searchWorks({
|
|
|
title: this.data.text,
|
|
|
grade: this.data.userInfo.grade
|
|
|
})
|
|
|
- console.log(list);
|
|
|
+ if (!this.data.historySearch.includes(this.data.text)) {
|
|
|
+ this.setData({
|
|
|
+ historySearch: [...this.data.historySearch, this.data.text]
|
|
|
+ })
|
|
|
+ }
|
|
|
this.setData({
|
|
|
list,
|
|
|
- historySearch: [...this.data.historySearch, this.data.text]
|
|
|
})
|
|
|
wx.setStorageSync('search', this.data.historySearch)
|
|
|
},
|
|
|
+ historySearch({
|
|
|
+ currentTarget
|
|
|
+ }) {
|
|
|
+ this.setData({
|
|
|
+ text: currentTarget.dataset.text
|
|
|
+ })
|
|
|
+ this.search()
|
|
|
+ },
|
|
|
+ deleteHistory({
|
|
|
+ currentTarget
|
|
|
+ }) {
|
|
|
+ let newList = this.data.historySearch.filter(item => {
|
|
|
+ return item != currentTarget.dataset.text
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ historySearch: newList
|
|
|
+ })
|
|
|
+ wx.setStorageSync('search', newList)
|
|
|
+ },
|
|
|
goRead({
|
|
|
currentTarget
|
|
|
}) {
|