diff --git a/frontend/src/components/admin/user/UserBalanceModal.vue b/frontend/src/components/admin/user/UserBalanceModal.vue
index 61d4785e..c669c2a5 100644
--- a/frontend/src/components/admin/user/UserBalanceModal.vue
+++ b/frontend/src/components/admin/user/UserBalanceModal.vue
@@ -3,14 +3,17 @@
@@ -35,11 +38,30 @@ const emit = defineEmits(['close', 'success']); const { t } = useI18n(); const a
const submitting = ref(false); const form = reactive({ amount: 0, notes: '' })
watch(() => props.show, (v) => { if(v) { form.amount = 0; form.notes = '' } })
+// 格式化余额:显示完整精度,去除尾部多余的0
+const formatBalance = (value: number) => {
+ if (value === 0) return '0.00'
+ // 最多保留8位小数,去除尾部的0
+ const formatted = value.toFixed(8).replace(/\.?0+$/, '')
+ // 确保至少有2位小数
+ const parts = formatted.split('.')
+ if (parts.length === 1) return formatted + '.00'
+ if (parts[1].length === 1) return formatted + '0'
+ return formatted
+}
+
+// 填入全部余额
+const fillAllBalance = () => {
+ if (props.user) {
+ form.amount = props.user.balance
+ }
+}
+
const calculateNewBalance = () => {
if (!props.user) return 0
const result = props.operation === 'add' ? props.user.balance + form.amount : props.user.balance - form.amount
// 避免浮点数精度问题导致的 -0.00 显示
- return result === 0 || Object.is(result, -0) ? 0 : result
+ return Math.abs(result) < 1e-10 ? 0 : result
}
const handleBalanceSubmit = async () => {
if (!props.user) return
@@ -47,10 +69,8 @@ const handleBalanceSubmit = async () => {
appStore.showError(t('admin.users.amountRequired'))
return
}
- // 使用小数点后两位精度比较,避免浮点数精度问题
- const amount = Math.round(form.amount * 100) / 100
- const balance = Math.round(props.user.balance * 100) / 100
- if (props.operation === 'subtract' && amount > balance) {
+ // 退款时验证金额不超过实际余额
+ if (props.operation === 'subtract' && form.amount > props.user.balance) {
appStore.showError(t('admin.users.insufficientBalance'))
return
}
diff --git a/frontend/src/i18n/locales/en.ts b/frontend/src/i18n/locales/en.ts
index bd17a7f1..3c4fbcc1 100644
--- a/frontend/src/i18n/locales/en.ts
+++ b/frontend/src/i18n/locales/en.ts
@@ -724,6 +724,7 @@ export default {
withdraw: 'Withdraw',
depositAmount: 'Deposit Amount',
withdrawAmount: 'Withdraw Amount',
+ withdrawAll: 'All',
currentBalance: 'Current Balance',
depositNotesPlaceholder:
'e.g., New user registration bonus, promotional credit, compensation, etc.',
diff --git a/frontend/src/i18n/locales/zh.ts b/frontend/src/i18n/locales/zh.ts
index 9724a55c..70d2fb35 100644
--- a/frontend/src/i18n/locales/zh.ts
+++ b/frontend/src/i18n/locales/zh.ts
@@ -780,6 +780,7 @@ export default {
withdraw: '退款',
depositAmount: '充值金额',
withdrawAmount: '退款金额',
+ withdrawAll: '全部',
depositNotesPlaceholder: '例如:新用户注册奖励、活动充值、补偿充值等',
withdrawNotesPlaceholder: '例如:服务问题退款、错误充值退回、账户注销退款等',
notesOptional: '备注为可选项,有助于未来查账',