2026年3月14日14:37:06
This commit is contained in:
@@ -230,7 +230,8 @@ Page({
|
||||
const displayContent = accessManager.canAccessFullContent(accessState) ? (res.data?.content ?? res.content) : res.content
|
||||
if (res && displayContent) {
|
||||
const { lines, segments } = contentParser.parseContent(displayContent)
|
||||
const previewCount = Math.ceil(lines.length * 0.2)
|
||||
// 预览内容由后端统一截取比例,这里展示全部预览内容
|
||||
const previewCount = lines.length
|
||||
const updates = {
|
||||
content: displayContent,
|
||||
contentParagraphs: lines,
|
||||
@@ -252,8 +253,9 @@ Page({
|
||||
try {
|
||||
const cached = wx.getStorageSync(cacheKey)
|
||||
if (cached && cached.content) {
|
||||
const { lines, segments } = contentParser.parseContent(cached.content)
|
||||
const previewCount = Math.ceil(lines.length * 0.2)
|
||||
const { lines, segments } = contentParser.parseContent(cached.content)
|
||||
// 预览内容由后端统一截取比例,这里展示全部预览内容
|
||||
const previewCount = lines.length
|
||||
this.setData({
|
||||
content: cached.content,
|
||||
contentParagraphs: lines,
|
||||
@@ -358,7 +360,8 @@ Page({
|
||||
// 设置章节内容(兼容纯文本/Markdown 与 TipTap HTML)
|
||||
setChapterContent(res) {
|
||||
const { lines, segments } = contentParser.parseContent(res.content)
|
||||
const previewCount = Math.ceil(lines.length * 0.2)
|
||||
// 预览内容由后端统一截取比例,这里展示全部预览内容
|
||||
const previewCount = lines.length
|
||||
const sectionPrice = this.data.sectionPrice ?? 1
|
||||
const sectionTitle = (res.sectionTitle || res.title || '').trim()
|
||||
|
||||
@@ -476,7 +479,7 @@ Page({
|
||||
const label = (e.currentTarget.dataset.label || '').trim()
|
||||
let tagType = (e.currentTarget.dataset.tagType || '').trim()
|
||||
let pagePath = (e.currentTarget.dataset.pagePath || '').trim()
|
||||
let mpKey = (e.currentTarget.dataset.mpKey || '').trim() || (e.currentTarget.dataset.appId || '').trim()
|
||||
let mpKey = (e.currentTarget.dataset.mpKey || '').trim()
|
||||
|
||||
// 旧格式(<a href>)tagType 为空 → 按 label 从缓存 linkTags 补充类型信息
|
||||
if (!tagType && label) {
|
||||
@@ -500,9 +503,9 @@ Page({
|
||||
if (tagType === 'miniprogram') {
|
||||
if (!mpKey && label) {
|
||||
const cached = (app.globalData.linkTagsConfig || []).find(t => t.label === label)
|
||||
if (cached) mpKey = cached.mpKey || cached.appId || ''
|
||||
if (cached) mpKey = cached.mpKey || ''
|
||||
}
|
||||
const linked = (app.globalData.linkedMiniprograms || []).find(m => (m.key || m.id) === mpKey)
|
||||
const linked = (app.globalData.linkedMiniprograms || []).find(m => m.key === mpKey)
|
||||
if (linked && linked.appId) {
|
||||
wx.navigateToMiniProgram({
|
||||
appId: linked.appId,
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
<view class="paywall">
|
||||
<view class="paywall-icon">🔒</view>
|
||||
<text class="paywall-title">登录后继续阅读</text>
|
||||
<text class="paywall-desc">已阅读20%,登录后查看完整内容</text>
|
||||
<text class="paywall-desc">已阅读50%,登录后查看完整内容</text>
|
||||
|
||||
<view class="login-btn" bindtap="showLoginModal">
|
||||
<text class="login-btn-text">立即登录</text>
|
||||
@@ -163,7 +163,7 @@
|
||||
<view class="paywall">
|
||||
<view class="paywall-icon">🔒</view>
|
||||
<text class="paywall-title">解锁完整内容</text>
|
||||
<text class="paywall-desc">已阅读20%,购买后继续阅读</text>
|
||||
<text class="paywall-desc">已阅读50%,购买后继续阅读</text>
|
||||
|
||||
<!-- 购买选项 -->
|
||||
<view class="purchase-options">
|
||||
|
||||
@@ -10,6 +10,12 @@ Page({
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
version: '1.0.0',
|
||||
isDevMode: false, // 是否开发版(用于显示切换账号入口)
|
||||
|
||||
// 切换账号(开发)
|
||||
showSwitchAccountModal: false,
|
||||
switchAccountUserId: '',
|
||||
switchAccountLoading: false,
|
||||
|
||||
// 绑定信息
|
||||
phoneNumber: '',
|
||||
@@ -28,10 +34,13 @@ Page({
|
||||
|
||||
onLoad() {
|
||||
wx.showShareMenu({ withShareTimeline: true })
|
||||
const accountInfo = wx.getAccountInfoSync ? wx.getAccountInfoSync() : null
|
||||
const envVersion = accountInfo?.miniProgram?.envVersion || ''
|
||||
this.setData({
|
||||
statusBarHeight: app.globalData.statusBarHeight,
|
||||
isLoggedIn: app.globalData.isLoggedIn,
|
||||
userInfo: app.globalData.userInfo
|
||||
userInfo: app.globalData.userInfo,
|
||||
isDevMode: envVersion === 'develop'
|
||||
})
|
||||
this.loadBindingInfo()
|
||||
},
|
||||
@@ -379,6 +388,66 @@ Page({
|
||||
this.setData({ showBindModal: false })
|
||||
},
|
||||
|
||||
// 打开切换账号弹窗(开发)
|
||||
openSwitchAccountModal() {
|
||||
this.setData({
|
||||
showSwitchAccountModal: true,
|
||||
switchAccountUserId: app.globalData.userInfo?.id || ''
|
||||
})
|
||||
},
|
||||
|
||||
// 关闭切换账号弹窗
|
||||
closeSwitchAccountModal() {
|
||||
if (this.data.switchAccountLoading) return
|
||||
this.setData({ showSwitchAccountModal: false, switchAccountUserId: '' })
|
||||
},
|
||||
|
||||
// 切换账号 userId 输入
|
||||
onSwitchAccountUserIdInput(e) {
|
||||
this.setData({ switchAccountUserId: e.detail.value.trim() })
|
||||
},
|
||||
|
||||
// 确认切换账号
|
||||
async confirmSwitchAccount() {
|
||||
const userId = this.data.switchAccountUserId.trim()
|
||||
if (!userId || this.data.switchAccountLoading) return
|
||||
this.setData({ switchAccountLoading: true })
|
||||
try {
|
||||
const res = await app.request('/api/miniprogram/dev/login-as', {
|
||||
method: 'POST',
|
||||
data: { userId }
|
||||
})
|
||||
if (res && res.success && res.data) {
|
||||
const { token, user } = res.data
|
||||
const openId = res.data.openId || ''
|
||||
wx.setStorageSync('token', token)
|
||||
wx.setStorageSync('userInfo', user)
|
||||
app.globalData.userInfo = user
|
||||
app.globalData.isLoggedIn = true
|
||||
app.globalData.purchasedSections = user.purchasedSections || []
|
||||
app.globalData.hasFullBook = user.hasFullBook || false
|
||||
app.globalData.isVip = user.isVip || false
|
||||
app.globalData.vipExpireDate = user.vipExpireDate || ''
|
||||
if (openId) {
|
||||
app.globalData.openId = openId
|
||||
wx.setStorageSync('openId', openId)
|
||||
}
|
||||
this.setData({
|
||||
showSwitchAccountModal: false,
|
||||
switchAccountUserId: '',
|
||||
switchAccountLoading: false
|
||||
})
|
||||
this.loadBindingInfo()
|
||||
wx.showToast({ title: '已切换为 ' + (user.nickname || userId), icon: 'success' })
|
||||
} else {
|
||||
throw new Error(res?.error || '切换失败')
|
||||
}
|
||||
} catch (e) {
|
||||
this.setData({ switchAccountLoading: false })
|
||||
wx.showToast({ title: e.message || '切换失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
// 清除缓存
|
||||
clearCache() {
|
||||
wx.showModal({
|
||||
|
||||
@@ -109,6 +109,15 @@
|
||||
<text class="tip-text">提示:绑定微信号才能使用提现功能</text>
|
||||
</view>
|
||||
|
||||
<!-- 开发专用:切换账号(仅开发版显示) -->
|
||||
<view class="dev-switch-card" wx:if="{{isDevMode}}" bindtap="openSwitchAccountModal">
|
||||
<view class="dev-switch-inner">
|
||||
<text class="dev-switch-icon">🔧</text>
|
||||
<text class="dev-switch-text">切换账号(开发)</text>
|
||||
<text class="dev-switch-desc">输入 userId 切换为其他账号调试</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="logout-btn" wx:if="{{isLoggedIn}}" bindtap="handleLogout">退出登录</view>
|
||||
</view>
|
||||
|
||||
@@ -143,4 +152,29 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 切换账号弹窗(开发) -->
|
||||
<view class="modal-overlay" wx:if="{{showSwitchAccountModal}}" bindtap="closeSwitchAccountModal">
|
||||
<view class="modal-content" catchtap="stopPropagation">
|
||||
<view class="modal-header">
|
||||
<text class="modal-title">切换账号(开发)</text>
|
||||
<view class="modal-close" bindtap="closeSwitchAccountModal">✕</view>
|
||||
</view>
|
||||
<view class="modal-body">
|
||||
<view class="input-wrapper">
|
||||
<input
|
||||
class="form-input"
|
||||
placeholder="请输入目标用户的 userId(如 ogpTW5fmXRGNpoUbXB3UEqnVe5Tg)"
|
||||
placeholder-class="input-placeholder"
|
||||
value="{{switchAccountUserId}}"
|
||||
bindinput="onSwitchAccountUserIdInput"
|
||||
/>
|
||||
</view>
|
||||
<text class="bind-tip">从管理端或数据库获取要调试的用户 ID,切换后将以该用户身份操作</text>
|
||||
<view class="btn-primary {{!switchAccountUserId || switchAccountLoading ? 'btn-disabled' : ''}}" bindtap="confirmSwitchAccount">
|
||||
{{switchAccountLoading ? '切换中...' : '确认切换'}}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -95,6 +95,13 @@
|
||||
.item-arrow { font-size: 28rpx; color: rgba(255,255,255,0.3); }
|
||||
.item-value { font-size: 26rpx; color: rgba(255,255,255,0.5); }
|
||||
|
||||
/* 开发专用:切换账号卡片 */
|
||||
.dev-switch-card { background: rgba(255,165,0,0.08); border: 2rpx solid rgba(255,165,0,0.3); border-radius: 32rpx; padding: 28rpx 32rpx; margin-bottom: 24rpx; }
|
||||
.dev-switch-inner { display: flex; flex-direction: column; gap: 8rpx; }
|
||||
.dev-switch-icon { font-size: 36rpx; }
|
||||
.dev-switch-text { font-size: 28rpx; font-weight: 600; color: #FFA500; }
|
||||
.dev-switch-desc { font-size: 24rpx; color: rgba(255,255,255,0.5); }
|
||||
|
||||
/* 退出登录按钮 */
|
||||
.logout-btn { margin-top: 48rpx; padding: 28rpx; background: rgba(244,67,54,0.1); border: 2rpx solid rgba(244,67,54,0.3); border-radius: 24rpx; text-align: center; font-size: 28rpx; color: #F44336; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user