fix: 修复小程序多个问题

1. 修复章节内容加载卡住问题 - 更新API返回格式和章节映射
2. 修复找伙伴页面 - 去掉今日剩余次数显示
3. 添加匹配动画 - 1-3秒转动动画后再弹出加入弹窗
4. 加入资源对接需要先绑定手机号或微信号
5. 重构加入弹窗UI - 更简洁美观
6. 修复手机号输入框问题
7. 关于作者页面 - 内容与真实章节数据保持一致(62个案例)
This commit is contained in:
卡若
2026-01-25 09:27:32 +08:00
parent e16dce118e
commit 4f11fe25f9
7 changed files with 547 additions and 180 deletions

View File

@@ -1,5 +1,5 @@
// app/api/book/chapter/[id]/route.ts
// 获取章节详情
// 获取章节详情 - 支持小程序和Web端
import { NextRequest, NextResponse } from 'next/server'
import fs from 'fs'
@@ -8,19 +8,109 @@ import matter from 'gray-matter'
const BOOK_DIR = path.join(process.cwd(), 'book')
// 章节ID到文件路径的映射
const CHAPTER_MAP: Record<string, { dir: string; file: string; partTitle: string; chapterTitle: string }> = {
'preface': { dir: '', file: '序言为什么我每天早上6点在Soul开播?.md', partTitle: '序言', chapterTitle: '为什么我每天早上6点在Soul开播?' },
'epilogue': { dir: '', file: '尾声|这本书的真实目的.md', partTitle: '尾声', chapterTitle: '这本书的真实目的' },
'1.1': { dir: '第一篇|真实的人/第1章人与人之间的底层逻辑', file: '1.1 荷包:电动车出租的被动收入模式.md', partTitle: '第一篇|真实的人', chapterTitle: '1.1 荷包:电动车出租的被动收入模式' },
'1.2': { dir: '第一篇|真实的人/第1章人与人之间的底层逻辑', file: '1.2 老墨:资源整合高手的社交方法.md', partTitle: '第一篇|真实的人', chapterTitle: '1.2 老墨:资源整合高手的社交方法' },
'1.3': { dir: '第一篇|真实的人/第1章人与人之间的底层逻辑', file: '1.3 笑声背后的MBTI为什么ENTJ适合做资源INTP适合做系统.md', partTitle: '第一篇|真实的人', chapterTitle: '1.3 笑声背后的MBTI' },
'1.4': { dir: '第一篇|真实的人/第1章人与人之间的底层逻辑', file: '1.4 人性的三角结构:利益、情感、价值观.md', partTitle: '第一篇|真实的人', chapterTitle: '1.4 人性的三角结构' },
'1.5': { dir: '第一篇|真实的人/第1章人与人之间的底层逻辑', file: '1.5 沟通差的问题:为什么你说的别人听不懂.md', partTitle: '第一篇|真实的人', chapterTitle: '1.5 沟通差的问题' },
'2.1': { dir: '第一篇|真实的人/第2章人性困境案例', file: '2.1 相亲故事:你以为找的是人,实际是在找模式.md', partTitle: '第一篇|真实的人', chapterTitle: '2.1 相亲故事' },
'2.2': { dir: '第一篇|真实的人/第2章人性困境案例', file: '2.2 找工作迷茫者:为什么简历解决不了人生.md', partTitle: '第一篇|真实的人', chapterTitle: '2.2 找工作迷茫者' },
'2.3': { dir: '第一篇|真实的人/第2章人性困境案例', file: '2.3 撸运费险:小钱困住大脑的真实心理.md', partTitle: '第一篇|真实的人', chapterTitle: '2.3 撸运费险' },
'2.4': { dir: '第一篇|真实的人/第2章人性困境案例', file: '2.4 游戏上瘾的年轻人:不是游戏吸引他,是生活没吸引力.md', partTitle: '第一篇|真实的人', chapterTitle: '2.4 游戏上瘾的年轻人' },
'2.5': { dir: '第一篇|真实的人/第2章人性困境案例', file: '2.5 健康焦虑(我的糖尿病经历):疾病是人生的第一次清醒.md', partTitle: '第一篇|真实的人', chapterTitle: '2.5 健康焦虑' },
'3.1': { dir: '第二篇|真实的行业/第3章电商篇', file: '3.1 3000万流水如何跑出来(退税模式解析).md', partTitle: '第二篇|真实的行业', chapterTitle: '3.1 3000万流水' },
'3.2': { dir: '第二篇|真实的行业/第3章电商篇', file: '3.2 供应链之王 vs 打工人:利润不在前端.md', partTitle: '第二篇|真实的行业', chapterTitle: '3.2 供应链之王' },
'3.3': { dir: '第二篇|真实的行业/第3章电商篇', file: '3.3 社区团购的底层逻辑.md', partTitle: '第二篇|真实的行业', chapterTitle: '3.3 社区团购' },
'3.4': { dir: '第二篇|真实的行业/第3章电商篇', file: '3.4 跨境电商与退税套利.md', partTitle: '第二篇|真实的行业', chapterTitle: '3.4 跨境电商' },
'4.1': { dir: '第二篇|真实的行业/第4章内容商业篇', file: '4.1 旅游号:30天10万粉的真实逻辑.md', partTitle: '第二篇|真实的行业', chapterTitle: '4.1 旅游号' },
'4.2': { dir: '第二篇|真实的行业/第4章内容商业篇', file: '4.2 做号工厂:如何让一个号变成一个机器.md', partTitle: '第二篇|真实的行业', chapterTitle: '4.2 做号工厂' },
'4.3': { dir: '第二篇|真实的行业/第4章内容商业篇', file: '4.3 情绪内容为什么比专业内容更赚钱.md', partTitle: '第二篇|真实的行业', chapterTitle: '4.3 情绪内容' },
'4.4': { dir: '第二篇|真实的行业/第4章内容商业篇', file: '4.4 猫与宠物号:为什么宠物赛道永不过时.md', partTitle: '第二篇|真实的行业', chapterTitle: '4.4 猫与宠物号' },
'4.5': { dir: '第二篇|真实的行业/第4章内容商业篇', file: '4.5 直播间里的三种人:演员、技术工、系统流.md', partTitle: '第二篇|真实的行业', chapterTitle: '4.5 直播间里的三种人' },
'5.1': { dir: '第二篇|真实的行业/第5章传统行业篇', file: '5.1 拍卖行抱朴一天240万的摇号生意.md', partTitle: '第二篇|真实的行业', chapterTitle: '5.1 拍卖行抱朴' },
'5.2': { dir: '第二篇|真实的行业/第5章传统行业篇', file: '5.2 土地拍卖:招拍挂背后的游戏规则.md', partTitle: '第二篇|真实的行业', chapterTitle: '5.2 土地拍卖' },
'5.3': { dir: '第二篇|真实的行业/第5章传统行业篇', file: '5.3 地摊经济数字化一个月900块的餐车生意.md', partTitle: '第二篇|真实的行业', chapterTitle: '5.3 地摊经济' },
'5.4': { dir: '第二篇|真实的行业/第5章传统行业篇', file: '5.4 不良资产拍卖:我错过的一个亿佣金.md', partTitle: '第二篇|真实的行业', chapterTitle: '5.4 不良资产拍卖' },
'5.5': { dir: '第二篇|真实的行业/第5章传统行业篇', file: '5.5 桶装水李总:跟物业合作的轻资产模式.md', partTitle: '第二篇|真实的行业', chapterTitle: '5.5 桶装水李总' },
'6.1': { dir: '第三篇|真实的错误/第6章我人生错过的4件大钱', file: '6.1 电商财税窗口2016年的千万级机会.md', partTitle: '第三篇|真实的错误', chapterTitle: '6.1 电商财税窗口' },
'6.2': { dir: '第三篇|真实的错误/第6章我人生错过的4件大钱', file: '6.2 供应链金融:我不懂的杠杆游戏.md', partTitle: '第三篇|真实的错误', chapterTitle: '6.2 供应链金融' },
'6.3': { dir: '第三篇|真实的错误/第6章我人生错过的4件大钱', file: '6.3 内容红利2019年我为什么没做抖音.md', partTitle: '第三篇|真实的错误', chapterTitle: '6.3 内容红利' },
'6.4': { dir: '第三篇|真实的错误/第6章我人生错过的4件大钱', file: '6.4 数据资产化:我还在观望的未来机会.md', partTitle: '第三篇|真实的错误', chapterTitle: '6.4 数据资产化' },
'7.1': { dir: '第三篇|真实的错误/第7章别人犯的错误', file: '7.1 投资房年轻人的迷茫:资金 vs 能力.md', partTitle: '第三篇|真实的错误', chapterTitle: '7.1 投资房年轻人' },
'7.2': { dir: '第三篇|真实的错误/第7章别人犯的错误', file: '7.2 信息差骗局:永远有人靠卖学习赚钱.md', partTitle: '第三篇|真实的错误', chapterTitle: '7.2 信息差骗局' },
'7.3': { dir: '第三篇|真实的错误/第7章别人犯的错误', file: '7.3 在Soul找恋爱但想赚钱的人.md', partTitle: '第三篇|真实的错误', chapterTitle: '7.3 在Soul找恋爱' },
'7.4': { dir: '第三篇|真实的错误/第7章别人犯的错误', file: '7.4 创业者的三种死法:冲动、轻信、没结构.md', partTitle: '第三篇|真实的错误', chapterTitle: '7.4 创业者的三种死法' },
'7.5': { dir: '第三篇|真实的错误/第7章别人犯的错误', file: '7.5 人情生意的终点:关系越多亏得越多.md', partTitle: '第三篇|真实的错误', chapterTitle: '7.5 人情生意' },
'8.1': { dir: '第四篇|真实的赚钱/第8章底层结构', file: '8.1 流量杠杆:抖音、Soul、飞书.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '8.1 流量杠杆' },
'8.2': { dir: '第四篇|真实的赚钱/第8章底层结构', file: '8.2 价格杠杆:供应链与信息差.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '8.2 价格杠杆' },
'8.3': { dir: '第四篇|真实的赚钱/第8章底层结构', file: '8.3 时间杠杆:自动化 + AI.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '8.3 时间杠杆' },
'8.4': { dir: '第四篇|真实的赚钱/第8章底层结构', file: '8.4 情绪杠杆:咨询、婚恋、生意场.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '8.4 情绪杠杆' },
'8.5': { dir: '第四篇|真实的赚钱/第8章底层结构', file: '8.5 社交杠杆:认识谁比你会什么更重要.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '8.5 社交杠杆' },
'8.6': { dir: '第四篇|真实的赚钱/第8章底层结构', file: '8.6 云阿米巴:分不属于自己的钱.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '8.6 云阿米巴' },
'9.1': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.1 游戏账号私域:账号即资产.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.1 游戏账号私域' },
'9.2': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.2 健康包模式:高复购、高毛利.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.2 健康包模式' },
'9.3': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.3 药物私域:长期关系赛道.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.3 药物私域' },
'9.4': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.4 残疾机构合作:退税 × AI × 人力成本.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.4 残疾机构合作' },
'9.5': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.5 私域银行:粉丝即小股东.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.5 私域银行' },
'9.6': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.6 Soul派对房:陌生人成交的最快场景.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.6 Soul派对房' },
'9.7': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.7 飞书中台:从聊天到成交的流程化体系.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.7 飞书中台' },
'9.8': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.8 餐饮女孩6万营收、1万利润的死撑生意.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.8 餐饮女孩' },
'9.9': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.9 电竞生态:从陪玩到签约到酒店的完整链条.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.9 电竞生态' },
'9.10': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.10 淘客大佬损耗30%的白色通道.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.10 淘客大佬' },
'9.11': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.11 蔬菜供应链:农户才是最赚钱的人.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.11 蔬菜供应链' },
'9.12': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.12 美业整合:一个人的公司如何月入十万.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.12 美业整合' },
'9.13': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.13 AI工具推广一个隐藏的高利润赛道.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.13 AI工具推广' },
'9.14': { dir: '第四篇|真实的赚钱/第9章我在Soul上亲访的赚钱案例', file: '9.14 大健康私域一个月150万的70后.md', partTitle: '第四篇|真实的赚钱', chapterTitle: '9.14 大健康私域' },
'10.1': { dir: '第五篇|真实的社会/第10章未来职业的变化趋势', file: '10.1 AI时代哪些工作会消失哪些会崛起.md', partTitle: '第五篇|真实的社会', chapterTitle: '10.1 AI时代' },
'10.2': { dir: '第五篇|真实的社会/第10章未来职业的变化趋势', file: '10.2 一人公司:为什么越来越多人选择单干.md', partTitle: '第五篇|真实的社会', chapterTitle: '10.2 一人公司' },
'10.3': { dir: '第五篇|真实的社会/第10章未来职业的变化趋势', file: '10.3 为什么链接能力会成为第一价值.md', partTitle: '第五篇|真实的社会', chapterTitle: '10.3 链接能力' },
'10.4': { dir: '第五篇|真实的社会/第10章未来职业的变化趋势', file: '10.4 新型公司:Soul-飞书-线下的三位一体.md', partTitle: '第五篇|真实的社会', chapterTitle: '10.4 新型公司' },
'11.1': { dir: '第五篇|真实的社会/第11章中国社会商业生态的未来', file: '11.1 私域经济:为什么流量越来越贵.md', partTitle: '第五篇|真实的社会', chapterTitle: '11.1 私域经济' },
'11.2': { dir: '第五篇|真实的社会/第11章中国社会商业生态的未来', file: '11.2 银发经济与孤独经济:两个被忽视的万亿市场.md', partTitle: '第五篇|真实的社会', chapterTitle: '11.2 银发经济' },
'11.3': { dir: '第五篇|真实的社会/第11章中国社会商业生态的未来', file: '11.3 流量红利的终局.md', partTitle: '第五篇|真实的社会', chapterTitle: '11.3 流量红利' },
'11.4': { dir: '第五篇|真实的社会/第11章中国社会商业生态的未来', file: '11.4 大模型 + 供应链的组合拳.md', partTitle: '第五篇|真实的社会', chapterTitle: '11.4 大模型+供应链' },
'11.5': { dir: '第五篇|真实的社会/第11章中国社会商业生态的未来', file: '11.5 社会分层的最终逻辑.md', partTitle: '第五篇|真实的社会', chapterTitle: '11.5 社会分层' },
'appendix-1': { dir: '附录', file: '附录1Soul派对房精选对话.md', partTitle: '附录', chapterTitle: 'Soul派对房精选对话' },
'appendix-2': { dir: '附录', file: '附录2创业者自检清单.md', partTitle: '附录', chapterTitle: '创业者自检清单' },
'appendix-3': { dir: '附录', file: '附录3本书提到的工具和资源.md', partTitle: '附录', chapterTitle: '本书提到的工具和资源' },
}
export async function GET(
req: NextRequest,
{ params }: { params: { id: string } }
) {
try {
const chapterId = params.id
console.log('[Chapter API] 请求章节:', chapterId)
// 根据ID查找对应的Markdown文件
const chapterFile = findChapterFile(chapterId)
// 先从映射表查找
const mapping = CHAPTER_MAP[chapterId]
let chapterFile: string | null = null
let partTitle = ''
let chapterTitle = ''
if (mapping) {
const filePath = path.join(BOOK_DIR, mapping.dir, mapping.file)
if (fs.existsSync(filePath)) {
chapterFile = filePath
partTitle = mapping.partTitle
chapterTitle = mapping.chapterTitle
}
}
// 如果映射找不到,尝试动态查找
if (!chapterFile) {
chapterFile = findChapterFile(chapterId)
}
if (!chapterFile) {
console.log('[Chapter API] 章节不存在:', chapterId)
return NextResponse.json(
{ error: '章节不存在' },
{ error: '章节不存在', success: false },
{ status: 404 }
)
}
@@ -28,62 +118,74 @@ export async function GET(
const fileContent = fs.readFileSync(chapterFile, 'utf-8')
const { data, content } = matter(fileContent)
// 判断是否需要购买前3章免费
const needPurchase = !isFreeChapter(chapterId)
// 判断是否免费章节
const isFree = isFreeChapter(chapterId)
// 如果需要购买,检查用户是否已购买
// TODO: 从token中获取用户信息检查购买状态
const chapter = {
console.log('[Chapter API] 返回章节内容:', chapterId, '长度:', content.length)
// 返回小程序兼容的格式
return NextResponse.json({
success: true,
id: chapterId,
title: data.title || path.basename(chapterFile, '.md'),
title: data.title || chapterTitle || path.basename(chapterFile, '.md'),
content: content,
partTitle: partTitle || data.category || '',
chapterTitle: chapterTitle || data.title || '',
words: content.length,
updateTime: data.date || fs.statSync(chapterFile).mtime.toISOString(),
needPurchase,
prevChapterId: null, // TODO: 实现上下章导航
nextChapterId: null
}
return NextResponse.json(chapter)
isFree,
needPurchase: !isFree
})
} catch (error) {
console.error('获取章节失败:', error)
console.error('[Chapter API] 获取章节失败:', error)
return NextResponse.json(
{ error: '获取章节失败' },
{ error: '获取章节失败', success: false },
{ status: 500 }
)
}
}
// 查找章节文件
// 递归查找章节文件
function findChapterFile(chapterId: string): string | null {
const categories = fs.readdirSync(BOOK_DIR).filter(item => {
const itemPath = path.join(BOOK_DIR, item)
return fs.statSync(itemPath).isDirectory()
})
for (const category of categories) {
const categoryPath = path.join(BOOK_DIR, category)
const files = fs.readdirSync(categoryPath).filter(file => file.endsWith('.md'))
for (const file of files) {
const slug = `${category}/${file.replace('.md', '')}`
if (slug === chapterId || file.replace('.md', '') === chapterId) {
return path.join(categoryPath, file)
function searchDir(dir: string): string | null {
try {
const items = fs.readdirSync(dir)
for (const item of items) {
const itemPath = path.join(dir, item)
const stat = fs.statSync(itemPath)
if (stat.isDirectory()) {
const result = searchDir(itemPath)
if (result) return result
} else if (item.endsWith('.md')) {
// 检查文件名是否匹配章节ID
if (item.startsWith(chapterId + ' ') ||
item.includes(chapterId) ||
item.replace('.md', '') === chapterId) {
return itemPath
}
}
}
} catch (e) {
// 忽略权限错误
}
return null
}
return null
return searchDir(BOOK_DIR)
}
// 判断是否免费章节前3章免费
// 判断是否免费章节
function isFreeChapter(chapterId: string): boolean {
const freeChapters = [
'序言',
'第一章',
'第二章'
'preface',
'epilogue',
'1.1',
'appendix-1',
'appendix-2',
'appendix-3'
]
return freeChapters.some(free => chapterId.includes(free))
return freeChapters.includes(chapterId)
}