33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
|
|
// 详情页:人视图(渲染阅读)/ AI 视图(结构化数据)
|
||
|
|
Page({
|
||
|
|
data: {
|
||
|
|
note: null,
|
||
|
|
view: 'human', // human | ai
|
||
|
|
rendered: [] // 人视图的轻量 Markdown 渲染结果
|
||
|
|
},
|
||
|
|
|
||
|
|
onLoad(query) {
|
||
|
|
const note = getApp().globalData.notes.find(n => n.id === query.id)
|
||
|
|
if (!note) return
|
||
|
|
this.setData({ note, rendered: this.renderMd(note.content) })
|
||
|
|
wx.setNavigationBarTitle({ title: note.title.slice(0, 12) })
|
||
|
|
},
|
||
|
|
|
||
|
|
// 轻量 Markdown 解析(原型够用;正式版换 towxml 完整渲染)
|
||
|
|
renderMd(md) {
|
||
|
|
return md.split('\n').filter(l => l.trim()).map(line => {
|
||
|
|
if (line.startsWith('## ')) return { type: 'h2', text: line.slice(3) }
|
||
|
|
if (line.startsWith('- ')) return { type: 'li', text: line.slice(2) }
|
||
|
|
const bold = line.startsWith('**') && line.endsWith('**')
|
||
|
|
return { type: bold ? 'bold' : 'p', text: bold ? line.slice(2, -2) : line }
|
||
|
|
})
|
||
|
|
},
|
||
|
|
|
||
|
|
onSwitchView(e) {
|
||
|
|
this.setData({ view: e.currentTarget.dataset.v })
|
||
|
|
},
|
||
|
|
|
||
|
|
onEdit() {
|
||
|
|
wx.navigateTo({ url: '/pages/editor/editor?id=' + this.data.note.id })
|
||
|
|
}
|
||
|
|
})
|