feat:增加数据接口
This commit is contained in:
21
lib/utils/date_util.dart
Normal file
21
lib/utils/date_util.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
/// 获取指定日期所在月份的第一天(返回"yyyy-MM-dd"格式)
|
||||
/// [date] 可选参数,默认使用当前日期
|
||||
String getFirstDayOfMonth([DateTime? date]) {
|
||||
final currentDate = date ?? DateTime.now();
|
||||
final firstDay = DateTime(currentDate.year, currentDate.month, 1);
|
||||
return "${firstDay.year}-${_twoDigits(firstDay.month)}-${_twoDigits(firstDay.day)}";
|
||||
}
|
||||
|
||||
/// 获取指定日期所在月份的最后一天(返回"yyyy-MM-dd"格式)
|
||||
/// [date] 可选参数,默认使用当前日期
|
||||
String getLastDayOfMonth([DateTime? date]) {
|
||||
final currentDate = date ?? DateTime.now();
|
||||
// 下个月第一天减一天即为当月最后一天
|
||||
final lastDay = DateTime(currentDate.year, currentDate.month + 1, 0);
|
||||
return "${lastDay.year}-${_twoDigits(lastDay.month)}-${_twoDigits(lastDay.day)}";
|
||||
}
|
||||
|
||||
/// 辅助函数:确保数字为两位数(如1→"01")
|
||||
String _twoDigits(int n) {
|
||||
return n.toString().padLeft(2, '0');
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:food_hub_app/utils/sp_util.dart';
|
||||
import 'package:food_hub_app/widgets/common/index.dart';
|
||||
|
||||
@@ -10,8 +11,7 @@ class HttpUtil {
|
||||
factory HttpUtil() => _instance;
|
||||
|
||||
late Dio _dio;
|
||||
bool isMock = true;
|
||||
String baseUrl = "http://192.168.1.3:8100";
|
||||
String baseUrl = kDebugMode ? "http://172.29.101.108:8100" : "http://14.103.235.151:81";
|
||||
|
||||
// 请求头配置
|
||||
Map<String, dynamic> headers = {
|
||||
@@ -55,7 +55,7 @@ class HttpUtil {
|
||||
InterceptorsWrapper(
|
||||
onResponse: (response, handler) {
|
||||
logger.d("响应状态码: ${response.statusCode}");
|
||||
logger.d("响应数据: ${response.data}");
|
||||
// logger.d("响应数据: ${response.data}");
|
||||
return handler.next(response);
|
||||
},
|
||||
),
|
||||
@@ -81,7 +81,7 @@ class HttpUtil {
|
||||
T Function(dynamic data)? converter,
|
||||
}) async {
|
||||
try {
|
||||
if (isMock) {
|
||||
if (kDebugMode) {
|
||||
path = path.replaceFirst('/food-service', '');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user