更新小程序首页精选推荐逻辑,调整展示的章节数据源为排名接口,优化展开功能以支持动态加载更多章节。修复图标组件的SVG映射,确保图标显示一致性。更新开发环境配置为本地地址,提升开发体验。

This commit is contained in:
Alex-larget
2026-03-20 17:02:09 +08:00
parent 1b87fa92f7
commit 905e8f1e8d
24 changed files with 337 additions and 161 deletions

View File

@@ -66,8 +66,7 @@ Page({
// 展开状态(首页精选/最新)
featuredExpanded: false,
latestExpanded: false,
featuredSectionsFull: [], // 展开时用 book/hot 加载的完整列表
featuredExpandedLoading: false,
featuredSectionsFull: [], // ranking 返回的 10 条,默认展示前 5 条
// 功能配置(搜索开关)
searchEnabled: true,
@@ -203,24 +202,29 @@ Page({
tagClass: ['tag-hot', 'tag-rec', 'tag-rec'][i] || 'tag-rec'
})
const [recRes, latestRes] = await Promise.all([
app.request({ url: '/api/miniprogram/book/recommended', silent: true }).catch(() => null),
const [rankRes, latestRes] = await Promise.all([
app.request({ url: '/api/miniprogram/book/ranking?limit=10', silent: true }).catch(() => null),
app.request({ url: '/api/miniprogram/book/latest-chapters', silent: true }).catch(() => null)
])
// 1. 精选推荐(recommended → hot 兜底
let featured = []
if (recRes && recRes.success && Array.isArray(recRes.data) && recRes.data.length > 0) {
featured = recRes.data.map((s, i) => toSection(s, i))
// 1. 精选推荐(10 条,默认展示 5 条,展开显示 10 条
let featuredFull = []
if (rankRes && rankRes.success && Array.isArray(rankRes.data) && rankRes.data.length > 0) {
featuredFull = rankRes.data.map((s, i) => toSection(s, i))
}
if (featured.length === 0) {
if (featuredFull.length === 0) {
try {
const hotRes = await app.request({ url: '/api/miniprogram/book/hot?limit=10', silent: true })
const hotList = (hotRes && hotRes.data) ? hotRes.data : []
if (hotList.length > 0) featured = hotList.slice(0, 3).map((s, i) => toSection(s, i))
if (hotList.length > 0) featuredFull = hotList.slice(0, 10).map((s, i) => toSection(s, i))
} catch (e) { console.log('[Index] book/hot 兜底失败:', e) }
}
if (featured.length > 0) this.setData({ featuredSections: featured })
if (featuredFull.length > 0) {
this.setData({
featuredSectionsFull: featuredFull,
featuredSections: featuredFull.slice(0, 5)
})
}
// 2. 最新更新 + 最新列表(共用 latest-chapters 数据)
const rawList = (latestRes && latestRes.data) ? latestRes.data : []
@@ -522,41 +526,14 @@ Page({
wx.switchTab({ url: '/pages/match/match' })
},
// 精选推荐:展开/折叠
async toggleFeaturedExpanded() {
if (this.data.featuredExpandedLoading) return
// 精选推荐:展开/折叠(默认 5 条,展开显示 10 条)
toggleFeaturedExpanded() {
trackClick('home', 'tab_click', this.data.featuredExpanded ? '精选收起' : '精选展开')
const full = this.data.featuredSectionsFull || []
if (this.data.featuredExpanded) {
const collapsed = this.data.featuredSectionsFull.length > 0 ? this.data.featuredSectionsFull.slice(0, 3) : this.data.featuredSections
this.setData({ featuredExpanded: false, featuredSections: collapsed })
return
}
if (this.data.featuredSectionsFull.length > 0) {
this.setData({ featuredExpanded: true, featuredSections: this.data.featuredSectionsFull })
return
}
this.setData({ featuredExpandedLoading: true })
try {
const res = await app.request({ url: '/api/miniprogram/book/hot?limit=50', silent: true })
const list = (res && res.data) ? res.data : []
const tagMap = ['热门', '推荐', '精选']
const full = list.map((s, i) => ({
id: s.id || s.section_id,
mid: s.mid ?? s.MID ?? 0,
title: s.sectionTitle || s.section_title || s.title || s.chapterTitle || '',
part: (s.partTitle || s.part_title || '').replace(/[_|]/g, ' ').trim(),
tag: tagMap[i % 3] || '精选',
tagClass: ['tag-hot', 'tag-rec', 'tag-rec'][i % 3] || 'tag-rec'
}))
this.setData({
featuredSectionsFull: full,
featuredSections: full,
featuredExpanded: true,
featuredExpandedLoading: false
})
} catch (e) {
console.log('[Index] 加载精选更多失败:', e)
this.setData({ featuredExpandedLoading: false })
this.setData({ featuredExpanded: false, featuredSections: full.slice(0, 5) })
} else {
this.setData({ featuredExpanded: true, featuredSections: full })
}
},

View File

@@ -96,8 +96,8 @@
<view class="section">
<view class="section-header">
<text class="section-title">精选推荐</text>
<view class="section-more" wx:if="{{featuredSections.length > 0}}" bindtap="toggleFeaturedExpanded">
<text class="more-text">{{featuredExpandedLoading ? '加载中...' : (featuredExpanded ? '收起' : '展开更多')}}</text>
<view class="section-more" wx:if="{{featuredSectionsFull.length > 5}}" bindtap="toggleFeaturedExpanded">
<text class="more-text">{{featuredExpanded ? '收起' : '展开更多'}}</text>
<icon name="{{featuredExpanded ? 'chevron-up' : 'chevron-down'}}" size="28" color="rgba(255,255,255,0.6)" customClass="more-arrow"></icon>
</view>
</view>

View File

@@ -14,7 +14,7 @@ const { trackClick } = require('../../utils/trackClick')
// 导师顾问:跳转到存客宝添加微信
// 团队招募:跳转到存客宝添加微信
let MATCH_TYPES = [
{ id: 'partner', label: '找伙伴', matchLabel: '找伙伴', icon: 'star', matchFromDB: true, showJoinAfterMatch: false },
{ id: 'partner', label: '找伙伴', matchLabel: '找伙伴', icon: 'handshake', matchFromDB: true, showJoinAfterMatch: false },
{ id: 'investor', label: '资源对接', matchLabel: '资源对接', icon: 'users', matchFromDB: true, showJoinAfterMatch: true, requirePurchase: true },
{ id: 'mentor', label: '导师顾问', matchLabel: '导师顾问', icon: 'heart', matchFromDB: true, showJoinAfterMatch: true },
{ id: 'team', label: '团队招募', matchLabel: '团队招募', icon: 'gamepad', matchFromDB: true, showJoinAfterMatch: true }
@@ -453,6 +453,13 @@ Page({
const newCount = this.data.todayMatchCount + 1
const matchesRemaining = this.data.hasFullBook ? 999999 : Math.max(0, this.data.totalMatchesAllowed - newCount)
// 规范化 commonInterestsemoji 或无效 icon 转为 SVG 图标名
const normalized = matchedUser.commonInterests?.map(item => ({
...item,
icon: /^[a-z0-9-]+$/i.test(item.icon) ? item.icon : 'target'
})) || []
if (normalized.length) matchedUser = { ...matchedUser, commonInterests: normalized }
this.setData({
isMatching: false,
currentMatch: matchedUser,

View File

@@ -53,6 +53,11 @@ Page({
}
},
onAvatarError() {
const mentor = { ...this.data.mentor, avatarError: true }
this.setData({ mentor })
},
onContactTap() {
if (!this.data.mentor || this.data.consultOptions.length === 0) {
wx.showToast({ title: '暂无咨询项目', icon: 'none' })

View File

@@ -11,7 +11,7 @@
<block wx:else>
<view class="mentor-header" wx:if="{{mentor}}">
<view class="mentor-avatar-wrap">
<image wx:if="{{mentor.avatar}}" class="mentor-avatar" src="{{mentor.avatar}}" mode="aspectFill"></image>
<image wx:if="{{mentor.avatar && !mentor.avatarError}}" class="mentor-avatar" src="{{mentor.avatar}}" mode="aspectFill" binderror="onAvatarError"></image>
<view wx:else class="mentor-avatar-placeholder">{{mentor.name ? mentor.name[0] : '?'}}</view>
</view>
<text class="mentor-name">{{mentor.name}}</text>

View File

@@ -54,6 +54,12 @@ Page({
this.loadMentors()
},
onAvatarError(e) {
const id = e.currentTarget.dataset.id
const mentors = this.data.mentors.map(m => (m.id === id ? { ...m, avatarError: true } : m))
this.setData({ mentors })
},
goDetail(e) {
const id = e.currentTarget.dataset.id
wx.navigateTo({ url: `/pages/mentor-detail/mentor-detail?id=${id}` })

View File

@@ -48,7 +48,7 @@
<view class="mentor-card" wx:for="{{mentors}}" wx:key="id">
<view class="mentor-card-inner">
<view class="mentor-avatar-wrap">
<image wx:if="{{item.avatar}}" class="mentor-avatar" src="{{item.avatar}}" mode="aspectFill"></image>
<image wx:if="{{item.avatar && !item.avatarError}}" class="mentor-avatar" src="{{item.avatar}}" mode="aspectFill" binderror="onAvatarError" data-id="{{item.id}}"></image>
<view wx:else class="mentor-avatar-placeholder">{{item.name ? item.name[0] : '?'}}</view>
</view>
<view class="mentor-info">

View File

@@ -156,7 +156,7 @@
</view>
<view class="menu-item" bindtap="handleMenuTap" data-id="giftPay">
<view class="menu-left">
<view class="menu-icon-wrap icon-gold"><image class="menu-icon-img" src="/assets/icons/gift.svg" mode="aspectFit"/></view>
<view class="menu-icon-wrap icon-teal"><icon name="gift" size="32" color="#4FD1C5" customClass="menu-icon"></icon></view>
<text class="menu-text">我的代付</text>
</view>
<icon name="chevron-right" size="28" color="rgba(255,255,255,0.35)" customClass="menu-arrow"></icon>

View File

@@ -85,6 +85,9 @@ Page({
// 余额(用于余额支付)
walletBalance: 0,
// 未解锁时显示的预览比例来自文章详情用于付费墙「已阅读X%」)
previewPercent: 20,
// 审核模式:隐藏购买按钮
auditMode: false,
@@ -337,6 +340,9 @@ Page({
chapterTitle: res.chapterTitle || ''
}
if (res.mid) updates.sectionMid = res.mid
if (res.previewPercent != null && res.previewPercent >= 1 && res.previewPercent <= 100) {
updates.previewPercent = res.previewPercent
}
this.setData(updates)
// 写入本地缓存(存 displayContent供离线/重试降级使用)
try { wx.setStorageSync(cacheKey, { ...res, content: displayContent }) } catch (_) {}

View File

@@ -94,17 +94,23 @@
<!-- 分享操作区 -->
<view class="action-section">
<view class="action-row-inline">
<view class="action-btn-inline btn-share-inline" bindtap="onShareTimelineTap">
<icon name="megaphone" size="32" color="#00CED1" customClass="action-icon-small"></icon>
<text class="action-text-small">分享到朋友圈</text>
<view class="action-btn-inline" bindtap="onShareTimelineTap">
<view class="action-btn-inner">
<image class="action-btn-icon" src="/assets/icons/share.svg" mode="aspectFit"></image>
<text class="action-text-small">分享到朋友圈</text>
</view>
</view>
<view class="action-btn-inline btn-poster-inline" bindtap="generatePoster">
<icon name="image" size="32" color="#00CED1" customClass="action-icon-small"></icon>
<text class="action-text-small">生成海报</text>
<view class="action-btn-inline" bindtap="generatePoster">
<view class="action-btn-inner">
<image class="action-btn-icon" src="/assets/icons/image.svg" mode="aspectFit"></image>
<text class="action-text-small">生成海报</text>
</view>
</view>
<view class="action-btn-inline btn-gift-inline" bindtap="showGiftShareModal" wx:if="{{isLoggedIn && !auditMode}}">
<icon name="gift" size="32" color="#00CED1" customClass="action-icon-small"></icon>
<text class="action-text-small">代付分享</text>
<view class="action-btn-inline" bindtap="showGiftShareModal" wx:if="{{isLoggedIn && !auditMode}}">
<view class="action-btn-inner">
<image class="action-btn-icon" src="/assets/icons/gift.svg" mode="aspectFit"></image>
<text class="action-text-small">代付分享</text>
</view>
</view>
</view>
<view class="share-tip-inline" wx:if="{{!auditMode}}">
@@ -128,7 +134,7 @@
<view class="paywall">
<view class="paywall-icon"><icon name="lock" size="80" color="#00CED1"></icon></view>
<text class="paywall-title">登录后继续阅读</text>
<text class="paywall-desc">已阅读50%,登录后查看完整内容</text>
<text class="paywall-desc">已阅读{{previewPercent}}%,登录后查看完整内容</text>
<view class="login-btn" bindtap="showLoginModal">
<text class="login-btn-text">手机号一键登录</text>
@@ -179,7 +185,7 @@
<view class="paywall">
<view class="paywall-icon"><icon name="lock" size="80" color="#00CED1"></icon></view>
<text class="paywall-title">解锁完整内容</text>
<text class="paywall-desc">已阅读50%,购买后继续阅读</text>
<text class="paywall-desc">已阅读{{previewPercent}}%,购买后继续阅读</text>
<!-- 购买选项(审核模式隐藏) -->
<view class="purchase-options" wx:if="{{!auditMode}}">
@@ -353,6 +359,6 @@
<!-- 右下角悬浮按钮 - 分享到朋友圈 -->
<view class="fab-share" bindtap="shareToMoments">
<icon name="globe" size="40" color="#ffffff" customClass="fab-moments-icon"></icon>
<image class="fab-circle-icon" src="/assets/icons/circle.svg" mode="aspectFit"></image>
</view>
</view>

View File

@@ -479,11 +479,10 @@
display: flex;
align-items: center;
justify-content: center;
gap: 8rpx;
padding: 24rpx 12rpx;
border-radius: 16rpx;
border: none;
background: transparent;
border: 2rpx solid rgba(0, 206, 209, 0.25);
background: rgba(0, 206, 209, 0.08);
line-height: normal;
box-sizing: border-box;
overflow: hidden;
@@ -493,31 +492,28 @@
border: none;
}
.btn-share-inline {
background: rgba(7, 193, 96, 0.15);
border: 2rpx solid rgba(7, 193, 96, 0.3);
.action-btn-inner {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 12rpx;
}
.btn-poster-inline {
background: rgba(255, 215, 0, 0.15);
border: 2rpx solid rgba(255, 215, 0, 0.3);
}
.action-icon-small {
font-size: 28rpx;
flex-shrink: 0;
.action-btn-icon {
width: 44rpx;
height: 44rpx;
filter: brightness(0) saturate(100%) invert(72%) sepia(54%) saturate(2933%) hue-rotate(134deg) brightness(101%) contrast(101%);
}
.action-text-small {
font-size: 24rpx;
color: #ffffff;
color: rgba(255, 255, 255, 0.9);
font-weight: 500;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
flex: 1;
min-width: 0;
max-width: 100%;
}
.share-tip-inline {
@@ -659,9 +655,6 @@
}
/* ===== 代付分享 ===== */
.btn-gift-inline {
/* 与 btn-share-inline 同风格 */
}
.gift-share-row {
display: flex;
align-items: center;
@@ -1255,20 +1248,15 @@
.fab-share {
position: fixed;
right: 32rpx;
width:70rpx!important;
bottom: calc(120rpx + env(safe-area-inset-bottom));
height: 70rpx;
border-radius: 60rpx;
background: linear-gradient(135deg, #00CED1 0%, #20B2AA 100%);
box-shadow: 0 8rpx 32rpx rgba(0, 206, 209, 0.4);
padding: 0;
margin: 0;
border: none;
z-index: 9999;
display:flex;
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.2s ease, box-shadow 0.2s ease;
transition: transform 0.2s ease;
}
.fab-share::after {
@@ -1277,18 +1265,10 @@
.fab-share:active {
transform: scale(0.95);
box-shadow: 0 4rpx 20rpx rgba(0, 206, 209, 0.5);
}
.fab-icon {
padding:16rpx;
width: 50rpx;
height: 50rpx;
display: block;
}
.fab-moments-icon {
font-size: 44rpx;
line-height: 1;
.fab-circle-icon {
width: 72rpx;
height: 72rpx;
}