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-01-14 12:50:00 +08:00
|
|
|
|
const app = getApp()
|
|
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
|
data: {
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 系统信息
|
|
|
|
|
|
statusBarHeight: 44,
|
|
|
|
|
|
navBarHeight: 88,
|
|
|
|
|
|
|
|
|
|
|
|
// 用户信息
|
|
|
|
|
|
isLoggedIn: false,
|
|
|
|
|
|
hasFullBook: false,
|
|
|
|
|
|
purchasedCount: 0,
|
|
|
|
|
|
|
|
|
|
|
|
// 书籍数据
|
|
|
|
|
|
totalSections: 62,
|
|
|
|
|
|
bookData: [],
|
|
|
|
|
|
|
|
|
|
|
|
// 推荐章节
|
|
|
|
|
|
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-01-21 15:49:12 +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: '未来职业与商业生态' }
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
|
|
// 加载状态
|
2026-01-14 12:50:00 +08:00
|
|
|
|
loading: true
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-25 19:37:59 +08:00
|
|
|
|
onLoad(options) {
|
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-01-21 15:49:12 +08:00
|
|
|
|
|
2026-01-25 19:37:59 +08:00
|
|
|
|
// 处理分享参数(推荐码绑定)
|
|
|
|
|
|
if (options && options.ref) {
|
|
|
|
|
|
console.log('[Index] 检测到推荐码:', options.ref)
|
|
|
|
|
|
app.handleReferralCode({ query: options })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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() {
|
|
|
|
|
|
// 设置TabBar选中状态
|
|
|
|
|
|
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
|
|
|
|
|
this.getTabBar().setData({ selected: 0 })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 更新用户状态
|
|
|
|
|
|
this.updateUserStatus()
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 初始化数据
|
|
|
|
|
|
async initData() {
|
|
|
|
|
|
this.setData({ loading: true })
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
await this.loadBookData()
|
2026-02-21 20:44:38 +08:00
|
|
|
|
await this.loadLatestSection()
|
2026-01-21 15:49:12 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.error('初始化失败:', e)
|
2026-02-21 20:44:38 +08:00
|
|
|
|
this.computeLatestSectionFallback()
|
2026-01-21 15:49:12 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
this.setData({ loading: false })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-21 20:44:38 +08:00
|
|
|
|
// 从后端获取最新章节(2日内有新章取最新3章,否则随机免费章)
|
|
|
|
|
|
async loadLatestSection() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await app.request('/api/book/latest-chapters')
|
|
|
|
|
|
if (res && res.success && res.banner) {
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
latestSection: res.banner,
|
|
|
|
|
|
latestLabel: res.label || '最新更新'
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
2026-01-25 19:37:59 +08:00
|
|
|
|
}
|
2026-02-21 20:44:38 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.warn('latest-chapters API 失败,使用兜底逻辑:', e.message)
|
2026-01-25 19:37:59 +08:00
|
|
|
|
}
|
2026-02-21 20:44:38 +08:00
|
|
|
|
this.computeLatestSectionFallback()
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 兜底:API 失败时从 bookData 计算(随机选免费章节)
|
|
|
|
|
|
computeLatestSectionFallback() {
|
|
|
|
|
|
const bookData = app.globalData.bookData || this.data.bookData || []
|
|
|
|
|
|
let sections = []
|
|
|
|
|
|
if (Array.isArray(bookData)) {
|
|
|
|
|
|
sections = bookData.map(s => ({
|
|
|
|
|
|
id: s.id,
|
|
|
|
|
|
title: s.title || s.sectionTitle,
|
|
|
|
|
|
part: s.part || s.sectionTitle || '真实的行业',
|
|
|
|
|
|
isFree: s.isFree,
|
|
|
|
|
|
price: s.price
|
|
|
|
|
|
}))
|
|
|
|
|
|
} else if (bookData && typeof bookData === 'object') {
|
|
|
|
|
|
const parts = bookData.parts || (Array.isArray(bookData) ? bookData : [])
|
|
|
|
|
|
if (Array.isArray(parts)) {
|
|
|
|
|
|
parts.forEach(p => {
|
|
|
|
|
|
(p.chapters || p.sections || []).forEach(c => {
|
|
|
|
|
|
(c.sections || [c]).forEach(s => {
|
|
|
|
|
|
sections.push({
|
|
|
|
|
|
id: s.id,
|
|
|
|
|
|
title: s.title || s.section_title,
|
|
|
|
|
|
part: p.title || p.part_title || c.title || '',
|
|
|
|
|
|
isFree: s.isFree,
|
|
|
|
|
|
price: s.price
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
const free = sections.filter(s => s.isFree !== false && (s.price === 0 || !s.price))
|
|
|
|
|
|
const candidates = free.length > 0 ? free : sections
|
|
|
|
|
|
if (candidates.length === 0) {
|
|
|
|
|
|
this.setData({ latestSection: { id: '1.1', title: '开始阅读', part: '真实的人' }, latestLabel: '为你推荐' })
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
const idx = Math.floor(Math.random() * candidates.length)
|
|
|
|
|
|
const selected = { id: candidates[idx].id, title: candidates[idx].title, part: candidates[idx].part || '真实的行业' }
|
|
|
|
|
|
this.setData({ latestSection: selected, latestLabel: '为你推荐' })
|
2026-01-25 19:37:59 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 加载书籍数据
|
|
|
|
|
|
async loadBookData() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await app.request('/api/book/all-chapters')
|
|
|
|
|
|
if (res && res.data) {
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
bookData: res.data,
|
|
|
|
|
|
totalSections: res.totalSections || 62
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.error('加载书籍数据失败:', e)
|
2026-01-14 12:50:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 更新用户状态
|
|
|
|
|
|
updateUserStatus() {
|
|
|
|
|
|
const { isLoggedIn, hasFullBook, purchasedSections } = app.globalData
|
|
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
isLoggedIn,
|
|
|
|
|
|
hasFullBook,
|
|
|
|
|
|
purchasedCount: hasFullBook ? this.data.totalSections : (purchasedSections?.length || 0)
|
2026-01-14 12:50:00 +08:00
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 跳转到目录
|
2026-01-14 12:50:00 +08:00
|
|
|
|
goToChapters() {
|
2026-01-21 15:49:12 +08:00
|
|
|
|
wx.switchTab({ url: '/pages/chapters/chapters' })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-25 19:37:59 +08:00
|
|
|
|
// 跳转到搜索页
|
|
|
|
|
|
goToSearch() {
|
|
|
|
|
|
wx.navigateTo({ url: '/pages/search/search' })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 跳转到阅读页
|
|
|
|
|
|
goToRead(e) {
|
|
|
|
|
|
const id = e.currentTarget.dataset.id
|
|
|
|
|
|
wx.navigateTo({ url: `/pages/read/read?id=${id}` })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 跳转到匹配页
|
|
|
|
|
|
goToMatch() {
|
|
|
|
|
|
wx.switchTab({ url: '/pages/match/match' })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 跳转到我的页面
|
|
|
|
|
|
goToMy() {
|
|
|
|
|
|
wx.switchTab({ url: '/pages/my/my' })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 下拉刷新
|
2026-01-21 15:49:12 +08:00
|
|
|
|
async onPullDownRefresh() {
|
|
|
|
|
|
await this.initData()
|
|
|
|
|
|
this.updateUserStatus()
|
|
|
|
|
|
wx.stopPullDownRefresh()
|
2026-01-14 12:50:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|