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;
+}