vending-machine/mobile/utils/membership.js
2026-04-08 20:45:41 +08:00

36 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 会员按钮状态解析工具
* 根据会员状态和订阅状态,返回各按钮的显示状态
*/
/**
* 解析会员页按钮状态
* @param {object} params
* @param {boolean} params.isMember - 是否为会员
* @param {boolean} params.isSubscribed - 是否已订阅
* @returns {{ monthly: { visible: boolean, disabled: boolean, label: string }, subscription: { visible: boolean, disabled: boolean, label: string } }}
*/
export function resolveMembershipButtons({ isMember, isSubscribed }) {
// 单月会员按钮
const monthly = {
// 已开通单月会员时隐藏单月按钮需求5.8
visible: !isMember,
// 非会员时可点击
disabled: isMember,
// 非会员显示"开通会员",已开通显示"会员已开通"需求5.5
label: isMember ? 'joinedBtn' : 'joinBtn'
}
// 订阅会员按钮
const subscription = {
// 订阅按钮始终可见
visible: true,
// 已订阅时不可点击需求5.9
disabled: isSubscribed,
// 已订阅显示"已购买订阅会员",否则显示"订阅会员"
label: isSubscribed ? 'subscribedBtn' : 'subscribeBtn'
}
return { monthly, subscription }
}