更新小程序配置,重构页面结构,删除不再使用的地址管理和章节页面,优化项目结构以提升可维护性;调整全局样式,增强组件的可复用性和一致性。
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
statusBarHeight: 44,
|
||||
navBarHeight: 88,
|
||||
query: '',
|
||||
results: [],
|
||||
keywords: [],
|
||||
isLoading: false,
|
||||
hotKeywords: ['私域', '流量', '赚钱', '电商', 'AI', '社群']
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
const statusBarHeight = app.globalData.statusBarHeight || 44
|
||||
const navBarHeight = app.globalData.navBarHeight || (statusBarHeight + 44)
|
||||
this.setData({ statusBarHeight, navBarHeight })
|
||||
},
|
||||
|
||||
onInput(e) {
|
||||
const query = (e.detail && e.detail.value) || ''
|
||||
this.setData({ query })
|
||||
if (!query.trim()) {
|
||||
this.setData({ results: [], keywords: [] })
|
||||
return
|
||||
}
|
||||
this.debounceSearch(query)
|
||||
},
|
||||
|
||||
_searchTimer: null,
|
||||
debounceSearch(query) {
|
||||
if (this._searchTimer) clearTimeout(this._searchTimer)
|
||||
this._searchTimer = setTimeout(() => this.doSearch(query), 300)
|
||||
},
|
||||
|
||||
doSearch(q) {
|
||||
if (!q || !q.trim()) return
|
||||
this.setData({ isLoading: true })
|
||||
app.request('/api/search?q=' + encodeURIComponent(q.trim()) + '&type=all')
|
||||
.then((res) => {
|
||||
const results = (res && res.data && res.data.results) ? res.data.results : []
|
||||
const keywords = (res && res.data && res.data.keywords) ? res.data.keywords : []
|
||||
this.setData({ results, keywords, isLoading: false })
|
||||
})
|
||||
.catch(() => {
|
||||
this.setData({ results: [], keywords: [], isLoading: false })
|
||||
})
|
||||
},
|
||||
|
||||
onKeywordTap(e) {
|
||||
const keyword = e.currentTarget.dataset.keyword
|
||||
this.setData({ query: keyword })
|
||||
this.doSearch(keyword)
|
||||
},
|
||||
|
||||
clearQuery() {
|
||||
this.setData({ query: '', results: [], keywords: [] })
|
||||
},
|
||||
|
||||
goToRead(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
if (!id) return
|
||||
wx.navigateTo({ url: '/pages/read/read?id=' + encodeURIComponent(id) })
|
||||
},
|
||||
|
||||
goBack() {
|
||||
wx.navigateBack({ fail: () => wx.switchTab({ url: '/pages/index/index' }) })
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user