|
@@ -1,15 +1,8 @@
|
|
-import {
|
|
|
|
- getCategoryWorks,
|
|
|
|
- searchWorks
|
|
|
|
-} from '~/api/works'
|
|
|
|
-import reachBottom from '~/mixins/reachBottom'
|
|
|
|
-import {
|
|
|
|
- createStoreBindings
|
|
|
|
-} from 'mobx-miniprogram-bindings'
|
|
|
|
-import {
|
|
|
|
- store
|
|
|
|
-} from '~/store/index'
|
|
|
|
-let storeBindings
|
|
|
|
|
|
+import { getCategoryWorks, searchWorks } from '~/api/works';
|
|
|
|
+import reachBottom from '~/mixins/reachBottom';
|
|
|
|
+import { createStoreBindings } from 'mobx-miniprogram-bindings';
|
|
|
|
+import { store } from '~/store/index';
|
|
|
|
+let storeBindings;
|
|
Page({
|
|
Page({
|
|
behaviors: [reachBottom],
|
|
behaviors: [reachBottom],
|
|
data: {
|
|
data: {
|
|
@@ -32,41 +25,41 @@ Page({
|
|
if (options.id) {
|
|
if (options.id) {
|
|
this.setData({
|
|
this.setData({
|
|
childType: options.id
|
|
childType: options.id
|
|
- })
|
|
|
|
- this.resetData()
|
|
|
|
|
|
+ });
|
|
|
|
+ this.resetData();
|
|
} else if (options.list) {
|
|
} else if (options.list) {
|
|
- let categoryList = JSON.parse(decodeURIComponent(options.list))
|
|
|
|
|
|
+ let categoryList = JSON.parse(decodeURIComponent(options.list));
|
|
this.setData({
|
|
this.setData({
|
|
categoryList
|
|
categoryList
|
|
- })
|
|
|
|
- this.resetData()
|
|
|
|
|
|
+ });
|
|
|
|
+ this.resetData();
|
|
}
|
|
}
|
|
- wx.setNavigationBarTitle({
|
|
|
|
|
|
+ tt.setNavigationBarTitle({
|
|
title: options.title || '搜索'
|
|
title: options.title || '搜索'
|
|
- })
|
|
|
|
|
|
+ });
|
|
this.setData({
|
|
this.setData({
|
|
type: options.type,
|
|
type: options.type,
|
|
- historySearch: wx.getStorageSync('search'),
|
|
|
|
|
|
+ historySearch: tt.getStorageSync('search'),
|
|
navBarTitle: options.title
|
|
navBarTitle: options.title
|
|
- })
|
|
|
|
|
|
+ });
|
|
this.storeBindings = createStoreBindings(this, {
|
|
this.storeBindings = createStoreBindings(this, {
|
|
store,
|
|
store,
|
|
fields: {
|
|
fields: {
|
|
userInfo: 'userInfo'
|
|
userInfo: 'userInfo'
|
|
- },
|
|
|
|
- })
|
|
|
|
|
|
+ }
|
|
|
|
+ });
|
|
// 立刻更新
|
|
// 立刻更新
|
|
- this.storeBindings.updateStoreBindings()
|
|
|
|
|
|
+ this.storeBindings.updateStoreBindings();
|
|
},
|
|
},
|
|
// 获取分类的内容
|
|
// 获取分类的内容
|
|
loadMore() {
|
|
loadMore() {
|
|
if (this.data.type == 'search') {
|
|
if (this.data.type == 'search') {
|
|
- return
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- let columnId = this.data.childType ? this.data.childType : this.data.categoryList[this.data.currentIndex].id
|
|
|
|
|
|
+ let columnId = this.data.childType ? this.data.childType : this.data.categoryList[this.data.currentIndex].id;
|
|
this.getData(getCategoryWorks, {
|
|
this.getData(getCategoryWorks, {
|
|
columnId
|
|
columnId
|
|
- })
|
|
|
|
|
|
+ });
|
|
},
|
|
},
|
|
setClass({
|
|
setClass({
|
|
currentTarget
|
|
currentTarget
|
|
@@ -76,84 +69,85 @@ Page({
|
|
navBarTitle: currentTarget.dataset.title,
|
|
navBarTitle: currentTarget.dataset.title,
|
|
currentIndex: currentTarget.dataset.index,
|
|
currentIndex: currentTarget.dataset.index,
|
|
currentId: `class${currentTarget.dataset.index}`
|
|
currentId: `class${currentTarget.dataset.index}`
|
|
- })
|
|
|
|
- this.resetData()
|
|
|
|
|
|
+ });
|
|
|
|
+ this.resetData();
|
|
},
|
|
},
|
|
setSearch({
|
|
setSearch({
|
|
detail
|
|
detail
|
|
}) {
|
|
}) {
|
|
if (!detail.value) {
|
|
if (!detail.value) {
|
|
this.setData({
|
|
this.setData({
|
|
- nullList: false
|
|
|
|
- })
|
|
|
|
|
|
+ nullList: false,
|
|
|
|
+ list: []
|
|
|
|
+ });
|
|
}
|
|
}
|
|
this.setData({
|
|
this.setData({
|
|
text: detail.value
|
|
text: detail.value
|
|
- })
|
|
|
|
|
|
+ });
|
|
},
|
|
},
|
|
async search() {
|
|
async search() {
|
|
if (!this.data.text) {
|
|
if (!this.data.text) {
|
|
this.setData({
|
|
this.setData({
|
|
list: []
|
|
list: []
|
|
- })
|
|
|
|
- return
|
|
|
|
|
|
+ });
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
let list = await searchWorks({
|
|
let list = await searchWorks({
|
|
title: this.data.text,
|
|
title: this.data.text,
|
|
grade: this.data.userInfo.grade
|
|
grade: this.data.userInfo.grade
|
|
- })
|
|
|
|
|
|
+ });
|
|
if (!this.data.historySearch.includes(this.data.text)) {
|
|
if (!this.data.historySearch.includes(this.data.text)) {
|
|
this.setData({
|
|
this.setData({
|
|
historySearch: [this.data.text, ...this.data.historySearch].slice(0, 20)
|
|
historySearch: [this.data.text, ...this.data.historySearch].slice(0, 20)
|
|
- })
|
|
|
|
- wx.setStorageSync('search', this.data.historySearch)
|
|
|
|
|
|
+ });
|
|
|
|
+ tt.setStorageSync('search', this.data.historySearch);
|
|
}
|
|
}
|
|
this.setData({
|
|
this.setData({
|
|
list,
|
|
list,
|
|
nullList: list.length == 0
|
|
nullList: list.length == 0
|
|
- })
|
|
|
|
|
|
+ });
|
|
},
|
|
},
|
|
historySearch({
|
|
historySearch({
|
|
currentTarget
|
|
currentTarget
|
|
}) {
|
|
}) {
|
|
this.setData({
|
|
this.setData({
|
|
- text: currentTarget.dataset.text,
|
|
|
|
- })
|
|
|
|
- this.search()
|
|
|
|
|
|
+ text: currentTarget.dataset.text
|
|
|
|
+ });
|
|
|
|
+ this.search();
|
|
},
|
|
},
|
|
deleteHistory({
|
|
deleteHistory({
|
|
currentTarget
|
|
currentTarget
|
|
}) {
|
|
}) {
|
|
let newList = this.data.historySearch.filter(item => {
|
|
let newList = this.data.historySearch.filter(item => {
|
|
- return item != currentTarget.dataset.text
|
|
|
|
- })
|
|
|
|
|
|
+ return item != currentTarget.dataset.text;
|
|
|
|
+ });
|
|
this.setData({
|
|
this.setData({
|
|
historySearch: newList.slice(0, 20)
|
|
historySearch: newList.slice(0, 20)
|
|
- })
|
|
|
|
- wx.setStorageSync('search', this.data.historySearch)
|
|
|
|
|
|
+ });
|
|
|
|
+ tt.setStorageSync('search', this.data.historySearch);
|
|
},
|
|
},
|
|
clearHistory() {
|
|
clearHistory() {
|
|
- wx.showModal({
|
|
|
|
|
|
+ tt.showModal({
|
|
title: '温馨提示',
|
|
title: '温馨提示',
|
|
content: '历史记录清除后无法恢复,是否清除全部记录',
|
|
content: '历史记录清除后无法恢复,是否清除全部记录',
|
|
- success: (res) => {
|
|
|
|
|
|
+ success: res => {
|
|
if (res.confirm) {
|
|
if (res.confirm) {
|
|
this.setData({
|
|
this.setData({
|
|
historySearch: []
|
|
historySearch: []
|
|
- })
|
|
|
|
- wx.setStorageSync('search', this.data.historySearch)
|
|
|
|
|
|
+ });
|
|
|
|
+ tt.setStorageSync('search', this.data.historySearch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ });
|
|
},
|
|
},
|
|
goRead({
|
|
goRead({
|
|
currentTarget
|
|
currentTarget
|
|
}) {
|
|
}) {
|
|
- wx.navigateTo({
|
|
|
|
- url: `/pages/reading/index?videoId=${currentTarget.dataset.id}&navBarTitle=${this.data.navBarTitle||''}`
|
|
|
|
- })
|
|
|
|
|
|
+ tt.navigateTo({
|
|
|
|
+ url: `/pages/reading/index?videoId=${currentTarget.dataset.id}&navBarTitle=${this.data.navBarTitle || ''}`
|
|
|
|
+ });
|
|
},
|
|
},
|
|
onUnload() {
|
|
onUnload() {
|
|
- this.storeBindings.destroyStoreBindings()
|
|
|
|
- },
|
|
|
|
-})
|
|
|
|
|
|
+ this.storeBindings.destroyStoreBindings();
|
|
|
|
+ }
|
|
|
|
+});
|