69 lines
2.4 KiB
JavaScript
69 lines
2.4 KiB
JavaScript
|
|
/**
|
|||
|
|
* 从 mpConfig.mpUi.pagePopupItems 按 pagePath + key 取文案(管理端 CRUD)。
|
|||
|
|
* 兼容旧版 mpUi.memberDetailPage / readPage 字段。
|
|||
|
|
*
|
|||
|
|
* 当前代码显式引用的键(与 soul-admin 默认种子 / db.defaultMpUi 一致,勿改 key 除非双端同步):
|
|||
|
|
* - MEMBER_PATH unlockIntroTitle, unlockIntroBody → member-detail.js _showUnlockIntroThenLogin
|
|||
|
|
* - READ_PATH beforeLoginHint, singlePageTitle, singlePagePaywallHint → read.js onLoad
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
const MEMBER_PATH = '/pages/member-detail/member-detail'
|
|||
|
|
const READ_PATH = '/pages/read/read'
|
|||
|
|
|
|||
|
|
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') return String(rp.beforeLoginHint || '').trim()
|
|||
|
|
if (key === 'singlePageTitle') return String(rp.singlePageTitle || '').trim()
|
|||
|
|
if (key === 'singlePagePaywallHint') return String(rp.singlePagePaywallHint || '').trim()
|
|||
|
|
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') return String(md.unlockIntroTitle || '').trim()
|
|||
|
|
if (key === 'unlockIntroBody') return String(md.unlockIntroBody || '').trim()
|
|||
|
|
return ''
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
module.exports = {
|
|||
|
|
getPagePopupContent,
|
|||
|
|
getReadPageContent,
|
|||
|
|
getMemberDetailContent,
|
|||
|
|
MEMBER_PATH,
|
|||
|
|
READ_PATH,
|
|||
|
|
}
|