更新小程序首页精选推荐逻辑,调整展示的章节数据源为排名接口,优化展开功能以支持动态加载更多章节。修复图标组件的SVG映射,确保图标显示一致性。更新开发环境配置为本地地址,提升开发体验。
This commit is contained in:
@@ -13,8 +13,8 @@ const DEFAULT_WITHDRAW_TMPL_ID = 'u3MbZGPRkrZIk-I7QdpwzFxnO_CeQPaCWF2FkiIablE'
|
||||
App({
|
||||
globalData: {
|
||||
// API 基础地址:开发时修改下面一行切换环境
|
||||
baseUrl: "https://soulapi.quwanzhi.com",
|
||||
// baseUrl: 'http://localhost:8080', // 开发
|
||||
// baseUrl: "https://soulapi.quwanzhi.com",
|
||||
baseUrl: 'http://localhost:8080', // 开发
|
||||
// baseUrl: 'https://souldev.quwanzhi.com', // 测试
|
||||
// 小程序配置 - 真实AppID
|
||||
appId: DEFAULT_APP_ID,
|
||||
|
||||
1
miniprogram/assets/icons/circle.svg
Normal file
1
miniprogram/assets/icons/circle.svg
Normal file
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1773994222626" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8757" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M512 954.24A442.24 442.24 0 1 0 69.76 512 442.08 442.08 0 0 0 512 954.24z m0-30.88a401.12 401.12 0 0 1-137.12-21.92V621.6l274.24 276.64A356 356 0 0 1 512 923.36z m285.28-119.68a400 400 0 0 1-112 81.28L487.2 687.04l389.44 1.92a359.52 359.52 0 0 1-79.2 114.72z m118.24-289.28a400 400 0 0 1-21.92 136.96H613.76l276.8-273.92a355.04 355.04 0 0 1 25.12 136.96z m-232.8-368a355.68 355.68 0 0 1 114.56 79.04 402.88 402.88 0 0 1 81.44 112L680.96 535.52zM512 653.6A141.6 141.6 0 1 1 653.6 512 141.6 141.6 0 0 1 512 653.6z m0-548.32A400 400 0 0 1 649.12 128v280L375.04 130.4A356.32 356.32 0 0 1 512 105.28z m-285.28 119.84a405.44 405.44 0 0 1 112-81.44l198.4 198.08-389.44-2.08a355.68 355.68 0 0 1 79.04-114.56zM108.64 514.4a400 400 0 0 1 21.92-136.96h279.84L133.6 651.36a357.92 357.92 0 0 1-24.96-136.96z m234.72-21.12l-1.92 389.44a357.12 357.12 0 0 1-114.72-79.04 401.76 401.76 0 0 1-81.28-112z" fill="#FFFFFF" p-id="8758"></path><path d="M649.12 128A400 400 0 0 0 512 105.28a356.32 356.32 0 0 0-137.12 25.12l274.08 276.8z" fill="#FC6B4F" p-id="8759"></path><path d="M797.44 225.12a355.68 355.68 0 0 0-114.56-79.04l-1.92 389.44 197.92-198.08a402.88 402.88 0 0 0-81.44-112.32z" fill="#7838F2" p-id="8760"></path><path d="M893.76 651.36a400 400 0 0 0 21.92-136.96 355.04 355.04 0 0 0-25.12-136.96l-276.8 273.92z" fill="#5698F3" p-id="8761"></path><path d="M685.12 884.96a400 400 0 0 0 112-81.28 359.52 359.52 0 0 0 79.2-114.72l-389.44-1.92z" fill="#20E9F4" p-id="8762"></path><path d="M375.04 901.44A401.12 401.12 0 0 0 512 923.36a356 356 0 0 0 136.96-25.12L375.04 621.6z" fill="#00FD60" p-id="8763"></path><path d="M341.44 882.72l1.92-389.44L145.44 691.2a401.76 401.76 0 0 0 81.28 112 357.12 357.12 0 0 0 114.72 79.52z" fill="#ABFB5B" p-id="8764"></path><path d="M130.56 377.44a400 400 0 0 0-21.92 136.96 357.92 357.92 0 0 0 24.96 136.96l276.8-273.92z" fill="#F0E254" p-id="8765"></path><path d="M339.04 144a405.44 405.44 0 0 0-112 81.44 355.68 355.68 0 0 0-79.04 114.56l389.44 2.08z" fill="#F6B351" p-id="8766"></path></svg>
|
||||
|
After Width: | Height: | Size: 2.3 KiB |
@@ -135,7 +135,7 @@ Component({
|
||||
'run-in': '\ue6a7',
|
||||
'pin': '\ue6a8',
|
||||
'save': '\ue6a9',
|
||||
'search': '', // 强制走 SVG
|
||||
'search': '\ue6aa',
|
||||
'share': '\ue6ab',
|
||||
'scanning': '\ue6ac',
|
||||
'security': '\ue6ad',
|
||||
@@ -157,19 +157,19 @@ Component({
|
||||
'chevron-right': '\ue6c6',
|
||||
'chevron-down': '\ue6c4',
|
||||
'chevron-up': '\ue6c2',
|
||||
'x': '', // 强制走 SVG
|
||||
'check': '', // 强制走 SVG
|
||||
'x': '\ue6c3',
|
||||
'check': '\ue6c7',
|
||||
'trash-2': '\ue66a',
|
||||
'pencil': '\ue685',
|
||||
'zap': '', // 强制走 SVG,找伙伴页等统一用 Lucide 风格
|
||||
'zap': '\ue75c',
|
||||
'info': '\ue69c',
|
||||
'map-pin': '\ue6a8',
|
||||
'message-circle': '', // 强制走 SVG
|
||||
'smartphone': '', // 强制走 SVG
|
||||
'message-circle': '\ue678',
|
||||
'smartphone': '\ue6a0',
|
||||
'refresh-cw': '\ue6a4',
|
||||
'shield': '\ue6ad',
|
||||
'star': '', // 强制走 SVG
|
||||
'heart': '', // 强制走 SVG
|
||||
'star': '\ue689',
|
||||
'heart': '\ue68e',
|
||||
'bar-chart': '\ue672',
|
||||
'clock': '\ue6b5',
|
||||
}
|
||||
@@ -224,9 +224,7 @@ Component({
|
||||
'corner-down-left': s + '<polyline points="9 10 4 15 9 20"/><path d="M20 4v7a4 4 0 0 1-4 4H4"/></svg>',
|
||||
'folder': s + '<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/><line x1="12" y1="11" x2="12" y2="17"/></svg>',
|
||||
'bar-chart': s + '<line x1="12" y1="20" x2="12" y2="10"/><line x1="18" y1="20" x2="18" y2="4"/><line x1="6" y1="20" x2="6" y2="16"/></svg>',
|
||||
'link': s + '<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>',
|
||||
'zap': s + '<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>',
|
||||
'x': s + '<path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>'
|
||||
'link': s + '<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>'
|
||||
}
|
||||
return svgMap[name] || ''
|
||||
},
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
// 规范化 commonInterests:emoji 或无效 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,
|
||||
|
||||
@@ -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' })
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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}` })
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 (_) {}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# 对接后端 base URL(不改 API 路径,仅改此处即可切换 Next → Gin)
|
||||
# 宝塔部署:若 API 站点开启了强制 HTTPS,这里必须用 https,否则预检请求会被重定向导致 CORS 报错
|
||||
# VITE_API_BASE_URL=http://localhost:3006
|
||||
# VITE_API_BASE_URL=http://localhost:8080
|
||||
VITE_API_BASE_URL=https://soulapi.quwanzhi.com
|
||||
VITE_API_BASE_URL=http://localhost:8080
|
||||
# VITE_API_BASE_URL=https://soulapi.quwanzhi.com
|
||||
|
||||
# VITE_API_BASE_URL=https://souldev.quwanzhi.com
|
||||
|
||||
|
||||
@@ -127,6 +127,7 @@ interface EditingSection {
|
||||
hotScore?: number
|
||||
editionStandard?: boolean
|
||||
editionPremium?: boolean
|
||||
previewPercent?: number | null
|
||||
}
|
||||
|
||||
function buildTree(sections: SectionListItem[], hotRankMap: Map<string, number>): Part[] {
|
||||
@@ -205,6 +206,7 @@ export function ContentPage() {
|
||||
isNew: false,
|
||||
isPinned: false,
|
||||
hotScore: 0,
|
||||
previewPercent: undefined as number | undefined,
|
||||
})
|
||||
|
||||
const [editingPart, setEditingPart] = useState<{ id: string; title: string } | null>(null)
|
||||
@@ -733,11 +735,11 @@ export function ContentPage() {
|
||||
section.mid != null && section.mid > 0
|
||||
? `/api/db/book?action=read&mid=${section.mid}`
|
||||
: `/api/db/book?action=read&id=${encodeURIComponent(section.id)}`
|
||||
const data = await get<{ success?: boolean; section?: { title?: string; price?: number; content?: string; editionStandard?: boolean; editionPremium?: boolean }; error?: string }>(
|
||||
const data = await get<{ success?: boolean; section?: { title?: string; price?: number; content?: string; editionStandard?: boolean; editionPremium?: boolean; previewPercent?: number | null }; error?: string }>(
|
||||
url,
|
||||
)
|
||||
if (data?.success && data.section) {
|
||||
const sec = data.section as { isNew?: boolean; editionStandard?: boolean; editionPremium?: boolean }
|
||||
const sec = data.section as { isNew?: boolean; editionStandard?: boolean; editionPremium?: boolean; previewPercent?: number | null }
|
||||
const isPremium = sec.editionPremium === true
|
||||
setEditingSection({
|
||||
id: section.id,
|
||||
@@ -752,6 +754,7 @@ export function ContentPage() {
|
||||
hotScore: section.hotScore ?? 0,
|
||||
editionStandard: isPremium ? false : (sec.editionStandard ?? true),
|
||||
editionPremium: isPremium,
|
||||
previewPercent: sec.previewPercent ?? undefined,
|
||||
})
|
||||
} else {
|
||||
setEditingSection({
|
||||
@@ -767,6 +770,7 @@ export function ContentPage() {
|
||||
hotScore: section.hotScore ?? 0,
|
||||
editionStandard: true,
|
||||
editionPremium: false,
|
||||
previewPercent: undefined,
|
||||
})
|
||||
if (data && !(data as { success?: boolean }).success) {
|
||||
toast.error('无法读取文件内容: ' + ((data as { error?: string }).error || '未知错误'))
|
||||
@@ -815,6 +819,9 @@ export function ContentPage() {
|
||||
hotScore: editingSection.hotScore,
|
||||
editionStandard: editingSection.editionPremium ? false : (editingSection.editionStandard ?? true),
|
||||
editionPremium: editingSection.editionPremium ?? false,
|
||||
...(editingSection.previewPercent != null && editingSection.previewPercent > 0 && editingSection.previewPercent <= 100
|
||||
? { previewPercent: editingSection.previewPercent }
|
||||
: { previewPercent: 0 }),
|
||||
saveToFile: true,
|
||||
},
|
||||
{ timeout: SAVE_REQUEST_TIMEOUT },
|
||||
@@ -826,7 +833,8 @@ export function ContentPage() {
|
||||
if (res && (res as { success?: boolean }).success !== false) {
|
||||
toast.success(`已保存:${editingSection.title}`)
|
||||
setEditingSection(null)
|
||||
loadList()
|
||||
await loadList()
|
||||
await loadRanking()
|
||||
loadPersons()
|
||||
loadLinkTags()
|
||||
} else {
|
||||
@@ -866,6 +874,9 @@ export function ContentPage() {
|
||||
editionStandard: newSection.editionPremium ? false : (newSection.editionStandard ?? true),
|
||||
editionPremium: newSection.editionPremium ?? false,
|
||||
hotScore: newSection.hotScore ?? 0,
|
||||
...(newSection.previewPercent != null && newSection.previewPercent > 0 && newSection.previewPercent <= 100
|
||||
? { previewPercent: newSection.previewPercent }
|
||||
: {}),
|
||||
saveToFile: false,
|
||||
},
|
||||
{ timeout: SAVE_REQUEST_TIMEOUT },
|
||||
@@ -884,8 +895,9 @@ export function ContentPage() {
|
||||
}
|
||||
toast.success(`章节创建成功:${newSection.title}`)
|
||||
setShowNewSectionModal(false)
|
||||
setNewSection({ id: '', title: '', price: 1, partId: 'part-1', chapterId: 'chapter-1', content: '', editionStandard: true, editionPremium: false, isFree: false, isNew: false, isPinned: false, hotScore: 0 })
|
||||
loadList()
|
||||
setNewSection({ id: '', title: '', price: 1, partId: 'part-1', chapterId: 'chapter-1', content: '', editionStandard: true, editionPremium: false, isFree: false, isNew: false, isPinned: false, hotScore: 0, previewPercent: undefined })
|
||||
await loadList()
|
||||
await loadRanking()
|
||||
loadPersons()
|
||||
loadLinkTags()
|
||||
} else {
|
||||
@@ -1422,6 +1434,25 @@ export function ContentPage() {
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label className="text-gray-300">未解锁预览比例 (%)</Label>
|
||||
<Input
|
||||
type="number"
|
||||
min="0"
|
||||
max="100"
|
||||
placeholder="空则用全局"
|
||||
className="bg-[#0a1628] border-gray-700 text-white"
|
||||
value={newSection.previewPercent ?? ''}
|
||||
onChange={(e) => {
|
||||
const v = e.target.value === '' ? undefined : Number(e.target.value)
|
||||
setNewSection({
|
||||
...newSection,
|
||||
previewPercent: v === undefined ? undefined : Math.max(0, Math.min(100, v)),
|
||||
})
|
||||
}}
|
||||
/>
|
||||
<span className="text-xs text-gray-500">小程序未付费用户显示前 N% 内容,空则用全局设置</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label className="text-gray-300">章节标题 *</Label>
|
||||
@@ -2091,6 +2122,25 @@ export function ContentPage() {
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label className="text-gray-300">未解锁预览比例 (%)</Label>
|
||||
<Input
|
||||
type="number"
|
||||
min="0"
|
||||
max="100"
|
||||
placeholder="空则用全局"
|
||||
className="bg-[#0a1628] border-gray-700 text-white"
|
||||
value={editingSection.previewPercent ?? ''}
|
||||
onChange={(e) => {
|
||||
const v = e.target.value === '' ? undefined : Number(e.target.value)
|
||||
setEditingSection({
|
||||
...editingSection,
|
||||
previewPercent: v === undefined ? undefined : Math.max(0, Math.min(100, v)),
|
||||
})
|
||||
}}
|
||||
/>
|
||||
<span className="text-xs text-gray-500">小程序未付费用户显示前 N% 内容,空则用全局设置</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label className="text-gray-300">章节标题</Label>
|
||||
@@ -2628,16 +2678,6 @@ export function ContentPage() {
|
||||
>
|
||||
<Users className="w-3 h-3" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" className="text-gray-400 hover:text-amber-400 h-6 px-2" title="编辑计划(跳转存客宝)" onClick={() => {
|
||||
const planId = (p as { ckbPlanId?: number }).ckbPlanId
|
||||
if (planId) {
|
||||
window.open(`https://h5.ckb.quwanzhi.com/#/scenarios/edit/${planId}`, '_blank')
|
||||
} else {
|
||||
toast.info('该人物尚未同步存客宝计划,请先保存后等待同步完成')
|
||||
}
|
||||
}}>
|
||||
<ExternalLink className="w-3 h-3" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" className="text-red-400 hover:text-red-300 h-6 px-2" title="删除(同时删除存客宝对应获客计划)" onClick={() => setPersonToDelete(p)}>
|
||||
<X className="w-3 h-3" />
|
||||
</Button>
|
||||
|
||||
@@ -138,6 +138,7 @@ export function DistributionPage() {
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [searchTerm, setSearchTerm] = useState('')
|
||||
const [effectiveSearch, setEffectiveSearch] = useState('') // 回车或点击搜索按钮后生效
|
||||
const [statusFilter, setStatusFilter] = useState<string>('all')
|
||||
const [page, setPage] = useState(1)
|
||||
const [pageSize, setPageSize] = useState(10)
|
||||
@@ -179,7 +180,7 @@ export function DistributionPage() {
|
||||
|
||||
useEffect(() => {
|
||||
setPage(1)
|
||||
}, [activeTab, statusFilter])
|
||||
}, [activeTab, statusFilter, effectiveSearch])
|
||||
|
||||
useEffect(() => {
|
||||
loadTabData(activeTab)
|
||||
@@ -192,7 +193,7 @@ export function DistributionPage() {
|
||||
if (activeTab === 'giftPay') {
|
||||
loadTabData('giftPay', true)
|
||||
}
|
||||
}, [page, pageSize, statusFilter, searchTerm, giftPayPage, giftPayStatusFilter])
|
||||
}, [page, pageSize, statusFilter, effectiveSearch, giftPayPage, giftPayStatusFilter])
|
||||
|
||||
useEffect(() => {
|
||||
if (activeTab === 'withdrawals') loadAutoApprove()
|
||||
@@ -217,7 +218,7 @@ export function DistributionPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadTabData(tab: string, force = false) {
|
||||
async function loadTabData(tab: string, force = false, overrides?: { search?: string; page?: number }) {
|
||||
if (!force && loadedTabs.has(tab)) return
|
||||
setLoading(true)
|
||||
try {
|
||||
@@ -227,11 +228,13 @@ export function DistributionPage() {
|
||||
break
|
||||
case 'orders': {
|
||||
try {
|
||||
const searchVal = overrides?.search ?? effectiveSearch
|
||||
const pageVal = overrides?.page ?? page
|
||||
const params = new URLSearchParams({
|
||||
page: String(page),
|
||||
page: String(pageVal),
|
||||
pageSize: String(pageSize),
|
||||
...(statusFilter !== 'all' && { status: statusFilter }),
|
||||
...(searchTerm && { search: searchTerm }),
|
||||
...(searchVal && { search: searchVal }),
|
||||
})
|
||||
const ordersData = await get<{ success?: boolean; orders?: Order[]; total?: number }>(
|
||||
`/api/admin/orders?${params}`,
|
||||
@@ -352,6 +355,12 @@ export function DistributionPage() {
|
||||
}
|
||||
}
|
||||
|
||||
function handleOrdersSearch() {
|
||||
setEffectiveSearch(searchTerm)
|
||||
setPage(1)
|
||||
void loadTabData('orders', true, { search: searchTerm, page: 1 })
|
||||
}
|
||||
|
||||
async function refreshCurrentTab() {
|
||||
setError(null)
|
||||
setLoadedTabs((prev) => {
|
||||
@@ -591,6 +600,7 @@ export function DistributionPage() {
|
||||
setActiveTab(tab.key as typeof activeTab)
|
||||
setStatusFilter('all')
|
||||
setSearchTerm('')
|
||||
setEffectiveSearch('')
|
||||
if (tab.key === 'giftPay') {
|
||||
setGiftPayStatusFilter('')
|
||||
setGiftPayPage(1)
|
||||
@@ -608,7 +618,7 @@ export function DistributionPage() {
|
||||
))}
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
{loading && activeTab !== 'orders' ? (
|
||||
<div className="flex items-center justify-center py-20">
|
||||
<RefreshCw className="w-8 h-8 text-[#38bdac] animate-spin" />
|
||||
<span className="ml-2 text-gray-400">加载中...</span>
|
||||
@@ -909,14 +919,32 @@ export function DistributionPage() {
|
||||
{activeTab === 'orders' && (
|
||||
<div className="space-y-4">
|
||||
<div className="flex flex-wrap gap-4 items-center">
|
||||
<div className="relative flex-1 min-w-[200px]">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400" />
|
||||
<Input
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
placeholder="搜索订单号、用户名、手机号..."
|
||||
className="pl-10 bg-[#0f2137] border-gray-700 text-white"
|
||||
/>
|
||||
<div className="flex flex-1 min-w-[200px] gap-2">
|
||||
<div className="relative flex-1">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400" />
|
||||
<Input
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
handleOrdersSearch()
|
||||
}
|
||||
}}
|
||||
placeholder="输入订单号、用户名或手机号,回车或点击搜索"
|
||||
className="pl-10 pr-3 bg-[#0f2137] border-gray-700 text-white"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={handleOrdersSearch}
|
||||
disabled={loading}
|
||||
className="border-gray-600 text-gray-300 hover:bg-gray-700/50 bg-transparent shrink-0"
|
||||
>
|
||||
<Search className="w-4 h-4 mr-2" />
|
||||
搜索
|
||||
</Button>
|
||||
</div>
|
||||
<select
|
||||
value={statusFilter}
|
||||
@@ -942,7 +970,12 @@ export function DistributionPage() {
|
||||
</div>
|
||||
<Card className="bg-[#0f2137] border-gray-700/50">
|
||||
<CardContent className="p-0">
|
||||
{orders.length === 0 ? (
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<RefreshCw className="w-6 h-6 text-[#38bdac] animate-spin" />
|
||||
<span className="ml-2 text-gray-400">加载中...</span>
|
||||
</div>
|
||||
) : orders.length === 0 ? (
|
||||
<div className="py-12 text-center text-gray-500">暂无订单数据</div>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
|
||||
@@ -50,7 +50,7 @@ var allChaptersSelectCols = []string{
|
||||
var chapterMetaCols = []string{
|
||||
"mid", "id", "part_id", "part_title", "chapter_id", "chapter_title",
|
||||
"section_title", "word_count", "is_free", "price", "sort_order", "status",
|
||||
"is_new", "edition_standard", "edition_premium", "hot_score", "created_at", "updated_at",
|
||||
"is_new", "edition_standard", "edition_premium", "hot_score", "preview_percent", "created_at", "updated_at",
|
||||
}
|
||||
|
||||
// allChaptersCache 内存缓存,减轻 DB 压力,30 秒 TTL
|
||||
@@ -621,12 +621,19 @@ func findChapterAndRespond(c *gin.Context, whereFn func(*gorm.DB) *gorm.DB) {
|
||||
userID := c.Query("userId")
|
||||
isPremium := ch.EditionPremium != nil && *ch.EditionPremium
|
||||
var returnContent string
|
||||
effectivePreviewPercent := 20 // 默认,小程序付费墙「已阅读X%」展示用
|
||||
if isFree {
|
||||
returnContent = ch.Content
|
||||
effectivePreviewPercent = 100
|
||||
} else if checkUserChapterAccess(db, userID, ch.ID, isPremium) {
|
||||
returnContent = ch.Content
|
||||
effectivePreviewPercent = 100
|
||||
} else {
|
||||
percent := getUnpaidPreviewPercent(db)
|
||||
if ch.PreviewPercent != nil && *ch.PreviewPercent > 0 {
|
||||
percent = *ch.PreviewPercent
|
||||
}
|
||||
effectivePreviewPercent = percent
|
||||
returnContent = previewContent(ch.Content, percent)
|
||||
}
|
||||
|
||||
@@ -635,15 +642,16 @@ func findChapterAndRespond(c *gin.Context, whereFn func(*gorm.DB) *gorm.DB) {
|
||||
chForResponse.Content = returnContent
|
||||
|
||||
out := gin.H{
|
||||
"success": true,
|
||||
"data": chForResponse,
|
||||
"content": returnContent,
|
||||
"chapterTitle": ch.ChapterTitle,
|
||||
"partTitle": ch.PartTitle,
|
||||
"id": ch.ID,
|
||||
"mid": ch.MID,
|
||||
"sectionTitle": ch.SectionTitle,
|
||||
"isFree": isFree,
|
||||
"success": true,
|
||||
"data": chForResponse,
|
||||
"content": returnContent,
|
||||
"chapterTitle": ch.ChapterTitle,
|
||||
"partTitle": ch.PartTitle,
|
||||
"id": ch.ID,
|
||||
"mid": ch.MID,
|
||||
"sectionTitle": ch.SectionTitle,
|
||||
"isFree": isFree,
|
||||
"previewPercent": effectivePreviewPercent, // 小程序付费墙「已阅读X%」展示用
|
||||
}
|
||||
// 文章详情内直接输出上一篇/下一篇,省去单独请求
|
||||
if list := getOrderedChapterList(); len(list) > 0 {
|
||||
@@ -808,8 +816,8 @@ func bookHotChaptersSorted(db *gorm.DB, limit int) []model.Chapter {
|
||||
}
|
||||
// 按阅读量降序、同量按 updated_at 降序
|
||||
type withSort struct {
|
||||
ch model.Chapter
|
||||
cnt int64
|
||||
ch model.Chapter
|
||||
cnt int64
|
||||
}
|
||||
withCnt := make([]withSort, 0, len(all))
|
||||
for _, c := range all {
|
||||
@@ -883,9 +891,53 @@ func BookRecommended(c *gin.Context) {
|
||||
if i < len(tags) {
|
||||
tag = tags[i]
|
||||
}
|
||||
// 与管理端内容排行榜 sectionListItem 字段一致,便于两端数据对齐
|
||||
out = append(out, gin.H{
|
||||
"id": s.ID,
|
||||
"mid": s.MID,
|
||||
"title": s.Title,
|
||||
"sectionTitle": s.Title, // 兼容小程序旧字段
|
||||
"partTitle": s.PartTitle,
|
||||
"chapterTitle": s.ChapterTitle,
|
||||
"tag": tag,
|
||||
"isFree": s.IsFree,
|
||||
"price": s.Price,
|
||||
"isNew": s.IsNew,
|
||||
"clickCount": s.ClickCount,
|
||||
"payCount": s.PayCount,
|
||||
"hotScore": s.HotScore,
|
||||
"isPinned": s.IsPinned,
|
||||
})
|
||||
}
|
||||
cache.Set(context.Background(), cache.KeyBookRecommended, out, cache.BookRelatedTTL)
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": out})
|
||||
}
|
||||
|
||||
// BookRanking GET /api/miniprogram/book/ranking 内容排行榜(与 recommended 同算法,支持 limit,供精选推荐展开用)
|
||||
func BookRanking(c *gin.Context) {
|
||||
limit := 50
|
||||
if l := c.Query("limit"); l != "" {
|
||||
if n, err := strconv.Atoi(l); err == nil && n > 0 && n <= 50 {
|
||||
limit = n
|
||||
}
|
||||
}
|
||||
sections, err := computeArticleRankingSections(database.DB())
|
||||
if err != nil || len(sections) == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": []gin.H{}})
|
||||
return
|
||||
}
|
||||
if len(sections) < limit {
|
||||
limit = len(sections)
|
||||
}
|
||||
tags := []string{"热门", "推荐", "精选"}
|
||||
out := make([]gin.H, 0, limit)
|
||||
for i := 0; i < limit; i++ {
|
||||
s := sections[i]
|
||||
tag := tags[i%len(tags)]
|
||||
out = append(out, gin.H{
|
||||
"id": s.ID,
|
||||
"mid": s.MID,
|
||||
"title": s.Title,
|
||||
"sectionTitle": s.Title,
|
||||
"partTitle": s.PartTitle,
|
||||
"chapterTitle": s.ChapterTitle,
|
||||
@@ -893,9 +945,12 @@ func BookRecommended(c *gin.Context) {
|
||||
"isFree": s.IsFree,
|
||||
"price": s.Price,
|
||||
"isNew": s.IsNew,
|
||||
"clickCount": s.ClickCount,
|
||||
"payCount": s.PayCount,
|
||||
"hotScore": s.HotScore,
|
||||
"isPinned": s.IsPinned,
|
||||
})
|
||||
}
|
||||
cache.Set(context.Background(), cache.KeyBookRecommended, out, cache.BookRelatedTTL)
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": out})
|
||||
}
|
||||
|
||||
|
||||
@@ -700,6 +700,10 @@ func DBConfigPost(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
cache.InvalidateConfig()
|
||||
// 排名权重或置顶配置变更时,使精选推荐缓存失效,与管理端内容排行榜保持一致
|
||||
if body.Key == "article_ranking_weights" || body.Key == "pinned_section_ids" {
|
||||
cache.InvalidateBookCache()
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "message": "配置保存成功"})
|
||||
}
|
||||
|
||||
|
||||
@@ -377,6 +377,7 @@ func DBBookAction(c *gin.Context) {
|
||||
"chapterTitle": ch.ChapterTitle,
|
||||
"editionStandard": ch.EditionStandard,
|
||||
"editionPremium": ch.EditionPremium,
|
||||
"previewPercent": ch.PreviewPercent,
|
||||
},
|
||||
})
|
||||
return
|
||||
@@ -517,6 +518,7 @@ func DBBookAction(c *gin.Context) {
|
||||
TargetPartTitle string `json:"targetPartTitle"`
|
||||
TargetChapterTitle string `json:"targetChapterTitle"`
|
||||
ID string `json:"id"`
|
||||
NewID string `json:"newId"` // 修改章节 ID 时传入,后端会更新 id 列
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Price *float64 `json:"price"`
|
||||
@@ -524,6 +526,7 @@ func DBBookAction(c *gin.Context) {
|
||||
IsNew *bool `json:"isNew"` // stitch_soul:标记最新新增
|
||||
EditionStandard *bool `json:"editionStandard"` // 是否属于普通版
|
||||
EditionPremium *bool `json:"editionPremium"` // 是否属于增值版
|
||||
PreviewPercent *int `json:"previewPercent"` // 未解锁显示前 N%,空则用全局
|
||||
PartID string `json:"partId"`
|
||||
PartTitle string `json:"partTitle"`
|
||||
ChapterID string `json:"chapterId"`
|
||||
@@ -684,6 +687,14 @@ func DBBookAction(c *gin.Context) {
|
||||
if body.HotScore != nil {
|
||||
updates["hot_score"] = *body.HotScore
|
||||
}
|
||||
if body.PreviewPercent != nil {
|
||||
p := *body.PreviewPercent
|
||||
if p <= 0 || p > 100 {
|
||||
updates["preview_percent"] = nil // 无效值则清空,用全局
|
||||
} else {
|
||||
updates["preview_percent"] = p
|
||||
}
|
||||
}
|
||||
if body.PartID != "" {
|
||||
updates["part_id"] = body.PartID
|
||||
}
|
||||
@@ -696,6 +707,9 @@ func DBBookAction(c *gin.Context) {
|
||||
if body.ChapterTitle != "" {
|
||||
updates["chapter_title"] = body.ChapterTitle
|
||||
}
|
||||
if body.NewID != "" && body.NewID != body.ID {
|
||||
updates["id"] = body.NewID
|
||||
}
|
||||
var existing model.Chapter
|
||||
err = db.Where("id = ?", body.ID).First(&existing).Error
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
@@ -741,6 +755,9 @@ func DBBookAction(c *gin.Context) {
|
||||
if body.IsNew != nil {
|
||||
ch.IsNew = body.IsNew
|
||||
}
|
||||
if body.PreviewPercent != nil && *body.PreviewPercent > 0 && *body.PreviewPercent <= 100 {
|
||||
ch.PreviewPercent = body.PreviewPercent
|
||||
}
|
||||
if err := db.Create(&ch).Error; err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"success": false, "error": err.Error()})
|
||||
return
|
||||
@@ -761,7 +778,12 @@ func DBBookAction(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"success": false, "error": err.Error()})
|
||||
return
|
||||
}
|
||||
cache.InvalidateChapterContentByID(body.ID)
|
||||
// id 变更后需按 mid 失效缓存(按 id 查会失败)
|
||||
if body.NewID != "" && body.NewID != body.ID {
|
||||
cache.InvalidateChapterContent(existing.MID)
|
||||
} else {
|
||||
cache.InvalidateChapterContentByID(body.ID)
|
||||
}
|
||||
cache.InvalidateBookParts()
|
||||
InvalidateChaptersByPartCache()
|
||||
cache.InvalidateBookCache()
|
||||
|
||||
@@ -22,6 +22,7 @@ type Chapter struct {
|
||||
EditionStandard *bool `gorm:"column:edition_standard" json:"editionStandard,omitempty"` // 是否属于普通版
|
||||
EditionPremium *bool `gorm:"column:edition_premium" json:"editionPremium,omitempty"` // 是否属于增值版
|
||||
HotScore int `gorm:"column:hot_score;default:0" json:"hotScore"` // 热度分,用于排名算法
|
||||
PreviewPercent *int `gorm:"column:preview_percent" json:"previewPercent,omitempty"` // 未解锁时显示前 N%,空则用全局 unpaid_preview_percent
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ func Setup(cfg *config.Config) *gin.Engine {
|
||||
miniprogram.GET("/config", handler.GetPublicDBConfig)
|
||||
miniprogram.POST("/login", handler.MiniprogramLogin)
|
||||
miniprogram.POST("/phone-login", handler.WechatPhoneLogin)
|
||||
miniprogram.POST("/dev/login-as", handler.MiniprogramDevLoginAs) // 开发专用:按 userId 切换账号
|
||||
miniprogram.POST("/dev/login-as", handler.MiniprogramDevLoginAs) // 开发专用:按 userId 切换账号
|
||||
miniprogram.POST("/dev/login-by-phone", handler.MiniprogramDevLoginByPhone) // 开发专用:按手机号登录(密码可空)
|
||||
miniprogram.POST("/phone", handler.MiniprogramPhone)
|
||||
miniprogram.GET("/pay", handler.MiniprogramPay)
|
||||
@@ -316,6 +316,7 @@ func Setup(cfg *config.Config) *gin.Engine {
|
||||
miniprogram.GET("/book/chapter/by-id/:id", handler.BookChapterByID)
|
||||
miniprogram.GET("/book/hot", handler.BookHot)
|
||||
miniprogram.GET("/book/recommended", handler.BookRecommended)
|
||||
miniprogram.GET("/book/ranking", handler.BookRanking)
|
||||
miniprogram.GET("/book/latest-chapters", handler.BookLatestChapters)
|
||||
miniprogram.GET("/book/search", handler.BookSearch)
|
||||
miniprogram.GET("/book/stats", handler.BookStats)
|
||||
|
||||
3
soul-api/scripts/add_preview_percent.sql
Normal file
3
soul-api/scripts/add_preview_percent.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
-- 文章级未解锁预览百分比:chapters.preview_percent
|
||||
-- 空或0则使用全局 unpaid_preview_percent
|
||||
ALTER TABLE chapters ADD COLUMN preview_percent INT DEFAULT NULL COMMENT '未解锁显示前N%,空则用全局';
|
||||
31
临时需求池/2026-03-20-文章级未解锁预览百分比.md
Normal file
31
临时需求池/2026-03-20-文章级未解锁预览百分比.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# 需求:文章级未解锁预览百分比
|
||||
|
||||
**日期**:2026-03-20
|
||||
|
||||
## 需求描述
|
||||
|
||||
小程序每篇文章未解锁显示的百分比可在管理端文章编辑、添加时单独设置。每篇文章独立配置,默认按全局设置展示。
|
||||
|
||||
## 三端实现
|
||||
|
||||
### 后端 (soul-api)
|
||||
|
||||
- **chapters 表**:新增 `preview_percent` 字段(INT NULL),空则用全局 `unpaid_preview_percent`
|
||||
- **book.go**:`findChapterAndRespond` 中,付费未解锁时优先使用 `ch.PreviewPercent`,空则 `getUnpaidPreviewPercent(db)`
|
||||
- **db_book.go**:PUT 创建/更新支持 `previewPercent`;GET read 返回 `previewPercent`
|
||||
|
||||
### 管理端 (soul-admin)
|
||||
|
||||
- **ContentPage**:新建章节、编辑章节表单增加「未解锁预览比例 (%)」输入框
|
||||
- 占位符「空则用全局」;1–100 有效,空或 0 表示使用全局
|
||||
|
||||
### 小程序
|
||||
|
||||
- 无变更,后端按文章级或全局百分比返回预览内容
|
||||
|
||||
## 验收
|
||||
|
||||
- [ ] 管理端新建文章时可设置预览百分比
|
||||
- [ ] 管理端编辑文章时可修改/清空预览百分比
|
||||
- [ ] 未设置时小程序显示按全局配置
|
||||
- [ ] 已设置时小程序显示按文章级配置
|
||||
Reference in New Issue
Block a user