首页新增额度风险提示卡片,作为补额度主入口

This commit is contained in:
yuming
2026-08-16 09:34:55 +08:00
parent bc4fb7445d
commit 7f420762ef
3 changed files with 80 additions and 1 deletions
+50 -1
View File
@@ -2,6 +2,8 @@
const storage = require('../../utils/storage')
const dateUtils = require('../../utils/date')
const fmt = require('../../utils/format')
const api = require('../../utils/api')
const subscribe = require('../../utils/subscribe')
Page({
data: {
@@ -11,7 +13,8 @@ Page({
currentFilter: 'all',
totalCount: 0,
upcomingCount: 0,
todayText: ''
todayText: '',
atRiskText: ''
},
onLoad() {
@@ -20,6 +23,9 @@ Page({
onShow() {
this.loadPersons()
this.refreshQuota()
// 提前查好订阅状态缓存到实例上:点击处理函数里不能再 await,否则手势上下文会丢
subscribe.getStatus().then(status => { this.subscribeStatus = status })
},
/**
@@ -159,6 +165,49 @@ Page({
})
},
/**
* 拉取额度风险,拼成给用户看的文案
* 说「谁的提醒有风险」而不是「还剩几次额度」——用户理解不了额度这种抽象概念
*/
async refreshQuota() {
try {
const res = await api.subscribe('get')
if (!res || !res.success) return
const names = res.atRiskNames || []
let text = ''
if (names.length > 0 && names.length <= 3) {
text = names.join('、')
} else if (names.length > 3) {
text = names.slice(0, 3).join('、') + ' 等 ' + names.length + ' 人'
}
this.setData({ atRiskText: text })
} catch (e) {
// 查询失败就不显示提示,静默处理,不打扰用户
console.warn('[index] 额度查询失败', e)
}
},
/**
* 点击风险提示卡片补额度
* 注意:wx.requestSubscribeMessage / wx.openSetting 必须在这里同步调用,
* 前面绝不能有 await,否则手势上下文丢失、调用必然失败
*/
onTopUp() {
const status = this.subscribeStatus
if (status === 'rejected' || status === 'mainSwitchOff') {
wx.openSetting({ withSubscriptions: true })
return
}
subscribe.requestAndReport().then(accepted => {
if (accepted) {
this.refreshQuota()
wx.showToast({ title: '已补充提醒次数', icon: 'success' })
} else {
wx.showToast({ title: '未开启提醒', icon: 'none' })
}
})
},
/**
* 点击添加按钮:直接进添加纪念日(方案 B:流程合并,姓名不存在自动建人)
*/