2026-01-21 15:49:12 +08:00
|
|
|
|
/**
|
2026-01-25 19:37:59 +08:00
|
|
|
|
* Soul创业派对 - 首页
|
2026-01-21 15:49:12 +08:00
|
|
|
|
* 开发: 卡若
|
2026-02-24 14:35:58 +08:00
|
|
|
|
* 技术支持: 存客宝
|
2026-01-21 15:49:12 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
2026-02-24 14:35:58 +08:00
|
|
|
|
console.log('[Index] ===== 首页文件开始加载 =====')
|
|
|
|
|
|
|
2026-01-14 12:50:00 +08:00
|
|
|
|
const app = getApp()
|
|
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
|
data: {
|
2026-02-24 14:35:58 +08:00
|
|
|
|
// 系统信息
|
2026-01-21 15:49:12 +08:00
|
|
|
|
statusBarHeight: 44,
|
|
|
|
|
|
navBarHeight: 88,
|
2026-02-24 14:35:58 +08:00
|
|
|
|
|
|
|
|
|
|
// 用户信息
|
2026-01-21 15:49:12 +08:00
|
|
|
|
isLoggedIn: false,
|
|
|
|
|
|
hasFullBook: false,
|
2026-02-24 14:35:58 +08:00
|
|
|
|
readCount: 0,
|
|
|
|
|
|
|
|
|
|
|
|
// 书籍数据
|
2026-01-21 15:49:12 +08:00
|
|
|
|
totalSections: 62,
|
|
|
|
|
|
bookData: [],
|
2026-02-24 14:35:58 +08:00
|
|
|
|
|
|
|
|
|
|
// 推荐章节
|
|
|
|
|
|
featuredSections: [
|
|
|
|
|
|
{ id: '1.1', title: '荷包:电动车出租的被动收入模式', tag: '免费', tagClass: 'tag-free', part: '真实的人' },
|
|
|
|
|
|
{ id: '3.1', title: '3000万流水如何跑出来', tag: '热门', tagClass: 'tag-pink', part: '真实的行业' },
|
|
|
|
|
|
{ id: '8.1', title: '流量杠杆:抖音、Soul、飞书', tag: '推荐', tagClass: 'tag-purple', part: '真实的赚钱' }
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
|
|
// 最新章节(动态计算)
|
2026-01-25 19:37:59 +08:00
|
|
|
|
latestSection: null,
|
|
|
|
|
|
latestLabel: '最新更新',
|
2026-02-24 14:35:58 +08:00
|
|
|
|
|
|
|
|
|
|
// 内容概览
|
|
|
|
|
|
partsList: [
|
|
|
|
|
|
{ id: 'part-1', number: '一', title: '真实的人', subtitle: '人与人之间的底层逻辑' },
|
|
|
|
|
|
{ id: 'part-2', number: '二', title: '真实的行业', subtitle: '电商、内容、传统行业解析' },
|
|
|
|
|
|
{ id: 'part-3', number: '三', title: '真实的错误', subtitle: '我和别人犯过的错' },
|
|
|
|
|
|
{ id: 'part-4', number: '四', title: '真实的赚钱', subtitle: '底层结构与真实案例' },
|
|
|
|
|
|
{ id: 'part-5', number: '五', title: '真实的社会', subtitle: '未来职业与商业生态' }
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
|
|
// 超级个体(VIP会员)
|
|
|
|
|
|
superMembers: [],
|
2026-02-27 14:22:58 +08:00
|
|
|
|
superMembersLoading: true,
|
2026-02-23 14:07:41 +08:00
|
|
|
|
|
2026-02-24 14:35:58 +08:00
|
|
|
|
// 最新新增章节
|
|
|
|
|
|
latestChapters: [],
|
|
|
|
|
|
|
2026-02-25 16:26:13 +08:00
|
|
|
|
// 篇章数(从 bookData 计算)
|
|
|
|
|
|
partCount: 0,
|
|
|
|
|
|
|
2026-02-24 14:35:58 +08:00
|
|
|
|
// 加载状态
|
2026-03-06 12:12:13 +08:00
|
|
|
|
loading: true,
|
|
|
|
|
|
|
|
|
|
|
|
// 链接卡若 - 留资弹窗
|
|
|
|
|
|
showLeadModal: false,
|
|
|
|
|
|
leadPhone: ''
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-25 19:37:59 +08:00
|
|
|
|
onLoad(options) {
|
2026-02-24 14:35:58 +08:00
|
|
|
|
console.log('[Index] ===== onLoad 触发 =====')
|
|
|
|
|
|
|
|
|
|
|
|
// 获取系统信息
|
2026-01-21 15:49:12 +08:00
|
|
|
|
this.setData({
|
|
|
|
|
|
statusBarHeight: app.globalData.statusBarHeight,
|
|
|
|
|
|
navBarHeight: app.globalData.navBarHeight
|
2026-01-14 12:50:00 +08:00
|
|
|
|
})
|
2026-02-24 14:35:58 +08:00
|
|
|
|
|
|
|
|
|
|
// 处理分享参数(推荐码绑定)
|
2026-01-25 19:37:59 +08:00
|
|
|
|
if (options && options.ref) {
|
2026-02-24 14:35:58 +08:00
|
|
|
|
console.log('[Index] 检测到推荐码:', options.ref)
|
2026-01-25 19:37:59 +08:00
|
|
|
|
app.handleReferralCode({ query: options })
|
|
|
|
|
|
}
|
2026-02-24 14:35:58 +08:00
|
|
|
|
|
2026-02-27 14:22:58 +08:00
|
|
|
|
wx.showShareMenu({ withShareTimeline: true })
|
2026-01-21 15:49:12 +08:00
|
|
|
|
this.initData()
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
onShow() {
|
2026-02-24 14:35:58 +08:00
|
|
|
|
console.log('[Index] onShow 触发')
|
|
|
|
|
|
|
|
|
|
|
|
// 设置TabBar选中状态
|
2026-01-21 15:49:12 +08:00
|
|
|
|
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
2026-02-24 14:35:58 +08:00
|
|
|
|
const tabBar = this.getTabBar()
|
|
|
|
|
|
console.log('[Index] TabBar 组件:', tabBar ? '已找到' : '未找到')
|
|
|
|
|
|
|
|
|
|
|
|
// 主动触发配置加载
|
|
|
|
|
|
if (tabBar && tabBar.loadFeatureConfig) {
|
|
|
|
|
|
console.log('[Index] 主动调用 TabBar.loadFeatureConfig()')
|
|
|
|
|
|
tabBar.loadFeatureConfig()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新选中状态
|
|
|
|
|
|
if (tabBar && tabBar.updateSelected) {
|
|
|
|
|
|
tabBar.updateSelected()
|
|
|
|
|
|
} else if (tabBar) {
|
|
|
|
|
|
tabBar.setData({ selected: 0 })
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log('[Index] TabBar 组件未找到或 getTabBar 方法不存在')
|
2026-01-14 12:50:00 +08:00
|
|
|
|
}
|
2026-02-24 14:35:58 +08:00
|
|
|
|
|
|
|
|
|
|
// 更新用户状态
|
2026-01-21 15:49:12 +08:00
|
|
|
|
this.updateUserStatus()
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-03-04 19:06:06 +08:00
|
|
|
|
// 初始化数据:首次进页面并行异步加载,加快首屏展示
|
|
|
|
|
|
initData() {
|
|
|
|
|
|
this.setData({ loading: false })
|
|
|
|
|
|
this.loadBookData()
|
|
|
|
|
|
this.loadFeaturedFromServer()
|
|
|
|
|
|
this.loadSuperMembers()
|
|
|
|
|
|
this.loadLatestChapters()
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-24 14:35:58 +08:00
|
|
|
|
async loadSuperMembers() {
|
2026-02-27 14:22:58 +08:00
|
|
|
|
this.setData({ superMembersLoading: true })
|
2026-02-23 14:07:41 +08:00
|
|
|
|
try {
|
2026-02-26 14:26:31 +08:00
|
|
|
|
// 优先加载 VIP 会员(购买 1980 fullbook/vip 订单的用户)
|
2026-02-24 14:35:58 +08:00
|
|
|
|
let members = []
|
|
|
|
|
|
try {
|
2026-02-25 11:50:07 +08:00
|
|
|
|
const res = await app.request({ url: '/api/miniprogram/vip/members', silent: true })
|
2026-02-24 14:35:58 +08:00
|
|
|
|
if (res && res.success && res.data) {
|
2026-02-26 14:26:31 +08:00
|
|
|
|
// 不再过滤无头像用户,无头像时用首字母展示
|
|
|
|
|
|
members = (Array.isArray(res.data) ? res.data : []).slice(0, 4).map(u => ({
|
|
|
|
|
|
id: u.id,
|
2026-03-06 12:12:13 +08:00
|
|
|
|
name: u.nickname || u.vipName || u.vip_name || '会员', // 超级个体:用户资料优先,随「我的」修改实时生效
|
|
|
|
|
|
avatar: u.avatar || '',
|
2026-02-26 14:26:31 +08:00
|
|
|
|
isVip: true
|
2026-02-24 14:35:58 +08:00
|
|
|
|
}))
|
2026-02-26 14:26:31 +08:00
|
|
|
|
if (members.length > 0) {
|
|
|
|
|
|
console.log('[Index] 超级个体加载成功:', members.length, '人')
|
|
|
|
|
|
}
|
2026-02-24 14:35:58 +08:00
|
|
|
|
}
|
2026-02-26 14:26:31 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log('[Index] vip/members 请求失败:', e)
|
|
|
|
|
|
}
|
|
|
|
|
|
// 不足 4 个则用有头像的普通用户补充
|
2026-02-24 14:35:58 +08:00
|
|
|
|
if (members.length < 4) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const dbRes = await app.request({ url: '/api/miniprogram/users?limit=20', silent: true })
|
|
|
|
|
|
if (dbRes && dbRes.success && dbRes.data) {
|
|
|
|
|
|
const existIds = new Set(members.map(m => m.id))
|
2026-02-26 14:26:31 +08:00
|
|
|
|
const extra = (Array.isArray(dbRes.data) ? dbRes.data : [])
|
2026-02-24 14:35:58 +08:00
|
|
|
|
.filter(u => u.avatar && u.nickname && !existIds.has(u.id))
|
|
|
|
|
|
.slice(0, 4 - members.length)
|
|
|
|
|
|
.map(u => ({ id: u.id, name: u.nickname, avatar: u.avatar, isVip: u.is_vip === 1 }))
|
|
|
|
|
|
members = members.concat(extra)
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {}
|
2026-02-23 14:07:41 +08:00
|
|
|
|
}
|
2026-02-27 14:22:58 +08:00
|
|
|
|
this.setData({ superMembers: members, superMembersLoading: false })
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log('[Index] 加载超级个体失败:', e)
|
|
|
|
|
|
this.setData({ superMembersLoading: false })
|
|
|
|
|
|
}
|
2026-02-23 14:07:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-28 15:16:23 +08:00
|
|
|
|
// 从服务端获取精选推荐、最新更新(stitch_soul:book/recommended、book/latest-chapters)
|
2026-02-24 14:35:58 +08:00
|
|
|
|
async loadFeaturedFromServer() {
|
2026-02-23 14:07:41 +08:00
|
|
|
|
try {
|
2026-02-28 15:16:23 +08:00
|
|
|
|
// 1. 精选推荐:优先用 book/recommended(按阅读量+算法,带 热门/推荐/精选 标签)
|
|
|
|
|
|
let featured = []
|
|
|
|
|
|
try {
|
|
|
|
|
|
const recRes = await app.request({ url: '/api/miniprogram/book/recommended', silent: true })
|
|
|
|
|
|
if (recRes && recRes.success && Array.isArray(recRes.data) && recRes.data.length > 0) {
|
|
|
|
|
|
featured = recRes.data.map((s, i) => ({
|
2026-02-24 14:35:58 +08:00
|
|
|
|
id: s.id || s.section_id,
|
2026-02-28 10:19:46 +08:00
|
|
|
|
mid: s.mid ?? s.MID ?? 0,
|
2026-02-28 15:16:23 +08:00
|
|
|
|
title: s.sectionTitle || s.section_title || s.title || s.chapterTitle || '',
|
|
|
|
|
|
part: (s.partTitle || s.part_title || '').replace(/[_||]/g, ' ').trim(),
|
|
|
|
|
|
tag: s.tag || ['热门', '推荐', '精选'][i] || '精选',
|
|
|
|
|
|
tagClass: ['tag-hot', 'tag-rec', 'tag-rec'][i] || 'tag-rec'
|
2026-02-24 14:35:58 +08:00
|
|
|
|
}))
|
2026-02-28 15:16:23 +08:00
|
|
|
|
this.setData({ featuredSections: featured })
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) { console.log('[Index] book/recommended 失败:', e) }
|
|
|
|
|
|
|
|
|
|
|
|
// 兜底:无 recommended 时从 all-chapters 按更新时间取前3
|
|
|
|
|
|
if (featured.length === 0) {
|
|
|
|
|
|
const res = await app.request({ url: '/api/miniprogram/book/all-chapters', silent: true })
|
|
|
|
|
|
const chapters = (res && res.data) || (res && res.chapters) || []
|
|
|
|
|
|
const valid = chapters.filter(c => {
|
|
|
|
|
|
const pt = (c.part_title || c.partTitle || '').toLowerCase()
|
|
|
|
|
|
return !pt.includes('序言') && !pt.includes('尾声') && !pt.includes('附录')
|
2026-02-24 14:35:58 +08:00
|
|
|
|
})
|
2026-02-28 15:16:23 +08:00
|
|
|
|
if (valid.length > 0) {
|
|
|
|
|
|
const tagMap = ['热门', '推荐', '精选']
|
|
|
|
|
|
featured = valid
|
|
|
|
|
|
.sort((a, b) => new Date(b.updated_at || b.updatedAt || 0) - new Date(a.updated_at || a.updatedAt || 0))
|
|
|
|
|
|
.slice(0, 3)
|
|
|
|
|
|
.map((s, i) => ({
|
|
|
|
|
|
id: s.id,
|
|
|
|
|
|
mid: s.mid ?? s.MID ?? 0,
|
|
|
|
|
|
title: s.section_title || s.sectionTitle || s.title || s.chapterTitle || '',
|
|
|
|
|
|
part: (s.part_title || s.partTitle || '').replace(/[_||]/g, ' ').trim(),
|
|
|
|
|
|
tag: tagMap[i] || '精选',
|
|
|
|
|
|
tagClass: ['tag-hot', 'tag-rec', 'tag-rec'][i] || 'tag-rec'
|
|
|
|
|
|
}))
|
|
|
|
|
|
this.setData({ featuredSections: featured })
|
|
|
|
|
|
}
|
2026-02-23 14:07:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-12 11:36:50 +08:00
|
|
|
|
// 2. 最新更新:用 book/latest-chapters 取第1条(排除「序言」「尾声」「附录」)
|
2026-02-28 15:16:23 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const latestRes = await app.request({ url: '/api/miniprogram/book/latest-chapters', silent: true })
|
2026-03-12 11:36:50 +08:00
|
|
|
|
const rawList = (latestRes && latestRes.data) ? latestRes.data : []
|
|
|
|
|
|
const latestList = rawList.filter(l => {
|
|
|
|
|
|
const pt = (l.part_title || l.partTitle || '').toLowerCase()
|
|
|
|
|
|
return !pt.includes('序言') && !pt.includes('尾声') && !pt.includes('附录')
|
|
|
|
|
|
})
|
2026-02-28 15:16:23 +08:00
|
|
|
|
if (latestList.length > 0) {
|
|
|
|
|
|
const l = latestList[0]
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
latestSection: {
|
|
|
|
|
|
id: l.id,
|
|
|
|
|
|
mid: l.mid ?? l.MID ?? 0,
|
|
|
|
|
|
title: l.section_title || l.sectionTitle || l.title || l.chapterTitle || '',
|
|
|
|
|
|
part: l.part_title || l.partTitle || ''
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
// 兜底:从 all-chapters 取
|
|
|
|
|
|
const res = await app.request({ url: '/api/miniprogram/book/all-chapters', silent: true })
|
|
|
|
|
|
const chapters = (res && res.data) || (res && res.chapters) || []
|
|
|
|
|
|
const valid = chapters.filter(c => {
|
|
|
|
|
|
const pt = (c.part_title || c.partTitle || '').toLowerCase()
|
|
|
|
|
|
return !pt.includes('序言') && !pt.includes('尾声') && !pt.includes('附录')
|
2026-02-24 14:35:58 +08:00
|
|
|
|
})
|
2026-02-28 15:16:23 +08:00
|
|
|
|
if (valid.length > 0) {
|
|
|
|
|
|
valid.sort((a, b) => new Date(b.updated_at || b.updatedAt || 0) - new Date(a.updated_at || a.updatedAt || 0))
|
|
|
|
|
|
const latest = valid[0]
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
latestSection: {
|
|
|
|
|
|
id: latest.id,
|
|
|
|
|
|
mid: latest.mid ?? latest.MID ?? 0,
|
|
|
|
|
|
title: latest.section_title || latest.sectionTitle || latest.title || latest.chapterTitle || '',
|
|
|
|
|
|
part: latest.part_title || latest.partTitle || ''
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2026-01-25 19:37:59 +08:00
|
|
|
|
}
|
2026-02-21 20:44:38 +08:00
|
|
|
|
} catch (e) {
|
2026-02-28 15:16:23 +08:00
|
|
|
|
console.log('[Index] 从服务端加载推荐失败:', e)
|
2026-02-21 20:44:38 +08:00
|
|
|
|
}
|
2026-01-25 19:37:59 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
async loadBookData() {
|
|
|
|
|
|
try {
|
2026-02-25 11:47:36 +08:00
|
|
|
|
const res = await app.request({ url: '/api/miniprogram/book/all-chapters', silent: true })
|
2026-02-24 14:35:58 +08:00
|
|
|
|
if (res && (res.data || res.chapters)) {
|
|
|
|
|
|
const chapters = res.data || res.chapters || []
|
2026-02-25 16:26:13 +08:00
|
|
|
|
const partIds = new Set(chapters.map(c => c.partId || c.part_id || '').filter(Boolean))
|
2026-02-23 14:07:41 +08:00
|
|
|
|
this.setData({
|
2026-02-24 14:35:58 +08:00
|
|
|
|
bookData: chapters,
|
2026-02-25 16:26:13 +08:00
|
|
|
|
totalSections: res.total || chapters.length || 62,
|
|
|
|
|
|
partCount: partIds.size || 5
|
2026-02-23 14:07:41 +08:00
|
|
|
|
})
|
2026-01-21 15:49:12 +08:00
|
|
|
|
}
|
2026-02-24 14:35:58 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.error('加载书籍数据失败:', e)
|
|
|
|
|
|
}
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-24 14:35:58 +08:00
|
|
|
|
// 更新用户状态(已读数 = 用户实际打开过的章节数,仅统计有权限阅读的)
|
2026-01-21 15:49:12 +08:00
|
|
|
|
updateUserStatus() {
|
|
|
|
|
|
const { isLoggedIn, hasFullBook, purchasedSections } = app.globalData
|
2026-02-24 14:35:58 +08:00
|
|
|
|
const readCount = Math.min(app.getReadCount(), this.data.totalSections || 62)
|
2026-01-21 15:49:12 +08:00
|
|
|
|
this.setData({
|
2026-02-24 14:35:58 +08:00
|
|
|
|
isLoggedIn,
|
|
|
|
|
|
hasFullBook,
|
|
|
|
|
|
readCount
|
2026-01-14 12:50:00 +08:00
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-24 14:35:58 +08:00
|
|
|
|
// 跳转到目录
|
|
|
|
|
|
goToChapters() {
|
|
|
|
|
|
wx.switchTab({ url: '/pages/chapters/chapters' })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 跳转到搜索页
|
|
|
|
|
|
goToSearch() {
|
|
|
|
|
|
wx.navigateTo({ url: '/pages/search/search' })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-28 10:19:46 +08:00
|
|
|
|
// 跳转到阅读页(优先传 mid,与分享逻辑一致)
|
2026-01-21 15:49:12 +08:00
|
|
|
|
goToRead(e) {
|
|
|
|
|
|
const id = e.currentTarget.dataset.id
|
2026-02-28 10:19:46 +08:00
|
|
|
|
const mid = e.currentTarget.dataset.mid || app.getSectionMid(id)
|
|
|
|
|
|
const q = mid ? `mid=${mid}` : `id=${id}`
|
|
|
|
|
|
wx.navigateTo({ url: `/pages/read/read?${q}` })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-24 14:35:58 +08:00
|
|
|
|
// 跳转到匹配页
|
|
|
|
|
|
goToMatch() {
|
|
|
|
|
|
wx.switchTab({ url: '/pages/match/match' })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
goToVip() {
|
|
|
|
|
|
wx.navigateTo({ url: '/pages/vip/vip' })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-25 16:26:13 +08:00
|
|
|
|
goToAbout() {
|
|
|
|
|
|
wx.navigateTo({ url: '/pages/about/about' })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-03-06 12:12:13 +08:00
|
|
|
|
async onLinkKaruo() {
|
|
|
|
|
|
const app = getApp()
|
|
|
|
|
|
if (!app.globalData.isLoggedIn || !app.globalData.userInfo) {
|
|
|
|
|
|
wx.showModal({
|
|
|
|
|
|
title: '提示',
|
|
|
|
|
|
content: '请先登录后再链接卡若',
|
|
|
|
|
|
confirmText: '去登录',
|
|
|
|
|
|
cancelText: '取消',
|
|
|
|
|
|
success: (res) => {
|
|
|
|
|
|
if (res.confirm) wx.switchTab({ url: '/pages/my/my' })
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
const userId = app.globalData.userInfo.id
|
2026-03-07 21:30:40 +08:00
|
|
|
|
// 2 分钟内只能点一次(与后端限频一致)
|
|
|
|
|
|
const leadLastTs = wx.getStorageSync('lead_last_submit_ts') || 0
|
|
|
|
|
|
if (Date.now() - leadLastTs < 2 * 60 * 1000) {
|
|
|
|
|
|
wx.showToast({ title: '操作太频繁,请2分钟后再试', icon: 'none' })
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-03-06 12:12:13 +08:00
|
|
|
|
let phone = (app.globalData.userInfo.phone || '').trim()
|
|
|
|
|
|
let wechatId = (app.globalData.userInfo.wechatId || app.globalData.userInfo.wechat_id || '').trim()
|
|
|
|
|
|
if (!phone && !wechatId) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const profileRes = await app.request({ url: `/api/miniprogram/user/profile?userId=${userId}`, silent: true })
|
|
|
|
|
|
if (profileRes?.success && profileRes.data) {
|
|
|
|
|
|
phone = (profileRes.data.phone || '').trim()
|
|
|
|
|
|
wechatId = (profileRes.data.wechatId || profileRes.data.wechat_id || '').trim()
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (phone || wechatId) {
|
|
|
|
|
|
wx.showLoading({ title: '提交中...', mask: true })
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await app.request({
|
2026-03-12 11:36:50 +08:00
|
|
|
|
url: '/api/miniprogram/ckb/index-lead',
|
2026-03-06 12:12:13 +08:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
data: {
|
|
|
|
|
|
userId,
|
|
|
|
|
|
phone: phone || undefined,
|
|
|
|
|
|
wechatId: wechatId || undefined,
|
|
|
|
|
|
name: (app.globalData.userInfo.nickname || '').trim() || undefined
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
if (res && res.success) {
|
2026-03-07 21:30:40 +08:00
|
|
|
|
wx.setStorageSync('lead_last_submit_ts', Date.now())
|
2026-03-06 12:12:13 +08:00
|
|
|
|
wx.showToast({ title: res.message || '提交成功', icon: 'success' })
|
|
|
|
|
|
} else {
|
|
|
|
|
|
wx.showToast({ title: (res && res.message) || '提交失败', icon: 'none' })
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
wx.showToast({ title: e.message || '提交失败', icon: 'none' })
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
this.setData({ showLeadModal: true, leadPhone: '' })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
closeLeadModal() {
|
|
|
|
|
|
this.setData({ showLeadModal: false, leadPhone: '' })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-03-10 20:20:03 +08:00
|
|
|
|
// 阻止弹窗内部点击事件冒泡到遮罩层
|
|
|
|
|
|
stopPropagation() {},
|
|
|
|
|
|
|
2026-03-06 12:12:13 +08:00
|
|
|
|
onLeadPhoneInput(e) {
|
|
|
|
|
|
this.setData({ leadPhone: (e.detail.value || '').trim() })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-03-11 14:49:45 +08:00
|
|
|
|
// 一键获取手机号(微信能力),成功后直接提交链接卡若
|
|
|
|
|
|
async onGetPhoneNumberForLead(e) {
|
|
|
|
|
|
if (e.detail.errMsg !== 'getPhoneNumber:ok') {
|
|
|
|
|
|
wx.showToast({ title: '未获取到手机号,请手动输入', icon: 'none' })
|
2026-03-06 12:12:13 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-03-11 14:49:45 +08:00
|
|
|
|
const code = e.detail.code
|
|
|
|
|
|
if (!code) {
|
|
|
|
|
|
wx.showToast({ title: '获取失败,请手动输入', icon: 'none' })
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
const app = getApp()
|
|
|
|
|
|
const userId = app.globalData.userInfo?.id
|
|
|
|
|
|
wx.showLoading({ title: '获取中...', mask: true })
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await app.request({
|
|
|
|
|
|
url: '/api/miniprogram/phone',
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
data: { code, userId }
|
|
|
|
|
|
})
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
if (res && res.success && res.phoneNumber) {
|
|
|
|
|
|
await this._submitLeadWithPhone(res.phoneNumber)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
wx.showToast({ title: '获取失败,请手动输入', icon: 'none' })
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
wx.showToast({ title: err.message || '获取失败,请手动输入', icon: 'none' })
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 内部:用手机号提交链接卡若(一键获取与手动输入共用)
|
|
|
|
|
|
async _submitLeadWithPhone(phone) {
|
|
|
|
|
|
const p = (phone || '').trim().replace(/\s/g, '')
|
|
|
|
|
|
if (!p || p.length < 11) {
|
2026-03-06 12:12:13 +08:00
|
|
|
|
wx.showToast({ title: '请输入正确的手机号', icon: 'none' })
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-03-07 21:30:40 +08:00
|
|
|
|
const leadLastTs = wx.getStorageSync('lead_last_submit_ts') || 0
|
|
|
|
|
|
if (Date.now() - leadLastTs < 2 * 60 * 1000) {
|
|
|
|
|
|
wx.showToast({ title: '操作太频繁,请2分钟后再试', icon: 'none' })
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-03-06 12:12:13 +08:00
|
|
|
|
const app = getApp()
|
|
|
|
|
|
const userId = app.globalData.userInfo?.id
|
|
|
|
|
|
wx.showLoading({ title: '提交中...', mask: true })
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await app.request({
|
2026-03-12 11:36:50 +08:00
|
|
|
|
url: '/api/miniprogram/ckb/index-lead',
|
2026-03-06 12:12:13 +08:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
data: {
|
|
|
|
|
|
userId,
|
2026-03-11 14:49:45 +08:00
|
|
|
|
phone: p,
|
2026-03-12 11:36:50 +08:00
|
|
|
|
name: (app.globalData.userInfo?.nickname || '').trim() || undefined,
|
|
|
|
|
|
},
|
2026-03-06 12:12:13 +08:00
|
|
|
|
})
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
this.setData({ showLeadModal: false, leadPhone: '' })
|
|
|
|
|
|
if (res && res.success) {
|
2026-03-07 21:30:40 +08:00
|
|
|
|
wx.setStorageSync('lead_last_submit_ts', Date.now())
|
2026-03-12 11:36:50 +08:00
|
|
|
|
// 同步手机号到用户资料
|
2026-03-10 20:20:03 +08:00
|
|
|
|
try {
|
2026-03-12 11:36:50 +08:00
|
|
|
|
if (userId) {
|
2026-03-10 20:20:03 +08:00
|
|
|
|
await app.request({
|
|
|
|
|
|
url: '/api/miniprogram/user/profile',
|
|
|
|
|
|
method: 'POST',
|
2026-03-12 11:36:50 +08:00
|
|
|
|
data: { userId, phone: p },
|
2026-03-10 20:20:03 +08:00
|
|
|
|
})
|
|
|
|
|
|
if (app.globalData.userInfo) {
|
2026-03-11 14:49:45 +08:00
|
|
|
|
app.globalData.userInfo.phone = p
|
2026-03-10 20:20:03 +08:00
|
|
|
|
wx.setStorageSync('userInfo', app.globalData.userInfo)
|
|
|
|
|
|
}
|
2026-03-11 14:49:45 +08:00
|
|
|
|
wx.setStorageSync('user_phone', p)
|
2026-03-10 20:20:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log('[Index] 同步手机号到用户资料失败:', e && e.message)
|
|
|
|
|
|
}
|
2026-03-06 12:12:13 +08:00
|
|
|
|
wx.showToast({ title: res.message || '提交成功,卡若会尽快联系您', icon: 'success' })
|
|
|
|
|
|
} else {
|
|
|
|
|
|
wx.showToast({ title: (res && res.message) || '提交失败', icon: 'none' })
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
wx.showToast({ title: e.message || '提交失败', icon: 'none' })
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-03-11 14:49:45 +08:00
|
|
|
|
async submitLead() {
|
|
|
|
|
|
const phone = (this.data.leadPhone || '').trim().replace(/\s/g, '')
|
|
|
|
|
|
if (!phone) {
|
|
|
|
|
|
wx.showToast({ title: '请输入手机号', icon: 'none' })
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
await this._submitLeadWithPhone(phone)
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-24 14:35:58 +08:00
|
|
|
|
goToSuperList() {
|
|
|
|
|
|
wx.switchTab({ url: '/pages/match/match' })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async loadLatestChapters() {
|
|
|
|
|
|
try {
|
2026-02-25 11:47:36 +08:00
|
|
|
|
const res = await app.request({ url: '/api/miniprogram/book/all-chapters', silent: true })
|
2026-02-24 14:35:58 +08:00
|
|
|
|
const chapters = (res && res.data) || (res && res.chapters) || []
|
2026-02-28 15:16:23 +08:00
|
|
|
|
const pt = (c) => (c.partTitle || c.part_title || '').toLowerCase()
|
|
|
|
|
|
const exclude = c => !pt(c).includes('序言') && !pt(c).includes('尾声') && !pt(c).includes('附录')
|
|
|
|
|
|
// stitch_soul:优先取 isNew 标记的章节;若无则取最近更新的前 10 章(排除序言/尾声/附录)
|
|
|
|
|
|
let candidates = chapters.filter(c => (c.isNew || c.is_new) === true && exclude(c))
|
2026-02-25 16:26:13 +08:00
|
|
|
|
if (candidates.length === 0) {
|
2026-02-28 15:16:23 +08:00
|
|
|
|
candidates = chapters.filter(exclude)
|
2026-02-25 16:26:13 +08:00
|
|
|
|
}
|
2026-03-06 12:12:13 +08:00
|
|
|
|
// 解析「第X场」用于倒序,最新(场次大)放在最上方
|
|
|
|
|
|
const sessionNum = (c) => {
|
|
|
|
|
|
const title = c.section_title || c.sectionTitle || c.title || c.chapterTitle || ''
|
|
|
|
|
|
const m = title.match(/第\s*(\d+)\s*场/) || title.match(/第(\d+)场/)
|
|
|
|
|
|
if (m) return parseInt(m[1], 10)
|
|
|
|
|
|
const id = c.id != null ? String(c.id) : ''
|
|
|
|
|
|
if (/^\d+$/.test(id)) return parseInt(id, 10)
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}
|
2026-02-25 16:26:13 +08:00
|
|
|
|
const latest = candidates
|
2026-03-06 12:12:13 +08:00
|
|
|
|
.sort((a, b) => {
|
|
|
|
|
|
const na = sessionNum(a)
|
|
|
|
|
|
const nb = sessionNum(b)
|
|
|
|
|
|
if (na !== nb) return nb - na // 场次倒序:最新在上
|
|
|
|
|
|
return new Date(b.updatedAt || b.updated_at || 0) - new Date(a.updatedAt || a.updated_at || 0)
|
|
|
|
|
|
})
|
2026-02-24 14:35:58 +08:00
|
|
|
|
.slice(0, 10)
|
|
|
|
|
|
.map(c => {
|
|
|
|
|
|
const d = new Date(c.updatedAt || c.updated_at || Date.now())
|
2026-02-25 16:26:13 +08:00
|
|
|
|
const title = c.section_title || c.sectionTitle || c.title || c.chapterTitle || ''
|
|
|
|
|
|
const rawContent = (c.content || '').replace(/<[^>]+>/g, '').trim()
|
|
|
|
|
|
// 描述仅用正文摘要,避免 #id 或标题重复;截取 36 字
|
|
|
|
|
|
let desc = ''
|
|
|
|
|
|
if (rawContent && rawContent.length > 0) {
|
|
|
|
|
|
const clean = rawContent.replace(/^#[\d.]+\s*/, '').trim()
|
|
|
|
|
|
desc = clean.length > 36 ? clean.slice(0, 36) + '...' : clean
|
|
|
|
|
|
}
|
2026-02-24 14:35:58 +08:00
|
|
|
|
return {
|
|
|
|
|
|
id: c.id,
|
2026-02-28 10:19:46 +08:00
|
|
|
|
mid: c.mid ?? c.MID ?? 0,
|
2026-02-25 16:26:13 +08:00
|
|
|
|
title,
|
|
|
|
|
|
desc,
|
|
|
|
|
|
price: c.price ?? 1,
|
2026-02-24 14:35:58 +08:00
|
|
|
|
dateStr: `${d.getMonth() + 1}/${d.getDate()}`
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
this.setData({ latestChapters: latest })
|
|
|
|
|
|
} catch (e) { console.log('[Index] 加载最新新增失败:', e) }
|
|
|
|
|
|
},
|
2026-01-14 12:50:00 +08:00
|
|
|
|
|
2026-02-23 14:07:41 +08:00
|
|
|
|
goToMemberDetail(e) {
|
|
|
|
|
|
const id = e.currentTarget.dataset.id
|
|
|
|
|
|
wx.navigateTo({ url: `/pages/member-detail/member-detail?id=${id}` })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-24 14:35:58 +08:00
|
|
|
|
// 跳转到我的页面
|
|
|
|
|
|
goToMy() {
|
|
|
|
|
|
wx.switchTab({ url: '/pages/my/my' })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-03-04 19:06:06 +08:00
|
|
|
|
// 下拉刷新(等待各异步加载完成后再结束)
|
2026-01-21 15:49:12 +08:00
|
|
|
|
async onPullDownRefresh() {
|
2026-03-04 19:06:06 +08:00
|
|
|
|
await Promise.all([
|
|
|
|
|
|
this.loadBookData(),
|
|
|
|
|
|
this.loadFeaturedFromServer(),
|
|
|
|
|
|
this.loadSuperMembers(),
|
|
|
|
|
|
this.loadLatestChapters()
|
|
|
|
|
|
])
|
2026-01-21 15:49:12 +08:00
|
|
|
|
this.updateUserStatus()
|
|
|
|
|
|
wx.stopPullDownRefresh()
|
2026-02-25 11:47:36 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
const ref = app.getMyReferralCode()
|
|
|
|
|
|
return {
|
|
|
|
|
|
title: 'Soul创业派对 - 真实商业故事',
|
|
|
|
|
|
path: ref ? `/pages/index/index?ref=${ref}` : '/pages/index/index'
|
|
|
|
|
|
}
|
2026-02-27 14:22:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onShareTimeline() {
|
|
|
|
|
|
const ref = app.getMyReferralCode()
|
|
|
|
|
|
return { title: 'Soul创业派对 - 真实商业故事', query: ref ? `ref=${ref}` : '' }
|
2026-01-14 12:50:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|