fix(accounts): 修复鱼翅筛选参数类型为浮点数并优化错误提示
1. 后端将 min_gold 与 max_gold 参数及 Schema 类型从 int 改为 float | None,支持小数鱼翅(如 >0 快捷筛选的 0.01); 2. 修复前端 axios 拦截器在遇到 FastAPI 422 验证错误时未展开 detail 导致弹出 [object Object] 的问题; 3. 单元测试补充验证浮点数鱼翅过滤场景。
This commit is contained in:
@@ -1766,6 +1766,11 @@ class TestHighValueAccountFilters:
|
|||||||
names = [it.username for it in items]
|
names = [it.username for it in items]
|
||||||
assert names == ["acc_crown"]
|
assert names == ["acc_crown"]
|
||||||
|
|
||||||
|
# 浮点数鱼翅过滤(如前端「有鱼翅」快捷筛选传 0.01)
|
||||||
|
items_float = self._query(min_gold=0.01)
|
||||||
|
names_float = [it.username for it in items_float]
|
||||||
|
assert "acc_crown" in names_float
|
||||||
|
|
||||||
# 宝典已开通
|
# 宝典已开通
|
||||||
items = self._query(elite_opened=True)
|
items = self._query(elite_opened=True)
|
||||||
names = [it.username for it in items]
|
names = [it.username for it in items]
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ def _filter_accounts_query(
|
|||||||
high_value_filter: str = "",
|
high_value_filter: str = "",
|
||||||
min_points: int | None = None,
|
min_points: int | None = None,
|
||||||
max_points: int | None = None,
|
max_points: int | None = None,
|
||||||
min_gold: int | None = None,
|
min_gold: float | None = None,
|
||||||
max_gold: int | None = None,
|
max_gold: float | None = None,
|
||||||
elite_opened: bool | None = None,
|
elite_opened: bool | None = None,
|
||||||
esports_opened: bool | None = None,
|
esports_opened: bool | None = None,
|
||||||
role_bind_status: str = "",
|
role_bind_status: str = "",
|
||||||
@@ -192,9 +192,9 @@ def _filter_accounts_query(
|
|||||||
query = query.filter(Account.points >= min_points)
|
query = query.filter(Account.points >= min_points)
|
||||||
if isinstance(max_points, int):
|
if isinstance(max_points, int):
|
||||||
query = query.filter(Account.points <= max_points)
|
query = query.filter(Account.points <= max_points)
|
||||||
if isinstance(min_gold, int):
|
if isinstance(min_gold, (int, float)):
|
||||||
query = query.filter(Account.gold_balance >= min_gold)
|
query = query.filter(Account.gold_balance >= min_gold)
|
||||||
if isinstance(max_gold, int):
|
if isinstance(max_gold, (int, float)):
|
||||||
query = query.filter(Account.gold_balance <= max_gold)
|
query = query.filter(Account.gold_balance <= max_gold)
|
||||||
|
|
||||||
# 开通状态过滤
|
# 开通状态过滤
|
||||||
@@ -295,8 +295,8 @@ def list_accounts(
|
|||||||
),
|
),
|
||||||
min_points: int | None = Query(None, description="最低积分"),
|
min_points: int | None = Query(None, description="最低积分"),
|
||||||
max_points: int | None = Query(None, description="最高积分"),
|
max_points: int | None = Query(None, description="最高积分"),
|
||||||
min_gold: int | None = Query(None, description="最低鱼翅"),
|
min_gold: float | None = Query(None, description="最低鱼翅"),
|
||||||
max_gold: int | None = Query(None, description="最高鱼翅"),
|
max_gold: float | None = Query(None, description="最高鱼翅"),
|
||||||
elite_opened: bool | None = Query(None, description="是否开通精英宝典"),
|
elite_opened: bool | None = Query(None, description="是否开通精英宝典"),
|
||||||
esports_opened: bool | None = Query(None, description="是否开通电竞手册"),
|
esports_opened: bool | None = Query(None, description="是否开通电竞手册"),
|
||||||
role_bind_status: str = Query(
|
role_bind_status: str = Query(
|
||||||
|
|||||||
@@ -143,8 +143,8 @@ class AccountBulkSelection(BaseModel):
|
|||||||
high_value_filter: str = ""
|
high_value_filter: str = ""
|
||||||
min_points: int | None = None
|
min_points: int | None = None
|
||||||
max_points: int | None = None
|
max_points: int | None = None
|
||||||
min_gold: int | None = None
|
min_gold: float | None = None
|
||||||
max_gold: int | None = None
|
max_gold: float | None = None
|
||||||
elite_opened: bool | None = None
|
elite_opened: bool | None = None
|
||||||
esports_opened: bool | None = None
|
esports_opened: bool | None = None
|
||||||
role_bind_status: str = ""
|
role_bind_status: str = ""
|
||||||
|
|||||||
@@ -16,7 +16,15 @@ api.interceptors.response.use(
|
|||||||
localStorage.removeItem('user');
|
localStorage.removeItem('user');
|
||||||
window.location.href = '/login';
|
window.location.href = '/login';
|
||||||
}
|
}
|
||||||
const msg = error.response?.data?.detail || error.message || '请求失败';
|
const detail = error.response?.data?.detail;
|
||||||
|
let msg = error.message || '请求失败';
|
||||||
|
if (typeof detail === 'string') {
|
||||||
|
msg = detail;
|
||||||
|
} else if (Array.isArray(detail) && detail.length > 0) {
|
||||||
|
msg = detail.map((d: any) => d?.msg || (typeof d === 'string' ? d : JSON.stringify(d))).join('; ');
|
||||||
|
} else if (detail && typeof detail === 'object') {
|
||||||
|
msg = JSON.stringify(detail);
|
||||||
|
}
|
||||||
return Promise.reject(new Error(msg));
|
return Promise.reject(new Error(msg));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user