fix(pre-planting): 修复购买失败时 List<dynamic> 类型转换错误和续购省市缺失
1. api_client.dart: NestJS validation error 返回 message 为数组时,
用 join(', ') 转为字符串,避免直接传给 ApiException(String) 崩溃
2. pre_planting_purchase_page.dart: 续购时传 _position 中已保存的
provinceCode/cityCode,满足后端 DTO 必填校验
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2d7b02aa96
commit
606d3c0b22
|
|
@ -384,7 +384,10 @@ class ApiClient {
|
||||||
case DioExceptionType.badResponse:
|
case DioExceptionType.badResponse:
|
||||||
final statusCode = error.response?.statusCode;
|
final statusCode = error.response?.statusCode;
|
||||||
final data = error.response?.data;
|
final data = error.response?.data;
|
||||||
final message = data is Map ? data['message'] ?? '请求失败' : '请求失败';
|
final rawMsg = data is Map ? data['message'] : null;
|
||||||
|
final message = rawMsg is List
|
||||||
|
? (rawMsg as List).join(', ')
|
||||||
|
: (rawMsg?.toString() ?? '请求失败');
|
||||||
|
|
||||||
switch (statusCode) {
|
switch (statusCode) {
|
||||||
case 400:
|
case 400:
|
||||||
|
|
|
||||||
|
|
@ -351,10 +351,10 @@ class _PrePlantingPurchasePageState
|
||||||
final response = await prePlantingService.createOrder(
|
final response = await prePlantingService.createOrder(
|
||||||
portionCount: _quantity,
|
portionCount: _quantity,
|
||||||
// 首次购买时传省市信息,续购时后端自动复用
|
// 首次购买时传省市信息,续购时后端自动复用
|
||||||
provinceCode: _isFirstPurchase ? _selectedProvinceCode : null,
|
provinceCode: _isFirstPurchase ? _selectedProvinceCode : _position?.provinceCode,
|
||||||
provinceName: _isFirstPurchase ? _selectedProvinceName : null,
|
provinceName: _isFirstPurchase ? _selectedProvinceName : _position?.provinceName,
|
||||||
cityCode: _isFirstPurchase ? _selectedCityCode : null,
|
cityCode: _isFirstPurchase ? _selectedCityCode : _position?.cityCode,
|
||||||
cityName: _isFirstPurchase ? _selectedCityName : null,
|
cityName: _isFirstPurchase ? _selectedCityName : _position?.cityName,
|
||||||
);
|
);
|
||||||
|
|
||||||
debugPrint(
|
debugPrint(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue