This commit is contained in:
Alex-larget
2026-03-25 15:58:12 +08:00
parent c040e5609b
commit d8362bc7a9
3 changed files with 36 additions and 19 deletions

View File

@@ -39,6 +39,14 @@ function getContentParseConfig() {
}
/** 补全 mentionDisplay避免旧数据无字段昵称去空白防「@ 名」 */
/** 付费墙「已阅读 x%」:与章节接口 previewPercent 一致(未全文解锁时),缺省 20 */
function normalizePreviewPercent(res) {
const p = res && res.previewPercent
const n = typeof p === 'number' ? Math.round(p) : parseInt(String(p), 10)
if (!isNaN(n) && n >= 1 && n <= 100) return n
return 20
}
function normalizeMentionSegments(segments) {
if (!Array.isArray(segments)) return []
return segments.map((row) => {
@@ -85,6 +93,8 @@ Page({
// 阅读进度
readingProgress: 0,
/** 未解锁时付费墙展示:与 /api/miniprogram/book/chapter/* 的 previewPercent 对齐 */
previewPercent: 20,
showPaywall: false,
// 上一篇/下一篇
@@ -425,7 +435,8 @@ Page({
contentSegments: normalizeMentionSegments(segments),
previewParagraphs: lines.slice(0, previewCount),
partTitle: res.partTitle || '',
chapterTitle: res.chapterTitle || ''
chapterTitle: res.chapterTitle || '',
previewPercent: normalizePreviewPercent(res),
}
if (res.mid) updates.sectionMid = res.mid
this.setData(updates)
@@ -451,7 +462,8 @@ Page({
contentSegments: normalizeMentionSegments(segments),
previewParagraphs: lines.slice(0, previewCount),
partTitle: cached.partTitle || '',
chapterTitle: cached.chapterTitle || ''
chapterTitle: cached.chapterTitle || '',
previewPercent: normalizePreviewPercent(cached),
})
app.touchRecentSection(id)
console.log('[Read] 从本地缓存加载成功')
@@ -571,7 +583,8 @@ Page({
previewParagraphs: lines.slice(0, previewCount),
partTitle: res.partTitle || '',
// 导航栏、分享等使用的文章标题,同样统一为 sectionTitle
chapterTitle: sectionTitle
chapterTitle: sectionTitle,
previewPercent: normalizePreviewPercent(res),
})
},

View File

@@ -140,7 +140,7 @@
<block wx:else>
<text class="paywall-title">解锁完整内容</text>
<text class="paywall-desc">已预览部分内容,登录并支付 ¥1 后阅读全文</text>
<text class="paywall-desc">已阅读{{previewPercent}}%,登录并支付 ¥{{section && section.price != null ? section.price : sectionPrice}} 后阅读全文</text>
<view class="purchase-options" wx:if="{{!auditMode}}">
<view class="purchase-btn purchase-section" bindtap="handlePurchaseSection">
<text class="btn-label">购买本章</text>
@@ -212,7 +212,7 @@
<block wx:else>
<text class="paywall-title">解锁完整内容</text>
<text class="paywall-desc">已阅读50%,购买后继续阅读</text>
<text class="paywall-desc">已阅读{{previewPercent}}%,购买后继续阅读</text>
<view class="purchase-options" wx:if="{{!auditMode}}">
<view class="purchase-btn purchase-section" bindtap="handlePurchaseSection">
<text class="btn-label">购买本章</text>