feat:增加菜谱后端接口
This commit is contained in:
@@ -2,6 +2,8 @@ import 'package:dio/dio.dart';
|
||||
import 'package:food_hub_app/utils/sp_util.dart';
|
||||
import 'package:food_hub_app/widgets/common/index.dart';
|
||||
|
||||
import 'log_util.dart';
|
||||
|
||||
class HttpUtil {
|
||||
static final HttpUtil _instance = HttpUtil._internal();
|
||||
|
||||
@@ -34,9 +36,9 @@ class HttpUtil {
|
||||
_dio.interceptors.add(
|
||||
InterceptorsWrapper(
|
||||
onRequest: (options, handler) {
|
||||
print("请求URL: ${options.uri}");
|
||||
logger.d("请求URL: ${options.uri}");
|
||||
if (options.data != null) {
|
||||
print("请求参数: ${options.data}");
|
||||
logger.d("请求参数: ${options.data}");
|
||||
}
|
||||
|
||||
if (SPUtil.getString('token').isNotEmpty) {
|
||||
@@ -51,8 +53,8 @@ class HttpUtil {
|
||||
_dio.interceptors.add(
|
||||
InterceptorsWrapper(
|
||||
onResponse: (response, handler) {
|
||||
print("响应状态码: ${response.statusCode}");
|
||||
print("响应数据: ${response.data}");
|
||||
logger.d("响应状态码: ${response.statusCode}");
|
||||
logger.d("响应数据: ${response.data}");
|
||||
return handler.next(response);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -14,4 +14,12 @@ String formatDateTime(DateTime dateTime, [String format = 'yyyy-MM-dd']) {
|
||||
final DateFormat formatter = DateFormat(format);
|
||||
// return formatter.format(dateTime);
|
||||
return Intl.withLocale('zh_CN', () => formatter.format(dateTime));
|
||||
}
|
||||
|
||||
/// 通用列表转换函数
|
||||
List<T> convertListResponse<T>(dynamic data, T Function(Map<String, dynamic>) fromJson) {
|
||||
if (data is List) {
|
||||
return data.map((item) => fromJson(item as Map<String, dynamic>)).toList();
|
||||
}
|
||||
throw FormatException('Expected a list of items for conversion, but got ${data.runtimeType}');
|
||||
}
|
||||
12
lib/utils/log_util.dart
Normal file
12
lib/utils/log_util.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
import 'package:logger/logger.dart';
|
||||
|
||||
// 全局日志实例,在整个项目中共享
|
||||
final Logger logger = Logger(
|
||||
printer: PrettyPrinter(
|
||||
methodCount: 1,
|
||||
colors: true,
|
||||
dateTimeFormat: DateTimeFormat.dateAndTime,
|
||||
),
|
||||
// 可选:配置输出到文件(需配合文件操作库)
|
||||
// output: FileOutput(file: File('logs/app.log')),
|
||||
);
|
||||
Reference in New Issue
Block a user