Compare commits
9 Commits
master
...
a3b2f14620
| Author | SHA1 | Date | |
|---|---|---|---|
| a3b2f14620 | |||
| d6b5c9ad44 | |||
| 36d1517eef | |||
| 30ce706280 | |||
| f22c2bedfe | |||
| be8576b887 | |||
| 5073f64240 | |||
| e363fb2799 | |||
| 81a9ed3dd1 |
10
env.js
10
env.js
@@ -9,17 +9,19 @@ const currentEnv = import.meta.env?.MODE || process.env.NODE_ENV;
|
||||
// 环境配置映射
|
||||
const envConfig = {
|
||||
[ENV.DEV]: {
|
||||
//baseURL: 'http://192.168.2.59:8081',//http://192.168.2.56:8081
|
||||
baseURL: 'http://1.95.137.212:8081',//http://192.168.2.56:8081
|
||||
////baseURL: 'http://1.95.137.212:59015',//http://192.168.2.56:8081
|
||||
//WS_URL: 'ws://192.168.2.59:9002/ws/',
|
||||
//mqtt_url: "ws://1.95.137.212:8083/mqtt",
|
||||
//geoserver_url: "http://192.168.2.59:7000/geoserver"
|
||||
|
||||
baseURL: 'http://1.95.137.212:8081',//http://192.168.2.56:8081
|
||||
//baseURL: 'http://1.95.137.212:8081',//http://192.168.2.56:8081
|
||||
//baseURL: 'http://192.168.2.62:8081',//http://192.168.2.56:8081
|
||||
//baseURL: 'https://serviceri.satabot.com',
|
||||
WS_URL: 'ws://1.95.137.212:9002/ws/',
|
||||
//WS_URL: 'ws://192.168.2.62:9002/ws/',
|
||||
mqtt_url: "ws://1.95.137.212:8083/mqtt",
|
||||
geoserver_url: "http://1.95.137.212:59018/geoserver"
|
||||
geoserver_url: "http://1.95.137.212:7900/geoserver"
|
||||
|
||||
//baseURL: 'http://1.95.137.212:59015',//http://192.168.2.56:8081
|
||||
////baseURL: 'https://serviceri.satabot.com',
|
||||
@@ -40,7 +42,7 @@ const envConfig = {
|
||||
//baseURL: 'https://serviceri.satabot.com',
|
||||
WS_URL: 'ws://1.95.137.212:9002/ws/',
|
||||
mqtt_url: "ws://1.95.137.212:8083/mqtt",
|
||||
geoserver_url: "http://1.95.137.212:59018/geoserver"
|
||||
geoserver_url: "http://1.95.137.212:7900/geoserver"
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -61,3 +61,4 @@ export default function App() {
|
||||
</I18nextProvider>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -455,6 +455,15 @@ export function hasPermission(params) {
|
||||
})
|
||||
}
|
||||
|
||||
///iot/workRecord/getTaskPath?taskId=74 get 获取算法回传的路径
|
||||
export function getTaskPath(params) {
|
||||
return request({
|
||||
url: '/iot/workRecord/getTaskPath',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -295,6 +295,7 @@ export default function AppLayout() {
|
||||
src="https://images.unsplash.com/photo-1509391366360-2e959784a276?ixlib=rb-1.2.1&auto=format&fit=crop&w=1200&q=80"
|
||||
/>
|
||||
<div style={{ fontSize: 11, color: '#666', lineHeight: 1.8 }}>
|
||||
{/*<div>{JSON.stringify(currentStation, null, 2)}</div>*/}
|
||||
<div>{t('layout.stationAddress')}:{currentStation.address || t('layout.defaultStationAddress')}</div>
|
||||
<div>{t('layout.stationType')}:{currentStation.type || t('layout.groundStation')}</div>
|
||||
<div style={{ marginTop: 4, display: 'flex', alignItems: 'center', color: '#41ad0a' }}>
|
||||
|
||||
@@ -39,6 +39,8 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
const planLineRef = useRef(null); // points 规划航线
|
||||
const navLineRef = useRef(null); // 完成点实时轨迹
|
||||
const markedPointsRef = useRef([]); // 标记点实体
|
||||
const { t } = useTranslation();
|
||||
|
||||
|
||||
const realtimeEntityRef = useRef(null);
|
||||
const realtimeLineRef = useRef(null);
|
||||
@@ -343,8 +345,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
}
|
||||
}, [markedPoints]);
|
||||
|
||||
function showRobotTooltip(tooltip, robot, position) {
|
||||
const { t } = useTranslation();
|
||||
function showRobotTooltip(tooltip, robot, position, t) {
|
||||
const statusMap = {
|
||||
1: { text: t('common.working'), color: "#10b981" },
|
||||
2: { text: t('devices.idle'), color: "#f59e0b" },
|
||||
@@ -498,6 +499,9 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
if (index == 2 && from == "other") {
|
||||
flyToLayer(layerIdentifier, baseUrl, 100);
|
||||
}
|
||||
//if (index == 0 && from == "other") {
|
||||
// flyToLayer(layerIdentifier, baseUrl, 100);
|
||||
//}
|
||||
//getLayerBoundsAndFit(wmsUrl, layerName);
|
||||
|
||||
if (baseUrl.includes('/gwc/service/wms')) {
|
||||
@@ -1397,7 +1401,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
const picked = viewer.scene.pick(movement.endPosition);
|
||||
if (window.Cesium.defined(picked) && picked.id?.properties?.robot) {
|
||||
const robot = picked.id.properties.robot.getValue();
|
||||
showRobotTooltip(tooltipRef.current, robot, movement.endPosition);
|
||||
showRobotTooltip(tooltipRef.current, robot, movement.endPosition, t);
|
||||
} else {
|
||||
tooltipRef.current.style.display = "none";
|
||||
}
|
||||
@@ -1599,7 +1603,6 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
|
||||
// 如果有航向角,设置旋转
|
||||
let rotation = 0;
|
||||
console.log('realtimePosition.heading:', realtimePosition.heading);
|
||||
|
||||
|
||||
if (realtimePosition?.heading !== undefined && !isNaN(Number(realtimePosition.heading))) {
|
||||
|
||||
@@ -484,7 +484,7 @@ export default function SmartDeviceManagement({
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label={t('systemSetting.leader')} name="userId" rules={[{ required: true, message: t('systemSetting.fixed2PleaseSelectFixed2LeaderFixed2') }]}>
|
||||
<Form.Item label={t('systemSetting.leader')} name="userId" >
|
||||
<Select
|
||||
placeholder={t('systemSetting.leaderFixed2')}
|
||||
allowClear
|
||||
|
||||
@@ -61,44 +61,50 @@ class WebSocketManager {
|
||||
// ==================== 连接管理 ====================
|
||||
|
||||
public connect(serialNumber: string, wsUrl: string): void {
|
||||
console.log("创建开始");//ws://192.168.2.56:9002/ws/
|
||||
// 清除之前的重连计时器
|
||||
console.log("创建开始");
|
||||
|
||||
// 清除重连计时器
|
||||
if (this.reconnectTimer) {
|
||||
clearTimeout(this.reconnectTimer);
|
||||
this.reconnectTimer = null;
|
||||
}
|
||||
|
||||
if (serialNumber == null || serialNumber.trim() === "") {
|
||||
console.log("serialNumber 是空/空白,停止执行");
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果序列号相同且已连接,跳过
|
||||
if (this.ws && this.currentSerialRef === serialNumber && this.status === 'connected') {
|
||||
console.log('WebSocket already connected for this device');
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果序列号不同,先关闭旧连接
|
||||
if (this.ws && this.currentSerialRef !== serialNumber) {
|
||||
// ========== 重点修复:关闭旧连接,并且清空旧ws的事件监听,防止旧消息回调执行 ==========
|
||||
if (this.ws) {
|
||||
// 解绑所有事件,阻止旧ws继续触发onmessage/onclose
|
||||
this.ws.onopen = null;
|
||||
this.ws.onmessage = null;
|
||||
this.ws.onerror = null;
|
||||
this.ws.onclose = null;
|
||||
this.close();
|
||||
this.ws = null;
|
||||
}
|
||||
|
||||
this.currentSerialRef = serialNumber;
|
||||
this.setStatus('connecting');
|
||||
this.isManualCloseRef = false;
|
||||
// 提前赋值,不要等到new WebSocket之后
|
||||
this.wsSerialRef = serialNumber;
|
||||
|
||||
console.log('Connecting WebSocket for', serialNumber);
|
||||
|
||||
|
||||
if (serialNumber == null || serialNumber.trim() === "") {
|
||||
console.log("serialNumber 是空/空白,停止执行");
|
||||
return;
|
||||
}
|
||||
|
||||
this.ws = new WebSocket(wsUrl);
|
||||
this.wsSerialRef = serialNumber;
|
||||
|
||||
this.ws.onopen = () => {
|
||||
console.log('WebSocket Connected');
|
||||
this.setStatus('connected');
|
||||
|
||||
|
||||
const dataStr = localStorage.getItem('userInfo');
|
||||
if (!dataStr) {
|
||||
console.error('用户信息未找到,无法发送认证包');
|
||||
@@ -109,18 +115,21 @@ class WebSocketManager {
|
||||
|
||||
console.log('WebSocket%', token);
|
||||
console.log('WebSocket%', parse);
|
||||
console.log("开始发送认证包");//ws://192.168.2.56:9002/ws/
|
||||
// 发送 AUTH 认证消息
|
||||
console.log("开始发送认证包");
|
||||
this.send({
|
||||
type: 'AUTH',
|
||||
token: token,
|
||||
userName: parse.username,
|
||||
deviceId: serialNumber,
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
this.ws.onmessage = (event) => {
|
||||
// 【防御二次校验】只有当前活跃serial才处理消息,旧连接残留消息直接丢弃
|
||||
if (this.wsSerialRef !== this.currentSerialRef) {
|
||||
console.log('丢弃过期ws消息');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
this.handleMessage(data);
|
||||
@@ -137,7 +146,7 @@ class WebSocketManager {
|
||||
const { code, reason, wasClean } = event;
|
||||
console.log('[WebSocket closed]', 'code =', code, 'reason =', reason || '(no reason)', 'wasClean =', wasClean);
|
||||
|
||||
// 如果不是当前设备的 ws,忽略
|
||||
// 不是当前设备直接忽略
|
||||
if (this.wsSerialRef !== this.currentSerialRef) {
|
||||
console.log('🟡 ignore old ws close');
|
||||
return;
|
||||
@@ -146,15 +155,13 @@ class WebSocketManager {
|
||||
this.ws = null;
|
||||
this.setStatus('disconnected');
|
||||
|
||||
// 主动关闭不重连
|
||||
if (this.isManualCloseRef || !this.currentSerialRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 5 秒后自动重连
|
||||
this.reconnectTimer = setTimeout(() => {
|
||||
if (this.currentSerialRef === this.wsSerialRef) {
|
||||
this.connect(this.currentSerialRef, wsUrl);
|
||||
this.connect(this.currentSerialRef!, wsUrl);
|
||||
}
|
||||
}, 5000);
|
||||
};
|
||||
@@ -164,21 +171,17 @@ class WebSocketManager {
|
||||
|
||||
public close(): void {
|
||||
this.isManualCloseRef = true;
|
||||
|
||||
if (this.reconnectTimer) {
|
||||
clearTimeout(this.reconnectTimer);
|
||||
this.reconnectTimer = null;
|
||||
}
|
||||
|
||||
if (this.ws) {
|
||||
console.log('Closing WebSocket');
|
||||
this.ws.close();
|
||||
this.ws = null;
|
||||
try {
|
||||
this.ws.close(1000, 'manual close');
|
||||
} catch (e) {
|
||||
console.warn('ws close exception', e);
|
||||
}
|
||||
}
|
||||
|
||||
this.currentSerialRef = null;
|
||||
this.wsSerialRef = null;
|
||||
this.setStatus('disconnected');
|
||||
}
|
||||
|
||||
// ==================== 消息发送 ====================
|
||||
|
||||
@@ -459,8 +459,17 @@ const RobotControlCenter = ({ setView }) => {
|
||||
}
|
||||
const getControl = (serialnum) => {
|
||||
setIsConnecting(true);
|
||||
let userParse = null;
|
||||
try {
|
||||
const dataStr = localStorage.getItem("userInfo");
|
||||
userParse = dataStr ? JSON.parse(dataStr) : null;
|
||||
} catch (e) {
|
||||
console.error("用户信息解析失败", e);
|
||||
}
|
||||
|
||||
const data = { platform: "web", deviceId: serialnum };
|
||||
const token = userParse.token || Cookies.get("Admin-Token");
|
||||
|
||||
const data = { platform: "web", deviceId: serialnum, token: token };
|
||||
getJurisdiction(data).then(res => {
|
||||
if (res?.data?.code === 200 && res?.data?.data?.remoteControl == true) {
|
||||
console.log("获取远程遥控权限成功");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, {
|
||||
import React, {
|
||||
useState,
|
||||
useEffect,
|
||||
useMemo,
|
||||
@@ -78,6 +78,7 @@ export default function DeviceStatusPage() {
|
||||
const [arrivedPoint, setArrivedPoint] = useState(null);//完成点
|
||||
const [isLoopMode, setIsLoopMode] = useState(true);
|
||||
const controllerRef = useRef<DeviceController | null>(null);
|
||||
const isFirstConnect = useRef(true);
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
|
||||
|
||||
@@ -95,6 +96,7 @@ export default function DeviceStatusPage() {
|
||||
const [connecting, setConnecting] = useState(false);
|
||||
const [wsStatus, setWsStatus] = useState('disconnected');
|
||||
const [wsDeviceInfo, setWsDeviceInfo] = useState({});
|
||||
const [locationInfo, setLocationInfo] = useState({});
|
||||
|
||||
|
||||
// 👇 加上这两个
|
||||
@@ -388,7 +390,7 @@ export default function DeviceStatusPage() {
|
||||
|
||||
const runningStatus = useMemo(() => {
|
||||
// 判断对象是否为空
|
||||
if ((!wsDeviceInfo || Object.keys(wsDeviceInfo).length === 0) && !isUAV) {
|
||||
if ((!wsDeviceInfo || Object.keys(wsDeviceInfo).length === 0) && (!locationInfo || Object.keys(locationInfo).length === 0) && !isUAV) {
|
||||
return {};
|
||||
}
|
||||
if (isUAV) {
|
||||
@@ -403,8 +405,9 @@ export default function DeviceStatusPage() {
|
||||
: {
|
||||
...base,
|
||||
...wsDeviceInfo,
|
||||
...locationInfo
|
||||
};
|
||||
}, [device, wsDeviceInfo, isUAV]);
|
||||
}, [device, wsDeviceInfo, isUAV, locationInfo]);
|
||||
|
||||
const { video: robotVideo, error, ready } = useWebRTCPlayer(
|
||||
(!isUAV && isVideoPlaying) ? (device?.serialNumber || '') : '',
|
||||
@@ -433,8 +436,8 @@ export default function DeviceStatusPage() {
|
||||
}
|
||||
|
||||
// 2. 机器人:从 wsDeviceInfo / runningStatus 取实时经纬度
|
||||
const robotLon = runningStatus.longitude || wsDeviceInfo.longitude;
|
||||
const robotLat = runningStatus.latitude || wsDeviceInfo.latitude;
|
||||
const robotLon = runningStatus.longitude || locationInfo.longitude;
|
||||
const robotLat = runningStatus.latitude || locationInfo.latitude;
|
||||
|
||||
if (robotLon && robotLat) {
|
||||
return {
|
||||
@@ -453,6 +456,7 @@ export default function DeviceStatusPage() {
|
||||
const controller = new DeviceController(userInfo, messageApi);
|
||||
|
||||
controller.onDeviceInfoUpdate = setWsDeviceInfo;
|
||||
controller.onLocationInfoUpdate = setLocationInfo;
|
||||
controller.onControlStatusChange = setIsControlled;
|
||||
controller.onHasControlRightChange = setHasControlRight;
|
||||
controller.onRequestControlStatusChange = setConnecting;
|
||||
@@ -480,13 +484,19 @@ export default function DeviceStatusPage() {
|
||||
|
||||
useEffect(() => {
|
||||
if (!device || !controllerRef.current || !device?.serialNumber || isUAV) {
|
||||
//controllerRef.current?.destroy();
|
||||
//setWsDeviceInfo({});
|
||||
return;
|
||||
}
|
||||
setWsDeviceInfo({});
|
||||
setLocationInfo({});
|
||||
|
||||
controllerRef.current.connectDevice(device);
|
||||
if (isFirstConnect.current) {
|
||||
|
||||
isFirstConnect.current = false;
|
||||
controllerRef.current.connectDevice(device);
|
||||
} else {
|
||||
|
||||
controllerRef.current.switchDevice(device);
|
||||
}
|
||||
|
||||
}, [device?.serialNumber]);
|
||||
|
||||
@@ -656,103 +666,6 @@ export default function DeviceStatusPage() {
|
||||
};
|
||||
|
||||
// 完成功能 - 调用路径规划接口
|
||||
const handleComplete = async () => {
|
||||
//如果时弓子模式
|
||||
if (isLoopMode) {
|
||||
if (markedPoints.length < 3) {
|
||||
messageApi.warning(t('devices.minThreePoints'));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 准备路径规划请求参数
|
||||
const positionPoints = [...markedPoints];
|
||||
|
||||
|
||||
const requestParams = {
|
||||
reference: {
|
||||
lat: positionPoints[0].lat,
|
||||
lon: positionPoints[0].lon,
|
||||
},
|
||||
heading: 0,
|
||||
outer: {
|
||||
position: positionPoints.map(point => ({
|
||||
lat: point.lat,
|
||||
lon: point.lon,
|
||||
})),
|
||||
sideWidth: 0.0,
|
||||
},
|
||||
holes: [],
|
||||
workType: 0,
|
||||
};
|
||||
|
||||
const response = await fetch('https://servicepathplan.satabot.com/api/path', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestParams),
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result) {
|
||||
const path = result?.data?.path?.map(p => {
|
||||
return {
|
||||
lng: p.lon,
|
||||
lat: p.lat
|
||||
}
|
||||
})
|
||||
setPoints(path);
|
||||
setSavePath({
|
||||
path: path, // 存储返回的路径结果
|
||||
outer: requestParams?.outer?.position?.map(p => {
|
||||
return {
|
||||
lng: p.lon,
|
||||
lat: p.lat
|
||||
}
|
||||
}
|
||||
),
|
||||
planModel: 0,
|
||||
});
|
||||
setCompleteFlag(true);
|
||||
messageApi.success(t('devices.pathPlanDone'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('路径规划失败:', error);
|
||||
messageApi.error(t('devices.pathPlanFailRetry'));
|
||||
}
|
||||
} else {
|
||||
const positionPoints = [...markedPoints].map(item => {
|
||||
return {
|
||||
lng: item.lon,
|
||||
lat: item.lat
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
setPoints(positionPoints);
|
||||
setSavePath({
|
||||
path: positionPoints, // 存储返回的路径结果
|
||||
outer: [],
|
||||
planModel: 2,
|
||||
});
|
||||
setCompleteFlag(true);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 打开保存模态框
|
||||
const handleOpenSaveModal = () => {
|
||||
if (!completeFlag) {
|
||||
messageApi.warning(t('devices.completePathFirst'));
|
||||
return;
|
||||
}
|
||||
setPlotName('');
|
||||
setIsSaveModalVisible(true);
|
||||
};
|
||||
|
||||
// 保存功能
|
||||
const handleSave = async () => {
|
||||
if (!plotName.trim()) {
|
||||
messageApi.warning(t('devices.inputPlotName'));
|
||||
@@ -761,6 +674,15 @@ export default function DeviceStatusPage() {
|
||||
|
||||
setIsSaving(true);
|
||||
try {
|
||||
// ✅重点:接收handleComplete返回的path数据,不再读组件savePath state
|
||||
const pathResult = await handleComplete();
|
||||
if (!pathResult) {
|
||||
messageApi.warning(t('devices.saveFail'));
|
||||
|
||||
// 路径规划失败/校验不通过直接终止
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 获取地图截图
|
||||
let screenshotDataUrl = null;
|
||||
if (mapRef.current) {
|
||||
@@ -776,18 +698,20 @@ export default function DeviceStatusPage() {
|
||||
const file = dataUrlToFile(screenshotDataUrl, "screenshot.jpg");
|
||||
console.log("blob", file)
|
||||
|
||||
|
||||
if (file instanceof File) {
|
||||
formData.append('file', file);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 添加 workRecord
|
||||
// 4. 添加 workRecord,直接使用函数返回的 pathResult,不读取state savePath
|
||||
const workRecord = {
|
||||
workName: plotName,
|
||||
siteId: stationId,
|
||||
jsonData: savePath,
|
||||
orgId: currentStation?.orgId,
|
||||
jsonData: pathResult, // 直接用返回值,彻底规避state异步延迟
|
||||
mode: isLoopMode ? "coverage" : "single_point",//"区域还是单点"
|
||||
};
|
||||
console.log("workRecord", workRecord)
|
||||
formData.append(
|
||||
"workRecord",
|
||||
new Blob([JSON.stringify(workRecord)], {
|
||||
@@ -795,8 +719,6 @@ export default function DeviceStatusPage() {
|
||||
})
|
||||
);
|
||||
|
||||
//formData.append('workRecord', JSON.stringify(workRecord));
|
||||
|
||||
// 5. 调用保存接口
|
||||
const res = await addRoute(formData);
|
||||
|
||||
@@ -818,6 +740,95 @@ export default function DeviceStatusPage() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 修改handleComplete:计算完成后 return路径对象;失败返回null
|
||||
*/
|
||||
const handleComplete = async () => {
|
||||
//如果是闭环模式
|
||||
if (isLoopMode) {
|
||||
if (markedPoints.length < 3) {
|
||||
messageApi.warning(t('devices.minThreePoints'));
|
||||
return null; //校验失败返回null
|
||||
}
|
||||
|
||||
try {
|
||||
// 准备路径规划请求参数
|
||||
let positionPoints = [...markedPoints];
|
||||
|
||||
// =========新增:保证闭环,第一个点和最后一个点一致=========
|
||||
const firstPt = positionPoints[0];
|
||||
const lastPt = positionPoints[positionPoints.length - 1];
|
||||
// 判断经纬度是否相等,不相等就把首点追加到末尾
|
||||
if (!(firstPt.lat === lastPt.lat && firstPt.lon === lastPt.lon)) {
|
||||
positionPoints.push({ ...firstPt });
|
||||
}
|
||||
|
||||
const requestParams = {
|
||||
outer: {
|
||||
position: positionPoints.map(point => ({
|
||||
lat: point.lat,
|
||||
lng: point.lon,
|
||||
})),
|
||||
},
|
||||
};
|
||||
|
||||
const path = requestParams?.outer?.position
|
||||
setPoints(path);
|
||||
|
||||
const resultObj = {
|
||||
path: path,
|
||||
outer: requestParams?.outer?.position?.map(p => {
|
||||
return {
|
||||
lng: p.lon,
|
||||
lat: p.lat
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
setSavePath(resultObj);
|
||||
setCompleteFlag(true);
|
||||
messageApi.success(t('devices.pathPlanDone'));
|
||||
return resultObj; // ✅返回计算好的数据给上层调用
|
||||
} catch (error) {
|
||||
console.error('路径规划失败:', error);
|
||||
messageApi.error(t('devices.pathPlanFailRetry'));
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
// 单点模式
|
||||
const positionPoints = [...markedPoints].map(item => {
|
||||
return {
|
||||
lng: item.lon,
|
||||
lat: item.lat
|
||||
}
|
||||
});
|
||||
|
||||
setPoints(positionPoints);
|
||||
|
||||
const resultObj = {
|
||||
path: positionPoints,
|
||||
outer: [],
|
||||
};
|
||||
setSavePath(resultObj);
|
||||
setCompleteFlag(true);
|
||||
|
||||
return resultObj; // ✅返回
|
||||
}
|
||||
};
|
||||
|
||||
// 打开保存模态框
|
||||
const handleOpenSaveModal = () => {
|
||||
//if (!completeFlag) {
|
||||
// messageApi.warning(t('devices.completePathFirst'));
|
||||
// return;
|
||||
//}
|
||||
setPlotName('');
|
||||
setIsSaveModalVisible(true);
|
||||
};
|
||||
|
||||
|
||||
|
||||
const realtimeType = useMemo(() => {
|
||||
return isUAV ? 'plane' : 'car';
|
||||
}, [isUAV]);
|
||||
@@ -856,8 +867,8 @@ export default function DeviceStatusPage() {
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
||||
<Text strong>{t('devices.pathPlanning')}:</Text>
|
||||
<Text type="secondary">{t('devices.markedPointsCount', { count: markedPoints.length })}</Text>
|
||||
<Text strong>{t('devices.pathPlanning')}:</Text>
|
||||
<Text type="secondary">{t('devices.markedPointsCount', { count: markedPoints.length })}</Text>
|
||||
</div>
|
||||
<Space size="middle">
|
||||
<Space>
|
||||
@@ -882,18 +893,18 @@ export default function DeviceStatusPage() {
|
||||
>
|
||||
{t('devices.clearMarks')}
|
||||
</Button>
|
||||
<Button
|
||||
{/*<Button
|
||||
type="primary"
|
||||
ghost
|
||||
onClick={handleComplete}
|
||||
disabled={markedPoints.length < 2}
|
||||
>
|
||||
{t('devices.complete')}
|
||||
</Button>
|
||||
</Button>*/}
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={handleOpenSaveModal}
|
||||
disabled={!completeFlag}
|
||||
//disabled={!completeFlag}
|
||||
>
|
||||
{t('common.save')}
|
||||
</Button>
|
||||
@@ -961,7 +972,7 @@ export default function DeviceStatusPage() {
|
||||
title={
|
||||
<>
|
||||
<VideoCameraOutlined />
|
||||
{t('devices.stationVideo')}
|
||||
{t('devices.stationVideo')}
|
||||
</>
|
||||
}
|
||||
bordered={false}
|
||||
@@ -1039,7 +1050,7 @@ export default function DeviceStatusPage() {
|
||||
title={
|
||||
<>
|
||||
<VideoCameraOutlined />
|
||||
{t('devices.droneVideo')}
|
||||
{t('devices.droneVideo')}
|
||||
</>
|
||||
}
|
||||
bordered={false}
|
||||
@@ -1103,33 +1114,33 @@ export default function DeviceStatusPage() {
|
||||
}}>
|
||||
<div style={{ marginBottom: 6, fontWeight: 600, color: '#1890ff' }}>{t('devices.robotStatus')}</div>
|
||||
<div style={{ display: 'flex', gap: '3px 10px', flexWrap: 'wrap' }}>
|
||||
<span>{t('devices.rtBattery')}</span>
|
||||
<span>{t('devices.rtBattery')}:</span>
|
||||
<span style={{ color: (runningStatus.battery || 0) < 20 ? '#ff4d4f' : '#52c41a' }}>
|
||||
{runningStatus.battery !== undefined ? `${runningStatus.battery}%` : '-'}
|
||||
</span>
|
||||
<span>{t('devices.rtVoltage')}</span>
|
||||
<span>{t('devices.rtVoltage')}:</span>
|
||||
<span>{runningStatus.voltage !== undefined ? `${Number(runningStatus.voltage).toFixed(2)}V` : '-'}</span>
|
||||
<span>{t('devices.rtLeftMotor')}</span>
|
||||
<span>{t('devices.rtLeftMotor')}:</span>
|
||||
<span>{runningStatus.leftCurrent !== undefined ? `${Number(runningStatus.leftCurrent).toFixed(2)}A` : '-'}</span>
|
||||
<span>{t('devices.rtRightMotor')}</span>
|
||||
<span>{t('devices.rtRightMotor')}:</span>
|
||||
<span>{runningStatus.rightCurrent !== undefined ? `${Number(runningStatus.rightCurrent).toFixed(2)}A` : '-'}</span>
|
||||
<span>{t('devices.rtLeftSpeed')}</span>
|
||||
<span>{t('devices.rtLeftSpeed')}:</span>
|
||||
<span>{runningStatus.leftMeasureSpeed !== undefined ? `${Number(runningStatus.leftMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
|
||||
<span>{t('devices.rtRightSpeed')}</span>
|
||||
<span>{t('devices.rtRightSpeed')}:</span>
|
||||
<span>{runningStatus.rightMeasureSpeed !== undefined ? `${Number(runningStatus.rightMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
|
||||
<span>{t('devices.rtLeftTemp')}</span>
|
||||
<span>{t('devices.rtLeftTemp')}:</span>
|
||||
<span>{runningStatus.leftMotorTemp !== undefined ? `${Number(runningStatus.leftMotorTemp).toFixed(1)}℃` : '-'}</span>
|
||||
<span>{t('devices.rtRightTemp')}</span>
|
||||
<span>{t('devices.rtRightTemp')}:</span>
|
||||
<span>{runningStatus.rightMotorTemp !== undefined ? `${Number(runningStatus.rightMotorTemp).toFixed(1)}℃` : '-'}</span>
|
||||
<span>{t('devices.rtMainTemp')}</span>
|
||||
<span>{t('devices.rtMainTemp')}:</span>
|
||||
<span>{runningStatus.chipTemp !== undefined ? `${Number(runningStatus.chipTemp).toFixed(1)}℃` : '-'}</span>
|
||||
<span>{t('devices.rtHeadingAngle')}</span>
|
||||
<span>{t('devices.rtHeadingAngle')}:</span>
|
||||
<span>{runningStatus.yaw !== undefined ? `${Number(runningStatus.yaw).toFixed(1)}°` : '-'}</span>
|
||||
<span>{t('devices.rtPitchAngle')}</span>
|
||||
<span>{t('devices.rtPitchAngle')}:</span>
|
||||
<span>{runningStatus.pitch !== undefined ? `${Number(runningStatus.pitch).toFixed(1)}°` : '-'}</span>
|
||||
<span>{t('devices.rtHeadingStatus')}</span>
|
||||
<span>{t('devices.rtHeadingStatus')}:</span>
|
||||
<span>{runningStatus.headingStatus !== undefined ? `${runningStatus.headingStatus == 1 ? t('devices.rtInitialized') : t('devices.uninitialized')}` : '-'}</span>
|
||||
<span>{t('devices.rtPositioning')}</span>
|
||||
<span>{t('devices.rtPositioning')}:</span>
|
||||
<span>
|
||||
{runningStatus.qual == 0 ? t('constants.locationInvalid') :
|
||||
runningStatus.qual == 1 ? t('devices.gpsSingle') :
|
||||
@@ -1137,9 +1148,9 @@ export default function DeviceStatusPage() {
|
||||
runningStatus.qual == 4 ? t('devices.rtkFixed2') :
|
||||
runningStatus.qual == 5 ? t('devices.rtkFloat') : t('constants.locationUnknown')}
|
||||
</span>
|
||||
<span>{t('devices.rtSatellites')}</span>
|
||||
<span>{t('devices.rtSatellites')}:</span>
|
||||
<span>{t('devices.satelliteCount', { count: runningStatus.satelliteCnt || 0 })}</span>
|
||||
<span>{t('devices.rtMode')}</span>
|
||||
<span>{t('devices.rtMode')}:</span>
|
||||
<span>
|
||||
{runningStatus.controlMode == 1 ? t('devices.localMode') :
|
||||
runningStatus.controlMode == 3 ? t('devices.remoteMode') : t('constants.locationUnknown')}
|
||||
@@ -1322,7 +1333,7 @@ export default function DeviceStatusPage() {
|
||||
title={
|
||||
<>
|
||||
<ControlOutlined />
|
||||
{t('devices.remoteControl')}
|
||||
{t('devices.remoteControl')}
|
||||
</>
|
||||
}
|
||||
bordered={false}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
||||
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
||||
import {
|
||||
Row, Col, Card, Button, Space, Table, Tag, Typography, Progress, Badge,
|
||||
Tabs, Input, Switch, Divider, Tooltip, Timeline, Select, message, DatePicker,
|
||||
Modal, InputNumber,
|
||||
TimePicker,
|
||||
Popconfirm,
|
||||
App
|
||||
App,
|
||||
Radio
|
||||
} from 'antd';
|
||||
import {
|
||||
PlusOutlined, ImportOutlined, NodeIndexOutlined,
|
||||
@@ -35,6 +36,7 @@ import {
|
||||
getSiteDeviceTaskHistory,
|
||||
getRouteByTask,
|
||||
deleteRoute,
|
||||
getTaskPath,
|
||||
} from '../../api/device';
|
||||
import dayjs from 'dayjs';
|
||||
import DraggableBox from '../Draggable';
|
||||
@@ -116,6 +118,8 @@ export default function RobotTaskPage() {
|
||||
robot: null,
|
||||
dateRange: null,
|
||||
});
|
||||
// 取消任务模式 normal普通取消 force强制取消
|
||||
const [cancelMode, setCancelMode] = useState<'normal' | 'force'>('normal');
|
||||
|
||||
|
||||
|
||||
@@ -137,6 +141,7 @@ export default function RobotTaskPage() {
|
||||
});
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
const controllerRef = useRef<DeviceController | null>(null);
|
||||
const isFirstConnect = useRef(true);
|
||||
const handleFinish = (data) => {
|
||||
setExecute(false);
|
||||
setShowVideo(false); // 任务完成关闭视频
|
||||
@@ -236,7 +241,7 @@ export default function RobotTaskPage() {
|
||||
setExecute(true);
|
||||
setExecutingRobot(targetDevice);
|
||||
setClearNavLine(v => v + 1); // 清空地图轨迹
|
||||
controllerRef.current?.connectDevice(targetDevice);
|
||||
if (isFirstConnect.current) { isFirstConnect.current = false; controllerRef.current?.connectDevice(targetDevice); } else { controllerRef.current?.switchDevice(targetDevice); }
|
||||
setShowVideo(true);
|
||||
};
|
||||
|
||||
@@ -244,7 +249,7 @@ export default function RobotTaskPage() {
|
||||
useEffect(() => {
|
||||
const controller = new DeviceController(userInfo, messageApi);
|
||||
|
||||
controller.onDeviceInfoUpdate = setRobotRealtimePosition;
|
||||
controller.onLocationInfoUpdate = setRobotRealtimePosition;
|
||||
controller.onIsFinished = handleFinish;
|
||||
controller.handleArrivedPoint = handleFinishEdPoint;
|
||||
|
||||
@@ -296,7 +301,7 @@ export default function RobotTaskPage() {
|
||||
setExecute(true);
|
||||
setExecutingRobot(targetDevice);
|
||||
setClearNavLine(v => v + 1); // 清空地图轨迹
|
||||
controllerRef.current?.connectDevice(targetDevice);
|
||||
if (isFirstConnect.current) { isFirstConnect.current = false; controllerRef.current?.connectDevice(targetDevice); } else { controllerRef.current?.switchDevice(targetDevice); }
|
||||
setShowVideo(true);
|
||||
|
||||
}, [devices, taskPoolList, executingRobot, runningPoolTask]);
|
||||
@@ -394,22 +399,14 @@ export default function RobotTaskPage() {
|
||||
// 调用接口获取路线详情
|
||||
const fetchRouteDetail = async () => {
|
||||
try {
|
||||
const res = await getSingleRouteList({ id: selectedPathWork.id });
|
||||
const res = await getTaskPath({ taskId: selectedPathWork.id })
|
||||
//const res = await getSingleRouteList({ id: selectedPathWork.id });
|
||||
if (res?.code === 200 && res?.data) {
|
||||
let pathPoints = [];
|
||||
let outerPoints = [];
|
||||
let method = '';//0弓子 2 回子
|
||||
|
||||
try {
|
||||
// 尝试解析 JSON
|
||||
if (res.data.jsonData) {
|
||||
const data = typeof res.data.jsonData === 'string'
|
||||
? JSON.parse(res.data.jsonData)
|
||||
: res.data.jsonData;
|
||||
pathPoints = data?.path || [];
|
||||
outerPoints = data?.outer || [];
|
||||
method = data?.planModel;
|
||||
|
||||
}
|
||||
pathPoints = res.data || [];
|
||||
} catch (err) {
|
||||
console.error('解析路线数据失败:', err);
|
||||
}
|
||||
@@ -417,15 +414,9 @@ export default function RobotTaskPage() {
|
||||
if (pathPoints.length === 0) {
|
||||
utils.message.warning(t('devices.route2'));
|
||||
}
|
||||
//if (outerPoints.length === 0 && method == 2) {
|
||||
// utils.message.warning(t('devices.route2'));
|
||||
//}
|
||||
//if (method == 0) {
|
||||
setPoints(pathPoints);
|
||||
//} else {
|
||||
// setPoints(outerPoints);
|
||||
|
||||
//}
|
||||
setPoints(pathPoints);
|
||||
|
||||
} else {
|
||||
setPoints([]);
|
||||
}
|
||||
@@ -460,7 +451,7 @@ export default function RobotTaskPage() {
|
||||
setExecute(true);
|
||||
setExecutingRobot(targetDevice);
|
||||
setClearNavLine(v => v + 1); // 清空地图轨迹
|
||||
controllerRef.current?.connectDevice(targetDevice);
|
||||
if (isFirstConnect.current) { isFirstConnect.current = false; controllerRef.current?.connectDevice(targetDevice); } else { controllerRef.current?.switchDevice(targetDevice); }
|
||||
setShowVideo(true);
|
||||
}
|
||||
}
|
||||
@@ -566,7 +557,7 @@ export default function RobotTaskPage() {
|
||||
fetchTaskList();
|
||||
fetchTaskPoolList();
|
||||
fetchTaskHistoryList();
|
||||
controllerRef.current?.connectDevice(selectedRobotForExecute);
|
||||
if (isFirstConnect.current) { isFirstConnect.current = false; controllerRef.current?.connectDevice(selectedRobotForExecute); } else { controllerRef.current?.switchDevice(selectedRobotForExecute); }
|
||||
setShowVideo(true); // 连接成功后自动打开视频
|
||||
|
||||
} else {
|
||||
@@ -653,13 +644,14 @@ export default function RobotTaskPage() {
|
||||
};
|
||||
|
||||
// 取消任务
|
||||
const handleCancelTask = async (task) => {
|
||||
const handleCancelTask = async (task, mode) => {
|
||||
try {
|
||||
const params = {
|
||||
taskId: task.id,
|
||||
//deviceId: task.deviceId,
|
||||
siteId: stationId,
|
||||
orgId: task.orgId,
|
||||
forceCancel: mode === 'force' ? true : false,
|
||||
};
|
||||
const res = await cancelRoute(params);
|
||||
if (res.code === 200 && res.data == true) {
|
||||
@@ -832,15 +824,17 @@ export default function RobotTaskPage() {
|
||||
dataIndex: 'taskStaus',
|
||||
width: 100,
|
||||
render: (status, record) => {
|
||||
console.log('status', status, record);
|
||||
const statusMap = {
|
||||
'NEW': { color: 'default', text: t('devices.statusNew') },
|
||||
'EXECUTING': { color: 'processing', text: t('workOrder.inProgress') },
|
||||
'PAUSE': { color: 'warning', text: t('devices.statusPaused') },
|
||||
'FINISH': { color: 'success', text: t('devices.statusFinished') },
|
||||
'FAILED': { color: 'error', text: t('devices.statusFailed') }
|
||||
'FAILED': { color: 'error', text: t('devices.statusFailed') },
|
||||
"CANCELING": { color: 'warning', text: t('devices.statusCanceling') },
|
||||
};
|
||||
const item = statusMap[status] || { color: 'default', text: record.taskStausTranslate || t('constants.locationUnknown') };
|
||||
return <Tag color={item.color}>{item.text}</Tag>;
|
||||
return <Tag color={item.color}>{record.taskStausTranslate}</Tag>;
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -889,7 +883,8 @@ export default function RobotTaskPage() {
|
||||
'EXECUTING': { color: 'processing', text: t('workOrder.inProgress') },
|
||||
'PAUSE': { color: 'warning', text: t('devices.statusPaused') },
|
||||
'FINISH': { color: 'success', text: t('devices.statusFinished') },
|
||||
'FAILED': { color: 'error', text: t('devices.statusFailed') }
|
||||
'FAILED': { color: 'error', text: t('devices.statusFailed') },
|
||||
"CANCELING": { color: 'warning', text: t('devices.statusCanceling') },
|
||||
};
|
||||
const item = statusMap[status] || { color: 'default', text: t('constants.locationUnknown') };
|
||||
return <Tag color={item.color}>{item.text}</Tag>;
|
||||
@@ -909,27 +904,46 @@ export default function RobotTaskPage() {
|
||||
|
||||
<>
|
||||
{/*{record.taskStaus === 'NEW' && (*/}
|
||||
<Popconfirm
|
||||
title={t('devices.confirmCancelTask')}
|
||||
onConfirm={() => handleCancelTask(record)}
|
||||
okText={t('common.ok')} cancelText={t('common.cancel')}
|
||||
>
|
||||
<Button type="text" size="small" danger icon={<CloseOutlined />} onClick={(e) => e.stopPropagation()}>
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
<Popconfirm
|
||||
title={t('devices.confirmCancelTask')}
|
||||
description={
|
||||
<Radio.Group
|
||||
value={cancelMode}
|
||||
onChange={(e) => setCancelMode(e.target.value)}
|
||||
style={{ marginTop: 8 }}
|
||||
>
|
||||
<Space direction="vertical">
|
||||
<Radio value="normal">{t('devices.normalCancel')}</Radio>
|
||||
<Radio value="force">{t('devices.forceCancel')}</Radio>
|
||||
</Space>
|
||||
</Radio.Group>
|
||||
}
|
||||
onConfirm={() => handleCancelTask(record, cancelMode)}
|
||||
okText={t('common.ok')}
|
||||
cancelText={t('common.cancel')}
|
||||
>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
danger
|
||||
icon={<CloseOutlined />}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
{/*//)}*/}
|
||||
|
||||
{/*{record.taskStaus === 'EXECUTING' && (*/}
|
||||
<Popconfirm
|
||||
title={t('devices.confirmPauseTask')}
|
||||
onConfirm={() => handlePauseTask(record)}
|
||||
okText={t('common.ok')} cancelText={t('common.cancel')}
|
||||
>
|
||||
<Button type="text" size="small" style={{ color: '#FF9500' }} onClick={(e) => e.stopPropagation()}>
|
||||
{t('video.pause')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
<Popconfirm
|
||||
title={t('devices.confirmPauseTask')}
|
||||
onConfirm={() => handlePauseTask(record)}
|
||||
okText={t('common.ok')} cancelText={t('common.cancel')}
|
||||
>
|
||||
<Button type="text" size="small" style={{ color: '#FF9500' }} onClick={(e) => e.stopPropagation()}>
|
||||
{t('video.pause')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
{/*)}/*/}
|
||||
|
||||
{record.taskStaus === 'PAUSE' && (
|
||||
|
||||
@@ -116,7 +116,7 @@ const XboxController = ({ onGamepadUpdate, handleControlModal, isControlled, isC
|
||||
return (
|
||||
<div className="relative h-[252px] aspect-[4/3] flex items-center justify-center "
|
||||
onClick={() => {
|
||||
if (connected && !isControlled && hasControlRight) {
|
||||
if (!isControlled) {
|
||||
console.log("点击了无控制权限,发起权限请求");
|
||||
// 示例:调用你代码中已有的权限请求弹窗逻辑
|
||||
handleControlModal({ control: true, type: "switchPermission" });
|
||||
@@ -125,7 +125,7 @@ const XboxController = ({ onGamepadUpdate, handleControlModal, isControlled, isC
|
||||
{/* Gamepad Status Badge */}
|
||||
<div
|
||||
className={`absolute top-0 right-0 px-2 py-0.5 rounded text-[8px] font-bold tracking-widest border
|
||||
${connected || !hasControlRight
|
||||
${connected
|
||||
? isConnecting
|
||||
? 'bg-yellow-500/20 text-yellow-400 border-yellow-500/30'
|
||||
: isControlled
|
||||
@@ -137,8 +137,6 @@ const XboxController = ({ onGamepadUpdate, handleControlModal, isControlled, isC
|
||||
>
|
||||
{!connected ? (
|
||||
t('devices.controllerNotConnected')
|
||||
) : !hasControlRight ? (
|
||||
t('devices.otherWebConnected')
|
||||
) : isConnecting ? (
|
||||
t('devices.control2')
|
||||
) : isControlled ? (
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import throttle from 'lodash/throttle';
|
||||
import { wsManager } from '../WebSocketManager.ts';
|
||||
import {
|
||||
getControlRight,
|
||||
getJurisdiction,
|
||||
releaseControl
|
||||
} from '../../api/device.ts';
|
||||
|
||||
import envConfig from '../../../env';
|
||||
@@ -17,7 +17,7 @@ export default class DeviceController {
|
||||
envConfig.WS_URL || 'wss://ri.satabot.com/ws/';
|
||||
|
||||
this.connectedDeviceSn = null;
|
||||
this.currentDevice = null; // 保存当前设备
|
||||
this.currentDevice = null;
|
||||
|
||||
this.requestDeviceId = '';
|
||||
|
||||
@@ -27,11 +27,14 @@ export default class DeviceController {
|
||||
|
||||
this.wsStatus = 'disconnected';
|
||||
this.wsDeviceInfo = {};
|
||||
this.locationInfo = {};
|
||||
|
||||
this.controlTimeout = null;
|
||||
this.keepAliveInterval = null; // 后台保活定时器
|
||||
this.keepAliveInterval = null;
|
||||
|
||||
this.onDeviceInfoUpdate = null;
|
||||
this.onLocationInfoUpdate = null;
|
||||
|
||||
this.onControlStatusChange = null;
|
||||
this.onWsStatusChange = null;
|
||||
this.onHasControlRightChange = null;
|
||||
@@ -43,6 +46,7 @@ export default class DeviceController {
|
||||
this.handleWsMessage = this.handleWsMessage.bind(this);
|
||||
this.handleWsStatus = this.handleWsStatus.bind(this);
|
||||
this.handleVisibilityChange = this.handleVisibilityChange.bind(this);
|
||||
this.handleBeforeUnload = this.handleBeforeUnload.bind(this);
|
||||
|
||||
this.sendGamepad = throttle(
|
||||
this.sendGamepad.bind(this),
|
||||
@@ -55,36 +59,38 @@ export default class DeviceController {
|
||||
this.unSubMessage = wsManager.onMessage(this.handleWsMessage);
|
||||
this.unSubStatus = wsManager.onStatusChange(this.handleWsStatus);
|
||||
|
||||
// ========== 【集成】页面可见性监听 ==========
|
||||
document.addEventListener('visibilitychange', this.handleVisibilityChange);
|
||||
document.addEventListener('beforeunload', this.handleBeforeUnload);
|
||||
}
|
||||
levae() {
|
||||
wsManager.close();
|
||||
|
||||
// ========== 【集成】后台保活定时 ==========
|
||||
//this.startKeepAlive();
|
||||
}
|
||||
|
||||
// ========== 【集成】页面切前台重连 ==========
|
||||
handleVisibilityChange() {
|
||||
// 切后台:关闭 WS
|
||||
if (document.visibilityState === 'hidden') {
|
||||
console.log('🔌 页面切后台,关闭 WebSocket');
|
||||
console.log('Page hidden, release control');
|
||||
//this.release();
|
||||
wsManager.close();
|
||||
this.connectedDeviceSn = null;
|
||||
|
||||
|
||||
this.isControlled = false;
|
||||
this.onControlStatusChange?.(false);
|
||||
}
|
||||
if (document.visibilityState === 'visible' && this.currentDevice) {
|
||||
if (!this.currentDevice?.serialNumber) return;
|
||||
console.log('✅ 页面切回前台,自动重连 WebSocket');
|
||||
console.log('Page visible, reconnect WebSocket');
|
||||
setTimeout(() => {
|
||||
this.connectDevice(this.currentDevice);
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 【集成】后台保活 ==========
|
||||
handleBeforeUnload() {
|
||||
console.log('Browser closing/refreshing, release control');
|
||||
this.release();
|
||||
}
|
||||
|
||||
startKeepAlive() {
|
||||
this.keepAliveInterval = setInterval(() => {
|
||||
if (
|
||||
@@ -92,47 +98,50 @@ export default class DeviceController {
|
||||
this.wsStatus !== 'connected' &&
|
||||
this.currentDevice?.serialNumber
|
||||
) {
|
||||
console.log('🔄 后台保活:尝试重连 WebSocket');
|
||||
console.log('Keep alive: reconnect WebSocket');
|
||||
this.connectDevice(this.currentDevice);
|
||||
}
|
||||
}, 8000);
|
||||
}
|
||||
release() {
|
||||
if (this.isControlled && this.connectedDeviceSn) {
|
||||
const data = {
|
||||
platform: "web",
|
||||
type: 1
|
||||
};
|
||||
const url = `${envConfig.baseURL}/forward/device/releaseControl`;
|
||||
|
||||
try {
|
||||
const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
|
||||
navigator.sendBeacon(url, blob);
|
||||
} catch (e) {
|
||||
console.error('Failed to send releaseControl beacon:', e);
|
||||
}
|
||||
async release() {
|
||||
if (!this.connectedDeviceSn) return;
|
||||
const data = {
|
||||
platform: 'web',
|
||||
type: 1,
|
||||
deviceId: this.connectedDeviceSn,
|
||||
token: this.userInfo.token,
|
||||
};
|
||||
const url = `${envConfig.baseURL}/forward/device/releaseControl`;
|
||||
|
||||
try {
|
||||
await releaseControl(data);
|
||||
const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
|
||||
navigator.sendBeacon(url, blob);
|
||||
console.log('releaseControl sent');
|
||||
} catch (e) {
|
||||
console.error('Failed to send releaseControl:', e);
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.clearControlTimeout();
|
||||
|
||||
// 清理保活
|
||||
if (this.keepAliveInterval) {
|
||||
clearInterval(this.keepAliveInterval);
|
||||
this.keepAliveInterval = null;
|
||||
}
|
||||
|
||||
// 移除监听
|
||||
document.removeEventListener('visibilitychange', this.handleVisibilityChange);
|
||||
document.removeEventListener('beforeunload', this.handleBeforeUnload);
|
||||
|
||||
this.release();
|
||||
this.levae();
|
||||
|
||||
this.unSubMessage?.();
|
||||
this.unSubStatus?.();
|
||||
//this.release();
|
||||
|
||||
//wsManager.close();
|
||||
this.connectedDeviceSn = null;
|
||||
|
||||
}
|
||||
|
||||
handleWsStatus(status) {
|
||||
@@ -148,7 +157,6 @@ export default class DeviceController {
|
||||
async connectDevice(device) {
|
||||
if (!device) return;
|
||||
|
||||
// 保存当前设备,用于保活/重连
|
||||
this.currentDevice = device;
|
||||
if (!device.serialNumber) return;
|
||||
|
||||
@@ -156,31 +164,17 @@ export default class DeviceController {
|
||||
|
||||
this.connectedDeviceSn = null;
|
||||
this.wsDeviceInfo = {};
|
||||
this.locationInfo = {};
|
||||
this.isControlled = false;
|
||||
this.onControlStatusChange?.(false);
|
||||
|
||||
wsManager.close();
|
||||
|
||||
try {
|
||||
const res = await getControlRight({
|
||||
userName: this.userInfo.username,
|
||||
sourceType: 1,
|
||||
token: this.userInfo.token,
|
||||
});
|
||||
|
||||
this.hasControlRight = res?.code === 200 && res.data == true;
|
||||
this.onHasControlRightChange?.(this.hasControlRight);
|
||||
|
||||
console.log('Connecting to', this.wsUrl);
|
||||
wsManager.connect(sn, this.wsUrl);
|
||||
this.connectedDeviceSn = sn;
|
||||
|
||||
if (!this.hasControlRight) {
|
||||
this.messageApi.warning(i18n.t('devices.fixed2OthersControlFixed2'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
await this.getControl(sn);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
@@ -188,11 +182,42 @@ export default class DeviceController {
|
||||
}
|
||||
}
|
||||
|
||||
async switchDevice(device) {
|
||||
if (!device) return;
|
||||
if (!device.serialNumber) return;
|
||||
|
||||
const newSn = device.serialNumber;
|
||||
|
||||
if (this.connectedDeviceSn === newSn && this.wsStatus === 'connected') {
|
||||
console.log('switchDevice: same device, skip');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Connecting to switchDevice: switching to', newSn);
|
||||
|
||||
this.currentDevice = device;
|
||||
this.connectedDeviceSn = newSn;
|
||||
this.wsDeviceInfo = {};
|
||||
this.locationInfo = {};
|
||||
this.isControlled = false;
|
||||
this.onControlStatusChange?.(false);
|
||||
|
||||
wsManager.send({
|
||||
type: 'AUTH',
|
||||
token: this.userInfo.token,
|
||||
userName: this.userInfo.username,
|
||||
deviceId: newSn,
|
||||
});
|
||||
|
||||
await this.getControl(newSn);
|
||||
}
|
||||
|
||||
async getControl(serialnum) {
|
||||
try {
|
||||
const res = await getJurisdiction({
|
||||
platform: 'web',
|
||||
deviceId: serialnum,
|
||||
token: this.userInfo.token,
|
||||
});
|
||||
|
||||
this.isControlled = res?.code === 200 && res?.data?.remoteControl === true;
|
||||
@@ -206,10 +231,7 @@ export default class DeviceController {
|
||||
|
||||
requestControl() {
|
||||
if (this.isRequestControl) return;
|
||||
if (!this.hasControlRight) {
|
||||
this.messageApi.warning(i18n.t('devices.noneControl'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.isRequestControl = true;
|
||||
this.onRequestControlStatusChange?.(true);
|
||||
@@ -252,7 +274,7 @@ export default class DeviceController {
|
||||
}
|
||||
|
||||
handleWsMessage(msg) {
|
||||
console.log('📨 收到消息:', msg);
|
||||
console.log('WS message:', msg);
|
||||
switch (msg.type) {
|
||||
case 'deviceInfo': {
|
||||
const data = {};
|
||||
@@ -263,6 +285,15 @@ export default class DeviceController {
|
||||
this.onDeviceInfoUpdate?.(data);
|
||||
break;
|
||||
}
|
||||
case 'locationInfo': {
|
||||
const data = {};
|
||||
msg.data.forEach((item) => {
|
||||
data[item.name] = item.value;
|
||||
});
|
||||
this.locationInfo = data;
|
||||
this.onLocationInfoUpdate?.(data);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'AUTH': {
|
||||
if (msg.isAuth) {
|
||||
@@ -277,7 +308,7 @@ export default class DeviceController {
|
||||
this.isRequestControl = false;
|
||||
this.onRequestControlStatusChange?.(false);
|
||||
|
||||
if (msg.success === false || msg?.respond?.switchResult === false) {
|
||||
if (msg?.success === false || msg?.respond?.switchResult === false) {
|
||||
this.isControlled = false;
|
||||
this.onControlStatusChange?.(false);
|
||||
this.messageApi.error({ key: 'control', content: msg.message || i18n.t('devices.controlFailed') });
|
||||
@@ -291,19 +322,16 @@ export default class DeviceController {
|
||||
case "device_task_change": {
|
||||
if (msg.deviceId != this.connectedDeviceSn) return;
|
||||
this.onIsFinished?.(true);
|
||||
console.log('🔌 控制结果任务变更,', msg);
|
||||
|
||||
console.log('task change:', msg);
|
||||
break;
|
||||
}
|
||||
//完成点
|
||||
case "device_task_arrive_point": {
|
||||
if (msg.deviceId != this.connectedDeviceSn) return;
|
||||
|
||||
this.handleArrivedPoint?.(msg.entity);
|
||||
console.log('🔌 到达完成点,', msg);
|
||||
|
||||
console.log('arrive point:', msg);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 'switchPermission': {
|
||||
const platform = (msg.platform || '').toLowerCase();
|
||||
if (!platform || platform === 'null') return;
|
||||
|
||||
@@ -659,6 +659,8 @@ const en = {
|
||||
optimize: 'Optimize',
|
||||
optionalEmpty: 'Optional Empty',
|
||||
otherWebControlling: 'Other Web Controlling',
|
||||
platformRequestControl: "{{platform}} platformRequestControl",
|
||||
|
||||
outDock: 'Out Dock',
|
||||
outdoor: 'Outdoor',
|
||||
panorama: 'Panorama',
|
||||
@@ -927,6 +929,8 @@ const en = {
|
||||
unitJia: '',
|
||||
unitTai: '',
|
||||
unitTiao: '',
|
||||
normalCancel: "normalCancel",
|
||||
forceCancel: "forceCancel",
|
||||
unknownDevice: 'Unknown Device',
|
||||
unknownDrone: 'Unknown Drone',
|
||||
unknownObject: 'Unknown Object',
|
||||
@@ -987,6 +991,9 @@ const en = {
|
||||
working: 'Working',
|
||||
workingCurrent: 'Working Current',
|
||||
zoomLens: 'Zoom Lens',
|
||||
controllerNotConnected: "controllerNotConnected",
|
||||
otherWebConnected: "otherWebConnected",
|
||||
clickToRequestControl: "clickToRequestControl",
|
||||
|
||||
fixed2TaskSuspended2: 'Fixed2 Task Suspended2 态势',
|
||||
|
||||
@@ -1280,9 +1287,10 @@ const en = {
|
||||
|
||||
failedFixed22: '权限校验 Failed Fixed2',
|
||||
|
||||
noneControl: 'None Control 权限',
|
||||
noneControl: 'None Control jurisdiction',
|
||||
|
||||
fixed2ControlFixed2: 'Fixed2 Control 请求 超时 Fixed2',
|
||||
controlFailed:"请求被拒绝",
|
||||
},
|
||||
video: {
|
||||
onlineVideo: 'Online Video',
|
||||
@@ -3174,7 +3182,6 @@ const en = {
|
||||
|
||||
deptRnd: 'R&D Department',
|
||||
|
||||
editMenu: 'Edit Menu',
|
||||
|
||||
editOrganization: 'Edit Organization',
|
||||
|
||||
@@ -3376,7 +3383,6 @@ const en = {
|
||||
abnormal: 'Abnormal',
|
||||
addSuccess: 'Add Success',
|
||||
confirmDeleteRole: 'Confirm Delete Role',
|
||||
editRole: 'Edit Role',
|
||||
editSuccess: 'Edit Success',
|
||||
manageMembers: 'Manage Members',
|
||||
menuPermissionConfig: 'Menu Permission Config',
|
||||
|
||||
@@ -321,10 +321,13 @@ const zh = {
|
||||
statusPaused: '暂停中',
|
||||
statusFinished: '执行成功',
|
||||
statusFailed: '执行失败',
|
||||
statusCanceling: '取消中',
|
||||
confirmDeleteTask: '确定要删除该任务吗?',
|
||||
confirmCancelTask: '确定要取消该任务吗?',
|
||||
confirmPauseTask: '确定要暂停该任务吗?',
|
||||
confirmResumeTask: '确定要恢复该任务吗?',
|
||||
normalCancel: "普通取消",
|
||||
forceCancel: "强制取消",
|
||||
recover: '恢复',
|
||||
statTodayPlan: '今日机器人计划',
|
||||
unitPlan: '条',
|
||||
@@ -413,7 +416,8 @@ const zh = {
|
||||
selectExecDate: '选择执行日期',
|
||||
execTime: '执行时间',
|
||||
saveTask: '保存任务',
|
||||
abMode: '模式',
|
||||
abMode: '自定义模式',
|
||||
saveFail: '保存失败',
|
||||
activatedTime: '已激活时间',
|
||||
aiAction1: 'AI',
|
||||
aiAction2: 'AI',
|
||||
@@ -444,14 +448,14 @@ const zh = {
|
||||
apiRequestException: 'API请求异常',
|
||||
autoFetch: '自动获取',
|
||||
autoResumeFromBreakpoint: '自动恢复从断点',
|
||||
backView: '返回查看',
|
||||
backView: '后视角',
|
||||
batteryCapacity: '电量容量',
|
||||
batteryWithPercent: '电量带百分比',
|
||||
batteryWithValue: '电量带值',
|
||||
blockUnit: '区块单位',
|
||||
boardTaskFetchFail: '看板任务获取失败',
|
||||
boundDrone: '边界无人机',
|
||||
bowMode: '船首模式',
|
||||
bowMode: '弓字模式',
|
||||
canWorkNormally: '可工作正常',
|
||||
cancelReturnHome: '取消返航首页',
|
||||
chargePoint: '充电点',
|
||||
@@ -554,11 +558,17 @@ const zh = {
|
||||
fillRequiredFields: '填写必填字段',
|
||||
firmwareVersion: '固件版本',
|
||||
fixed: '固定',
|
||||
controllerNotConnected: "控制器未连接",
|
||||
otherWebConnected: "其他网页已连接",
|
||||
clickToRequestControl: "点击请求控制",
|
||||
|
||||
controlling: "控制中",
|
||||
|
||||
fixed2: '',
|
||||
fixedEnv: '固定环境',
|
||||
flightAltitude: '飞行高度',
|
||||
flightWindSpeed: '飞行风速度',
|
||||
frontView: '前查看',
|
||||
frontView: '前视角',
|
||||
ganttViewTitle: '甘特查看标题',
|
||||
generateTask: '生成任务',
|
||||
gnssQuality: 'GNSS质量',
|
||||
@@ -591,7 +601,7 @@ const zh = {
|
||||
issueTaskFirst: '问题任务先',
|
||||
landingDockSn: '降落停靠序列号',
|
||||
landingDockSnLabel: '降落停靠序列号标签',
|
||||
leftView: '左查看',
|
||||
leftView: '左视角',
|
||||
leftWheelDrive: '左轮驱动',
|
||||
legendTitle: '图例标题',
|
||||
levelHigh: '级别高',
|
||||
@@ -610,12 +620,12 @@ const zh = {
|
||||
loginInfoExpired: '登录提示已过期',
|
||||
lostControlAction: '丢失控制操作',
|
||||
lostControlActionLabel: '丢失控制操作标签',
|
||||
markPoint: '标记点',
|
||||
markPoint: '打点',
|
||||
markedPointsCount: '已标记点数量',
|
||||
minBattery: '最小电量',
|
||||
minBatteryLabel: '最小电量标签',
|
||||
minExecBatteryLabel: '最小执行电量标签',
|
||||
minThreePoints: '最小三点',
|
||||
minThreePoints: '最少三个点',
|
||||
modeAuto: '模式自动',
|
||||
modeDebugLocal: '模式调试本地',
|
||||
modeDebugRemote: '模式调试远程',
|
||||
@@ -762,7 +772,7 @@ const zh = {
|
||||
returnHomeAltitudeLabel: '返航首页高度标签',
|
||||
returnHomeMode: '返航首页模式',
|
||||
returnHomeModeLabel: '返航首页模式标签',
|
||||
rightView: '右查看',
|
||||
rightView: '右视角',
|
||||
rightWheelDrive: '右轮驱动',
|
||||
robotExecutingCount: '机器人执行中数量',
|
||||
robotInTaskCount: '机器人内任务数量',
|
||||
@@ -804,7 +814,7 @@ const zh = {
|
||||
rtkModeDesc: 'RTK模式描述',
|
||||
rtkStatus: 'RTK状态',
|
||||
safeRthBattery: '安全返航电量',
|
||||
satelliteCount: '卫星数量',
|
||||
satelliteCount: '卫星数量 {{count}}',
|
||||
savePathTitle: '保存路径标题',
|
||||
savePlan: '保存计划',
|
||||
saving: '节省',
|
||||
@@ -1292,6 +1302,9 @@ const zh = {
|
||||
cancel: "取消",
|
||||
UnitsRobot: "台",
|
||||
UnitsDrone: "架",
|
||||
platformRequestControl: "{{platform}} 正在请求控制权限",
|
||||
controlFailed: "controlFailed",
|
||||
|
||||
},
|
||||
video: {
|
||||
onlineVideo: '在线视频',
|
||||
@@ -2641,7 +2654,6 @@ const zh = {
|
||||
s36: '用户名',
|
||||
|
||||
s37: '关联产品',
|
||||
editMenu: '编辑菜单',
|
||||
addMenu: '新增菜单',
|
||||
editSite: '编辑场站',
|
||||
addSite: '新增场站',
|
||||
|
||||
@@ -113,6 +113,8 @@ export default function Login() {
|
||||
<Form.Item
|
||||
name="agreement"
|
||||
valuePropName="checked"
|
||||
initialValue={true}
|
||||
|
||||
rules={[{ validator: (_, value) => value ? Promise.resolve() : Promise.reject(new Error(t('login.agreeRequired'))) }]}
|
||||
>
|
||||
<Checkbox>
|
||||
|
||||
@@ -1,334 +1,4 @@
|
||||
import React, { lazy, Suspense } from 'react';
|
||||
import { createBrowserRouter } from 'react-router-dom';
|
||||
import type { RouteObject } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
|
||||
|
||||
// 🔥 所有组件全部改为懒加载
|
||||
const VideoMonitorPage = lazy(() => import('../pages/VideoMonitorPage'));
|
||||
const AIDiagnosisPage = lazy(() => import('../pages/AIAnalysis'));
|
||||
const CleanOptimizationPage = lazy(() => import('../pages/CleanOptimization'));
|
||||
const WorkOrderPage = lazy(() => import('../pages/WorkOrder'));
|
||||
const ReportCenterPage = lazy(() => import('../pages/ReportCenter'));
|
||||
const RealTimeMonitorPage = lazy(() => import('../pages/RealTimeMonitor'));
|
||||
const Agri = lazy(() => import('../pages/Agri'));
|
||||
|
||||
const Layout = lazy(() => import('../components/Layout'));
|
||||
const ProtectedRoute = lazy(() => import('../components/ProtectedRoute'));
|
||||
const Login = lazy(() => import('../pages/Login'));
|
||||
|
||||
const Home = lazy(() => import('../pages/Home'));
|
||||
|
||||
const Video = lazy(() => import('../pages/Video'));
|
||||
const Alerts = lazy(() => import('../pages/Alerts'));
|
||||
const Downloads = lazy(() => import('../pages/Downloads'));
|
||||
const Roles = lazy(() => import('../pages/Roles'));
|
||||
const Users = lazy(() => import('../pages/Users'));
|
||||
const MenuList = lazy(() => import('../components/SystemSetting/MenuList'));
|
||||
const Organization = lazy(() => import('../components/SystemSetting/Organization'));
|
||||
const StationManage = lazy(() => import('../components/SystemSetting/StationManage'));
|
||||
const SystemSetting = lazy(() => import('../pages/SystemSetting'));
|
||||
const Profile = lazy(() => import('../pages/Profile'));
|
||||
|
||||
|
||||
const DeviceStatus = lazy(() => import('../components/devices/DeviceStatusPage'));
|
||||
const WayLineTask = lazy(() => import('../components/devices/WayLinePage'));
|
||||
const RobotTask = lazy(() => import('../components/devices/RobotTaskPage'));
|
||||
const DevicesOverview = lazy(() => import('../components/devices/DeviceOverviewPage'));
|
||||
|
||||
|
||||
const BasicSettings = lazy(() => import('../components/SystemSetting/BasicSettings'));
|
||||
const UserRolePage = lazy(() => import('../components/SystemSetting/UserPage'));
|
||||
const DeviceAccessPage = lazy(() => import('../components/SystemSetting/DeviceAccessPage'));
|
||||
const OnlineUserPage = lazy(() => import('../components/SystemSetting/OnlineUser'));
|
||||
const DeviceManagementPage = lazy(() => import('../components/SystemSetting/DeviceManagement'));
|
||||
const SystemMaintenancePage = lazy(() => import('../components/SystemSetting/SystemMaintain'));
|
||||
const LogManagement = lazy(() => import('../components/SystemSetting/LogManagement'));
|
||||
const VideoManagement = lazy(() => import('../components/SystemSetting/VideoManagement'));
|
||||
//const ErrorManagement = lazy(() => import('../components/SystemSetting/ErrorManagement'));
|
||||
//const AlarmSettingsManagement = lazy(() => import('../components/SystemSetting/AlarmSettingsManagement'));
|
||||
//const WorkOrderSettingsManagement = lazy(() => import('../components/SystemSetting/WorkOrderSettingsManagement'));
|
||||
|
||||
// 加载中动画
|
||||
function PageFallback() {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-full min-h-[200px]">
|
||||
<div className="w-8 h-8 border-4 border-blue-500 border-t-transparent rounded-full animate-spin" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 占位页(国际化)
|
||||
const NoticePolicyPlaceholder = () => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div style={{ padding: 20 }}>
|
||||
<h2>{t('router.noticePolicy')}</h2>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const DataSafetyPlaceholder = () => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div style={{ padding: 20 }}>
|
||||
<h2>{t('router.dataSafety')}</h2>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const ModuleDeveloping = () => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center h-full gap-4 text-gray-400 select-none">
|
||||
<span className="text-6xl opacity-20">🚧</span>
|
||||
<p className="text-lg font-medium">{t('router.moduleDeveloping')}</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// ====================== 全部懒加载的路由配置 ======================
|
||||
const routes: RouteObject[] = [
|
||||
{
|
||||
path: '/login',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Login />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<ProtectedRoute />
|
||||
</Suspense>
|
||||
),
|
||||
children: [
|
||||
{
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Layout />
|
||||
</Suspense>
|
||||
),
|
||||
children: [
|
||||
{
|
||||
index: true,
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Home />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'overview',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Home />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'devices/overview',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<DevicesOverview />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'devices/status',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<DeviceStatus />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'devices/wayLineTask',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<WayLineTask />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'devices/robotTask',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<RobotTask />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'video',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Video />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'RealtimeMonitor',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<RealTimeMonitorPage />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'monitor',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<VideoMonitorPage />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'agri',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Agri />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'alerts/all',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Alerts />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'AIanalysis',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<AIDiagnosisPage />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'clean',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<CleanOptimizationPage />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'task',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<WorkOrderPage />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'table',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<ReportCenterPage />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'systemSetting',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<SystemSetting />
|
||||
</Suspense>
|
||||
),
|
||||
children: [
|
||||
{ index: true, element: <Suspense fallback={<PageFallback />}><BasicSettings /></Suspense> },
|
||||
{ path: 'basic', element: <Suspense fallback={<PageFallback />}><BasicSettings /></Suspense> },
|
||||
{ path: 'User', element: <Suspense fallback={<PageFallback />}><UserRolePage /></Suspense> },
|
||||
{ path: 'menu', element: <Suspense fallback={<PageFallback />}><MenuList /></Suspense> },
|
||||
{ path: 'org', element: <Suspense fallback={<PageFallback />}><Organization /></Suspense> },
|
||||
{ path: 'site', element: <Suspense fallback={<PageFallback />}><StationManage /></Suspense> },
|
||||
{ path: 'notice', element: <Suspense fallback={<PageFallback />}><NoticePolicyPlaceholder /></Suspense> },
|
||||
{ path: 'deviceAccess', element: <Suspense fallback={<PageFallback />}><DeviceAccessPage /></Suspense> },
|
||||
{ path: 'dataSafety', element: <Suspense fallback={<PageFallback />}><DataSafetyPlaceholder /></Suspense> },
|
||||
{ path: 'systemMaintenance', element: <Suspense fallback={<PageFallback />}><SystemMaintenancePage /></Suspense> },
|
||||
{ path: 'monitor', element: <Suspense fallback={<PageFallback />}><OnlineUserPage /></Suspense> },
|
||||
{ path: 'devices', element: <Suspense fallback={<PageFallback />}><DeviceManagementPage /></Suspense> },
|
||||
{ path: 'log', element: <Suspense fallback={<PageFallback />}><LogManagement /></Suspense> },
|
||||
{ path: 'videoManage', element: <Suspense fallback={<PageFallback />}><VideoManagement /></Suspense> },
|
||||
]
|
||||
},
|
||||
{
|
||||
path: 'downloads',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Downloads />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'manage/users',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Users />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'manage/roles',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Roles />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'manage/menuList',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<MenuList />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'organization',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Organization />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'station',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<StationManage />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'system',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<SystemSetting />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: 'profile',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Profile />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: '*',
|
||||
element: <ModuleDeveloping />,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
import { routes } from './routes';
|
||||
|
||||
export const router = createBrowserRouter(routes);
|
||||
|
||||
219
src/router/routes.tsx
Normal file
219
src/router/routes.tsx
Normal file
@@ -0,0 +1,219 @@
|
||||
import React, { lazy, Suspense } from 'react';
|
||||
import type { RouteObject } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
// 🔥 所有组件全部改为懒加载
|
||||
const VideoMonitorPage = lazy(() => import('../pages/VideoMonitorPage'));
|
||||
const AIDiagnosisPage = lazy(() => import('../pages/AIAnalysis'));
|
||||
const CleanOptimizationPage = lazy(() => import('../pages/CleanOptimization'));
|
||||
const WorkOrderPage = lazy(() => import('../pages/WorkOrder'));
|
||||
const ReportCenterPage = lazy(() => import('../pages/ReportCenter'));
|
||||
const RealTimeMonitorPage = lazy(() => import('../pages/RealTimeMonitor'));
|
||||
const Agri = lazy(() => import('../pages/Agri'));
|
||||
|
||||
const Layout = lazy(() => import('../components/Layout'));
|
||||
const ProtectedRoute = lazy(() => import('../components/ProtectedRoute'));
|
||||
const Login = lazy(() => import('../pages/Login'));
|
||||
|
||||
const Home = lazy(() => import('../pages/Home'));
|
||||
const Video = lazy(() => import('../pages/Video'));
|
||||
const Alerts = lazy(() => import('../pages/Alerts'));
|
||||
const Downloads = lazy(() => import('../pages/Downloads'));
|
||||
const Roles = lazy(() => import('../pages/Roles'));
|
||||
const Users = lazy(() => import('../pages/Users'));
|
||||
const MenuList = lazy(() => import('../components/SystemSetting/MenuList'));
|
||||
const Organization = lazy(() => import('../components/SystemSetting/Organization'));
|
||||
const StationManage = lazy(() => import('../components/SystemSetting/StationManage'));
|
||||
const SystemSetting = lazy(() => import('../pages/SystemSetting'));
|
||||
const Profile = lazy(() => import('../pages/Profile'));
|
||||
|
||||
const DeviceStatus = lazy(() => import('../components/devices/DeviceStatusPage'));
|
||||
const WayLineTask = lazy(() => import('../components/devices/WayLinePage'));
|
||||
const RobotTask = lazy(() => import('../components/devices/RobotTaskPage'));
|
||||
const DevicesOverview = lazy(() => import('../components/devices/DeviceOverviewPage'));
|
||||
|
||||
const BasicSettings = lazy(() => import('../components/SystemSetting/BasicSettings'));
|
||||
const UserRolePage = lazy(() => import('../components/SystemSetting/UserPage'));
|
||||
const DeviceAccessPage = lazy(() => import('../components/SystemSetting/DeviceAccessPage'));
|
||||
const OnlineUserPage = lazy(() => import('../components/SystemSetting/OnlineUser'));
|
||||
const DeviceManagementPage = lazy(() => import('../components/SystemSetting/DeviceManagement'));
|
||||
const SystemMaintenancePage = lazy(() => import('../components/SystemSetting/SystemMaintain'));
|
||||
const LogManagement = lazy(() => import('../components/SystemSetting/LogManagement'));
|
||||
const VideoManagement = lazy(() => import('../components/SystemSetting/VideoManagement'));
|
||||
|
||||
// 加载中动画
|
||||
export function PageFallback() {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-full min-h-[200px]">
|
||||
<div className="w-8 h-8 border-4 border-blue-500 border-t-transparent rounded-full animate-spin" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 封装高阶组件,消除重复 Suspense
|
||||
export const withSuspense = (Comp: React.LazyExoticComponent<React.FC>) => {
|
||||
return <Suspense fallback={<PageFallback />}>{<Comp />}</Suspense>;
|
||||
};
|
||||
|
||||
// 占位页(国际化)
|
||||
const NoticePolicyPlaceholder = () => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div style={{ padding: 20 }}>
|
||||
<h2>{t('router.noticePolicy')}</h2>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const DataSafetyPlaceholder = () => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div style={{ padding: 20 }}>
|
||||
<h2>{t('router.dataSafety')}</h2>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const ModuleDeveloping = () => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center h-full gap-4 text-gray-400 select-none">
|
||||
<span className="text-6xl opacity-20">🚧</span>
|
||||
<p className="text-lg font-medium">{t('router.moduleDeveloping')}</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ====================== 路由配置数组 ======================
|
||||
export const routes: RouteObject[] = [
|
||||
{
|
||||
path: '/login',
|
||||
element: withSuspense(Login),
|
||||
},
|
||||
{
|
||||
element: withSuspense(ProtectedRoute),
|
||||
children: [
|
||||
{
|
||||
element: withSuspense(Layout),
|
||||
children: [
|
||||
{
|
||||
index: true,
|
||||
element: withSuspense(Home)
|
||||
},
|
||||
{
|
||||
path: 'overview',
|
||||
element: withSuspense(Home)
|
||||
},
|
||||
{
|
||||
path: 'devices/overview',
|
||||
element: withSuspense(DevicesOverview)
|
||||
},
|
||||
{
|
||||
path: 'devices/status',
|
||||
element: withSuspense(DeviceStatus)
|
||||
},
|
||||
{
|
||||
path: 'devices/wayLineTask',
|
||||
element: withSuspense(WayLineTask)
|
||||
},
|
||||
{
|
||||
path: 'devices/robotTask',
|
||||
element: withSuspense(RobotTask)
|
||||
},
|
||||
{
|
||||
path: 'video',
|
||||
element: withSuspense(Video)
|
||||
},
|
||||
{
|
||||
path: 'RealtimeMonitor',
|
||||
element: withSuspense(RealTimeMonitorPage)
|
||||
},
|
||||
{
|
||||
path: 'monitor',
|
||||
element: withSuspense(VideoMonitorPage)
|
||||
},
|
||||
{
|
||||
path: 'agri',
|
||||
element: withSuspense(Agri)
|
||||
},
|
||||
{
|
||||
path: 'alerts/all',
|
||||
element: withSuspense(Alerts)
|
||||
},
|
||||
{
|
||||
path: 'AIanalysis',
|
||||
element: withSuspense(AIDiagnosisPage)
|
||||
},
|
||||
{
|
||||
path: 'clean',
|
||||
element: withSuspense(CleanOptimizationPage)
|
||||
},
|
||||
{
|
||||
path: 'task',
|
||||
element: withSuspense(WorkOrderPage)
|
||||
},
|
||||
{
|
||||
path: 'table',
|
||||
element: withSuspense(ReportCenterPage)
|
||||
},
|
||||
{
|
||||
path: 'systemSetting',
|
||||
element: withSuspense(SystemSetting),
|
||||
children: [
|
||||
{ index: true, element: withSuspense(BasicSettings) },
|
||||
{ path: 'basic', element: withSuspense(BasicSettings) },
|
||||
{ path: 'User', element: withSuspense(UserRolePage) },
|
||||
{ path: 'menu', element: withSuspense(MenuList) },
|
||||
{ path: 'org', element: withSuspense(Organization) },
|
||||
{ path: 'site', element: withSuspense(StationManage) },
|
||||
{ path: 'notice', element: <Suspense fallback={<PageFallback />}><NoticePolicyPlaceholder /></Suspense> },
|
||||
{ path: 'deviceAccess', element: withSuspense(DeviceAccessPage) },
|
||||
{ path: 'dataSafety', element: <Suspense fallback={<PageFallback />}><DataSafetyPlaceholder /></Suspense> },
|
||||
{ path: 'systemMaintenance', element: withSuspense(SystemMaintenancePage) },
|
||||
{ path: 'monitor', element: withSuspense(OnlineUserPage) },
|
||||
{ path: 'devices', element: withSuspense(DeviceManagementPage) },
|
||||
{ path: 'log', element: withSuspense(LogManagement) },
|
||||
{ path: 'videoManage', element: withSuspense(VideoManagement) },
|
||||
]
|
||||
},
|
||||
{
|
||||
path: 'downloads',
|
||||
element: withSuspense(Downloads)
|
||||
},
|
||||
{
|
||||
path: 'manage/users',
|
||||
element: withSuspense(Users)
|
||||
},
|
||||
{
|
||||
path: 'manage/roles',
|
||||
element: withSuspense(Roles)
|
||||
},
|
||||
{
|
||||
path: 'manage/menuList',
|
||||
element: withSuspense(MenuList)
|
||||
},
|
||||
{
|
||||
path: 'organization',
|
||||
element: withSuspense(Organization)
|
||||
},
|
||||
{
|
||||
path: 'station',
|
||||
element: withSuspense(StationManage)
|
||||
},
|
||||
{
|
||||
path: 'system',
|
||||
element: withSuspense(SystemSetting)
|
||||
},
|
||||
{
|
||||
path: 'profile',
|
||||
element: withSuspense(Profile)
|
||||
},
|
||||
{
|
||||
path: '*',
|
||||
element: <ModuleDeveloping />,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user