更新首页逻辑以支持动态标题生成,优化用户体验。调整管理后台资源文件,替换旧的 JavaScript 和 CSS 文件,提升页面性能和样式一致性。同时,更新数据库结构以支持更细粒度的推送状态。
This commit is contained in:
@@ -66,6 +66,42 @@ function normalizeMentionSegments(segments) {
|
||||
})
|
||||
}
|
||||
|
||||
function normalizeLinkTagLabel(raw) {
|
||||
return String(raw || '')
|
||||
.replace(/^[##\s\u00a0\u200b\u3000]+/u, '')
|
||||
.replace(/[\s\u00a0\u200b\u3000]+$/u, '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
}
|
||||
|
||||
function resolveLinkTagByLabel(label) {
|
||||
const normalized = normalizeLinkTagLabel(label)
|
||||
if (!normalized) return null
|
||||
const tags = Array.isArray(app.globalData.linkTagsConfig) ? app.globalData.linkTagsConfig : []
|
||||
for (const t of tags) {
|
||||
if (!t) continue
|
||||
const candidates = [t.label]
|
||||
if (typeof t.aliases === 'string' && t.aliases.trim()) {
|
||||
candidates.push(...t.aliases.split(','))
|
||||
}
|
||||
for (const c of candidates) {
|
||||
if (normalizeLinkTagLabel(c) === normalized) return t
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function pickLinkTagField(tag, keys, defaultValue = '') {
|
||||
if (!tag || typeof tag !== 'object') return defaultValue
|
||||
for (const key of keys) {
|
||||
const v = tag[key]
|
||||
if (v == null) continue
|
||||
const s = String(v).trim()
|
||||
if (s) return s
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
// 系统信息
|
||||
@@ -100,6 +136,11 @@ Page({
|
||||
readingProgress: 0,
|
||||
/** 未解锁付费墙:合并 data.previewPercent(章节)与顶层 previewPercent(全局) */
|
||||
previewPercent: 20,
|
||||
/** mpUi.readPage.beforeLoginHint:未登录付费墙上方说明文案 */
|
||||
readBeforeLoginHint: '',
|
||||
/** 朋友圈单页:标题与说明(mpUi.readPage.singlePageTitle / singlePagePaywallHint) */
|
||||
readSinglePageTitle: '解锁全文',
|
||||
readSinglePageHint: '',
|
||||
showPaywall: false,
|
||||
|
||||
// 上一篇/下一篇
|
||||
@@ -209,7 +250,18 @@ Page({
|
||||
const mp = (cfg && cfg.mpConfig) || {}
|
||||
const auditMode = !!mp.auditMode
|
||||
app.globalData.auditMode = auditMode
|
||||
if (typeof this.setData === 'function') this.setData({ auditMode })
|
||||
const rp = (mp.mpUi && mp.mpUi.readPage) || {}
|
||||
const readBeforeLoginHint = String(rp.beforeLoginHint || '').trim()
|
||||
const readSinglePageTitle = String(rp.singlePageTitle || '解锁全文').trim() || '解锁全文'
|
||||
const readSinglePageHint = String(rp.singlePagePaywallHint || '').trim()
|
||||
if (typeof this.setData === 'function') {
|
||||
this.setData({
|
||||
auditMode,
|
||||
readBeforeLoginHint,
|
||||
readSinglePageTitle,
|
||||
readSinglePageHint,
|
||||
})
|
||||
}
|
||||
}
|
||||
if (extras && Array.isArray(extras.linkTags)) {
|
||||
app.globalData.linkTagsConfig = extras.linkTags
|
||||
@@ -660,18 +712,18 @@ Page({
|
||||
onLinkTagTap(e) {
|
||||
let url = (e.currentTarget.dataset.url || '').trim()
|
||||
const label = (e.currentTarget.dataset.label || '').trim()
|
||||
let tagType = (e.currentTarget.dataset.tagType || '').trim()
|
||||
let tagType = (e.currentTarget.dataset.tagType || '').trim().toLowerCase()
|
||||
let pagePath = (e.currentTarget.dataset.pagePath || '').trim()
|
||||
let mpKey = (e.currentTarget.dataset.mpKey || '').trim()
|
||||
|
||||
// 旧格式(<a href>)tagType 为空 → 按 label 从缓存 linkTags 补充类型信息
|
||||
if (!tagType && label) {
|
||||
const cached = (app.globalData.linkTagsConfig || []).find(t => t.label === label)
|
||||
const cached = resolveLinkTagByLabel(label)
|
||||
if (cached) {
|
||||
tagType = cached.type || 'url'
|
||||
pagePath = cached.pagePath || ''
|
||||
if (!url) url = cached.url || ''
|
||||
if (cached.mpKey) mpKey = cached.mpKey
|
||||
tagType = pickLinkTagField(cached, ['type', 'tagType'], 'url').toLowerCase()
|
||||
pagePath = pickLinkTagField(cached, ['pagePath', 'page_path'], '')
|
||||
if (!url) url = pickLinkTagField(cached, ['url', 'linkUrl', 'link_url'], '')
|
||||
if (!mpKey) mpKey = pickLinkTagField(cached, ['mpKey', 'mp_key', 'appId', 'app_id'], '')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,8 +737,8 @@ Page({
|
||||
// 小程序类型:用密钥查 linkedMiniprograms 得 appId,再唤醒(需在 app.json 的 navigateToMiniProgramAppIdList 中配置)
|
||||
if (tagType === 'miniprogram') {
|
||||
if (!mpKey && label) {
|
||||
const cached = (app.globalData.linkTagsConfig || []).find(t => t.label === label)
|
||||
if (cached) mpKey = cached.mpKey || ''
|
||||
const cached = resolveLinkTagByLabel(label)
|
||||
if (cached) mpKey = pickLinkTagField(cached, ['mpKey', 'mp_key', 'appId', 'app_id'], '')
|
||||
}
|
||||
const linked = (app.globalData.linkedMiniprograms || []).find(m => m.key === mpKey)
|
||||
if (linked && linked.appId) {
|
||||
|
||||
@@ -127,7 +127,8 @@
|
||||
<view class="paywall-icon"><icon name="lock" size="80" color="#00CED1"></icon></view>
|
||||
|
||||
<block wx:if="{{readSinglePageMode}}">
|
||||
<text class="paywall-title">解锁全文</text>
|
||||
<text class="paywall-title">{{readSinglePageTitle}}</text>
|
||||
<text class="paywall-desc" wx:if="{{!auditMode}}">试读 {{previewPercent}}%(与后台试读比例一致)</text>
|
||||
<view class="purchase-options" wx:if="{{!auditMode}}">
|
||||
<view class="purchase-btn purchase-section" bindtap="onUnlockTapInSinglePage">
|
||||
<text class="btn-label">购买本章</text>
|
||||
@@ -135,11 +136,12 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="paywall-audit-tip" wx:if="{{auditMode}}">审核中,暂不支持购买</view>
|
||||
<text class="paywall-desc paywall-desc--moments-expanded" wx:if="{{momentsPaywallExpanded}}">预览不可付款,请点底部「前往小程序」。</text>
|
||||
<text class="paywall-desc paywall-desc--moments-expanded" wx:if="{{momentsPaywallExpanded}}">{{readSinglePageHint || '预览不可付款,请点底部「前往小程序」。'}}</text>
|
||||
</block>
|
||||
|
||||
<block wx:else>
|
||||
<text class="paywall-title">解锁完整内容</text>
|
||||
<text class="paywall-desc paywall-desc--pre" wx:if="{{readBeforeLoginHint}}">{{readBeforeLoginHint}}</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">
|
||||
@@ -199,7 +201,8 @@
|
||||
<view class="paywall-icon"><icon name="lock" size="80" color="#00CED1"></icon></view>
|
||||
|
||||
<block wx:if="{{readSinglePageMode}}">
|
||||
<text class="paywall-title">解锁全文</text>
|
||||
<text class="paywall-title">{{readSinglePageTitle}}</text>
|
||||
<text class="paywall-desc" wx:if="{{!auditMode}}">试读 {{previewPercent}}%(与后台试读比例一致)</text>
|
||||
<view class="purchase-options" wx:if="{{!auditMode}}">
|
||||
<view class="purchase-btn purchase-section" bindtap="onUnlockTapInSinglePage">
|
||||
<text class="btn-label">购买本章</text>
|
||||
@@ -207,7 +210,7 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="paywall-audit-tip" wx:if="{{auditMode}}">审核中,暂不支持购买</view>
|
||||
<text class="paywall-desc paywall-desc--moments-expanded" wx:if="{{momentsPaywallExpanded}}">预览不可付款,请点底部「前往小程序」。</text>
|
||||
<text class="paywall-desc paywall-desc--moments-expanded" wx:if="{{momentsPaywallExpanded}}">{{readSinglePageHint || '预览不可付款,请点底部「前往小程序」。'}}</text>
|
||||
</block>
|
||||
|
||||
<block wx:else>
|
||||
|
||||
Reference in New Issue
Block a user