主要更新: - 后台菜单精简(9项→6项) - 新增搜索功能(敏感信息过滤) - 分销绑定和提现系统完善 - 数据库初始化API(自动修复表结构) - 用户管理:显示绑定关系详情 - 小程序:上下章导航优化、匹配页面重构 - 修复hydration和数据类型问题
88 lines
1.8 KiB
JavaScript
88 lines
1.8 KiB
JavaScript
/**
|
|
* Soul创业派对 - 章节搜索页
|
|
* 搜索章节标题和内容
|
|
*/
|
|
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 44,
|
|
keyword: '',
|
|
results: [],
|
|
loading: false,
|
|
searched: false,
|
|
total: 0,
|
|
// 热门搜索
|
|
hotKeywords: ['私域', '电商', '流量', '赚钱', '创业', 'Soul', '抖音']
|
|
},
|
|
|
|
onLoad() {
|
|
this.setData({
|
|
statusBarHeight: app.globalData.statusBarHeight || 44
|
|
})
|
|
},
|
|
|
|
// 输入关键词
|
|
onInput(e) {
|
|
this.setData({ keyword: e.detail.value })
|
|
},
|
|
|
|
// 清空搜索
|
|
clearSearch() {
|
|
this.setData({
|
|
keyword: '',
|
|
results: [],
|
|
searched: false,
|
|
total: 0
|
|
})
|
|
},
|
|
|
|
// 点击热门关键词
|
|
onHotKeyword(e) {
|
|
const keyword = e.currentTarget.dataset.keyword
|
|
this.setData({ keyword })
|
|
this.doSearch()
|
|
},
|
|
|
|
// 执行搜索
|
|
async doSearch() {
|
|
const { keyword } = this.data
|
|
if (!keyword || keyword.trim().length < 1) {
|
|
wx.showToast({ title: '请输入搜索关键词', icon: 'none' })
|
|
return
|
|
}
|
|
|
|
this.setData({ loading: true, searched: true })
|
|
|
|
try {
|
|
const res = await app.request(`/api/book/search?q=${encodeURIComponent(keyword.trim())}`)
|
|
|
|
if (res && res.success) {
|
|
this.setData({
|
|
results: res.results || [],
|
|
total: res.total || 0
|
|
})
|
|
} else {
|
|
this.setData({ results: [], total: 0 })
|
|
}
|
|
} catch (e) {
|
|
console.error('搜索失败:', e)
|
|
wx.showToast({ title: '搜索失败', icon: 'none' })
|
|
this.setData({ results: [], total: 0 })
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
// 跳转阅读
|
|
goToRead(e) {
|
|
const id = e.currentTarget.dataset.id
|
|
wx.navigateTo({ url: `/pages/read/read?id=${id}` })
|
|
},
|
|
|
|
// 返回上一页
|
|
goBack() {
|
|
wx.navigateBack()
|
|
}
|
|
})
|