54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
// 知识库首页:搜索 + 标签筛选 + 卡片流
|
||
Page({
|
||
data: {
|
||
keyword: '',
|
||
activeTag: '全部',
|
||
tags: ['全部', '读书', '生活', '灵感', '星象'],
|
||
notes: []
|
||
},
|
||
|
||
onShow() {
|
||
this.refresh()
|
||
},
|
||
|
||
refresh() {
|
||
const all = getApp().globalData.notes
|
||
const kw = this.data.keyword.trim()
|
||
let list = all
|
||
if (this.data.activeTag !== '全部') {
|
||
list = list.filter(n => n.tags.includes(this.data.activeTag))
|
||
}
|
||
if (kw) {
|
||
list = list.filter(n =>
|
||
n.title.includes(kw) || n.summary.includes(kw) || n.tags.join('').includes(kw)
|
||
)
|
||
}
|
||
this.setData({ notes: list })
|
||
},
|
||
|
||
onSearchInput(e) {
|
||
this.setData({ keyword: e.detail.value })
|
||
this.refresh()
|
||
},
|
||
|
||
onTapTag(e) {
|
||
this.setData({ activeTag: e.currentTarget.dataset.tag })
|
||
this.refresh()
|
||
},
|
||
|
||
onTapNote(e) {
|
||
wx.navigateTo({ url: '/pages/detail/detail?id=' + e.currentTarget.dataset.id })
|
||
},
|
||
|
||
onTapAdd() {
|
||
wx.navigateTo({ url: '/pages/editor/editor' })
|
||
},
|
||
|
||
onAskAI() {
|
||
wx.showModal({
|
||
title: 'AI 问答(原型占位)',
|
||
content: '正式版接 DeepSeek:对“公开且 AI 可读”的条目做检索问答,每人每天 10 次。',
|
||
showCancel: false
|
||
})
|
||
}
|
||
})
|