首页新增额度风险提示卡片,作为补额度主入口
This commit is contained in:
+50
-1
@@ -2,6 +2,8 @@
|
|||||||
const storage = require('../../utils/storage')
|
const storage = require('../../utils/storage')
|
||||||
const dateUtils = require('../../utils/date')
|
const dateUtils = require('../../utils/date')
|
||||||
const fmt = require('../../utils/format')
|
const fmt = require('../../utils/format')
|
||||||
|
const api = require('../../utils/api')
|
||||||
|
const subscribe = require('../../utils/subscribe')
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
@@ -11,7 +13,8 @@ Page({
|
|||||||
currentFilter: 'all',
|
currentFilter: 'all',
|
||||||
totalCount: 0,
|
totalCount: 0,
|
||||||
upcomingCount: 0,
|
upcomingCount: 0,
|
||||||
todayText: ''
|
todayText: '',
|
||||||
|
atRiskText: ''
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
@@ -20,6 +23,9 @@ Page({
|
|||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
this.loadPersons()
|
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:流程合并,姓名不存在自动建人)
|
* 点击添加按钮:直接进添加纪念日(方案 B:流程合并,姓名不存在自动建人)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -18,6 +18,12 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 额度风险提示卡片:谁的提醒可能发不出去,同时是补额度的主入口 -->
|
||||||
|
<view wx:if="{{atRiskText}}" class="quota-warn" bindtap="onTopUp">
|
||||||
|
<text class="quota-warn-icon">⚠️</text>
|
||||||
|
<text class="quota-warn-text">{{atRiskText}}的生日提醒可能发不出去,点这里补上</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
<!-- 搜索栏 -->
|
<!-- 搜索栏 -->
|
||||||
<view class="search-wrap">
|
<view class="search-wrap">
|
||||||
<view class="search-box">
|
<view class="search-box">
|
||||||
|
|||||||
@@ -391,3 +391,27 @@ page {
|
|||||||
line-height: 1;
|
line-height: 1;
|
||||||
margin-top: -4rpx;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user