重构和优化http接口支持切换端口
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import '../env/env_config.dart';
|
||||
|
||||
class HttpApiConsts {
|
||||
// static const String baseUrl = "http://8.159.134.0:8012"; // 旧地址
|
||||
// static const String baseUrl = "http://1.95.137.212:59015"; // 测试地址
|
||||
static const String baseUrl = "http://1.95.137.212:8081"; // 生产地址
|
||||
// 环境地址统一由 EnvConfig 按 ENV 切换:prod=8081 / test=59015
|
||||
static const String baseUrl = EnvConfig.baseUrl;
|
||||
|
||||
/// 账号相关
|
||||
// 登录
|
||||
@@ -65,7 +66,7 @@ class HttpApiConsts {
|
||||
static const String flightTaskCommand = "$baseUrl/iot/UAV/flightTaskCommand";
|
||||
|
||||
/// 告警相关
|
||||
static const String alarmBaseUrl = "http://1.95.137.212:8081";
|
||||
static const String alarmBaseUrl = baseUrl;
|
||||
// 获取告警工单配置列表
|
||||
static const String alarmOrderConfigList =
|
||||
"$alarmBaseUrl/iot/alarmOrderConfig/list";
|
||||
|
||||
6
lib/core/env/env_config.dart
vendored
6
lib/core/env/env_config.dart
vendored
@@ -14,6 +14,12 @@ class EnvConfig {
|
||||
|
||||
static bool get isProduction => environment == 'prod';
|
||||
|
||||
/// HTTP 主后端地址(编译期常量,随 ENV 切换)
|
||||
/// 生产: 8081 测试: 59015
|
||||
static const String baseUrl = environment == 'prod'
|
||||
? 'http://1.95.137.212:8081'
|
||||
: 'http://1.95.137.212:59015';
|
||||
|
||||
/// TCP 服务器配置
|
||||
static String get tcpIp => '1.95.137.212';
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
logger.logWithLevel(
|
||||
'用户点击bindDevice方法API 请求开始',
|
||||
level: 'INFO',
|
||||
data: {'url': 'http://1.95.137.212:8081/iot/device/bindDevice'},
|
||||
data: {'url': '${HttpApiConsts.baseUrl}/iot/device/bindDevice'},
|
||||
);
|
||||
var response = await dio.post(
|
||||
HttpApiConsts.bindDevice,
|
||||
@@ -44,7 +44,7 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
'请求详细参数',
|
||||
level: 'DEBUG',
|
||||
data: {
|
||||
'url': 'http://1.95.137.212:8081/iot/device/bindDevice',
|
||||
'url': '${HttpApiConsts.baseUrl}/iot/device/bindDevice',
|
||||
'deviceId': deviceId,
|
||||
'deviceAlias': deviceAlias,
|
||||
},
|
||||
@@ -122,7 +122,7 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
logger.logWithLevel(
|
||||
'用户点击switchDevice方法API 请求开始',
|
||||
level: 'INFO',
|
||||
data: {'url': 'http://1.95.137.212:8081/iot/device/switchDevice'},
|
||||
data: {'url': '${HttpApiConsts.baseUrl}/iot/device/switchDevice'},
|
||||
);
|
||||
var response = await dio.post(
|
||||
HttpApiConsts.switchDevice,
|
||||
@@ -138,7 +138,7 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
'请求详细参数',
|
||||
level: 'DEBUG',
|
||||
data: {
|
||||
'url': 'http://1.95.137.212:8081/iot/device/switchDevice',
|
||||
'url': '${HttpApiConsts.baseUrl}/iot/device/switchDevice',
|
||||
'platform': platform,
|
||||
'deviceId': deviceId,
|
||||
},
|
||||
@@ -219,12 +219,12 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
'请求详细参数',
|
||||
level: 'DEBUG',
|
||||
data: {
|
||||
'url': 'http://1.95.137.212:8081/iot/device/userDevice',
|
||||
'url': '${HttpApiConsts.baseUrl}/iot/device/userDevice',
|
||||
'tenantName': deviceame,
|
||||
},
|
||||
);
|
||||
final response = await dio.get(
|
||||
'http://1.95.137.212:8081/iot/device/userDevice',
|
||||
HttpApiConsts.getDeviceLocation,
|
||||
queryParameters: {'tenantName': deviceame},
|
||||
// options: Options(
|
||||
// headers: {
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:get_it/get_it.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:maibu_satabot_v2/core/storage/user_storage.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_run_hostrity_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/errors/device_failure.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/repositories/device_hostrity_work_repository.dart';
|
||||
@@ -35,7 +36,7 @@ class DeviceHostrityWorkRepositoryImpl implements DeviceHostrityWorkRepositoryRe
|
||||
_logger.logWithLevel('用户信息获取成功,Token: $token', level: 'info');
|
||||
|
||||
final response = await client.get(
|
||||
'http://1.95.137.212:8081/iot/device/getDeviceRunStatistics?deviceId=$deviceId',
|
||||
'${HttpApiConsts.baseUrl}/iot/device/getDeviceRunStatistics?deviceId=$deviceId',
|
||||
options: Options(headers: {'Content-Type': 'application/json', 'Authorization': 'Bearer $token'}),
|
||||
);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:xml/xml.dart';
|
||||
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/storage/user_storage.dart';
|
||||
import '../../../../core/consts/http_api_consts.dart';
|
||||
import '../../domain/repositories/path_repository.dart';
|
||||
import '../datasources/path_http_datasource.dart';
|
||||
import '../models/device_add_path_point_model.dart';
|
||||
@@ -47,7 +48,7 @@ class PathRepositoryImpl implements PathRepository {
|
||||
required String userId,
|
||||
required String jsonData,
|
||||
}) async {
|
||||
final url = Uri.parse('http://1.95.137.212:8081/iot/workRecord/add');
|
||||
final url = Uri.parse('${HttpApiConsts.baseUrl}/iot/workRecord/add');
|
||||
final headers = {'Content-Type': 'application/json'};
|
||||
final body = jsonEncode({
|
||||
'workName': workName,
|
||||
@@ -74,7 +75,7 @@ class PathRepositoryImpl implements PathRepository {
|
||||
}) async {
|
||||
final timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||
final url = Uri.parse(
|
||||
'http://1.95.137.212:8081/iot/workRecord/selectByUserId',
|
||||
'${HttpApiConsts.baseUrl}/iot/workRecord/selectByUserId',
|
||||
).replace(queryParameters: {'userId': userId, '_t': timestamp.toString()});
|
||||
|
||||
try {
|
||||
@@ -103,7 +104,7 @@ class PathRepositoryImpl implements PathRepository {
|
||||
final timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||
final url =
|
||||
Uri.parse(
|
||||
'http://1.95.137.212:8081/iot/workRecord/deleteByWorkName',
|
||||
'${HttpApiConsts.baseUrl}/iot/workRecord/deleteByWorkName',
|
||||
).replace(
|
||||
queryParameters: {'workName': workName, '_t': timestamp.toString()},
|
||||
);
|
||||
@@ -132,7 +133,7 @@ class PathRepositoryImpl implements PathRepository {
|
||||
final timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||
final url =
|
||||
Uri.parse(
|
||||
'http://1.95.137.212:8081/iot/workRecord/selectByWorkName',
|
||||
'${HttpApiConsts.baseUrl}/iot/workRecord/selectByWorkName',
|
||||
).replace(
|
||||
queryParameters: {'workName': workName, '_t': timestamp.toString()},
|
||||
);
|
||||
@@ -268,7 +269,7 @@ class PathRepositoryImpl implements PathRepository {
|
||||
final timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||
final url =
|
||||
Uri.parse(
|
||||
'http://1.95.137.212:8081/iot/workRecord/selectBySiteId',
|
||||
'${HttpApiConsts.baseUrl}/iot/workRecord/selectBySiteId',
|
||||
).replace(
|
||||
queryParameters: {
|
||||
'siteId': siteId.toString(),
|
||||
@@ -531,7 +532,7 @@ class PathRepositoryImpl implements PathRepository {
|
||||
|
||||
try {
|
||||
final response = await dio.post(
|
||||
'http://1.95.137.212:8081/iot/deviceTask/createDeviceTask',
|
||||
'${HttpApiConsts.baseUrl}/iot/deviceTask/createDeviceTask',
|
||||
data: body,
|
||||
);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import 'package:maibu_satabot_v2/components/toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/tcp_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/core/network/net_message_dispatcher.dart';
|
||||
@@ -965,7 +966,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
final String workRecordJson = jsonEncode(workRecord);
|
||||
final http.MultipartRequest request = http.MultipartRequest(
|
||||
'POST',
|
||||
Uri.parse('http://1.95.137.212:8081/iot/workRecord/add'),
|
||||
Uri.parse('${HttpApiConsts.baseUrl}/iot/workRecord/add'),
|
||||
);
|
||||
|
||||
// 🔥 添加 Authorization 认证头
|
||||
@@ -1033,7 +1034,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
// debugPrint('📤 [保存地块] path长度: ${(savePath['path'] as List?)?.length ?? 0}');
|
||||
// debugPrint('📤 [保存地块] outer长度: ${(savePath['outer'] as List?)?.length ?? 0}');
|
||||
// debugPrint('📤 [保存地块] 是否有图片文件: ${imgBase64 != null && imgBase64.isNotEmpty}');
|
||||
// debugPrint('📤 [保存地块] 请求URL: http://1.95.137.212:8081/iot/workRecord/add');
|
||||
// debugPrint('📤 [保存地块] 请求URL: ${HttpApiConsts.baseUrl}/iot/workRecord/add');
|
||||
// debugPrint('📤 [保存地块] workRecord(完整JSON): $workRecordJson');
|
||||
// debugPrint('📤 [保存地块] savePath(原始对象): $savePath');
|
||||
// debugPrint('📤 [保存地块] ========== 请求参数 END ==========');
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:fpdart/fpdart.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:maibu_satabot_v2/core/router/route_paths.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
|
||||
import 'package:maibu_satabot_v2/features/auth/presentation/bloc/auth_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/my/repository/my_repository.dart';
|
||||
import 'dart:convert';
|
||||
@@ -26,7 +27,7 @@ class MyRepositoryImpl implements MyRepository {
|
||||
// 核心修复:严格匹配抽象类的方法签名
|
||||
@override
|
||||
Future<Either<DeviceFailure, int>> updateName(String nickName) async {
|
||||
final url = Uri.parse('http://1.95.137.212:8081/system/user/profile');
|
||||
final url = Uri.parse('${HttpApiConsts.baseUrl}/system/user/profile');
|
||||
|
||||
// 补充:从 UserStorage 获取 token(接口通常需要认证)
|
||||
final token = await _getToken();
|
||||
|
||||
@@ -1456,7 +1456,7 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
try {
|
||||
final dio = DioClient.create();
|
||||
final response = await dio.post(
|
||||
'http://1.95.137.212:8081/iot/UAV/flightTaskCommand',
|
||||
'${HttpApiConsts.baseUrl}/iot/UAV/flightTaskCommand',
|
||||
data: {'command': command, 'deviceSn': widget.droneSn},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user