fix: 全面优化小程序功能

🔧 数据库配置:
- 切换到腾讯云外网数据库
- 配置连接参数和连接池

🎨 界面优化:
- 未登录时只显示登录按钮,隐藏其他功能
- 优化登录卡片样式
- 修复章节图标和标题对齐问题

💳 支付流程优化:
- 增加重复购买检测,避免重复支付
- 优化openId获取逻辑,支持静默获取
- 已登录用户可直接支付,无需重复登录

📊 后台管理:
- 创建章节管理API (/api/admin/chapters)
- 创建章节管理页面 (/admin/chapters)
- 支持查看所有章节、修改价格、设置免费状态
This commit is contained in:
卡若
2026-01-23 17:25:15 +08:00
parent 1e1e6a1093
commit 7ff181f743
11 changed files with 1131 additions and 254 deletions

View File

@@ -336,15 +336,15 @@
}
.section-icon {
width: 32rpx;
height: 32rpx;
min-width: 32rpx;
font-size: 24rpx;
width: 36rpx;
height: 36rpx;
min-width: 36rpx;
font-size: 28rpx;
flex-shrink: 0;
display: inline-flex;
display: flex;
align-items: center;
justify-content: center;
margin-right: 4rpx;
line-height: 1;
}
.icon-unlocked {
@@ -361,8 +361,11 @@
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
line-height: 32rpx;
line-height: 36rpx;
flex: 1;
height: 36rpx;
display: flex;
align-items: center;
}
.section-right {

View File

@@ -11,31 +11,16 @@
<!-- 导航栏占位 -->
<view class="nav-placeholder" style="height: {{statusBarHeight + 44}}px;"></view>
<!-- 用户卡片 - 未登录状态 -->
<view class="user-card card-gradient" wx:if="{{!isLoggedIn}}">
<view class="user-header">
<view class="avatar avatar-empty">
<text class="avatar-icon">👤</text>
</view>
<view class="user-info">
<view class="login-btn" bindtap="showLogin">点击登录</view>
<text class="user-subtitle">解锁专属权益</text>
</view>
</view>
<view class="stats-grid">
<view class="stat-item">
<text class="stat-value brand-color">0</text>
<text class="stat-label">已购章节</text>
</view>
<view class="stat-item">
<text class="stat-value brand-color">0</text>
<text class="stat-label">推荐好友</text>
</view>
<view class="stat-item">
<text class="stat-value gold-color">--</text>
<text class="stat-label">待领收益</text>
</view>
<!-- 用户卡片 - 未登录状态 - 只显示登录提示 -->
<view class="user-card card-gradient login-card" wx:if="{{!isLoggedIn}}">
<view class="login-prompt">
<view class="login-icon-large">🔐</view>
<text class="login-title">登录 Soul创业实验</text>
<text class="login-desc">登录后可购买章节、参与匹配、赚取佣金</text>
<button class="btn-wechat-large" bindtap="handleWechatLogin">
<text class="btn-icon">微</text>
<text>微信快捷登录</text>
</button>
</view>
</view>
@@ -71,17 +56,6 @@
</view>
</view>
<!-- 推广入口 - 未登录 -->
<view class="referral-card" wx:if="{{!isLoggedIn}}" bindtap="showLogin">
<view class="referral-left">
<view class="referral-icon gold-bg">🎁</view>
<view class="referral-info">
<text class="referral-title">推广赚收益</text>
<text class="referral-desc">登录后查看详情</text>
</view>
</view>
<view class="referral-btn">立即登录</view>
</view>
<!-- Tab切换 - 仅登录用户显示 -->
<view class="tab-bar-custom" wx:if="{{isLoggedIn}}">
@@ -100,29 +74,6 @@
</view>
</view>
<!-- 基础功能菜单 - 未登录用户 -->
<view class="basic-menu" wx:if="{{!isLoggedIn}}">
<view class="menu-card card">
<view class="menu-item" bindtap="goToChapters">
<view class="menu-left">
<view class="menu-icon icon-brand">📚</view>
<text class="menu-title">购买章节</text>
</view>
<view class="menu-right">
<text class="menu-arrow">→</text>
</view>
</view>
<view class="menu-item" bindtap="goToAbout">
<view class="menu-left">
<view class="menu-icon icon-gray"></view>
<text class="menu-title">关于我们</text>
</view>
<view class="menu-right">
<text class="menu-arrow">→</text>
</view>
</view>
</view>
</view>
<!-- 概览内容 - 仅登录用户显示 -->
<view class="tab-content" wx:if="{{activeTab === 'overview' && isLoggedIn}}">

View File

@@ -113,6 +113,69 @@
margin-top: 4rpx;
}
/* ===== 登录卡片样式 ===== */
.login-card {
min-height: 400rpx;
display: flex;
align-items: center;
justify-content: center;
}
.login-prompt {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
padding: 40rpx 0;
width: 100%;
}
.login-icon-large {
font-size: 80rpx;
margin-bottom: 32rpx;
}
.login-title {
font-size: 36rpx;
font-weight: 600;
color: #ffffff;
margin-bottom: 16rpx;
}
.login-desc {
font-size: 26rpx;
color: rgba(255, 255, 255, 0.5);
margin-bottom: 48rpx;
line-height: 1.6;
}
.btn-wechat-large {
display: flex;
align-items: center;
justify-content: center;
gap: 16rpx;
width: 80%;
padding: 28rpx 0;
background: linear-gradient(135deg, #07C160 0%, #06AD56 100%);
border-radius: 48rpx;
border: none;
color: #ffffff;
font-size: 32rpx;
font-weight: 600;
}
.btn-wechat-large .btn-icon {
width: 48rpx;
height: 48rpx;
background: rgba(255, 255, 255, 0.2);
border-radius: 8rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 28rpx;
font-weight: 700;
}
.user-name {
font-size: 36rpx;
font-weight: 600;

View File

@@ -363,6 +363,20 @@ ${id === 'preface' || id === 'epilogue' || id.startsWith('appendix') || id === '
// 处理支付 - 调用真实微信支付接口
async processPayment(type, sectionId, amount) {
// 检查是否已购买(避免重复购买)
if (type === 'section' && sectionId) {
const purchasedSections = app.globalData.purchasedSections || []
if (purchasedSections.includes(sectionId)) {
wx.showToast({ title: '已购买过此章节', icon: 'none' })
return
}
}
if (type === 'fullbook' && app.globalData.hasFullBook) {
wx.showToast({ title: '已购买全书', icon: 'none' })
return
}
this.setData({ isPaying: true })
try {
@@ -370,17 +384,23 @@ ${id === 'preface' || id === 'epilogue' || id.startsWith('appendix') || id === '
let openId = app.globalData.openId || wx.getStorageSync('openId')
if (!openId) {
console.log('[Pay] 需要先获取openId')
console.log('[Pay] 需要先获取openId,尝试静默获取')
openId = await app.getOpenId()
if (!openId) {
wx.showModal({
title: '提示',
content: '需要登录后才能支付,请先登录',
showCancel: false
})
this.setData({ showLoginModal: true, isPaying: false })
return
// openId获取失败但已登录用户可以使用用户ID替代
if (app.globalData.isLoggedIn && app.globalData.userInfo?.id) {
console.log('[Pay] 使用用户ID作为替代')
openId = app.globalData.userInfo.id
} else {
wx.showModal({
title: '提示',
content: '需要登录后才能支付,请先登录',
showCancel: false
})
this.setData({ showLoginModal: true, isPaying: false })
return
}
}
}