修复(充值商品): 保存前校验价格分与基础泥点为正整数
- AdminRechargeProductPage 改用严格 parsePositiveInteger 解析价格分与基础泥点 - 空串/非法输入直接提示表单错误,不再静默落库成 0 价或 0 泥点商品
This commit is contained in:
@@ -19,7 +19,7 @@ import {
|
||||
} from '../api/adminApiClient';
|
||||
import type { ProfileRechargeProductConfigAdminResponse } from '../api/adminApiTypes';
|
||||
import { useAdminWriteConfirm } from '../components/useAdminWriteConfirm';
|
||||
import { handlePageError, parsePositiveIntegerOrZero } from './pageUtils';
|
||||
import { handlePageError, parsePositiveInteger } from './pageUtils';
|
||||
|
||||
interface AdminRechargeProductPageProps {
|
||||
token: string;
|
||||
@@ -117,6 +117,13 @@ export function AdminRechargeProductPage({
|
||||
}
|
||||
|
||||
setErrorMessage('');
|
||||
// 中文注释:价格分与基础泥点必须是正整数;空串/非法输入不能静默落库成 0。
|
||||
const normalizedPriceCents = parsePositiveInteger(priceCents);
|
||||
const normalizedPointsAmount = parsePositiveInteger(pointsAmount);
|
||||
if (normalizedPriceCents === null || normalizedPointsAmount === null) {
|
||||
setErrorMessage('价格分与基础泥点必须是大于 0 的整数');
|
||||
return;
|
||||
}
|
||||
const confirmed = await confirmWrite({
|
||||
action: enabled ? '保存充值商品' : '停用充值商品',
|
||||
target: productId.trim(),
|
||||
@@ -130,9 +137,9 @@ export function AdminRechargeProductPage({
|
||||
const response = await upsertProfileRechargeProduct(token, {
|
||||
productId: productId.trim(),
|
||||
title: title.trim(),
|
||||
priceCents: parsePositiveIntegerOrZero(priceCents),
|
||||
priceCents: normalizedPriceCents,
|
||||
kind: 'points',
|
||||
pointsAmount: parsePositiveIntegerOrZero(pointsAmount),
|
||||
pointsAmount: normalizedPointsAmount,
|
||||
badgeLabel: badgeLabel.trim(),
|
||||
description: description.trim(),
|
||||
enabled,
|
||||
|
||||
Reference in New Issue
Block a user