多角色的配置适配

This commit is contained in:
2026-09-14 12:35:20 +08:00
parent 3547f80383
commit a1e01da241
11 changed files with 333 additions and 187 deletions

View File

@@ -5,6 +5,7 @@ import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:xml/xml.dart';
import '../../../../core/consts/http_api_consts.dart';
import '../../../../core/di/injection.dart';
import '../../../../core/storage/user_storage.dart';
import '../../domain/repositories/path_repository.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:59003/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:59003/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:59003/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:59003/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:59003/iot/workRecord/selectBySiteId',
'${HttpApiConsts.baseUrl}/iot/workRecord/selectBySiteId',
).replace(
queryParameters: {
'siteId': siteId.toString(),
@@ -508,7 +509,7 @@ class PathRepositoryImpl implements PathRepository {
}
/// 鍒涘缓璁惧<E79281>浠诲姟锛堥€氳繃鎺ュ彛鎵ц<E98EB5>浣滀笟锛?
/// 鎺ュ彛鍦板潃: http://1.95.137.212:59003/iot/deviceTask/createDeviceTask
/// 鎺ュ彛鍦板潃: ${HttpApiConsts.baseUrl}/iot/deviceTask/createDeviceTask
/// 鍏ュ弬: {"deviceId":"...","routeId":76,"siteId":22,"orgId":5}
/// 杩斿洖: 鍒涘缓鎴愬姛鐨勪换鍔<E68DA2>D
@override
@@ -531,7 +532,7 @@ class PathRepositoryImpl implements PathRepository {
try {
final response = await dio.post(
'http://1.95.137.212:59003/iot/deviceTask/createDeviceTask',
'${HttpApiConsts.baseUrl}/iot/deviceTask/createDeviceTask',
data: body,
);

View File

@@ -102,6 +102,9 @@ class DeviceTaskCubit extends Cubit<DeviceTaskState> {
taskPool: taskList,
currentTask: currentTask,
currentTaskId: currentTask?.id,
// 🔥 活跃任务为空时必须显式清空,否则 copyWith 会保留旧任务导致卡片一直显示
clearCurrentTask: currentTask == null,
clearCurrentTaskId: currentTask == null,
activeTasks: activeTasks,
),
);
@@ -398,7 +401,7 @@ class DeviceTaskCubit extends Cubit<DeviceTaskState> {
/// 清除当前任务
void clearCurrentTask() {
emit(state.copyWith(currentTask: null, currentTaskId: null));
emit(state.copyWith(clearCurrentTask: true, clearCurrentTaskId: true));
_logger.logWithLevel('🧹 清除当前任务');
}

View File

@@ -32,7 +32,9 @@ class DeviceTaskState extends Equatable {
DeviceTaskState copyWith({
List<DeviceTaskEntity>? taskPool,
DeviceTaskEntity? currentTask,
bool clearCurrentTask = false, // 🔥 显式清空 currentTask(copyWith 传 null 无法置空)
int? currentTaskId,
bool clearCurrentTaskId = false, // 🔥 显式清空 currentTaskId
List<DeviceTaskEntity>? activeTasks, // 🔥 新增
bool? isLoading,
String? errorMessage,
@@ -41,8 +43,9 @@ class DeviceTaskState extends Equatable {
}) {
return DeviceTaskState(
taskPool: taskPool ?? this.taskPool,
currentTask: currentTask ?? this.currentTask,
currentTaskId: currentTaskId ?? this.currentTaskId,
currentTask: clearCurrentTask ? null : (currentTask ?? this.currentTask),
currentTaskId:
clearCurrentTaskId ? null : (currentTaskId ?? this.currentTaskId),
activeTasks: activeTasks ?? this.activeTasks, // 🔥 新增
isLoading: isLoading ?? this.isLoading,
errorMessage: errorMessage,