This commit is contained in:
sion
2026-03-30 00:30:42 +08:00
parent 41c1288616
commit 2a901de2c3
27 changed files with 1324 additions and 650 deletions

View File

@@ -2,6 +2,7 @@
class ResponseCode {
static const String success = '0000';
static const String unauthorized = '0002';
static const String kycRequired = 'KYC_REQUIRED';
}
/// API 响应模型
@@ -71,4 +72,5 @@ class ApiResponse<T> {
bool get isSuccess => success;
bool get isUnauthorized => code == ResponseCode.unauthorized;
bool get isKycRequired => code == ResponseCode.kycRequired;
}

View File

@@ -68,6 +68,24 @@ class DioClient {
}
}
/// Multipart 文件上传
Future<ApiResponse<T>> upload<T>(
String path, {
required FormData formData,
T Function(dynamic)? fromJson,
}) async {
try {
final response = await _dio.post(
path,
data: formData,
options: Options(contentType: 'multipart/form-data'),
);
return _handleResponse<T>(response, fromJson);
} on DioException catch (e) {
return _handleError<T>(e);
}
}
ApiResponse<T> _handleResponse<T>(
Response response,
T Function(dynamic)? fromJson,