Files
soul-yongping/miniprogram/pages/index/index.js

70 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const app = getApp()
Page({
data: {
statusBarHeight: 44,
navBarHeight: 88,
totalSections: 62,
purchasedCount: 0,
hasFullBook: false,
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: '真实的赚钱' }
],
latestSection: { id: '9.14', title: '大健康私域一个月150万的70后', part: '真实的赚钱' },
partsList: [
{ id: 'part-1', number: '01', title: '真实的人', subtitle: '人性观察与社交逻辑' },
{ id: 'part-2', number: '02', title: '真实的行业', subtitle: '社会运作的底层规则' },
{ id: 'part-3', number: '03', title: '真实的错误', subtitle: '错过机会比失败更贵' },
{ id: 'part-4', number: '04', title: '真实的赚钱', subtitle: '所有行业的杠杆结构' },
{ id: 'part-5', number: '05', title: '真实的未来', subtitle: '人与系统的关系' }
]
},
onLoad(options) {
this.setNavBarHeight()
if (options && options.ref) app.handleReferralCode({ query: options })
this.loadBookData()
this.updateUserStatus()
},
setNavBarHeight() {
const statusBarHeight = app.globalData.statusBarHeight || 44
const navBarHeight = app.globalData.navBarHeight || (statusBarHeight + 44)
this.setData({ statusBarHeight, navBarHeight })
},
onShow() {
if (typeof this.getTabBar === 'function' && this.getTabBar()) this.getTabBar().setData({ selected: 0 })
this.setNavBarHeight()
this.updateUserStatus()
},
loadBookData() {
app.request('/api/book/all-chapters').then((res) => {
if (res && res.data) this.setData({ totalSections: res.totalSections || 62 })
}).catch(() => {})
},
updateUserStatus() {
const { hasFullBook, purchasedSections } = app.globalData
const total = this.data.totalSections || 62
const count = hasFullBook ? total : (purchasedSections?.length || 0)
this.setData({ hasFullBook, purchasedCount: count })
},
goToChapters() { wx.switchTab({ url: '/pages/chapters/chapters' }) },
goToSearch() { wx.navigateTo({ url: '/pages/search/search' }) },
goToRead(e) {
const id = e.currentTarget.dataset.id
wx.navigateTo({ url: '/pages/read/read?id=' + (id || '') })
},
onPullDownRefresh() {
this.loadBookData()
this.updateUserStatus()
wx.stopPullDownRefresh()
}
})