130 lines
5.1 KiB
JavaScript
130 lines
5.1 KiB
JavaScript
/**
|
||
* 从 mpConfig.mpUi.pagePopupItems 按 pagePath + key 取文案(管理端 CRUD)。
|
||
* 兼容旧版 mpUi.memberDetailPage / readPage 字段。
|
||
* 云端未配置或 content 为空时,使用本文件内写死兜底(与种子文案一致)。
|
||
*
|
||
* 当前代码显式引用的键(与 soul-admin 默认种子 / db.defaultMpUi 一致,勿改 key 除非双端同步):
|
||
* - MEMBER_PATH unlockIntroTitle, unlockIntroBody → member-detail.js _showUnlockIntroThenLogin
|
||
* - READ_PATH beforeLoginHint, singlePageTitle, singlePagePaywallHint → read.js onLoad
|
||
* - READ_PATH global* → app.js getGlobalPopupContent(与 pagePopupItems 同页路径存全局键)
|
||
*/
|
||
|
||
const MEMBER_PATH = '/pages/member-detail/member-detail'
|
||
const READ_PATH = '/pages/read/read'
|
||
|
||
/** 阅读页 mpUi 兜底(pagePopupItems / readPage 均无或为空时) */
|
||
const READ_PAGE_FALLBACK = {
|
||
beforeLoginHint: '试读进度与下方百分比以后台配置为准;登录后可购买解锁全文。',
|
||
singlePageTitle: '解锁完整内容',
|
||
singlePagePaywallHint:
|
||
'当前为朋友圈单页预览,无法在此登录或付款。请点击底部「前往小程序」进入完整版后再解锁本章。',
|
||
}
|
||
|
||
/** 成员详情解锁说明兜底 */
|
||
const MEMBER_DETAIL_FALLBACK = {
|
||
unlockIntroTitle: '解锁与链接说明',
|
||
unlockIntroBody:
|
||
'「链接」用于提交留资,由对方通过获客计划跟进;「解锁」用于复制手机/微信号后自行添加好友。\n\n请确认已了解后再登录。',
|
||
}
|
||
|
||
/**
|
||
* 全局弹窗键与 app.js showModal 兜底一致(pagePath 仍为 READ_PATH,key 以 global 开头)
|
||
*/
|
||
const GLOBAL_POPUP_FALLBACK = {
|
||
globalSinglePageAuthTitle: '请打开完整小程序',
|
||
globalSinglePageAuthBody:
|
||
'当前是朋友圈预览,无法在这里登录或付款。请先点击屏幕底部「前往小程序」,进入完整版后再解锁本章。',
|
||
globalAvatarGuideTitle: '设置头像与昵称',
|
||
globalAvatarGuideBody: '头像与昵称会出现在名片与匹配卡片上,方便伙伴认出你。',
|
||
globalVipProfileHintTitle: '补全对外展示信息',
|
||
globalVipProfileHintBody: 'VIP 名片与派对场景会展示头像与昵称,补全后对方更容易认出你。',
|
||
globalVipPhoneTitle: '补全手机号',
|
||
globalVipPhoneBody: '手机号用于找伙伴、提现验证与重要通知,仅本人可见。',
|
||
globalVipWechatOptionalTitle: '补全微信号(可选)',
|
||
globalVipWechatOptionalBody: '填写微信号后,对方在允许的场景下能更快加到你;不填也可继续使用。',
|
||
globalAppUpdateTitle: '更新提示',
|
||
globalAppUpdateBody: '新版本已准备好,重启后即可使用',
|
||
}
|
||
|
||
function getList(app) {
|
||
const mpUi = app.globalData.configCache && app.globalData.configCache.mpConfig
|
||
? app.globalData.configCache.mpConfig.mpUi
|
||
: null
|
||
const list = mpUi && mpUi.pagePopupItems
|
||
return Array.isArray(list) ? list : []
|
||
}
|
||
|
||
/**
|
||
* @param {object} app getApp()
|
||
* @param {string} pagePath 如 /pages/read/read
|
||
* @param {string} key 英文键
|
||
* @returns {string} 文案,未配置时返回空串
|
||
*/
|
||
function getPagePopupContent(app, pagePath, key) {
|
||
const list = getList(app)
|
||
const it = list.find(function (p) {
|
||
return p && p.pagePath === pagePath && p.key === key
|
||
})
|
||
if (it && typeof it.content === 'string') return it.content.trim()
|
||
return ''
|
||
}
|
||
|
||
/**
|
||
* 带旧版 readPage / memberDetailPage 兜底
|
||
*/
|
||
function getReadPageContent(app, key) {
|
||
const v = getPagePopupContent(app, READ_PATH, key)
|
||
if (v) return v
|
||
const rp = (app.globalData.configCache && app.globalData.configCache.mpConfig &&
|
||
app.globalData.configCache.mpConfig.mpUi &&
|
||
app.globalData.configCache.mpConfig.mpUi.readPage) || {}
|
||
if (key === 'beforeLoginHint') {
|
||
const s = String(rp.beforeLoginHint || '').trim()
|
||
return s || READ_PAGE_FALLBACK.beforeLoginHint
|
||
}
|
||
if (key === 'singlePageTitle') {
|
||
const s = String(rp.singlePageTitle || '').trim()
|
||
return s || READ_PAGE_FALLBACK.singlePageTitle
|
||
}
|
||
if (key === 'singlePagePaywallHint') {
|
||
const s = String(rp.singlePagePaywallHint || '').trim()
|
||
return s || READ_PAGE_FALLBACK.singlePagePaywallHint
|
||
}
|
||
return ''
|
||
}
|
||
|
||
function getMemberDetailContent(app, key) {
|
||
const v = getPagePopupContent(app, MEMBER_PATH, key)
|
||
if (v) return v
|
||
const md = (app.globalData.configCache && app.globalData.configCache.mpConfig &&
|
||
app.globalData.configCache.mpConfig.mpUi &&
|
||
app.globalData.configCache.mpConfig.mpUi.memberDetailPage) || {}
|
||
if (key === 'unlockIntroTitle') {
|
||
const s = String(md.unlockIntroTitle || '').trim()
|
||
return s || MEMBER_DETAIL_FALLBACK.unlockIntroTitle
|
||
}
|
||
if (key === 'unlockIntroBody') {
|
||
const s = String(md.unlockIntroBody || '').trim()
|
||
return s || MEMBER_DETAIL_FALLBACK.unlockIntroBody
|
||
}
|
||
return ''
|
||
}
|
||
|
||
/**
|
||
* 全局弹窗文案:与阅读页共用 pagePath(后台种子挂在 /pages/read/read),key 为 global* 开头
|
||
*/
|
||
function getGlobalPopupContent(app, key) {
|
||
const v = getPagePopupContent(app, READ_PATH, key)
|
||
if (v) return v
|
||
return GLOBAL_POPUP_FALLBACK[key] || ''
|
||
}
|
||
|
||
module.exports = {
|
||
getPagePopupContent,
|
||
getReadPageContent,
|
||
getMemberDetailContent,
|
||
getGlobalPopupContent,
|
||
MEMBER_PATH,
|
||
READ_PATH,
|
||
}
|