Files
soul-yongping/miniprogram/pages/about/about.js
2026-03-07 22:58:43 +08:00

134 lines
3.9 KiB
JavaScript

/**
* Soul创业派对 - 关于作者页
* 开发: 卡若
*/
const app = getApp()
Page({
data: {
statusBarHeight: 44,
authorLoading: true,
author: {
name: '卡若',
avatar: 'K',
avatarImg: '/assets/images/author-avatar.png',
title: '',
bio: '',
stats: [],
highlights: []
},
bookInfo: {
title: '一场Soul的创业实验',
totalChapters: 62,
parts: [
{ name: '真实的人', chapters: 10 },
{ name: '真实的行业', chapters: 15 },
{ name: '真实的错误', chapters: 9 },
{ name: '真实的赚钱', chapters: 20 },
{ name: '真实的社会', chapters: 9 }
],
price: 9.9
}
},
onLoad() {
wx.showShareMenu({ withShareTimeline: true })
this.setData({
statusBarHeight: app.globalData.statusBarHeight
})
this.loadAuthor()
this.loadBookStats()
},
async loadAuthor() {
this.setData({ authorLoading: true })
try {
const res = await app.request({ url: '/api/miniprogram/about/author', silent: true })
if (res?.success && res.data) {
const d = res.data
let avatarImg = d.avatarImg || ''
if (avatarImg && !avatarImg.startsWith('http')) {
const base = (app.globalData.baseUrl || '').replace(/\/$/, '')
avatarImg = base ? base + (avatarImg.startsWith('/') ? avatarImg : '/' + avatarImg) : avatarImg
}
this.setData({
author: {
name: d.name || '卡若',
avatar: d.avatar || 'K',
avatarImg: avatarImg || '/assets/images/author-avatar.png',
title: d.title || '',
bio: d.bio || '',
stats: Array.isArray(d.stats) ? d.stats : [
{ label: '商业案例', value: '62' },
{ label: '连续直播', value: '365天' },
{ label: '派对分享', value: '1000+' }
],
highlights: Array.isArray(d.highlights) ? d.highlights : []
},
authorLoading: false
})
} else {
this.setData({ authorLoading: false })
}
} catch (e) {
console.log('[About] 加载作者配置失败,使用默认')
this.setData({ authorLoading: false })
}
},
// 加载书籍统计(合并到作者统计第一项「商业案例」)
async loadBookStats() {
try {
const res = await app.request({ url: '/api/miniprogram/book/stats', silent: true })
if (res?.success && res.data) {
const total = res.data?.totalChapters || 62
this.setData({ 'bookInfo.totalChapters': total })
const stats = this.data.author?.stats || []
const idx = stats.findIndex((s) => s && (s.label === '商业案例' || s.label === '章节'))
if (idx >= 0 && stats[idx]) {
const next = [...stats]
next[idx] = { ...stats[idx], value: String(total) }
this.setData({ 'author.stats': next })
} else if (stats.length === 0) {
this.setData({
'author.stats': [
{ label: '商业案例', value: String(total) },
{ label: '连续直播', value: '365天' },
{ label: '派对分享', value: '1000+' }
]
})
}
}
} catch (e) {
console.log('[About] 加载书籍统计失败,使用默认值')
}
},
// 联系方式功能已禁用
copyWechat() {
wx.showToast({ title: '请在派对房联系作者', icon: 'none' })
},
callPhone() {
wx.showToast({ title: '请在派对房联系作者', icon: 'none' })
},
// 返回
goBack() {
getApp().goBackOrToHome()
},
onShareAppMessage() {
const ref = app.getMyReferralCode()
return {
title: 'Soul创业派对 - 关于',
path: ref ? `/pages/about/about?ref=${ref}` : '/pages/about/about'
}
},
onShareTimeline() {
const ref = app.getMyReferralCode()
return { title: 'Soul创业派对 - 关于', query: ref ? `ref=${ref}` : '' }
}
})