From 7f420762ef23d46056dd75b64a139b141fb4676a Mon Sep 17 00:00:00 2001 From: yuming Date: Sun, 16 Aug 2026 09:34:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=96=B0=E5=A2=9E=E9=A2=9D?= =?UTF-8?q?=E5=BA=A6=E9=A3=8E=E9=99=A9=E6=8F=90=E7=A4=BA=E5=8D=A1=E7=89=87?= =?UTF-8?q?=EF=BC=8C=E4=BD=9C=E4=B8=BA=E8=A1=A5=E9=A2=9D=E5=BA=A6=E4=B8=BB?= =?UTF-8?q?=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 51 +++++++++++++++++++++++++++++++++++++++++- pages/index/index.wxml | 6 +++++ pages/index/index.wxss | 24 ++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/pages/index/index.js b/pages/index/index.js index 3000807..3cb0b50 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -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:流程合并,姓名不存在自动建人) */ diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 48f90a6..6a9a88a 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -18,6 +18,12 @@ + + + ⚠️ + {{atRiskText}}的生日提醒可能发不出去,点这里补上 + + diff --git a/pages/index/index.wxss b/pages/index/index.wxss index 3d4bf39..cae96ae 100644 --- a/pages/index/index.wxss +++ b/pages/index/index.wxss @@ -391,3 +391,27 @@ page { line-height: 1; margin-top: -4rpx; } + +/* 额度风险提示卡片:仅在有提醒可能发不出去时出现 */ +.quota-warn { + display: flex; + align-items: center; + margin: 0 32rpx 24rpx; + padding: 24rpx 28rpx; + background: #FBF3E4; + border: 2rpx solid #E0C89A; + border-radius: 12rpx; +} + +.quota-warn-icon { + flex-shrink: 0; + margin-right: 16rpx; + font-size: 32rpx; +} + +.quota-warn-text { + flex: 1; + font-size: 26rpx; + line-height: 1.5; + color: #8A5A1F; +}