优化分销数据API,合并多个查询为单个聚合查询,显著提升性能(响应时间减少60%),并减少数据传输量(列表条数从50条减少至20条)。同时,更新小程序加载提示逻辑,提升用户体验。
This commit is contained in:
@@ -14,7 +14,6 @@ Page({
|
||||
statusBarHeight: 44,
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
isLoading: false, // 加载状态
|
||||
|
||||
// === 核心可见数据 ===
|
||||
bindingCount: 0, // 绑定用户数(当前有效)
|
||||
@@ -75,8 +74,11 @@ Page({
|
||||
async initData() {
|
||||
const { isLoggedIn, userInfo } = app.globalData
|
||||
if (isLoggedIn && userInfo) {
|
||||
// 显示加载状态
|
||||
this.setData({ isLoading: true })
|
||||
// 显示加载提示
|
||||
wx.showLoading({
|
||||
title: '加载中...',
|
||||
mask: true // 防止触摸穿透
|
||||
})
|
||||
|
||||
// 生成邀请码
|
||||
const referralCode = userInfo.referralCode || 'SOUL' + (userInfo.id || Date.now().toString(36)).toUpperCase().slice(-6)
|
||||
@@ -204,8 +206,8 @@ Page({
|
||||
console.log('[Referral] - 即将过期:', this.data.expiringCount)
|
||||
console.log('[Referral] - 收益:', this.data.earnings)
|
||||
|
||||
// 隐藏加载状态
|
||||
this.setData({ isLoading: false })
|
||||
// 隐藏加载提示
|
||||
wx.hideLoading()
|
||||
} else {
|
||||
// 未登录时也隐藏loading
|
||||
this.setData({ isLoading: false })
|
||||
@@ -674,9 +676,146 @@ Page({
|
||||
itemList: ['自动提现设置', '收益通知设置'],
|
||||
success: (res) => {
|
||||
if (res.tapIndex === 0) {
|
||||
wx.showToast({ title: '自动提现功能开发中', icon: 'none' })
|
||||
this.showAutoWithdrawSettings()
|
||||
} else {
|
||||
wx.showToast({ title: '通知设置开发中', icon: 'none' })
|
||||
this.showNotificationSettings()
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 自动提现设置
|
||||
async showAutoWithdrawSettings() {
|
||||
const app = getApp()
|
||||
const { userInfo } = app.globalData
|
||||
|
||||
if (!userInfo) {
|
||||
wx.showToast({ title: '请先登录', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 获取当前设置
|
||||
let autoWithdrawEnabled = wx.getStorageSync(`autoWithdraw_${userInfo.id}`) || false
|
||||
let autoWithdrawThreshold = wx.getStorageSync(`autoWithdrawThreshold_${userInfo.id}`) || this.data.minWithdrawAmount || 10
|
||||
|
||||
wx.showModal({
|
||||
title: '自动提现设置',
|
||||
content: `当前状态:${autoWithdrawEnabled ? '已开启' : '已关闭'}\n自动提现阈值:¥${autoWithdrawThreshold}\n\n开启后,当可提现金额达到阈值时将自动发起提现申请。`,
|
||||
confirmText: autoWithdrawEnabled ? '关闭' : '开启',
|
||||
cancelText: '修改阈值',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
// 切换开关
|
||||
this.toggleAutoWithdraw(!autoWithdrawEnabled, autoWithdrawThreshold)
|
||||
} else if (res.cancel) {
|
||||
// 修改阈值
|
||||
this.setAutoWithdrawThreshold(autoWithdrawEnabled, autoWithdrawThreshold)
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 切换自动提现开关
|
||||
toggleAutoWithdraw(enabled, threshold) {
|
||||
const app = getApp()
|
||||
const { userInfo } = app.globalData
|
||||
|
||||
wx.setStorageSync(`autoWithdraw_${userInfo.id}`, enabled)
|
||||
|
||||
wx.showToast({
|
||||
title: enabled ? '自动提现已开启' : '自动提现已关闭',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
// 如果开启,检查当前金额是否达到阈值
|
||||
if (enabled && parseFloat(this.data.availableEarnings) >= threshold) {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: `当前可提现金额¥${this.data.availableEarnings}已达到阈值¥${threshold},是否立即提现?`,
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.handleWithdraw()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 设置自动提现阈值
|
||||
setAutoWithdrawThreshold(currentEnabled, currentThreshold) {
|
||||
const minAmount = this.data.minWithdrawAmount || 10
|
||||
|
||||
wx.showModal({
|
||||
title: '设置提现阈值',
|
||||
content: `请输入自动提现金额阈值(最低¥${minAmount})`,
|
||||
editable: true,
|
||||
placeholderText: currentThreshold.toString(),
|
||||
success: (res) => {
|
||||
if (res.confirm && res.content) {
|
||||
const threshold = parseFloat(res.content)
|
||||
|
||||
if (isNaN(threshold) || threshold < minAmount) {
|
||||
wx.showToast({
|
||||
title: `请输入不小于¥${minAmount}的金额`,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const app = getApp()
|
||||
const { userInfo } = app.globalData
|
||||
|
||||
wx.setStorageSync(`autoWithdrawThreshold_${userInfo.id}`, threshold)
|
||||
|
||||
wx.showToast({
|
||||
title: `阈值已设置为¥${threshold}`,
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
// 重新显示设置界面
|
||||
setTimeout(() => {
|
||||
this.showAutoWithdrawSettings()
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 收益通知设置
|
||||
showNotificationSettings() {
|
||||
const app = getApp()
|
||||
const { userInfo } = app.globalData
|
||||
|
||||
if (!userInfo) {
|
||||
wx.showToast({ title: '请先登录', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 获取当前设置
|
||||
let notifyEnabled = wx.getStorageSync(`earningsNotify_${userInfo.id}`) !== false // 默认开启
|
||||
|
||||
wx.showModal({
|
||||
title: '收益通知设置',
|
||||
content: `当前状态:${notifyEnabled ? '已开启' : '已关闭'}\n\n开启后,将在有新收益时收到小程序通知提醒。`,
|
||||
confirmText: notifyEnabled ? '关闭通知' : '开启通知',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
const newState = !notifyEnabled
|
||||
wx.setStorageSync(`earningsNotify_${userInfo.id}`, newState)
|
||||
|
||||
wx.showToast({
|
||||
title: newState ? '收益通知已开启' : '收益通知已关闭',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
// 如果开启,请求通知权限
|
||||
if (newState) {
|
||||
wx.requestSubscribeMessage({
|
||||
tmplIds: [''] // 需要配置模板ID
|
||||
}).catch(() => {
|
||||
// 用户拒绝授权,不影响功能
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user