重构小程序图标组件,替换传统 emoji 为 SVG 图标,提升视觉一致性和可维护性。更新多个页面以使用新图标组件,优化用户界面体验。同时,调整了数据加载逻辑,确保更高效的状态管理和用户交互。
This commit is contained in:
@@ -65,7 +65,7 @@ Page({
|
||||
this.setData({ searchEnabled: app.globalData.features.searchEnabled })
|
||||
return
|
||||
}
|
||||
const res = await app.request({ url: '/api/miniprogram/config', silent: true })
|
||||
const res = await app.getConfig()
|
||||
const features = (res && res.features) || {}
|
||||
const searchEnabled = features.searchEnabled !== false
|
||||
if (!app.globalData.features) app.globalData.features = {}
|
||||
@@ -76,18 +76,11 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
// 懒加载:仅拉取篇章列表 + totalSections + fixedSections
|
||||
// 优先 book/parts,404 或失败时降级为 all-chapters 推导
|
||||
// 懒加载:仅拉取篇章列表 + totalSections + fixedSections(book/parts,不再用 all-chapters)
|
||||
async loadParts() {
|
||||
this.setData({ partsLoading: true })
|
||||
try {
|
||||
let res
|
||||
try {
|
||||
res = await app.request({ url: '/api/miniprogram/book/parts', silent: true })
|
||||
} catch (e) {
|
||||
console.log('[Chapters] book/parts 失败,降级 all-chapters:', e?.message || e)
|
||||
res = null
|
||||
}
|
||||
const res = await app.request({ url: '/api/miniprogram/book/parts', silent: true })
|
||||
let parts = []
|
||||
let totalSections = 0
|
||||
let fixedSections = []
|
||||
@@ -95,21 +88,6 @@ Page({
|
||||
parts = res.parts
|
||||
totalSections = res.totalSections ?? 0
|
||||
fixedSections = res.fixedSections || []
|
||||
} else {
|
||||
// 降级:从 all-chapters 推导 parts
|
||||
const allRes = await app.request({ url: '/api/miniprogram/book/all-chapters', silent: true })
|
||||
const list = (allRes?.data || allRes?.chapters || [])
|
||||
totalSections = list.length
|
||||
const pt = (c) => (c.partTitle || c.part_title || '').toLowerCase()
|
||||
const exclude = (c) => !pt(c).includes('序言') && !pt(c).includes('尾声') && !pt(c).includes('附录')
|
||||
const partMap = new Map()
|
||||
list.filter(exclude).forEach(c => {
|
||||
const pid = c.partId || c.part_id || 'default'
|
||||
const ptitle = c.partTitle || c.part_title || '未分类'
|
||||
if (!partMap.has(pid)) partMap.set(pid, { id: pid, title: ptitle, subtitle: '', chapterCount: 0 })
|
||||
partMap.get(pid).chapterCount++
|
||||
})
|
||||
parts = Array.from(partMap.values())
|
||||
}
|
||||
const numbers = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二']
|
||||
const fixedMap = {}
|
||||
@@ -185,7 +163,7 @@ Page({
|
||||
else bookDataFlat.push(r)
|
||||
})
|
||||
app.globalData.bookData = bookDataFlat
|
||||
wx.setStorageSync('bookData', bookDataFlat)
|
||||
wx.setStorage({ key: 'bookData', data: bookDataFlat }) // 异步写入,避免阻塞主线程
|
||||
this.setData({ bookData, _loadedChapters: loaded })
|
||||
} catch (e) {
|
||||
console.log('[Chapters] 加载章节失败:', e)
|
||||
@@ -252,7 +230,7 @@ Page({
|
||||
// 跳转到阅读页(优先传 mid,与分享逻辑一致)
|
||||
goToRead(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
const mid = e.currentTarget.dataset.mid || app.getSectionMid(id)
|
||||
const mid = e.currentTarget.dataset.mid
|
||||
trackClick('chapters', 'card_click', id || '章节')
|
||||
const q = mid ? `mid=${mid}` : `id=${id}`
|
||||
wx.navigateTo({ url: `/pages/read/read?${q}` })
|
||||
|
||||
Reference in New Issue
Block a user