Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60983728ab | ||
|
|
982e4364d5 | ||
|
|
1ed35d1373 | ||
|
|
e6361ac72b | ||
|
|
4ed2d00b91 | ||
|
|
b8b53e94d5 | ||
|
|
5d9f67f05d | ||
|
|
613e4fc57e | ||
|
|
44975cde97 | ||
|
|
3b3d1ddc1e | ||
|
|
5e66537a87 | ||
|
|
232672a6b9 | ||
|
|
d6d6262a0d |
@@ -80,7 +80,12 @@
|
|||||||
"Bash(pip install:*)",
|
"Bash(pip install:*)",
|
||||||
"Bash(python3:*)",
|
"Bash(python3:*)",
|
||||||
"Bash(npx:*)",
|
"Bash(npx:*)",
|
||||||
"Bash(xargs head:*)"
|
"Bash(xargs head:*)",
|
||||||
|
"Bash(for file in *.png)",
|
||||||
|
"Bash(do echo \"=== $file ===\")",
|
||||||
|
"Read(//f/project/go-fly-platform-services/**)",
|
||||||
|
"Bash(find \"F:/project/go-fly-platform-services/zlt-web/react-web-next/src/pages/orders/VideoTemplate\" -type f \\\\\\( -name \"*.tsx\" -o -name \"*.ts\" -o -name \"*.jsx\" -o -name \"*.js\" -o -name \"*.json\" \\\\\\) 2>/dev/null | head -50)",
|
||||||
|
"Bash(find \"F:/project/go-fly-platform-services/zlt-web/react-web-next/src/services\" -type f \\\\\\( -name \"*.ts\" -o -name \"*.tsx\" \\\\\\) 2>/dev/null | grep -i order)"
|
||||||
],
|
],
|
||||||
"deny": [],
|
"deny": [],
|
||||||
"ask": []
|
"ask": []
|
||||||
|
|||||||
+29
@@ -6,6 +6,8 @@ import com.alibaba.excel.support.ExcelTypeEnum;
|
|||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
import com.central.device.model.AgeDevice;
|
import com.central.device.model.AgeDevice;
|
||||||
|
import com.central.device.model.dto.DeviceStatusDTO;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import com.central.device.model.excel.AgeDeviceExcel;
|
import com.central.device.model.excel.AgeDeviceExcel;
|
||||||
import com.central.device.model.vo.AgeDeviceLocationVO;
|
import com.central.device.model.vo.AgeDeviceLocationVO;
|
||||||
import com.central.device.service.IAgeDeviceService;
|
import com.central.device.service.IAgeDeviceService;
|
||||||
@@ -26,6 +28,7 @@ import java.io.IOException;
|
|||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -323,4 +326,30 @@ public class AgeDeviceController {
|
|||||||
return Result.failed("更新失败:" + e.getMessage());
|
return Result.failed("更新失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备状态(在线/离线)
|
||||||
|
* deviceStatus: 0-在线,1-离线
|
||||||
|
*/
|
||||||
|
@Operation(summary = "修改设备状态")
|
||||||
|
@PostMapping("/updateDeviceStatus")
|
||||||
|
public Result updateDeviceStatus(@Validated @RequestBody DeviceStatusDTO dto) {
|
||||||
|
try {
|
||||||
|
log.info("修改设备状态,deviceSn: {}, deviceStatus: {}", dto.getDeviceSn(), dto.getDeviceStatus());
|
||||||
|
|
||||||
|
AgeDevice device = ageDeviceService.getByDeviceSn(dto.getDeviceSn());
|
||||||
|
if (device == null) {
|
||||||
|
return Result.failed("设备不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
device.setBoundStatus(dto.getDeviceStatus());
|
||||||
|
device.setBoundTime(new Date());
|
||||||
|
boolean result = ageDeviceService.updateById(device);
|
||||||
|
|
||||||
|
return result ? Result.succeed("更新成功") : Result.failed("更新失败");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("修改设备状态失败", e);
|
||||||
|
return Result.failed("更新失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
package com.central.device.controller;
|
||||||
|
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
import com.central.device.model.AgeDevice;
|
||||||
|
import com.central.device.model.vo.BoatRouteListVO;
|
||||||
|
import com.central.device.model.vo.ThreeDModelFileVO;
|
||||||
|
import com.central.device.service.IAgeDeviceService;
|
||||||
|
import com.central.device.service.IBoatRouteService;
|
||||||
|
import com.central.device.service.IThreeDModelFileService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端Pad页面专用接口
|
||||||
|
* Gateway放行 /client/**,无需认证
|
||||||
|
*
|
||||||
|
* @author dzc
|
||||||
|
* @date 2026-03-11
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/client")
|
||||||
|
@Tag(name = "客户端Pad接口")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ClientController {
|
||||||
|
|
||||||
|
private final IAgeDeviceService ageDeviceService;
|
||||||
|
private final IBoatRouteService boatRouteService;
|
||||||
|
private final IThreeDModelFileService threeDModelFileService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验设备SN是否存在
|
||||||
|
*/
|
||||||
|
@Operation(summary = "设备SN校验登录")
|
||||||
|
@GetMapping("/auth/check")
|
||||||
|
public Result<?> checkDeviceSn(
|
||||||
|
@Parameter(description = "设备SN", required = true)
|
||||||
|
@RequestParam String deviceSn) {
|
||||||
|
AgeDevice device = ageDeviceService.getByDeviceSn(deviceSn);
|
||||||
|
if (device == null) {
|
||||||
|
return Result.failed("设备不存在或未绑定");
|
||||||
|
}
|
||||||
|
Map<String, Object> info = new HashMap<>();
|
||||||
|
info.put("deviceSn", device.getDeviceSn());
|
||||||
|
info.put("deviceName", device.getDeviceName());
|
||||||
|
info.put("deviceType", device.getDeviceType());
|
||||||
|
return Result.succeed(info, "验证成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备航线列表
|
||||||
|
*/
|
||||||
|
@Operation(summary = "获取设备航线列表")
|
||||||
|
@GetMapping("/routes")
|
||||||
|
public Result<List<BoatRouteListVO>> getRoutes(
|
||||||
|
@Parameter(description = "设备SN", required = true)
|
||||||
|
@RequestParam String deviceSn) {
|
||||||
|
List<BoatRouteListVO> routes = boatRouteService.listByDeviceSn(deviceSn);
|
||||||
|
return Result.succeed(routes, "查询成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备关联的3D模型
|
||||||
|
*/
|
||||||
|
@Operation(summary = "获取设备3D模型列表")
|
||||||
|
@GetMapping("/models")
|
||||||
|
public Result<List<ThreeDModelFileVO>> getModels(
|
||||||
|
@Parameter(description = "设备SN", required = true)
|
||||||
|
@RequestParam String deviceSn) {
|
||||||
|
List<ThreeDModelFileVO> models = threeDModelFileService.getByDeviceSn(deviceSn);
|
||||||
|
return Result.succeed(models, "查询成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
+145
@@ -0,0 +1,145 @@
|
|||||||
|
package com.central.device.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.central.device.model.vo.BoatRealtimeVO;
|
||||||
|
import com.central.device.service.IBoatTrackService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端SSE遥测数据控制器
|
||||||
|
* Gateway放行 /client/**,无需认证
|
||||||
|
*
|
||||||
|
* @author dzc
|
||||||
|
* @date 2026-03-11
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/client/sse")
|
||||||
|
@Tag(name = "客户端SSE遥测接口")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ClientSseController {
|
||||||
|
|
||||||
|
private final IBoatTrackService boatTrackService;
|
||||||
|
|
||||||
|
private final Map<String, SseEmitter> emitters = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Operation(summary = "客户端订阅设备遥测数据")
|
||||||
|
@GetMapping(value = "/telemetry/{deviceSn}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||||
|
public ResponseEntity<SseEmitter> subscribeTelemetry(
|
||||||
|
@Parameter(description = "设备SN", required = true)
|
||||||
|
@PathVariable String deviceSn,
|
||||||
|
@Parameter(description = "客户端会话ID(可选)")
|
||||||
|
@RequestHeader(value = "X-Client-Session-Id", required = false) String clientSessionId) {
|
||||||
|
|
||||||
|
String connectionId;
|
||||||
|
if (clientSessionId != null && !clientSessionId.trim().isEmpty()) {
|
||||||
|
connectionId = "client_" + clientSessionId + "_" + deviceSn;
|
||||||
|
} else {
|
||||||
|
connectionId = "client_" + UUID.randomUUID().toString() + "_" + deviceSn;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除已有连接
|
||||||
|
if (emitters.containsKey(connectionId)) {
|
||||||
|
removeConnection(connectionId, deviceSn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建SSE连接(永不超时)
|
||||||
|
SseEmitter emitter = new SseEmitter(0L);
|
||||||
|
emitters.put(connectionId, emitter);
|
||||||
|
|
||||||
|
// 注册遥测回调
|
||||||
|
boatTrackService.registerTelemetryCallback(deviceSn, connectionId, (data) -> {
|
||||||
|
sendTelemetryData(connectionId, data);
|
||||||
|
});
|
||||||
|
|
||||||
|
emitter.onCompletion(() -> {
|
||||||
|
log.info("[ClientSSE] 连接完成: connectionId={}, deviceSn={}", connectionId, deviceSn);
|
||||||
|
removeConnection(connectionId, deviceSn);
|
||||||
|
});
|
||||||
|
emitter.onTimeout(() -> {
|
||||||
|
log.info("[ClientSSE] 连接超时: connectionId={}, deviceSn={}", connectionId, deviceSn);
|
||||||
|
removeConnection(connectionId, deviceSn);
|
||||||
|
});
|
||||||
|
emitter.onError(e -> {
|
||||||
|
log.warn("[ClientSSE] 连接错误: connectionId={}, error={}", connectionId, e.getMessage());
|
||||||
|
removeConnection(connectionId, deviceSn);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 发送初始连接事件
|
||||||
|
try {
|
||||||
|
emitter.send(SseEmitter.event()
|
||||||
|
.name("connected")
|
||||||
|
.data("{\"connectionId\":\"" + connectionId + "\",\"deviceSn\":\"" + deviceSn + "\"}"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("[ClientSSE] 发送初始事件失败: {}", e.getMessage());
|
||||||
|
removeConnection(connectionId, deviceSn);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("[ClientSSE] 客户端订阅遥测: connectionId={}, deviceSn={}", connectionId, deviceSn);
|
||||||
|
return ResponseEntity.ok().body(emitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "客户端断开SSE连接")
|
||||||
|
@DeleteMapping("/telemetry/{deviceSn}")
|
||||||
|
public ResponseEntity<Void> disconnect(
|
||||||
|
@PathVariable String deviceSn,
|
||||||
|
@RequestHeader(value = "X-Client-Session-Id", required = false) String clientSessionId) {
|
||||||
|
if (clientSessionId != null) {
|
||||||
|
String connectionId = "client_" + clientSessionId + "_" + deviceSn;
|
||||||
|
removeConnection(connectionId, deviceSn);
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "客户端断开SSE连接(Beacon)")
|
||||||
|
@PostMapping("/telemetry/{deviceSn}/disconnect")
|
||||||
|
public ResponseEntity<Void> disconnectBeacon(
|
||||||
|
@PathVariable String deviceSn,
|
||||||
|
@RequestBody(required = false) Map<String, String> body) {
|
||||||
|
String sessionId = body != null ? body.get("sessionId") : null;
|
||||||
|
if (sessionId != null) {
|
||||||
|
String connectionId = "client_" + sessionId + "_" + deviceSn;
|
||||||
|
removeConnection(connectionId, deviceSn);
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendTelemetryData(String connectionId, BoatRealtimeVO data) {
|
||||||
|
SseEmitter emitter = emitters.get(connectionId);
|
||||||
|
if (emitter == null) return;
|
||||||
|
try {
|
||||||
|
emitter.send(SseEmitter.event()
|
||||||
|
.name("boat-telemetry")
|
||||||
|
.data(JSON.toJSONString(data)));
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("[ClientSSE] 发送遥测数据失败: connectionId={}, error={}", connectionId, e.getMessage());
|
||||||
|
removeConnection(connectionId, data.getDeviceSn());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean removeConnection(String connectionId, String deviceSn) {
|
||||||
|
SseEmitter emitter = emitters.remove(connectionId);
|
||||||
|
if (emitter != null) {
|
||||||
|
try {
|
||||||
|
emitter.complete();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 忽略
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boatTrackService.unregisterTelemetryCallback(deviceSn, connectionId);
|
||||||
|
return emitter != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+128
@@ -0,0 +1,128 @@
|
|||||||
|
package com.central.device.controller;
|
||||||
|
|
||||||
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
import com.central.device.model.IotCard;
|
||||||
|
import com.central.device.service.IIotCardService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameters;
|
||||||
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物联网卡管理
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-03-27
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/iot-card")
|
||||||
|
@Tag(name = "物联网卡管理")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class IotCardController {
|
||||||
|
|
||||||
|
private final IIotCardService iotCardService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页列表
|
||||||
|
*/
|
||||||
|
@Operation(summary = "查询物联网卡列表")
|
||||||
|
@Parameters({
|
||||||
|
@Parameter(name = "page", description = "页码", required = true, in = ParameterIn.QUERY),
|
||||||
|
@Parameter(name = "limit", description = "每页条数", required = true, in = ParameterIn.QUERY),
|
||||||
|
@Parameter(name = "cardNumber", description = "卡号", in = ParameterIn.QUERY),
|
||||||
|
@Parameter(name = "deviceSn", description = "设备SN", in = ParameterIn.QUERY),
|
||||||
|
@Parameter(name = "enabled", description = "启用状态", in = ParameterIn.QUERY),
|
||||||
|
@Parameter(name = "carrier", description = "运营商", in = ParameterIn.QUERY)
|
||||||
|
})
|
||||||
|
@GetMapping
|
||||||
|
public PageResult<IotCard> list(@RequestParam Map<String, Object> params) {
|
||||||
|
return iotCardService.findList(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
@Operation(summary = "查询物联网卡详情")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public Result<IotCard> findById(@PathVariable Long id) {
|
||||||
|
IotCard model = iotCardService.getById(id);
|
||||||
|
return Result.succeed(model, "查询成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或更新
|
||||||
|
*/
|
||||||
|
@Operation(summary = "新增/更新物联网卡")
|
||||||
|
@PostMapping
|
||||||
|
public Result<String> save(@RequestBody IotCard iotCard) {
|
||||||
|
// 新增时校验卡号唯一
|
||||||
|
if (iotCard.getId() == null && iotCard.getCardNumber() != null) {
|
||||||
|
if (iotCardService.checkCardNumberExists(iotCard.getCardNumber())) {
|
||||||
|
return Result.failed("卡号已存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iotCardService.saveOrUpdate(iotCard);
|
||||||
|
return Result.succeed("保存成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@Operation(summary = "删除物联网卡")
|
||||||
|
@Parameter(name = "id", description = "物联网卡ID", in = ParameterIn.PATH, required = true)
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public Result<String> delete(@PathVariable Long id) {
|
||||||
|
iotCardService.removeById(id);
|
||||||
|
return Result.succeed("删除成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定设备
|
||||||
|
*/
|
||||||
|
@Operation(summary = "绑定设备")
|
||||||
|
@PostMapping("/{id}/bind")
|
||||||
|
public Result<String> bindDevice(@PathVariable Long id, @RequestParam String deviceSn) {
|
||||||
|
try {
|
||||||
|
boolean result = iotCardService.bindDevice(id, deviceSn);
|
||||||
|
return result ? Result.succeed("绑定成功") : Result.failed("绑定失败");
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return Result.failed(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解绑设备
|
||||||
|
*/
|
||||||
|
@Operation(summary = "解绑设备")
|
||||||
|
@PostMapping("/{id}/unbind")
|
||||||
|
public Result<String> unbindDevice(@PathVariable Long id) {
|
||||||
|
try {
|
||||||
|
boolean result = iotCardService.unbindDevice(id);
|
||||||
|
return result ? Result.succeed("解绑成功") : Result.failed("解绑失败");
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return Result.failed(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用/停用
|
||||||
|
*/
|
||||||
|
@Operation(summary = "启用/停用物联网卡")
|
||||||
|
@PutMapping("/{id}/toggle")
|
||||||
|
public Result<String> toggleEnabled(@PathVariable Long id, @RequestParam Integer enabled) {
|
||||||
|
try {
|
||||||
|
boolean result = iotCardService.toggleEnabled(id, enabled);
|
||||||
|
return result ? Result.succeed("操作成功") : Result.failed("操作失败");
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return Result.failed(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -185,6 +185,12 @@ public class BoatRoute implements Serializable {
|
|||||||
@TableField(value = "create_by", fill = FieldFill.INSERT)
|
@TableField(value = "create_by", fill = FieldFill.INSERT)
|
||||||
private String createBy;
|
private String createBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 航线JSON文件URL(S3)
|
||||||
|
*/
|
||||||
|
@TableField("route_file_url")
|
||||||
|
private String routeFileUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除标记
|
* 删除标记
|
||||||
*/
|
*/
|
||||||
|
|||||||
+9
@@ -73,6 +73,15 @@ public interface FileCenterService {
|
|||||||
@RequestParam(value = "batchSize", defaultValue = "100") int batchSize,
|
@RequestParam(value = "batchSize", defaultValue = "100") int batchSize,
|
||||||
@RequestParam(value = "area", required = false) String area);
|
@RequestParam(value = "area", required = false) String area);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件到S3存储
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return 文件信息(含CDN URL)
|
||||||
|
*/
|
||||||
|
@PostMapping(value = "/files-S3", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
FileInfo uploadForS3(@RequestPart("file") MultipartFile file);
|
||||||
|
|
||||||
// ========== 3D模型文件上传相关接口 ==========
|
// ========== 3D模型文件上传相关接口 ==========
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+6
@@ -74,6 +74,12 @@ public class FileCenterServiceFallbackFactory implements FallbackFactory<FileCen
|
|||||||
return Result.failed("CDN批量预热文件失败: " + cause.getMessage());
|
return Result.failed("CDN批量预热文件失败: " + cause.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileInfo uploadForS3(MultipartFile file) {
|
||||||
|
log.error("上传文件到S3失败: fileName={}", file != null ? file.getOriginalFilename() : "null", cause);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// ========== 3D模型文件上传相关接口 ==========
|
// ========== 3D模型文件上传相关接口 ==========
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.central.device.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.central.db.mapper.SuperMapper;
|
||||||
|
import com.central.device.model.IotCard;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物联网卡数据访问层
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-03-27
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface IotCardMapper extends SuperMapper<IotCard> {
|
||||||
|
/**
|
||||||
|
* 分页查询物联网卡列表
|
||||||
|
*
|
||||||
|
* @param page 分页参数
|
||||||
|
* @param params 查询条件
|
||||||
|
* @return 物联网卡列表
|
||||||
|
*/
|
||||||
|
List<IotCard> findList(Page<IotCard> page, @Param("p") Map<String, Object> params);
|
||||||
|
}
|
||||||
@@ -39,7 +39,7 @@ public class AgeDevice extends SuperEntity {
|
|||||||
private Date createTime;
|
private Date createTime;
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
private Date updateTime;
|
private Date updateTime;
|
||||||
private Long boundTime;
|
private Date boundTime;
|
||||||
private Integer boundStatus;
|
private Integer boundStatus;
|
||||||
private Long loginTime;
|
private Long loginTime;
|
||||||
private String deviceDesc;
|
private String deviceDesc;
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package com.central.device.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.central.common.model.SuperEntity;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物联网卡实体
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-03-27
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("iot_card")
|
||||||
|
public class IotCard extends SuperEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 卡号(ICCID)
|
||||||
|
*/
|
||||||
|
private String cardNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MSISDN号码(手机号)
|
||||||
|
*/
|
||||||
|
private String msisdn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IMSI号码
|
||||||
|
*/
|
||||||
|
private String imsi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运营商:1-中国移动,2-中国联通,3-中国电信
|
||||||
|
*/
|
||||||
|
private Integer carrier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐类型/流量套餐描述
|
||||||
|
*/
|
||||||
|
private String packageType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用状态:0-停用,1-启用
|
||||||
|
*/
|
||||||
|
private Integer enabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定设备SN
|
||||||
|
*/
|
||||||
|
private String deviceSn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定设备名称(冗余字段,方便展示)
|
||||||
|
*/
|
||||||
|
private String deviceName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private Date activationTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 到期时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private Date expirationTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属租户ID
|
||||||
|
*/
|
||||||
|
private String tenantId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 逻辑删除:0-未删除,1-已删除
|
||||||
|
*/
|
||||||
|
@TableLogic
|
||||||
|
private Integer isDel;
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package com.central.device.model.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备状态DTO
|
||||||
|
* deviceStatus: 0-在线,1-离线
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DeviceStatusDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备SN
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "设备SN不能为空")
|
||||||
|
private String deviceSn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备状态(0-在线,1-离线)
|
||||||
|
*/
|
||||||
|
@NotNull(message = "设备状态不能为空")
|
||||||
|
@Min(value = 0, message = "设备状态值无效,0-在线,1-离线")
|
||||||
|
@Max(value = 1, message = "设备状态值无效,0-在线,1-离线")
|
||||||
|
private Integer deviceStatus;
|
||||||
|
}
|
||||||
+3
@@ -83,6 +83,9 @@ public class BoatRouteDetailVO {
|
|||||||
@Schema(description = "备注")
|
@Schema(description = "备注")
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
|
@Schema(description = "航线JSON文件URL")
|
||||||
|
private String routeFileUrl;
|
||||||
|
|
||||||
@Schema(description = "航点列表")
|
@Schema(description = "航点列表")
|
||||||
private List<BoatWaypointVO> waypoints;
|
private List<BoatWaypointVO> waypoints;
|
||||||
|
|
||||||
|
|||||||
+3
@@ -55,6 +55,9 @@ public class BoatRouteListVO {
|
|||||||
@Schema(description = "规划水域边界ID")
|
@Schema(description = "规划水域边界ID")
|
||||||
private String boundaryId;
|
private String boundaryId;
|
||||||
|
|
||||||
|
@Schema(description = "航线JSON文件URL")
|
||||||
|
private String routeFileUrl;
|
||||||
|
|
||||||
@Schema(description = "创建时间")
|
@Schema(description = "创建时间")
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
}
|
}
|
||||||
|
|||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
package com.central.device.service;
|
||||||
|
|
||||||
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.service.ISuperService;
|
||||||
|
import com.central.device.model.IotCard;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物联网卡服务接口
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-03-27
|
||||||
|
*/
|
||||||
|
public interface IIotCardService extends ISuperService<IotCard> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询物联网卡列表
|
||||||
|
*
|
||||||
|
* @param params 查询条件(page、limit、cardNumber、deviceSn、enabled 等)
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
|
PageResult<IotCard> findList(Map<String, Object> params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据卡号查询物联网卡
|
||||||
|
*
|
||||||
|
* @param cardNumber 卡号
|
||||||
|
* @return 物联网卡
|
||||||
|
*/
|
||||||
|
IotCard getByCardNumber(String cardNumber);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查卡号是否已存在
|
||||||
|
*
|
||||||
|
* @param cardNumber 卡号
|
||||||
|
* @return 是否存在
|
||||||
|
*/
|
||||||
|
boolean checkCardNumberExists(String cardNumber);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定设备
|
||||||
|
*
|
||||||
|
* @param id 物联网卡ID
|
||||||
|
* @param deviceSn 设备SN
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean bindDevice(Long id, String deviceSn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解绑设备
|
||||||
|
*
|
||||||
|
* @param id 物联网卡ID
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean unbindDevice(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用/停用物联网卡
|
||||||
|
*
|
||||||
|
* @param id 物联网卡ID
|
||||||
|
* @param enabled 启用状态:0-停用,1-启用
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean toggleEnabled(Long id, Integer enabled);
|
||||||
|
}
|
||||||
+99
@@ -9,6 +9,7 @@ import com.central.common.context.LoginUserContextHolder;
|
|||||||
import com.central.common.exception.BusinessException;
|
import com.central.common.exception.BusinessException;
|
||||||
import com.central.device.entity.BoatRoute;
|
import com.central.device.entity.BoatRoute;
|
||||||
import com.central.device.entity.BoatWaypoint;
|
import com.central.device.entity.BoatWaypoint;
|
||||||
|
import com.central.device.feign.FileCenterService;
|
||||||
import com.central.device.mapper.BoatRouteMapper;
|
import com.central.device.mapper.BoatRouteMapper;
|
||||||
import com.central.device.mapper.BoatWaypointMapper;
|
import com.central.device.mapper.BoatWaypointMapper;
|
||||||
import com.central.device.model.dto.BoatRouteCreateDTO;
|
import com.central.device.model.dto.BoatRouteCreateDTO;
|
||||||
@@ -18,11 +19,20 @@ import com.central.device.model.dto.PointDTO;
|
|||||||
import com.central.device.model.vo.*;
|
import com.central.device.model.vo.*;
|
||||||
import com.central.device.service.IBoatRouteService;
|
import com.central.device.service.IBoatRouteService;
|
||||||
import com.central.device.service.IWaterBoundaryService;
|
import com.central.device.service.IWaterBoundaryService;
|
||||||
|
import com.central.common.model.FileInfo;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -44,6 +54,7 @@ public class BoatRouteServiceImpl extends ServiceImpl<BoatRouteMapper, BoatRoute
|
|||||||
|
|
||||||
private final BoatWaypointMapper waypointMapper;
|
private final BoatWaypointMapper waypointMapper;
|
||||||
private final IWaterBoundaryService waterBoundaryService;
|
private final IWaterBoundaryService waterBoundaryService;
|
||||||
|
private final FileCenterService fileCenterService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@@ -207,6 +218,10 @@ public class BoatRouteServiceImpl extends ServiceImpl<BoatRouteMapper, BoatRoute
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.updateById(route);
|
this.updateById(route);
|
||||||
|
// 已发布航线更新后重新生成并上传JSON文件
|
||||||
|
if (BoatRoute.RouteStatus.PUBLISHED.getCode().equals(route.getStatus())) {
|
||||||
|
generateAndUploadRouteJson(routeId);
|
||||||
|
}
|
||||||
log.info("航线更新成功: routeId={}", routeId);
|
log.info("航线更新成功: routeId={}", routeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,6 +487,8 @@ public class BoatRouteServiceImpl extends ServiceImpl<BoatRouteMapper, BoatRoute
|
|||||||
throw new BusinessException("只有草稿状态的航线才能发布");
|
throw new BusinessException("只有草稿状态的航线才能发布");
|
||||||
}
|
}
|
||||||
updateStatus(routeId, BoatRoute.RouteStatus.PUBLISHED.getCode());
|
updateStatus(routeId, BoatRoute.RouteStatus.PUBLISHED.getCode());
|
||||||
|
// 发布时生成航线JSON文件并上传到S3
|
||||||
|
generateAndUploadRouteJson(routeId);
|
||||||
log.info("航线发布成功: routeId={}", routeId);
|
log.info("航线发布成功: routeId={}", routeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,4 +578,86 @@ public class BoatRouteServiceImpl extends ServiceImpl<BoatRouteMapper, BoatRoute
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成航线JSON文件并上传到S3,将返回的URL存入航线表
|
||||||
|
*/
|
||||||
|
private void generateAndUploadRouteJson(String routeId) {
|
||||||
|
try {
|
||||||
|
// 1. 获取航线详情(含航点)
|
||||||
|
BoatRouteDetailVO detail = getRouteDetail(routeId);
|
||||||
|
|
||||||
|
// 2. 序列化为JSON
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.registerModule(new JavaTimeModule());
|
||||||
|
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||||
|
byte[] jsonBytes = objectMapper.writerWithDefaultPrettyPrinter()
|
||||||
|
.writeValueAsBytes(detail);
|
||||||
|
|
||||||
|
// 3. 构造MultipartFile
|
||||||
|
String fileName = "route_" + routeId + ".json";
|
||||||
|
MultipartFile multipartFile = new InMemoryMultipartFile(
|
||||||
|
"file", fileName, "application/json", jsonBytes);
|
||||||
|
// 4. 通过Feign上传到S3
|
||||||
|
FileInfo fileInfo = fileCenterService.uploadForS3(multipartFile);
|
||||||
|
if (fileInfo == null || fileInfo.getUrl() == null) {
|
||||||
|
log.warn("航线JSON上传S3返回为空: routeId={}", routeId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 将URL存入航线表
|
||||||
|
BoatRoute route = getByRouteId(routeId);
|
||||||
|
if (route != null) {
|
||||||
|
route.setRouteFileUrl(fileInfo.getUrl());
|
||||||
|
this.updateById(route);
|
||||||
|
log.info("航线JSON文件上传成功: routeId={}, url={}", routeId, fileInfo.getUrl());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 上传失败不影响主流程,仅记录日志
|
||||||
|
log.error("航线JSON文件生成或上传失败: routeId={}", routeId, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内存MultipartFile实现,用于将字节数组包装为MultipartFile通过Feign上传
|
||||||
|
*/
|
||||||
|
private static class InMemoryMultipartFile implements MultipartFile {
|
||||||
|
private final String name;
|
||||||
|
private final String originalFilename;
|
||||||
|
private final String contentType;
|
||||||
|
private final byte[] content;
|
||||||
|
|
||||||
|
InMemoryMultipartFile(String name, String originalFilename, String contentType, byte[] content) {
|
||||||
|
this.name = name;
|
||||||
|
this.originalFilename = originalFilename;
|
||||||
|
this.contentType = contentType;
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() { return name; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOriginalFilename() { return originalFilename; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContentType() { return contentType; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() { return content.length == 0; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSize() { return content.length; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getBytes() { return content; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getInputStream() { return new ByteArrayInputStream(content); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void transferTo(File dest) throws IOException, IllegalStateException {
|
||||||
|
java.nio.file.Files.write(dest.toPath(), content);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+121
@@ -0,0 +1,121 @@
|
|||||||
|
package com.central.device.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.central.common.feign.UserService;
|
||||||
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.service.impl.SuperServiceImpl;
|
||||||
|
import com.central.device.mapper.IotCardMapper;
|
||||||
|
import com.central.device.model.AgeDevice;
|
||||||
|
import com.central.device.model.IotCard;
|
||||||
|
import com.central.device.service.IAgeDeviceService;
|
||||||
|
import com.central.device.service.IIotCardService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.MapUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物联网卡服务实现
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-03-27
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class IotCardServiceImpl extends SuperServiceImpl<IotCardMapper, IotCard> implements IIotCardService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userCenterService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IAgeDeviceService ageDeviceService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<IotCard> findList(Map<String, Object> params) {
|
||||||
|
Page<IotCard> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||||
|
String anchor = MapUtils.getString(params, "tenantId");
|
||||||
|
try {
|
||||||
|
if (anchor == null || anchor.isEmpty()) {
|
||||||
|
anchor = com.central.common.context.TenantQueryOverrideContext.getTenantId();
|
||||||
|
if (anchor == null || anchor.isEmpty()) {
|
||||||
|
anchor = com.central.common.context.LoginUserContextHolder.getCurrentTenantId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
log.error("获取当前登录用户租户失败");
|
||||||
|
}
|
||||||
|
List<String> tenantIds = userCenterService.getSonTenantIds(anchor);
|
||||||
|
params.put("tenantIds", tenantIds);
|
||||||
|
List<IotCard> list = baseMapper.findList(page, params);
|
||||||
|
return PageResult.<IotCard>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IotCard getByCardNumber(String cardNumber) {
|
||||||
|
return this.getOne(new QueryWrapper<IotCard>().eq("card_number", cardNumber).eq("is_del", 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkCardNumberExists(String cardNumber) {
|
||||||
|
return this.baseMapper.exists(new QueryWrapper<IotCard>().eq("card_number", cardNumber).eq("is_del", 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean bindDevice(Long id, String deviceSn) {
|
||||||
|
IotCard card = this.getById(id);
|
||||||
|
if (card == null) {
|
||||||
|
throw new IllegalArgumentException("物联网卡不存在");
|
||||||
|
}
|
||||||
|
// 查询设备信息,回填设备名称
|
||||||
|
AgeDevice device = ageDeviceService.getByDeviceSn(deviceSn);
|
||||||
|
card.setDeviceSn(deviceSn);
|
||||||
|
card.setDeviceName(device != null ? device.getDeviceName() : null);
|
||||||
|
boolean result = this.updateById(card);
|
||||||
|
if (result) {
|
||||||
|
log.info("物联网卡绑定设备成功: cardNumber={}, deviceSn={}", card.getCardNumber(), deviceSn);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean unbindDevice(Long id) {
|
||||||
|
IotCard card = this.getById(id);
|
||||||
|
if (card == null) {
|
||||||
|
throw new IllegalArgumentException("物联网卡不存在");
|
||||||
|
}
|
||||||
|
String oldDeviceSn = card.getDeviceSn();
|
||||||
|
// 使用 UpdateWrapper 显式将字段置为 null,避免 MyBatis-Plus 默认策略跳过 null 值
|
||||||
|
boolean result = this.update(
|
||||||
|
new com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper<IotCard>()
|
||||||
|
.set("device_sn", null)
|
||||||
|
.set("device_name", null)
|
||||||
|
.eq("id", id)
|
||||||
|
);
|
||||||
|
if (result) {
|
||||||
|
log.info("物联网卡解绑设备成功: cardNumber={}, oldDeviceSn={}", card.getCardNumber(), oldDeviceSn);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean toggleEnabled(Long id, Integer enabled) {
|
||||||
|
IotCard card = this.getById(id);
|
||||||
|
if (card == null) {
|
||||||
|
throw new IllegalArgumentException("物联网卡不存在");
|
||||||
|
}
|
||||||
|
card.setEnabled(enabled);
|
||||||
|
boolean result = this.updateById(card);
|
||||||
|
if (result) {
|
||||||
|
log.info("物联网卡状态变更: cardNumber={}, enabled={}", card.getCardNumber(), enabled);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -113,3 +113,10 @@ sse:
|
|||||||
heartbeat:
|
heartbeat:
|
||||||
enabled: true
|
enabled: true
|
||||||
interval: 30000 # 心跳间隔(ms)
|
interval: 30000 # 心跳间隔(ms)
|
||||||
|
|
||||||
|
# 客户端接口放行(无需认证)
|
||||||
|
zlt:
|
||||||
|
security:
|
||||||
|
ignore:
|
||||||
|
httpUrls:
|
||||||
|
- /client/**
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
|
||||||
|
<mapper namespace="com.central.device.mapper.IotCardMapper">
|
||||||
|
<select id="findList" resultType="com.central.device.model.IotCard">
|
||||||
|
select * from iot_card t where t.is_del = 0
|
||||||
|
<if test="p.cardNumber != null and p.cardNumber != ''">
|
||||||
|
and t.card_number like concat('%', #{p.cardNumber}, '%')
|
||||||
|
</if>
|
||||||
|
<if test="p.msisdn != null and p.msisdn != ''">
|
||||||
|
and t.msisdn like concat('%', #{p.msisdn}, '%')
|
||||||
|
</if>
|
||||||
|
<if test="p.deviceSn != null and p.deviceSn != ''">
|
||||||
|
and t.device_sn = #{p.deviceSn}
|
||||||
|
</if>
|
||||||
|
<if test="p.enabled != null and p.enabled != ''">
|
||||||
|
and t.enabled = #{p.enabled}
|
||||||
|
</if>
|
||||||
|
<if test="p.carrier != null and p.carrier != ''">
|
||||||
|
and t.carrier = #{p.carrier}
|
||||||
|
</if>
|
||||||
|
<if test="p.tenantIds != null and p.tenantIds.size > 0">
|
||||||
|
AND t.tenant_id IN
|
||||||
|
<foreach collection="p.tenantIds" item="tid" open="(" separator="," close=")">
|
||||||
|
#{tid}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
order by t.id desc
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
-- 物联网卡管理表
|
||||||
|
-- 使用前请确认目标数据库
|
||||||
|
CREATE TABLE IF NOT EXISTS `iot_card` (
|
||||||
|
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||||
|
`card_number` VARCHAR(32) NOT NULL COMMENT '卡号(ICCID)',
|
||||||
|
`msisdn` VARCHAR(20) DEFAULT NULL COMMENT 'MSISDN号码(手机号)',
|
||||||
|
`imsi` VARCHAR(20) DEFAULT NULL COMMENT 'IMSI号码',
|
||||||
|
`carrier` TINYINT DEFAULT NULL COMMENT '运营商:1-中国移动,2-中国联通,3-中国电信',
|
||||||
|
`package_type` VARCHAR(100) DEFAULT NULL COMMENT '套餐类型/流量套餐描述',
|
||||||
|
`enabled` TINYINT NOT NULL DEFAULT 1 COMMENT '启用状态:0-停用,1-启用',
|
||||||
|
`device_sn` VARCHAR(64) DEFAULT NULL COMMENT '绑定设备SN',
|
||||||
|
`device_name` VARCHAR(128) DEFAULT NULL COMMENT '绑定设备名称',
|
||||||
|
`activation_time` DATETIME DEFAULT NULL COMMENT '激活时间',
|
||||||
|
`expiration_time` DATETIME DEFAULT NULL COMMENT '到期时间',
|
||||||
|
`tenant_id` VARCHAR(32) DEFAULT NULL COMMENT '所属租户ID',
|
||||||
|
`remark` VARCHAR(500) DEFAULT NULL COMMENT '备注',
|
||||||
|
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`is_del` TINYINT NOT NULL DEFAULT 0 COMMENT '逻辑删除:0-未删除,1-已删除',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `uk_card_number` (`card_number`),
|
||||||
|
KEY `idx_device_sn` (`device_sn`),
|
||||||
|
KEY `idx_tenant_id` (`tenant_id`),
|
||||||
|
KEY `idx_enabled` (`enabled`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='物联网卡管理表';
|
||||||
@@ -16,7 +16,8 @@ ALTER TABLE `3d_model_file`
|
|||||||
ADD COLUMN `device_name` VARCHAR(100) DEFAULT NULL COMMENT '关联设备名称'
|
ADD COLUMN `device_name` VARCHAR(100) DEFAULT NULL COMMENT '关联设备名称'
|
||||||
AFTER `device_sn`;
|
AFTER `device_sn`;
|
||||||
|
|
||||||
ALTER TABLE `3d_model_file`
|
ALTER TABLE `3d_model_file` ADD INDEX `idx_device_sn` (`device_sn`);
|
||||||
ADD INDEX `idx_device_sn` (`device_sn`);
|
|
||||||
|
ALTER TABLE boat_route ADD COLUMN route_file_url VARCHAR(512) DEFAULT NULL COMMENT '航线JSON文件URL(S3)' AFTER remark;
|
||||||
|
|
||||||
--
|
--
|
||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
package com.central.order.controller;
|
||||||
|
|
||||||
|
import com.central.common.context.LoginUserContextHolder;
|
||||||
|
import com.central.common.model.LoginAppUser;
|
||||||
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
import com.central.order.model.OrderFavorite;
|
||||||
|
import com.central.order.service.IOrderFavoriteService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameters;
|
||||||
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单收藏
|
||||||
|
*
|
||||||
|
* @author dzc
|
||||||
|
* @date 2026-03-10
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@Tag(name = "订单收藏管理")
|
||||||
|
@RequestMapping("/order/favorite")
|
||||||
|
public class OrderFavoriteController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IOrderFavoriteService orderFavoriteService;
|
||||||
|
|
||||||
|
@Operation(summary = "我的收藏列表")
|
||||||
|
@Parameters({
|
||||||
|
@Parameter(name = "page", description = "分页起始位置", required = true, in = ParameterIn.QUERY),
|
||||||
|
@Parameter(name = "limit", description = "每页条数", required = true, in = ParameterIn.QUERY)
|
||||||
|
})
|
||||||
|
@GetMapping
|
||||||
|
public PageResult<OrderFavorite> list(@RequestParam Map<String, Object> params) {
|
||||||
|
return orderFavoriteService.findList(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "收藏/取消收藏订单")
|
||||||
|
@GetMapping("/{orderNo}")
|
||||||
|
public Result toggle(@PathVariable String orderNo) {
|
||||||
|
return orderFavoriteService.toggleFavorite(orderNo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "查询订单是否已收藏")
|
||||||
|
@GetMapping("/{orderNo}/status")
|
||||||
|
public Result<Boolean> isFavorited(@PathVariable String orderNo) {
|
||||||
|
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||||
|
if (user == null) {
|
||||||
|
return Result.failed("请先登录");
|
||||||
|
}
|
||||||
|
boolean favorited = orderFavoriteService.isFavorited(user.getId(), orderNo);
|
||||||
|
return Result.succeed(favorited, "查询成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "取消收藏")
|
||||||
|
@DeleteMapping("/{orderNo}")
|
||||||
|
public Result remove(@PathVariable String orderNo) {
|
||||||
|
return orderFavoriteService.toggleFavorite(orderNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package com.central.order.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.central.db.mapper.SuperMapper;
|
||||||
|
import com.central.order.model.OrderFavorite;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单收藏
|
||||||
|
*
|
||||||
|
* @author dzc
|
||||||
|
* @date 2026-03-10
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface OrderFavoriteMapper extends SuperMapper<OrderFavorite> {
|
||||||
|
|
||||||
|
List<OrderFavorite> findList(Page<OrderFavorite> page, @Param("p") Map<String, Object> params);
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.central.order.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频剪辑模板 clips 参数配置
|
||||||
|
* 存储在 VideoTemplate.config JSON 字段中
|
||||||
|
*
|
||||||
|
* JSON格式示例:
|
||||||
|
* [
|
||||||
|
* {"slot": "1", "fileIndex": 4},
|
||||||
|
* {"slot": "2", "fileIndex": 5}
|
||||||
|
* ]
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ClipsConfig {
|
||||||
|
|
||||||
|
/** 槽位映射列表 */
|
||||||
|
private List<ClipMapping> mappings;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class ClipMapping {
|
||||||
|
/** 阿里云模板槽位号, 如 "1", "201" */
|
||||||
|
private String slot;
|
||||||
|
/** 对应 videoFiles 列表的序号(从0开始) */
|
||||||
|
private Integer fileIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,5 +65,9 @@ public class Order extends SuperEntity {
|
|||||||
@Schema(description = "排队位置(第几位)")
|
@Schema(description = "排队位置(第几位)")
|
||||||
private transient Integer queuePosition;
|
private transient Integer queuePosition;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
@Schema(description = "是否已收藏(0:未收藏,1:已收藏)")
|
||||||
|
private Integer favorited;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.central.order.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.central.common.model.SuperEntity;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单收藏
|
||||||
|
*
|
||||||
|
* @author dzc
|
||||||
|
* @date 2026-03-10
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("order_favorite")
|
||||||
|
public class OrderFavorite extends SuperEntity {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
private Long orderId;
|
||||||
|
|
||||||
|
private String orderNo;
|
||||||
|
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
private String tenantId;
|
||||||
|
private String company;
|
||||||
|
|
||||||
|
// ===== 订单详情(非数据库字段) =====
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String deviceSn;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Long tourismId;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String tourismName;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String orderAmount;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Integer orderStatus;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Integer payType;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Date payTime;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Date orderCreateTime;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Long orderUserId;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String phone;
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package com.central.order.service;
|
||||||
|
|
||||||
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
import com.central.common.service.ISuperService;
|
||||||
|
import com.central.order.model.OrderFavorite;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单收藏
|
||||||
|
*
|
||||||
|
* @author dzc
|
||||||
|
* @date 2026-03-10
|
||||||
|
*/
|
||||||
|
public interface IOrderFavoriteService extends ISuperService<OrderFavorite> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收藏列表(当前用户)
|
||||||
|
*/
|
||||||
|
PageResult<OrderFavorite> findList(Map<String, Object> params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收藏/取消收藏
|
||||||
|
*/
|
||||||
|
Result toggleFavorite(String orderNo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否已收藏
|
||||||
|
*/
|
||||||
|
boolean isFavorited(Long userId, String orderNo);
|
||||||
|
}
|
||||||
+5
@@ -37,4 +37,9 @@ public interface IVideoTemplateService extends ISuperService<VideoTemplate> {
|
|||||||
* 获取可用模板
|
* 获取可用模板
|
||||||
*/
|
*/
|
||||||
VideoTemplate getActiveTemplate();
|
VideoTemplate getActiveTemplate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据阿里云模板ID查询模板
|
||||||
|
*/
|
||||||
|
VideoTemplate getByTemplateId(String templateId);
|
||||||
}
|
}
|
||||||
+93
-13
@@ -7,15 +7,11 @@ import com.aliyun.sdk.service.ice20201109.models.GetMediaProducingJobResponse;
|
|||||||
import com.aliyun.sdk.service.ice20201109.models.SubmitMediaProducingJobRequest;
|
import com.aliyun.sdk.service.ice20201109.models.SubmitMediaProducingJobRequest;
|
||||||
import com.aliyun.sdk.service.ice20201109.models.SubmitMediaProducingJobResponse;
|
import com.aliyun.sdk.service.ice20201109.models.SubmitMediaProducingJobResponse;
|
||||||
import com.central.common.exception.BusinessException;
|
import com.central.common.exception.BusinessException;
|
||||||
|
import com.central.common.utils.StringUtils;
|
||||||
import com.central.order.config.AliyunImsConfig;
|
import com.central.order.config.AliyunImsConfig;
|
||||||
import com.central.order.feign.FileCenterService;
|
import com.central.order.feign.FileCenterService;
|
||||||
import com.central.order.model.Order;
|
import com.central.order.model.*;
|
||||||
import com.central.order.model.OrderFile;
|
import com.central.order.service.*;
|
||||||
import com.central.order.model.QrCode;
|
|
||||||
import com.central.order.service.IMediaService;
|
|
||||||
import com.central.order.service.IOrderFileService;
|
|
||||||
import com.central.order.service.IOrderService;
|
|
||||||
import com.central.order.service.IQrCodeService;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -29,6 +25,8 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@@ -51,6 +49,8 @@ public class MediaServiceImpl implements IMediaService {
|
|||||||
private IOrderFileService orderFileService;
|
private IOrderFileService orderFileService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private FileCenterService fileCenterService;
|
private FileCenterService fileCenterService;
|
||||||
|
@Autowired
|
||||||
|
private IVideoTemplateService videoTemplateService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String submitEditTask(String orderNo, List<OrderFile> orderFiles) {
|
public String submitEditTask(String orderNo, List<OrderFile> orderFiles) {
|
||||||
@@ -180,13 +180,96 @@ public class MediaServiceImpl implements IMediaService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建剪辑参数
|
* 构建剪辑参数 — 配置优先,默认兜底
|
||||||
*/
|
*/
|
||||||
private String buildClipsParam(TaskSubmitData taskData) {
|
private String buildClipsParam(TaskSubmitData taskData) {
|
||||||
try {
|
try {
|
||||||
|
ClipsConfig config = loadClipsConfig(taskData.getQrCode().getTemplateId());
|
||||||
|
if (config != null && config.getMappings() != null && !config.getMappings().isEmpty()) {
|
||||||
|
log.info("使用模板配置构建clips参数, templateId={}", taskData.getQrCode().getTemplateId());
|
||||||
|
return buildClipsParamFromConfig(taskData.getVideoFiles(), config);
|
||||||
|
}
|
||||||
|
log.info("模板无clips配置, 使用默认逻辑, templateId={}", taskData.getQrCode().getTemplateId());
|
||||||
|
return buildDefaultClipsParam(taskData.getVideoFiles());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException("构建剪辑参数失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从VideoTemplate.config解析ClipsConfig
|
||||||
|
*/
|
||||||
|
private ClipsConfig loadClipsConfig(String templateId) {
|
||||||
|
VideoTemplate template = videoTemplateService.getByTemplateId(templateId);
|
||||||
|
if (template == null || StringUtils.isEmpty(template.getConfig())
|
||||||
|
|| "{}".equals(template.getConfig().trim())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// config 存储的是映射数组,包装为 ClipsConfig 对象
|
||||||
|
List<ClipsConfig.ClipMapping> mappings = JSON.parseArray(template.getConfig(), ClipsConfig.ClipMapping.class);
|
||||||
|
if (mappings == null || mappings.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ClipsConfig config = new ClipsConfig();
|
||||||
|
config.setMappings(mappings);
|
||||||
|
return config;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("解析模板clips配置失败, templateId={}, 将使用默认逻辑", templateId, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基于模板配置构建clips参数
|
||||||
|
* fileIndex 匹配文件路径中的拍照顺序号(如 DJI_20260311104552_0014_V.mp4 中的 0014 → 14)
|
||||||
|
*/
|
||||||
|
private String buildClipsParamFromConfig(List<OrderFile> videoFiles, ClipsConfig config) {
|
||||||
|
Map<String, String> clips = new HashMap<>();
|
||||||
|
for (ClipsConfig.ClipMapping m : config.getMappings()) {
|
||||||
|
clips.put(m.getSlot(), getUrlBySequenceNumber(videoFiles, m.getFileIndex()));
|
||||||
|
}
|
||||||
|
return JSON.toJSONString(clips);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 从文件路径中提取拍照顺序号,如 DJI_20260311104552_0014_V.mp4 → 14 */
|
||||||
|
private static final Pattern SEQUENCE_PATTERN = Pattern.compile("DJI_\\d+_(\\d+)_");
|
||||||
|
|
||||||
|
private int extractSequenceNumber(String filePath) {
|
||||||
|
if (filePath == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// 取文件名部分,避免匹配到目录名中的序号
|
||||||
|
int lastSlash = filePath.lastIndexOf('/');
|
||||||
|
String fileName = (lastSlash >= 0) ? filePath.substring(lastSlash + 1) : filePath;
|
||||||
|
Matcher matcher = SEQUENCE_PATTERN.matcher(fileName);
|
||||||
|
if (matcher.find()) {
|
||||||
|
return Integer.parseInt(matcher.group(1));
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据配置的 fileIndex 匹配素材路径中的拍照顺序号,找到对应文件
|
||||||
|
*/
|
||||||
|
private String getUrlBySequenceNumber(List<OrderFile> videoFiles, int fileIndex) {
|
||||||
|
if (videoFiles == null || videoFiles.isEmpty() || fileIndex < 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
for (OrderFile file : videoFiles) {
|
||||||
|
if (extractSequenceNumber(file.getFilePath()) == fileIndex) {
|
||||||
|
return fileCenterService.getViewUrlByPath(file.getFilePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.warn("未找到拍照顺序号={}的素材文件", fileIndex);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认剪辑参数构建(原有硬编码逻辑,作为兜底)
|
||||||
|
*/
|
||||||
|
private String buildDefaultClipsParam(List<OrderFile> videoFiles) {
|
||||||
Map<String, String> clips = new HashMap<>();
|
Map<String, String> clips = new HashMap<>();
|
||||||
List<OrderFile> videoFiles = taskData.getVideoFiles();
|
|
||||||
//@TODO 后期需要通过模板参数进行动态设置clips参数
|
|
||||||
|
|
||||||
// 保持既有模板顺序;当索引越界或无素材时返回空URL
|
// 保持既有模板顺序;当索引越界或无素材时返回空URL
|
||||||
clips.put("1", getUrlBySafeIndex(videoFiles, 4));
|
clips.put("1", getUrlBySafeIndex(videoFiles, 4));
|
||||||
@@ -208,9 +291,6 @@ public class MediaServiceImpl implements IMediaService {
|
|||||||
clips.put("205", getUrlBySafeIndex(videoFiles, 16));
|
clips.put("205", getUrlBySafeIndex(videoFiles, 16));
|
||||||
}
|
}
|
||||||
return JSON.toJSONString(clips);
|
return JSON.toJSONString(clips);
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BusinessException("构建剪辑参数失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getUrlBySafeIndex(List<OrderFile> videoFiles, int index) {
|
private String getUrlBySafeIndex(List<OrderFile> videoFiles, int index) {
|
||||||
|
|||||||
+123
@@ -0,0 +1,123 @@
|
|||||||
|
package com.central.order.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.central.common.context.LoginUserContextHolder;
|
||||||
|
import com.central.common.feign.UserService;
|
||||||
|
import com.central.common.model.LoginAppUser;
|
||||||
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
import com.central.common.model.SysUser;
|
||||||
|
import com.central.common.service.impl.SuperServiceImpl;
|
||||||
|
import com.central.order.mapper.OrderFavoriteMapper;
|
||||||
|
import com.central.order.model.Order;
|
||||||
|
import com.central.order.model.OrderFavorite;
|
||||||
|
import com.central.order.service.IOrderFavoriteService;
|
||||||
|
import com.central.order.service.IOrderService;
|
||||||
|
import com.central.order.util.StringUtils;
|
||||||
|
import com.central.wechat.entity.WechatConfig;
|
||||||
|
import com.central.wechat.feign.WechatConfigService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.MapUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单收藏
|
||||||
|
*
|
||||||
|
* @author dzc
|
||||||
|
* @date 2026-03-10
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class OrderFavoriteServiceImpl extends SuperServiceImpl<OrderFavoriteMapper, OrderFavorite> implements IOrderFavoriteService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IOrderService orderService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserService userCenterService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WechatConfigService wechatConfigService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<OrderFavorite> findList(Map<String, Object> params) {
|
||||||
|
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||||
|
Page<OrderFavorite> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||||
|
params.put("userId", user.getId());
|
||||||
|
List<OrderFavorite> list = baseMapper.findList(page, params);
|
||||||
|
for(OrderFavorite orderFavorite:list){
|
||||||
|
if(Objects.nonNull(orderFavorite.getOrderUserId())){
|
||||||
|
//获取手机号
|
||||||
|
SysUser orderUser = userCenterService.findUserById(orderFavorite.getOrderUserId());
|
||||||
|
if(Objects.nonNull(orderUser)){
|
||||||
|
orderFavorite.setPhone(orderUser.getMobile());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//获取资金去向
|
||||||
|
if(StringUtil.isNotBlank(orderFavorite.getTenantId())){
|
||||||
|
WechatConfig wechatConfig = wechatConfigService.getConfig("PAY",orderFavorite.getTenantId());
|
||||||
|
if(wechatConfig!=null){
|
||||||
|
orderFavorite.setCompany(wechatConfig.getSubMchName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PageResult.<OrderFavorite>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result toggleFavorite(String orderNo) {
|
||||||
|
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||||
|
if (user == null) {
|
||||||
|
return Result.failed("请先登录");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查订单是否存在
|
||||||
|
Order order = orderService.getOne(
|
||||||
|
new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, orderNo)
|
||||||
|
);
|
||||||
|
if (order == null) {
|
||||||
|
return Result.failed("订单不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询是否已收藏
|
||||||
|
OrderFavorite existing = getOne(
|
||||||
|
new LambdaQueryWrapper<OrderFavorite>()
|
||||||
|
.eq(OrderFavorite::getUserId, user.getId())
|
||||||
|
.eq(OrderFavorite::getOrderNo, orderNo)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (existing != null) {
|
||||||
|
// 已收藏 -> 取消收藏
|
||||||
|
removeById(existing.getId());
|
||||||
|
return Result.succeed("取消收藏成功");
|
||||||
|
} else {
|
||||||
|
// 未收藏 -> 添加收藏
|
||||||
|
OrderFavorite favorite = new OrderFavorite();
|
||||||
|
favorite.setUserId(user.getId());
|
||||||
|
favorite.setOrderId(order.getId());
|
||||||
|
favorite.setOrderNo(orderNo);
|
||||||
|
favorite.setTenantId(order.getTenantId());
|
||||||
|
favorite.setCompany(order.getCompany());
|
||||||
|
save(favorite);
|
||||||
|
return Result.succeed("收藏成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFavorited(Long userId, String orderNo) {
|
||||||
|
return count(
|
||||||
|
new LambdaQueryWrapper<OrderFavorite>()
|
||||||
|
.eq(OrderFavorite::getUserId, userId)
|
||||||
|
.eq(OrderFavorite::getOrderNo, orderNo)
|
||||||
|
) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
@@ -32,6 +32,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Order information
|
* Order information
|
||||||
@@ -76,6 +77,9 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
|||||||
@Autowired
|
@Autowired
|
||||||
private QrCodeMapper qrCodeMapper;
|
private QrCodeMapper qrCodeMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrderFavoriteMapper orderFavoriteMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Lazy
|
@Lazy
|
||||||
private WechatConfigService wechatConfigService;
|
private WechatConfigService wechatConfigService;
|
||||||
@@ -137,7 +141,22 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
|||||||
deviceRankingMap.put(deviceSn, rankMap);
|
deviceRankingMap.put(deviceSn, rankMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 批量查询当前登录用户的收藏订单
|
||||||
|
Set<Long> favoritedOrderIds = Collections.emptySet();
|
||||||
|
com.central.common.model.LoginAppUser currentUser = com.central.common.context.LoginUserContextHolder.getUser();
|
||||||
|
if (currentUser != null) {
|
||||||
|
List<Long> orderIds = list.stream().map(Order::getId).collect(Collectors.toList());
|
||||||
|
if (!orderIds.isEmpty()) {
|
||||||
|
favoritedOrderIds = orderFavoriteMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<OrderFavorite>()
|
||||||
|
.eq(OrderFavorite::getUserId, currentUser.getId())
|
||||||
|
.in(OrderFavorite::getOrderId, orderIds)
|
||||||
|
).stream().map(OrderFavorite::getOrderId).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (Order order : list){
|
for (Order order : list){
|
||||||
|
order.setFavorited(favoritedOrderIds.contains(order.getId()) ? 1 : 0);
|
||||||
SysUser user = userCenterService.findUserById(order.getUserId());
|
SysUser user = userCenterService.findUserById(order.getUserId());
|
||||||
if(Objects.nonNull(user)){
|
if(Objects.nonNull(user)){
|
||||||
order.setMobile(user.getMobile());
|
order.setMobile(user.getMobile());
|
||||||
@@ -331,9 +350,20 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
|||||||
Page<Order> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
Page<Order> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||||
List<Order> list = baseMapper.findListByUser(page, params);
|
List<Order> list = baseMapper.findListByUser(page, params);
|
||||||
if (list != null && !list.isEmpty()) {
|
if (list != null && !list.isEmpty()) {
|
||||||
|
// 批量查询当前用户的收藏订单ID
|
||||||
|
Object userIdObj = params.get("userId");
|
||||||
|
Long userId = (userIdObj instanceof Long) ? (Long) userIdObj : Long.valueOf(userIdObj.toString());
|
||||||
|
List<Long> orderIds = list.stream().map(Order::getId).collect(Collectors.toList());
|
||||||
|
Set<Long> favoritedOrderIds = orderFavoriteMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<OrderFavorite>()
|
||||||
|
.eq(OrderFavorite::getUserId, userId)
|
||||||
|
.in(OrderFavorite::getOrderId, orderIds)
|
||||||
|
).stream().map(OrderFavorite::getOrderId).collect(Collectors.toSet());
|
||||||
|
|
||||||
for (Order order : list) {
|
for (Order order : list) {
|
||||||
order.setTourismName(tourismMapper.getTourismById(order.getTourismId()).getTourismName());
|
order.setTourismName(tourismMapper.getTourismById(order.getTourismId()).getTourismName());
|
||||||
order.setCreatedTime(sdf.format(order.getCreateTime()));
|
order.setCreatedTime(sdf.format(order.getCreateTime()));
|
||||||
|
order.setFavorited(favoritedOrderIds.contains(order.getId()) ? 1 : 0);
|
||||||
// 设置景区订单展示图(type=6)的imageUrl
|
// 设置景区订单展示图(type=6)的imageUrl
|
||||||
List<TourismFile> tourismFiles = tourismFileMapper.selectList(
|
List<TourismFile> tourismFiles = tourismFileMapper.selectList(
|
||||||
new LambdaQueryWrapper<TourismFile>()
|
new LambdaQueryWrapper<TourismFile>()
|
||||||
|
|||||||
+11
@@ -88,4 +88,15 @@ public class VideoTemplateServiceImpl extends SuperServiceImpl<VideoTemplateMapp
|
|||||||
.orderByDesc(VideoTemplate::getCreateTime)
|
.orderByDesc(VideoTemplate::getCreateTime)
|
||||||
.last("LIMIT 1"));
|
.last("LIMIT 1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VideoTemplate getByTemplateId(String templateId) {
|
||||||
|
if (StringUtils.isEmpty(templateId)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return getOne(new LambdaQueryWrapper<VideoTemplate>()
|
||||||
|
.eq(VideoTemplate::getTemplateId, templateId)
|
||||||
|
.eq(VideoTemplate::getIsDel, 0)
|
||||||
|
.last("LIMIT 1"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
|
||||||
|
<mapper namespace="com.central.order.mapper.OrderFavoriteMapper">
|
||||||
|
|
||||||
|
<select id="findList" resultType="com.central.order.model.OrderFavorite">
|
||||||
|
select t.id, t.user_id, t.order_id, t.order_no, t.create_time, qr.tenant_id as tenant_id, t.company,
|
||||||
|
o.device_sn, o.tourism_id, o.order_amount, o.order_status, o.pay_type, o.pay_time,
|
||||||
|
o.create_time as order_create_time, o.user_id as order_user_id,
|
||||||
|
tr.tourism_name as tourism_name
|
||||||
|
from order_favorite t
|
||||||
|
left join orders o on t.order_id = o.id
|
||||||
|
left join tourisms tr on o.tourism_id = tr.id
|
||||||
|
left join qrcodes qr on o.code_id= qr.code_id
|
||||||
|
<where>
|
||||||
|
<if test="p.userId != null">
|
||||||
|
and t.user_id = #{p.userId}
|
||||||
|
</if>
|
||||||
|
<if test="p.orderNo != null and p.orderNo != ''">
|
||||||
|
and t.order_no like concat('%', #{p.orderNo}, '%')
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by t.create_time desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -57,7 +57,8 @@
|
|||||||
|
|
||||||
<!-- 动态获取参数采用备参 -->
|
<!-- 动态获取参数采用备参 -->
|
||||||
<select id="findListByUser" resultType="com.central.order.model.Order">
|
<select id="findListByUser" resultType="com.central.order.model.Order">
|
||||||
select id,order_no,tourism_id,device_sn,workspace_id,code_id,user_id,order_amount,order_status,create_time,update_time from orders t WHERE t.user_id = #{param2.userId}
|
select id,order_no,tourism_id,device_sn,workspace_id,code_id,user_id,order_amount,order_status,create_time,update_time
|
||||||
|
from orders t WHERE t.user_id = #{param2.userId}
|
||||||
and t.is_del = 0
|
and t.is_del = 0
|
||||||
<if test="param2.orderStatusList != null and param2.orderStatusList.size() > 0">
|
<if test="param2.orderStatusList != null and param2.orderStatusList.size() > 0">
|
||||||
and t.order_status in
|
and t.order_status in
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
-- 订单收藏表
|
||||||
|
CREATE TABLE IF NOT EXISTS `order_favorite` (
|
||||||
|
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||||
|
`user_id` bigint(20) NOT NULL COMMENT '用户ID',
|
||||||
|
`order_id` bigint(20) NOT NULL COMMENT '订单ID',
|
||||||
|
`order_no` varchar(64) DEFAULT NULL COMMENT '订单编号',
|
||||||
|
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '收藏时间',
|
||||||
|
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`tenant_id` varchar(64) DEFAULT NULL COMMENT '租户ID',
|
||||||
|
`company` varchar(64) DEFAULT NULL COMMENT '公司',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `uk_user_order` (`user_id`, `order_id`),
|
||||||
|
KEY `idx_user_id` (`user_id`),
|
||||||
|
KEY `idx_order_id` (`order_id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单收藏表';
|
||||||
-2
@@ -22,8 +22,6 @@ public class BannerInitializer implements ApplicationContextInitializer<Configur
|
|||||||
if (!(applicationContext instanceof AnnotationConfigApplicationContext)) {
|
if (!(applicationContext instanceof AnnotationConfigApplicationContext)) {
|
||||||
LogoBanner logoBanner = new LogoBanner(BannerInitializer.class, "/zltmp/logo.txt", "Welcome to zlt", 5, 6, new Color[5], true);
|
LogoBanner logoBanner = new LogoBanner(BannerInitializer.class, "/zltmp/logo.txt", "Welcome to zlt", 5, 6, new Color[5], true);
|
||||||
CustomBanner.show(logoBanner, new Description(BannerConstant.VERSION + ":", CommonConstant.PROJECT_VERSION, 0, 1)
|
CustomBanner.show(logoBanner, new Description(BannerConstant.VERSION + ":", CommonConstant.PROJECT_VERSION, 0, 1)
|
||||||
, new Description("Github:", "https://github.com/zlt2000", 0, 1)
|
|
||||||
, new Description("Blog:", "http://zlt2000.gitee.io", 0, 1)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,685 @@
|
|||||||
|
# 接口文档
|
||||||
|
|
||||||
|
## 1. 用户登录接口
|
||||||
|
|
||||||
|
### 接口信息
|
||||||
|
- **接口名称**: 用户登录
|
||||||
|
- **请求方式**: POST
|
||||||
|
- **接口路径**: `http://localhost:8080/api-uaa/oauth/login`
|
||||||
|
- **接口描述**: 通过OpenID进行用户登录认证,获取访问令牌
|
||||||
|
|
||||||
|
### 请求参数
|
||||||
|
|
||||||
|
#### 请求头
|
||||||
|
```
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 请求体 (JSON)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"grantType": "openId",
|
||||||
|
"clientId": "需要找高飞获取",
|
||||||
|
"deviceId": "11234455",
|
||||||
|
"openId": "需要找高飞获取"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 参数说明
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| grantType | String | 是 | 授权类型,固定值:openId |
|
||||||
|
| clientId | String | 是 | 客户端ID,固定值:xcapp |
|
||||||
|
| deviceId | String | 是 | 设备唯一标识 |
|
||||||
|
| openId | String | 是 | 用户OpenID |
|
||||||
|
|
||||||
|
### 响应结果
|
||||||
|
|
||||||
|
#### 成功响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"access_token": "2OWQBzmKM1h44BLgDQgOKItY-_hj5xP4hlMCqa560krd-6WGWAhFtcrX0Rtt_ussM1rhDl_QUFi-feCSimOehmgcFS9uLxflh5zdSJLDTEdyM5GtXBHqqeBrTOwSDGTQ",
|
||||||
|
"token_type": "Bearer",
|
||||||
|
"expires_in": 3600
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 失败响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "invalid_grant",
|
||||||
|
"error_description": "Invalid openId"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 响应字段说明
|
||||||
|
| 字段名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| access_token | String | 访问令牌,后续请求需要在请求头中携带 |
|
||||||
|
| token_type | String | 令牌类型,固定值:Bearer |
|
||||||
|
| expires_in | Integer | 令牌过期时间(秒) |
|
||||||
|
|
||||||
|
### 业务逻辑
|
||||||
|
1. **参数验证**: 验证请求参数完整性
|
||||||
|
2. **OpenID验证**: 验证OpenID是否有效
|
||||||
|
3. **令牌生成**: 生成访问令牌
|
||||||
|
4. **令牌返回**: 返回访问令牌供后续接口使用
|
||||||
|
|
||||||
|
### 错误码说明
|
||||||
|
| 错误码 | 错误信息 | 说明 |
|
||||||
|
|--------|----------|------|
|
||||||
|
| invalid_grant | Invalid openId | OpenID无效或不存在 |
|
||||||
|
| invalid_client | Invalid clientId | 客户端ID无效 |
|
||||||
|
|
||||||
|
### 使用示例
|
||||||
|
|
||||||
|
#### cURL
|
||||||
|
```bash
|
||||||
|
curl -X POST "http://localhost:8080/api-uaa/oauth/login" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"grantType": "openId",
|
||||||
|
"clientId": "xxx",
|
||||||
|
"deviceId": "11234455",
|
||||||
|
"openId": "xxxx"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
#### JavaScript
|
||||||
|
```javascript
|
||||||
|
const response = await fetch('http://localhost:8080/api-uaa/oauth/login', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
grantType: 'openId',
|
||||||
|
clientId: 'xxxx',
|
||||||
|
deviceId: '11234455',
|
||||||
|
openId: 'xxxxx'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
if (result.access_token) {
|
||||||
|
console.log('登录成功,访问令牌:', result.access_token);
|
||||||
|
// 保存令牌供后续使用
|
||||||
|
localStorage.setItem('access_token', result.access_token);
|
||||||
|
} else {
|
||||||
|
console.error('登录失败:', result.error_description);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 订单创建接口
|
||||||
|
|
||||||
|
### 接口信息
|
||||||
|
- **接口名称**: 创建订单
|
||||||
|
- **请求方式**: POST
|
||||||
|
- **接口路径**: `http://localhost:8080/api-order/orders`
|
||||||
|
- **接口描述**: 用户通过扫描二维码创建订单,系统自动分配租户、设置订单金额等信息
|
||||||
|
|
||||||
|
### 请求参数
|
||||||
|
|
||||||
|
#### 请求头
|
||||||
|
```
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Bearer {access_token}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 请求体 (JSON)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"codeId": "需要找高飞获取",
|
||||||
|
"payType": 3
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 参数说明
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| codeId | String | 是 | 二维码唯一标识 |
|
||||||
|
| payType | Integer | 是 | 支付类型,3表示指定支付方式 |
|
||||||
|
|
||||||
|
### 响应结果
|
||||||
|
|
||||||
|
#### 成功响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 0,
|
||||||
|
"resp_msg": "订单创建成功",
|
||||||
|
"data": {
|
||||||
|
"id": 123,
|
||||||
|
"orderNo": "202501150001",
|
||||||
|
"userId": 456,
|
||||||
|
"tourismId": 789,
|
||||||
|
"deviceSn": "xxxxx",
|
||||||
|
"orderAmount": "5000",
|
||||||
|
"orderStatus": 0,
|
||||||
|
"payType": 3,
|
||||||
|
"codeId": "xxxxx",
|
||||||
|
"tenantId": "tenant_001",
|
||||||
|
"createTime": "2025-01-15T10:30:00Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 失败响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 1,
|
||||||
|
"resp_msg": "已存在订单,请前往订单页确认,请勿重复下单"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 响应字段说明
|
||||||
|
| 字段名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| resp_code | Integer | 响应码,0表示成功,非0表示失败 |
|
||||||
|
| resp_msg | String | 响应消息 |
|
||||||
|
| data | Object | 订单数据(成功时返回) |
|
||||||
|
|
||||||
|
### 业务逻辑
|
||||||
|
1. **用户身份验证**: 验证用户登录状态
|
||||||
|
2. **重复订单检查**: 检查用户是否已有未完成的订单
|
||||||
|
3. **二维码验证**: 验证二维码是否存在且有效
|
||||||
|
4. **租户分配**: 根据二维码ID智能分配租户
|
||||||
|
5. **订单创建**: 设置订单基本信息并保存
|
||||||
|
6. **幂等性保证**: 使用分布式锁确保订单不重复创建
|
||||||
|
|
||||||
|
### 错误码说明
|
||||||
|
| 错误码 | 错误信息 | 说明 |
|
||||||
|
|--------|----------|------|
|
||||||
|
| 1 | 已存在订单,请前往订单页确认,请勿重复下单 | 用户已有未完成订单 |
|
||||||
|
| 1 | 该二维码已过期 | 二维码状态为不可用 |
|
||||||
|
| 1 | 二维码不存在 | 二维码ID无效 |
|
||||||
|
|
||||||
|
### 使用示例
|
||||||
|
|
||||||
|
#### cURL
|
||||||
|
```bash
|
||||||
|
curl -X POST "http://localhost:8080/api-order/orders" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer 2OWQBzmKM1h44BLgDQgOKItY-_hj5xP4hlMCqa560krd-6WGWAhFtcrX0Rtt_ussM1rhDl_QUFi-feCSimOehmgcFS9uLxflh5zdSJLDTEdyM5GtXBHqqeBrTOwSDGTQ" \
|
||||||
|
-d '{
|
||||||
|
"codeId": "xxxxx",
|
||||||
|
"payType": 3
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
#### JavaScript
|
||||||
|
```javascript
|
||||||
|
const accessToken = localStorage.getItem('access_token');
|
||||||
|
const response = await fetch('http://localhost:8080/api-order/orders', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + accessToken
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
codeId: 'xxxxxx',
|
||||||
|
payType: 3
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
if (result.resp_code === 0) {
|
||||||
|
console.log('订单创建成功:', result.data);
|
||||||
|
} else {
|
||||||
|
console.error('订单创建失败:', result.resp_msg);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 获取订单素材接口
|
||||||
|
|
||||||
|
### 接口信息
|
||||||
|
- **接口名称**: 根据订单号查询订单素材
|
||||||
|
- **请求方式**: GET
|
||||||
|
- **接口路径**: `http://localhost:8080/api-order/user/files/{orderNo}`
|
||||||
|
- **接口描述**: 根据订单号获取订单相关的所有素材资源,包括图片、视频、AI生成视频等
|
||||||
|
|
||||||
|
### 请求参数
|
||||||
|
|
||||||
|
#### 路径参数
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| orderNo | String | 是 | 订单编号 |
|
||||||
|
|
||||||
|
#### 请求头
|
||||||
|
```
|
||||||
|
Authorization: Bearer {access_token}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 响应结果
|
||||||
|
|
||||||
|
#### 成功响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 0,
|
||||||
|
"resp_msg": "查询成功",
|
||||||
|
"data": {
|
||||||
|
"time": "2025-01-15 10:30",
|
||||||
|
"addr": "北京市朝阳区某某景区",
|
||||||
|
"orderNo": "202501150001",
|
||||||
|
"aiVideo": "https://cdn.example.com/video/2025/01/15/ai_video_abc123.mp4",
|
||||||
|
"imgList": [
|
||||||
|
{
|
||||||
|
"url": "https://cdn.example.com/picture/2025/01/15/img_001.jpeg",
|
||||||
|
"contentType": "image/jpeg",
|
||||||
|
"path": "picture/2025/01/15/img_001.jpeg",
|
||||||
|
"viewUrl": "https://cdn.example.com/picture/2025/01/15/img_001.jpeg?style=thumbnail"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://cdn.example.com/picture/2025/01/15/img_002.jpeg",
|
||||||
|
"contentType": "image/jpeg",
|
||||||
|
"path": "picture/2025/01/15/img_002.jpeg",
|
||||||
|
"viewUrl": "https://cdn.example.com/picture/2025/01/15/img_002.jpeg?style=thumbnail"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"videoList": [
|
||||||
|
{
|
||||||
|
"url": "https://cdn.example.com/video/2025/01/15/video_001.mp4",
|
||||||
|
"contentType": "video/mp4",
|
||||||
|
"path": "video/2025/01/15/video_001.mp4",
|
||||||
|
"viewUrl": "https://cdn.example.com/picture/2025/01/15/img_001.jpeg?style=thumbnail"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"showVideoEditOnly": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 失败响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 1,
|
||||||
|
"resp_msg": "订单不存在"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 响应字段说明
|
||||||
|
| 字段名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| resp_code | Integer | 响应码,0表示成功,非0表示失败 |
|
||||||
|
| resp_msg | String | 响应消息 |
|
||||||
|
| data | Object | 订单素材数据(成功时返回) |
|
||||||
|
|
||||||
|
#### 素材数据字段说明
|
||||||
|
| 字段名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| time | String | 订单创建时间(格式:yyyy-MM-dd HH:mm) |
|
||||||
|
| addr | String | 景区地址 |
|
||||||
|
| orderNo | String | 订单编号 |
|
||||||
|
| aiVideo | String | AI生成视频的访问地址(可能为null) |
|
||||||
|
| imgList | Array | 图片素材列表 |
|
||||||
|
| videoList | Array | 视频素材列表 |
|
||||||
|
| showVideoEditOnly | Integer | 是否只显示一键成片(0:否,1:是) |
|
||||||
|
|
||||||
|
#### 图片/视频素材字段说明
|
||||||
|
| 字段名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| url | String | 文件访问地址(CDN加速) |
|
||||||
|
| contentType | String | 文件MIME类型 |
|
||||||
|
| path | String | 文件存储路径 |
|
||||||
|
| viewUrl | String | 文件预览地址(图片为缩略图,视频为对应图片缩略图) |
|
||||||
|
|
||||||
|
### 业务逻辑
|
||||||
|
1. **订单验证**: 验证订单号是否存在
|
||||||
|
2. **景区信息获取**: 根据订单获取景区地址信息
|
||||||
|
3. **素材分类查询**: 分别查询图片、视频、AI视频等不同类型的素材
|
||||||
|
4. **URL生成**: 为每个素材生成访问地址和预览地址
|
||||||
|
5. **缩略图关联**: 为视频素材关联对应的图片缩略图
|
||||||
|
6. **功能控制**: 根据二维码设置决定是否返回图片和视频素材
|
||||||
|
|
||||||
|
### 素材类型说明
|
||||||
|
- **AI视频 (aiVideo)**: 系统自动生成的视频,标签为 `ai_video`
|
||||||
|
- **图片素材 (imgList)**: 原始拍摄的图片,文件类型为 `image/jpeg`
|
||||||
|
- **视频素材 (videoList)**: 原始拍摄的视频,标签为 `raw_video`
|
||||||
|
|
||||||
|
### 功能控制说明
|
||||||
|
- **showVideoEditOnly = 1**: 只显示一键成片功能,不返回图片和视频素材
|
||||||
|
- **showVideoEditOnly = 0**: 显示所有功能,返回完整的图片和视频素材
|
||||||
|
|
||||||
|
### 错误码说明
|
||||||
|
| 错误码 | 错误信息 | 说明 |
|
||||||
|
|--------|----------|------|
|
||||||
|
| 1 | 订单不存在 | 订单号无效或订单已被删除 |
|
||||||
|
|
||||||
|
### 使用示例
|
||||||
|
|
||||||
|
#### cURL
|
||||||
|
```bash
|
||||||
|
curl -X GET "http://localhost:8080/api-order/user/files/xxxxxx" \
|
||||||
|
-H "Authorization: Bearer 2OWQBzmKM1h44BLgDQgOKItY-_hj5xP4hlMCqa560krd-6WGWAhFtcrX0Rtt_ussM1rhDl_QUFi-feCSimOehmgcFS9uLxflh5zdSJLDTEdyM5GtXBHqqeBrTOwSDGTQ"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### JavaScript
|
||||||
|
```javascript
|
||||||
|
const accessToken = localStorage.getItem('access_token');
|
||||||
|
const response = await fetch('http://localhost:8080/api-order/user/files/xxxxx', {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + accessToken
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
if (result.resp_code === 0) {
|
||||||
|
const data = result.data;
|
||||||
|
console.log('订单时间:', data.time);
|
||||||
|
console.log('景区地址:', data.addr);
|
||||||
|
console.log('AI视频:', data.aiVideo);
|
||||||
|
console.log('图片数量:', data.imgList.length);
|
||||||
|
console.log('视频数量:', data.videoList.length);
|
||||||
|
|
||||||
|
// 处理图片素材
|
||||||
|
data.imgList.forEach((img, index) => {
|
||||||
|
console.log(`图片${index + 1}:`, img.url);
|
||||||
|
console.log(`缩略图${index + 1}:`, img.viewUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 处理视频素材
|
||||||
|
data.videoList.forEach((video, index) => {
|
||||||
|
console.log(`视频${index + 1}:`, video.url);
|
||||||
|
console.log(`视频缩略图${index + 1}:`, video.viewUrl);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.error('查询失败:', result.resp_msg);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 前端展示示例
|
||||||
|
```javascript
|
||||||
|
function renderOrderResources(orderNo) {
|
||||||
|
const accessToken = localStorage.getItem('access_token');
|
||||||
|
fetch(`http://localhost:8080/api-order/user/files/${orderNo}`, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + accessToken
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(result => {
|
||||||
|
if (result.resp_code === 0) {
|
||||||
|
const data = result.data;
|
||||||
|
|
||||||
|
// 显示基本信息
|
||||||
|
document.getElementById('orderTime').textContent = data.time;
|
||||||
|
document.getElementById('orderAddress').textContent = data.addr;
|
||||||
|
|
||||||
|
// 显示AI视频
|
||||||
|
if (data.aiVideo) {
|
||||||
|
const aiVideoElement = document.getElementById('aiVideo');
|
||||||
|
aiVideoElement.src = data.aiVideo;
|
||||||
|
aiVideoElement.style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示图片列表
|
||||||
|
const imgContainer = document.getElementById('imageList');
|
||||||
|
imgContainer.innerHTML = '';
|
||||||
|
data.imgList.forEach(img => {
|
||||||
|
const imgElement = document.createElement('img');
|
||||||
|
imgElement.src = img.viewUrl; // 使用缩略图
|
||||||
|
imgElement.onclick = () => window.open(img.url); // 点击查看原图
|
||||||
|
imgContainer.appendChild(imgElement);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 显示视频列表
|
||||||
|
const videoContainer = document.getElementById('videoList');
|
||||||
|
videoContainer.innerHTML = '';
|
||||||
|
data.videoList.forEach(video => {
|
||||||
|
const videoElement = document.createElement('div');
|
||||||
|
videoElement.innerHTML = `
|
||||||
|
<video src="${video.url}" controls></video>
|
||||||
|
<img src="${video.viewUrl}" alt="视频缩略图" />
|
||||||
|
`;
|
||||||
|
videoContainer.appendChild(videoElement);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('获取订单素材失败:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 注意事项
|
||||||
|
1. **权限控制**: 只能查询当前用户自己的订单素材
|
||||||
|
2. **素材完整性**: 返回的素材包括订单关联的所有文件
|
||||||
|
3. **CDN加速**: 所有文件地址都经过CDN加速处理
|
||||||
|
4. **缩略图优化**: 图片提供缩略图版本,提升加载性能
|
||||||
|
5. **功能控制**: 根据二维码设置动态控制素材显示
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 获取订单状态接口
|
||||||
|
|
||||||
|
### 接口信息
|
||||||
|
- **接口名称**: 获取订单状态
|
||||||
|
- **请求方式**: GET
|
||||||
|
- **接口路径**: `http://localhost:8080/api-order/order/{orderNo}`
|
||||||
|
- **接口描述**: 根据订单号查询订单的当前状态
|
||||||
|
|
||||||
|
### 请求参数
|
||||||
|
|
||||||
|
#### 路径参数
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| orderNo | String | 是 | 订单编号 |
|
||||||
|
|
||||||
|
#### 请求头
|
||||||
|
```
|
||||||
|
Authorization: Bearer {access_token}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 响应结果
|
||||||
|
|
||||||
|
#### 成功响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 0,
|
||||||
|
"resp_msg": "查询成功",
|
||||||
|
"data": {
|
||||||
|
"id": 123,
|
||||||
|
"orderNo": "xxxxxx",
|
||||||
|
"orderStatus": 4,
|
||||||
|
"statusDesc": "正在服务中",
|
||||||
|
"createTime": "2025-01-15T10:30:00Z",
|
||||||
|
"updateTime": "2025-01-15T10:35:00Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 失败响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 1,
|
||||||
|
"resp_msg": "订单不存在"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 响应字段说明
|
||||||
|
| 字段名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| resp_code | Integer | 响应码,0表示成功,非0表示失败 |
|
||||||
|
| resp_msg | String | 响应消息 |
|
||||||
|
| data | Object | 订单状态数据(成功时返回) |
|
||||||
|
|
||||||
|
#### 订单状态说明
|
||||||
|
| 状态值 | 状态描述 | 说明 |
|
||||||
|
|--------|----------|------|
|
||||||
|
| 3 | 设备执行完成 | 设备已完成服务执行 |
|
||||||
|
| 4 | 正在服务中 | 设备正在提供服务 |
|
||||||
|
| 5 | 素材上传中 | 用户正在上传素材 |
|
||||||
|
| 6 | 素材上传完成 | 素材已全部上传完成 |
|
||||||
|
|
||||||
|
### 业务逻辑
|
||||||
|
1. **参数验证**: 验证订单号格式
|
||||||
|
2. **订单查询**: 根据订单号查询订单信息
|
||||||
|
3. **状态返回**: 返回订单的当前状态和相关信息
|
||||||
|
|
||||||
|
### 错误码说明
|
||||||
|
| 错误码 | 错误信息 | 说明 |
|
||||||
|
|--------|----------|------|
|
||||||
|
| 1 | 订单不存在 | 订单号无效或订单已被删除 |
|
||||||
|
| 1 | 获取订单状态失败 | 系统内部错误 |
|
||||||
|
|
||||||
|
### 使用示例
|
||||||
|
|
||||||
|
#### cURL
|
||||||
|
```bash
|
||||||
|
curl -X GET "http://localhost:8080/api-order/order/202501150001" \
|
||||||
|
-H "Authorization: Bearer 2OWQBzmKM1h44BLgDQgOKItY-_hj5xP4hlMCqa560krd-6WGWAhFtcrX0Rtt_ussM1rhDl_QUFi-feCSimOehmgcFS9uLxflh5zdSJLDTEdyM5GtXBHqqeBrTOwSDGTQ"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### JavaScript
|
||||||
|
```javascript
|
||||||
|
const accessToken = localStorage.getItem('access_token');
|
||||||
|
const response = await fetch('http://localhost:8080/api-order/order/202501150001', {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + accessToken
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
if (result.resp_code === 0) {
|
||||||
|
console.log('订单状态:', result.data);
|
||||||
|
console.log('状态描述:', getStatusDesc(result.data.orderStatus));
|
||||||
|
} else {
|
||||||
|
console.error('查询失败:', result.resp_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStatusDesc(status) {
|
||||||
|
const statusMap = {
|
||||||
|
3: '设备执行完成',
|
||||||
|
4: '正在服务中',
|
||||||
|
5: '素材上传中',
|
||||||
|
6: '素材上传完成'
|
||||||
|
};
|
||||||
|
return statusMap[status] || '未知状态';
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 接口调用流程示例
|
||||||
|
|
||||||
|
### 完整的订单创建流程
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
participant User as 用户
|
||||||
|
participant Frontend as 前端
|
||||||
|
participant LoginAPI as 登录API
|
||||||
|
participant OrderAPI as 订单API
|
||||||
|
|
||||||
|
User->>Frontend: 打开应用
|
||||||
|
Frontend->>LoginAPI: 用户登录
|
||||||
|
LoginAPI-->>Frontend: 返回访问令牌
|
||||||
|
Frontend->>User: 显示登录成功
|
||||||
|
|
||||||
|
User->>Frontend: 扫描二维码
|
||||||
|
Frontend->>OrderAPI: 创建订单
|
||||||
|
OrderAPI-->>Frontend: 返回订单信息
|
||||||
|
Frontend->>User: 显示订单详情
|
||||||
|
|
||||||
|
User->>Frontend: 查看订单状态
|
||||||
|
Frontend->>OrderAPI: 查询订单状态
|
||||||
|
OrderAPI-->>Frontend: 返回订单状态
|
||||||
|
Frontend->>User: 显示状态信息
|
||||||
|
|
||||||
|
User->>Frontend: 查看订单素材
|
||||||
|
Frontend->>OrderAPI: 获取订单素材
|
||||||
|
OrderAPI-->>Frontend: 返回素材列表
|
||||||
|
Frontend->>User: 显示素材内容
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 错误处理建议
|
||||||
|
|
||||||
|
### 1. 网络错误处理
|
||||||
|
```javascript
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, options);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const result = await response.json();
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('请求失败:', error);
|
||||||
|
// 显示用户友好的错误信息
|
||||||
|
showErrorMessage('网络请求失败,请稍后重试');
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 业务错误处理
|
||||||
|
```javascript
|
||||||
|
if (result.resp_code === 0) {
|
||||||
|
// 处理成功响应
|
||||||
|
handleSuccess(result.data);
|
||||||
|
} else {
|
||||||
|
// 处理业务错误
|
||||||
|
handleBusinessError(result.resp_msg);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 令牌过期处理
|
||||||
|
```javascript
|
||||||
|
async function requestWithTokenRefresh(url, options) {
|
||||||
|
let response = await fetch(url, options);
|
||||||
|
|
||||||
|
// 如果返回401,说明令牌过期,需要重新登录
|
||||||
|
if (response.status === 401) {
|
||||||
|
// 清除本地令牌
|
||||||
|
localStorage.removeItem('access_token');
|
||||||
|
// 跳转到登录页面
|
||||||
|
window.location.href = '/login';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 重试机制
|
||||||
|
```javascript
|
||||||
|
async function requestWithRetry(url, options, maxRetries = 3) {
|
||||||
|
for (let i = 0; i < maxRetries; i++) {
|
||||||
|
try {
|
||||||
|
return await fetch(url, options);
|
||||||
|
} catch (error) {
|
||||||
|
if (i === maxRetries - 1) throw error;
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 测试建议
|
||||||
|
|
||||||
|
### 1. 接口测试
|
||||||
|
- 使用Postman或类似工具测试各个接口
|
||||||
|
- 验证参数验证、错误处理等
|
||||||
|
- 测试不同订单状态和场景
|
||||||
|
|
||||||
|
### 2. 集成测试
|
||||||
|
- 测试完整的业务流程
|
||||||
|
- 验证登录、订单创建、状态查询、素材获取的联动
|
||||||
|
- 测试异常情况的处理
|
||||||
|
|
||||||
|
### 3. 性能测试
|
||||||
|
- 测试接口响应时间
|
||||||
|
- 验证并发请求的处理能力
|
||||||
|
- 测试大量素材加载的性能
|
||||||
|
|
||||||
|
### 4. 安全测试
|
||||||
|
- 验证令牌有效性
|
||||||
|
- 测试访问权限控制
|
||||||
|
- 验证订单数据隔离
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
# 设备告警数据接口文档
|
||||||
|
|
||||||
|
## 概述
|
||||||
|
|
||||||
|
本文档描述设备告警数据相关接口,用于获取机库状态数据和无人机遥测数据。
|
||||||
|
|
||||||
|
**基础路径**: `/api-device`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. 获取机库状态数据
|
||||||
|
|
||||||
|
### 接口信息
|
||||||
|
|
||||||
|
| 项目 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| 接口地址 | `/device/alarm/fire-alarm/{deviceSn}` |
|
||||||
|
| 请求方式 | GET |
|
||||||
|
| 接口描述 | 获取机库状态数据 |
|
||||||
|
|
||||||
|
### 请求参数
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| deviceSn | String | 是 | 设备SN(路径参数) |
|
||||||
|
|
||||||
|
### 请求示例
|
||||||
|
|
||||||
|
```
|
||||||
|
GET /api-device/device/alarm/fire-alarm/1234567890
|
||||||
|
```
|
||||||
|
|
||||||
|
### 响应参数
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| code | Integer | 状态码,0表示成功,其他表示失败 |
|
||||||
|
| msg | String | 响应消息 |
|
||||||
|
| data | Object | 响应数据 |
|
||||||
|
| data.deviceSn | String | 设备SN |
|
||||||
|
| data.alarmType | String | 告警类型,固定值 `fire_alarm` |
|
||||||
|
| data.success | Boolean | 是否成功获取到数据 |
|
||||||
|
| data.message | String | 结果消息 |
|
||||||
|
| data.data | Object | 机库状态数据(JSON格式) |
|
||||||
|
| data.fromCache | Boolean | 数据是否来自缓存 |
|
||||||
|
|
||||||
|
### 响应示例
|
||||||
|
|
||||||
|
**成功响应**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"deviceSn": "8UUXNBN00A0TYV",
|
||||||
|
"alarmType": "fire_alarm",
|
||||||
|
"success": true,
|
||||||
|
"message": "fire_alarm: 实时订阅获取成功",
|
||||||
|
"data": {
|
||||||
|
"headers": {
|
||||||
|
"productId": "AutoDock3",
|
||||||
|
"traceparent": "00-9c7698e115633f9a7d7bf10cdeaf8027-b5a3471c1f6ebe11-01",
|
||||||
|
"creatorId": "1199596756811550720",
|
||||||
|
"deviceName": "福建怀远楼",
|
||||||
|
"_uid": "Rpx2mOEWT1gwVVYVFI6mbYOHiNw0LrVx",
|
||||||
|
"productName": "智能机场"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"data": {
|
||||||
|
"first_power_on": 1631945855969,
|
||||||
|
"latitude": 24.674428422729886,
|
||||||
|
"drone_charge_state": {
|
||||||
|
"capacity_percent": 95,
|
||||||
|
"state": 0
|
||||||
|
},
|
||||||
|
"storage": {
|
||||||
|
"total": 53082240,
|
||||||
|
"used": 230488
|
||||||
|
},
|
||||||
|
"putter_state": 0,
|
||||||
|
"cover_state": 0,
|
||||||
|
"silent_mode": 0,
|
||||||
|
"temperature": 19.3,
|
||||||
|
"humidity": 76,
|
||||||
|
"wind_speed": 0,
|
||||||
|
"supplement_light_state": 0,
|
||||||
|
"longitude": 117.0895028889822,
|
||||||
|
"height": 445.89630126953125,
|
||||||
|
"alternate_land_point": {
|
||||||
|
"safe_land_height": 30,
|
||||||
|
"latitude": 24.674308892544445,
|
||||||
|
"is_configured": 1,
|
||||||
|
"longitude": 117.08956638945415,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"rainfall": 0,
|
||||||
|
"heading": 63.878204345703125,
|
||||||
|
"alarm_state": 0,
|
||||||
|
"sub_device": {
|
||||||
|
"device_paired": 1,
|
||||||
|
"device_sn": "1581F8HHX259N00A04B1",
|
||||||
|
"device_online_status": 0,
|
||||||
|
"device_model_key": "0-100-0"
|
||||||
|
},
|
||||||
|
"emergency_stop_state": 0,
|
||||||
|
"battery_store_mode": 2,
|
||||||
|
"environment_temperature": 16.3,
|
||||||
|
"home_position_is_valid": 1,
|
||||||
|
"air_conditioner": {
|
||||||
|
"switch_time": 0,
|
||||||
|
"air_conditioner_state": 1
|
||||||
|
},
|
||||||
|
"drone_in_dock": 1,
|
||||||
|
"position_state": {
|
||||||
|
"is_calibration": 1,
|
||||||
|
"rtk_number": 45,
|
||||||
|
"gps_number": 7,
|
||||||
|
"is_fixed": 2,
|
||||||
|
"quality": 5
|
||||||
|
},
|
||||||
|
"network_state": {
|
||||||
|
"rate": 4,
|
||||||
|
"type": 2,
|
||||||
|
"quality": 0
|
||||||
|
},
|
||||||
|
"mode_code": 0
|
||||||
|
},
|
||||||
|
"deviceId": "8UUXNBN00A0TYV",
|
||||||
|
"timestamp": 1771516256520
|
||||||
|
},
|
||||||
|
"messageType": "EVENT",
|
||||||
|
"messageId": "2024512031305228288",
|
||||||
|
"event": "fire_alarm",
|
||||||
|
"deviceId": "8UUXNBN00A0TYV",
|
||||||
|
"timestamp": 1771516256534
|
||||||
|
},
|
||||||
|
"fromCache": false
|
||||||
|
},
|
||||||
|
"resp_code": 0,
|
||||||
|
"resp_msg": "获取成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**失败响应**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 1,
|
||||||
|
"msg": "设备SN不能为空",
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 获取无人机遥测数据
|
||||||
|
|
||||||
|
### 接口信息
|
||||||
|
|
||||||
|
| 项目 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| 接口地址 | `/device/alarm/msg-alarm/{deviceSn}` |
|
||||||
|
| 请求方式 | GET |
|
||||||
|
| 接口描述 | 一次性获取无人机遥测数据。**注意:无人机需开机才有数据** |
|
||||||
|
|
||||||
|
### 请求参数
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| deviceSn | String | 是 | 设备SN(路径参数) |
|
||||||
|
|
||||||
|
### 请求示例
|
||||||
|
|
||||||
|
```
|
||||||
|
GET /api-device/device/alarm/msg-alarm/1234567890
|
||||||
|
```
|
||||||
|
|
||||||
|
### 响应参数
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| code | Integer | 状态码,0表示成功,其他表示失败 |
|
||||||
|
| msg | String | 响应消息 |
|
||||||
|
| data | Object | 响应数据 |
|
||||||
|
| data.deviceSn | String | 设备SN |
|
||||||
|
| data.alarmType | String | 告警类型,固定值 `msg_alarm` |
|
||||||
|
| data.success | Boolean | 是否成功获取到数据 |
|
||||||
|
| data.message | String | 结果消息 |
|
||||||
|
| data.data | Object | 无人机遥测数据(JSON格式) |
|
||||||
|
| data.fromCache | Boolean | 数据是否来自缓存 |
|
||||||
|
|
||||||
|
### 响应示例
|
||||||
|
|
||||||
|
**成功响应**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "获取成功",
|
||||||
|
"data": {
|
||||||
|
"deviceSn": "1234567890",
|
||||||
|
"alarmType": "msg_alarm",
|
||||||
|
"success": true,
|
||||||
|
"message": "获取成功",
|
||||||
|
"data": {
|
||||||
|
"attitude_head": 45.2,
|
||||||
|
"attitude_pitch": 0.5,
|
||||||
|
"attitude_roll": -0.3,
|
||||||
|
"battery_capacity_percent": 85,
|
||||||
|
"elevation": 120.5,
|
||||||
|
"firmware_version": "01.00.0600",
|
||||||
|
"gear": 1,
|
||||||
|
"height": 50.3,
|
||||||
|
"home_distance": 150.8,
|
||||||
|
"horizontal_speed": 5.2,
|
||||||
|
"latitude": 30.123456,
|
||||||
|
"longitude": 120.654321,
|
||||||
|
"mode_code": 0,
|
||||||
|
"vertical_speed": 0.0,
|
||||||
|
"wind_direction": 180,
|
||||||
|
"wind_speed": 3.5
|
||||||
|
},
|
||||||
|
"fromCache": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**无人机未开机响应**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "未获取到数据(无人机可能未开机)",
|
||||||
|
"data": {
|
||||||
|
"deviceSn": "1234567890",
|
||||||
|
"alarmType": "msg_alarm",
|
||||||
|
"success": false,
|
||||||
|
"message": "订阅超时,未收到数据",
|
||||||
|
"data": null,
|
||||||
|
"fromCache": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 错误码说明
|
||||||
|
|
||||||
|
| 错误码 | 说明 |
|
||||||
|
|--------|------|
|
||||||
|
| 0 | 成功 |
|
||||||
|
| 1 | 业务失败(具体原因见msg字段) |
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
1. **机库状态数据**: 机库在线即可获取,数据包含机库环境信息、无人机充电状态等
|
||||||
|
2. **无人机遥测数据**: 仅在无人机开机状态下才有数据,如果无人机未开机则返回 `success=false`
|
||||||
Binary file not shown.
@@ -0,0 +1,833 @@
|
|||||||
|
# 高飞平台 API 对接文档
|
||||||
|
|
||||||
|
> 版本:v1.0 | 更新日期:2025-02-28|作者:杜志超
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 目录
|
||||||
|
|
||||||
|
1. [概述](#概述)
|
||||||
|
2. [接入准备](#接入准备)
|
||||||
|
3. [通用说明](#通用说明)
|
||||||
|
4. [接口列表](#接口列表)
|
||||||
|
- 4.1 [用户登录](#41-用户登录)
|
||||||
|
- 4.2 [创建订单](#42-创建订单)
|
||||||
|
- 4.3 [查询订单状态](#43-查询订单状态)
|
||||||
|
- 4.4 [获取订单素材](#44-获取订单素材)
|
||||||
|
- 4.5 [获取机库状态数据](#45-获取机库状态数据)
|
||||||
|
- 4.6 [获取无人机遥测数据](#46-获取无人机遥测数据)
|
||||||
|
5. [回调接口(第三方实现)](#5-回调接口第三方实现)
|
||||||
|
- 5.1 [一件成片回调](#51-一件成片回调)
|
||||||
|
- 5.2 [订单结束回调](#52-订单结束回调)
|
||||||
|
6. [全局错误码](#6-全局错误码)
|
||||||
|
7. [接入流程](#7-接入流程)
|
||||||
|
8. [附录](#8-附录)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 概述
|
||||||
|
|
||||||
|
本文档为高飞平台对外开放的完整 API 对接文档,涵盖以下能力:
|
||||||
|
|
||||||
|
| 能力模块 | 说明 |
|
||||||
|
|----------|------|
|
||||||
|
| 用户认证 | 基于 OpenID 的 OAuth 登录,获取 access_token |
|
||||||
|
| 订单管理 | 创建第三方订单、查询订单状态、获取订单素材 |
|
||||||
|
| 设备数据 | 获取机库状态、无人机遥测数据 |
|
||||||
|
| 回调通知 | 一件成片完成通知、订单结束通知(需第三方实现接收端) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 接入准备
|
||||||
|
|
||||||
|
在开始对接前,请向高飞平台申请以下凭证:
|
||||||
|
|
||||||
|
| 凭证 | 说明 | 获取方式 |
|
||||||
|
|------|------|----------|
|
||||||
|
| clientId | 客户端标识 | 联系高飞平台获取 |
|
||||||
|
| openId | 开放平台用户标识 | 联系高飞平台获取 |
|
||||||
|
| 回调地址 | 接收回调通知的 URL | 第三方自行提供 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 通用说明
|
||||||
|
|
||||||
|
### 基础地址
|
||||||
|
|
||||||
|
| 环境 | 地址 |
|
||||||
|
|------|------|
|
||||||
|
| 测试环境 | `http://test.gofly.com` |
|
||||||
|
|
||||||
|
### 认证方式
|
||||||
|
|
||||||
|
除登录接口外,所有接口均需在请求头中携带 Bearer Token:
|
||||||
|
|
||||||
|
```
|
||||||
|
Authorization: Bearer {access_token}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 通用响应格式
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 0,
|
||||||
|
"resp_msg": "成功",
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| resp_code | Integer | 响应码,0 表示成功 |
|
||||||
|
| resp_msg | String | 响应消息 |
|
||||||
|
| data | Object | 业务数据 |
|
||||||
|
|
||||||
|
### 请求规范
|
||||||
|
|
||||||
|
- Content-Type: `application/json`
|
||||||
|
- 字符编码: `UTF-8`
|
||||||
|
- 时间格式: `yyyy-MM-dd HH:mm:ss`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 接口列表
|
||||||
|
|
||||||
|
### 4.1 用户登录
|
||||||
|
|
||||||
|
获取访问令牌,后续所有接口调用均依赖此令牌。
|
||||||
|
|
||||||
|
| 项目 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| 接口路径 | `/api-uaa/oauth/login` |
|
||||||
|
| 请求方式 | POST |
|
||||||
|
|
||||||
|
#### 请求参数
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| grantType | String | 是 | 授权类型,固定值:`openId` |
|
||||||
|
| clientId | String | 是 | 客户端ID,由平台分配 |
|
||||||
|
| deviceId | String | 是 | 设备唯一标识 |
|
||||||
|
| openId | String | 是 | 用户 OpenID,由平台分配 |
|
||||||
|
|
||||||
|
#### 请求示例
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST "http://test.gofly.com/api-uaa/oauth/login" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"grantType": "openId",
|
||||||
|
"clientId": "your_client_id",
|
||||||
|
"deviceId": "device_001",
|
||||||
|
"openId": "your_open_id"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"access_token": "2OWQBzmKM1h44BLgDQgOKItY-_hj5xP4hlMCqa560krd...",
|
||||||
|
"token_type": "Bearer",
|
||||||
|
"expires_in": 3600
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 响应字段
|
||||||
|
|
||||||
|
| 字段名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| access_token | String | 访问令牌 |
|
||||||
|
| token_type | String | 令牌类型,固定值 `Bearer` |
|
||||||
|
| expires_in | Integer | 过期时间(秒) |
|
||||||
|
|
||||||
|
#### 错误码
|
||||||
|
|
||||||
|
| 错误码 | 错误信息 | 说明 |
|
||||||
|
|--------|----------|------|
|
||||||
|
| invalid_grant | Invalid openId | OpenID 无效 |
|
||||||
|
| invalid_client | Invalid clientId | 客户端ID 无效 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4.2 创建订单
|
||||||
|
|
||||||
|
创建第三方订单
|
||||||
|
|
||||||
|
| 项目 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| 接口路径 | `/api-order/order/create` |
|
||||||
|
| 请求方式 | POST |
|
||||||
|
| 认证 | 需要 Bearer Token |
|
||||||
|
|
||||||
|
#### 请求参数
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| codeId | String | 是 | 二维码唯一标识 |
|
||||||
|
| payType | Integer | 是 | 支付类型,3表示指定支付方式 |
|
||||||
|
|
||||||
|
#### 请求示例
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST "http://test.gofly.com/api-order/order/create" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer {access_token}" \
|
||||||
|
-d '{
|
||||||
|
"codeId": "需要找高飞获取",
|
||||||
|
"payType": 3
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 0,
|
||||||
|
"resp_msg": "订单创建成功",
|
||||||
|
"data": {
|
||||||
|
"id": 123,
|
||||||
|
"orderNo": "202501150001",
|
||||||
|
"userId": 456,
|
||||||
|
"tourismId": 789,
|
||||||
|
"deviceSn": "xxxxx",
|
||||||
|
"orderAmount": "5000",
|
||||||
|
"orderStatus": 0,
|
||||||
|
"payType": 3,
|
||||||
|
"codeId": "xxxxx",
|
||||||
|
"tenantId": "tenant_001",
|
||||||
|
"createTime": "2025-01-15T10:30:00Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
#### 失败响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 1,
|
||||||
|
"resp_msg": "已存在订单,请前往订单页确认,请勿重复下单"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 响应字段说明
|
||||||
|
| 字段名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| resp_code | Integer | 响应码,0表示成功,非0表示失败 |
|
||||||
|
| resp_msg | String | 响应消息 |
|
||||||
|
| data | Object | 订单数据(成功时返回) |
|
||||||
|
|
||||||
|
### 业务逻辑
|
||||||
|
1. **用户身份验证**: 验证用户登录状态
|
||||||
|
2. **重复订单检查**: 检查用户是否已有未完成的订单
|
||||||
|
3. **二维码验证**: 验证二维码是否存在且有效
|
||||||
|
4. **租户分配**: 根据二维码ID智能分配租户
|
||||||
|
5. **订单创建**: 设置订单基本信息并保存
|
||||||
|
6. **幂等性保证**: 使用分布式锁确保订单不重复创建
|
||||||
|
|
||||||
|
### 错误码说明
|
||||||
|
| 错误码 | 错误信息 | 说明 |
|
||||||
|
|--------|----------|------|
|
||||||
|
| 1 | 已存在订单,请前往订单页确认,请勿重复下单 | 用户已有未完成订单 |
|
||||||
|
| 1 | 该二维码已过期 | 二维码状态为不可用 |
|
||||||
|
| 1 | 二维码不存在 | 二维码ID无效 |
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4.3 查询订单状态
|
||||||
|
|
||||||
|
查询指定订单的当前状态和详细信息。
|
||||||
|
|
||||||
|
| 项目 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| 接口路径 | `/api-order/order/status/{orderNo}` |
|
||||||
|
| 请求方式 | GET |
|
||||||
|
| 认证 | 需要 Bearer Token |
|
||||||
|
|
||||||
|
#### 请求参数
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| orderNo | String | 是 | 订单号(路径参数) |
|
||||||
|
|
||||||
|
#### 请求示例
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X GET "http://test.gofly.com/api-order/order/status/GF2025031700001" \
|
||||||
|
-H "Authorization: Bearer {access_token}"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 0,
|
||||||
|
"resp_msg": "查询成功",
|
||||||
|
"data": {
|
||||||
|
"id": 123,
|
||||||
|
"orderNo": "xxxxxx",
|
||||||
|
"orderStatus": 4,
|
||||||
|
"statusDesc": "正在服务中",
|
||||||
|
"createTime": "2025-01-15T10:30:00Z",
|
||||||
|
"updateTime": "2025-01-15T10:35:00Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 失败响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 1,
|
||||||
|
"resp_msg": "订单不存在"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 订单状态枚举
|
||||||
|
|
||||||
|
| 状态值 | 说明 |
|
||||||
|
|-----|--------|
|
||||||
|
| 0 | 待支付 |
|
||||||
|
| 1 | 已支付排队中 |
|
||||||
|
| 2 | 已取消 |
|
||||||
|
| 3 | 任务完成 |
|
||||||
|
| 4 | 正在服务中 |
|
||||||
|
| 5 | 素材上传中 |
|
||||||
|
| 6 | 素材上传完成 |
|
||||||
|
| 7 | 退款中 |
|
||||||
|
| 8 | 已退款 |
|
||||||
|
| 9 | 退款失败 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4.4 获取订单素材
|
||||||
|
|
||||||
|
分页获取订单关联的照片、视频、AI成片等素材。
|
||||||
|
|
||||||
|
| 项目 | 说明 |
|
||||||
|
|------|-----------------------------------|
|
||||||
|
| 接口路径 | `/api-order/user/files/{orderNo}` |
|
||||||
|
| 请求方式 | GET |
|
||||||
|
| 认证 | 需要 Bearer Token |
|
||||||
|
|
||||||
|
#### 请求参数
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| orderNo | String | 是 | 订单号(路径参数) |
|
||||||
|
|
||||||
|
#### 请求示例
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X GET "http://localhost:8080/api-order/user/files/xxxxxx" \
|
||||||
|
-H "Authorization: Bearer {access_token}"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 0,
|
||||||
|
"resp_msg": "查询成功",
|
||||||
|
"data": {
|
||||||
|
"time": "2025-01-15 10:30",
|
||||||
|
"addr": "北京市朝阳区某某景区",
|
||||||
|
"orderNo": "202501150001",
|
||||||
|
"aiVideo": "https://cdn.example.com/video/2025/01/15/ai_video_abc123.mp4",
|
||||||
|
"imgList": [
|
||||||
|
{
|
||||||
|
"url": "https://cdn.example.com/picture/2025/01/15/img_001.jpeg",
|
||||||
|
"contentType": "image/jpeg",
|
||||||
|
"path": "picture/2025/01/15/img_001.jpeg",
|
||||||
|
"viewUrl": "https://cdn.example.com/picture/2025/01/15/img_001.jpeg?style=thumbnail"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://cdn.example.com/picture/2025/01/15/img_002.jpeg",
|
||||||
|
"contentType": "image/jpeg",
|
||||||
|
"path": "picture/2025/01/15/img_002.jpeg",
|
||||||
|
"viewUrl": "https://cdn.example.com/picture/2025/01/15/img_002.jpeg?style=thumbnail"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"videoList": [
|
||||||
|
{
|
||||||
|
"url": "https://cdn.example.com/video/2025/01/15/video_001.mp4",
|
||||||
|
"contentType": "video/mp4",
|
||||||
|
"path": "video/2025/01/15/video_001.mp4",
|
||||||
|
"viewUrl": "https://cdn.example.com/picture/2025/01/15/img_001.jpeg?style=thumbnail"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"showVideoEditOnly": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 失败响应
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 1,
|
||||||
|
"resp_msg": "订单不存在"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
#### 素材数据字段说明
|
||||||
|
| 字段名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| time | String | 订单创建时间(格式:yyyy-MM-dd HH:mm) |
|
||||||
|
| addr | String | 景区地址 |
|
||||||
|
| orderNo | String | 订单编号 |
|
||||||
|
| aiVideo | String | AI生成视频的访问地址(可能为null) |
|
||||||
|
| imgList | Array | 图片素材列表 |
|
||||||
|
| videoList | Array | 视频素材列表 |
|
||||||
|
|
||||||
|
#### 图片/视频素材字段说明
|
||||||
|
| 字段名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| url | String | 文件访问地址(CDN加速) |
|
||||||
|
| contentType | String | 文件MIME类型 |
|
||||||
|
| path | String | 文件存储路径 |
|
||||||
|
| viewUrl | String | 文件预览地址(图片为缩略图,视频为对应图片缩略图) |
|
||||||
|
#### 素材类型说明
|
||||||
|
|
||||||
|
| 类型 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| image/jpeg | 原始拍摄的图片 |
|
||||||
|
| raw_video | 第三方原始视频 |
|
||||||
|
| ai_video | AI 一件成片视频 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4.5 获取机库状态数据
|
||||||
|
|
||||||
|
获取指定设备的机库实时状态数据,包含环境信息、无人机充电状态等。
|
||||||
|
|
||||||
|
| 项目 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| 接口路径 | `/api-device/device/alarm/fire-alarm/{deviceSn}` |
|
||||||
|
| 请求方式 | GET |
|
||||||
|
| 认证 | 需要 Bearer Token |
|
||||||
|
|
||||||
|
#### 请求参数
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| deviceSn | String | 是 | 设备 SN 序列号(路径参数) |
|
||||||
|
|
||||||
|
#### 请求示例
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X GET "http://test.gofly.com/api-device/device/alarm/fire-alarm/8UUXNBN00A0TYV" \
|
||||||
|
-H "Authorization: Bearer {access_token}"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 0,
|
||||||
|
"resp_msg": "获取成功",
|
||||||
|
"data": {
|
||||||
|
"deviceSn": "xxxxxxx",
|
||||||
|
"alarmType": "fire_alarm",
|
||||||
|
"success": true,
|
||||||
|
"message": "fire_alarm: 实时订阅获取成功",
|
||||||
|
"data": {
|
||||||
|
"first_power_on": 1631945855969,
|
||||||
|
"latitude": 24.674428422729886,
|
||||||
|
"longitude": 117.0895028889822,
|
||||||
|
"height": 445.89,
|
||||||
|
"drone_charge_state": {
|
||||||
|
"capacity_percent": 95,
|
||||||
|
"state": 0
|
||||||
|
},
|
||||||
|
"storage": {
|
||||||
|
"total": 53082240,
|
||||||
|
"used": 230488
|
||||||
|
},
|
||||||
|
"temperature": 19.3,
|
||||||
|
"humidity": 76,
|
||||||
|
"wind_speed": 0,
|
||||||
|
"rainfall": 0,
|
||||||
|
"drone_in_dock": 1,
|
||||||
|
"cover_state": 0,
|
||||||
|
"alarm_state": 0,
|
||||||
|
"emergency_stop_state": 0,
|
||||||
|
"mode_code": 0,
|
||||||
|
"network_state": {
|
||||||
|
"rate": 4,
|
||||||
|
"type": 2,
|
||||||
|
"quality": 0
|
||||||
|
},
|
||||||
|
"position_state": {
|
||||||
|
"is_calibration": 1,
|
||||||
|
"rtk_number": 45,
|
||||||
|
"gps_number": 7,
|
||||||
|
"is_fixed": 2,
|
||||||
|
"quality": 5
|
||||||
|
},
|
||||||
|
"sub_device": {
|
||||||
|
"device_paired": 1,
|
||||||
|
"device_sn": "1581F8HHX259N00A04B1",
|
||||||
|
"device_online_status": 0,
|
||||||
|
"device_model_key": "0-100-0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fromCache": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 主要数据字段说明
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| latitude | Double | 纬度 |
|
||||||
|
| longitude | Double | 经度 |
|
||||||
|
| height | Double | 海拔高度(米) |
|
||||||
|
| temperature | Double | 机库内温度(℃) |
|
||||||
|
| humidity | Integer | 湿度(%) |
|
||||||
|
| wind_speed | Double | 风速(m/s) |
|
||||||
|
| rainfall | Double | 降雨量 |
|
||||||
|
| drone_in_dock | Integer | 无人机是否在机库内,1=在 0=不在 |
|
||||||
|
| cover_state | Integer | 舱盖状态,0=关闭 1=打开 |
|
||||||
|
| alarm_state | Integer | 告警状态,0=正常 |
|
||||||
|
| emergency_stop_state | Integer | 急停状态,0=正常 |
|
||||||
|
| mode_code | Integer | 工作模式 "0":"空闲中","1":"现场调试","2":"远程调试","3":"固件升级中","4":"作业中","5":"待标定"|
|
||||||
|
| drone_charge_state.capacity_percent | Integer | 无人机电量百分比 |
|
||||||
|
| drone_charge_state.state | Integer | 充电状态,0=未充电 |
|
||||||
|
| storage.total | Long | 存储总量(KB) |
|
||||||
|
| storage.used | Long | 已用存储(KB) |
|
||||||
|
|
||||||
|
#### 失败响应
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 1,
|
||||||
|
"msg": "设备SN不能为空",
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4.6 获取无人机遥测数据
|
||||||
|
|
||||||
|
获取无人机实时遥测数据,包含位置、姿态、电量等信息。
|
||||||
|
|
||||||
|
> **注意**:无人机需处于开机状态才有数据返回。
|
||||||
|
|
||||||
|
| 项目 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| 接口路径 | `/api-device/device/alarm/msg-alarm/{deviceSn}` |
|
||||||
|
| 请求方式 | GET |
|
||||||
|
| 认证 | 需要 Bearer Token |
|
||||||
|
|
||||||
|
#### 请求参数
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| deviceSn | String | 是 | 设备 SN 序列号(路径参数) |
|
||||||
|
|
||||||
|
#### 请求示例
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X GET "http://test.gofly.com/api-device/device/alarm/msg-alarm/1581F8HHX259N00A04B1" \
|
||||||
|
-H "Authorization: Bearer {access_token}"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 0,
|
||||||
|
"resp_msg": "获取成功",
|
||||||
|
"data": {
|
||||||
|
"deviceSn": "1581F8HHX259N00A04B1",
|
||||||
|
"alarmType": "msg_alarm",
|
||||||
|
"success": true,
|
||||||
|
"message": "获取成功",
|
||||||
|
"data": {
|
||||||
|
"attitude_head": 45.2,
|
||||||
|
"attitude_pitch": 0.5,
|
||||||
|
"attitude_roll": -0.3,
|
||||||
|
"battery_capacity_percent": 85,
|
||||||
|
"elevation": 120.5,
|
||||||
|
"firmware_version": "01.00.0600",
|
||||||
|
"gear": 1,
|
||||||
|
"height": 50.3,
|
||||||
|
"home_distance": 150.8,
|
||||||
|
"horizontal_speed": 5.2,
|
||||||
|
"latitude": 30.123456,
|
||||||
|
"longitude": 120.654321,
|
||||||
|
"mode_code": 0,
|
||||||
|
"vertical_speed": 0.0,
|
||||||
|
"wind_direction": 180,
|
||||||
|
"wind_speed": 3.5
|
||||||
|
},
|
||||||
|
"fromCache": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 遥测数据字段说明
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| attitude_head | Double | 航向角(°) |
|
||||||
|
| attitude_pitch | Double | 俯仰角(°) |
|
||||||
|
| attitude_roll | Double | 横滚角(°) |
|
||||||
|
| battery_capacity_percent | Integer | 电池电量(%) |
|
||||||
|
| elevation | Double | 海拔高度(米) |
|
||||||
|
| height | Double | 相对起飞点高度(米) |
|
||||||
|
| home_distance | Double | 距返航点距离(米) |
|
||||||
|
| horizontal_speed | Double | 水平速度(m/s) |
|
||||||
|
| vertical_speed | Double | 垂直速度(m/s) |
|
||||||
|
| latitude | Double | 纬度 |
|
||||||
|
| longitude | Double | 经度 |
|
||||||
|
| wind_direction | Integer | 风向(°) |
|
||||||
|
| wind_speed | Double | 风速(m/s) |
|
||||||
|
| firmware_version | String | 固件版本 |
|
||||||
|
| gear | Integer | 档位 |
|
||||||
|
| mode_code | Integer | 飞行模式 "0":"待机","1":"起飞准备","2":"起飞准备完毕","3":"手动飞行","4":"自动起飞","5":"航线飞行","6":"全景拍照","7":"智能跟随","8":"ADS-B 躲避","9":"自动返航","10":"自动降落","11":"强制降落","12":"三桨叶降落","13":"升级中","14":"未连接","15":"APAS","16":"虚拟摇杆状态","17":"指令飞行","18":"空中 RTK 收敛模式","19":"机场选址中","20":"POI环绕","21":"进离场航线飞行过程中" |
|
||||||
|
|
||||||
|
#### 无人机未开机响应
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"resp_code": 0,
|
||||||
|
"resp_msg": "未获取到数据(无人机可能未开机)",
|
||||||
|
"data": {
|
||||||
|
"deviceSn": "1581F8HHX259N00A04B1",
|
||||||
|
"alarmType": "msg_alarm",
|
||||||
|
"success": false,
|
||||||
|
"message": "订阅超时,未收到数据",
|
||||||
|
"data": null,
|
||||||
|
"fromCache": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 回调接口(第三方实现)
|
||||||
|
|
||||||
|
以下回调接口由高飞平台主动调用,第三方系统需实现对应的接收端点。
|
||||||
|
|
||||||
|
> 回调统一使用 `openId` 进行身份验证,第三方需校验 `openId` 合法性。
|
||||||
|
|
||||||
|
### 5.1 一件成片回调
|
||||||
|
|
||||||
|
AI 一件成片完成后,高飞平台将视频 URL 推送至第三方。
|
||||||
|
|
||||||
|
| 项目 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| 接口路径 | 由第三方提供,示例:`/api/callback/ai-video` |
|
||||||
|
| 请求方式 | POST |
|
||||||
|
| 调用方 | 高飞平台 → 第三方 |
|
||||||
|
|
||||||
|
#### 请求参数
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| openId | String | 是 | 开放平台标识ID,用于身份验证 |
|
||||||
|
| orderNo | String | 是 | 高飞平台订单号 |
|
||||||
|
| aiVideoUrl | String | 是 | AI 生成的视频 URL(经过 URLEncoder.encode UTF-8 编码) |
|
||||||
|
|
||||||
|
#### 请求示例
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST "https://your-domain.com/api/callback/ai-video" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"openId": "高飞提供的openId",
|
||||||
|
"orderNo": "GF2025031700001",
|
||||||
|
"aiVideoUrl": "https%3A%2F%2Fcdn.goflytec.com%2Fvideo%2Fsample.mp4"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 第三方应返回的响应
|
||||||
|
|
||||||
|
成功:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "success",
|
||||||
|
"data": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
失败:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 500,
|
||||||
|
"msg": "处理失败原因",
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 响应字段说明
|
||||||
|
|
||||||
|
| 字段名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| code | Integer | 响应码,0 表示成功,非 0 表示失败 |
|
||||||
|
| msg | String | 响应消息 |
|
||||||
|
| data | Boolean | 处理结果,true 表示成功 |
|
||||||
|
|
||||||
|
#### 注意事项
|
||||||
|
|
||||||
|
1. 第三方需对 `aiVideoUrl` 进行 URL 解码后使用
|
||||||
|
2. 同一订单号可能多次回调,第三方需做幂等处理
|
||||||
|
3. 如处理失败,高飞平台将进行重试
|
||||||
|
4. 建议第三方接口响应时间控制在 5 秒内
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 5.2 订单结束回调
|
||||||
|
|
||||||
|
订单飞行任务结束后,高飞平台通知第三方订单已完成。
|
||||||
|
|
||||||
|
| 项目 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| 接口路径 | 由第三方提供,示例:`/api/callback/order-end` |
|
||||||
|
| 请求方式 | POST |
|
||||||
|
| 调用方 | 高飞平台 → 第三方 |
|
||||||
|
|
||||||
|
#### 请求参数
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|--------|------|------|------|
|
||||||
|
| openId | String | 是 | 开放平台标识ID,用于身份验证 |
|
||||||
|
| orderNo | String | 是 | 高飞平台订单号 |
|
||||||
|
|
||||||
|
#### 请求示例
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST "https://your-domain.com/api/callback/order-end" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"openId": "高飞提供的openId",
|
||||||
|
"orderNo": "GF2025031700001"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 第三方应返回的响应
|
||||||
|
|
||||||
|
成功:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "success",
|
||||||
|
"data": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
失败:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 500,
|
||||||
|
"msg": "处理失败原因",
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 注意事项
|
||||||
|
|
||||||
|
1. 收到订单结束回调后,可调用 [获取订单素材](#44-获取订单素材) 接口拉取最终素材
|
||||||
|
2. 如通知失败,高飞平台将进行重试
|
||||||
|
3. 建议第三方接口响应时间控制在 5 秒内
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. 全局错误码
|
||||||
|
|
||||||
|
| 错误码 | 说明 |
|
||||||
|
|--------|------|
|
||||||
|
| 0 | 成功 |
|
||||||
|
| 1 | 业务失败(具体原因见 msg 字段) |
|
||||||
|
| 500 | 系统内部错误 |
|
||||||
|
| invalid_grant | OAuth 认证失败 |
|
||||||
|
| invalid_client | 客户端ID无效 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. 接入流程
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 接入流程 │
|
||||||
|
├─────────────────────────────────────────────────────────────────┤
|
||||||
|
│ │
|
||||||
|
│ Step 1: 获取凭证 │
|
||||||
|
│ ├── 向高飞平台申请 clientId、openId │
|
||||||
|
│ └── 提供回调接口地址 │
|
||||||
|
│ │
|
||||||
|
│ Step 2: 实现回调接口 │
|
||||||
|
│ ├── 实现一件成片回调接口 (5.1) │
|
||||||
|
│ └── 实现订单结束回调接口 (5.2) │
|
||||||
|
│ │
|
||||||
|
│ Step 3: 调用登录接口 │
|
||||||
|
│ └── POST /api-uaa/oauth/login → 获取 access_token │
|
||||||
|
│ │
|
||||||
|
│ Step 4: 业务接口调用 │
|
||||||
|
│ ├── 创建订单 → 查询状态 → 获取素材 │
|
||||||
|
│ └── 获取设备数据(机库状态 / 无人机遥测) │
|
||||||
|
│ │
|
||||||
|
│ Step 5: 接收回调 │
|
||||||
|
│ ├── 一件成片完成 → 接收 AI 视频 URL │
|
||||||
|
│ └── 订单结束 → 拉取最终素材 │
|
||||||
|
│ │
|
||||||
|
└─────────────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
### 典型业务时序
|
||||||
|
|
||||||
|
```
|
||||||
|
第三方系统 高飞平台 无人机/机库
|
||||||
|
│ │ │
|
||||||
|
│ 1. POST /oauth/login │ │
|
||||||
|
│ ────────────────────────> │ │
|
||||||
|
│ ← access_token │ │
|
||||||
|
│ │ │
|
||||||
|
│ 2. POST /order/create │ │
|
||||||
|
│ ────────────────────────> │ │
|
||||||
|
│ ← orderId │ │
|
||||||
|
│ │ 3. 下发飞行任务 │
|
||||||
|
│ │ ────────────────────────> │
|
||||||
|
│ │ │
|
||||||
|
│ 4. GET /order/status │ │
|
||||||
|
│ ────────────────────────> │ │
|
||||||
|
│ ← status: 飞行中 │ │
|
||||||
|
│ │ │
|
||||||
|
│ │ 5. 飞行完成,上传素材 │
|
||||||
|
│ │ <──────────────────────── │
|
||||||
|
│ │ │
|
||||||
|
│ 6. 订单结束回调 │ │
|
||||||
|
│ <──────────────────────── │ │
|
||||||
|
│ │ │
|
||||||
|
│ 7. 一件成片回调 │ │
|
||||||
|
│ <──────────────────────── │ │
|
||||||
|
│ │ │
|
||||||
|
│ 8. GET /order/materials │ │
|
||||||
|
│ ────────────────────────> │ │
|
||||||
|
│ ← 素材列表 │ │
|
||||||
|
│ │ │
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. 附录
|
||||||
|
|
||||||
|
### Token 管理建议
|
||||||
|
|
||||||
|
1. Token 有效期为 3600 秒(1小时),建议在过期前 5 分钟刷新
|
||||||
|
2. 收到 401 响应时,重新调用登录接口获取新 Token
|
||||||
|
3. 建议在应用层缓存 Token,避免频繁调用登录接口
|
||||||
|
|
||||||
|
### 重试策略建议
|
||||||
|
|
||||||
|
```
|
||||||
|
第1次重试: 延迟 1 秒
|
||||||
|
第2次重试: 延迟 2 秒
|
||||||
|
第3次重试: 延迟 4 秒
|
||||||
|
最大重试次数: 3 次
|
||||||
|
```
|
||||||
|
|
||||||
|
### 联系方式
|
||||||
|
|
||||||
|
如有技术问题,请联系高飞平台技术支持团队。
|
||||||
Binary file not shown.
@@ -0,0 +1,949 @@
|
|||||||
|
# 道路桥梁智能巡检平台
|
||||||
|
## 介绍文档
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一、执行摘要
|
||||||
|
|
||||||
|
道路桥梁智能巡检平台是一套基于无人机技术、人工智能和云计算的企业级智能巡检解决方案。平台通过自动化飞行、端侧实时识别和云端AI分析,实现道路、桥梁基础设施的全天候、高精度、智能化巡检,从问题发现到处置形成完整闭环管理。
|
||||||
|
|
||||||
|
**核心价值:**
|
||||||
|
- 巡检效率提升 **300%**,人力成本降低 **70%**
|
||||||
|
- 问题发现率提升 **95%**,响应时间缩短至 **15分钟内**
|
||||||
|
- 支持 **7×24小时** 全天候自动巡检
|
||||||
|
- 年度巡检成本节省 **60%以上**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、平台概述
|
||||||
|
|
||||||
|
### 2.1 平台定位
|
||||||
|
|
||||||
|
道路桥梁智能巡检平台是面向交通管理部门、高速公路运营商、市政管理单位的专业级基础设施巡检系统,采用"无人机+AI+云平台"三位一体架构,实现道路桥梁全生命周期智能化管理。
|
||||||
|
|
||||||
|
**平台界面展示:**
|
||||||
|
|
||||||
|

|
||||||
|
*图:综合管控平台 - 统一管理界面,集成设备监控、任务调度、数据分析*
|
||||||
|
|
||||||
|

|
||||||
|
*图:后台管理系统 - 设备管理模块,支持设备注册、状态监控、维护记录*
|
||||||
|
|
||||||
|
### 2.2 应用场景
|
||||||
|
|
||||||
|
**日常巡检场景:**
|
||||||
|
- 高速公路日常巡查(路面、护栏、标识)
|
||||||
|
- 国省道定期巡检
|
||||||
|
- 城市道路安全监测
|
||||||
|
- 桥梁日常状态监控
|
||||||
|
- 边坡地质灾害预警
|
||||||
|
|
||||||
|
**专项检测场景:**
|
||||||
|
- 桥梁结构详细检测(桥面、桥墩、桥下)
|
||||||
|
- 裂缝、锈蚀、位移病害识别
|
||||||
|
- 隧道内壁检测
|
||||||
|
- 边坡稳定性评估
|
||||||
|
|
||||||
|
**应急响应场景:**
|
||||||
|
- 交通事故现场勘查
|
||||||
|
- 自然灾害快速评估
|
||||||
|
- 应急指挥调度(喊话器、照明设备)
|
||||||
|
- 夜间紧急巡查
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三、核心功能模块
|
||||||
|
|
||||||
|
### 3.1 智能航线规划系统
|
||||||
|
|
||||||
|
**功能特点:**
|
||||||
|
- **自动航线生成**:根据道路、桥梁GIS数据自动生成最优巡检航线
|
||||||
|
- **多模式飞行**:支持直线巡航、环绕拍摄、定点悬停、仿地飞行
|
||||||
|
- **动态避障**:实时感知障碍物,自动调整飞行路径
|
||||||
|
- **精准定位**:厘米级RTK定位,确保巡检覆盖无遗漏
|
||||||
|
|
||||||
|
**航线类型:**
|
||||||
|
1. **道路巡检航线**:沿道路中心线自动规划,覆盖路面、护栏、边坡
|
||||||
|
2. **桥梁环绕航线**:360度环绕桥梁,多角度拍摄桥墩、桥面、支座
|
||||||
|
3. **桥下检测航线**:专用低空航线,适配桥下空间结构
|
||||||
|
4. **边坡扫描航线**:倾斜摄影航线,生成边坡三维模型
|
||||||
|
|
||||||
|
**航线规划界面示意图:**
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 智能航线规划系统 [保存] [执行] │
|
||||||
|
├─────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ │
|
||||||
|
│ ┌─────────────────┐ ┌──────────────────────────────────────────┐ │
|
||||||
|
│ │ 航线类型选择 │ │ 地图显示区域 │ │
|
||||||
|
│ │ │ │ │ │
|
||||||
|
│ │ ○ 道路巡检 │ │ ╔═══════════════════════╗ │ │
|
||||||
|
│ │ ● 桥梁环绕 │ │ ║ 桥梁A ║ │ │
|
||||||
|
│ │ ○ 桥下检测 │ │ ║ ┌─────────┐ ║ │ │
|
||||||
|
│ │ ○ 边坡扫描 │ │ ║ │ ▲ 起点 │ ║ │ │
|
||||||
|
│ │ │ │ ║ │ ↓ │ ║ │ │
|
||||||
|
│ │ 飞行参数: │ │ ║ │ ← ● → │ ║ │ │
|
||||||
|
│ │ 高度: 50m │ │ ║ │ ↑ │ ║ │ │
|
||||||
|
│ │ 速度: 10m/s │ │ ║ │ ▼ 终点 │ ║ │ │
|
||||||
|
│ │ 重叠率: 70% │ │ ║ └─────────┘ ║ │ │
|
||||||
|
│ │ │ │ ╚═══════════════════════╝ │ │
|
||||||
|
│ │ [自动生成航线] │ │ │ │
|
||||||
|
│ │ [手动调整] │ │ 航点数: 24 总距离: 2.3km │ │
|
||||||
|
│ └─────────────────┘ │ 预计时间: 15分钟 电量消耗: 35% │ │
|
||||||
|
│ └──────────────────────────────────────────┘ │
|
||||||
|
│ │
|
||||||
|
│ ┌─────────────────────────────────────────────────────────────────┐│
|
||||||
|
│ │ 航点列表 ││
|
||||||
|
│ │ #1 起飞点 N31.2345° E121.4567° 高度:0m 动作:起飞 ││
|
||||||
|
│ │ #2 航点1 N31.2346° E121.4568° 高度:50m 动作:拍照 ││
|
||||||
|
│ │ #3 航点2 N31.2347° E121.4569° 高度:50m 动作:拍照+悬停 ││
|
||||||
|
│ │ ... ││
|
||||||
|
│ └─────────────────────────────────────────────────────────────────┘│
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
**平台界面截图:**
|
||||||
|
|
||||||
|

|
||||||
|
*图:航线规划系统实际界面 - 支持地图可视化、航点编辑、参数配置*
|
||||||
|
|
||||||
|

|
||||||
|
*图:后台管理系统 - 航线管理模块,支持航线库管理、模板配置*
|
||||||
|
|
||||||
|
### 3.2 端侧实时AI识别
|
||||||
|
|
||||||
|
**边缘计算能力:**
|
||||||
|
平台在无人机端部署轻量级AI识别模型,实现飞行过程中的实时问题检测,无需等待回传即可发现紧急隐患。
|
||||||
|
|
||||||
|
**识别能力清单:**
|
||||||
|
|
||||||
|
| 类别 | 识别项目 | 响应时间 | 准确率 |
|
||||||
|
|------|---------|---------|--------|
|
||||||
|
| 路面问题 | 路面塌陷、坑槽、裂缝 | <2秒 | 96% |
|
||||||
|
| 交通事故 | 车辆碰撞、翻车、拥堵 | <1秒 | 98% |
|
||||||
|
| 抛洒物 | 货物散落、障碍物 | <1秒 | 95% |
|
||||||
|
| 排水设施 | 排水沟堵塞、井盖缺失 | <2秒 | 93% |
|
||||||
|
| 护栏设施 | 护栏破损、缺失、变形 | <2秒 | 94% |
|
||||||
|
| 边坡灾害 | 滑坡、崩塌、裂缝 | <3秒 | 92% |
|
||||||
|
| 桥梁病害 | 裂缝、剥落、渗水 | <3秒 | 91% |
|
||||||
|
|
||||||
|
**实时告警机制:**
|
||||||
|
- 发现紧急隐患立即触发告警
|
||||||
|
- 自动标注GPS坐标和时间戳
|
||||||
|
- 推送至指挥中心和责任人手机
|
||||||
|
- 支持现场语音播报
|
||||||
|
|
||||||
|
**端侧AI识别实时界面:**
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 无人机端侧AI识别系统 - 实时监控 飞行中 ● │
|
||||||
|
├─────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ │
|
||||||
|
│ ┌────────────────────────────┐ ┌──────────────────────────────┐ │
|
||||||
|
│ │ 实时视频流 │ │ 识别结果统计 │ │
|
||||||
|
│ │ │ │ │ │
|
||||||
|
│ │ ┌──────────────────┐ │ │ 今日巡检: 12.5km │ │
|
||||||
|
│ │ │ ╔══════════╗ │ │ │ 已识别: 8处 │ │
|
||||||
|
│ │ │ ║ 护栏破损 ║ ⚠️ │ │ │ │ │
|
||||||
|
│ │ │ ╚══════════╝ │ │ │ ┌────────────────────────┐ │ │
|
||||||
|
│ │ │ [置信度:94%] │ │ │ │ 类型 数量 等级 │ │ │
|
||||||
|
│ │ │ │ │ │ ├────────────────────────┤ │ │
|
||||||
|
│ │ │ GPS: N31.2345° │ │ │ │ 护栏破损 3 紧急 │ │ │
|
||||||
|
│ │ │ E121.4567° │ │ │ │ 路面裂缝 2 重要 │ │ │
|
||||||
|
│ │ └──────────────────┘ │ │ │ 排水堵塞 2 重要 │ │ │
|
||||||
|
│ │ │ │ │ 标识缺失 1 一般 │ │ │
|
||||||
|
│ └────────────────────────────┘ │ └────────────────────────┘ │ │
|
||||||
|
│ │ │ │
|
||||||
|
│ ┌────────────────────────────┐ │ 最新告警: │ │
|
||||||
|
│ │ 飞行状态 │ │ ⚠️ 15:23 护栏破损(紧急) │ │
|
||||||
|
│ │ 电量: ████████░░ 78% │ │ 📍 K125+340 已推送短信 │ │
|
||||||
|
│ │ 高度: 52m 速度: 12m/s │ │ │ │
|
||||||
|
│ │ 信号: ████████░░ 良好 │ │ ⚠️ 15:18 路面裂缝(重要) │ │
|
||||||
|
│ │ 已飞: 8.2km / 12.5km │ │ 📍 K124+890 │ │
|
||||||
|
│ └────────────────────────────┘ └──────────────────────────────┘ │
|
||||||
|
│ │
|
||||||
|
│ [暂停巡检] [返航] [查看详情] [导出报告] │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
识别流程:
|
||||||
|
摄像头采集 → 边缘AI处理 → 实时识别 → 立即告警 → 云端存储
|
||||||
|
(30fps) (<2秒) (置信度>90%) (SMS推送) (永久归档)
|
||||||
|
```
|
||||||
|
|
||||||
|
**平台界面截图:**
|
||||||
|
|
||||||
|

|
||||||
|
*图:实时监控中心 - 多设备状态监控、实时视频流、飞行数据展示*
|
||||||
|
|
||||||
|

|
||||||
|
*图:任务管理界面 - 任务列表、状态跟踪、执行记录*
|
||||||
|
|
||||||
|
### 3.3 云端深度AI分析
|
||||||
|
|
||||||
|
**深度学习模型:**
|
||||||
|
巡检完成后,所有影像资料上传至云端,采用高精度深度学习模型进行二次分析,识别端侧可能遗漏的细微病害。
|
||||||
|
|
||||||
|
**桥梁专项检测能力:**
|
||||||
|
|
||||||
|
**裂缝检测:**
|
||||||
|
- 最小识别宽度:0.1mm
|
||||||
|
- 自动测量裂缝长度、宽度、走向
|
||||||
|
- 裂缝类型分类(横向、纵向、网状、龟裂)
|
||||||
|
- 危险等级评估(轻微、中度、严重、危急)
|
||||||
|
|
||||||
|
**锈蚀检测:**
|
||||||
|
- 钢结构锈蚀面积计算
|
||||||
|
- 锈蚀程度分级(表面锈、点蚀、坑蚀、层状剥落)
|
||||||
|
- 钢筋外露识别
|
||||||
|
- 预测剩余使用寿命
|
||||||
|
|
||||||
|
**位移监测:**
|
||||||
|
- 桥梁挠度变化分析
|
||||||
|
- 支座位移检测
|
||||||
|
- 伸缩缝异常识别
|
||||||
|
- 历史数据对比分析
|
||||||
|
|
||||||
|
**混凝土病害:**
|
||||||
|
- 剥落、空鼓、蜂窝麻面
|
||||||
|
- 钢筋锈胀、保护层脱落
|
||||||
|
- 渗水、泛碱、冻融破坏
|
||||||
|
|
||||||
|
**AI识别效果对比示意图:**
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 桥梁裂缝AI识别效果对比 │
|
||||||
|
├─────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ │
|
||||||
|
│ 原始图像 端侧识别 云端深度分析 │
|
||||||
|
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
|
||||||
|
│ │ │ │ ╱╲ │ │ ╱╲ │ │
|
||||||
|
│ │ ╱╲ │ → │ ║══║ ⚠️ │ → │ ║══║ │ │
|
||||||
|
│ │ ╱ ╲ │ │╱ ╲ │ │╱ ║ ╲ │ │
|
||||||
|
│ │ ╱ ╲ │ │ ╲ │ │ ║ ╲ │ │
|
||||||
|
│ │╱ ╲ │ │ ╲ │ │ ║ ╲ │ │
|
||||||
|
│ └──────────┘ └──────────┘ └──────────┘ │
|
||||||
|
│ │
|
||||||
|
│ 识别结果: 识别结果: 识别结果: │
|
||||||
|
│ 无 主裂缝1条 主裂缝1条 + 次生裂缝3条 │
|
||||||
|
│ 长度: 约2m 长度: 2.34m │
|
||||||
|
│ 宽度: >1mm 宽度: 1.2mm │
|
||||||
|
│ 置信度: 94% 类型: 纵向裂缝 │
|
||||||
|
│ 等级: 重要 走向: 垂直向下 │
|
||||||
|
│ 危险等级: 中度 │
|
||||||
|
│ 建议: 立即封闭处理 │
|
||||||
|
│ │
|
||||||
|
├─────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ 识别能力对比表 │
|
||||||
|
│ ┌─────────────┬──────────┬──────────┬──────────────────┐ │
|
||||||
|
│ │ 对比项 │ 端侧AI │ 云端AI │ 说明 │ │
|
||||||
|
│ ├─────────────┼──────────┼──────────┼──────────────────┤ │
|
||||||
|
│ │ 响应时间 │ <2秒 │ 5-10分钟│ 端侧实时告警 │ │
|
||||||
|
│ │ 识别精度 │ 90-95% │ 95-98% │ 云端更精准 │ │
|
||||||
|
│ │ 最小裂缝 │ 0.5mm │ 0.1mm │ 云端识别更细微 │ │
|
||||||
|
│ │ 裂缝测量 │ 估算 │ 精确 │ 云端可精确测量 │ │
|
||||||
|
│ │ 病害分类 │ 基础 │ 详细 │ 云端分类更细致 │ │
|
||||||
|
│ │ 历史对比 │ 不支持 │ 支持 │ 云端可趋势分析 │ │
|
||||||
|
│ └─────────────┴──────────┴──────────┴──────────────────┘ │
|
||||||
|
│ │
|
||||||
|
│ 结论: 端侧+云端双重AI识别,实现"快速响应"与"精准分析"完美结合 │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.4 缺陷管理与闭环处置
|
||||||
|
|
||||||
|
**完整工作流程图:**
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 缺陷管理闭环流程 │
|
||||||
|
└─────────────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
┌──────────────┐
|
||||||
|
│ 1.问题发现 │ 端侧AI识别 + 云端深度分析
|
||||||
|
│ ⚠️ 护栏破损 │ 自动生成缺陷报告(位置/类型/照片)
|
||||||
|
└──────┬───────┘
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌──────────────┐
|
||||||
|
│ 2.自动分类 │ AI智能分类: 路面/桥梁/护栏/边坡...
|
||||||
|
│ 📋 护栏设施 │ 关联历史数据和维护记录
|
||||||
|
└──────┬───────┘
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌──────────────┐
|
||||||
|
│ 3.等级评估 │ 危险等级: 特急/紧急/重要/一般
|
||||||
|
│ ⚠️ 紧急 │ 处置时限: 15分钟内响应
|
||||||
|
└──────┬───────┘
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌──────────────┐
|
||||||
|
│ 4.任务派发 │ 自动分配: K125路段养护队
|
||||||
|
│ 📱 短信推送 │ 通知方式: 短信+APP+电话
|
||||||
|
└──────┬───────┘ 责任人: 张工(13800138000)
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌──────────────┐
|
||||||
|
│ 5.现场处置 │ 责任人接单并前往现场
|
||||||
|
│ 🔧 维修中 │ 上传处置照片和说明
|
||||||
|
└──────┬───────┘ 记录材料和工时
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌──────────────┐
|
||||||
|
│ 6.验收复查 │ 自动生成复查任务
|
||||||
|
│ ✓ 复查通过 │ 无人机再次飞行验证
|
||||||
|
└──────┬───────┘ AI对比处置前后效果
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌──────────────┐
|
||||||
|
│ 7.归档统计 │ 数据永久存档
|
||||||
|
│ 📊 已完成 │ 生成统计报表
|
||||||
|
└──────────────┘ 支持决策分析
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 时间轴示例 │
|
||||||
|
├─────────────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ 15:23 发现问题 → 15:23 自动分类 → 15:24 等级评估 → 15:25 任务派发 │
|
||||||
|
│ (实时) (1秒) (30秒) (1分钟) │
|
||||||
|
│ │
|
||||||
|
│ 15:40 责任人接单 → 16:20 到达现场 → 17:30 处置完成 → 次日 复查验收 │
|
||||||
|
│ (15分钟) (40分钟) (70分钟) (24小时) │
|
||||||
|
│ │
|
||||||
|
│ 总耗时: 从发现到处置完成约2小时,次日验收通过后归档 │
|
||||||
|
└─────────────────────────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
**1. 问题发现阶段**
|
||||||
|
- 端侧实时识别 + 云端深度分析
|
||||||
|
- 自动生成缺陷报告
|
||||||
|
- 包含:位置、类型、等级、照片、视频
|
||||||
|
|
||||||
|
**2. 智能分类与评估**
|
||||||
|
- 按病害类型自动分类
|
||||||
|
- AI评估危险等级(一般/较大/重大/特别重大)
|
||||||
|
- 计算紧急程度和处置时限
|
||||||
|
|
||||||
|
**3. 任务自动派发**
|
||||||
|
- 根据缺陷类型和位置自动分配责任单位
|
||||||
|
- 短信/APP推送通知相关人员
|
||||||
|
- 设置处置时限和提醒机制
|
||||||
|
|
||||||
|
**4. 现场处置跟踪**
|
||||||
|
- 责任人接收任务并确认
|
||||||
|
- 上传现场处置照片和说明
|
||||||
|
- 记录处置时间和材料成本
|
||||||
|
|
||||||
|
**5. 验收复查**
|
||||||
|
- 处置完成后自动生成复查任务
|
||||||
|
- 无人机再次飞行验证
|
||||||
|
- AI对比处置前后效果
|
||||||
|
|
||||||
|
**6. 数据归档与统计**
|
||||||
|
- 所有数据永久存档
|
||||||
|
- 生成月度/季度/年度统计报表
|
||||||
|
- 为养护决策提供数据支撑
|
||||||
|
|
||||||
|
**闭环管理流程详细说明:**
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 缺陷管理闭环流程 │
|
||||||
|
└─────────────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
┌──────────────┐
|
||||||
|
│ 1.问题发现 │ 端侧AI识别 + 云端深度分析
|
||||||
|
│ ⚠️ 护栏破损 │ 自动生成缺陷报告(位置/类型/照片)
|
||||||
|
└──────┬───────┘
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌──────────────┐
|
||||||
|
│ 2.自动分类 │ AI智能分类: 路面/桥梁/护栏/边坡...
|
||||||
|
│ 📋 护栏设施 │ 关联历史数据和维护记录
|
||||||
|
└──────┬───────┘
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌──────────────┐
|
||||||
|
│ 3.等级评估 │ 危险等级: 特急/紧急/重要/一般
|
||||||
|
│ ⚠️ 紧急 │ 处置时限: 15分钟内响应
|
||||||
|
└──────┬───────┘
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌──────────────┐
|
||||||
|
│ 4.任务派发 │ 自动分配: K125路段养护队
|
||||||
|
│ 📱 短信推送 │ 通知方式: 短信+APP+电话
|
||||||
|
└──────┬───────┘ 责任人: 张工(13800138000)
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌──────────────┐
|
||||||
|
│ 5.现场处置 │ 责任人接单并前往现场
|
||||||
|
│ 🔧 维修中 │ 上传处置照片和说明
|
||||||
|
└──────┬───────┘ 记录材料和工时
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌──────────────┐
|
||||||
|
│ 6.验收复查 │ 自动生成复查任务
|
||||||
|
│ ✓ 复查通过 │ 无人机再次飞行验证
|
||||||
|
└──────┬───────┘ AI对比处置前后效果
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌──────────────┐
|
||||||
|
│ 7.归档统计 │ 数据永久存档
|
||||||
|
│ 📊 已完成 │ 生成统计报表
|
||||||
|
└──────────────┘ 支持决策分析
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 时间轴示例 │
|
||||||
|
├─────────────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ 15:23 发现问题 → 15:23 自动分类 → 15:24 等级评估 → 15:25 任务派发 │
|
||||||
|
│ (实时) (1秒) (30秒) (1分钟) │
|
||||||
|
│ │
|
||||||
|
│ 15:40 责任人接单 → 16:20 到达现场 → 17:30 处置完成 → 次日 复查验收 │
|
||||||
|
│ (15分钟) (40分钟) (70分钟) (24小时) │
|
||||||
|
│ │
|
||||||
|
│ 总耗时: 从发现到处置完成约2小时,次日验收通过后归档 │
|
||||||
|
└─────────────────────────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### 3.5 多级告警与通知系统
|
||||||
|
|
||||||
|
**告警分级:**
|
||||||
|
|
||||||
|
| 等级 | 类型 | 响应时限 | 通知方式 |
|
||||||
|
|------|------|---------|---------|
|
||||||
|
| 特急 | 交通事故、路面塌陷、桥梁严重病害 | 立即 | 短信+电话+APP推送 |
|
||||||
|
| 紧急 | 护栏破损、边坡滑坡、排水堵塞 | 15分钟 | 短信+APP推送 |
|
||||||
|
| 重要 | 路面裂缝、标识缺失、轻微病害 | 2小时 | APP推送 |
|
||||||
|
| 一般 | 日常维护项目 | 24小时 | 系统内通知 |
|
||||||
|
|
||||||
|
**通知对象:**
|
||||||
|
- 指挥中心调度员
|
||||||
|
- 路段责任人
|
||||||
|
- 养护单位负责人
|
||||||
|
- 应急处置队伍
|
||||||
|
- 上级主管部门
|
||||||
|
|
||||||
|
**通知内容:**
|
||||||
|
- 问题描述和位置(GPS坐标+地图标注)
|
||||||
|
- 现场照片/视频
|
||||||
|
- 危险等级和建议处置方案
|
||||||
|
- 历史同类问题参考
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 四、技术架构
|
||||||
|
|
||||||
|
### 4.1 系统架构图
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 前端展示层 │
|
||||||
|
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
|
||||||
|
│ │Web管理台 │ │ 移动APP │ │大屏指挥 │ │微信小程序│ │
|
||||||
|
│ │React+Ant │ │React Nav │ │数据可视化│ │轻量查询 │ │
|
||||||
|
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
|
||||||
|
└────────────────────────────────┬────────────────────────────────────────────┘
|
||||||
|
│ HTTPS / WebSocket
|
||||||
|
↓
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ Spring Cloud Gateway │
|
||||||
|
│ 统一网关 | 路由转发 | 认证鉴权 | 限流熔断 │
|
||||||
|
└────────────────────────────────┬────────────────────────────────────────────┘
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 业务应用层 │
|
||||||
|
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
|
||||||
|
│ │航线规划 │ │任务调度 │ │AI识别 │ │缺陷管理 │ │统计分析 │ │
|
||||||
|
│ │服务 │ │服务 │ │服务 │ │服务 │ │服务 │ │
|
||||||
|
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
|
||||||
|
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
|
||||||
|
│ │告警通知 │ │报表生成 │ │工单流转 │ │数据导出 │ │
|
||||||
|
│ │服务 │ │服务 │ │服务 │ │服务 │ │
|
||||||
|
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
|
||||||
|
└────────────────────────────────┬────────────────────────────────────────────┘
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 微服务支撑层 │
|
||||||
|
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
|
||||||
|
│ │设备管理 │ │文件存储 │ │用户权限 │ │消息队列 │ │任务引擎 │ │
|
||||||
|
│ │Device │ │File │ │User │ │Message │ │Job │ │
|
||||||
|
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
|
||||||
|
└────────────────────────────────┬────────────────────────────────────────────┘
|
||||||
|
│
|
||||||
|
↓
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 基础设施层 │
|
||||||
|
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
|
||||||
|
│ │MySQL 8.0 │ │Redis 7.0 │ │ElasticS │ │MinIO │ │RocketMQ │ │
|
||||||
|
│ │业务数据 │ │缓存/会话 │ │日志/搜索 │ │对象存储 │ │消息中间件│ │
|
||||||
|
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
|
||||||
|
│ ┌──────────┐ ┌──────────┐ │
|
||||||
|
│ │Nacos │ │Sentinel │ │
|
||||||
|
│ │注册/配置 │ │流控/降级 │ │
|
||||||
|
│ └──────────┘ └──────────┘ │
|
||||||
|
└────────────────────────────────┬────────────────────────────────────────────┘
|
||||||
|
│ MQTT / HTTP / WebSocket
|
||||||
|
↓
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 设备接入层 │
|
||||||
|
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
|
||||||
|
│ │无人机 │ │多旋翼 │ │固定翼 │ │桥检专用 │ │
|
||||||
|
│ │自动机场 │ │无人机 │ │无人机 │ │无人机 │ │
|
||||||
|
│ │DJI Dock │ │M300/M350 │ │WingtraOne│ │Elios 3 │ │
|
||||||
|
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
|
||||||
|
│ ↓ ↓ ↓ ↓ │
|
||||||
|
│ [自动起降] [端侧AI] [长航时] [桥下检测] │
|
||||||
|
└─────────────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
数据流向:
|
||||||
|
设备采集 → 实时上传 → 业务处理 → 数据存储 → 前端展示
|
||||||
|
↑ ↓
|
||||||
|
└──────────────── 控制指令反馈 ────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 核心技术栈
|
||||||
|
|
||||||
|
**后端技术:**
|
||||||
|
- Spring Cloud 微服务架构
|
||||||
|
- Spring Boot 3.1.6
|
||||||
|
- MyBatis Plus 3.5.4
|
||||||
|
- Java 17
|
||||||
|
- Redis 7.0(缓存与消息)
|
||||||
|
- MySQL 8.0(业务数据)
|
||||||
|
- Elasticsearch 7.13(日志与搜索)
|
||||||
|
|
||||||
|
**前端技术:**
|
||||||
|
- React 17
|
||||||
|
- Ant Design Pro 4.20
|
||||||
|
- UmiJS 3.5
|
||||||
|
- TypeScript
|
||||||
|
- ECharts(数据可视化)
|
||||||
|
|
||||||
|
**AI技术:**
|
||||||
|
- TensorFlow / PyTorch
|
||||||
|
- YOLOv8(目标检测)
|
||||||
|
- DeepLab(语义分割)
|
||||||
|
- ResNet(特征提取)
|
||||||
|
- 边缘计算框架(NVIDIA Jetson)
|
||||||
|
|
||||||
|
**无人机技术:**
|
||||||
|
- DJI SDK集成
|
||||||
|
- MAVLink协议
|
||||||
|
- RTK高精度定位
|
||||||
|
- 自动机场对接
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 五、设备方案与一机多用
|
||||||
|
|
||||||
|
### 5.1 一机多用解决方案
|
||||||
|
|
||||||
|
**"一机多用"的理解与实现:**
|
||||||
|
|
||||||
|
平台支持单台无人机通过**快速更换挂载设备**和**切换飞行模式**,适应不同巡检场景,实现设备投资效益最大化。
|
||||||
|
|
||||||
|
**核心实现方式:**
|
||||||
|
|
||||||
|
**1. 模块化挂载系统**
|
||||||
|
- 快拆式云台接口,5分钟内完成设备更换
|
||||||
|
- 标准化电源和数据接口
|
||||||
|
- 自动识别挂载设备类型
|
||||||
|
|
||||||
|
**2. 多功能挂载设备库**
|
||||||
|
|
||||||
|
| 挂载设备 | 应用场景 | 更换时间 |
|
||||||
|
|---------|---------|---------|
|
||||||
|
| 高清变焦相机 | 日常道路巡检、桥梁外观检测 | 标配 |
|
||||||
|
| 热成像相机 | 夜间巡查、桥梁内部缺陷检测 | 3分钟 |
|
||||||
|
| 激光雷达 | 三维建模、位移监测 | 5分钟 |
|
||||||
|
| 喊话器 | 应急指挥、交通疏导 | 2分钟 |
|
||||||
|
| 照明灯 | 夜间应急、桥下检测 | 2分钟 |
|
||||||
|
| 多光谱相机 | 植被监测、边坡分析 | 5分钟 |
|
||||||
|
| 抛投器 | 应急救援物资投送 | 3分钟 |
|
||||||
|
|
||||||
|
**3. 智能任务调度**
|
||||||
|
- 系统根据任务类型自动提示所需挂载
|
||||||
|
- 优化任务排序,减少设备更换次数
|
||||||
|
- 同类任务批量执行
|
||||||
|
|
||||||
|
**典型应用示例(一机多用全天工作流):**
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 一机多用 - 全天工作流程 │
|
||||||
|
├─────────────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ │
|
||||||
|
│ 08:00-11:00 日常道路巡检 │
|
||||||
|
│ ┌─────────────────────────────────────────────────────────────┐ │
|
||||||
|
│ │ 无人机: M350 RTK │ │
|
||||||
|
│ │ 挂载: 📷 高清变焦相机 (Zenmuse H20T) │ │
|
||||||
|
│ │ 任务: 10公里道路巡查 │ │
|
||||||
|
│ │ 识别: 路面、护栏、标识、抛洒物 │ │
|
||||||
|
│ │ 成果: 发现3处护栏破损,2处路面裂缝 │ │
|
||||||
|
│ └─────────────────────────────────────────────────────────────┘ │
|
||||||
|
│ ↓ 更换挂载 (5分钟) │
|
||||||
|
│ 11:30-14:00 桥梁详细检测 │
|
||||||
|
│ ┌─────────────────────────────────────────────────────────────┐ │
|
||||||
|
│ │ 无人机: M350 RTK (同一台) │ │
|
||||||
|
│ │ 挂载: 📷 高清相机 + 📡 激光雷达 (L1) │ │
|
||||||
|
│ │ 任务: 3座桥梁结构检测 │ │
|
||||||
|
│ │ 识别: 裂缝、锈蚀、位移、支座状态 │ │
|
||||||
|
│ │ 成果: 生成3D模型,发现5处裂缝病害 │ │
|
||||||
|
│ └─────────────────────────────────────────────────────────────┘ │
|
||||||
|
│ ↓ 更换挂载 (5分钟) │
|
||||||
|
│ 14:30-17:00 边坡监测 │
|
||||||
|
│ ┌─────────────────────────────────────────────────────────────┐ │
|
||||||
|
│ │ 无人机: M350 RTK (同一台) │ │
|
||||||
|
│ │ 挂载: 🌈 多光谱相机 (P1) │ │
|
||||||
|
│ │ 任务: 5处边坡扫描 │ │
|
||||||
|
│ │ 识别: 滑坡、植被覆盖、地质变化 │ │
|
||||||
|
│ │ 成果: 发现1处潜在滑坡风险 │ │
|
||||||
|
│ └─────────────────────────────────────────────────────────────┘ │
|
||||||
|
│ ↓ 更换挂载 (3分钟) │
|
||||||
|
│ 20:00-22:00 应急响应 (突发交通事故) │
|
||||||
|
│ ┌─────────────────────────────────────────────────────────────┐ │
|
||||||
|
│ │ 无人机: M350 RTK (同一台) │ │
|
||||||
|
│ │ 挂载: 🔥 热成像 + 💡 照明灯 + 📢 喊话器 │ │
|
||||||
|
│ │ 任务: 交通事故现场勘查 │ │
|
||||||
|
│ │ 功能: 热成像搜救、现场照明、指挥疏导 │ │
|
||||||
|
│ │ 成果: 快速定位伤员,协助救援 │ │
|
||||||
|
│ └─────────────────────────────────────────────────────────────┘ │
|
||||||
|
│ │
|
||||||
|
│ 设备利用率: 85% | 总飞行时间: 8小时 | 更换挂载次数: 3次 │
|
||||||
|
│ 投资回报: 单台设备完成4类任务,相当于4台专用设备的工作量 │
|
||||||
|
└─────────────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
挂载设备快速更换示意:
|
||||||
|
┌──────────┐ ┌──────────┐ ┌──────────┐
|
||||||
|
│ 无人机 │ │ 挂载库 │ │ 新挂载 │
|
||||||
|
│ ▼ │ → │ 📷🌈📡💡 │ → │ ▲ │
|
||||||
|
│ [旧挂载] │ │ 快拆接口 │ │ [新挂载] │
|
||||||
|
└──────────┘ └──────────┘ └──────────┘
|
||||||
|
卸下(1分钟) 选择设备 安装(2分钟)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.2 桥下巡检专用方案
|
||||||
|
|
||||||
|
**问题:桥下巡检是否只能用专用无人机?是否需要挂载定位模块?**
|
||||||
|
|
||||||
|
**解决方案:**
|
||||||
|
|
||||||
|
**方案一:专用桥检无人机(推荐)**
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 专用桥检无人机配置方案 │
|
||||||
|
├─────────────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ │
|
||||||
|
│ 设备示意图: 定位模块配置: │
|
||||||
|
│ │
|
||||||
|
│ ╔═══════════╗ ┌─────────────────────────┐ │
|
||||||
|
│ ║ ▲ ▲ ▲ ║ ← 全向避障 │ 1️⃣ RTK定位模块 │ │
|
||||||
|
│ ║ ◄─●─► ║ ← 防撞框架 │ 厘米级精度 │ │
|
||||||
|
│ ║ ▼ ▼ ▼ ║ │ 桥外开阔区域使用 │ │
|
||||||
|
│ ╚═══════════╝ └─────────────────────────┘ │
|
||||||
|
│ │ │ │ ┌─────────────────────────┐ │
|
||||||
|
│ 📷💡📡 │ 2️⃣ 视觉定位系统 (VPS) │ │
|
||||||
|
│ 相机+补光+雷达 │ 桥下GPS弱信号时启用 │ │
|
||||||
|
│ │ 识别地面纹理定位 │ │
|
||||||
|
│ 核心特点: └─────────────────────────┘ │
|
||||||
|
│ ✓ 小型化设计 (350mm轴距) ┌─────────────────────────┐ │
|
||||||
|
│ ✓ 六面障碍物感知 │ 3️⃣ 超声波定位 │ │
|
||||||
|
│ ✓ 强光补偿系统 │ 近距离测距 (0.1-5m) │ │
|
||||||
|
│ ✓ 防撞保护框架 │ 防止碰撞桥墩/梁体 │ │
|
||||||
|
│ ✓ 续航30分钟 └─────────────────────────┘ │
|
||||||
|
│ ┌─────────────────────────┐ │
|
||||||
|
│ 桥下飞行路径示意: │ 4️⃣ 惯性导航系统 (IMU) │ │
|
||||||
|
│ │ 信号丢失时维持定位 │ │
|
||||||
|
│ ╔═══════════════════════╗ │ 短时自主飞行 │ │
|
||||||
|
│ ║ 桥面 ║ └─────────────────────────┘ │
|
||||||
|
│ ╠═══════════════════════╣ │
|
||||||
|
│ ║ ┌→→→→→→→→→→→→→→┐ ║ 定位切换逻辑: │
|
||||||
|
│ ║ ↑ 扫描路径 ↓ ║ 开阔区域 → RTK (精度±2cm) │
|
||||||
|
│ ║ └←←←←←←←←←←←←←←┘ ║ 桥下区域 → VPS (精度±10cm) │
|
||||||
|
│ ║ 桥墩 桥墩 桥墩 ║ 近距离 → 超声波 (精度±5cm) │
|
||||||
|
│ ╚═══════════════════════╝ 信号丢失 → IMU (维持10秒) │
|
||||||
|
│ │
|
||||||
|
│ 适用场景: │
|
||||||
|
│ ✓ 大型桥梁桥下全面检测 (跨度>50m) │
|
||||||
|
│ ✓ 复杂结构桥梁 (斜拉桥、悬索桥、拱桥) │
|
||||||
|
│ ✓ 高频次桥梁专项检测 (每月1次以上) │
|
||||||
|
│ ✓ 对检测精度要求高的项目 │
|
||||||
|
└─────────────────────────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
**方案二:通用无人机+增强定位(经济型)**
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 通用无人机改装方案 │
|
||||||
|
├─────────────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ │
|
||||||
|
│ 改装前: 改装后: │
|
||||||
|
│ │
|
||||||
|
│ ┌─────────┐ ╔═══════════╗ │
|
||||||
|
│ │ ▲ ▲ │ ║ ▲ ▲ ▲ ║ ← 新增避障 │
|
||||||
|
│ │ ● │ ────改装───→ ║ ◄─●─► ║ ← 防撞框 │
|
||||||
|
│ │ ▼ ▼ │ ║ ▼ ▼ ▼ ║ │
|
||||||
|
│ └─────────┘ ╚═══════════╝ │
|
||||||
|
│ │ │ │ │ │ │
|
||||||
|
│ 📷 📷💡📡 │
|
||||||
|
│ 标配相机 相机+补光+定位 │
|
||||||
|
│ │
|
||||||
|
│ 改装清单: 成本对比: │
|
||||||
|
│ ┌─────────────────────────┐ ┌──────────────────────────┐ │
|
||||||
|
│ │ 1. 视觉定位模块 2万元 │ │ 专用桥检机: 15-25万元 │ │
|
||||||
|
│ │ 2. 补光灯系统 0.5万元 │ │ 通用机改装: 8-12万元 │ │
|
||||||
|
│ │ 3. 防撞保护框 0.3万元 │ │ 节省成本: 40-50% │ │
|
||||||
|
│ │ 4. 避障传感器 1.2万元 │ └──────────────────────────┘ │
|
||||||
|
│ │ 总计: 4万元 │ │
|
||||||
|
│ └─────────────────────────┘ 性能对比: │
|
||||||
|
│ ┌──────────┬────────┬────────┐ │
|
||||||
|
│ 适用场景: │ 对比项 │ 专用机 │ 改装机 │ │
|
||||||
|
│ ✓ 中小型桥梁 (跨度<50m) ├──────────┼────────┼────────┤ │
|
||||||
|
│ ✓ 预算有限的项目 │ 检测精度 │ 极高 │ 较高 │ │
|
||||||
|
│ ✓ 低频次桥下巡检 (季度1次) │ 操作难度 │ 低 │ 中 │ │
|
||||||
|
│ ✓ 简单结构桥梁 │ 安全性 │ 极高 │ 较高 │ │
|
||||||
|
│ │ 适用范围 │ 全部 │ 部分 │ │
|
||||||
|
│ └──────────┴────────┴────────┘ │
|
||||||
|
└─────────────────────────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
**方案对比:**
|
||||||
|
|
||||||
|
| 对比项 | 专用桥检无人机 | 通用无人机改装 |
|
||||||
|
|-------|--------------|--------------|
|
||||||
|
| 投资成本 | 15-25万元/台 | 8-12万元/台 |
|
||||||
|
| 检测精度 | 极高 | 较高 |
|
||||||
|
| 操作难度 | 低(高度自动化) | 中(需要经验) |
|
||||||
|
| 适用范围 | 所有桥梁 | 中小型桥梁 |
|
||||||
|
| 安全性 | 极高 | 较高 |
|
||||||
|
| 推荐场景 | 专业桥检单位 | 综合巡检单位 |
|
||||||
|
|
||||||
|
**平台支持:**
|
||||||
|
- 两种方案均可接入平台统一管理
|
||||||
|
- 自动识别设备类型并匹配航线
|
||||||
|
- 统一的数据格式和分析流程
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 六、竞争优势
|
||||||
|
|
||||||
|
### 6.1 技术优势
|
||||||
|
|
||||||
|
**1. 端云协同AI识别**
|
||||||
|
- 业界首创端侧+云端双重AI识别
|
||||||
|
- 端侧实时响应,云端深度分析
|
||||||
|
- 识别准确率行业领先
|
||||||
|
|
||||||
|
**2. 全场景航线规划**
|
||||||
|
- 支持道路、桥梁、隧道、边坡全场景
|
||||||
|
- 自动避障与动态调整
|
||||||
|
- 厘米级精准定位
|
||||||
|
|
||||||
|
**3. 完整闭环管理**
|
||||||
|
- 从发现到处置全流程数字化
|
||||||
|
- 自动派单与进度跟踪
|
||||||
|
- 数据永久存档与分析
|
||||||
|
|
||||||
|
**4. 企业级架构**
|
||||||
|
- 微服务架构,支持百万级数据
|
||||||
|
- 高可用、高并发、高扩展
|
||||||
|
- 多租户隔离,数据安全
|
||||||
|
|
||||||
|
### 6.2 业务优势
|
||||||
|
|
||||||
|
**1. 降本增效显著**
|
||||||
|
- 人力成本降低70%
|
||||||
|
- 巡检效率提升300%
|
||||||
|
- 年度成本节省60%以上
|
||||||
|
|
||||||
|
**2. 问题发现率高**
|
||||||
|
- AI识别准确率95%以上
|
||||||
|
- 细微病害不遗漏
|
||||||
|
- 早发现早处置,避免重大事故
|
||||||
|
|
||||||
|
**3. 响应速度快**
|
||||||
|
- 紧急问题15分钟内响应
|
||||||
|
- 自动派单无需人工干预
|
||||||
|
- 移动端随时随地处理
|
||||||
|
|
||||||
|
**4. 数据资产积累**
|
||||||
|
- 所有巡检数据永久保存
|
||||||
|
- 形成基础设施健康档案
|
||||||
|
- 支持大数据分析与预测
|
||||||
|
|
||||||
|
### 6.3 行业优势
|
||||||
|
|
||||||
|
**1. 深度行业理解**
|
||||||
|
- 团队具备交通行业背景
|
||||||
|
- 熟悉道路桥梁养护规范
|
||||||
|
- 符合行业标准和要求
|
||||||
|
|
||||||
|
**2. 成熟案例积累**
|
||||||
|
- 已服务多个省市交通部门
|
||||||
|
- 累计巡检里程超10万公里
|
||||||
|
- 发现并处置隐患5000+处
|
||||||
|
|
||||||
|
**3. 持续技术创新**
|
||||||
|
- 专业研发团队
|
||||||
|
- 每季度功能迭代
|
||||||
|
- 紧跟行业前沿技术
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 七、商业模式
|
||||||
|
|
||||||
|
### 8.1 产品销售模式
|
||||||
|
|
||||||
|
**标准版:**
|
||||||
|
- 适用于:中小型道路管理单位
|
||||||
|
- 包含:基础巡检功能 + 5台无人机
|
||||||
|
- 价格:80-120万元
|
||||||
|
|
||||||
|
**专业版:**
|
||||||
|
- 适用于:高速公路运营商
|
||||||
|
- 包含:全功能 + 10台无人机 + 3个机场
|
||||||
|
- 价格:200-300万元
|
||||||
|
|
||||||
|
**旗舰版:**
|
||||||
|
- 适用于:省级交通管理部门
|
||||||
|
- 包含:全功能 + 定制开发 + 培训服务
|
||||||
|
- 价格:500万元以上
|
||||||
|
|
||||||
|
### 8.2 服务订阅模式
|
||||||
|
|
||||||
|
**SaaS云服务:**
|
||||||
|
- 客户无需购买设备
|
||||||
|
- 按巡检里程或次数付费
|
||||||
|
- 价格:5-10元/公里
|
||||||
|
|
||||||
|
**托管运营模式:**
|
||||||
|
- 平台提供设备+人员+系统
|
||||||
|
- 客户按年付费
|
||||||
|
- 价格:50-100万元/年
|
||||||
|
|
||||||
|
### 8.3 数据增值服务
|
||||||
|
|
||||||
|
- 巡检数据分析报告
|
||||||
|
- 养护决策咨询
|
||||||
|
- 预测性维护建议
|
||||||
|
- 行业大数据服务
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 九、市场前景
|
||||||
|
|
||||||
|
### 9.1 市场规模
|
||||||
|
|
||||||
|
**国内市场:**
|
||||||
|
- 公路总里程:535万公里
|
||||||
|
- 桥梁总数:100万座
|
||||||
|
- 年度养护市场:超1000亿元
|
||||||
|
- 智能化改造需求:200亿元以上
|
||||||
|
|
||||||
|
**目标市场:**
|
||||||
|
- 高速公路运营商:全国31个省市
|
||||||
|
- 国省道管理部门:2000+个
|
||||||
|
- 城市市政管理:300+个城市
|
||||||
|
- 桥梁检测机构:500+家
|
||||||
|
|
||||||
|
### 9.2 政策支持
|
||||||
|
|
||||||
|
- 《交通强国建设纲要》:推进智慧交通发展
|
||||||
|
- 《数字交通发展规划纲要》:加快基础设施数字化
|
||||||
|
- 各省市智慧交通专项资金支持
|
||||||
|
- 新基建政策红利
|
||||||
|
|
||||||
|
### 9.3 增长预测
|
||||||
|
|
||||||
|
- 2026年:市场规模50亿元,年增长率80%
|
||||||
|
- 2027年:市场规模100亿元,年增长率100%
|
||||||
|
- 2028年:市场规模200亿元,年增长率100%
|
||||||
|
- 2030年:市场规模500亿元,进入成熟期
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 十、投资亮点
|
||||||
|
|
||||||
|
### 10.1 技术壁垒高
|
||||||
|
|
||||||
|
- 核心AI算法自主研发
|
||||||
|
- 多项发明专利
|
||||||
|
- 行业数据积累优势
|
||||||
|
- 技术团队经验丰富
|
||||||
|
|
||||||
|
### 10.2 市场空间大
|
||||||
|
|
||||||
|
- 千亿级市场规模
|
||||||
|
- 政策强力支持
|
||||||
|
- 刚性需求,抗周期
|
||||||
|
- 可复制性强
|
||||||
|
|
||||||
|
### 10.3 商业模式清晰
|
||||||
|
|
||||||
|
- 多元化收入来源
|
||||||
|
- 高毛利率(60%以上)
|
||||||
|
- 客户粘性强
|
||||||
|
- 可持续增长
|
||||||
|
|
||||||
|
### 10.4 团队实力强
|
||||||
|
|
||||||
|
- 核心团队来自交通、AI、无人机领域
|
||||||
|
- 成功案例丰富
|
||||||
|
- 执行力强
|
||||||
|
- 行业资源深厚
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 十一、技术参数
|
||||||
|
|
||||||
|
### 11.1 系统性能指标
|
||||||
|
|
||||||
|
| 指标项 | 参数 |
|
||||||
|
|-------|------|
|
||||||
|
| 并发用户数 | >1000 |
|
||||||
|
| 数据处理能力 | 10TB/天 |
|
||||||
|
| 系统响应时间 | <200ms |
|
||||||
|
| 系统可用性 | 99.9% |
|
||||||
|
| 数据存储 | PB级 |
|
||||||
|
| AI识别速度 | 100张/秒 |
|
||||||
|
|
||||||
|
### 11.2 无人机性能指标
|
||||||
|
|
||||||
|
| 指标项 | 多旋翼 | 固定翼 | 桥检专用 |
|
||||||
|
|-------|--------|--------|---------|
|
||||||
|
| 续航时间 | 45分钟 | 120分钟 | 30分钟 |
|
||||||
|
| 巡航速度 | 15m/s | 25m/s | 5m/s |
|
||||||
|
| 最大航程 | 20km | 100km | 5km |
|
||||||
|
| 抗风等级 | 6级 | 7级 | 4级 |
|
||||||
|
| 定位精度 | ±2cm | ±5cm | ±1cm |
|
||||||
|
| 相机像素 | 4800万 | 4800万 | 6000万 |
|
||||||
|
|
||||||
|
### 11.3 AI识别指标
|
||||||
|
|
||||||
|
| 病害类型 | 准确率 | 召回率 | 处理速度 |
|
||||||
|
|---------|--------|--------|---------|
|
||||||
|
| 路面裂缝 | 96% | 94% | 0.5秒/张 |
|
||||||
|
| 桥梁裂缝 | 95% | 93% | 0.8秒/张 |
|
||||||
|
| 护栏破损 | 97% | 95% | 0.3秒/张 |
|
||||||
|
| 边坡滑坡 | 94% | 92% | 1.0秒/张 |
|
||||||
|
| 交通事故 | 98% | 97% | 0.2秒/张 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**附录:**
|
||||||
|
- 附录A:系统架构详细设计文档
|
||||||
|
- 附录B:AI算法技术白皮书
|
||||||
|
- 附录C:典型案例详细报告
|
||||||
|
- 附录D:产品价格清单
|
||||||
|
- 附录E:实施方案模板
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*本文档为商业机密,仅供投资人参考,未经授权不得传播。*
|
||||||
@@ -53,6 +53,8 @@ export default [
|
|||||||
{ path: '/device/device.html', component: '@/pages/device/Device' },
|
{ path: '/device/device.html', component: '@/pages/device/Device' },
|
||||||
// 3D模型管理
|
// 3D模型管理
|
||||||
{ path: '/device/3dModel.html', name: '3D模型管理', component: '@/pages/device/ThreeDModel' },
|
{ path: '/device/3dModel.html', name: '3D模型管理', component: '@/pages/device/ThreeDModel' },
|
||||||
|
// 物联网卡管理
|
||||||
|
{ path: '/device/iotCard.html', component: '@/pages/device/IotCard' },
|
||||||
// 景区地图仪表盘
|
// 景区地图仪表盘
|
||||||
{ path: '/device/mapDashboard.html', name: '地图仪表盘', component: '@/pages/device/mapDashboard', exact: true },
|
{ path: '/device/mapDashboard.html', name: '地图仪表盘', component: '@/pages/device/mapDashboard', exact: true },
|
||||||
{ path: '/device/mapDashboard/tourismDeviceDetail/:tourismId', component: '@/pages/device/mapDashboard/TourismDeviceDetail' },
|
{ path: '/device/mapDashboard/tourismDeviceDetail/:tourismId', component: '@/pages/device/mapDashboard/TourismDeviceDetail' },
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,114 @@
|
|||||||
|
import React, { useEffect, useRef } from 'react';
|
||||||
|
import {
|
||||||
|
ModalForm,
|
||||||
|
ProForm,
|
||||||
|
ProFormText,
|
||||||
|
ProFormSelect,
|
||||||
|
ProFormDateTimePicker,
|
||||||
|
ProFormTextArea,
|
||||||
|
} from '@ant-design/pro-components';
|
||||||
|
import TenantSelector from '@/components/ui/TenantSelector';
|
||||||
|
import { CARRIER_OPTIONS, ENABLED_OPTIONS } from '@/services/iotCard';
|
||||||
|
|
||||||
|
export type IotCardFormValues = {
|
||||||
|
id?: number;
|
||||||
|
cardNumber?: string;
|
||||||
|
msisdn?: string;
|
||||||
|
imsi?: string;
|
||||||
|
carrier?: number;
|
||||||
|
packageType?: string;
|
||||||
|
enabled?: number;
|
||||||
|
deviceSn?: string;
|
||||||
|
activationTime?: string;
|
||||||
|
expirationTime?: string;
|
||||||
|
tenantId?: string;
|
||||||
|
remark?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
interface IotCardFormProps {
|
||||||
|
title: string;
|
||||||
|
visible: boolean;
|
||||||
|
onVisibleChange: (v: boolean) => void;
|
||||||
|
onFinish: (values: IotCardFormValues) => Promise<boolean>;
|
||||||
|
initialValues?: Partial<IotCardFormValues>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const IotCardForm: React.FC<IotCardFormProps> = ({
|
||||||
|
title,
|
||||||
|
visible,
|
||||||
|
onVisibleChange,
|
||||||
|
onFinish,
|
||||||
|
initialValues,
|
||||||
|
}) => {
|
||||||
|
const formRef = useRef<any>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (visible && initialValues) {
|
||||||
|
setTimeout(() => {
|
||||||
|
formRef.current?.setFieldsValue(initialValues);
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
}, [visible, initialValues]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ModalForm<IotCardFormValues>
|
||||||
|
title={title}
|
||||||
|
visible={visible}
|
||||||
|
formRef={formRef}
|
||||||
|
onVisibleChange={onVisibleChange}
|
||||||
|
onFinish={onFinish}
|
||||||
|
modalProps={{ destroyOnClose: true }}
|
||||||
|
initialValues={initialValues}
|
||||||
|
>
|
||||||
|
{/* 所属租户 */}
|
||||||
|
<TenantSelector
|
||||||
|
nameTenant="tenantId"
|
||||||
|
labelTenant="所属租户"
|
||||||
|
hideIncludeChildren
|
||||||
|
rulesTenant={[{ required: true, message: '请选择租户' }]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ProForm.Group>
|
||||||
|
<ProFormText
|
||||||
|
name="cardNumber"
|
||||||
|
label="卡号(ICCID)"
|
||||||
|
rules={[{ required: true, message: '请输入卡号' }]}
|
||||||
|
width="md"
|
||||||
|
placeholder="请输入物联网卡ICCID号"
|
||||||
|
disabled={!!initialValues?.id}
|
||||||
|
/>
|
||||||
|
<ProFormText name="msisdn" label="MSISDN号码" width="md" placeholder="手机号" />
|
||||||
|
<ProFormText name="imsi" label="IMSI号码" width="md" placeholder="IMSI" />
|
||||||
|
</ProForm.Group>
|
||||||
|
|
||||||
|
<ProForm.Group>
|
||||||
|
<ProFormSelect
|
||||||
|
name="carrier"
|
||||||
|
label="运营商"
|
||||||
|
options={CARRIER_OPTIONS}
|
||||||
|
width="md"
|
||||||
|
placeholder="请选择运营商"
|
||||||
|
/>
|
||||||
|
<ProFormText name="packageType" label="套餐类型" width="md" placeholder="如:月包30M" />
|
||||||
|
<ProFormSelect
|
||||||
|
name="enabled"
|
||||||
|
label="启用状态"
|
||||||
|
options={ENABLED_OPTIONS}
|
||||||
|
width="md"
|
||||||
|
initialValue={1}
|
||||||
|
/>
|
||||||
|
</ProForm.Group>
|
||||||
|
|
||||||
|
<ProForm.Group>
|
||||||
|
<ProFormDateTimePicker name="activationTime" label="激活时间" width="md" />
|
||||||
|
<ProFormDateTimePicker name="expirationTime" label="到期时间" width="md" />
|
||||||
|
</ProForm.Group>
|
||||||
|
|
||||||
|
<ProForm.Group>
|
||||||
|
<ProFormTextArea name="remark" label="备注" width="lg" />
|
||||||
|
</ProForm.Group>
|
||||||
|
</ModalForm>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default IotCardForm;
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
import React, { forwardRef, useImperativeHandle, useRef, useEffect } from 'react';
|
||||||
|
import { ProTable } from '@ant-design/pro-components';
|
||||||
|
import type { ProColumns, ActionType } from '@ant-design/pro-components';
|
||||||
|
import { Space, Tag, Tooltip, Popconfirm } from 'antd';
|
||||||
|
import { EditOutlined, DeleteOutlined, LinkOutlined, DisconnectOutlined } from '@ant-design/icons';
|
||||||
|
import { iotCardApi, CARRIER_MAP } from '@/services/iotCard';
|
||||||
|
|
||||||
|
export interface IotCardTableRef {
|
||||||
|
reload: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IotCardTableProps {
|
||||||
|
params?: Record<string, any>;
|
||||||
|
onEdit?: (record: any) => void;
|
||||||
|
onDelete?: (record: any) => void;
|
||||||
|
onBind?: (record: any) => void;
|
||||||
|
onUnbind?: (record: any) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const IotCardTable = forwardRef<IotCardTableRef, IotCardTableProps>(
|
||||||
|
({ params, onEdit, onDelete, onBind, onUnbind }, ref) => {
|
||||||
|
const actionRef = useRef<ActionType>();
|
||||||
|
useImperativeHandle(ref, () => ({ reload: () => actionRef.current?.reload() }));
|
||||||
|
|
||||||
|
// 当查询参数变化时,自动重置到第一页
|
||||||
|
useEffect(() => {
|
||||||
|
if (actionRef.current) {
|
||||||
|
actionRef.current.setPageInfo?.({ current: 1 });
|
||||||
|
actionRef.current.reload();
|
||||||
|
}
|
||||||
|
}, [JSON.stringify(params)]);
|
||||||
|
|
||||||
|
const columns: ProColumns<any>[] = [
|
||||||
|
{ dataIndex: 'index', valueType: 'indexBorder', width: 48, fixed: 'left' },
|
||||||
|
{ title: '卡号(ICCID)', dataIndex: 'cardNumber', copyable: true, fixed: 'left', width: 200 },
|
||||||
|
{ title: 'MSISDN', dataIndex: 'msisdn', width: 140 },
|
||||||
|
{ title: 'IMSI', dataIndex: 'imsi', width: 160 },
|
||||||
|
{
|
||||||
|
title: '运营商',
|
||||||
|
dataIndex: 'carrier',
|
||||||
|
width: 100,
|
||||||
|
render: (_, record) => {
|
||||||
|
const name = CARRIER_MAP[record.carrier];
|
||||||
|
return name || '-';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ title: '套餐类型', dataIndex: 'packageType', width: 120, ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'enabled',
|
||||||
|
width: 80,
|
||||||
|
render: (_, record) => (
|
||||||
|
<Tag color={record.enabled === 1 ? 'green' : 'default'}>
|
||||||
|
{record.enabled === 1 ? '启用' : '停用'}
|
||||||
|
</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '绑定设备',
|
||||||
|
dataIndex: 'deviceSn',
|
||||||
|
width: 180,
|
||||||
|
render: (_, record) =>
|
||||||
|
record.deviceSn ? (
|
||||||
|
<Tooltip title={record.deviceName || record.deviceSn}>
|
||||||
|
<Tag color="blue">{record.deviceSn}</Tag>
|
||||||
|
</Tooltip>
|
||||||
|
) : (
|
||||||
|
<Tag>未绑定</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ title: '所属租户', dataIndex: 'tenantId', width: 120 },
|
||||||
|
{ title: '激活时间', dataIndex: 'activationTime', valueType: 'dateTime', width: 170 },
|
||||||
|
{ title: '到期时间', dataIndex: 'expirationTime', valueType: 'dateTime', width: 170 },
|
||||||
|
{ title: '备注', dataIndex: 'remark', ellipsis: true, width: 150 },
|
||||||
|
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 170 },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
key: 'action',
|
||||||
|
valueType: 'option',
|
||||||
|
width: 140,
|
||||||
|
fixed: 'right',
|
||||||
|
render: (_, record) => (
|
||||||
|
<Space>
|
||||||
|
{record.deviceSn ? (
|
||||||
|
<Tooltip title="解绑设备">
|
||||||
|
<a style={{ color: '#faad14' }} onClick={() => onUnbind?.(record)}>
|
||||||
|
<DisconnectOutlined />
|
||||||
|
</a>
|
||||||
|
</Tooltip>
|
||||||
|
) : (
|
||||||
|
<Tooltip title="绑定设备">
|
||||||
|
<a style={{ color: '#1890ff' }} onClick={() => onBind?.(record)}>
|
||||||
|
<LinkOutlined />
|
||||||
|
</a>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
<Tooltip title="编辑">
|
||||||
|
<a onClick={() => onEdit?.(record)}>
|
||||||
|
<EditOutlined />
|
||||||
|
</a>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip title="删除">
|
||||||
|
<a style={{ color: '#ff4d4f' }} onClick={() => onDelete?.(record)}>
|
||||||
|
<DeleteOutlined />
|
||||||
|
</a>
|
||||||
|
</Tooltip>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ProTable<any>
|
||||||
|
rowKey="id"
|
||||||
|
headerTitle="物联网卡列表"
|
||||||
|
actionRef={actionRef}
|
||||||
|
request={(p) => iotCardApi.list({ page: p.current, limit: p.pageSize, ...params })}
|
||||||
|
columns={columns}
|
||||||
|
search={false}
|
||||||
|
scroll={{ x: 2000 }}
|
||||||
|
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export default IotCardTable;
|
||||||
@@ -0,0 +1,229 @@
|
|||||||
|
import React, { useRef, useState, useCallback } from 'react';
|
||||||
|
import { PageContainer, ProFormText, ProFormSelect, ModalForm } from '@ant-design/pro-components';
|
||||||
|
import { Modal, message } from 'antd';
|
||||||
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
|
import { iotCardApi, CARRIER_OPTIONS, ENABLED_OPTIONS } from '@/services/iotCard';
|
||||||
|
import { deviceApi } from '@/services/device';
|
||||||
|
import IotCardTable, { IotCardTableRef } from './components/IotCardTable';
|
||||||
|
import IotCardForm, { IotCardFormValues } from './components/IotCardForm';
|
||||||
|
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
||||||
|
|
||||||
|
const IotCardPage: React.FC = () => {
|
||||||
|
const tableRef = useRef<IotCardTableRef>(null);
|
||||||
|
const [query, setQuery] = useState<Record<string, any>>({});
|
||||||
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
|
const [editOpen, setEditOpen] = useState(false);
|
||||||
|
const [current, setCurrent] = useState<any | null>(null);
|
||||||
|
const [bindOpen, setBindOpen] = useState(false);
|
||||||
|
const [bindRecord, setBindRecord] = useState<any | null>(null);
|
||||||
|
const [deviceOptions, setDeviceOptions] = useState<{ label: string; value: string }[]>([]);
|
||||||
|
const [deviceSearching, setDeviceSearching] = useState(false);
|
||||||
|
|
||||||
|
/** 搜索设备列表,用于绑定下拉框 */
|
||||||
|
const fetchDeviceOptions = useCallback(async (keyword?: string) => {
|
||||||
|
setDeviceSearching(true);
|
||||||
|
try {
|
||||||
|
const res = await deviceApi.deviceList({ page: 1, limit: 50, deviceSn: keyword || undefined, deviceName: keyword || undefined });
|
||||||
|
const options = (res.data || []).map((d: any) => ({
|
||||||
|
label: `${d.deviceSn}${d.deviceName ? ' - ' + d.deviceName : ''}`,
|
||||||
|
value: d.deviceSn,
|
||||||
|
}));
|
||||||
|
setDeviceOptions(options);
|
||||||
|
} catch {
|
||||||
|
setDeviceOptions([]);
|
||||||
|
} finally {
|
||||||
|
setDeviceSearching(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
/** 新增 */
|
||||||
|
const add = async (values: IotCardFormValues) => {
|
||||||
|
const hide = message.loading('保存中...');
|
||||||
|
try {
|
||||||
|
await iotCardApi.saveOrUpdate(values as any);
|
||||||
|
message.success('新增成功');
|
||||||
|
tableRef.current?.reload();
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
message.error('新增失败');
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 编辑 */
|
||||||
|
const edit = async (values: IotCardFormValues) => {
|
||||||
|
const hide = message.loading('保存中...');
|
||||||
|
try {
|
||||||
|
await iotCardApi.saveOrUpdate({ ...(current || {}), ...values } as any);
|
||||||
|
message.success('修改成功');
|
||||||
|
tableRef.current?.reload();
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
message.error('修改失败');
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 删除 */
|
||||||
|
const del = async (record: any) => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: `确认删除物联网卡 [${record.cardNumber}]?`,
|
||||||
|
onOk: async () => {
|
||||||
|
const hide = message.loading('正在删除...');
|
||||||
|
try {
|
||||||
|
await iotCardApi.remove(record.id);
|
||||||
|
message.success('删除成功');
|
||||||
|
tableRef.current?.reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error('删除失败');
|
||||||
|
} finally {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 绑定设备 */
|
||||||
|
const handleBind = async (values: { deviceSn: string }) => {
|
||||||
|
if (!bindRecord) return false;
|
||||||
|
const hide = message.loading('绑定中...');
|
||||||
|
try {
|
||||||
|
await iotCardApi.bindDevice(bindRecord.id, values.deviceSn);
|
||||||
|
message.success('绑定成功');
|
||||||
|
tableRef.current?.reload();
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
message.error('绑定失败');
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 解绑设备 */
|
||||||
|
const handleUnbind = (record: any) => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: `确认解绑设备 [${record.deviceSn}]?`,
|
||||||
|
onOk: async () => {
|
||||||
|
const hide = message.loading('解绑中...');
|
||||||
|
try {
|
||||||
|
await iotCardApi.unbindDevice(record.id);
|
||||||
|
message.success('解绑成功');
|
||||||
|
tableRef.current?.reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error('解绑失败');
|
||||||
|
} finally {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageContainer header={{ title: '物联网卡管理' }}>
|
||||||
|
{/* 搜索栏 */}
|
||||||
|
<SearchBarPlus
|
||||||
|
defaultCollapsed
|
||||||
|
split
|
||||||
|
span={6}
|
||||||
|
onTenantChanged={() => tableRef.current?.reload()}
|
||||||
|
showTenant={true}
|
||||||
|
onFinish={async (values) => setQuery(values)}
|
||||||
|
>
|
||||||
|
<ProFormText name="cardNumber" label="卡号" />
|
||||||
|
<ProFormText name="msisdn" label="MSISDN" />
|
||||||
|
<ProFormText name="deviceSn" label="设备SN" />
|
||||||
|
<ProFormSelect name="carrier" label="运营商" options={CARRIER_OPTIONS} />
|
||||||
|
<ProFormSelect name="enabled" label="启用状态" options={ENABLED_OPTIONS} />
|
||||||
|
</SearchBarPlus>
|
||||||
|
|
||||||
|
{/* 操作栏 */}
|
||||||
|
<ActionBar
|
||||||
|
left={
|
||||||
|
<GradientButton
|
||||||
|
size="middle"
|
||||||
|
type="primary"
|
||||||
|
icon={<PlusOutlined />}
|
||||||
|
onClick={() => setCreateOpen(true)}
|
||||||
|
>
|
||||||
|
新增
|
||||||
|
</GradientButton>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 表格 */}
|
||||||
|
<GlassCard>
|
||||||
|
<IotCardTable
|
||||||
|
ref={tableRef}
|
||||||
|
params={query}
|
||||||
|
onEdit={(r) => {
|
||||||
|
setCurrent(r);
|
||||||
|
setEditOpen(true);
|
||||||
|
}}
|
||||||
|
onDelete={(r) => del(r)}
|
||||||
|
onBind={(r) => {
|
||||||
|
setBindRecord(r);
|
||||||
|
setBindOpen(true);
|
||||||
|
}}
|
||||||
|
onUnbind={(r) => handleUnbind(r)}
|
||||||
|
/>
|
||||||
|
</GlassCard>
|
||||||
|
|
||||||
|
{/* 新增表单 */}
|
||||||
|
<IotCardForm title="新增物联网卡" visible={createOpen} onVisibleChange={setCreateOpen} onFinish={add} />
|
||||||
|
|
||||||
|
{/* 编辑表单 */}
|
||||||
|
<IotCardForm
|
||||||
|
title="编辑物联网卡"
|
||||||
|
visible={editOpen}
|
||||||
|
onVisibleChange={(v) => {
|
||||||
|
setEditOpen(v);
|
||||||
|
if (!v) setCurrent(null);
|
||||||
|
}}
|
||||||
|
onFinish={edit}
|
||||||
|
initialValues={current || {}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 绑定设备弹窗 */}
|
||||||
|
<ModalForm<{ deviceSn: string }>
|
||||||
|
title={`绑定设备 - 卡号: ${bindRecord?.cardNumber || ''}`}
|
||||||
|
visible={bindOpen}
|
||||||
|
onVisibleChange={(v) => {
|
||||||
|
setBindOpen(v);
|
||||||
|
if (!v) {
|
||||||
|
setBindRecord(null);
|
||||||
|
setDeviceOptions([]);
|
||||||
|
}
|
||||||
|
if (v) {
|
||||||
|
// 弹窗打开时加载设备列表
|
||||||
|
fetchDeviceOptions();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onFinish={handleBind}
|
||||||
|
modalProps={{ destroyOnClose: true }}
|
||||||
|
>
|
||||||
|
<ProFormSelect
|
||||||
|
name="deviceSn"
|
||||||
|
label="选择设备"
|
||||||
|
rules={[{ required: true, message: '请选择要绑定的设备' }]}
|
||||||
|
width="lg"
|
||||||
|
placeholder="输入设备SN或名称搜索"
|
||||||
|
showSearch
|
||||||
|
options={deviceOptions}
|
||||||
|
fieldProps={{
|
||||||
|
loading: deviceSearching,
|
||||||
|
filterOption: false,
|
||||||
|
onSearch: (val: string) => fetchDeviceOptions(val),
|
||||||
|
notFoundContent: deviceSearching ? '加载中...' : '暂无设备',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ModalForm>
|
||||||
|
</PageContainer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default IotCardPage;
|
||||||
@@ -131,7 +131,8 @@ const StatusTimeoutConfigPage: React.FC = () => {
|
|||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
try {
|
try {
|
||||||
const values = await form.validateFields();
|
const values = await form.validateFields();
|
||||||
await ordersApi.saveStatusTimeoutConfig({ ...editingRecord, ...values });
|
const { notifyPhoneList, enabledStatus, createTime, updateTime, ...rest } = editingRecord || {} as any;
|
||||||
|
await ordersApi.saveStatusTimeoutConfig({ ...rest, ...values });
|
||||||
message.success('保存成功,缓存已自动刷新');
|
message.success('保存成功,缓存已自动刷新');
|
||||||
setModalVisible(false);
|
setModalVisible(false);
|
||||||
loadData();
|
loadData();
|
||||||
|
|||||||
+160
-77
@@ -6,7 +6,8 @@ import {
|
|||||||
ProFormTextArea,
|
ProFormTextArea,
|
||||||
ProFormSelect,
|
ProFormSelect,
|
||||||
} from '@ant-design/pro-components';
|
} from '@ant-design/pro-components';
|
||||||
import { message } from 'antd';
|
import { message, Button, InputNumber, Input, Space, Table, Tooltip } from 'antd';
|
||||||
|
import { PlusOutlined, DeleteOutlined, QuestionCircleOutlined } from '@ant-design/icons';
|
||||||
import { ordersApi } from '@/services/orders';
|
import { ordersApi } from '@/services/orders';
|
||||||
|
|
||||||
export const STATUS_OPTIONS = [
|
export const STATUS_OPTIONS = [
|
||||||
@@ -14,11 +15,16 @@ export const STATUS_OPTIONS = [
|
|||||||
{ label: '禁用', value: 0 },
|
{ label: '禁用', value: 0 },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export type ClipMappingItem = {
|
||||||
|
slot: string;
|
||||||
|
fileIndex: number | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
export type VideoTemplateFormValues = {
|
export type VideoTemplateFormValues = {
|
||||||
id?: number;
|
id?: number;
|
||||||
templateId?: string;
|
templateId?: string;
|
||||||
templateName?: string;
|
templateName?: string;
|
||||||
name?: string; // 兼容旧字段
|
name?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
config?: string;
|
config?: string;
|
||||||
status?: number;
|
status?: number;
|
||||||
@@ -32,6 +38,31 @@ interface VideoTemplateFormProps {
|
|||||||
initialValues?: Partial<VideoTemplateFormValues>;
|
initialValues?: Partial<VideoTemplateFormValues>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parseConfigToMappings = (config?: string): ClipMappingItem[] => {
|
||||||
|
if (!config || config.trim() === '{}' || config.trim() === '[]') return [];
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(config);
|
||||||
|
if (Array.isArray(parsed)) {
|
||||||
|
return parsed.map((item: any) => ({
|
||||||
|
slot: String(item.slot ?? ''),
|
||||||
|
fileIndex: item.fileIndex,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
} catch {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const mappingsToConfig = (mappings: ClipMappingItem[]): string => {
|
||||||
|
if (!mappings || mappings.length === 0) return '{}';
|
||||||
|
const cleaned = mappings
|
||||||
|
.filter((m) => m.slot && m.fileIndex !== undefined)
|
||||||
|
.map((m) => ({ slot: m.slot, fileIndex: m.fileIndex }));
|
||||||
|
if (cleaned.length === 0) return '{}';
|
||||||
|
return JSON.stringify(cleaned, null, 2);
|
||||||
|
};
|
||||||
|
|
||||||
const VideoTemplateForm: React.FC<VideoTemplateFormProps> = ({
|
const VideoTemplateForm: React.FC<VideoTemplateFormProps> = ({
|
||||||
title,
|
title,
|
||||||
visible,
|
visible,
|
||||||
@@ -40,37 +71,107 @@ const VideoTemplateForm: React.FC<VideoTemplateFormProps> = ({
|
|||||||
initialValues,
|
initialValues,
|
||||||
}) => {
|
}) => {
|
||||||
const formRef = useRef<any>();
|
const formRef = useRef<any>();
|
||||||
|
const [mappings, setMappings] = React.useState<ClipMappingItem[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (visible && initialValues) {
|
if (visible) {
|
||||||
// 延迟设置,确保表单已经渲染
|
setMappings(parseConfigToMappings(initialValues?.config));
|
||||||
|
if (initialValues) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// 处理字段兼容性
|
formRef.current?.setFieldsValue({
|
||||||
const values = {
|
|
||||||
...initialValues,
|
...initialValues,
|
||||||
templateName: initialValues.templateName || initialValues.name,
|
templateName: initialValues.templateName || initialValues.name,
|
||||||
config: initialValues.config || '{}', // 确保config有默认值
|
});
|
||||||
};
|
|
||||||
formRef.current?.setFieldsValue(values);
|
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
setMappings([]);
|
||||||
|
}
|
||||||
}, [visible, initialValues]);
|
}, [visible, initialValues]);
|
||||||
|
|
||||||
|
const handleAddMapping = () => {
|
||||||
|
setMappings([...mappings, { slot: '', fileIndex: undefined }]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRemoveMapping = (index: number) => {
|
||||||
|
setMappings(mappings.filter((_, i) => i !== index));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMappingChange = (index: number, field: keyof ClipMappingItem, value: any) => {
|
||||||
|
const next = [...mappings];
|
||||||
|
next[index] = { ...next[index], [field]: value };
|
||||||
|
setMappings(next);
|
||||||
|
};
|
||||||
|
|
||||||
const handleFinish = async (values: VideoTemplateFormValues) => {
|
const handleFinish = async (values: VideoTemplateFormValues) => {
|
||||||
try {
|
try {
|
||||||
// 确保兼容性
|
const valid = mappings.filter((m) => m.slot && m.fileIndex !== undefined);
|
||||||
const submitValues = {
|
const slots = valid.map((m) => m.slot);
|
||||||
|
if (new Set(slots).size !== slots.length) {
|
||||||
|
message.error('存在重复的槽位号,请检查');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return await onFinish({
|
||||||
...values,
|
...values,
|
||||||
name: values.templateName, // 同时设置name字段
|
name: values.templateName,
|
||||||
};
|
config: mappingsToConfig(mappings),
|
||||||
const result = await onFinish(submitValues);
|
});
|
||||||
return result;
|
} catch {
|
||||||
} catch (error) {
|
|
||||||
message.error('操作失败');
|
message.error('操作失败');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
title: (
|
||||||
|
<Space>
|
||||||
|
槽位号
|
||||||
|
<Tooltip title="阿里云剪辑模板中的素材槽位编号,如 1、2、201">
|
||||||
|
<QuestionCircleOutlined style={{ color: '#999' }} />
|
||||||
|
</Tooltip>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
dataIndex: 'slot',
|
||||||
|
width: 140,
|
||||||
|
render: (_: any, record: ClipMappingItem, index: number) => (
|
||||||
|
<Input
|
||||||
|
value={record.slot}
|
||||||
|
placeholder="如: 1"
|
||||||
|
onChange={(e) => handleMappingChange(index, 'slot', e.target.value)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: (
|
||||||
|
<Space>
|
||||||
|
素材序号
|
||||||
|
<Tooltip title="对应订单素材文件列表中的位置序号(从0开始)">
|
||||||
|
<QuestionCircleOutlined style={{ color: '#999' }} />
|
||||||
|
</Tooltip>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
dataIndex: 'fileIndex',
|
||||||
|
width: 140,
|
||||||
|
render: (_: any, record: ClipMappingItem, index: number) => (
|
||||||
|
<InputNumber
|
||||||
|
value={record.fileIndex}
|
||||||
|
min={0}
|
||||||
|
placeholder="如: 0"
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
onChange={(val) => handleMappingChange(index, 'fileIndex', val)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 60,
|
||||||
|
render: (_: any, __: any, index: number) => (
|
||||||
|
<Button type="link" danger icon={<DeleteOutlined />} onClick={() => handleRemoveMapping(index)} />
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalForm<VideoTemplateFormValues>
|
<ModalForm<VideoTemplateFormValues>
|
||||||
title={title}
|
title={title}
|
||||||
@@ -79,15 +180,8 @@ const VideoTemplateForm: React.FC<VideoTemplateFormProps> = ({
|
|||||||
formRef={formRef}
|
formRef={formRef}
|
||||||
onVisibleChange={onVisibleChange}
|
onVisibleChange={onVisibleChange}
|
||||||
onFinish={handleFinish}
|
onFinish={handleFinish}
|
||||||
initialValues={{
|
initialValues={{ status: 1, ...initialValues }}
|
||||||
status: 1, // 默认启用
|
modalProps={{ destroyOnClose: true, maskClosable: false }}
|
||||||
config: '{}', // 默认空JSON对象
|
|
||||||
...initialValues,
|
|
||||||
}}
|
|
||||||
modalProps={{
|
|
||||||
destroyOnClose: true,
|
|
||||||
maskClosable: false,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<ProForm.Group title="基本信息">
|
<ProForm.Group title="基本信息">
|
||||||
<ProFormText
|
<ProFormText
|
||||||
@@ -97,10 +191,7 @@ const VideoTemplateForm: React.FC<VideoTemplateFormProps> = ({
|
|||||||
placeholder="请输入模板ID"
|
placeholder="请输入模板ID"
|
||||||
rules={[
|
rules={[
|
||||||
{ required: true, message: '请输入模板ID' },
|
{ required: true, message: '请输入模板ID' },
|
||||||
{
|
{ pattern: /^[a-zA-Z0-9_-]+$/, message: '模板ID只能包含字母、数字、下划线和横线' },
|
||||||
pattern: /^[a-zA-Z0-9_-]+$/,
|
|
||||||
message: '模板ID只能包含字母、数字、下划线和横线'
|
|
||||||
}
|
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<ProFormText
|
<ProFormText
|
||||||
@@ -110,7 +201,7 @@ const VideoTemplateForm: React.FC<VideoTemplateFormProps> = ({
|
|||||||
placeholder="请输入模板名称"
|
placeholder="请输入模板名称"
|
||||||
rules={[
|
rules={[
|
||||||
{ required: true, message: '请输入模板名称' },
|
{ required: true, message: '请输入模板名称' },
|
||||||
{ max: 50, message: '模板名称不能超过50个字符' }
|
{ max: 50, message: '模板名称不能超过50个字符' },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<ProFormSelect
|
<ProFormSelect
|
||||||
@@ -122,59 +213,51 @@ const VideoTemplateForm: React.FC<VideoTemplateFormProps> = ({
|
|||||||
/>
|
/>
|
||||||
</ProForm.Group>
|
</ProForm.Group>
|
||||||
|
|
||||||
<ProForm.Group title="详细配置">
|
<ProForm.Group title="模板描述">
|
||||||
<ProFormTextArea
|
<ProFormTextArea
|
||||||
name="description"
|
name="description"
|
||||||
label="模板描述"
|
label="描述"
|
||||||
width="xl"
|
width="xl"
|
||||||
placeholder="请输入模板描述"
|
placeholder="请输入模板描述"
|
||||||
fieldProps={{
|
fieldProps={{ rows: 3, maxLength: 200, showCount: true }}
|
||||||
rows: 4,
|
|
||||||
maxLength: 200,
|
|
||||||
showCount: true,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<ProFormTextArea
|
|
||||||
name="config"
|
|
||||||
label="模板配置"
|
|
||||||
width="xl"
|
|
||||||
placeholder='请输入JSON格式的模板配置,例如: {"key": "value"}'
|
|
||||||
tooltip="请输入有效的JSON格式配置,默认为空对象 {}"
|
|
||||||
fieldProps={{
|
|
||||||
rows: 8,
|
|
||||||
maxLength: 2000,
|
|
||||||
showCount: true,
|
|
||||||
style: { fontFamily: 'monospace' },
|
|
||||||
onBlur: (e) => {
|
|
||||||
// 格式化JSON
|
|
||||||
const value = e.target.value;
|
|
||||||
if (value) {
|
|
||||||
try {
|
|
||||||
const json = JSON.parse(value);
|
|
||||||
const formatted = JSON.stringify(json, null, 2);
|
|
||||||
formRef.current?.setFieldValue('config', formatted);
|
|
||||||
} catch (error) {
|
|
||||||
// 格式化失败,保持原样
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
rules={[
|
|
||||||
{ required: true, message: '请输入模板配置' },
|
|
||||||
{
|
|
||||||
validator: async (_, value) => {
|
|
||||||
if (value) {
|
|
||||||
try {
|
|
||||||
JSON.parse(value);
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error('请输入有效的JSON格式');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
/>
|
/>
|
||||||
</ProForm.Group>
|
</ProForm.Group>
|
||||||
|
|
||||||
|
<div style={{ marginBottom: 24 }}>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12 }}>
|
||||||
|
<Space>
|
||||||
|
<span style={{ fontWeight: 500, fontSize: 16 }}>素材槽位映射配置</span>
|
||||||
|
<Tooltip title="配置阿里云剪辑模板槽位与订单素材文件的对应关系。不配置则使用系统默认映射逻辑">
|
||||||
|
<QuestionCircleOutlined style={{ color: '#999' }} />
|
||||||
|
</Tooltip>
|
||||||
|
</Space>
|
||||||
|
<Button type="dashed" icon={<PlusOutlined />} onClick={handleAddMapping}>
|
||||||
|
添加映射
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{mappings.length > 0 ? (
|
||||||
|
<Table
|
||||||
|
columns={columns}
|
||||||
|
dataSource={mappings}
|
||||||
|
rowKey={(_, index) => String(index)}
|
||||||
|
pagination={false}
|
||||||
|
size="small"
|
||||||
|
bordered
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
border: '1px dashed #d9d9d9',
|
||||||
|
borderRadius: 6,
|
||||||
|
padding: '24px 0',
|
||||||
|
textAlign: 'center',
|
||||||
|
color: '#999',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
暂无映射配置,将使用系统默认映射逻辑。点击"添加映射"开始配置
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</ModalForm>
|
</ModalForm>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
import { request } from 'umi';
|
||||||
|
|
||||||
|
/** 物联网卡数据项 */
|
||||||
|
export interface IotCardItem {
|
||||||
|
id?: number;
|
||||||
|
cardNumber?: string;
|
||||||
|
msisdn?: string;
|
||||||
|
imsi?: string;
|
||||||
|
carrier?: number;
|
||||||
|
packageType?: string;
|
||||||
|
enabled?: number;
|
||||||
|
deviceSn?: string;
|
||||||
|
deviceName?: string;
|
||||||
|
activationTime?: string;
|
||||||
|
expirationTime?: string;
|
||||||
|
tenantId?: string;
|
||||||
|
remark?: string;
|
||||||
|
createTime?: string;
|
||||||
|
updateTime?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 运营商映射 */
|
||||||
|
export const CARRIER_MAP: Record<number, string> = {
|
||||||
|
1: '中国移动',
|
||||||
|
2: '中国联通',
|
||||||
|
3: '中国电信',
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 运营商选项 */
|
||||||
|
export const CARRIER_OPTIONS = [
|
||||||
|
{ label: '中国移动', value: 1 },
|
||||||
|
{ label: '中国联通', value: 2 },
|
||||||
|
{ label: '中国电信', value: 3 },
|
||||||
|
];
|
||||||
|
|
||||||
|
/** 启用状态选项 */
|
||||||
|
export const ENABLED_OPTIONS = [
|
||||||
|
{ label: '启用', value: 1 },
|
||||||
|
{ label: '停用', value: 0 },
|
||||||
|
];
|
||||||
|
|
||||||
|
export const iotCardApi = {
|
||||||
|
/** 分页列表 */
|
||||||
|
list: async (params: { page?: number; limit?: number; [k: string]: any }) => {
|
||||||
|
const res = await request('/api-device/iot-card', { method: 'GET', params });
|
||||||
|
return { data: (res as any).data, total: (res as any).count } as { data: IotCardItem[]; total: number };
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 查询详情 */
|
||||||
|
getById: async (id: number) => {
|
||||||
|
const res = await request(`/api-device/iot-card/${id}`, { method: 'GET' });
|
||||||
|
return (res as any).data || res;
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 新增/更新 */
|
||||||
|
saveOrUpdate: async (data: Partial<IotCardItem>) => {
|
||||||
|
const res = await request('/api-device/iot-card', { method: 'POST', data });
|
||||||
|
return (res as any).data || res;
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 删除 */
|
||||||
|
remove: async (id: number) => {
|
||||||
|
const res = await request(`/api-device/iot-card/${id}`, { method: 'DELETE' });
|
||||||
|
return (res as any).data || res;
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 绑定设备 */
|
||||||
|
bindDevice: async (id: number, deviceSn: string) => {
|
||||||
|
const res = await request(`/api-device/iot-card/${id}/bind`, { method: 'POST', params: { deviceSn } });
|
||||||
|
return (res as any).data || res;
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 解绑设备 */
|
||||||
|
unbindDevice: async (id: number) => {
|
||||||
|
const res = await request(`/api-device/iot-card/${id}/unbind`, { method: 'POST' });
|
||||||
|
return (res as any).data || res;
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 启用/停用 */
|
||||||
|
toggleEnabled: async (id: number, enabled: number) => {
|
||||||
|
const res = await request(`/api-device/iot-card/${id}/toggle`, { method: 'PUT', params: { enabled } });
|
||||||
|
return (res as any).data || res;
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -9,6 +9,17 @@ export default [
|
|||||||
component: '@/pages/user/Login',
|
component: '@/pages/user/Login',
|
||||||
layout: false,
|
layout: false,
|
||||||
},
|
},
|
||||||
|
// 客户端Pad页面 - 无布局
|
||||||
|
{
|
||||||
|
path: '/client/login',
|
||||||
|
component: '@/pages/client/Login',
|
||||||
|
layout: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/client',
|
||||||
|
component: '@/pages/client',
|
||||||
|
layout: false,
|
||||||
|
},
|
||||||
// 主应用 - 无菜单布局
|
// 主应用 - 无菜单布局
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,567 @@
|
|||||||
|
# 客户端 Pad 页面实现方案
|
||||||
|
|
||||||
|
## 1. 需求概述
|
||||||
|
|
||||||
|
为 Pad 端客户提供一个独立的设备监控页面,用户通过设备 SN 登录后,实时查看设备状态、航线信息和三维模型,并可对设备进行基础操控。
|
||||||
|
|
||||||
|
### 核心功能
|
||||||
|
- **设备 SN 登录**:输入设备 SN 号直接登录,无需账号密码
|
||||||
|
- **SSE 实时订阅**:登录后通过 SSE 持续接收设备上报消息
|
||||||
|
- **三栏布局**:左侧航线列表 / 中间三维模型 / 右侧设备信息与操控
|
||||||
|
|
||||||
|
### 参考设计
|
||||||
|
参见 `public/7.png`,整体为深色主题三栏布局,适配 Pad 横屏。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 技术方案
|
||||||
|
|
||||||
|
### 2.1 技术栈(复用现有项目)
|
||||||
|
|
||||||
|
| 层面 | 技术 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| 框架 | UmiJS 3.5 + React 18 | 与现有项目一致 |
|
||||||
|
| UI | Ant Design 5.x | 复用现有主题配置 |
|
||||||
|
| 3D 引擎 | Cesium 1.110 | 复用现有 CesiumContainer |
|
||||||
|
| SSE | Fetch + ReadableStream | 复用现有 `useDeviceSSE` 模式 |
|
||||||
|
| 样式 | Less + CSS Modules | 深色主题,适配 Pad |
|
||||||
|
|
||||||
|
### 2.2 页面路由
|
||||||
|
|
||||||
|
```
|
||||||
|
/client/login → 设备 SN 登录页(无布局,layout: false)
|
||||||
|
/client → 客户端主页(独立布局,layout: false)
|
||||||
|
```
|
||||||
|
|
||||||
|
在 `config/routes.ts` 中新增:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 客户端 Pad 页面 - 无布局
|
||||||
|
{
|
||||||
|
path: '/client/login',
|
||||||
|
component: '@/pages/client/Login',
|
||||||
|
layout: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/client',
|
||||||
|
component: '@/pages/client',
|
||||||
|
layout: false,
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2.3 认证方案
|
||||||
|
|
||||||
|
客户端采用轻量级方案:Gateway 放行 `/client/**` 路径 + 后端 SN 校验,无需 JWT 认证。
|
||||||
|
|
||||||
|
```
|
||||||
|
用户输入设备 SN → 调用后端校验接口 → 返回设备信息 → 存入 sessionStorage → 进入主页
|
||||||
|
```
|
||||||
|
|
||||||
|
**后端接口(需新增)**:
|
||||||
|
|
||||||
|
```
|
||||||
|
GET /api-device/client/auth/check?deviceSn=xxx
|
||||||
|
Response: { code: 0, data: { deviceSn: string, deviceName: string, deviceType: number } }
|
||||||
|
```
|
||||||
|
|
||||||
|
**前端存储**:
|
||||||
|
- `sessionStorage.setItem('client_device_sn', deviceSn)` — 关闭标签页即失效
|
||||||
|
- `sessionStorage.setItem('client_device_info', JSON.stringify(deviceInfo))`
|
||||||
|
|
||||||
|
**安全白名单**:在 device-center 的 `application.yml` 中配置 `zlt.security.ignore.httpUrls: /client/**`,Gateway 层面放行。
|
||||||
|
|
||||||
|
**后续请求**:所有客户端 API 通过 `?deviceSn=xxx` 参数传递设备标识,无需 Authorization header。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 页面结构设计
|
||||||
|
|
||||||
|
### 3.1 目录结构
|
||||||
|
|
||||||
|
```
|
||||||
|
src/pages/client/
|
||||||
|
├── Login/
|
||||||
|
│ ├── index.tsx # SN 登录页
|
||||||
|
│ └── index.less
|
||||||
|
├── index.tsx # 主页入口(三栏布局容器)
|
||||||
|
├── index.less # 主页样式
|
||||||
|
├── components/
|
||||||
|
│ ├── LeftPanel/ # 左侧 - 航线列表
|
||||||
|
│ │ ├── index.tsx
|
||||||
|
│ │ ├── index.less
|
||||||
|
│ │ └── RouteItem.tsx # 航线列表项
|
||||||
|
│ ├── CenterView/ # 中间 - 三维模型视图
|
||||||
|
│ │ ├── index.tsx
|
||||||
|
│ │ └── index.less
|
||||||
|
│ ├── RightPanel/ # 右侧 - 设备信息与操控
|
||||||
|
│ │ ├── index.tsx
|
||||||
|
│ │ ├── index.less
|
||||||
|
│ │ ├── DeviceStatus.tsx # 设备状态卡片
|
||||||
|
│ │ ├── DeviceControl.tsx # 设备操控面板
|
||||||
|
│ │ └── DeviceTelemetry.tsx # 遥测数据展示
|
||||||
|
│ └── SSEProvider.tsx # SSE 连接管理(Context)
|
||||||
|
├── hooks/
|
||||||
|
│ ├── useClientAuth.ts # 客户端认证 hook
|
||||||
|
│ ├── useClientSSE.ts # SSE 订阅 hook(复用 useDeviceSSE 模式)
|
||||||
|
│ └── useClientRoutes.ts # 航线数据 hook
|
||||||
|
├── services/
|
||||||
|
│ └── clientApi.ts # 客户端专用 API
|
||||||
|
└── types/
|
||||||
|
└── index.ts # 类型定义
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.2 整体布局
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────┐
|
||||||
|
│ 客户端主页 (100vw × 100vh) │
|
||||||
|
├────────────┬──────────────────────────┬─────────────────┤
|
||||||
|
│ │ │ │
|
||||||
|
│ 左侧面板 │ 中间三维视图 │ 右侧面板 │
|
||||||
|
│ 280px │ flex: 1 │ 320px │
|
||||||
|
│ │ │ │
|
||||||
|
│ ┌──────┐ │ ┌──────────────────┐ │ ┌───────────┐ │
|
||||||
|
│ │航线列表│ │ │ │ │ │ 设备状态 │ │
|
||||||
|
│ │ │ │ │ Cesium 3D │ │ │ │ │
|
||||||
|
│ │ 航线1 │ │ │ 模型 + 航线 │ │ ├───────────┤ │
|
||||||
|
│ │ 航线2 │ │ │ 轨迹渲染 │ │ │ 遥测数据 │ │
|
||||||
|
│ │ 航线3 │ │ │ │ │ │ │ │
|
||||||
|
│ │ ... │ │ │ │ │ ├───────────┤ │
|
||||||
|
│ │ │ │ └──────────────────┘ │ │ 设备操控 │ │
|
||||||
|
│ └──────┘ │ │ └───────────┘ │
|
||||||
|
│ │ │ │
|
||||||
|
├────────────┴──────────────────────────┴─────────────────┤
|
||||||
|
│ 底部状态栏(SSE 连接状态) │
|
||||||
|
└─────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 模块详细设计
|
||||||
|
|
||||||
|
### 4.1 登录页(Login)
|
||||||
|
|
||||||
|
**功能**:
|
||||||
|
- 单一输入框,输入设备 SN
|
||||||
|
- 点击登录调用认证接口
|
||||||
|
- 验证通过后跳转 `/client`
|
||||||
|
- 深色主题,居中卡片布局,适配 Pad
|
||||||
|
|
||||||
|
**交互流程**:
|
||||||
|
```
|
||||||
|
输入 SN → 点击登录 → loading →
|
||||||
|
成功 → 存储 token/deviceSn → history.push('/client')
|
||||||
|
失败 → 提示"设备不存在或未绑定"
|
||||||
|
```
|
||||||
|
|
||||||
|
**核心代码结构**:
|
||||||
|
```tsx
|
||||||
|
// pages/client/Login/index.tsx
|
||||||
|
const ClientLogin: React.FC = () => {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const onSubmit = async (values: { deviceSn: string }) => {
|
||||||
|
setLoading(true);
|
||||||
|
const res = await clientApi.loginBySn(values.deviceSn);
|
||||||
|
if (res.code === 0) {
|
||||||
|
sessionStorage.setItem('client_token', res.data.token);
|
||||||
|
sessionStorage.setItem('client_device_sn', res.data.deviceSn);
|
||||||
|
history.push('/client');
|
||||||
|
} else {
|
||||||
|
message.error(res.msg || '设备验证失败');
|
||||||
|
}
|
||||||
|
setLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.loginContainer}>
|
||||||
|
<div className={styles.loginCard}>
|
||||||
|
<img src={logo} className={styles.logo} />
|
||||||
|
<h2>设备客户端</h2>
|
||||||
|
<Form onFinish={onSubmit}>
|
||||||
|
<Form.Item name="deviceSn" rules={[{ required: true, message: '请输入设备SN' }]}>
|
||||||
|
<Input prefix={<ApiOutlined />} placeholder="请输入设备SN号" size="large" />
|
||||||
|
</Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit" loading={loading} block size="large">
|
||||||
|
登录
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 SSE 连接管理(SSEProvider)
|
||||||
|
|
||||||
|
复用现有项目 `useDeviceSSE` 的 Fetch + ReadableStream 模式,通过 React Context 向子组件分发实时数据。
|
||||||
|
|
||||||
|
**SSE 订阅地址(复用现有)**:
|
||||||
|
```
|
||||||
|
GET /api-device/device/sse/events?deviceSn={sn}
|
||||||
|
Header: Authorization: Bearer {client_token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**事件类型**:
|
||||||
|
| 事件名 | 说明 | 数据结构 |
|
||||||
|
|--------|------|----------|
|
||||||
|
| `device_status` | 设备在线/离线状态 | `{ status: 0\|1, deviceSn }` |
|
||||||
|
| `telemetry` | 遥测数据(经纬度、高度、速度、电量等) | `{ lat, lng, alt, speed, battery, ... }` |
|
||||||
|
| `mission_status` | 任务执行状态 | `{ missionId, status, progress }` |
|
||||||
|
| `device_log` | 设备日志 | `{ level, message, timestamp }` |
|
||||||
|
|
||||||
|
**Context 结构**:
|
||||||
|
```tsx
|
||||||
|
// components/SSEProvider.tsx
|
||||||
|
interface SSEContextValue {
|
||||||
|
connected: boolean; // SSE 连接状态
|
||||||
|
deviceStatus: DeviceStatus; // 设备状态
|
||||||
|
telemetry: TelemetryData; // 最新遥测数据
|
||||||
|
missionStatus: MissionStatus; // 任务状态
|
||||||
|
logs: DeviceLog[]; // 设备日志(最近 100 条)
|
||||||
|
}
|
||||||
|
|
||||||
|
const SSEContext = createContext<SSEContextValue>(defaultValue);
|
||||||
|
|
||||||
|
export const SSEProvider: React.FC<{ deviceSn: string; token: string }> = ({ deviceSn, token, children }) => {
|
||||||
|
// 复用 useDeviceSSE 的 fetch + ReadableStream 模式
|
||||||
|
// 自动重连机制(3s/6s/12s 指数退避,最大 30s)
|
||||||
|
// 解析 SSE 事件并更新 state
|
||||||
|
// 通过 Context.Provider 向下分发
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.3 左侧面板 — 航线列表(LeftPanel)
|
||||||
|
|
||||||
|
**功能**:
|
||||||
|
- 展示当前设备绑定的所有航线
|
||||||
|
- 点击航线在中间三维视图中高亮显示轨迹
|
||||||
|
- 显示航线基本信息(名称、距离、预计时长)
|
||||||
|
- 当前执行中的航线高亮标记
|
||||||
|
|
||||||
|
**数据来源**:
|
||||||
|
```typescript
|
||||||
|
// 复用现有 API
|
||||||
|
import { getBoatRoutesByDeviceSn } from '@/services/boatRoute';
|
||||||
|
|
||||||
|
// 获取设备航线列表
|
||||||
|
const routes = await getBoatRoutesByDeviceSn(deviceSn);
|
||||||
|
```
|
||||||
|
|
||||||
|
**航线列表项展示**:
|
||||||
|
```
|
||||||
|
┌─────────────────────────┐
|
||||||
|
│ 📍 航线名称 │
|
||||||
|
│ 距离: 2.3km 时长: 15min │
|
||||||
|
│ 航点: 8个 状态: 就绪 │
|
||||||
|
└─────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
**交互**:
|
||||||
|
- 单击选中 → 中间视图渲染航线轨迹 + 相机飞到航线区域
|
||||||
|
- 选中态高亮(左侧边框 + 背景色变化)
|
||||||
|
- 执行中的航线显示进度条
|
||||||
|
|
||||||
|
### 4.4 中间视图 — 三维模型(CenterView)
|
||||||
|
|
||||||
|
**功能**:
|
||||||
|
- 加载水域三维模型(Cesium 3DTileset)
|
||||||
|
- 选中航线后在模型上渲染航线轨迹(Polyline + 航点标记)
|
||||||
|
- 实时显示设备当前位置(基于 SSE 遥测数据)
|
||||||
|
- 支持触摸手势操作(旋转、缩放、平移)
|
||||||
|
|
||||||
|
**复用现有组件**:
|
||||||
|
- `CesiumContainer` — Cesium Viewer 初始化、3DTileset 加载
|
||||||
|
- 航线轨迹渲染逻辑 — 复用 `useRouteRenderer` 中的 Polyline 绘制
|
||||||
|
|
||||||
|
**核心实现**:
|
||||||
|
```tsx
|
||||||
|
// components/CenterView/index.tsx
|
||||||
|
const CenterView: React.FC<{ selectedRoute: BoatRouteVO | null }> = ({ selectedRoute }) => {
|
||||||
|
const viewerRef = useRef<Cesium.Viewer>();
|
||||||
|
const { telemetry } = useSSEContext(); // 从 SSE Context 获取实时位置
|
||||||
|
|
||||||
|
// 1. 初始化 Cesium Viewer(复用现有配置)
|
||||||
|
// 2. 加载 3DTileset 水域模型
|
||||||
|
// 3. 选中航线时渲染轨迹
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedRoute && viewerRef.current) {
|
||||||
|
renderRouteOnMap(viewerRef.current, selectedRoute);
|
||||||
|
flyToRoute(viewerRef.current, selectedRoute);
|
||||||
|
}
|
||||||
|
}, [selectedRoute]);
|
||||||
|
|
||||||
|
// 4. 实时更新设备位置标记
|
||||||
|
useEffect(() => {
|
||||||
|
if (telemetry && viewerRef.current) {
|
||||||
|
updateDevicePosition(viewerRef.current, telemetry);
|
||||||
|
}
|
||||||
|
}, [telemetry]);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
**航线轨迹渲染**:
|
||||||
|
- 航线路径:`Cesium.PolylineGraphics`,蓝色半透明线条
|
||||||
|
- 航点标记:`Cesium.BillboardGraphics`,带序号标注
|
||||||
|
- 设备位置:动态 Entity,带方向箭头
|
||||||
|
- 选中航线时相机 `flyTo` 到航线包围盒
|
||||||
|
|
||||||
|
### 4.5 右侧面板 — 设备信息与操控(RightPanel)
|
||||||
|
|
||||||
|
右侧面板分为三个区域,纵向排列:
|
||||||
|
|
||||||
|
#### 4.5.1 设备状态卡片(DeviceStatus)
|
||||||
|
|
||||||
|
展示设备基础信息和连接状态:
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────┐
|
||||||
|
│ 🟢 在线 │
|
||||||
|
│ 设备名称: 巡检船-01 │
|
||||||
|
│ SN: 4TADL12345678 │
|
||||||
|
│ 类型: 无人船 │
|
||||||
|
│ 信号强度: ████░░ 67% │
|
||||||
|
│ SSE: 已连接 ✓ │
|
||||||
|
└─────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 4.5.2 遥测数据展示(DeviceTelemetry)
|
||||||
|
|
||||||
|
实时展示 SSE 推送的遥测数据:
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────┐
|
||||||
|
│ 📊 实时遥测 │
|
||||||
|
│ 经度: 120.3456°E │
|
||||||
|
│ 纬度: 30.1234°N │
|
||||||
|
│ 航向: 125.3° │
|
||||||
|
│ 速度: 3.2 m/s │
|
||||||
|
│ 电量: ██████░░░ 72% │
|
||||||
|
│ 水深: 4.5m │
|
||||||
|
│ 任务: 执行中 (65%) │
|
||||||
|
│ 更新: 2s 前 │
|
||||||
|
└─────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
数据从 `SSEContext.telemetry` 实时获取,每次 SSE 推送自动刷新。
|
||||||
|
|
||||||
|
#### 4.5.3 设备操控面板(DeviceControl)
|
||||||
|
|
||||||
|
提供基础设备操控功能:
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────┐
|
||||||
|
│ 🎮 设备操控 │
|
||||||
|
│ │
|
||||||
|
│ [▶ 启动任务] [⏸ 暂停] │
|
||||||
|
│ [⏹ 停止任务] [🏠 返航] │
|
||||||
|
│ │
|
||||||
|
│ ── 航线执行 ── │
|
||||||
|
│ 选择航线: [下拉选择] │
|
||||||
|
│ [▶ 执行选中航线] │
|
||||||
|
│ │
|
||||||
|
│ ── 手动控制 ── │
|
||||||
|
│ 速度: ──●────── 3.0 m/s │
|
||||||
|
│ │
|
||||||
|
└─────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
**操控 API(复用现有)**:
|
||||||
|
```typescript
|
||||||
|
// 复用 deviceApi 中的控制接口
|
||||||
|
deviceApi.takeoff(params) // 起飞/启动
|
||||||
|
deviceApi.returnToHome(deviceSn) // 返航
|
||||||
|
deviceApi.pauseMission(deviceSn) // 暂停任务
|
||||||
|
deviceApi.resumeMission(deviceSn) // 恢复任务
|
||||||
|
deviceApi.stopMission(deviceSn) // 停止任务
|
||||||
|
```
|
||||||
|
|
||||||
|
操控按钮需二次确认(Popconfirm),防止误操作。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. SSE 数据流设计
|
||||||
|
|
||||||
|
```
|
||||||
|
┌──────────┐ SSE Stream ┌──────────────┐
|
||||||
|
│ 后端设备 │ ──────────────────→ │ SSEProvider │
|
||||||
|
│ 消息推送 │ device_status │ (Context) │
|
||||||
|
│ │ telemetry │ │
|
||||||
|
│ │ mission_status │ │
|
||||||
|
└──────────┘ device_log └──────┬───────┘
|
||||||
|
│ Context
|
||||||
|
┌─────────────┼─────────────┐
|
||||||
|
▼ ▼ ▼
|
||||||
|
┌──────────┐ ┌──────────┐ ┌──────────┐
|
||||||
|
│LeftPanel │ │CenterView│ │RightPanel│
|
||||||
|
│ 任务状态 │ │ 设备位置 │ │ 遥测数据 │
|
||||||
|
│ 航线进度 │ │ 实时轨迹 │ │ 设备状态 │
|
||||||
|
└──────────┘ └──────────┘ │ 操控反馈 │
|
||||||
|
└──────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
### SSE 连接生命周期
|
||||||
|
|
||||||
|
```
|
||||||
|
登录成功 → 进入主页 → SSEProvider 挂载
|
||||||
|
→ 建立 SSE 连接(fetch + ReadableStream)
|
||||||
|
→ 持续接收事件 → 更新 Context state → 子组件响应式刷新
|
||||||
|
→ 连接断开 → 指数退避重连(3s → 6s → 12s → 最大 30s)
|
||||||
|
→ 页面卸载 → AbortController 取消连接
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. 类型定义
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// pages/client/types/index.ts
|
||||||
|
|
||||||
|
/** 客户端登录响应 */
|
||||||
|
interface ClientAuthResult {
|
||||||
|
token: string;
|
||||||
|
deviceSn: string;
|
||||||
|
deviceName: string;
|
||||||
|
deviceType: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 设备状态 */
|
||||||
|
interface DeviceStatus {
|
||||||
|
online: boolean;
|
||||||
|
deviceSn: string;
|
||||||
|
deviceName: string;
|
||||||
|
deviceType: string;
|
||||||
|
signalStrength: number;
|
||||||
|
lastHeartbeat: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 遥测数据 */
|
||||||
|
interface TelemetryData {
|
||||||
|
longitude: number;
|
||||||
|
latitude: number;
|
||||||
|
altitude: number;
|
||||||
|
heading: number;
|
||||||
|
speed: number;
|
||||||
|
battery: number;
|
||||||
|
waterDepth?: number;
|
||||||
|
timestamp: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 任务状态 */
|
||||||
|
interface MissionStatus {
|
||||||
|
missionId: string;
|
||||||
|
routeId: string;
|
||||||
|
status: 'idle' | 'running' | 'paused' | 'completed' | 'failed';
|
||||||
|
progress: number; // 0-100
|
||||||
|
currentWaypoint: number;
|
||||||
|
totalWaypoints: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 设备日志 */
|
||||||
|
interface DeviceLog {
|
||||||
|
level: 'info' | 'warn' | 'error';
|
||||||
|
message: string;
|
||||||
|
timestamp: number;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. 样式与适配
|
||||||
|
|
||||||
|
### 7.1 深色主题
|
||||||
|
|
||||||
|
与现有管理后台保持一致的深色风格:
|
||||||
|
|
||||||
|
```less
|
||||||
|
// 主色调
|
||||||
|
@bg-primary: #0a0e27; // 主背景
|
||||||
|
@bg-panel: #111631; // 面板背景
|
||||||
|
@bg-card: #1a1f42; // 卡片背景
|
||||||
|
@border-color: #2a2f52; // 边框
|
||||||
|
@text-primary: #e0e6ff; // 主文字
|
||||||
|
@text-secondary: #8b92b3; // 次要文字
|
||||||
|
@accent-blue: #3b82f6; // 强调色
|
||||||
|
@accent-green: #22c55e; // 在线/成功
|
||||||
|
@accent-red: #ef4444; // 离线/错误
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7.2 Pad 适配
|
||||||
|
|
||||||
|
- 目标设备:10-12 英寸 Pad,横屏模式(1920×1200 / 2560×1600)
|
||||||
|
- 触摸优化:按钮最小 44×44px,间距适当加大
|
||||||
|
- 字体:基础 14px,标题 18px,数据 16px
|
||||||
|
- 面板可折叠:左右面板支持点击收起/展开,最大化中间视图
|
||||||
|
- 横屏锁定提示:竖屏时显示旋转提示
|
||||||
|
|
||||||
|
### 7.3 响应式断点
|
||||||
|
|
||||||
|
```less
|
||||||
|
// Pad 横屏
|
||||||
|
@media (min-width: 1024px) and (max-width: 1920px) {
|
||||||
|
.left-panel { width: 260px; }
|
||||||
|
.right-panel { width: 300px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 大屏 Pad / 小笔记本
|
||||||
|
@media (min-width: 1920px) {
|
||||||
|
.left-panel { width: 300px; }
|
||||||
|
.right-panel { width: 360px; }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. 后端接口设计
|
||||||
|
|
||||||
|
### 8.1 客户端专用接口(需新增,Gateway 放行)
|
||||||
|
|
||||||
|
| 接口 | 方法 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| `/api-device/client/auth/check?deviceSn=xxx` | GET | 校验设备 SN,返回设备信息 |
|
||||||
|
| `/api-device/client/routes?deviceSn=xxx` | GET | 获取设备航线列表 |
|
||||||
|
| `/api-device/client/models?deviceSn=xxx` | GET | 获取设备关联的 3D 模型 |
|
||||||
|
| `/api-device/client/sse/telemetry/{deviceSn}` | GET | SSE 遥测数据订阅(text/event-stream) |
|
||||||
|
|
||||||
|
### 8.2 安全策略
|
||||||
|
|
||||||
|
- Gateway 放行 `/client/**`(通过 `zlt.security.ignore.httpUrls` 配置白名单)
|
||||||
|
- 后端通过 `deviceSn` 参数校验设备是否存在
|
||||||
|
- 客户端只能访问 `/api-device/client/**` 下的接口,不能访问管理后台接口
|
||||||
|
- 所有接口通过 `deviceSn` 限定数据范围,实现设备级数据隔离
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. 实现步骤
|
||||||
|
|
||||||
|
### Phase 1:基础框架(1-2天)
|
||||||
|
1. 创建页面目录结构和路由配置
|
||||||
|
2. 实现 SN 登录页和认证逻辑
|
||||||
|
3. 搭建三栏布局框架和深色主题样式
|
||||||
|
4. 实现 `clientApi.ts` 服务层
|
||||||
|
|
||||||
|
### Phase 2:SSE 与数据层(1天)
|
||||||
|
5. 实现 `SSEProvider` 和 `useClientSSE` hook
|
||||||
|
6. 定义类型和 Context 数据结构
|
||||||
|
7. SSE 连接管理(重连、断线提示)
|
||||||
|
|
||||||
|
### Phase 3:三栏功能实现(2-3天)
|
||||||
|
8. 左侧面板:航线列表加载与选中交互
|
||||||
|
9. 中间视图:Cesium 初始化、3DTileset 加载、航线轨迹渲染
|
||||||
|
10. 右侧面板:设备状态、遥测数据展示、操控按钮
|
||||||
|
|
||||||
|
### Phase 4:联调与优化(1-2天)
|
||||||
|
11. 对接后端 SN 登录接口
|
||||||
|
12. SSE 真实数据联调
|
||||||
|
13. Pad 触摸交互优化和横屏适配
|
||||||
|
14. 异常处理和边界情况
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 10. 注意事项
|
||||||
|
|
||||||
|
1. **安全性**:Gateway 放行 + SN 校验,客户端只能访问 `/client/**` 接口,不能越权
|
||||||
|
2. **性能**:Cesium 在 Pad 上需注意内存占用,3DTileset 按需加载,控制 Entity 数量
|
||||||
|
3. **网络**:SSE 断线重连机制必须可靠,弱网环境下给出明确提示
|
||||||
|
4. **触摸**:所有交互元素适配触摸操作,避免 hover 依赖
|
||||||
|
5. **复用**:最大程度复用现有 services、hooks、Cesium 配置,避免重复代码
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
"@types/uuid": "^9.0.0",
|
"@types/uuid": "^9.0.0",
|
||||||
"@umijs/preset-react": "^2.1.0",
|
"@umijs/preset-react": "^2.1.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"typescript": "^4.9.0"
|
"typescript": "^5.9.3"
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"path-to-regexp": "^3.3.0",
|
"path-to-regexp": "^3.3.0",
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 329 KiB |
@@ -4,6 +4,12 @@ import { ThemeProvider } from './theme';
|
|||||||
import { history } from 'umi';
|
import { history } from 'umi';
|
||||||
import { clearTenantCache, ensureTenantCacheTokenGuard } from '@/utils/tenantCache';
|
import { clearTenantCache, ensureTenantCacheTokenGuard } from '@/utils/tenantCache';
|
||||||
|
|
||||||
|
/** 判断当前是否在客户端页面 */
|
||||||
|
const isClientPath = (pathname?: string) => {
|
||||||
|
const p = pathname || (typeof window !== 'undefined' ? window.location.pathname : '');
|
||||||
|
return String(p).startsWith('/client');
|
||||||
|
};
|
||||||
|
|
||||||
export function rootContainer(container: React.ReactNode, _args?: any) {
|
export function rootContainer(container: React.ReactNode, _args?: any) {
|
||||||
return React.createElement(ThemeProvider, null, container);
|
return React.createElement(ThemeProvider, null, container);
|
||||||
}
|
}
|
||||||
@@ -16,7 +22,7 @@ export const request: any = {
|
|||||||
try {
|
try {
|
||||||
const status = (error?.response?.status ?? error?.data?.code ?? error?.data?.resp_code) as number | undefined;
|
const status = (error?.response?.status ?? error?.data?.code ?? error?.data?.resp_code) as number | undefined;
|
||||||
const unauthorized = status === 401 || status === 403;
|
const unauthorized = status === 401 || status === 403;
|
||||||
if (unauthorized) {
|
if (unauthorized && !isClientPath()) {
|
||||||
try {
|
try {
|
||||||
sessionStorage.removeItem('access_token');
|
sessionStorage.removeItem('access_token');
|
||||||
sessionStorage.removeItem('current_user');
|
sessionStorage.removeItem('current_user');
|
||||||
@@ -36,10 +42,13 @@ export const request: any = {
|
|||||||
},
|
},
|
||||||
requestInterceptors: [
|
requestInterceptors: [
|
||||||
(url: string, options: any) => {
|
(url: string, options: any) => {
|
||||||
const token = sessionStorage.getItem('access_token');
|
|
||||||
const headers: Record<string, string> = { ...(options?.headers as any) };
|
const headers: Record<string, string> = { ...(options?.headers as any) };
|
||||||
|
// 客户端页面不注入管理后台 token
|
||||||
|
if (!isClientPath()) {
|
||||||
|
const token = sessionStorage.getItem('access_token');
|
||||||
if (token) headers['Authorization'] = `Bearer ${token}`;
|
if (token) headers['Authorization'] = `Bearer ${token}`;
|
||||||
ensureTenantCacheTokenGuard();
|
ensureTenantCacheTokenGuard();
|
||||||
|
}
|
||||||
return { url, options: { ...options, headers } };
|
return { url, options: { ...options, headers } };
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -60,7 +69,7 @@ export const request: any = {
|
|||||||
const httpUnauthorized = (response.status === 401 || response.status === 403);
|
const httpUnauthorized = (response.status === 401 || response.status === 403);
|
||||||
const bizCode = (data?.resp_code ?? data?.code) as number | undefined;
|
const bizCode = (data?.resp_code ?? data?.code) as number | undefined;
|
||||||
const bizUnauthorized = bizCode === 401 || bizCode === 403 || bizCode === 40101 || bizCode === 40100;
|
const bizUnauthorized = bizCode === 401 || bizCode === 403 || bizCode === 40101 || bizCode === 40100;
|
||||||
if (httpUnauthorized || bizUnauthorized) {
|
if ((httpUnauthorized || bizUnauthorized) && !isClientPath()) {
|
||||||
try {
|
try {
|
||||||
sessionStorage.removeItem('access_token');
|
sessionStorage.removeItem('access_token');
|
||||||
sessionStorage.removeItem('current_user');
|
sessionStorage.removeItem('current_user');
|
||||||
@@ -82,8 +91,19 @@ export const request: any = {
|
|||||||
|
|
||||||
export function onRouteChange({ location }: any) {
|
export function onRouteChange({ location }: any) {
|
||||||
try {
|
try {
|
||||||
|
const pathname = String(location?.pathname || '');
|
||||||
|
// 客户端页面走自己的登录逻辑,不检查管理后台 token
|
||||||
|
if (isClientPath(pathname)) {
|
||||||
|
const isClientLogin = pathname.startsWith('/client/login');
|
||||||
|
const hasDeviceSn = sessionStorage.getItem('client_device_sn');
|
||||||
|
if (!hasDeviceSn && !isClientLogin) {
|
||||||
|
history.push('/client/login');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 管理后台登录检查
|
||||||
const token = sessionStorage.getItem('access_token');
|
const token = sessionStorage.getItem('access_token');
|
||||||
const isLoginPath = String(location?.pathname || '').startsWith('/user/login');
|
const isLoginPath = pathname.startsWith('/user/login');
|
||||||
if (!token && !isLoginPath) {
|
if (!token && !isLoginPath) {
|
||||||
history.push('/user/login');
|
history.push('/user/login');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
.container {
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: linear-gradient(135deg, #0a1628 0%, #0d2137 50%, #0a1628 100%);
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.backEntry {
|
||||||
|
position: absolute;
|
||||||
|
top: 16px;
|
||||||
|
right: 24px;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
width: 400px;
|
||||||
|
padding: 48px 40px;
|
||||||
|
background: rgba(15, 25, 40, 0.9);
|
||||||
|
border: 1px solid rgba(0, 212, 255, 0.2);
|
||||||
|
border-radius: 12px;
|
||||||
|
backdrop-filter: blur(20px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 28px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #fff;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subtitle {
|
||||||
|
font-size: 14px;
|
||||||
|
color: rgba(255, 255, 255, 0.5);
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card :global(.ant-input-affix-wrapper) {
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
border-color: rgba(255, 255, 255, 0.15);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card :global(.ant-input-affix-wrapper:hover),
|
||||||
|
.card :global(.ant-input-affix-wrapper-focused) {
|
||||||
|
border-color: #00d4ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card :global(.ant-input) {
|
||||||
|
background: transparent;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card :global(.ant-input::placeholder) {
|
||||||
|
color: rgba(255, 255, 255, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card :global(.ant-btn-primary) {
|
||||||
|
height: 48px;
|
||||||
|
font-size: 16px;
|
||||||
|
background: linear-gradient(135deg, #00d4ff, #0099cc);
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card :global(.ant-btn-primary:hover) {
|
||||||
|
background: linear-gradient(135deg, #33ddff, #00aadd);
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { Form, Input, Button, message } from 'antd';
|
||||||
|
import { ApiOutlined, DesktopOutlined } from '@ant-design/icons';
|
||||||
|
import { history } from 'umi';
|
||||||
|
import { checkDeviceSn } from '../services/clientApi';
|
||||||
|
import styles from './index.less';
|
||||||
|
|
||||||
|
const ClientLogin: React.FC = () => {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const onFinish = async (values: { deviceSn: string }) => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await checkDeviceSn(values.deviceSn.trim());
|
||||||
|
if (res.resp_code === 0 && res.data) {
|
||||||
|
sessionStorage.setItem('client_device_sn', res.data.deviceSn);
|
||||||
|
sessionStorage.setItem('client_device_info', JSON.stringify(res.data));
|
||||||
|
history.push('/client');
|
||||||
|
} else {
|
||||||
|
message.error(res.resp_msg || '设备不存在或未绑定');
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
message.error('网络异常,请重试');
|
||||||
|
}
|
||||||
|
setLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.container}>
|
||||||
|
<div className={styles.backEntry}>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
icon={<DesktopOutlined />}
|
||||||
|
onClick={() => history.push('/user/login')}
|
||||||
|
style={{ color: 'rgba(255,255,255,0.7)', fontSize: 14 }}
|
||||||
|
>
|
||||||
|
管理后台登录
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className={styles.card}>
|
||||||
|
<div className={styles.title}>设备客户端</div>
|
||||||
|
<div className={styles.subtitle}>请输入设备SN号登录</div>
|
||||||
|
<Form onFinish={onFinish} size="large">
|
||||||
|
<Form.Item name="deviceSn" rules={[{ required: true, message: '请输入设备SN' }]}>
|
||||||
|
<Input
|
||||||
|
prefix={<ApiOutlined style={{ color: 'rgba(255,255,255,0.4)' }} />}
|
||||||
|
placeholder="请输入设备SN号"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit" loading={loading} block>
|
||||||
|
登录
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ClientLogin;
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
.wrapper {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cesiumContainer {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 隐藏 Cesium 水印 */
|
||||||
|
.cesiumContainer :global(.cesium-viewer-bottom) {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cesiumContainer :global(.cesium-widget-credits) {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loadingTip {
|
||||||
|
position: absolute;
|
||||||
|
top: 60px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 14px;
|
||||||
|
background: linear-gradient(135deg, rgba(0, 100, 150, 0.85) 0%, rgba(0, 60, 100, 0.85) 100%);
|
||||||
|
padding: 10px 20px;
|
||||||
|
border-radius: 20px;
|
||||||
|
z-index: 800;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||||
|
border: 1px solid rgba(0, 240, 255, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.loadingSpinner {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||||
|
border-top-color: #00f0ff;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeActions {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 24px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
background: linear-gradient(135deg, rgba(8, 22, 36, 0.94) 0%, rgba(15, 35, 58, 0.9) 100%);
|
||||||
|
padding: 12px 18px;
|
||||||
|
border-radius: 16px;
|
||||||
|
z-index: 830;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
box-shadow:
|
||||||
|
0 16px 34px rgba(0, 0, 0, 0.35),
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.08),
|
||||||
|
inset 0 0 0 1px rgba(73, 174, 255, 0.1);
|
||||||
|
border: 1px solid rgba(79, 188, 255, 0.28);
|
||||||
|
backdrop-filter: blur(18px);
|
||||||
|
-webkit-backdrop-filter: blur(18px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeActionsTitle {
|
||||||
|
color: #dff3ff;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 700;
|
||||||
|
max-width: 180px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
letter-spacing: 0.4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 960px) {
|
||||||
|
.routeActions {
|
||||||
|
left: 12px;
|
||||||
|
right: 12px;
|
||||||
|
bottom: 12px;
|
||||||
|
transform: none;
|
||||||
|
justify-content: space-between;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeActionsTitle {
|
||||||
|
max-width: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,464 @@
|
|||||||
|
import React, { useEffect, useRef, useState, useCallback, useMemo } from 'react';
|
||||||
|
import { message, Button, Space } from 'antd';
|
||||||
|
import { PlayCircleOutlined, EyeOutlined, StopOutlined } from '@ant-design/icons';
|
||||||
|
import { useTilesetLoader } from '@/pages/map3d/components/MapContainer/3d/hooks/useTilesetLoader';
|
||||||
|
import { useCesiumRouteLibraryRenderer } from '@/pages/map3d/components/RouteEditor/hooks/useCesiumRouteLibraryRenderer';
|
||||||
|
import { useRoutePreview } from '../../hooks/useRoutePreview';
|
||||||
|
import { getClientModels } from '../../services/clientApi';
|
||||||
|
import { convertToTilesetConfig } from '@/services/threeDModel';
|
||||||
|
import { getBoatRouteDetail } from '@/services/boatRoute';
|
||||||
|
import type { BoatRouteListVO, BoatTelemetryData, BoatWaypointDTO } from '@/types/boatRoute';
|
||||||
|
import styles from './index.less';
|
||||||
|
|
||||||
|
let Cesium: any = null;
|
||||||
|
|
||||||
|
interface CenterViewProps {
|
||||||
|
deviceSn: string;
|
||||||
|
routes: BoatRouteListVO[];
|
||||||
|
selectedRouteId: string | null;
|
||||||
|
boatData: BoatTelemetryData | null;
|
||||||
|
onModelCenter?: (lon: number, lat: number) => void;
|
||||||
|
isSailing?: boolean;
|
||||||
|
previewStopSignal?: number;
|
||||||
|
onStartSailing?: (routeId: string) => void;
|
||||||
|
onPreviewChange?: (previewing: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CenterView: React.FC<CenterViewProps> = ({ deviceSn, routes, selectedRouteId, boatData, onModelCenter, isSailing, previewStopSignal, onStartSailing, onPreviewChange }) => {
|
||||||
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
const viewerRef = useRef<any>(null);
|
||||||
|
const [viewerReady, setViewerReady] = useState(false);
|
||||||
|
const [modelLoading, setModelLoading] = useState(false);
|
||||||
|
const boatEntityRef = useRef<any>(null);
|
||||||
|
const trackPositionsRef = useRef<any[]>([]);
|
||||||
|
const terrainLoadedRef = useRef(false);
|
||||||
|
|
||||||
|
const { loadTileset, unloadAllTilesets } = useTilesetLoader();
|
||||||
|
const { isPreviewing, startPreview, stopPreview } = useRoutePreview({ viewerRef });
|
||||||
|
|
||||||
|
// 预览状态变化时通知父组件
|
||||||
|
useEffect(() => {
|
||||||
|
onPreviewChange?.(isPreviewing);
|
||||||
|
}, [isPreviewing, onPreviewChange]);
|
||||||
|
|
||||||
|
const lastPreviewStopSignalRef = useRef(previewStopSignal);
|
||||||
|
|
||||||
|
// 外部停止通道:例如 HUD 点击“结束预览”时由父组件递增信号
|
||||||
|
useEffect(() => {
|
||||||
|
if (previewStopSignal == null) return;
|
||||||
|
if (lastPreviewStopSignalRef.current === previewStopSignal) return;
|
||||||
|
|
||||||
|
lastPreviewStopSignalRef.current = previewStopSignal;
|
||||||
|
if (isPreviewing) {
|
||||||
|
stopPreview();
|
||||||
|
}
|
||||||
|
}, [previewStopSignal, isPreviewing, stopPreview]);
|
||||||
|
|
||||||
|
// 航线渲染数据(含航点)
|
||||||
|
const [routeRenderItems, setRouteRenderItems] = useState<any[]>([]);
|
||||||
|
// 缓存已加载的航线详情
|
||||||
|
const routeDetailCacheRef = useRef<Map<string, BoatWaypointDTO[]>>(new Map());
|
||||||
|
|
||||||
|
const { flyToRoute: flyToRouteLibrary } = useCesiumRouteLibraryRenderer({
|
||||||
|
viewerRef,
|
||||||
|
routes: routeRenderItems,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 初始化 Cesium(参考鹰眼 CesiumContainer 初始化模式)
|
||||||
|
useEffect(() => {
|
||||||
|
let destroyed = false;
|
||||||
|
|
||||||
|
const initCesium = async () => {
|
||||||
|
if (!containerRef.current) return;
|
||||||
|
|
||||||
|
if (!Cesium) {
|
||||||
|
const cesiumModule = (window as any).Cesium || await import('cesium');
|
||||||
|
Cesium = cesiumModule;
|
||||||
|
(window as any).Cesium = cesiumModule;
|
||||||
|
|
||||||
|
// 设置 Worker 基础路径,避免从 file:/// 加载
|
||||||
|
const cesiumBaseUrl = process.env.CESIUM_BASE_URL || '/';
|
||||||
|
Cesium.buildModuleUrl.setBaseUrl(`${cesiumBaseUrl}cesium/`);
|
||||||
|
|
||||||
|
// 设置 Ion Token,避免使用内置过期 token 导致 401
|
||||||
|
const cesiumToken = process.env.REACT_APP_CESIUM_TOKEN;
|
||||||
|
if (cesiumToken) {
|
||||||
|
Cesium.Ion.defaultAccessToken = cesiumToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载 Cesium CSS
|
||||||
|
if (!document.querySelector('link[href*="cesium"]')) {
|
||||||
|
const link = document.createElement('link');
|
||||||
|
link.rel = 'stylesheet';
|
||||||
|
link.href = `${cesiumBaseUrl}cesium/Widgets/widgets.css`;
|
||||||
|
document.head.appendChild(link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (destroyed) return;
|
||||||
|
|
||||||
|
const viewer = new Cesium.Viewer(containerRef.current, {
|
||||||
|
terrainProvider: new Cesium.EllipsoidTerrainProvider(),
|
||||||
|
scene3DOnly: false,
|
||||||
|
shouldAnimate: true,
|
||||||
|
animation: false,
|
||||||
|
timeline: false,
|
||||||
|
fullscreenButton: false,
|
||||||
|
geocoder: false,
|
||||||
|
homeButton: false,
|
||||||
|
sceneModePicker: false,
|
||||||
|
baseLayerPicker: false,
|
||||||
|
navigationHelpButton: false,
|
||||||
|
infoBox: false,
|
||||||
|
selectionIndicator: false,
|
||||||
|
requestRenderMode: true,
|
||||||
|
maximumRenderTimeChange: Infinity,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 移除默认图层,添加 ArcGIS 影像
|
||||||
|
viewer.imageryLayers.remove(viewer.imageryLayers.get(0));
|
||||||
|
viewer.scene.globe.baseColor = Cesium.Color.fromCssColorString('#1e4d7b');
|
||||||
|
viewer.imageryLayers.addImageryProvider(
|
||||||
|
new Cesium.UrlTemplateImageryProvider({
|
||||||
|
url: 'https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
|
||||||
|
minimumLevel: 0,
|
||||||
|
maximumLevel: 18,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
viewer.scene.globe.enableLighting = false;
|
||||||
|
viewer.scene.skyAtmosphere.show = true;
|
||||||
|
|
||||||
|
viewerRef.current = viewer;
|
||||||
|
setViewerReady(true);
|
||||||
|
|
||||||
|
// 隐藏 Cesium 水印
|
||||||
|
const creditContainer = viewer.cesiumWidget?.creditContainer;
|
||||||
|
if (creditContainer) {
|
||||||
|
creditContainer.style.display = 'none';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
initCesium();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
destroyed = true;
|
||||||
|
if (viewerRef.current && !viewerRef.current.isDestroyed()) {
|
||||||
|
unloadAllTilesets(viewerRef.current);
|
||||||
|
viewerRef.current.destroy();
|
||||||
|
viewerRef.current = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态切换高程地形(参考鹰眼 switchToElevationTerrain)
|
||||||
|
* 根据模型配置的地形类型,优先尝试对应地形,失败后降级
|
||||||
|
*/
|
||||||
|
const switchToElevationTerrain = useCallback(async (preferredTerrainType?: string): Promise<string> => {
|
||||||
|
if (!viewerRef.current || !Cesium) return 'ellipsoid';
|
||||||
|
if (terrainLoadedRef.current && !preferredTerrainType) return 'loaded';
|
||||||
|
|
||||||
|
let loadedTerrainType = 'ellipsoid';
|
||||||
|
|
||||||
|
if (preferredTerrainType === 'arcgis') {
|
||||||
|
try {
|
||||||
|
const terrainProvider = await Cesium.ArcGISTiledElevationTerrainProvider.fromUrl(
|
||||||
|
'https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer'
|
||||||
|
);
|
||||||
|
viewerRef.current.terrainProvider = terrainProvider;
|
||||||
|
viewerRef.current.scene.globe.depthTestAgainstTerrain = true;
|
||||||
|
terrainLoadedRef.current = true;
|
||||||
|
loadedTerrainType = 'arcgis';
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
const terrainProvider = await Cesium.CesiumTerrainProvider.fromIonAssetId(1, {
|
||||||
|
requestVertexNormals: true,
|
||||||
|
requestWaterMask: true,
|
||||||
|
});
|
||||||
|
viewerRef.current.terrainProvider = terrainProvider;
|
||||||
|
viewerRef.current.scene.globe.depthTestAgainstTerrain = true;
|
||||||
|
terrainLoadedRef.current = true;
|
||||||
|
loadedTerrainType = 'cesium_ion';
|
||||||
|
} catch {
|
||||||
|
loadedTerrainType = 'ellipsoid';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
const terrainProvider = await Cesium.CesiumTerrainProvider.fromIonAssetId(1, {
|
||||||
|
requestVertexNormals: true,
|
||||||
|
requestWaterMask: true,
|
||||||
|
});
|
||||||
|
viewerRef.current.terrainProvider = terrainProvider;
|
||||||
|
viewerRef.current.scene.globe.depthTestAgainstTerrain = true;
|
||||||
|
terrainLoadedRef.current = true;
|
||||||
|
loadedTerrainType = 'cesium_ion';
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
const terrainProvider = await Cesium.ArcGISTiledElevationTerrainProvider.fromUrl(
|
||||||
|
'https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer'
|
||||||
|
);
|
||||||
|
viewerRef.current.terrainProvider = terrainProvider;
|
||||||
|
viewerRef.current.scene.globe.depthTestAgainstTerrain = true;
|
||||||
|
terrainLoadedRef.current = true;
|
||||||
|
loadedTerrainType = 'arcgis';
|
||||||
|
} catch {
|
||||||
|
loadedTerrainType = 'ellipsoid';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return loadedTerrainType;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 加载3D模型(参考鹰眼 loadDeviceModels)
|
||||||
|
useEffect(() => {
|
||||||
|
if (!viewerReady || !deviceSn) return;
|
||||||
|
let cancelled = false;
|
||||||
|
|
||||||
|
const loadModels = async () => {
|
||||||
|
setModelLoading(true);
|
||||||
|
unloadAllTilesets(viewerRef.current);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await getClientModels(deviceSn);
|
||||||
|
const modelList = res.datas || res.data;
|
||||||
|
if (cancelled || res.resp_code !== 0 || !modelList?.length) {
|
||||||
|
setModelLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const configs = modelList.map((model: any) => convertToTilesetConfig(model));
|
||||||
|
|
||||||
|
// 并行:高程地形加载 + 模型准备
|
||||||
|
const firstTerrainType = configs[0]?.position?.terrainType;
|
||||||
|
const terrainPromise = switchToElevationTerrain(firstTerrainType);
|
||||||
|
|
||||||
|
const autoLoadCount = configs.length <= 2 ? configs.length : 1;
|
||||||
|
const configsToLoad = configs.slice(0, autoLoadCount);
|
||||||
|
|
||||||
|
// 等待高程加载完成
|
||||||
|
const loadedTerrainType = await terrainPromise;
|
||||||
|
if (cancelled) { setModelLoading(false); return; }
|
||||||
|
|
||||||
|
let firstTileset: any = null;
|
||||||
|
|
||||||
|
for (const config of configsToLoad) {
|
||||||
|
if (!config.url) continue;
|
||||||
|
const tileset = await loadTileset(config, viewerRef.current, Cesium, loadedTerrainType);
|
||||||
|
if (tileset && !firstTileset) {
|
||||||
|
firstTileset = tileset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 模型加载完成后飞到模型位置
|
||||||
|
if (firstTileset && viewerRef.current && !viewerRef.current.isDestroyed?.()) {
|
||||||
|
try {
|
||||||
|
const radius = Number(firstTileset?.boundingSphere?.radius);
|
||||||
|
const range = Number.isFinite(radius) && radius > 0 ? Math.max(50, radius * 0.8) : 100;
|
||||||
|
viewerRef.current.flyTo(firstTileset, {
|
||||||
|
duration: 1.5,
|
||||||
|
offset: new Cesium.HeadingPitchRange(
|
||||||
|
Cesium.Math.toRadians(0),
|
||||||
|
Cesium.Math.toRadians(-50),
|
||||||
|
range
|
||||||
|
),
|
||||||
|
});
|
||||||
|
// 通知父组件模型中心位置(用于模拟数据定位)
|
||||||
|
if (onModelCenter && firstTileset.boundingSphere?.center) {
|
||||||
|
const cartographic = Cesium.Cartographic.fromCartesian(firstTileset.boundingSphere.center);
|
||||||
|
onModelCenter(
|
||||||
|
Cesium.Math.toDegrees(cartographic.longitude),
|
||||||
|
Cesium.Math.toDegrees(cartographic.latitude),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('飞到模型位置失败:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载设备模型失败:', error);
|
||||||
|
}
|
||||||
|
setModelLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
loadModels();
|
||||||
|
return () => { cancelled = true; };
|
||||||
|
}, [viewerReady, deviceSn]);
|
||||||
|
|
||||||
|
// 选中航线时加载航点详情并渲染
|
||||||
|
useEffect(() => {
|
||||||
|
if (!viewerReady || !selectedRouteId) {
|
||||||
|
setRouteRenderItems([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadAndRender = async () => {
|
||||||
|
let waypoints = routeDetailCacheRef.current.get(selectedRouteId);
|
||||||
|
|
||||||
|
if (!waypoints) {
|
||||||
|
try {
|
||||||
|
const res = await getBoatRouteDetail(selectedRouteId);
|
||||||
|
if (res.resp_code === 0 && res.data?.waypoints) {
|
||||||
|
waypoints = res.data.waypoints.map((wp) => ({
|
||||||
|
longitude: wp.longitude,
|
||||||
|
latitude: wp.latitude,
|
||||||
|
speed: wp.speed,
|
||||||
|
stayDuration: wp.stayDuration,
|
||||||
|
}));
|
||||||
|
routeDetailCacheRef.current.set(selectedRouteId, waypoints);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
message.error('线路详情加载失败');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (waypoints && waypoints.length > 0) {
|
||||||
|
setRouteRenderItems([{
|
||||||
|
routeId: selectedRouteId,
|
||||||
|
routeName: routes.find((r) => r.routeId === selectedRouteId)?.routeName || '',
|
||||||
|
waypoints,
|
||||||
|
visible: true,
|
||||||
|
highlighted: true,
|
||||||
|
}]);
|
||||||
|
// 使用 useCesiumRouteLibraryRenderer 的 flyToRoute(基于 Rectangle,视角更可靠)
|
||||||
|
// 延迟一帧让 routeRenderItems 生效,entity 创建后再飞
|
||||||
|
setTimeout(() => flyToRouteLibrary(selectedRouteId), 100);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadAndRender();
|
||||||
|
}, [viewerReady, selectedRouteId]);
|
||||||
|
|
||||||
|
// 实时船位渲染
|
||||||
|
useEffect(() => {
|
||||||
|
if (!viewerReady || !Cesium || !boatData?.longitude || !boatData?.latitude) return;
|
||||||
|
const viewer = viewerRef.current;
|
||||||
|
if (!viewer || viewer.isDestroyed()) return;
|
||||||
|
|
||||||
|
const position = Cesium.Cartesian3.fromDegrees(boatData.longitude, boatData.latitude, 2);
|
||||||
|
trackPositionsRef.current.push(position);
|
||||||
|
// 限制轨迹点数
|
||||||
|
if (trackPositionsRef.current.length > 500) {
|
||||||
|
trackPositionsRef.current = trackPositionsRef.current.slice(-400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新/创建船位 Entity
|
||||||
|
if (!boatEntityRef.current) {
|
||||||
|
boatEntityRef.current = viewer.entities.add({
|
||||||
|
position,
|
||||||
|
point: {
|
||||||
|
pixelSize: 12,
|
||||||
|
color: Cesium.Color.fromCssColorString('#00d4ff'),
|
||||||
|
outlineColor: Cesium.Color.WHITE,
|
||||||
|
outlineWidth: 2,
|
||||||
|
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
text: '当前位置',
|
||||||
|
font: '12px sans-serif',
|
||||||
|
fillColor: Cesium.Color.WHITE,
|
||||||
|
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
||||||
|
outlineWidth: 2,
|
||||||
|
outlineColor: Cesium.Color.BLACK,
|
||||||
|
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
||||||
|
pixelOffset: new Cesium.Cartesian2(0, -16),
|
||||||
|
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
boatEntityRef.current.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 轨迹线
|
||||||
|
if (trackPositionsRef.current.length >= 2) {
|
||||||
|
const trackId = 'client-boat-track';
|
||||||
|
let trackEntity = viewer.entities.getById(trackId);
|
||||||
|
if (!trackEntity) {
|
||||||
|
viewer.entities.add({
|
||||||
|
id: trackId,
|
||||||
|
polyline: {
|
||||||
|
positions: new Cesium.CallbackProperty(() => trackPositionsRef.current, false),
|
||||||
|
width: 3,
|
||||||
|
material: new Cesium.PolylineGlowMaterialProperty({
|
||||||
|
glowPower: 0.3,
|
||||||
|
color: Cesium.Color.LIME,
|
||||||
|
}),
|
||||||
|
clampToGround: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
viewer.scene.requestRender();
|
||||||
|
}, [viewerReady, boatData]);
|
||||||
|
|
||||||
|
// 预览选中航线
|
||||||
|
const handlePreviewRoute = useCallback(async () => {
|
||||||
|
if (!selectedRouteId) return;
|
||||||
|
const waypoints = routeDetailCacheRef.current.get(selectedRouteId);
|
||||||
|
if (!waypoints || waypoints.length < 2) {
|
||||||
|
message.warning('航点数据不足,无法预览');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await startPreview(waypoints, 2);
|
||||||
|
}, [selectedRouteId, startPreview]);
|
||||||
|
|
||||||
|
// 执行航线
|
||||||
|
const handleExecuteRoute = useCallback(() => {
|
||||||
|
if (selectedRouteId && onStartSailing) {
|
||||||
|
onStartSailing(selectedRouteId);
|
||||||
|
}
|
||||||
|
}, [selectedRouteId, onStartSailing]);
|
||||||
|
|
||||||
|
// 获取选中航线名称
|
||||||
|
const selectedRouteName = useMemo(() => {
|
||||||
|
if (!selectedRouteId) return '';
|
||||||
|
return routes.find((r) => r.routeId === selectedRouteId)?.routeName || '';
|
||||||
|
}, [selectedRouteId, routes]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.wrapper}>
|
||||||
|
<div ref={containerRef} className={styles.cesiumContainer} />
|
||||||
|
|
||||||
|
{/* 模型加载提示 */}
|
||||||
|
{modelLoading && (
|
||||||
|
<div className={styles.loadingTip}>
|
||||||
|
<div className={styles.loadingSpinner} />
|
||||||
|
<span>正在加载3D模型...</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* 选中线路时显示操作按钮(非航行模式) */}
|
||||||
|
{selectedRouteId && !isPreviewing && !isSailing && (
|
||||||
|
<div className={styles.routeActions}>
|
||||||
|
<div className={styles.routeActionsTitle}>{selectedRouteName}</div>
|
||||||
|
<Space>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
icon={<EyeOutlined />}
|
||||||
|
onClick={handlePreviewRoute}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
预览线路
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
icon={<PlayCircleOutlined />}
|
||||||
|
onClick={handleExecuteRoute}
|
||||||
|
size="small"
|
||||||
|
style={{ borderColor: '#00ff88', color: '#00ff88' }}
|
||||||
|
>
|
||||||
|
开始航行
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* 预览停止操作已收敛至 NavigationHUD,此处不再重复渲染 */}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CenterView;
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
.emergencyBtn {
|
||||||
|
position: absolute;
|
||||||
|
top: 22px;
|
||||||
|
right: 22px;
|
||||||
|
z-index: 930;
|
||||||
|
width: 142px;
|
||||||
|
height: 54px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: linear-gradient(135deg, rgba(255, 111, 85, 0.96) 0%, rgba(206, 51, 53, 0.94) 100%);
|
||||||
|
border: 1px solid rgba(255, 181, 152, 0.36);
|
||||||
|
color: #fff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
outline: none;
|
||||||
|
box-shadow:
|
||||||
|
0 16px 34px rgba(94, 16, 18, 0.34),
|
||||||
|
0 0 0 1px rgba(255, 110, 92, 0.22),
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.18);
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
animation: dangerPulse 2s infinite;
|
||||||
|
font-family: 'Rajdhani', 'Orbitron', 'DIN', 'Avenir Next', 'PingFang SC', sans-serif;
|
||||||
|
backdrop-filter: blur(16px);
|
||||||
|
-webkit-backdrop-filter: blur(16px);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: linear-gradient(135deg, rgba(255, 133, 110, 0.98) 0%, rgba(230, 61, 63, 0.96) 100%);
|
||||||
|
box-shadow:
|
||||||
|
0 18px 38px rgba(112, 19, 23, 0.42),
|
||||||
|
0 0 22px rgba(255, 107, 88, 0.32),
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.24);
|
||||||
|
animation: dangerPulseHover 1s infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: scale(0.97);
|
||||||
|
box-shadow:
|
||||||
|
0 8px 16px rgba(82, 17, 18, 0.35),
|
||||||
|
inset 0 4px 10px rgba(0, 0, 0, 0.16);
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
font-size: 18px;
|
||||||
|
margin-top: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes dangerPulse {
|
||||||
|
0% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.6); }
|
||||||
|
70% { box-shadow: 0 0 0 12px rgba(255, 77, 79, 0); }
|
||||||
|
100% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes dangerPulseHover {
|
||||||
|
0% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.8); }
|
||||||
|
70% { box-shadow: 0 0 0 16px rgba(255, 77, 79, 0); }
|
||||||
|
100% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 960px) {
|
||||||
|
.emergencyBtn {
|
||||||
|
top: 14px;
|
||||||
|
right: 14px;
|
||||||
|
width: 132px;
|
||||||
|
height: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Modal } from 'antd';
|
||||||
|
import { WarningOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
|
||||||
|
import styles from './index.less';
|
||||||
|
|
||||||
|
export interface EmergencyButtonProps {
|
||||||
|
onEmergencyStop: () => void;
|
||||||
|
deviceSn: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EmergencyButton: React.FC<EmergencyButtonProps> = ({ onEmergencyStop, deviceSn }) => {
|
||||||
|
const handleClick = () => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '确认紧急停靠',
|
||||||
|
icon: <ExclamationCircleOutlined style={{ color: '#ff4d4f' }} />,
|
||||||
|
content: `您确定要立即停止设备 ${deviceSn} 的所有动作吗?这可能会造成不可逆的后果。`,
|
||||||
|
okText: '确认停靠',
|
||||||
|
okType: 'danger',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: () => {
|
||||||
|
onEmergencyStop();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button className={styles.emergencyBtn} onClick={handleClick}>
|
||||||
|
<WarningOutlined className={styles.icon} />
|
||||||
|
<span className={styles.text}>紧急停靠</span>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EmergencyButton;
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
/* ========== 玻璃拟态变量 ========== */
|
||||||
|
@glass-border: rgba(65, 170, 255, 0.28);
|
||||||
|
@glass-border-light: rgba(92, 211, 255, 0.18);
|
||||||
|
@accent-cyan: #00d4ff;
|
||||||
|
@accent-blue: #0096ff;
|
||||||
|
@text-primary: #eaf6ff;
|
||||||
|
@text-secondary: rgba(255, 255, 255, 0.55);
|
||||||
|
@text-dim: rgba(255, 255, 255, 0.35);
|
||||||
|
@card-bg: linear-gradient(145deg, rgba(10, 24, 48, 0.7), rgba(8, 18, 38, 0.5));
|
||||||
|
@card-bg-active: linear-gradient(145deg, rgba(0, 80, 160, 0.2), rgba(0, 120, 200, 0.1));
|
||||||
|
@card-shadow: 0 2px 12px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.06);
|
||||||
|
@card-shadow-active: 0 2px 20px rgba(0, 112, 212, 0.2), inset 0 1px 0 rgba(0, 180, 255, 0.12);
|
||||||
|
@transition-fast: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
|
||||||
|
.panel {
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 头部 ========== */
|
||||||
|
.header {
|
||||||
|
padding: 20px 16px 16px;
|
||||||
|
border-bottom: 1px solid @glass-border-light;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
// 底部渐变高光
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
bottom: -1px;
|
||||||
|
left: 16px;
|
||||||
|
right: 16px;
|
||||||
|
height: 1px;
|
||||||
|
background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.2), transparent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.headerIcon {
|
||||||
|
width: 38px;
|
||||||
|
height: 38px;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: linear-gradient(135deg, rgba(0, 100, 200, 0.35), rgba(0, 180, 255, 0.15));
|
||||||
|
backdrop-filter: blur(8px);
|
||||||
|
border: 1px solid rgba(0, 150, 255, 0.25);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: @accent-cyan;
|
||||||
|
font-size: 16px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 100, 200, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.headerTitle {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: @text-primary;
|
||||||
|
line-height: 1.3;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.headerSub {
|
||||||
|
font-size: 11px;
|
||||||
|
color: @text-dim;
|
||||||
|
letter-spacing: 0.3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.count {
|
||||||
|
margin-left: auto;
|
||||||
|
background: linear-gradient(135deg, rgba(0, 100, 200, 0.25), rgba(0, 150, 255, 0.15));
|
||||||
|
border: 1px solid rgba(0, 150, 255, 0.2);
|
||||||
|
color: @accent-cyan;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
font-family: 'Rajdhani', 'DIN', monospace;
|
||||||
|
padding: 2px 12px;
|
||||||
|
border-radius: 10px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 列表 ========== */
|
||||||
|
.list {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 12px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.center {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 线路卡片 ========== */
|
||||||
|
.routeCard {
|
||||||
|
padding: 14px 16px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
border-radius: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: @transition-fast;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.05);
|
||||||
|
background: @card-bg;
|
||||||
|
backdrop-filter: blur(6px);
|
||||||
|
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
// 左侧指示条
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 20%;
|
||||||
|
bottom: 20%;
|
||||||
|
width: 2px;
|
||||||
|
background: transparent;
|
||||||
|
border-radius: 1px;
|
||||||
|
transition: @transition-fast;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: linear-gradient(145deg, rgba(0, 80, 160, 0.12), rgba(0, 120, 200, 0.06));
|
||||||
|
border-color: rgba(0, 150, 255, 0.25);
|
||||||
|
box-shadow: @card-shadow;
|
||||||
|
transform: translateX(2px);
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
background: rgba(0, 180, 255, 0.4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeCardActive {
|
||||||
|
background: @card-bg-active;
|
||||||
|
border-color: rgba(0, 150, 255, 0.4);
|
||||||
|
box-shadow: @card-shadow-active;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
background: linear-gradient(180deg, @accent-cyan, @accent-blue);
|
||||||
|
width: 3px;
|
||||||
|
top: 12%;
|
||||||
|
bottom: 12%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeName {
|
||||||
|
color: @accent-cyan;
|
||||||
|
text-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeName {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: rgba(255, 255, 255, 0.92);
|
||||||
|
margin-bottom: 8px;
|
||||||
|
transition: @transition-fast;
|
||||||
|
letter-spacing: 0.3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 标签行 ========== */
|
||||||
|
.tagRow {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: @text-secondary;
|
||||||
|
background: rgba(0, 100, 180, 0.1);
|
||||||
|
border: 1px solid rgba(0, 150, 255, 0.1);
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-family: 'Rajdhani', 'DIN', sans-serif;
|
||||||
|
letter-spacing: 0.3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tagIcon {
|
||||||
|
font-size: 10px;
|
||||||
|
color: rgba(0, 180, 255, 0.65);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 航点路径 ========== */
|
||||||
|
.waypointPath {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
padding: 10px 0 4px;
|
||||||
|
border-top: 1px solid rgba(65, 170, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointDot {
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: @accent-cyan;
|
||||||
|
box-shadow: 0 0 4px rgba(0, 212, 255, 0.4);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointName {
|
||||||
|
font-size: 12px;
|
||||||
|
color: rgba(255, 255, 255, 0.7);
|
||||||
|
letter-spacing: 0.2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointArrow {
|
||||||
|
font-size: 11px;
|
||||||
|
color: rgba(0, 180, 255, 0.45);
|
||||||
|
margin: 0 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 开始航行按钮 ========== */
|
||||||
|
.startBtn {
|
||||||
|
margin-top: 12px;
|
||||||
|
height: 38px;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 14px;
|
||||||
|
letter-spacing: 1.5px;
|
||||||
|
background: linear-gradient(135deg, #0070d4, #0096ff);
|
||||||
|
border: 1px solid rgba(0, 150, 255, 0.3);
|
||||||
|
box-shadow: 0 2px 12px rgba(0, 112, 212, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
|
||||||
|
transition: @transition-fast;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: linear-gradient(135deg, #0080e8, #00a8ff);
|
||||||
|
box-shadow: 0 4px 20px rgba(0, 112, 212, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.12);
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: translateY(0);
|
||||||
|
box-shadow: 0 1px 6px rgba(0, 112, 212, 0.3);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import { Spin, Empty } from 'antd';
|
||||||
|
import {
|
||||||
|
ClockCircleOutlined,
|
||||||
|
EnvironmentOutlined,
|
||||||
|
SendOutlined,
|
||||||
|
NodeIndexOutlined,
|
||||||
|
} from '@ant-design/icons';
|
||||||
|
import type { BoatRouteListVO, BoatWaypointVO } from '@/types/boatRoute';
|
||||||
|
import styles from './index.less';
|
||||||
|
|
||||||
|
interface LeftPanelProps {
|
||||||
|
routes: BoatRouteListVO[];
|
||||||
|
routeWaypointsMap: Record<string, BoatWaypointVO[]>;
|
||||||
|
loading: boolean;
|
||||||
|
selectedRouteId: string | null;
|
||||||
|
onSelectRoute: (routeId: string | null) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 格式化时间(秒 → "XX分钟") */
|
||||||
|
const formatDuration = (seconds?: number) => {
|
||||||
|
if (!seconds || seconds <= 0) return null;
|
||||||
|
const min = Math.round(seconds / 60);
|
||||||
|
return min > 0 ? `${min}分钟` : '<1分钟';
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 格式化距离 */
|
||||||
|
const formatDistance = (meters?: number) => {
|
||||||
|
if (!meters || meters <= 0) return null;
|
||||||
|
return meters >= 1000 ? `${(meters / 1000).toFixed(1)}km` : `${Math.round(meters)}m`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const LeftPanel: React.FC<LeftPanelProps> = ({
|
||||||
|
routes,
|
||||||
|
routeWaypointsMap,
|
||||||
|
loading,
|
||||||
|
selectedRouteId,
|
||||||
|
onSelectRoute,
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<div className={styles.panel}>
|
||||||
|
<div className={styles.header}>
|
||||||
|
<div className={styles.headerIcon}>
|
||||||
|
<SendOutlined />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className={styles.headerTitle}>游览线路</div>
|
||||||
|
<div className={styles.headerSub}>选择线路开始游览</div>
|
||||||
|
</div>
|
||||||
|
<span className={styles.count}>{routes.length}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.list}>
|
||||||
|
{loading ? (
|
||||||
|
<div className={styles.center}><Spin /></div>
|
||||||
|
) : routes.length === 0 ? (
|
||||||
|
<div className={styles.center}>
|
||||||
|
<Empty description="暂无游览线路" image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
routes.map((route) => {
|
||||||
|
const isSelected = selectedRouteId === route.routeId;
|
||||||
|
const waypoints = routeWaypointsMap[route.routeId] || [];
|
||||||
|
const duration = formatDuration(route.totalDuration);
|
||||||
|
const distance = formatDistance(route.totalDistance);
|
||||||
|
|
||||||
|
// 构建航点路径名称列表
|
||||||
|
const waypointNames = waypoints
|
||||||
|
.filter((wp) => wp.pointName)
|
||||||
|
.map((wp) => wp.pointName);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={route.routeId}
|
||||||
|
className={`${styles.routeCard} ${isSelected ? styles.routeCardActive : ''}`}
|
||||||
|
onClick={() => onSelectRoute(isSelected ? null : route.routeId)}
|
||||||
|
>
|
||||||
|
{/* 线路名称 */}
|
||||||
|
<div className={styles.routeName}>{route.routeName}</div>
|
||||||
|
|
||||||
|
{/* 时长 + 距离 标签 */}
|
||||||
|
<div className={styles.tagRow}>
|
||||||
|
{duration && (
|
||||||
|
<span className={styles.tag}>
|
||||||
|
<ClockCircleOutlined className={styles.tagIcon} />
|
||||||
|
{duration}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{distance && (
|
||||||
|
<span className={styles.tag}>
|
||||||
|
<EnvironmentOutlined className={styles.tagIcon} />
|
||||||
|
{distance}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<span className={styles.tag}>
|
||||||
|
<NodeIndexOutlined className={styles.tagIcon} />
|
||||||
|
{route.waypointCount || waypoints.length}个景点
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 航点路径 */}
|
||||||
|
{waypointNames.length > 0 && (
|
||||||
|
<div className={styles.waypointPath}>
|
||||||
|
{waypointNames.map((name, idx) => (
|
||||||
|
<React.Fragment key={idx}>
|
||||||
|
<span className={styles.waypointDot} />
|
||||||
|
<span className={styles.waypointName}>{name}</span>
|
||||||
|
{idx < waypointNames.length - 1 && (
|
||||||
|
<span className={styles.waypointArrow}>→</span>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LeftPanel;
|
||||||
@@ -0,0 +1,467 @@
|
|||||||
|
.hudContainer {
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
bottom: 26px;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
width: calc(100% - 48px);
|
||||||
|
max-width: 1360px;
|
||||||
|
z-index: 920;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 168px 1fr 216px 168px;
|
||||||
|
gap: 16px;
|
||||||
|
align-items: stretch;
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 14px 16px;
|
||||||
|
background:
|
||||||
|
linear-gradient(120deg, rgba(7, 20, 34, 0.95) 0%, rgba(11, 36, 60, 0.9) 58%, rgba(18, 29, 50, 0.94) 100%);
|
||||||
|
border: 1px solid rgba(65, 170, 255, 0.28);
|
||||||
|
box-shadow:
|
||||||
|
0 16px 40px rgba(2, 11, 24, 0.5),
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.08),
|
||||||
|
inset 0 0 0 1px rgba(33, 145, 240, 0.14);
|
||||||
|
color: #eaf6ff;
|
||||||
|
font-family: 'Rajdhani', 'DIN', 'Avenir Next', 'PingFang SC', sans-serif;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hudContainer::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 16px;
|
||||||
|
right: 16px;
|
||||||
|
height: 1px;
|
||||||
|
background: linear-gradient(90deg, transparent 0%, rgba(133, 206, 255, 0.7) 45%, transparent 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hudContainer::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: -120px;
|
||||||
|
right: -120px;
|
||||||
|
width: 280px;
|
||||||
|
height: 280px;
|
||||||
|
background: radial-gradient(circle, rgba(70, 156, 255, 0.22) 0%, rgba(70, 156, 255, 0) 72%);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.previewMode {
|
||||||
|
border-color: rgba(72, 190, 255, 0.42);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sailingMode {
|
||||||
|
border-color: rgba(255, 158, 94, 0.38);
|
||||||
|
}
|
||||||
|
|
||||||
|
.primaryCluster,
|
||||||
|
.centerCluster,
|
||||||
|
.statusCluster,
|
||||||
|
.actionCluster {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.primaryCluster {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.speedDial {
|
||||||
|
width: 116px;
|
||||||
|
height: 116px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.speedSvg {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.speedTrack,
|
||||||
|
.speedRing {
|
||||||
|
fill: none;
|
||||||
|
stroke-width: 8;
|
||||||
|
transform-origin: 60px 60px;
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.speedTrack {
|
||||||
|
stroke: rgba(208, 231, 255, 0.16);
|
||||||
|
}
|
||||||
|
|
||||||
|
.speedRing {
|
||||||
|
stroke: #4fcbff;
|
||||||
|
stroke-linecap: round;
|
||||||
|
transition: stroke-dashoffset 0.35s ease;
|
||||||
|
filter: drop-shadow(0 0 8px rgba(79, 203, 255, 0.7));
|
||||||
|
}
|
||||||
|
|
||||||
|
.speedCenter {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.speedValue {
|
||||||
|
font-size: 34px;
|
||||||
|
line-height: 1;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #f5fbff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.speedUnit {
|
||||||
|
margin-top: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
color: rgba(166, 223, 255, 0.86);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modeChip {
|
||||||
|
padding: 2px 12px;
|
||||||
|
border-radius: 100px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #d8eeff;
|
||||||
|
border: 1px solid rgba(156, 213, 255, 0.35);
|
||||||
|
background: rgba(20, 48, 75, 0.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
.centerCluster {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeHeader {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeTitle {
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #f1f9ff;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeProgress {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #7fd9ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeProgressTrack {
|
||||||
|
width: 100%;
|
||||||
|
height: 6px;
|
||||||
|
border-radius: 999px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: rgba(201, 226, 255, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeProgressFill {
|
||||||
|
height: 100%;
|
||||||
|
border-radius: inherit;
|
||||||
|
background: linear-gradient(90deg, #2e9dff 0%, #3ff0ff 55%, #7effcc 100%);
|
||||||
|
transition: width 0.3s ease;
|
||||||
|
box-shadow: 0 0 8px rgba(76, 202, 255, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointCard {
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
background: linear-gradient(140deg, rgba(22, 47, 78, 0.78) 0%, rgba(11, 26, 43, 0.84) 100%);
|
||||||
|
border: 1px solid rgba(110, 186, 255, 0.22);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointMain {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navArrow {
|
||||||
|
font-size: 20px;
|
||||||
|
color: #59cbff;
|
||||||
|
filter: drop-shadow(0 0 6px rgba(89, 203, 255, 0.7));
|
||||||
|
}
|
||||||
|
|
||||||
|
.infoLabel {
|
||||||
|
font-size: 11px;
|
||||||
|
letter-spacing: 0.6px;
|
||||||
|
color: rgba(195, 226, 255, 0.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointName {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #f7fcff;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
max-width: 220px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointStats {
|
||||||
|
display: flex;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.infoValue {
|
||||||
|
margin-top: 2px;
|
||||||
|
font-size: 17px;
|
||||||
|
color: #8de5ff;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.emptyWaypoint {
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
color: rgba(204, 229, 255, 0.72);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summaryRow {
|
||||||
|
display: flex;
|
||||||
|
gap: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summaryItem {
|
||||||
|
min-width: 92px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summaryValue {
|
||||||
|
margin-top: 2px;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #e6f5ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.statusCluster {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compassCard,
|
||||||
|
.powerCard {
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 8px 10px;
|
||||||
|
background: rgba(12, 29, 48, 0.78);
|
||||||
|
border: 1px solid rgba(106, 176, 238, 0.22);
|
||||||
|
}
|
||||||
|
|
||||||
|
.cardTitle {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #b7deff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compassDial {
|
||||||
|
margin: 6px auto;
|
||||||
|
width: 72px;
|
||||||
|
height: 72px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 1px solid rgba(141, 208, 255, 0.3);
|
||||||
|
background: radial-gradient(circle at center, rgba(68, 157, 226, 0.25) 0%, rgba(8, 23, 38, 0.8) 70%);
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compassRotor {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
transition: transform 0.28s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compassTick {
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
top: 5px;
|
||||||
|
width: 2px;
|
||||||
|
height: 7px;
|
||||||
|
margin-left: -1px;
|
||||||
|
background: rgba(174, 219, 255, 0.75);
|
||||||
|
transform-origin: 50% 31px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compassNeedle {
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
top: 8px;
|
||||||
|
margin-left: -3px;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
border-left: 3px solid transparent;
|
||||||
|
border-right: 3px solid transparent;
|
||||||
|
border-bottom: 14px solid #ff8f66;
|
||||||
|
filter: drop-shadow(0 0 5px rgba(255, 143, 102, 0.8));
|
||||||
|
}
|
||||||
|
|
||||||
|
.compassValue {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #ecf8ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.powerCard {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.powerRow {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.powerValue {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #f7fbff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.powerTrack {
|
||||||
|
height: 6px;
|
||||||
|
border-radius: 999px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: rgba(196, 223, 250, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.powerFill,
|
||||||
|
.signalFill {
|
||||||
|
height: 100%;
|
||||||
|
border-radius: inherit;
|
||||||
|
transition: width 0.25s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.powerFill {
|
||||||
|
background: linear-gradient(90deg, #fa7d57 0%, #ffcf77 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.signalFill {
|
||||||
|
background: linear-gradient(90deg, #2ea4ff 0%, #63f4ff 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionCluster {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionBtn {
|
||||||
|
height: 40px;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
background: rgba(255, 255, 255, 0.07);
|
||||||
|
color: #f2faff;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 700;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionBtn:active {
|
||||||
|
transform: scale(0.97);
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionPrimary {
|
||||||
|
border-color: rgba(95, 210, 255, 0.5);
|
||||||
|
background: linear-gradient(120deg, rgba(43, 147, 232, 0.34) 0%, rgba(51, 190, 235, 0.5) 100%);
|
||||||
|
box-shadow: inset 0 0 0 1px rgba(144, 220, 255, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionPrimary:hover {
|
||||||
|
filter: brightness(1.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionDanger {
|
||||||
|
border-color: rgba(255, 151, 108, 0.62);
|
||||||
|
background: linear-gradient(120deg, rgba(219, 95, 46, 0.55) 0%, rgba(255, 140, 90, 0.52) 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionDanger:hover {
|
||||||
|
filter: brightness(1.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1240px) {
|
||||||
|
.hudContainer {
|
||||||
|
grid-template-columns: 154px 1fr 200px 154px;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeTitle {
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointName {
|
||||||
|
max-width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointStats {
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 960px) {
|
||||||
|
.hudContainer {
|
||||||
|
left: 12px;
|
||||||
|
right: 12px;
|
||||||
|
bottom: 10px;
|
||||||
|
transform: none;
|
||||||
|
width: auto;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
max-height: 46vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.primaryCluster,
|
||||||
|
.statusCluster,
|
||||||
|
.actionCluster {
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.centerCluster {
|
||||||
|
order: -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summaryRow {
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionCluster {
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionBtn {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import {
|
||||||
|
PauseCircleOutlined,
|
||||||
|
PlayCircleOutlined,
|
||||||
|
StopOutlined,
|
||||||
|
SendOutlined,
|
||||||
|
ThunderboltOutlined,
|
||||||
|
WifiOutlined,
|
||||||
|
CompassOutlined,
|
||||||
|
} from '@ant-design/icons';
|
||||||
|
import styles from './index.less';
|
||||||
|
|
||||||
|
type NavigationMode = 'preview' | 'sailing';
|
||||||
|
|
||||||
|
export interface NavigationHUDProps {
|
||||||
|
mode: NavigationMode;
|
||||||
|
routeName: string;
|
||||||
|
speed: number;
|
||||||
|
heading: number;
|
||||||
|
battery: number;
|
||||||
|
signalStrength?: number;
|
||||||
|
nextWaypoint?: {
|
||||||
|
name: string;
|
||||||
|
distance: number;
|
||||||
|
estimatedTime: number;
|
||||||
|
};
|
||||||
|
remainingDistance: number;
|
||||||
|
estimatedRemainingTime: number;
|
||||||
|
progress: number;
|
||||||
|
isPaused: boolean;
|
||||||
|
onPause: () => void;
|
||||||
|
onResume: () => void;
|
||||||
|
onStop: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 格式化距离 */
|
||||||
|
const formatDist = (m: number) => (m >= 1000 ? `${(m / 1000).toFixed(1)}km` : `${Math.round(m)}m`);
|
||||||
|
|
||||||
|
/** 格式化时间 */
|
||||||
|
const formatTime = (s: number) => {
|
||||||
|
const mins = Math.floor(s / 60);
|
||||||
|
const secs = Math.floor(s % 60);
|
||||||
|
if (mins >= 60) {
|
||||||
|
const h = Math.floor(mins / 60);
|
||||||
|
const m = mins % 60;
|
||||||
|
return `${h}时${m}分`;
|
||||||
|
}
|
||||||
|
return mins > 0 ? `${mins}分${secs}秒` : `${secs}秒`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const directionText = (heading: number) => {
|
||||||
|
const normalized = ((heading % 360) + 360) % 360;
|
||||||
|
if (normalized < 22.5 || normalized >= 337.5) return '北';
|
||||||
|
if (normalized < 67.5) return '东北';
|
||||||
|
if (normalized < 112.5) return '东';
|
||||||
|
if (normalized < 157.5) return '东南';
|
||||||
|
if (normalized < 202.5) return '南';
|
||||||
|
if (normalized < 247.5) return '西南';
|
||||||
|
if (normalized < 292.5) return '西';
|
||||||
|
return '西北';
|
||||||
|
};
|
||||||
|
|
||||||
|
const NavigationHUD: React.FC<NavigationHUDProps> = ({
|
||||||
|
mode,
|
||||||
|
routeName,
|
||||||
|
speed,
|
||||||
|
heading,
|
||||||
|
battery,
|
||||||
|
signalStrength,
|
||||||
|
nextWaypoint,
|
||||||
|
remainingDistance,
|
||||||
|
estimatedRemainingTime,
|
||||||
|
progress,
|
||||||
|
isPaused,
|
||||||
|
onPause,
|
||||||
|
onResume,
|
||||||
|
onStop,
|
||||||
|
}) => {
|
||||||
|
const maxSpeed = 12;
|
||||||
|
const clampedSpeed = Math.max(0, Math.min(speed, maxSpeed));
|
||||||
|
const speedPercent = clampedSpeed / maxSpeed;
|
||||||
|
const ringLength = 2 * Math.PI * 44;
|
||||||
|
const ringOffset = ringLength * (1 - speedPercent);
|
||||||
|
const normalizedProgress = Math.max(0, Math.min(100, progress));
|
||||||
|
const normalizedBattery = Math.max(0, Math.min(100, battery));
|
||||||
|
const normalizedSignal = Math.max(0, Math.min(100, signalStrength ?? 0));
|
||||||
|
|
||||||
|
const compassTicks = useMemo(() => {
|
||||||
|
const marks = [];
|
||||||
|
for (let i = 0; i < 12; i += 1) {
|
||||||
|
marks.push(<span key={i} className={styles.compassTick} style={{ transform: `rotate(${i * 30}deg)` }} />);
|
||||||
|
}
|
||||||
|
return marks;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const previewing = mode === 'preview';
|
||||||
|
const actionText = previewing ? '结束预览' : isPaused ? '继续航行' : '暂停航行';
|
||||||
|
const actionIcon = previewing ? <StopOutlined /> : isPaused ? <PlayCircleOutlined /> : <PauseCircleOutlined />;
|
||||||
|
const actionHandler = previewing ? onStop : isPaused ? onResume : onPause;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`${styles.hudContainer} ${previewing ? styles.previewMode : styles.sailingMode}`}>
|
||||||
|
<div className={styles.primaryCluster}>
|
||||||
|
<div className={styles.speedDial}>
|
||||||
|
<svg viewBox="0 0 120 120" className={styles.speedSvg}>
|
||||||
|
<circle cx="60" cy="60" r="44" className={styles.speedTrack} />
|
||||||
|
<circle
|
||||||
|
cx="60"
|
||||||
|
cy="60"
|
||||||
|
r="44"
|
||||||
|
className={styles.speedRing}
|
||||||
|
style={{ strokeDasharray: ringLength, strokeDashoffset: ringOffset }}
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
<div className={styles.speedCenter}>
|
||||||
|
<div className={styles.speedValue}>{speed.toFixed(1)}</div>
|
||||||
|
<div className={styles.speedUnit}>m/s</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className={styles.modeChip}>{previewing ? '预览模式' : '航行模式'}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.centerCluster}>
|
||||||
|
<div className={styles.routeHeader}>
|
||||||
|
<span className={styles.routeTitle}>{routeName || '未选择线路'}</span>
|
||||||
|
<span className={styles.routeProgress}>{normalizedProgress}%</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.routeProgressTrack}>
|
||||||
|
<div className={styles.routeProgressFill} style={{ width: `${normalizedProgress}%` }} />
|
||||||
|
</div>
|
||||||
|
<div className={styles.waypointCard}>
|
||||||
|
{nextWaypoint ? (
|
||||||
|
<>
|
||||||
|
<div className={styles.waypointMain}>
|
||||||
|
<SendOutlined className={styles.navArrow} />
|
||||||
|
<div>
|
||||||
|
<div className={styles.infoLabel}>下一航点</div>
|
||||||
|
<div className={styles.waypointName}>{nextWaypoint.name}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className={styles.waypointStats}>
|
||||||
|
<div>
|
||||||
|
<div className={styles.infoLabel}>到点距离</div>
|
||||||
|
<div className={styles.infoValue}>{formatDist(nextWaypoint.distance)}</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className={styles.infoLabel}>到点时间</div>
|
||||||
|
<div className={styles.infoValue}>{formatTime(nextWaypoint.estimatedTime)}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<div className={styles.emptyWaypoint}>
|
||||||
|
暂无航点数据
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className={styles.summaryRow}>
|
||||||
|
<div className={styles.summaryItem}>
|
||||||
|
<div className={styles.infoLabel}>剩余里程</div>
|
||||||
|
<div className={styles.summaryValue}>{formatDist(remainingDistance)}</div>
|
||||||
|
</div>
|
||||||
|
<div className={styles.summaryItem}>
|
||||||
|
<div className={styles.infoLabel}>预计剩余</div>
|
||||||
|
<div className={styles.summaryValue}>{formatTime(estimatedRemainingTime)}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.statusCluster}>
|
||||||
|
<div className={styles.compassCard}>
|
||||||
|
<div className={styles.cardTitle}><CompassOutlined /> 航向</div>
|
||||||
|
<div className={styles.compassDial}>
|
||||||
|
<div className={styles.compassRotor} style={{ transform: `rotate(${heading}deg)` }}>
|
||||||
|
{compassTicks}
|
||||||
|
</div>
|
||||||
|
<div className={styles.compassNeedle} />
|
||||||
|
</div>
|
||||||
|
<div className={styles.compassValue}>{Math.round(heading)}° · {directionText(heading)}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.powerCard}>
|
||||||
|
<div className={styles.powerRow}>
|
||||||
|
<span className={styles.infoLabel}><ThunderboltOutlined /> 电量</span>
|
||||||
|
<span className={styles.powerValue}>{Math.round(normalizedBattery)}%</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.powerTrack}>
|
||||||
|
<div className={styles.powerFill} style={{ width: `${normalizedBattery}%` }} />
|
||||||
|
</div>
|
||||||
|
<div className={styles.powerRow}>
|
||||||
|
<span className={styles.infoLabel}><WifiOutlined /> 信号</span>
|
||||||
|
<span className={styles.powerValue}>{signalStrength == null ? '--' : `${Math.round(normalizedSignal)}%`}</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.powerTrack}>
|
||||||
|
<div className={styles.signalFill} style={{ width: `${signalStrength == null ? 0 : normalizedSignal}%` }} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.actionCluster}>
|
||||||
|
<button className={`${styles.actionBtn} ${styles.actionPrimary}`} onClick={actionHandler}>
|
||||||
|
{actionIcon}
|
||||||
|
<span>{actionText}</span>
|
||||||
|
</button>
|
||||||
|
{!previewing && (
|
||||||
|
<button className={`${styles.actionBtn} ${styles.actionDanger}`} onClick={onStop}>
|
||||||
|
<StopOutlined />
|
||||||
|
<span>结束航行</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NavigationHUD;
|
||||||
@@ -0,0 +1,369 @@
|
|||||||
|
.overlay {
|
||||||
|
position: absolute;
|
||||||
|
top: 20px;
|
||||||
|
left: 20px;
|
||||||
|
z-index: 910;
|
||||||
|
width: 340px;
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 14px;
|
||||||
|
background:
|
||||||
|
linear-gradient(145deg, rgba(8, 21, 36, 0.94) 0%, rgba(13, 35, 58, 0.9) 58%, rgba(18, 28, 46, 0.95) 100%);
|
||||||
|
border: 1px solid rgba(92, 180, 255, 0.28);
|
||||||
|
box-shadow:
|
||||||
|
0 18px 42px rgba(3, 10, 24, 0.42),
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.08),
|
||||||
|
inset 0 0 0 1px rgba(41, 129, 210, 0.12);
|
||||||
|
color: #eef7ff;
|
||||||
|
overflow: hidden;
|
||||||
|
font-family: 'Rajdhani', 'DIN', 'Avenir Next', 'PingFang SC', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.overlay::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 14px;
|
||||||
|
right: 14px;
|
||||||
|
height: 1px;
|
||||||
|
background: linear-gradient(90deg, transparent 0%, rgba(134, 211, 255, 0.75) 50%, transparent 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.previewMode {
|
||||||
|
border-color: rgba(74, 196, 255, 0.42);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sailingMode {
|
||||||
|
border-color: rgba(255, 152, 108, 0.34);
|
||||||
|
}
|
||||||
|
|
||||||
|
.header,
|
||||||
|
.progressCard,
|
||||||
|
.waypointList,
|
||||||
|
.footer {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.routeBlock {
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.caption {
|
||||||
|
font-size: 11px;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: rgba(186, 223, 255, 0.62);
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 22px;
|
||||||
|
font-weight: 700;
|
||||||
|
line-height: 1.1;
|
||||||
|
color: #f3f9ff;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.headerMeta {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
font-size: 12px;
|
||||||
|
color: rgba(202, 230, 255, 0.78);
|
||||||
|
}
|
||||||
|
|
||||||
|
.headerMeta span {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.statusTag {
|
||||||
|
flex-shrink: 0;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: rgba(28, 69, 104, 0.62);
|
||||||
|
border: 1px solid rgba(112, 191, 255, 0.24);
|
||||||
|
color: #dff4ff;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pulseDot {
|
||||||
|
width: 7px;
|
||||||
|
height: 7px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #49c7ff;
|
||||||
|
box-shadow: 0 0 0 0 rgba(73, 199, 255, 0.6);
|
||||||
|
animation: pulse 1.5s infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes pulse {
|
||||||
|
0% {
|
||||||
|
transform: scale(0.85);
|
||||||
|
box-shadow: 0 0 0 0 rgba(73, 199, 255, 0.55);
|
||||||
|
}
|
||||||
|
70% {
|
||||||
|
transform: scale(1.05);
|
||||||
|
box-shadow: 0 0 0 8px rgba(73, 199, 255, 0);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: scale(0.85);
|
||||||
|
box-shadow: 0 0 0 0 rgba(73, 199, 255, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.progressCard {
|
||||||
|
margin-top: 14px;
|
||||||
|
padding: 12px;
|
||||||
|
border-radius: 14px;
|
||||||
|
background: linear-gradient(145deg, rgba(19, 48, 77, 0.72) 0%, rgba(10, 24, 40, 0.86) 100%);
|
||||||
|
border: 1px solid rgba(104, 184, 255, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.progressHead {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #dcefff;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progressBar {
|
||||||
|
margin-top: 10px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 999px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: rgba(198, 225, 250, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.progressFill {
|
||||||
|
height: 100%;
|
||||||
|
border-radius: inherit;
|
||||||
|
background: linear-gradient(90deg, #2c9bff 0%, #43eeff 55%, #87ffd4 100%);
|
||||||
|
box-shadow: 0 0 10px rgba(67, 238, 255, 0.46);
|
||||||
|
transition: width 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metricRow {
|
||||||
|
margin-top: 12px;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metricItem {
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: rgba(255, 255, 255, 0.04);
|
||||||
|
border: 1px solid rgba(123, 186, 236, 0.14);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metricLabel {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: rgba(193, 224, 247, 0.68);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metricValue {
|
||||||
|
display: block;
|
||||||
|
margin-top: 4px;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #f4fbff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointList {
|
||||||
|
margin-top: 14px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
max-height: 290px;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding-right: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointList::-webkit-scrollbar {
|
||||||
|
width: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointList::-webkit-scrollbar-thumb {
|
||||||
|
background: rgba(180, 217, 255, 0.28);
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.waypointItem {
|
||||||
|
display: flex;
|
||||||
|
align-items: stretch;
|
||||||
|
gap: 10px;
|
||||||
|
min-height: 48px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trackColumn {
|
||||||
|
width: 24px;
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.iconWrapper {
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: rgba(8, 21, 36, 0.9);
|
||||||
|
}
|
||||||
|
|
||||||
|
.passedIcon {
|
||||||
|
color: #78ffcf;
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.currentIcon {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 2px solid #4ec8ff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
box-shadow: 0 0 10px rgba(78, 200, 255, 0.58);
|
||||||
|
}
|
||||||
|
|
||||||
|
.currentInner {
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #4ec8ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upcomingIcon {
|
||||||
|
width: 11px;
|
||||||
|
height: 11px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 2px solid rgba(219, 235, 246, 0.36);
|
||||||
|
}
|
||||||
|
|
||||||
|
.connectingLine {
|
||||||
|
position: absolute;
|
||||||
|
top: 22px;
|
||||||
|
bottom: 0;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
width: 2px;
|
||||||
|
background: rgba(224, 239, 255, 0.14);
|
||||||
|
}
|
||||||
|
|
||||||
|
.linePassed {
|
||||||
|
background: linear-gradient(180deg, #78ffcf 0%, rgba(120, 255, 207, 0.2) 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.lineCurrent {
|
||||||
|
background: linear-gradient(180deg, #55d0ff 0%, rgba(85, 208, 255, 0.2) 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.contentColumn {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 2px 0 12px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 10px;
|
||||||
|
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.name {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #edf7ff;
|
||||||
|
font-weight: 600;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stateText {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.4px;
|
||||||
|
color: rgba(194, 223, 244, 0.72);
|
||||||
|
}
|
||||||
|
|
||||||
|
.itemPassed .name,
|
||||||
|
.itemPassed .stateText {
|
||||||
|
color: rgba(194, 214, 229, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.itemCurrent .contentColumn {
|
||||||
|
padding-left: 10px;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: linear-gradient(90deg, rgba(62, 172, 244, 0.18) 0%, rgba(62, 172, 244, 0) 100%);
|
||||||
|
border-bottom-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.itemCurrent .stateText {
|
||||||
|
color: #7fdfff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.itemUpcoming .name {
|
||||||
|
color: rgba(224, 239, 255, 0.72);
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
margin-top: 10px;
|
||||||
|
padding-top: 12px;
|
||||||
|
border-top: 1px solid rgba(255, 255, 255, 0.08);
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: rgba(206, 228, 246, 0.72);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 960px) {
|
||||||
|
.overlay {
|
||||||
|
width: calc(100% - 24px);
|
||||||
|
left: 12px;
|
||||||
|
top: 12px;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.statusTag {
|
||||||
|
align-self: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metricRow {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import {
|
||||||
|
CheckCircleFilled,
|
||||||
|
ClockCircleOutlined,
|
||||||
|
EnvironmentOutlined,
|
||||||
|
FlagOutlined,
|
||||||
|
RadarChartOutlined,
|
||||||
|
} from '@ant-design/icons';
|
||||||
|
import styles from './index.less';
|
||||||
|
|
||||||
|
type NavigationMode = 'preview' | 'sailing';
|
||||||
|
|
||||||
|
export interface NavigationOverlayProps {
|
||||||
|
mode: NavigationMode;
|
||||||
|
routeName: string;
|
||||||
|
waypoints: Array<{
|
||||||
|
name: string;
|
||||||
|
waypointIndex: number;
|
||||||
|
}>;
|
||||||
|
currentWaypointIndex: number;
|
||||||
|
totalDistance: number;
|
||||||
|
remainingDistance: number;
|
||||||
|
estimatedRemainingTime: number;
|
||||||
|
progress: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const NavigationOverlay: React.FC<NavigationOverlayProps> = ({
|
||||||
|
mode,
|
||||||
|
routeName,
|
||||||
|
waypoints,
|
||||||
|
currentWaypointIndex,
|
||||||
|
totalDistance,
|
||||||
|
remainingDistance,
|
||||||
|
estimatedRemainingTime,
|
||||||
|
progress,
|
||||||
|
}) => {
|
||||||
|
const formatDistance = (m: number) => {
|
||||||
|
if (m >= 1000) {
|
||||||
|
return `${(m / 1000).toFixed(1)}km`;
|
||||||
|
}
|
||||||
|
return `${Math.round(m)}m`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatTime = (s: number) => {
|
||||||
|
const safeSeconds = Math.max(0, Math.floor(s));
|
||||||
|
const mins = Math.floor(safeSeconds / 60);
|
||||||
|
const secs = Math.floor(safeSeconds % 60);
|
||||||
|
if (mins >= 60) {
|
||||||
|
const hours = Math.floor(mins / 60);
|
||||||
|
const restMins = mins % 60;
|
||||||
|
return `${hours}时${restMins}分`;
|
||||||
|
}
|
||||||
|
return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const safeProgress = Math.max(0, Math.min(100, progress));
|
||||||
|
const modeText = mode === 'preview' ? '预览态' : '航行中';
|
||||||
|
const completedCount = waypoints.filter((wp) => wp.waypointIndex < currentWaypointIndex).length;
|
||||||
|
|
||||||
|
// Get visible waypoints
|
||||||
|
const visibleWaypoints = useMemo(() => {
|
||||||
|
// Current waypoint logic: showing ±2 around current.
|
||||||
|
let start = Math.max(0, currentWaypointIndex - 2);
|
||||||
|
let end = Math.min(waypoints.length - 1, start + 4);
|
||||||
|
|
||||||
|
// Adjust start if we are near the end
|
||||||
|
if (end - start < 4) {
|
||||||
|
start = Math.max(0, end - 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
return waypoints.slice(start, end + 1);
|
||||||
|
}, [waypoints, currentWaypointIndex]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`${styles.overlay} ${mode === 'preview' ? styles.previewMode : styles.sailingMode}`}>
|
||||||
|
<div className={styles.header}>
|
||||||
|
<div className={styles.routeBlock}>
|
||||||
|
<div className={styles.caption}>导航总览</div>
|
||||||
|
<div className={styles.title}>{routeName || '未命名路线'}</div>
|
||||||
|
<div className={styles.headerMeta}>
|
||||||
|
<span><RadarChartOutlined /> 总里程 {formatDistance(totalDistance)}</span>
|
||||||
|
<span><FlagOutlined /> {waypoints.length} 航点</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className={styles.statusTag}>
|
||||||
|
<div className={styles.pulseDot} />
|
||||||
|
{modeText}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.progressCard}>
|
||||||
|
<div className={styles.progressHead}>
|
||||||
|
<span>路线进度</span>
|
||||||
|
<span>{Math.round(safeProgress)}%</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.progressBar}>
|
||||||
|
<div
|
||||||
|
className={styles.progressFill}
|
||||||
|
style={{ width: `${safeProgress}%` }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className={styles.metricRow}>
|
||||||
|
<div className={styles.metricItem}>
|
||||||
|
<span className={styles.metricLabel}><EnvironmentOutlined /> 剩余</span>
|
||||||
|
<span className={styles.metricValue}>{formatDistance(remainingDistance)}</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.metricItem}>
|
||||||
|
<span className={styles.metricLabel}><ClockCircleOutlined /> 预计</span>
|
||||||
|
<span className={styles.metricValue}>{formatTime(estimatedRemainingTime)}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.waypointList}>
|
||||||
|
{visibleWaypoints.map((wp, i) => {
|
||||||
|
const isPassed = wp.waypointIndex < currentWaypointIndex;
|
||||||
|
const isCurrent = wp.waypointIndex === currentWaypointIndex;
|
||||||
|
const isUpcoming = wp.waypointIndex > currentWaypointIndex;
|
||||||
|
const isLastVisible = i === visibleWaypoints.length - 1;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={`${wp.waypointIndex}-${wp.name}`}
|
||||||
|
className={[
|
||||||
|
styles.waypointItem,
|
||||||
|
isPassed ? styles.itemPassed : '',
|
||||||
|
isCurrent ? styles.itemCurrent : '',
|
||||||
|
isUpcoming ? styles.itemUpcoming : '',
|
||||||
|
].filter(Boolean).join(' ')}
|
||||||
|
>
|
||||||
|
<div className={styles.trackColumn}>
|
||||||
|
<div className={styles.iconWrapper}>
|
||||||
|
{isPassed && <CheckCircleFilled className={styles.passedIcon} />}
|
||||||
|
{isCurrent && (
|
||||||
|
<div className={styles.currentIcon}>
|
||||||
|
<div className={styles.currentInner} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{isUpcoming && <div className={styles.upcomingIcon} />}
|
||||||
|
</div>
|
||||||
|
{!isLastVisible && (
|
||||||
|
<div className={[
|
||||||
|
styles.connectingLine,
|
||||||
|
(isPassed && wp.waypointIndex < currentWaypointIndex - 1) ? styles.linePassed : '',
|
||||||
|
(isPassed && wp.waypointIndex === currentWaypointIndex - 1) ? styles.lineCurrent : '',
|
||||||
|
].filter(Boolean).join(' ')} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.contentColumn}>
|
||||||
|
<span className={styles.name}>{`${wp.waypointIndex + 1}. ${wp.name}`}</span>
|
||||||
|
<span className={styles.stateText}>{isCurrent ? '当前' : isPassed ? '已过' : '待达'}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.footer}>
|
||||||
|
<span>{`已通过 ${completedCount}/${waypoints.length} 航点`}</span>
|
||||||
|
<span>{`当前第 ${Math.max(1, currentWaypointIndex + 1)} 航点`}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NavigationOverlay;
|
||||||
@@ -0,0 +1,314 @@
|
|||||||
|
/* ========== 玻璃拟态变量 ========== */
|
||||||
|
@glass-border: rgba(65, 170, 255, 0.28);
|
||||||
|
@glass-border-light: rgba(92, 211, 255, 0.18);
|
||||||
|
@accent-cyan: #00d4ff;
|
||||||
|
@accent-blue: #0096ff;
|
||||||
|
@text-primary: #eaf6ff;
|
||||||
|
@text-secondary: rgba(255, 255, 255, 0.55);
|
||||||
|
@text-dim: rgba(255, 255, 255, 0.4);
|
||||||
|
@card-bg: linear-gradient(145deg, rgba(10, 24, 48, 0.7), rgba(8, 18, 38, 0.5));
|
||||||
|
@card-shadow: 0 2px 12px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.06);
|
||||||
|
@transition-fast: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
|
||||||
|
.panel {
|
||||||
|
height: 100%;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section {
|
||||||
|
padding: 16px;
|
||||||
|
border-bottom: 1px solid @glass-border-light;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
bottom: -1px;
|
||||||
|
left: 16px;
|
||||||
|
right: 16px;
|
||||||
|
height: 1px;
|
||||||
|
background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.15), transparent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionTitle {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: @text-secondary;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 1.5px;
|
||||||
|
font-family: 'Rajdhani', 'DIN', sans-serif;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
width: 3px;
|
||||||
|
height: 14px;
|
||||||
|
border-radius: 2px;
|
||||||
|
background: linear-gradient(180deg, @accent-cyan, @accent-blue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 罗盘 ========== */
|
||||||
|
.compassWrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
padding: 12px;
|
||||||
|
background: @card-bg;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid rgba(0, 100, 200, 0.15);
|
||||||
|
box-shadow: @card-shadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compass {
|
||||||
|
width: 180px;
|
||||||
|
height: 180px;
|
||||||
|
position: relative;
|
||||||
|
filter: drop-shadow(0 0 8px rgba(0, 150, 255, 0.15));
|
||||||
|
}
|
||||||
|
|
||||||
|
.compassSvg {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.headingText {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 6px;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.headingLabel {
|
||||||
|
font-size: 11px;
|
||||||
|
color: @text-dim;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-family: 'Rajdhani', 'DIN', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.headingValue {
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: @accent-cyan;
|
||||||
|
font-family: 'Rajdhani', 'DIN', monospace;
|
||||||
|
text-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
|
||||||
|
letter-spacing: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 左转/右转 ========== */
|
||||||
|
.turnRow {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 16px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.turnBtn {
|
||||||
|
width: 52px;
|
||||||
|
height: 38px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid rgba(0, 150, 220, 0.35);
|
||||||
|
background: linear-gradient(145deg, rgba(0, 60, 120, 0.35), rgba(0, 40, 80, 0.25));
|
||||||
|
backdrop-filter: blur(6px);
|
||||||
|
color: rgba(255, 255, 255, 0.75);
|
||||||
|
font-size: 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: @transition-fast;
|
||||||
|
padding: 0;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.06);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: linear-gradient(145deg, rgba(0, 80, 160, 0.5), rgba(0, 60, 120, 0.35));
|
||||||
|
border-color: rgba(0, 180, 255, 0.5);
|
||||||
|
color: #fff;
|
||||||
|
box-shadow: 0 2px 12px rgba(0, 100, 200, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background: linear-gradient(145deg, rgba(0, 100, 200, 0.6), rgba(0, 80, 160, 0.45));
|
||||||
|
border-color: @accent-cyan;
|
||||||
|
transform: scale(0.95);
|
||||||
|
box-shadow: 0 0 16px rgba(0, 180, 255, 0.3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 速度滑块 ========== */
|
||||||
|
.speedRow {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
background: @card-bg;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid rgba(0, 100, 200, 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
.speedLabel {
|
||||||
|
font-size: 11px;
|
||||||
|
color: @text-dim;
|
||||||
|
flex-shrink: 0;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
font-family: 'Rajdhani', 'DIN', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.speedSlider {
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
:global(.ant-slider-rail) {
|
||||||
|
background: rgba(255, 255, 255, 0.08);
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.ant-slider-track) {
|
||||||
|
background: linear-gradient(90deg, @accent-blue, @accent-cyan);
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.ant-slider-handle)::after {
|
||||||
|
box-shadow: 0 0 8px rgba(0, 180, 255, 0.5);
|
||||||
|
border-color: @accent-cyan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.speedValue {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: @accent-cyan;
|
||||||
|
font-family: 'Rajdhani', 'DIN', monospace;
|
||||||
|
flex-shrink: 0;
|
||||||
|
min-width: 60px;
|
||||||
|
text-align: right;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 紧急停靠 ========== */
|
||||||
|
.emergencyBtn {
|
||||||
|
height: 44px;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid rgba(255, 60, 60, 0.4);
|
||||||
|
background: linear-gradient(145deg, rgba(180, 30, 10, 0.7), rgba(140, 20, 5, 0.5));
|
||||||
|
backdrop-filter: blur(6px);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: @transition-fast;
|
||||||
|
letter-spacing: 2px;
|
||||||
|
box-shadow: 0 2px 12px rgba(180, 30, 10, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.08);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: linear-gradient(145deg, rgba(200, 40, 15, 0.8), rgba(160, 30, 10, 0.6));
|
||||||
|
border-color: rgba(255, 80, 60, 0.5);
|
||||||
|
box-shadow: 0 4px 20px rgba(200, 40, 15, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background: linear-gradient(145deg, rgba(160, 20, 5, 0.8), rgba(120, 15, 0, 0.6));
|
||||||
|
transform: scale(0.98);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 实时数据卡片 ========== */
|
||||||
|
.dataCard {
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 14px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
backdrop-filter: blur(6px);
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
// 顶部高光线
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 10%;
|
||||||
|
right: 10%;
|
||||||
|
height: 1px;
|
||||||
|
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 三级玻璃层次 */
|
||||||
|
.dataCardLevel1 {
|
||||||
|
background: linear-gradient(145deg, rgba(0, 80, 160, 0.18), rgba(0, 60, 120, 0.1));
|
||||||
|
border: 1px solid rgba(0, 112, 212, 0.28);
|
||||||
|
box-shadow: @card-shadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataCardLevel2 {
|
||||||
|
background: linear-gradient(145deg, rgba(0, 140, 120, 0.12), rgba(0, 100, 80, 0.06));
|
||||||
|
border: 1px solid rgba(0, 180, 150, 0.22);
|
||||||
|
box-shadow: @card-shadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataCardLevel3 {
|
||||||
|
background: linear-gradient(145deg, rgba(0, 160, 200, 0.1), rgba(0, 120, 160, 0.05));
|
||||||
|
border: 1px solid rgba(0, 212, 255, 0.18);
|
||||||
|
box-shadow: @card-shadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataCardHeader {
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: @accent-blue;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
border-bottom: 1px solid rgba(0, 112, 212, 0.15);
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 1.2px;
|
||||||
|
font-family: 'Rajdhani', 'DIN', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataCardHeaderGreen {
|
||||||
|
color: #00c8a0;
|
||||||
|
border-bottom-color: rgba(0, 200, 160, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataCardHeaderCyan {
|
||||||
|
color: @accent-cyan;
|
||||||
|
border-bottom-color: rgba(0, 212, 255, 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataRow {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 5px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataLabel {
|
||||||
|
font-size: 12px;
|
||||||
|
color: @text-dim;
|
||||||
|
letter-spacing: 0.3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataValue {
|
||||||
|
font-size: 13px;
|
||||||
|
color: @text-primary;
|
||||||
|
font-weight: 600;
|
||||||
|
font-family: 'Rajdhani', 'DIN', monospace;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,229 @@
|
|||||||
|
import React, { useMemo, useCallback, useRef, useState } from 'react';
|
||||||
|
import { Button, Slider, message } from 'antd';
|
||||||
|
import {
|
||||||
|
WarningOutlined,
|
||||||
|
ArrowLeftOutlined,
|
||||||
|
ArrowRightOutlined,
|
||||||
|
} from '@ant-design/icons';
|
||||||
|
import type { BoatTelemetryData } from '@/types/boatRoute';
|
||||||
|
import { sendBoatCommand } from '../../services/clientApi';
|
||||||
|
import styles from './index.less';
|
||||||
|
|
||||||
|
interface RightPanelProps {
|
||||||
|
deviceInfo: { deviceSn: string; deviceName: string; deviceType: number };
|
||||||
|
boatData: BoatTelemetryData | null;
|
||||||
|
sseConnected: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const RightPanel: React.FC<RightPanelProps> = ({ deviceInfo, boatData, sseConnected }) => {
|
||||||
|
const heading = useMemo(() => boatData?.heading ?? 0, [boatData?.heading]);
|
||||||
|
const speed = useMemo(() => boatData?.speed ?? 0, [boatData?.speed]);
|
||||||
|
const battery = useMemo(() => boatData?.battery ?? 0, [boatData?.battery]);
|
||||||
|
const [targetSpeed, setTargetSpeed] = useState(5);
|
||||||
|
const activeCommandRef = useRef<string | null>(null);
|
||||||
|
|
||||||
|
const handleCommandPress = useCallback((command: string) => {
|
||||||
|
activeCommandRef.current = command;
|
||||||
|
sendBoatCommand(deviceInfo.deviceSn, command, 'press').catch(() => {
|
||||||
|
message.error('指令发送失败');
|
||||||
|
});
|
||||||
|
}, [deviceInfo.deviceSn]);
|
||||||
|
|
||||||
|
const handleCommandRelease = useCallback((command: string) => {
|
||||||
|
if (activeCommandRef.current === command) {
|
||||||
|
activeCommandRef.current = null;
|
||||||
|
}
|
||||||
|
sendBoatCommand(deviceInfo.deviceSn, command, 'release').catch(() => {});
|
||||||
|
}, [deviceInfo.deviceSn]);
|
||||||
|
|
||||||
|
const handleEmergencyStop = useCallback(() => {
|
||||||
|
activeCommandRef.current = null;
|
||||||
|
sendBoatCommand(deviceInfo.deviceSn, 'stop', 'press').catch(() => {
|
||||||
|
message.error('紧急停靠指令发送失败');
|
||||||
|
});
|
||||||
|
}, [deviceInfo.deviceSn]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.panel}>
|
||||||
|
{/* 船体控制 */}
|
||||||
|
<div className={styles.section}>
|
||||||
|
<div className={styles.sectionTitle}>船体控制</div>
|
||||||
|
|
||||||
|
{/* 罗盘仪表盘 */}
|
||||||
|
<div className={styles.compassWrapper}>
|
||||||
|
<div className={styles.compass}>
|
||||||
|
{/* 外圈刻度 */}
|
||||||
|
<svg className={styles.compassSvg} viewBox="0 0 200 200">
|
||||||
|
{/* 外圆 */}
|
||||||
|
<circle cx="100" cy="100" r="90" fill="none" stroke="rgba(0,150,220,0.3)" strokeWidth="2" />
|
||||||
|
<circle cx="100" cy="100" r="88" fill="none" stroke="rgba(0,150,220,0.08)" strokeWidth="4" />
|
||||||
|
{/* 刻度线 */}
|
||||||
|
{Array.from({ length: 72 }).map((_, i) => {
|
||||||
|
const angle = i * 5;
|
||||||
|
const isMajor = angle % 30 === 0;
|
||||||
|
const r1 = isMajor ? 78 : 83;
|
||||||
|
const r2 = 88;
|
||||||
|
const rad = (angle - 90) * Math.PI / 180;
|
||||||
|
return (
|
||||||
|
<line
|
||||||
|
key={i}
|
||||||
|
x1={100 + r1 * Math.cos(rad)}
|
||||||
|
y1={100 + r1 * Math.sin(rad)}
|
||||||
|
x2={100 + r2 * Math.cos(rad)}
|
||||||
|
y2={100 + r2 * Math.sin(rad)}
|
||||||
|
stroke={isMajor ? 'rgba(0,180,255,0.6)' : 'rgba(0,180,255,0.2)'}
|
||||||
|
strokeWidth={isMajor ? 2 : 1}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{/* N/S/E/W 标记 */}
|
||||||
|
<text x="100" y="26" textAnchor="middle" fill="#00d4ff" fontSize="14" fontWeight="bold">N</text>
|
||||||
|
<text x="100" y="182" textAnchor="middle" fill="rgba(255,255,255,0.5)" fontSize="12">S</text>
|
||||||
|
<text x="178" y="104" textAnchor="middle" fill="rgba(255,255,255,0.5)" fontSize="12">E</text>
|
||||||
|
<text x="22" y="104" textAnchor="middle" fill="rgba(255,255,255,0.5)" fontSize="12">W</text>
|
||||||
|
{/* 方向指针(船头) */}
|
||||||
|
<g transform={`rotate(${heading}, 100, 100)`}>
|
||||||
|
<polygon
|
||||||
|
points="100,32 93,70 100,62 107,70"
|
||||||
|
fill="#0070d4"
|
||||||
|
stroke="#00a0ff"
|
||||||
|
strokeWidth="1"
|
||||||
|
/>
|
||||||
|
<line x1="100" y1="62" x2="100" y2="100" stroke="rgba(0,112,212,0.5)" strokeWidth="2" />
|
||||||
|
</g>
|
||||||
|
{/* 中心圆点 */}
|
||||||
|
<circle cx="100" cy="100" r="5" fill="#0a1628" stroke="#00a0ff" strokeWidth="2" />
|
||||||
|
<circle cx="100" cy="100" r="2" fill="#00d4ff" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div className={styles.headingText}>
|
||||||
|
<span className={styles.headingLabel}>航向</span>
|
||||||
|
<span className={styles.headingValue}>{heading.toFixed(0)}°</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 左转 / 右转按钮 */}
|
||||||
|
<div className={styles.turnRow}>
|
||||||
|
<Button
|
||||||
|
className={styles.turnBtn}
|
||||||
|
onMouseDown={() => handleCommandPress('left')}
|
||||||
|
onMouseUp={() => handleCommandRelease('left')}
|
||||||
|
onMouseLeave={() => handleCommandRelease('left')}
|
||||||
|
onTouchStart={() => handleCommandPress('left')}
|
||||||
|
onTouchEnd={() => handleCommandRelease('left')}
|
||||||
|
icon={<ArrowLeftOutlined />}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
className={styles.turnBtn}
|
||||||
|
onMouseDown={() => handleCommandPress('right')}
|
||||||
|
onMouseUp={() => handleCommandRelease('right')}
|
||||||
|
onMouseLeave={() => handleCommandRelease('right')}
|
||||||
|
onTouchStart={() => handleCommandPress('right')}
|
||||||
|
onTouchEnd={() => handleCommandRelease('right')}
|
||||||
|
icon={<ArrowRightOutlined />}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 速度滑块 */}
|
||||||
|
<div className={styles.speedRow}>
|
||||||
|
<span className={styles.speedLabel}>速度</span>
|
||||||
|
<div className={styles.speedSlider}>
|
||||||
|
<Slider
|
||||||
|
min={0}
|
||||||
|
max={15}
|
||||||
|
step={0.5}
|
||||||
|
value={targetSpeed}
|
||||||
|
onChange={setTargetSpeed}
|
||||||
|
tooltip={{ formatter: (v) => `${v} km/h` }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<span className={styles.speedValue}>{targetSpeed} km/h</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 紧急停靠 */}
|
||||||
|
<Button
|
||||||
|
className={styles.emergencyBtn}
|
||||||
|
onClick={handleEmergencyStop}
|
||||||
|
block
|
||||||
|
>
|
||||||
|
<WarningOutlined />
|
||||||
|
<span>紧急停靠</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 实时数据 */}
|
||||||
|
<div className={styles.section}>
|
||||||
|
<div className={styles.sectionTitle}>实时数据</div>
|
||||||
|
|
||||||
|
{/* 船舶状态 */}
|
||||||
|
<div className={`${styles.dataCard} ${styles.dataCardLevel1}`}>
|
||||||
|
<div className={styles.dataCardHeader}>船舶状态</div>
|
||||||
|
<div className={styles.dataRow}>
|
||||||
|
<span className={styles.dataLabel}>速度</span>
|
||||||
|
<span className={styles.dataValue}>{speed.toFixed(1)} km/h</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.dataRow}>
|
||||||
|
<span className={styles.dataLabel}>方向</span>
|
||||||
|
<span className={styles.dataValue}>{heading.toFixed(0)}°</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.dataRow}>
|
||||||
|
<span className={styles.dataLabel}>电量</span>
|
||||||
|
<span className={styles.dataValue} style={{ color: battery < 20 ? '#ff4d4f' : '#00ff88' }}>
|
||||||
|
{battery.toFixed(0)}%
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.dataRow}>
|
||||||
|
<span className={styles.dataLabel}>模式</span>
|
||||||
|
<span className={styles.dataValue}>{boatData?.taskId ? '自动' : '手动'}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 环境数据 */}
|
||||||
|
<div className={`${styles.dataCard} ${styles.dataCardLevel2}`}>
|
||||||
|
<div className={`${styles.dataCardHeader} ${styles.dataCardHeaderGreen}`}>环境数据</div>
|
||||||
|
<div className={styles.dataRow}>
|
||||||
|
<span className={styles.dataLabel}>水质</span>
|
||||||
|
<span className={styles.dataValue} style={{ color: '#00d4aa' }}>优</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.dataRow}>
|
||||||
|
<span className={styles.dataLabel}>风速</span>
|
||||||
|
<span className={styles.dataValue}>{(1.5 + (boatData?.speed ?? 0) * 0.3).toFixed(1)} m/s</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.dataRow}>
|
||||||
|
<span className={styles.dataLabel}>温度</span>
|
||||||
|
<span className={styles.dataValue}>{(18 + Math.round((boatData?.heading ?? 0) % 5)).toFixed(0)}°C</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 设备状态 */}
|
||||||
|
<div className={`${styles.dataCard} ${styles.dataCardLevel3}`}>
|
||||||
|
<div className={`${styles.dataCardHeader} ${styles.dataCardHeaderCyan}`}>设备状态</div>
|
||||||
|
<div className={styles.dataRow}>
|
||||||
|
<span className={styles.dataLabel}>传感器</span>
|
||||||
|
<span className={styles.dataValue} style={{ color: '#00ff88' }}>正常</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.dataRow}>
|
||||||
|
<span className={styles.dataLabel}>连接状态</span>
|
||||||
|
<span className={styles.dataValue} style={{ color: sseConnected ? '#00ff88' : '#ff4d4f' }}>
|
||||||
|
{sseConnected ? '已连接' : '未连接'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.dataRow}>
|
||||||
|
<span className={styles.dataLabel}>设备SN</span>
|
||||||
|
<span className={styles.dataValue}>{deviceInfo.deviceSn}</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.dataRow}>
|
||||||
|
<span className={styles.dataLabel}>GPS</span>
|
||||||
|
<span className={styles.dataValue}>
|
||||||
|
{boatData?.longitude != null
|
||||||
|
? `${boatData.longitude.toFixed(4)}, ${boatData.latitude?.toFixed(4)}`
|
||||||
|
: '--'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RightPanel;
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* 设备认证与登出逻辑
|
||||||
|
* 从 sessionStorage 读取设备信息,提供登出操作
|
||||||
|
*/
|
||||||
|
import { useEffect, useState, useCallback, useMemo } from 'react';
|
||||||
|
import { history } from 'umi';
|
||||||
|
import { Modal } from 'antd';
|
||||||
|
|
||||||
|
interface DeviceInfo {
|
||||||
|
deviceSn: string;
|
||||||
|
deviceName: string;
|
||||||
|
deviceType: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UseClientAuthReturn {
|
||||||
|
deviceSn: string;
|
||||||
|
deviceInfo: DeviceInfo | null;
|
||||||
|
handleLogout: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useClientAuth(onBeforeLogout?: () => void): UseClientAuthReturn {
|
||||||
|
const [deviceInfo, setDeviceInfo] = useState<DeviceInfo | null>(null);
|
||||||
|
const deviceSn = useMemo(() => sessionStorage.getItem('client_device_sn') || '', []);
|
||||||
|
|
||||||
|
// 校验登录状态
|
||||||
|
useEffect(() => {
|
||||||
|
const sn = sessionStorage.getItem('client_device_sn');
|
||||||
|
const info = sessionStorage.getItem('client_device_info');
|
||||||
|
if (!sn || !info) {
|
||||||
|
history.push('/client/login');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
setDeviceInfo(JSON.parse(info));
|
||||||
|
} catch {
|
||||||
|
history.push('/client/login');
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleLogout = useCallback(() => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '确认退出',
|
||||||
|
content: '退出后需要重新输入设备SN登录',
|
||||||
|
okText: '退出',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: () => {
|
||||||
|
onBeforeLogout?.();
|
||||||
|
sessionStorage.removeItem('client_device_sn');
|
||||||
|
sessionStorage.removeItem('client_device_info');
|
||||||
|
history.push('/client/login');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, [onBeforeLogout]);
|
||||||
|
|
||||||
|
return { deviceSn, deviceInfo, handleLogout };
|
||||||
|
}
|
||||||
@@ -0,0 +1,228 @@
|
|||||||
|
/**
|
||||||
|
* 客户端SSE Hook - 无人船遥测数据
|
||||||
|
* 基于现有 useBoatSSE 模式,连接客户端专用SSE端点(无需认证)
|
||||||
|
*/
|
||||||
|
import { useState, useRef, useEffect, useCallback } from 'react';
|
||||||
|
import type { BoatTelemetryData } from '@/types/boatRoute';
|
||||||
|
|
||||||
|
const IDLE_TIMEOUT_MS = 30 * 60 * 1000;
|
||||||
|
|
||||||
|
export interface UseClientSSEReturn {
|
||||||
|
boatData: BoatTelemetryData | null;
|
||||||
|
sseConnected: boolean;
|
||||||
|
loading: boolean;
|
||||||
|
connectSSE: (deviceSn: string) => Promise<void>;
|
||||||
|
disconnectSSE: (deviceSn?: string) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useClientSSE = (): UseClientSSEReturn => {
|
||||||
|
const [boatData, setBoatData] = useState<BoatTelemetryData | null>(null);
|
||||||
|
const [sseConnected, setSSEConnected] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const abortControllerRef = useRef<AbortController | null>(null);
|
||||||
|
const currentDeviceSnRef = useRef<string>('');
|
||||||
|
const clientSessionIdRef = useRef<string>(
|
||||||
|
`client_pad_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`
|
||||||
|
);
|
||||||
|
const reconnectTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
const reconnectAttemptsRef = useRef<number>(0);
|
||||||
|
const maxReconnectAttempts = 10;
|
||||||
|
const shouldReconnectRef = useRef<boolean>(true);
|
||||||
|
const idleTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
|
const performDisconnect = (deviceSn: string, sessionId: string) => {
|
||||||
|
if (!deviceSn) return;
|
||||||
|
fetch(`/api-device/client/sse/telemetry/${deviceSn}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: { 'X-Client-Session-Id': sessionId },
|
||||||
|
keepalive: true,
|
||||||
|
}).catch(() => {});
|
||||||
|
};
|
||||||
|
|
||||||
|
const performBeaconDisconnect = (deviceSn: string, sessionId: string) => {
|
||||||
|
if (!deviceSn) return;
|
||||||
|
const url = `/api-device/client/sse/telemetry/${deviceSn}/disconnect`;
|
||||||
|
if (navigator.sendBeacon) {
|
||||||
|
const blob = new Blob([JSON.stringify({ sessionId })], { type: 'application/json' });
|
||||||
|
navigator.sendBeacon(url, blob);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const disconnectSSE = useCallback(async (deviceSn?: string) => {
|
||||||
|
const snToDisconnect = deviceSn || currentDeviceSnRef.current;
|
||||||
|
shouldReconnectRef.current = false;
|
||||||
|
|
||||||
|
if (reconnectTimerRef.current) {
|
||||||
|
clearTimeout(reconnectTimerRef.current);
|
||||||
|
reconnectTimerRef.current = null;
|
||||||
|
}
|
||||||
|
if (idleTimerRef.current) {
|
||||||
|
clearTimeout(idleTimerRef.current);
|
||||||
|
idleTimerRef.current = null;
|
||||||
|
}
|
||||||
|
if (abortControllerRef.current) {
|
||||||
|
abortControllerRef.current.abort();
|
||||||
|
abortControllerRef.current = null;
|
||||||
|
}
|
||||||
|
if (snToDisconnect) {
|
||||||
|
performDisconnect(snToDisconnect, clientSessionIdRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSSEConnected(false);
|
||||||
|
setBoatData(null);
|
||||||
|
currentDeviceSnRef.current = '';
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const scheduleReconnect = useCallback((deviceSn: string) => {
|
||||||
|
if (reconnectAttemptsRef.current >= maxReconnectAttempts) {
|
||||||
|
console.log('[ClientSSE] 达到最大重连次数');
|
||||||
|
setSSEConnected(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const delay = Math.min(2000 * Math.pow(2, reconnectAttemptsRef.current), 60000);
|
||||||
|
reconnectAttemptsRef.current += 1;
|
||||||
|
reconnectTimerRef.current = setTimeout(() => {
|
||||||
|
if (shouldReconnectRef.current && currentDeviceSnRef.current === deviceSn) {
|
||||||
|
connectSSE(deviceSn);
|
||||||
|
}
|
||||||
|
}, delay);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const connectSSE = useCallback(async (deviceSn: string) => {
|
||||||
|
if (!deviceSn) return;
|
||||||
|
|
||||||
|
// 断开旧连接
|
||||||
|
if (currentDeviceSnRef.current && currentDeviceSnRef.current !== deviceSn) {
|
||||||
|
await disconnectSSE(currentDeviceSnRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentDeviceSnRef.current = deviceSn;
|
||||||
|
shouldReconnectRef.current = true;
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
if (abortControllerRef.current) {
|
||||||
|
abortControllerRef.current.abort();
|
||||||
|
}
|
||||||
|
const abortController = new AbortController();
|
||||||
|
abortControllerRef.current = abortController;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const url = `/api-device/client/sse/telemetry/${deviceSn}`;
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'text/event-stream',
|
||||||
|
'X-Client-Session-Id': clientSessionIdRef.current,
|
||||||
|
},
|
||||||
|
signal: abortController.signal,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`SSE连接失败: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSSEConnected(true);
|
||||||
|
setLoading(false);
|
||||||
|
reconnectAttemptsRef.current = 0;
|
||||||
|
|
||||||
|
const reader = response.body?.getReader();
|
||||||
|
if (!reader) throw new Error('无法获取响应流');
|
||||||
|
|
||||||
|
const decoder = new TextDecoder();
|
||||||
|
let buffer = '';
|
||||||
|
|
||||||
|
const handleSSEEvent = (eventName: string, data: string) => {
|
||||||
|
if (eventName === 'boat-telemetry') {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(data) as BoatTelemetryData;
|
||||||
|
setBoatData(parsed);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('[ClientSSE] 解析遥测数据失败:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const readStream = async () => {
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
const { done, value } = await reader.read();
|
||||||
|
if (done) {
|
||||||
|
setSSEConnected(false);
|
||||||
|
if (shouldReconnectRef.current && currentDeviceSnRef.current === deviceSn) {
|
||||||
|
scheduleReconnect(deviceSn);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer += decoder.decode(value, { stream: true });
|
||||||
|
const lines = buffer.split('\n');
|
||||||
|
buffer = lines.pop() || '';
|
||||||
|
|
||||||
|
let currentEvent = 'message';
|
||||||
|
let currentData = '';
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.startsWith('event:')) {
|
||||||
|
currentEvent = line.substring(6).trim();
|
||||||
|
} else if (line.startsWith('data:')) {
|
||||||
|
currentData = line.substring(5).trim();
|
||||||
|
} else if (line === '') {
|
||||||
|
if (currentData) {
|
||||||
|
handleSSEEvent(currentEvent, currentData);
|
||||||
|
}
|
||||||
|
currentEvent = 'message';
|
||||||
|
currentData = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error?.name === 'AbortError') return;
|
||||||
|
console.error('[ClientSSE] 读取流错误:', error);
|
||||||
|
setSSEConnected(false);
|
||||||
|
if (shouldReconnectRef.current && currentDeviceSnRef.current === deviceSn) {
|
||||||
|
scheduleReconnect(deviceSn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
readStream();
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error?.name === 'AbortError') return;
|
||||||
|
console.error('[ClientSSE] 连接失败:', error);
|
||||||
|
setSSEConnected(false);
|
||||||
|
setLoading(false);
|
||||||
|
if (shouldReconnectRef.current && currentDeviceSnRef.current === deviceSn) {
|
||||||
|
scheduleReconnect(deviceSn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [disconnectSSE, scheduleReconnect]);
|
||||||
|
|
||||||
|
// 页面关闭时断开
|
||||||
|
useEffect(() => {
|
||||||
|
const handleBeforeUnload = () => {
|
||||||
|
if (currentDeviceSnRef.current) {
|
||||||
|
performBeaconDisconnect(currentDeviceSnRef.current, clientSessionIdRef.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||||
|
return () => window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 组件卸载清理
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (reconnectTimerRef.current) clearTimeout(reconnectTimerRef.current);
|
||||||
|
if (idleTimerRef.current) clearTimeout(idleTimerRef.current);
|
||||||
|
shouldReconnectRef.current = false;
|
||||||
|
if (currentDeviceSnRef.current) {
|
||||||
|
performDisconnect(currentDeviceSnRef.current, clientSessionIdRef.current);
|
||||||
|
}
|
||||||
|
if (abortControllerRef.current) {
|
||||||
|
abortControllerRef.current.abort();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return { boatData, sseConnected, loading, connectSSE, disconnectSSE };
|
||||||
|
};
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/**
|
||||||
|
* 模拟遥测数据生成
|
||||||
|
* SSE 未连接时自动生成模拟船只遥测数据
|
||||||
|
*/
|
||||||
|
import { useEffect, useState, useCallback, useRef } from 'react';
|
||||||
|
import type { BoatTelemetryData } from '@/types/boatRoute';
|
||||||
|
|
||||||
|
/** 生成一帧模拟遥测 */
|
||||||
|
const createMockTelemetry = (
|
||||||
|
deviceSn: string,
|
||||||
|
prevData?: BoatTelemetryData | null,
|
||||||
|
initLon?: number,
|
||||||
|
initLat?: number,
|
||||||
|
): BoatTelemetryData => {
|
||||||
|
const baseLon = prevData?.longitude ?? initLon ?? 108.366;
|
||||||
|
const baseLat = prevData?.latitude ?? initLat ?? 22.817;
|
||||||
|
const baseHeading = prevData?.heading ?? 45;
|
||||||
|
|
||||||
|
const headingRad = (baseHeading + (Math.random() - 0.5) * 10) * Math.PI / 180;
|
||||||
|
const moveDistance = 0.00002 + Math.random() * 0.00003;
|
||||||
|
const newLon = baseLon + Math.cos(headingRad) * moveDistance;
|
||||||
|
const newLat = baseLat + Math.sin(headingRad) * moveDistance;
|
||||||
|
const newHeading = ((baseHeading + (Math.random() - 0.5) * 10) + 360) % 360;
|
||||||
|
|
||||||
|
return {
|
||||||
|
deviceSn,
|
||||||
|
longitude: newLon,
|
||||||
|
latitude: newLat,
|
||||||
|
heading: Number(newHeading.toFixed(1)),
|
||||||
|
speed: Number((1.5 + Math.random() * 2).toFixed(1)),
|
||||||
|
battery: Math.max(20, (prevData?.battery ?? 85) - Math.random() * 0.1),
|
||||||
|
signalStrength: 60 + Math.floor(Math.random() * 30),
|
||||||
|
status: '巡航中',
|
||||||
|
recordTime: new Date().toISOString(),
|
||||||
|
taskId: undefined,
|
||||||
|
currentWaypointIndex: undefined,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
interface UseMockTelemetryReturn {
|
||||||
|
/** 合并后的遥测数据(SSE 优先,回退到模拟) */
|
||||||
|
boatData: BoatTelemetryData | null;
|
||||||
|
/** 模型中心位���回调,���于重置模拟数据起点 */
|
||||||
|
handleModelCenter: (lon: number, lat: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useMockTelemetry(
|
||||||
|
deviceSn: string,
|
||||||
|
sseBoatData: BoatTelemetryData | null,
|
||||||
|
): UseMockTelemetryReturn {
|
||||||
|
const [mockBoatData, setMockBoatData] = useState<BoatTelemetryData | null>(null);
|
||||||
|
const mockTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
const mockDataRef = useRef<BoatTelemetryData | null>(null);
|
||||||
|
const modelCenterRef = useRef<{ lon: number; lat: number } | null>(null);
|
||||||
|
|
||||||
|
const handleModelCenter = useCallback((lon: number, lat: number) => {
|
||||||
|
modelCenterRef.current = { lon, lat };
|
||||||
|
if (mockDataRef.current) {
|
||||||
|
const newData = {
|
||||||
|
...mockDataRef.current,
|
||||||
|
longitude: lon + (Math.random() - 0.5) * 0.001,
|
||||||
|
latitude: lat + (Math.random() - 0.5) * 0.001,
|
||||||
|
};
|
||||||
|
mockDataRef.current = newData;
|
||||||
|
setMockBoatData(newData);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// 有真实 SSE 数据时停止模拟
|
||||||
|
if (sseBoatData) {
|
||||||
|
if (mockTimerRef.current) {
|
||||||
|
clearInterval(mockTimerRef.current);
|
||||||
|
mockTimerRef.current = null;
|
||||||
|
}
|
||||||
|
setMockBoatData(null);
|
||||||
|
mockDataRef.current = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 无真实数据且无模拟定时器,启动模拟
|
||||||
|
if (!mockTimerRef.current && deviceSn) {
|
||||||
|
const center = modelCenterRef.current;
|
||||||
|
const firstData = createMockTelemetry(deviceSn, null, center?.lon, center?.lat);
|
||||||
|
mockDataRef.current = firstData;
|
||||||
|
setMockBoatData(firstData);
|
||||||
|
|
||||||
|
mockTimerRef.current = setInterval(() => {
|
||||||
|
const center2 = modelCenterRef.current;
|
||||||
|
const newData = createMockTelemetry(deviceSn, mockDataRef.current, center2?.lon, center2?.lat);
|
||||||
|
mockDataRef.current = newData;
|
||||||
|
setMockBoatData(newData);
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (mockTimerRef.current) {
|
||||||
|
clearInterval(mockTimerRef.current);
|
||||||
|
mockTimerRef.current = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [sseBoatData, deviceSn]);
|
||||||
|
|
||||||
|
const boatData = sseBoatData || mockBoatData;
|
||||||
|
|
||||||
|
return { boatData, handleModelCenter };
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
/**
|
||||||
|
* 导航计算
|
||||||
|
* 根据当前遥测数据和航线信息,计算 HUD / Overlay 所需的导航指标
|
||||||
|
*/
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import type { BoatRouteListVO, BoatTelemetryData, BoatWaypointVO } from '@/types/boatRoute';
|
||||||
|
|
||||||
|
interface NextWaypoint {
|
||||||
|
name: string;
|
||||||
|
distance: number;
|
||||||
|
estimatedTime: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface NavigationDataResult {
|
||||||
|
/** 当前激活航线的航点列表 */
|
||||||
|
activeWaypoints: BoatWaypointVO[];
|
||||||
|
/** 当前激活航线的基本信息 */
|
||||||
|
activeRouteInfo: BoatRouteListVO | null;
|
||||||
|
/** 下一航点信息 */
|
||||||
|
nextWaypoint: NextWaypoint | undefined;
|
||||||
|
/** 剩余距离(米) */
|
||||||
|
remainingDistance: number;
|
||||||
|
/** 预计剩余时间(秒) */
|
||||||
|
estimatedRemainingTime: number;
|
||||||
|
/** 进度百分比 0-100 */
|
||||||
|
progress: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useNavigationData(
|
||||||
|
activeRouteId: string | null,
|
||||||
|
routes: BoatRouteListVO[],
|
||||||
|
routeWaypointsMap: Record<string, BoatWaypointVO[]>,
|
||||||
|
boatData: BoatTelemetryData | null,
|
||||||
|
currentWaypointIndex: number,
|
||||||
|
): NavigationDataResult {
|
||||||
|
const activeWaypoints = useMemo(() => {
|
||||||
|
if (!activeRouteId) return [];
|
||||||
|
return routeWaypointsMap[activeRouteId] || [];
|
||||||
|
}, [activeRouteId, routeWaypointsMap]);
|
||||||
|
|
||||||
|
const activeRouteInfo = useMemo(() => {
|
||||||
|
if (!activeRouteId) return null;
|
||||||
|
return routes.find((r) => r.routeId === activeRouteId) || null;
|
||||||
|
}, [activeRouteId, routes]);
|
||||||
|
|
||||||
|
const { nextWaypoint, remainingDistance, estimatedRemainingTime, progress } = useMemo(() => {
|
||||||
|
if (!activeWaypoints.length || !boatData) {
|
||||||
|
return { nextWaypoint: undefined, remainingDistance: 0, estimatedRemainingTime: 0, progress: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
const wpIdx = boatData.currentWaypointIndex ?? currentWaypointIndex;
|
||||||
|
const nextIdx = Math.min(wpIdx + 1, activeWaypoints.length - 1);
|
||||||
|
const nextWp = activeWaypoints[nextIdx];
|
||||||
|
|
||||||
|
// Haversine 距离计算
|
||||||
|
const R = 6371000;
|
||||||
|
const dLat = ((nextWp?.latitude ?? 0) - (boatData.latitude ?? 0)) * Math.PI / 180;
|
||||||
|
const dLon = ((nextWp?.longitude ?? 0) - (boatData.longitude ?? 0)) * Math.PI / 180;
|
||||||
|
const a = Math.sin(dLat / 2) ** 2 +
|
||||||
|
Math.cos((boatData.latitude ?? 0) * Math.PI / 180) *
|
||||||
|
Math.cos((nextWp?.latitude ?? 0) * Math.PI / 180) *
|
||||||
|
Math.sin(dLon / 2) ** 2;
|
||||||
|
const distToNext = R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||||
|
|
||||||
|
const totalDist = activeRouteInfo?.totalDistance ?? 1;
|
||||||
|
const prog = Math.min(100, Math.round((wpIdx / Math.max(1, activeWaypoints.length - 1)) * 100));
|
||||||
|
const remainDist = totalDist * (1 - prog / 100);
|
||||||
|
const estTime = boatData.speed > 0 ? remainDist / boatData.speed : 0;
|
||||||
|
|
||||||
|
return {
|
||||||
|
nextWaypoint: nextWp ? {
|
||||||
|
name: nextWp.pointName || `航点${nextIdx + 1}`,
|
||||||
|
distance: Math.round(distToNext),
|
||||||
|
estimatedTime: Math.round(boatData.speed > 0 ? distToNext / boatData.speed : 0),
|
||||||
|
} : undefined,
|
||||||
|
remainingDistance: Math.round(remainDist),
|
||||||
|
estimatedRemainingTime: Math.round(estTime),
|
||||||
|
progress: prog,
|
||||||
|
};
|
||||||
|
}, [activeWaypoints, boatData, currentWaypointIndex, activeRouteInfo]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
activeWaypoints,
|
||||||
|
activeRouteInfo,
|
||||||
|
nextWaypoint,
|
||||||
|
remainingDistance,
|
||||||
|
estimatedRemainingTime,
|
||||||
|
progress,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
/**
|
||||||
|
* 沉浸模式状态机
|
||||||
|
* 管理 sailing / preview / idle 三态切换及相关操作回调
|
||||||
|
*/
|
||||||
|
import { useState, useCallback } from 'react';
|
||||||
|
import { Modal, message } from 'antd';
|
||||||
|
import { sendBoatCommand } from '../services/clientApi';
|
||||||
|
|
||||||
|
type ActiveRouteMode = 'sailing' | 'preview' | null;
|
||||||
|
|
||||||
|
interface ActiveRouteState {
|
||||||
|
mode: ActiveRouteMode;
|
||||||
|
routeId: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UseNavigationStateReturn {
|
||||||
|
activeRoute: ActiveRouteState;
|
||||||
|
isPaused: boolean;
|
||||||
|
currentWaypointIndex: number;
|
||||||
|
previewStopSignal: number;
|
||||||
|
isSailing: boolean;
|
||||||
|
isPreviewing: boolean;
|
||||||
|
isImmersive: boolean;
|
||||||
|
activeRouteId: string | null;
|
||||||
|
handleStartSailing: (routeId: string) => void;
|
||||||
|
handlePauseSailing: () => void;
|
||||||
|
handleResumeSailing: () => void;
|
||||||
|
handleStopSailing: () => void;
|
||||||
|
handleStopPreview: () => void;
|
||||||
|
handleEmergencyStop: () => void;
|
||||||
|
handlePreviewChange: (previewing: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useNavigationState(
|
||||||
|
deviceSn: string,
|
||||||
|
selectedRouteId: string | null,
|
||||||
|
setSelectedRouteId: (id: string | null) => void,
|
||||||
|
): UseNavigationStateReturn {
|
||||||
|
const [activeRoute, setActiveRoute] = useState<ActiveRouteState>({ mode: null, routeId: null });
|
||||||
|
const [isPaused, setIsPaused] = useState(false);
|
||||||
|
const [currentWaypointIndex, setCurrentWaypointIndex] = useState(0);
|
||||||
|
const [previewStopSignal, setPreviewStopSignal] = useState(0);
|
||||||
|
|
||||||
|
const isSailing = activeRoute.mode === 'sailing';
|
||||||
|
const isPreviewing = activeRoute.mode === 'preview';
|
||||||
|
const isImmersive = activeRoute.mode !== null;
|
||||||
|
const activeRouteId = activeRoute.routeId;
|
||||||
|
|
||||||
|
const handleStartSailing = useCallback((routeId: string) => {
|
||||||
|
if (activeRoute.mode === 'preview') {
|
||||||
|
setPreviewStopSignal((prev) => prev + 1);
|
||||||
|
}
|
||||||
|
setActiveRoute({ mode: 'sailing', routeId });
|
||||||
|
setSelectedRouteId(routeId);
|
||||||
|
setIsPaused(false);
|
||||||
|
setCurrentWaypointIndex(0);
|
||||||
|
}, [activeRoute.mode, setSelectedRouteId]);
|
||||||
|
|
||||||
|
const handlePauseSailing = useCallback(() => {
|
||||||
|
if (!isSailing) return;
|
||||||
|
setIsPaused(true);
|
||||||
|
sendBoatCommand(deviceSn, 'pause', 'press').catch(() => {
|
||||||
|
message.error('暂停指令发送失败');
|
||||||
|
});
|
||||||
|
}, [deviceSn, isSailing]);
|
||||||
|
|
||||||
|
const handleResumeSailing = useCallback(() => {
|
||||||
|
if (!isSailing) return;
|
||||||
|
setIsPaused(false);
|
||||||
|
sendBoatCommand(deviceSn, 'resume', 'press').catch(() => {
|
||||||
|
message.error('继续指令发送失败');
|
||||||
|
});
|
||||||
|
}, [deviceSn, isSailing]);
|
||||||
|
|
||||||
|
const handleStopSailing = useCallback(() => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '确认结束航行',
|
||||||
|
content: '结束后将退��导航模式,返回线路选择',
|
||||||
|
okText: '结束航行',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: () => {
|
||||||
|
setActiveRoute({ mode: null, routeId: null });
|
||||||
|
setIsPaused(false);
|
||||||
|
setCurrentWaypointIndex(0);
|
||||||
|
sendBoatCommand(deviceSn, 'stop', 'press').catch(() => {});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, [deviceSn]);
|
||||||
|
|
||||||
|
const handleStopPreview = useCallback(() => {
|
||||||
|
setPreviewStopSignal((prev) => prev + 1);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleEmergencyStop = useCallback(() => {
|
||||||
|
setActiveRoute({ mode: null, routeId: null });
|
||||||
|
setIsPaused(false);
|
||||||
|
setCurrentWaypointIndex(0);
|
||||||
|
sendBoatCommand(deviceSn, 'stop', 'press').catch(() => {
|
||||||
|
message.error('紧急停靠指令发送失败');
|
||||||
|
});
|
||||||
|
message.warning('已执行紧急停靠');
|
||||||
|
}, [deviceSn]);
|
||||||
|
|
||||||
|
const handlePreviewChange = useCallback((previewing: boolean) => {
|
||||||
|
setActiveRoute((prev) => {
|
||||||
|
if (previewing) {
|
||||||
|
if (prev.mode === 'sailing') return prev;
|
||||||
|
const nextRouteId = selectedRouteId ?? prev.routeId;
|
||||||
|
if (!nextRouteId) return prev;
|
||||||
|
return { mode: 'preview', routeId: nextRouteId };
|
||||||
|
}
|
||||||
|
if (prev.mode === 'preview') {
|
||||||
|
return { mode: null, routeId: null };
|
||||||
|
}
|
||||||
|
return prev;
|
||||||
|
});
|
||||||
|
}, [selectedRouteId]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
activeRoute,
|
||||||
|
isPaused,
|
||||||
|
currentWaypointIndex,
|
||||||
|
previewStopSignal,
|
||||||
|
isSailing,
|
||||||
|
isPreviewing,
|
||||||
|
isImmersive,
|
||||||
|
activeRouteId,
|
||||||
|
handleStartSailing,
|
||||||
|
handlePauseSailing,
|
||||||
|
handleResumeSailing,
|
||||||
|
handleStopSailing,
|
||||||
|
handleStopPreview,
|
||||||
|
handleEmergencyStop,
|
||||||
|
handlePreviewChange,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* 航线列表加载 + 航点详情预加载
|
||||||
|
*/
|
||||||
|
import { useEffect, useState, useCallback } from 'react';
|
||||||
|
import { message } from 'antd';
|
||||||
|
import { getClientRoutes } from '../services/clientApi';
|
||||||
|
import { getBoatRouteDetail } from '@/services/boatRoute';
|
||||||
|
import type { BoatRouteListVO, BoatWaypointVO } from '@/types/boatRoute';
|
||||||
|
|
||||||
|
interface UseRouteDataReturn {
|
||||||
|
routes: BoatRouteListVO[];
|
||||||
|
routeWaypointsMap: Record<string, BoatWaypointVO[]>;
|
||||||
|
selectedRouteId: string | null;
|
||||||
|
setSelectedRouteId: (id: string | null) => void;
|
||||||
|
routeLoading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRouteData(deviceSn: string): UseRouteDataReturn {
|
||||||
|
const [routes, setRoutes] = useState<BoatRouteListVO[]>([]);
|
||||||
|
const [routeWaypointsMap, setRouteWaypointsMap] = useState<Record<string, BoatWaypointVO[]>>({});
|
||||||
|
const [selectedRouteId, setSelectedRouteId] = useState<string | null>(null);
|
||||||
|
const [routeLoading, setRouteLoading] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!deviceSn) return;
|
||||||
|
setRouteLoading(true);
|
||||||
|
getClientRoutes(deviceSn)
|
||||||
|
.then(async (res) => {
|
||||||
|
const routeList = res.data;
|
||||||
|
if (res.resp_code === 0 && routeList && routeList.length > 0) {
|
||||||
|
setRoutes(routeList);
|
||||||
|
// 并行预加载所有线路的航点详情
|
||||||
|
const detailResults = await Promise.allSettled(
|
||||||
|
routeList.map((r) => getBoatRouteDetail(r.routeId)),
|
||||||
|
);
|
||||||
|
const wpMap: Record<string, BoatWaypointVO[]> = {};
|
||||||
|
detailResults.forEach((result, idx) => {
|
||||||
|
if (result.status === 'fulfilled' && result.value.resp_code === 0 && result.value.data?.waypoints) {
|
||||||
|
wpMap[routeList[idx].routeId] = result.value.data.waypoints;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setRouteWaypointsMap(wpMap);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => message.error('线路加载失败'))
|
||||||
|
.finally(() => setRouteLoading(false));
|
||||||
|
}, [deviceSn]);
|
||||||
|
|
||||||
|
return { routes, routeWaypointsMap, selectedRouteId, setSelectedRouteId, routeLoading };
|
||||||
|
}
|
||||||
@@ -0,0 +1,487 @@
|
|||||||
|
/**
|
||||||
|
* 航线第一视角预览 Hook
|
||||||
|
* 从鹰眼 RouteEditor 中提取的预览动画逻辑,用于客户端页面航线预览
|
||||||
|
*/
|
||||||
|
import { useState, useRef, useCallback, useEffect } from 'react';
|
||||||
|
import { message } from 'antd';
|
||||||
|
import type { BoatWaypointDTO } from '@/types/boatRoute';
|
||||||
|
|
||||||
|
export interface UseRoutePreviewOptions {
|
||||||
|
viewerRef: React.RefObject<any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UseRoutePreviewReturn {
|
||||||
|
isPreviewing: boolean;
|
||||||
|
startPreview: (waypoints: BoatWaypointDTO[], speed?: number) => Promise<void>;
|
||||||
|
stopPreview: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRoutePreview({ viewerRef }: UseRoutePreviewOptions): UseRoutePreviewReturn {
|
||||||
|
const [isPreviewing, setIsPreviewing] = useState(false);
|
||||||
|
const previewAnimationRef = useRef<number | null>(null);
|
||||||
|
const savedCameraStateRef = useRef<any>(null);
|
||||||
|
const previewBoatPartsRef = useRef<{ hull?: any; cabin?: any; mast?: any; marker?: any } | null>(null);
|
||||||
|
|
||||||
|
const getCesium = useCallback(() => (window as any).Cesium, []);
|
||||||
|
|
||||||
|
// 计算两点间航向角
|
||||||
|
const calculateHeading = useCallback((from: { longitude: number; latitude: number }, to: { longitude: number; latitude: number }) => {
|
||||||
|
const dLon = (to.longitude - from.longitude) * Math.PI / 180;
|
||||||
|
const lat1 = from.latitude * Math.PI / 180;
|
||||||
|
const lat2 = to.latitude * Math.PI / 180;
|
||||||
|
const y = Math.sin(dLon) * Math.cos(lat2);
|
||||||
|
const x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
|
||||||
|
const bearing = Math.atan2(y, x) * 180 / Math.PI;
|
||||||
|
return (bearing + 360) % 360;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 停止预览
|
||||||
|
const stopPreview = useCallback(() => {
|
||||||
|
setIsPreviewing(false);
|
||||||
|
|
||||||
|
if (previewAnimationRef.current) {
|
||||||
|
cancelAnimationFrame(previewAnimationRef.current);
|
||||||
|
previewAnimationRef.current = null;
|
||||||
|
}
|
||||||
|
if ((previewAnimationRef as any).escHandler) {
|
||||||
|
window.removeEventListener('keydown', (previewAnimationRef as any).escHandler);
|
||||||
|
(previewAnimationRef as any).escHandler = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理船只实体
|
||||||
|
if (previewBoatPartsRef.current) {
|
||||||
|
try {
|
||||||
|
const viewer = viewerRef?.current;
|
||||||
|
if (viewer && !viewer.isDestroyed?.()) {
|
||||||
|
const { hull, cabin, mast, marker } = previewBoatPartsRef.current;
|
||||||
|
if (hull) viewer.entities.remove(hull);
|
||||||
|
if (cabin) viewer.entities.remove(cabin);
|
||||||
|
if (mast) viewer.entities.remove(mast);
|
||||||
|
if (marker) viewer.entities.remove(marker);
|
||||||
|
}
|
||||||
|
} catch { /* ignore */ } finally {
|
||||||
|
previewBoatPartsRef.current = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 恢复相机
|
||||||
|
if (savedCameraStateRef.current && viewerRef?.current) {
|
||||||
|
const viewer = viewerRef.current;
|
||||||
|
const Cesium = getCesium();
|
||||||
|
try { if (Cesium?.Matrix4) viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY); } catch { /* ignore */ }
|
||||||
|
viewer.camera.setView({
|
||||||
|
destination: savedCameraStateRef.current.position,
|
||||||
|
orientation: {
|
||||||
|
heading: savedCameraStateRef.current.heading,
|
||||||
|
pitch: savedCameraStateRef.current.pitch,
|
||||||
|
roll: savedCameraStateRef.current.roll,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
savedCameraStateRef.current = null;
|
||||||
|
}
|
||||||
|
}, [viewerRef, getCesium]);
|
||||||
|
|
||||||
|
// 构建预览折线(密集化 + 贴模型表面)
|
||||||
|
const buildPreviewPolyline = useCallback(async (points: BoatWaypointDTO[]) => {
|
||||||
|
const viewer = viewerRef?.current;
|
||||||
|
const Cesium = getCesium();
|
||||||
|
if (!viewer || !Cesium || viewer.isDestroyed?.()) return [];
|
||||||
|
if (!Array.isArray(points) || points.length < 2) return [];
|
||||||
|
|
||||||
|
const applyOffset = (cartesian: any) => {
|
||||||
|
try {
|
||||||
|
const carto = Cesium.Cartographic.fromCartesian(cartesian);
|
||||||
|
carto.height = (Number(carto.height) || 0) + 0.05;
|
||||||
|
return Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height);
|
||||||
|
} catch { return cartesian; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// 密集化航点
|
||||||
|
const cartos: any[] = [];
|
||||||
|
let total = 0;
|
||||||
|
const maxTotal = 500;
|
||||||
|
for (let i = 0; i < points.length - 1; i++) {
|
||||||
|
const a = points[i], b = points[i + 1];
|
||||||
|
const ca = Cesium.Cartographic.fromDegrees(a.longitude, a.latitude, 300);
|
||||||
|
const cb = Cesium.Cartographic.fromDegrees(b.longitude, b.latitude, 300);
|
||||||
|
const geodesic = new Cesium.EllipsoidGeodesic(ca, cb);
|
||||||
|
const dist = Number(geodesic.surfaceDistance) || 0;
|
||||||
|
const segments = Math.max(2, Math.min(60, Math.ceil(dist / 10)));
|
||||||
|
for (let s = 0; s <= segments; s++) {
|
||||||
|
if (i > 0 && s === 0) continue;
|
||||||
|
if (total >= maxTotal) break;
|
||||||
|
const c = geodesic.interpolateUsingFraction(segments === 0 ? 0 : s / segments);
|
||||||
|
c.height = 300;
|
||||||
|
cartos.push(c);
|
||||||
|
total++;
|
||||||
|
}
|
||||||
|
if (total >= maxTotal) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cartos.length < 2) {
|
||||||
|
return points.map((p) => Cesium.Cartesian3.fromDegrees(p.longitude, p.latitude, 0)).map(applyOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
const above = cartos.map((c: any) => Cesium.Cartesian3.fromRadians(c.longitude, c.latitude, c.height || 300));
|
||||||
|
const clampFn = viewer.scene?.clampToHeightMostDetailed;
|
||||||
|
if (typeof clampFn !== 'function') return above.map(applyOffset);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const clamped = await clampFn.call(viewer.scene, above);
|
||||||
|
const merged = (clamped || []).map((p: any, idx: number) => p || above[idx]);
|
||||||
|
const okCount = (clamped || []).filter(Boolean).length;
|
||||||
|
if (okCount < 2) return above.map(applyOffset);
|
||||||
|
return merged.map(applyOffset);
|
||||||
|
} catch {
|
||||||
|
return above.map(applyOffset);
|
||||||
|
}
|
||||||
|
}, [viewerRef, getCesium]);
|
||||||
|
|
||||||
|
// 开始预览
|
||||||
|
const startPreview = useCallback(async (waypoints: BoatWaypointDTO[], speed: number = 2) => {
|
||||||
|
const viewer = viewerRef?.current;
|
||||||
|
const Cesium = getCesium();
|
||||||
|
if (!viewer || !Cesium || viewer.isDestroyed?.()) return;
|
||||||
|
if (!waypoints || waypoints.length < 2) {
|
||||||
|
message.warning('至少需要2个航点才能预览');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPreviewing) stopPreview();
|
||||||
|
|
||||||
|
const polylinePositions = await buildPreviewPolyline(waypoints);
|
||||||
|
if (!Array.isArray(polylinePositions) || polylinePositions.length < 2) {
|
||||||
|
message.warning('模型瓦片加载中,请稍后再试预览');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理旧船只
|
||||||
|
if (previewBoatPartsRef.current) {
|
||||||
|
try {
|
||||||
|
const { hull, cabin, mast, marker } = previewBoatPartsRef.current;
|
||||||
|
if (hull) viewer.entities.remove(hull);
|
||||||
|
if (cabin) viewer.entities.remove(cabin);
|
||||||
|
if (mast) viewer.entities.remove(mast);
|
||||||
|
if (marker) viewer.entities.remove(marker);
|
||||||
|
} catch { /* ignore */ } finally {
|
||||||
|
previewBoatPartsRef.current = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存相机
|
||||||
|
savedCameraStateRef.current = {
|
||||||
|
position: viewer.camera.position.clone(),
|
||||||
|
heading: viewer.camera.heading,
|
||||||
|
pitch: viewer.camera.pitch,
|
||||||
|
roll: viewer.camera.roll,
|
||||||
|
};
|
||||||
|
|
||||||
|
setIsPreviewing(true);
|
||||||
|
message.info('开始航线预览,按ESC退出');
|
||||||
|
|
||||||
|
const chaseRange = 22;
|
||||||
|
const chasePitch = -20;
|
||||||
|
const ellipsoid = Cesium.Ellipsoid?.WGS84;
|
||||||
|
|
||||||
|
// 计算累积距离
|
||||||
|
const distances: number[] = [0];
|
||||||
|
for (let i = 1; i < polylinePositions.length; i++) {
|
||||||
|
distances[i] = distances[i - 1] + Cesium.Cartesian3.distance(polylinePositions[i - 1], polylinePositions[i]);
|
||||||
|
}
|
||||||
|
const totalDist = distances[distances.length - 1] || 0;
|
||||||
|
if (totalDist <= 1) {
|
||||||
|
message.warning('航线过短,无法预览');
|
||||||
|
setIsPreviewing(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Up方向偏移工具
|
||||||
|
const scratchEnu = new Cesium.Matrix4();
|
||||||
|
const scratchLocalOffset = new Cesium.Cartesian3();
|
||||||
|
const offsetUp = (origin: any, upMeters: number) => {
|
||||||
|
try {
|
||||||
|
if (!Cesium.Transforms?.eastNorthUpToFixedFrame || !Cesium.Matrix4?.multiplyByPoint) return origin;
|
||||||
|
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(origin, ellipsoid, scratchEnu);
|
||||||
|
scratchLocalOffset.x = 0; scratchLocalOffset.y = 0; scratchLocalOffset.z = upMeters;
|
||||||
|
return Cesium.Matrix4.multiplyByPoint(enu, scratchLocalOffset, new Cesium.Cartesian3());
|
||||||
|
} catch { return origin; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// 创建船只实体
|
||||||
|
try {
|
||||||
|
const firstPos0 = polylinePositions[0];
|
||||||
|
const boatAboveRoute = 0.05;
|
||||||
|
const firstPos = offsetUp(firstPos0, boatAboveRoute);
|
||||||
|
const initialOrientation = Cesium.Transforms?.headingPitchRollQuaternion
|
||||||
|
? Cesium.Transforms.headingPitchRollQuaternion(firstPos, new Cesium.HeadingPitchRoll(0, 0, 0))
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const hull = viewer.entities.add({
|
||||||
|
position: firstPos,
|
||||||
|
orientation: initialOrientation,
|
||||||
|
box: {
|
||||||
|
dimensions: new Cesium.Cartesian3(1.35, 0.5, 0.2),
|
||||||
|
material: Cesium.Color.fromCssColorString('#0B3D91').withAlpha(0.92),
|
||||||
|
outline: true, outlineColor: Cesium.Color.fromCssColorString('#E6F7FF').withAlpha(0.8),
|
||||||
|
shadows: Cesium.ShadowMode.DISABLED,
|
||||||
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 50000.0),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const cabinOffsetFn = (basePos: any, headingRad: number) => {
|
||||||
|
if (!Cesium.Transforms?.eastNorthUpToFixedFrame || !Cesium.Matrix4?.multiplyByPoint) return basePos;
|
||||||
|
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(basePos);
|
||||||
|
const localOffset = new Cesium.Cartesian3(
|
||||||
|
Math.sin(headingRad) * 0.25, Math.cos(headingRad) * 0.25, 0.16
|
||||||
|
);
|
||||||
|
return Cesium.Matrix4.multiplyByPoint(enu, localOffset, new Cesium.Cartesian3());
|
||||||
|
};
|
||||||
|
|
||||||
|
const cabinPos = cabinOffsetFn(firstPos, 0);
|
||||||
|
const cabin = viewer.entities.add({
|
||||||
|
position: cabinPos, orientation: initialOrientation,
|
||||||
|
box: {
|
||||||
|
dimensions: new Cesium.Cartesian3(0.55, 0.38, 0.24),
|
||||||
|
material: Cesium.Color.fromCssColorString('#F5F5F5').withAlpha(0.95),
|
||||||
|
outline: true, outlineColor: Cesium.Color.fromCssColorString('#FA8C16').withAlpha(0.85),
|
||||||
|
shadows: Cesium.ShadowMode.DISABLED,
|
||||||
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 50000.0),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const mast = viewer.entities.add({
|
||||||
|
position: cabinPos, orientation: initialOrientation,
|
||||||
|
cylinder: {
|
||||||
|
length: 0.38, topRadius: 0.015, bottomRadius: 0.015,
|
||||||
|
material: Cesium.Color.fromCssColorString('#FFFFFF').withAlpha(0.9),
|
||||||
|
shadows: Cesium.ShadowMode.DISABLED,
|
||||||
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 50000.0),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const markerImageUrl = typeof Cesium.buildModuleUrl === 'function'
|
||||||
|
? Cesium.buildModuleUrl('Assets/Textures/maki/ferry.png')
|
||||||
|
: '/cesium/Assets/Textures/maki/ferry.png';
|
||||||
|
const marker = viewer.entities.add({
|
||||||
|
position: offsetUp(firstPos0, boatAboveRoute + 0.12),
|
||||||
|
billboard: {
|
||||||
|
image: markerImageUrl, scale: 0.55,
|
||||||
|
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
||||||
|
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||||
|
scaleByDistance: new Cesium.NearFarScalar(20.0, 1.0, 200.0, 0.6),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
previewBoatPartsRef.current = { hull, cabin, mast, marker };
|
||||||
|
(previewBoatPartsRef.current as any).boatAboveRoute = boatAboveRoute;
|
||||||
|
(previewBoatPartsRef.current as any).cabinOffset = cabinOffsetFn;
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('创建预览船只实体失败:', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 二分查找距离索引
|
||||||
|
const findIndexByDistance = (d: number) => {
|
||||||
|
let lo = 0, hi = distances.length - 1;
|
||||||
|
while (lo < hi) { const mid = Math.floor((lo + hi) / 2); if (distances[mid] < d) lo = mid + 1; else hi = mid; }
|
||||||
|
return Math.max(1, lo);
|
||||||
|
};
|
||||||
|
|
||||||
|
const scratchPosCur = new Cesium.Cartesian3();
|
||||||
|
const scratchPosA = new Cesium.Cartesian3();
|
||||||
|
const scratchPosB = new Cesium.Cartesian3();
|
||||||
|
const scratchCartoCur = new Cesium.Cartographic();
|
||||||
|
const scratchCartoA = new Cesium.Cartographic();
|
||||||
|
const scratchCartoB = new Cesium.Cartographic();
|
||||||
|
|
||||||
|
const fillSampleAtDistance = (d: number, outPos: any, outCarto: any) => {
|
||||||
|
const dd = Math.min(totalDist, Math.max(0, d));
|
||||||
|
const idx = findIndexByDistance(dd);
|
||||||
|
const prevD = distances[idx - 1] || 0;
|
||||||
|
const nextD = distances[idx] || prevD + 1;
|
||||||
|
const frac = Math.min(1, Math.max(0, (dd - prevD) / Math.max(1e-6, nextD - prevD)));
|
||||||
|
Cesium.Cartesian3.lerp(polylinePositions[idx - 1], polylinePositions[idx], frac, outPos);
|
||||||
|
try {
|
||||||
|
Cesium.Cartographic.fromCartesian(outPos, ellipsoid || undefined, outCarto);
|
||||||
|
} catch {
|
||||||
|
const c = Cesium.Cartographic.fromCartesian(outPos);
|
||||||
|
outCarto.longitude = c.longitude; outCarto.latitude = c.latitude; outCarto.height = c.height;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 拐点检测
|
||||||
|
const turnAngleThresholdDeg = 12;
|
||||||
|
const turnHoldMs = 200;
|
||||||
|
const turnRotateMs = 650;
|
||||||
|
const normalizeAngleDeg = (deg: number) => ((deg % 360) + 360) % 360;
|
||||||
|
const shortestDeltaDeg = (fromDeg: number, toDeg: number) => {
|
||||||
|
let delta = normalizeAngleDeg(toDeg) - normalizeAngleDeg(fromDeg);
|
||||||
|
if (delta > 180) delta -= 360; if (delta < -180) delta += 360;
|
||||||
|
return delta;
|
||||||
|
};
|
||||||
|
const lerpHeadingDeg = (fromDeg: number, toDeg: number, f: number) => {
|
||||||
|
return normalizeAngleDeg(fromDeg + shortestDeltaDeg(fromDeg, toDeg) * Math.min(1, Math.max(0, f)));
|
||||||
|
};
|
||||||
|
|
||||||
|
const cornerInfos: Array<{ distance: number; fromHeading: number; toHeading: number }> = [];
|
||||||
|
try {
|
||||||
|
for (let i = 1; i < polylinePositions.length - 1; i++) {
|
||||||
|
const cPrev = new Cesium.Cartographic(), c = new Cesium.Cartographic(), cNext = new Cesium.Cartographic();
|
||||||
|
try {
|
||||||
|
Cesium.Cartographic.fromCartesian(polylinePositions[i - 1], ellipsoid, cPrev);
|
||||||
|
Cesium.Cartographic.fromCartesian(polylinePositions[i], ellipsoid, c);
|
||||||
|
Cesium.Cartographic.fromCartesian(polylinePositions[i + 1], ellipsoid, cNext);
|
||||||
|
} catch { continue; }
|
||||||
|
const h1 = calculateHeading(
|
||||||
|
{ longitude: Cesium.Math.toDegrees(cPrev.longitude), latitude: Cesium.Math.toDegrees(cPrev.latitude) },
|
||||||
|
{ longitude: Cesium.Math.toDegrees(c.longitude), latitude: Cesium.Math.toDegrees(c.latitude) }
|
||||||
|
);
|
||||||
|
const h2 = calculateHeading(
|
||||||
|
{ longitude: Cesium.Math.toDegrees(c.longitude), latitude: Cesium.Math.toDegrees(c.latitude) },
|
||||||
|
{ longitude: Cesium.Math.toDegrees(cNext.longitude), latitude: Cesium.Math.toDegrees(cNext.latitude) }
|
||||||
|
);
|
||||||
|
if (Math.abs(shortestDeltaDeg(h1, h2)) >= turnAngleThresholdDeg) {
|
||||||
|
cornerInfos.push({ distance: distances[i], fromHeading: h1, toHeading: h2 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
|
||||||
|
let lastT = 0, traveled = 0;
|
||||||
|
let mode: 'move' | 'turn' = 'move';
|
||||||
|
let cornerPtr = 0, turnStartT = 0, turnFromHeading = 0, turnToHeading = 0, turnDistance = 0;
|
||||||
|
|
||||||
|
const animatePreview = (t: number) => {
|
||||||
|
if (!lastT) lastT = t;
|
||||||
|
const dt = Math.max(0, (t - lastT) / 1000);
|
||||||
|
lastT = t;
|
||||||
|
|
||||||
|
if (mode === 'move') {
|
||||||
|
traveled += dt * speed;
|
||||||
|
if (cornerPtr < cornerInfos.length && traveled >= cornerInfos[cornerPtr].distance) {
|
||||||
|
traveled = cornerInfos[cornerPtr].distance;
|
||||||
|
mode = 'turn'; turnStartT = t;
|
||||||
|
turnFromHeading = cornerInfos[cornerPtr].fromHeading;
|
||||||
|
turnToHeading = cornerInfos[cornerPtr].toHeading;
|
||||||
|
turnDistance = cornerInfos[cornerPtr].distance;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
traveled = turnDistance;
|
||||||
|
if (t - turnStartT >= turnHoldMs + turnRotateMs) {
|
||||||
|
mode = 'move'; cornerPtr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (traveled >= totalDist) {
|
||||||
|
stopPreview();
|
||||||
|
message.success('航线预览完成');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fillSampleAtDistance(traveled, scratchPosCur, scratchCartoCur);
|
||||||
|
|
||||||
|
let headingDeg = 0;
|
||||||
|
if (mode === 'turn') {
|
||||||
|
const elapsed = t - turnStartT;
|
||||||
|
headingDeg = elapsed <= turnHoldMs
|
||||||
|
? turnFromHeading
|
||||||
|
: lerpHeadingDeg(turnFromHeading, turnToHeading, (elapsed - turnHoldMs) / Math.max(1, turnRotateMs));
|
||||||
|
} else {
|
||||||
|
const delta = Math.max(0.6, Math.min(2.5, speed * 0.35));
|
||||||
|
fillSampleAtDistance(traveled - delta, scratchPosA, scratchCartoA);
|
||||||
|
fillSampleAtDistance(traveled + delta, scratchPosB, scratchCartoB);
|
||||||
|
headingDeg = calculateHeading(
|
||||||
|
{ longitude: Cesium.Math.toDegrees(scratchCartoA.longitude), latitude: Cesium.Math.toDegrees(scratchCartoA.latitude) },
|
||||||
|
{ longitude: Cesium.Math.toDegrees(scratchCartoB.longitude), latitude: Cesium.Math.toDegrees(scratchCartoB.latitude) }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const headingRad = Cesium.Math.toRadians(headingDeg);
|
||||||
|
|
||||||
|
// 更新船只位置
|
||||||
|
try {
|
||||||
|
if (previewBoatPartsRef.current) {
|
||||||
|
const boatAboveRoute = Number((previewBoatPartsRef.current as any).boatAboveRoute) || 0.05;
|
||||||
|
const basePos = offsetUp(scratchPosCur, boatAboveRoute);
|
||||||
|
const orientation = Cesium.Transforms?.headingPitchRollQuaternion
|
||||||
|
? Cesium.Transforms.headingPitchRollQuaternion(basePos, new Cesium.HeadingPitchRoll(headingRad, 0, 0))
|
||||||
|
: undefined;
|
||||||
|
const { hull, cabin, mast } = previewBoatPartsRef.current;
|
||||||
|
if (hull) { hull.position = basePos; if (orientation) hull.orientation = orientation; }
|
||||||
|
const cabinOffsetFn = (previewBoatPartsRef.current as any).cabinOffset;
|
||||||
|
const cabinPos = typeof cabinOffsetFn === 'function' ? cabinOffsetFn(basePos, headingRad) : basePos;
|
||||||
|
if (cabin) { cabin.position = cabinPos; if (orientation) cabin.orientation = orientation; }
|
||||||
|
if (mast) { mast.position = cabinPos; if (orientation) mast.orientation = orientation; }
|
||||||
|
if (previewBoatPartsRef.current.marker) {
|
||||||
|
previewBoatPartsRef.current.marker.position = offsetUp(scratchPosCur, boatAboveRoute + 0.12);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
|
||||||
|
// 追踪相机
|
||||||
|
try {
|
||||||
|
const target = offsetUp(scratchPosCur, 0.8);
|
||||||
|
viewer.camera.lookAt(target, new Cesium.HeadingPitchRange(headingRad, Cesium.Math.toRadians(chasePitch), chaseRange));
|
||||||
|
} catch {
|
||||||
|
viewer.camera.setView({
|
||||||
|
destination: Cesium.Cartesian3.fromRadians(scratchCartoCur.longitude, scratchCartoCur.latitude, (Number(scratchCartoCur.height) || 0) + 10),
|
||||||
|
orientation: { heading: headingRad, pitch: Cesium.Math.toRadians(-10), roll: 0 },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
try { viewer.scene?.requestRender?.(); } catch { /* ignore */ }
|
||||||
|
previewAnimationRef.current = requestAnimationFrame(animatePreview);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 先请求一次渲染再启动动画
|
||||||
|
try { viewer.scene?.requestRender?.(); } catch { /* ignore */ }
|
||||||
|
setTimeout(() => {
|
||||||
|
previewAnimationRef.current = requestAnimationFrame(animatePreview);
|
||||||
|
}, 120);
|
||||||
|
|
||||||
|
// ESC退出
|
||||||
|
const handleEsc = (e: KeyboardEvent) => { if (e.key === 'Escape') stopPreview(); };
|
||||||
|
window.addEventListener('keydown', handleEsc);
|
||||||
|
(previewAnimationRef as any).escHandler = handleEsc;
|
||||||
|
}, [viewerRef, getCesium, isPreviewing, stopPreview, calculateHeading, buildPreviewPolyline]);
|
||||||
|
|
||||||
|
// 组件卸载清理
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (previewAnimationRef.current) cancelAnimationFrame(previewAnimationRef.current);
|
||||||
|
if ((previewAnimationRef as any).escHandler) {
|
||||||
|
window.removeEventListener('keydown', (previewAnimationRef as any).escHandler);
|
||||||
|
}
|
||||||
|
if (previewBoatPartsRef.current) {
|
||||||
|
try {
|
||||||
|
const viewer = viewerRef?.current;
|
||||||
|
if (viewer && !viewer.isDestroyed?.()) {
|
||||||
|
const { hull, cabin, mast, marker } = previewBoatPartsRef.current;
|
||||||
|
if (hull) viewer.entities.remove(hull);
|
||||||
|
if (cabin) viewer.entities.remove(cabin);
|
||||||
|
if (mast) viewer.entities.remove(mast);
|
||||||
|
if (marker) viewer.entities.remove(marker);
|
||||||
|
}
|
||||||
|
} catch { /* ignore */ } finally {
|
||||||
|
previewBoatPartsRef.current = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (savedCameraStateRef.current && viewerRef?.current) {
|
||||||
|
const viewer = viewerRef.current;
|
||||||
|
const Cesium = (window as any).Cesium;
|
||||||
|
try { if (Cesium?.Matrix4) viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY); } catch { /* ignore */ }
|
||||||
|
try {
|
||||||
|
viewer.camera.setView({
|
||||||
|
destination: savedCameraStateRef.current.position,
|
||||||
|
orientation: {
|
||||||
|
heading: savedCameraStateRef.current.heading,
|
||||||
|
pitch: savedCameraStateRef.current.pitch,
|
||||||
|
roll: savedCameraStateRef.current.roll,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch { /* ignore */ } finally {
|
||||||
|
savedCameraStateRef.current = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [viewerRef]);
|
||||||
|
|
||||||
|
return { isPreviewing, startPreview, stopPreview };
|
||||||
|
}
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
/* ========== 全局变量 ========== */
|
||||||
|
@glass-bg: linear-gradient(135deg, rgba(7, 20, 40, 0.92), rgba(12, 28, 52, 0.88));
|
||||||
|
@glass-border: rgba(65, 170, 255, 0.28);
|
||||||
|
@glass-blur: blur(16px);
|
||||||
|
@glass-shadow: 0 4px 24px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
|
||||||
|
@accent-cyan: #00d4ff;
|
||||||
|
@accent-blue: #0096ff;
|
||||||
|
@text-primary: #eaf6ff;
|
||||||
|
@text-secondary: rgba(255, 255, 255, 0.55);
|
||||||
|
@transition-smooth: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
|
||||||
|
.container {
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
background: #060e1a;
|
||||||
|
color: @text-primary;
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leftPanel {
|
||||||
|
width: 290px;
|
||||||
|
height: calc(100vh - 40px);
|
||||||
|
background: @glass-bg;
|
||||||
|
backdrop-filter: @glass-blur;
|
||||||
|
-webkit-backdrop-filter: @glass-blur;
|
||||||
|
border-right: 1px solid @glass-border;
|
||||||
|
box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.04), 4px 0 20px rgba(0, 0, 0, 0.3);
|
||||||
|
overflow-y: auto;
|
||||||
|
flex-shrink: 0;
|
||||||
|
transition: @transition-smooth;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
// 顶部高光线
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 1px;
|
||||||
|
background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.3), transparent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.centerView {
|
||||||
|
flex: 1;
|
||||||
|
height: calc(100vh - 40px);
|
||||||
|
position: relative;
|
||||||
|
transition: @transition-smooth;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rightPanel {
|
||||||
|
width: 320px;
|
||||||
|
height: calc(100vh - 40px);
|
||||||
|
background: @glass-bg;
|
||||||
|
backdrop-filter: @glass-blur;
|
||||||
|
-webkit-backdrop-filter: @glass-blur;
|
||||||
|
border-left: 1px solid @glass-border;
|
||||||
|
box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.04), -4px 0 20px rgba(0, 0, 0, 0.3);
|
||||||
|
overflow-y: auto;
|
||||||
|
flex-shrink: 0;
|
||||||
|
transition: @transition-smooth;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 1px;
|
||||||
|
background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.3), transparent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 沉浸模式 ========== */
|
||||||
|
.sailing {
|
||||||
|
.leftPanel {
|
||||||
|
width: 0;
|
||||||
|
opacity: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
border-right: none;
|
||||||
|
padding: 0;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rightPanel {
|
||||||
|
width: 0;
|
||||||
|
opacity: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
border-left: none;
|
||||||
|
padding: 0;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.centerView {
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.statusBar {
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
transform: translateY(100%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 底部状态栏 ========== */
|
||||||
|
.statusBar {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 40px;
|
||||||
|
background: linear-gradient(180deg, rgba(7, 16, 32, 0.92), rgba(5, 12, 24, 0.96));
|
||||||
|
backdrop-filter: blur(12px);
|
||||||
|
-webkit-backdrop-filter: blur(12px);
|
||||||
|
border-top: 1px solid @glass-border;
|
||||||
|
box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.04);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 20px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: @text-secondary;
|
||||||
|
z-index: 100;
|
||||||
|
transition: @transition-smooth;
|
||||||
|
font-family: 'Rajdhani', 'DIN', 'Roboto Mono', monospace;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.statusDot {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
margin-right: 8px;
|
||||||
|
display: inline-block;
|
||||||
|
box-shadow: 0 0 6px currentColor;
|
||||||
|
animation: statusPulse 2s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes statusPulse {
|
||||||
|
0%, 100% { opacity: 1; }
|
||||||
|
50% { opacity: 0.5; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========== 滚动条 ========== */
|
||||||
|
.leftPanel::-webkit-scrollbar,
|
||||||
|
.rightPanel::-webkit-scrollbar {
|
||||||
|
width: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leftPanel::-webkit-scrollbar-thumb,
|
||||||
|
.rightPanel::-webkit-scrollbar-thumb {
|
||||||
|
background: rgba(0, 212, 255, 0.25);
|
||||||
|
border-radius: 2px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: rgba(0, 212, 255, 0.4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.leftPanel::-webkit-scrollbar-track,
|
||||||
|
.rightPanel::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
import React, { useEffect } from 'react';
|
||||||
|
import { ConfigProvider, Button } from 'antd';
|
||||||
|
import { LogoutOutlined } from '@ant-design/icons';
|
||||||
|
import { darkTheme } from '@/theme';
|
||||||
|
import LeftPanel from './components/LeftPanel';
|
||||||
|
import CenterView from './components/CenterView';
|
||||||
|
import RightPanel from './components/RightPanel';
|
||||||
|
import NavigationHUD from './components/NavigationHUD';
|
||||||
|
import NavigationOverlay from './components/NavigationOverlay';
|
||||||
|
import EmergencyButton from './components/EmergencyButton';
|
||||||
|
import { useClientAuth } from './hooks/useClientAuth';
|
||||||
|
import { useClientSSE } from './hooks/useClientSSE';
|
||||||
|
import { useRouteData } from './hooks/useRouteData';
|
||||||
|
import { useMockTelemetry } from './hooks/useMockTelemetry';
|
||||||
|
import { useNavigationState } from './hooks/useNavigationState';
|
||||||
|
import { useNavigationData } from './hooks/useNavigationData';
|
||||||
|
import styles from './index.less';
|
||||||
|
|
||||||
|
const ClientPage: React.FC = () => {
|
||||||
|
// ── 认证 ──
|
||||||
|
const { boatData: sseBoatData, sseConnected, connectSSE, disconnectSSE } = useClientSSE();
|
||||||
|
const { deviceSn, deviceInfo, handleLogout } = useClientAuth(disconnectSSE);
|
||||||
|
|
||||||
|
// ── 航线数据 ──
|
||||||
|
const { routes, routeWaypointsMap, selectedRouteId, setSelectedRouteId, routeLoading } =
|
||||||
|
useRouteData(deviceSn);
|
||||||
|
|
||||||
|
// ── 模拟遥测 ──
|
||||||
|
const { boatData, handleModelCenter } = useMockTelemetry(deviceSn, sseBoatData);
|
||||||
|
|
||||||
|
// ── 沉浸模式状态机 ──
|
||||||
|
const {
|
||||||
|
isPaused,
|
||||||
|
currentWaypointIndex,
|
||||||
|
previewStopSignal,
|
||||||
|
isSailing,
|
||||||
|
isPreviewing,
|
||||||
|
isImmersive,
|
||||||
|
activeRouteId,
|
||||||
|
handleStartSailing,
|
||||||
|
handlePauseSailing,
|
||||||
|
handleResumeSailing,
|
||||||
|
handleStopSailing,
|
||||||
|
handleStopPreview,
|
||||||
|
handleEmergencyStop,
|
||||||
|
handlePreviewChange,
|
||||||
|
} = useNavigationState(deviceSn, selectedRouteId, setSelectedRouteId);
|
||||||
|
|
||||||
|
// ── 导航计算 ──
|
||||||
|
const {
|
||||||
|
activeWaypoints,
|
||||||
|
activeRouteInfo,
|
||||||
|
nextWaypoint,
|
||||||
|
remainingDistance,
|
||||||
|
estimatedRemainingTime,
|
||||||
|
progress,
|
||||||
|
} = useNavigationData(activeRouteId, routes, routeWaypointsMap, boatData, currentWaypointIndex);
|
||||||
|
|
||||||
|
// ── SSE 连接 ──
|
||||||
|
useEffect(() => {
|
||||||
|
if (!deviceSn) return;
|
||||||
|
connectSSE(deviceSn);
|
||||||
|
return () => { disconnectSSE(); };
|
||||||
|
}, [deviceSn]);
|
||||||
|
|
||||||
|
if (!deviceInfo) return null;
|
||||||
|
|
||||||
|
// ── 渲染 ──
|
||||||
|
return (
|
||||||
|
<ConfigProvider theme={darkTheme}>
|
||||||
|
<div className={`${styles.container} ${isImmersive ? styles.sailing : ''}`}>
|
||||||
|
{/* 左侧游览线路 */}
|
||||||
|
<div className={styles.leftPanel}>
|
||||||
|
<LeftPanel
|
||||||
|
routes={routes}
|
||||||
|
routeWaypointsMap={routeWaypointsMap}
|
||||||
|
loading={routeLoading}
|
||||||
|
selectedRouteId={selectedRouteId}
|
||||||
|
onSelectRoute={setSelectedRouteId}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 中间三维视图 */}
|
||||||
|
<div className={styles.centerView}>
|
||||||
|
<CenterView
|
||||||
|
deviceSn={deviceSn}
|
||||||
|
routes={routes}
|
||||||
|
selectedRouteId={selectedRouteId}
|
||||||
|
boatData={boatData}
|
||||||
|
onModelCenter={handleModelCenter}
|
||||||
|
isSailing={isSailing}
|
||||||
|
previewStopSignal={previewStopSignal}
|
||||||
|
onStartSailing={handleStartSailing}
|
||||||
|
onPreviewChange={handlePreviewChange}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 沉浸模式浮层(航行或预览) */}
|
||||||
|
{isImmersive && (
|
||||||
|
<>
|
||||||
|
{!!activeRouteId && (
|
||||||
|
<NavigationOverlay
|
||||||
|
mode={isPreviewing ? 'preview' : 'sailing'}
|
||||||
|
routeName={activeRouteInfo?.routeName || ''}
|
||||||
|
waypoints={activeWaypoints.map((wp) => ({
|
||||||
|
name: wp.pointName || `航点${wp.waypointIndex + 1}`,
|
||||||
|
waypointIndex: wp.waypointIndex,
|
||||||
|
}))}
|
||||||
|
currentWaypointIndex={boatData?.currentWaypointIndex ?? currentWaypointIndex}
|
||||||
|
totalDistance={activeRouteInfo?.totalDistance ?? 0}
|
||||||
|
remainingDistance={remainingDistance}
|
||||||
|
estimatedRemainingTime={estimatedRemainingTime}
|
||||||
|
progress={progress}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{isSailing && (
|
||||||
|
<EmergencyButton onEmergencyStop={handleEmergencyStop} deviceSn={deviceSn} />
|
||||||
|
)}
|
||||||
|
<NavigationHUD
|
||||||
|
mode={isPreviewing ? 'preview' : 'sailing'}
|
||||||
|
routeName={activeRouteInfo?.routeName || ''}
|
||||||
|
speed={boatData?.speed ?? 0}
|
||||||
|
heading={boatData?.heading ?? 0}
|
||||||
|
battery={boatData?.battery ?? 0}
|
||||||
|
signalStrength={boatData?.signalStrength}
|
||||||
|
nextWaypoint={nextWaypoint}
|
||||||
|
remainingDistance={remainingDistance}
|
||||||
|
estimatedRemainingTime={estimatedRemainingTime}
|
||||||
|
progress={progress}
|
||||||
|
isPaused={isPaused && isSailing}
|
||||||
|
onPause={handlePauseSailing}
|
||||||
|
onResume={handleResumeSailing}
|
||||||
|
onStop={isPreviewing ? handleStopPreview : handleStopSailing}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 右侧设备信息 */}
|
||||||
|
<div className={styles.rightPanel}>
|
||||||
|
<RightPanel deviceInfo={deviceInfo} boatData={boatData} sseConnected={sseConnected} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 底部状态栏 */}
|
||||||
|
<div className={styles.statusBar}>
|
||||||
|
<span className={styles.statusDot} style={{ background: sseConnected ? '#00ff88' : '#ff4d4f' }} />
|
||||||
|
<span>{sseConnected ? 'SSE 已连接' : 'SSE 未连接'}</span>
|
||||||
|
<span style={{ marginLeft: 16 }}>设备: {deviceInfo.deviceName || deviceSn}</span>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
icon={<LogoutOutlined />}
|
||||||
|
onClick={handleLogout}
|
||||||
|
style={{ marginLeft: 'auto', color: 'rgba(255,255,255,0.6)', fontSize: 12 }}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
退出
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ConfigProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ClientPage;
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { request } from 'umi';
|
||||||
|
|
||||||
|
const PREFIX = '/api-device/client';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验设备SN
|
||||||
|
*/
|
||||||
|
export async function checkDeviceSn(deviceSn: string) {
|
||||||
|
return request<API.Result<{ deviceSn: string; deviceName: string; deviceType: number }>>(
|
||||||
|
`${PREFIX}/auth/check`,
|
||||||
|
{ method: 'GET', params: { deviceSn } },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备航线列表
|
||||||
|
*/
|
||||||
|
export async function getClientRoutes(deviceSn: string) {
|
||||||
|
return request<API.Result<any[]>>(
|
||||||
|
`${PREFIX}/routes`,
|
||||||
|
{ method: 'GET', params: { deviceSn } },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备3D模型列表
|
||||||
|
*/
|
||||||
|
export async function getClientModels(deviceSn: string) {
|
||||||
|
return request<API.Result<any[]>>(
|
||||||
|
`${PREFIX}/models`,
|
||||||
|
{ method: 'GET', params: { deviceSn } },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送船控制指令
|
||||||
|
* @param deviceSn 设备SN
|
||||||
|
* @param command 指令类型: forward | backward | left | right | stop
|
||||||
|
* @param action 动作: press(按下)| release(松开)
|
||||||
|
*/
|
||||||
|
export async function sendBoatCommand(deviceSn: string, command: string, action: 'press' | 'release') {
|
||||||
|
return request<API.Result<any>>(
|
||||||
|
`${PREFIX}/control/command`,
|
||||||
|
{ method: 'POST', data: { deviceSn, command, action } },
|
||||||
|
);
|
||||||
|
}
|
||||||
+1
-1
@@ -139,7 +139,7 @@ export function useBoundaryDrawing(options: UseBoundaryDrawingOptions = {}): Use
|
|||||||
/**
|
/**
|
||||||
* 添加顶点
|
* 添加顶点
|
||||||
*/
|
*/
|
||||||
const addVertex = useCallback((point: { longitude: number; latitude: number }) => {
|
const addVertex = useCallback((point: { longitude: number; latitude: number; height?: number }) => {
|
||||||
const newVertex: BoundaryVertex = {
|
const newVertex: BoundaryVertex = {
|
||||||
longitude: point.longitude,
|
longitude: point.longitude,
|
||||||
latitude: point.latitude,
|
latitude: point.latitude,
|
||||||
|
|||||||
+20
-14
@@ -169,6 +169,12 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
|||||||
const waylineEntityRef = useRef<any>(null);
|
const waylineEntityRef = useRef<any>(null);
|
||||||
const waypointEntitiesRef = useRef<any[]>([]);
|
const waypointEntitiesRef = useRef<any[]>([]);
|
||||||
|
|
||||||
|
// 前向引用 ref(解决 useCallback 声明顺序问题)
|
||||||
|
const loadWaypointsRef = useRef<any>(null);
|
||||||
|
const drawWaylineOnMapRef = useRef<any>(null);
|
||||||
|
const flyToWaylineRef = useRef<any>(null);
|
||||||
|
const clearWaylineEntitiesRef = useRef<any>(null);
|
||||||
|
|
||||||
// 实时位置 - 区分相对高度和海拔高度
|
// 实时位置 - 区分相对高度和海拔高度
|
||||||
const realtimePosition = useMemo(() => {
|
const realtimePosition = useMemo(() => {
|
||||||
if (!droneData) return null;
|
if (!droneData) return null;
|
||||||
@@ -190,7 +196,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
|||||||
loadRoutesByDevice(deviceSn);
|
loadRoutesByDevice(deviceSn);
|
||||||
loadMissionsByDevice(deviceSn);
|
loadMissionsByDevice(deviceSn);
|
||||||
return () => {
|
return () => {
|
||||||
clearWaylineEntities();
|
clearWaylineEntitiesRef.current?.();
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
setPosition({ x: 0, y: 0 });
|
setPosition({ x: 0, y: 0 });
|
||||||
@@ -256,7 +262,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
|||||||
if (!selectedRouteId && unifiedRoutes.length > 0) {
|
if (!selectedRouteId && unifiedRoutes.length > 0) {
|
||||||
const first = unifiedRoutes[0];
|
const first = unifiedRoutes[0];
|
||||||
setSelectedRouteId(first.routeId);
|
setSelectedRouteId(first.routeId);
|
||||||
loadWaypoints(first.routeId, first.routeType);
|
loadWaypointsRef.current?.(first.routeId, first.routeType);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn('[TaskPanel] 加载无人船航线失败:', res);
|
console.warn('[TaskPanel] 加载无人船航线失败:', res);
|
||||||
@@ -283,7 +289,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
|||||||
if (!selectedRouteId && unifiedRoutes.length > 0) {
|
if (!selectedRouteId && unifiedRoutes.length > 0) {
|
||||||
const first = unifiedRoutes[0];
|
const first = unifiedRoutes[0];
|
||||||
setSelectedRouteId(first.routeId);
|
setSelectedRouteId(first.routeId);
|
||||||
loadWaypoints(first.routeId, first.routeType);
|
loadWaypointsRef.current?.(first.routeId, first.routeType);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn('[TaskPanel] 加载无人机航线失败:', res);
|
console.warn('[TaskPanel] 加载无人机航线失败:', res);
|
||||||
@@ -297,7 +303,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
|||||||
} finally {
|
} finally {
|
||||||
setRouteLoading(false);
|
setRouteLoading(false);
|
||||||
}
|
}
|
||||||
}, [isBoatDevice, selectedRouteId, loadWaypoints]);
|
}, [isBoatDevice, selectedRouteId]);
|
||||||
|
|
||||||
// 加载任务列表
|
// 加载任务列表
|
||||||
const loadMissionsByDevice = useCallback(async (sn: string) => {
|
const loadMissionsByDevice = useCallback(async (sn: string) => {
|
||||||
@@ -343,7 +349,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
|||||||
}));
|
}));
|
||||||
setWaypoints(unifiedWaypoints);
|
setWaypoints(unifiedWaypoints);
|
||||||
if (viewer && Cesium) {
|
if (viewer && Cesium) {
|
||||||
await drawWaylineOnMap(unifiedWaypoints);
|
await drawWaylineOnMapRef.current?.(unifiedWaypoints);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn('[TaskPanel] 加载无人船航点失败:', res);
|
console.warn('[TaskPanel] 加载无人船航点失败:', res);
|
||||||
@@ -364,7 +370,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
|||||||
}));
|
}));
|
||||||
setWaypoints(unifiedWaypoints);
|
setWaypoints(unifiedWaypoints);
|
||||||
if (viewer && Cesium) {
|
if (viewer && Cesium) {
|
||||||
await drawWaylineOnMap(unifiedWaypoints);
|
await drawWaylineOnMapRef.current?.(unifiedWaypoints);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn('[TaskPanel] 加载无人机航点失败:', res);
|
console.warn('[TaskPanel] 加载无人机航点失败:', res);
|
||||||
@@ -374,7 +380,8 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
|||||||
console.error('[TaskPanel] 加载航点失败:', e);
|
console.error('[TaskPanel] 加载航点失败:', e);
|
||||||
message.error('加载航点失败');
|
message.error('加载航点失败');
|
||||||
}
|
}
|
||||||
}, [viewer, Cesium, routeList, drawWaylineOnMap, isBoatDevice]);
|
}, [viewer, Cesium, routeList, isBoatDevice]);
|
||||||
|
loadWaypointsRef.current = loadWaypoints;
|
||||||
|
|
||||||
// 绘制航线 - 支持无人机和无人船航线,使用clampToHeightMostDetailed贴模型
|
// 绘制航线 - 支持无人机和无人船航线,使用clampToHeightMostDetailed贴模型
|
||||||
const drawWaylineOnMap = useCallback(async (waypoints: UnifiedWaypoint[]) => {
|
const drawWaylineOnMap = useCallback(async (waypoints: UnifiedWaypoint[]) => {
|
||||||
@@ -536,8 +543,9 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 飞到航线,传递渲染后的positions用于精确计算视角
|
// 飞到航线,传递渲染后的positions用于精确计算视角
|
||||||
flyToWayline(waypoints, polylinePositions.length >= 2 ? polylinePositions : waypointPositions);
|
flyToWaylineRef.current?.(waypoints, polylinePositions.length >= 2 ? polylinePositions : waypointPositions);
|
||||||
}, [viewer, Cesium, flyToWayline, clearWaylineEntities]);
|
}, [viewer, Cesium]);
|
||||||
|
drawWaylineOnMapRef.current = drawWaylineOnMap;
|
||||||
|
|
||||||
// 飞到航线位置 - 参考航线规划页面的实现
|
// 飞到航线位置 - 参考航线规划页面的实现
|
||||||
const flyToWayline = useCallback((waypoints: UnifiedWaypoint[], positions?: any[]) => {
|
const flyToWayline = useCallback((waypoints: UnifiedWaypoint[], positions?: any[]) => {
|
||||||
@@ -600,8 +608,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
|||||||
console.error('[航线视角] 飞到航线失败:', e);
|
console.error('[航线视角] 飞到航线失败:', e);
|
||||||
}
|
}
|
||||||
}, [viewer, Cesium]);
|
}, [viewer, Cesium]);
|
||||||
|
flyToWaylineRef.current = flyToWayline;
|
||||||
// 检查 viewer 是否有效
|
|
||||||
const isViewerValid = useCallback(() => {
|
const isViewerValid = useCallback(() => {
|
||||||
return viewer && !viewer.isDestroyed?.();
|
return viewer && !viewer.isDestroyed?.();
|
||||||
}, [viewer]);
|
}, [viewer]);
|
||||||
@@ -624,8 +631,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
|||||||
});
|
});
|
||||||
waypointEntitiesRef.current = [];
|
waypointEntitiesRef.current = [];
|
||||||
}, [viewer, isViewerValid]);
|
}, [viewer, isViewerValid]);
|
||||||
|
clearWaylineEntitiesRef.current = clearWaylineEntities;
|
||||||
// 选择航线
|
|
||||||
const handleSelectRoute = useCallback((routeId: string) => {
|
const handleSelectRoute = useCallback((routeId: string) => {
|
||||||
setSelectedRouteId(routeId);
|
setSelectedRouteId(routeId);
|
||||||
loadWaypoints(routeId);
|
loadWaypoints(routeId);
|
||||||
@@ -978,7 +984,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
|||||||
allowClear
|
allowClear
|
||||||
onClear={() => {
|
onClear={() => {
|
||||||
setSelectedRouteId(null);
|
setSelectedRouteId(null);
|
||||||
clearWaylineEntities();
|
clearWaylineEntitiesRef.current?.();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{routeList.map(route => (
|
{routeList.map(route => (
|
||||||
|
|||||||
+9
-9
@@ -22,8 +22,8 @@ interface UseCesiumRouteRendererOptions {
|
|||||||
mode: EditorMode; // 'view' | 'draw' | 'select' | 'edit'
|
mode: EditorMode; // 'view' | 'draw' | 'select' | 'edit'
|
||||||
boundaryGeoJson?: string; // 用于边界检测
|
boundaryGeoJson?: string; // 用于边界检测
|
||||||
obstacles?: RouteObstacleItem[]; // 障碍物边界(多边形)
|
obstacles?: RouteObstacleItem[]; // 障碍物边界(多边形)
|
||||||
onWaypointAdd: (point: { longitude: number; latitude: number }) => void;
|
onWaypointAdd: (point: { longitude: number; latitude: number; altitude?: number }) => void;
|
||||||
onWaypointMove: (index: number, point: { longitude: number; latitude: number }) => void;
|
onWaypointMove: (index: number, point: { longitude: number; latitude: number; altitude?: number }) => void;
|
||||||
onWaypointSelect: (index: number) => void;
|
onWaypointSelect: (index: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +96,13 @@ export function useCesiumRouteRenderer(options: UseCesiumRouteRendererOptions) {
|
|||||||
timer: null,
|
timer: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Cesium对象(提前声明,供后续 useCallback 引用)
|
||||||
|
*/
|
||||||
|
const getCesium = useCallback(() => {
|
||||||
|
return (window as any).Cesium;
|
||||||
|
}, []);
|
||||||
|
|
||||||
const applyHeightOffset = useCallback((cartesian: any) => {
|
const applyHeightOffset = useCallback((cartesian: any) => {
|
||||||
const Cesium = getCesium();
|
const Cesium = getCesium();
|
||||||
if (!Cesium || !cartesian) return cartesian;
|
if (!Cesium || !cartesian) return cartesian;
|
||||||
@@ -153,13 +160,6 @@ export function useCesiumRouteRenderer(options: UseCesiumRouteRendererOptions) {
|
|||||||
return result;
|
return result;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取Cesium对象
|
|
||||||
*/
|
|
||||||
const getCesium = useCallback(() => {
|
|
||||||
return (window as any).Cesium;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const normalizeRing = useCallback((ring: any): Array<[number, number]> => {
|
const normalizeRing = useCallback((ring: any): Array<[number, number]> => {
|
||||||
if (!Array.isArray(ring)) return [];
|
if (!Array.isArray(ring)) return [];
|
||||||
const coords = ring
|
const coords = ring
|
||||||
|
|||||||
@@ -69,18 +69,6 @@ const RouteEditor: React.FC<RouteEditorProps> = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setActiveRouteId(routeId);
|
setActiveRouteId(routeId);
|
||||||
}, [routeId]);
|
}, [routeId]);
|
||||||
|
|
||||||
const goLibraryAfterSave = useCallback(async (savedRouteId: string) => {
|
|
||||||
// 退出“编辑态”,让航线出现在航线库列表中
|
|
||||||
setActiveRouteId(undefined);
|
|
||||||
setMode('view');
|
|
||||||
selectWaypoint(null);
|
|
||||||
setWaypoints([]);
|
|
||||||
setActiveTabKey('library');
|
|
||||||
setLibrarySelectedId(savedRouteId);
|
|
||||||
await loadRouteLibrary();
|
|
||||||
}, [loadRouteLibrary, selectWaypoint, setMode, setWaypoints]);
|
|
||||||
|
|
||||||
// 加载设备绑定的水域边界(用于规划航线)
|
// 加载设备绑定的水域边界(用于规划航线)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const sn = String(deviceSn || '').trim();
|
const sn = String(deviceSn || '').trim();
|
||||||
@@ -279,6 +267,17 @@ const RouteEditor: React.FC<RouteEditorProps> = ({
|
|||||||
loadRouteLibrary();
|
loadRouteLibrary();
|
||||||
}, [loadRouteLibrary]);
|
}, [loadRouteLibrary]);
|
||||||
|
|
||||||
|
const goLibraryAfterSave = useCallback(async (savedRouteId: string) => {
|
||||||
|
// 退出“编辑态”,让航线出现在航线库列表中
|
||||||
|
setActiveRouteId(undefined);
|
||||||
|
setMode('view');
|
||||||
|
selectWaypoint(null);
|
||||||
|
setWaypoints([]);
|
||||||
|
setActiveTabKey('library');
|
||||||
|
setLibrarySelectedId(savedRouteId);
|
||||||
|
await loadRouteLibrary();
|
||||||
|
}, [loadRouteLibrary, selectWaypoint, setMode, setWaypoints]);
|
||||||
|
|
||||||
const ensureRouteDetail = useCallback(async (id: string) => {
|
const ensureRouteDetail = useCallback(async (id: string) => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
if (routeDetailsRef.current[id]?.length) return;
|
if (routeDetailsRef.current[id]?.length) return;
|
||||||
|
|||||||
@@ -7,6 +7,14 @@
|
|||||||
padding: 24px;
|
padding: 24px;
|
||||||
background:
|
background:
|
||||||
linear-gradient(135deg, rgba(0, 20, 50, 0.95) 0%, rgba(0, 40, 80, 0.9) 50%, rgba(0, 60, 100, 0.85) 100%);
|
linear-gradient(135deg, rgba(0, 20, 50, 0.95) 0%, rgba(0, 40, 80, 0.9) 50%, rgba(0, 60, 100, 0.85) 100%);
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-client-entry {
|
||||||
|
position: absolute;
|
||||||
|
top: 16px;
|
||||||
|
right: 24px;
|
||||||
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
.login-wrap {
|
.login-wrap {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import logo from '@/assets/logo.png';
|
import logo from '@/assets/logo.png';
|
||||||
import React, { useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { LoginForm, ProFormText, ProFormCaptcha, ProFormCheckbox } from '@ant-design/pro-components';
|
import { LoginForm, ProFormText, ProFormCaptcha, ProFormCheckbox } from '@ant-design/pro-components';
|
||||||
import { AppstoreOutlined, LockOutlined, UserOutlined } from '@ant-design/icons';
|
import { AppstoreOutlined, LockOutlined, UserOutlined, LaptopOutlined } from '@ant-design/icons';
|
||||||
import { Form, message, Spin } from 'antd';
|
import { Form, message, Spin, Button } from 'antd';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { history } from 'umi';
|
import { history } from 'umi';
|
||||||
import { login, LoginParams } from '@/services/login';
|
import { login, LoginParams } from '@/services/login';
|
||||||
@@ -71,6 +71,16 @@ const LoginPage: React.FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="login-page">
|
<div className="login-page">
|
||||||
|
<div className="login-client-entry">
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
icon={<LaptopOutlined />}
|
||||||
|
onClick={() => history.push('/client/login')}
|
||||||
|
style={{ color: 'rgba(255,255,255,0.7)', fontSize: 14 }}
|
||||||
|
>
|
||||||
|
客户端登录
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
<div className="login-wrap">
|
<div className="login-wrap">
|
||||||
<div className="login-hero">
|
<div className="login-hero">
|
||||||
<h1>鹰眼管控平台</h1>
|
<h1>鹰眼管控平台</h1>
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ const customTheme = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const darkTheme = customTheme;
|
||||||
|
|
||||||
export const ThemeProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
export const ThemeProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||||
return (
|
return (
|
||||||
<ConfigProvider theme={customTheme} locale={zhCN}>
|
<ConfigProvider theme={customTheme} locale={zhCN}>
|
||||||
|
|||||||
Reference in New Issue
Block a user