✨ 新增功能: - 配置后台匹配规则选择功能,支持多种匹配类型自定义 - 推广中心使用真实数据,实现H5/小程序绑定关系 - 配置MySQL数据库连接,建立完整数据表结构 🎨 界面优化: - 优化登录状态显示,未登录只显示基础功能 - 修复推广中心等页面宽度问题,统一界面布局 - 优化设置页面绑定弹窗样式,简洁大气 - 修复目录页图标和文字对齐问题 🔧 技术改进: - 匹配功能支持后台配置,动态加载匹配类型 - 推广数据支持API获取,本地存储作为备份 - 数据库表结构完整,支持用户、订单、推广关系 - 小程序登录仅保留微信登录方式 📱 小程序优化: - 匹配次数调整为每日3次免费 - 支持¥1购买额外匹配次数 - 分享到朋友圈功能优化 - 界面宽度统一,卡片布局一致
234 lines
5.6 KiB
JavaScript
234 lines
5.6 KiB
JavaScript
/**
|
|
* Soul创业实验 - 我的页面
|
|
* 开发: 卡若
|
|
* 技术支持: 存客宝
|
|
*/
|
|
|
|
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
// 系统信息
|
|
statusBarHeight: 44,
|
|
navBarHeight: 88,
|
|
|
|
// 用户状态
|
|
isLoggedIn: false,
|
|
userInfo: null,
|
|
|
|
// 统计数据
|
|
totalSections: 62,
|
|
purchasedCount: 0,
|
|
referralCount: 0,
|
|
earnings: 0,
|
|
pendingEarnings: 0,
|
|
|
|
// 阅读统计
|
|
totalReadTime: 0,
|
|
matchHistory: 0,
|
|
|
|
// Tab切换
|
|
activeTab: 'overview', // overview | footprint
|
|
|
|
// 最近阅读
|
|
recentChapters: [],
|
|
|
|
// 菜单列表
|
|
menuList: [
|
|
{ id: 'orders', title: '我的订单', icon: '📦', count: 0 },
|
|
{ id: 'referral', title: '推广中心', icon: '🎁', badge: '90%佣金' },
|
|
{ id: 'about', title: '关于作者', icon: '👤', iconBg: 'brand' },
|
|
{ id: 'settings', title: '设置', icon: '⚙️', iconBg: 'gray' }
|
|
],
|
|
|
|
// 登录弹窗
|
|
showLoginModal: false,
|
|
isLoggingIn: false
|
|
},
|
|
|
|
onLoad() {
|
|
this.setData({
|
|
statusBarHeight: app.globalData.statusBarHeight,
|
|
navBarHeight: app.globalData.navBarHeight
|
|
})
|
|
this.initUserStatus()
|
|
},
|
|
|
|
onShow() {
|
|
// 设置TabBar选中状态
|
|
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
|
this.getTabBar().setData({ selected: 3 })
|
|
}
|
|
this.initUserStatus()
|
|
},
|
|
|
|
// 初始化用户状态
|
|
initUserStatus() {
|
|
const { isLoggedIn, userInfo, hasFullBook, purchasedSections } = app.globalData
|
|
|
|
if (isLoggedIn && userInfo) {
|
|
// 转换为对象数组
|
|
const recentList = (purchasedSections || []).slice(-5).map(id => ({
|
|
id: id,
|
|
title: `章节 ${id}`
|
|
}))
|
|
|
|
this.setData({
|
|
isLoggedIn: true,
|
|
userInfo,
|
|
purchasedCount: hasFullBook ? this.data.totalSections : (purchasedSections?.length || 0),
|
|
referralCount: userInfo.referralCount || 0,
|
|
earnings: userInfo.earnings || 0,
|
|
pendingEarnings: userInfo.pendingEarnings || 0,
|
|
recentChapters: recentList,
|
|
totalReadTime: Math.floor(Math.random() * 200) + 50
|
|
})
|
|
} else {
|
|
this.setData({
|
|
isLoggedIn: false,
|
|
userInfo: null,
|
|
purchasedCount: 0,
|
|
referralCount: 0,
|
|
earnings: 0,
|
|
pendingEarnings: 0,
|
|
recentChapters: []
|
|
})
|
|
}
|
|
},
|
|
|
|
// 切换Tab
|
|
switchTab(e) {
|
|
const tab = e.currentTarget.dataset.tab
|
|
this.setData({ activeTab: tab })
|
|
},
|
|
|
|
// 显示登录弹窗
|
|
showLogin() {
|
|
this.setData({ showLoginModal: true })
|
|
},
|
|
|
|
// 关闭登录弹窗
|
|
closeLoginModal() {
|
|
if (this.data.isLoggingIn) return
|
|
this.setData({ showLoginModal: false })
|
|
},
|
|
|
|
// 微信登录
|
|
async handleWechatLogin() {
|
|
this.setData({ isLoggingIn: true })
|
|
|
|
try {
|
|
const result = await app.login()
|
|
if (result) {
|
|
this.initUserStatus()
|
|
this.setData({ showLoginModal: false })
|
|
wx.showToast({ title: '登录成功', icon: 'success' })
|
|
} else {
|
|
wx.showToast({ title: '登录失败,请重试', icon: 'none' })
|
|
}
|
|
} catch (e) {
|
|
console.error('微信登录错误:', e)
|
|
wx.showToast({ title: '登录失败,请重试', icon: 'none' })
|
|
} finally {
|
|
this.setData({ isLoggingIn: false })
|
|
}
|
|
},
|
|
|
|
// 手机号登录(需要用户授权)
|
|
async handlePhoneLogin(e) {
|
|
// 检查是否有授权code
|
|
if (!e.detail.code) {
|
|
// 用户拒绝授权或获取失败,尝试使用微信登录
|
|
console.log('手机号授权失败,尝试微信登录')
|
|
return this.handleWechatLogin()
|
|
}
|
|
|
|
this.setData({ isLoggingIn: true })
|
|
|
|
try {
|
|
const result = await app.loginWithPhone(e.detail.code)
|
|
if (result) {
|
|
this.initUserStatus()
|
|
this.setData({ showLoginModal: false })
|
|
wx.showToast({ title: '登录成功', icon: 'success' })
|
|
} else {
|
|
wx.showToast({ title: '登录失败,请重试', icon: 'none' })
|
|
}
|
|
} catch (e) {
|
|
console.error('手机号登录错误:', e)
|
|
wx.showToast({ title: '登录失败,请重试', icon: 'none' })
|
|
} finally {
|
|
this.setData({ isLoggingIn: false })
|
|
}
|
|
},
|
|
|
|
// 点击菜单
|
|
handleMenuTap(e) {
|
|
const id = e.currentTarget.dataset.id
|
|
|
|
if (!this.data.isLoggedIn && id !== 'about') {
|
|
this.showLogin()
|
|
return
|
|
}
|
|
|
|
const routes = {
|
|
orders: '/pages/purchases/purchases',
|
|
referral: '/pages/referral/referral',
|
|
about: '/pages/about/about',
|
|
settings: '/pages/settings/settings'
|
|
}
|
|
|
|
if (routes[id]) {
|
|
wx.navigateTo({ url: routes[id] })
|
|
}
|
|
},
|
|
|
|
// 跳转到阅读页
|
|
goToRead(e) {
|
|
const id = e.currentTarget.dataset.id
|
|
wx.navigateTo({ url: `/pages/read/read?id=${id}` })
|
|
},
|
|
|
|
// 跳转到目录
|
|
goToChapters() {
|
|
wx.switchTab({ url: '/pages/chapters/chapters' })
|
|
},
|
|
|
|
// 跳转到关于页
|
|
goToAbout() {
|
|
wx.navigateTo({ url: '/pages/about/about' })
|
|
},
|
|
|
|
// 跳转到匹配
|
|
goToMatch() {
|
|
wx.switchTab({ url: '/pages/match/match' })
|
|
},
|
|
|
|
// 跳转到推广中心
|
|
goToReferral() {
|
|
if (!this.data.isLoggedIn) {
|
|
this.showLogin()
|
|
return
|
|
}
|
|
wx.navigateTo({ url: '/pages/referral/referral' })
|
|
},
|
|
|
|
// 退出登录
|
|
handleLogout() {
|
|
wx.showModal({
|
|
title: '退出登录',
|
|
content: '确定要退出登录吗?',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
app.logout()
|
|
this.initUserStatus()
|
|
wx.showToast({ title: '已退出登录', icon: 'success' })
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
// 阻止冒泡
|
|
stopPropagation() {}
|
|
})
|