diff --git a/src/utils/rewardFormatter.js b/src/utils/rewardFormatter.js new file mode 100644 index 0000000..15c07fe --- /dev/null +++ b/src/utils/rewardFormatter.js @@ -0,0 +1,22 @@ +/** + * 奖励内容格式化工具 + */ + +/** + * 格式化奖励的展示信息 + * @param {string} type - 奖励类型 (GOLD, DIAMOND, GIFT, FRAGMENTS, DOLLARS 等) + * @param {object} reward - 奖励对象 + * @returns {string} 格式化后的奖励展示文本 + */ +export const formatRewardDisplay = (type, reward) => { + const showAmountTypes = ['GOLD', 'DIAMOND', 'GIFT', 'FRAGMENTS', 'TICKET'] + + if (showAmountTypes.includes(type)) { + return reward.content || '' + } else if (type === 'DOLLARS') { + return `$${reward.content}` + } else { + // 默认返回数量加天数格式 + return `${reward.quantity}Days` + } +}