diff --git a/env.js b/env.js index 465aa70..fabe523 100644 --- a/env.js +++ b/env.js @@ -9,11 +9,11 @@ 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:59015',//http://192.168.2.56:8081 - //WS_URL: 'ws://192.168.2.59:9002/ws/', - //mqtt_url: "ws://192.168.2.59:8083/mqtt", - //geoserver_url: "http://192.168.2.59:7000/geoserver" + baseURL: 'http://192.168.2.59: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://192.168.2.59: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: 'https://serviceri.satabot.com', @@ -21,11 +21,11 @@ const envConfig = { //mqtt_url: "ws://1.95.137.212:59021/mqtt", //geoserver_url: "http://1.95.137.212:59018/geoserver" - baseURL: 'http://1.95.137.212:59015',//http://192.168.2.56:8081 - //baseURL: 'https://serviceri.satabot.com', - WS_URL: 'ws://1.95.137.212:59017/ws/', - mqtt_url: "ws://1.95.137.212:59021/mqtt", - geoserver_url: "http://1.95.137.212:59018/geoserver" + //baseURL: 'http://1.95.137.212:59015',//http://192.168.2.56:8081 + ////baseURL: 'https://serviceri.satabot.com', + //WS_URL: 'ws://1.95.137.212:59017/ws/', + //mqtt_url: "ws://1.95.137.212:59021/mqtt", + //geoserver_url: "http://1.95.137.212:59018/geoserver" }, [ENV.PROD]: { //baseURL: 'https://pvcloudservice.satabot.com', diff --git a/src/api/device.ts b/src/api/device.ts index e4bda2b..7b20f4e 100644 --- a/src/api/device.ts +++ b/src/api/device.ts @@ -408,15 +408,12 @@ export function addRoute(data) { const config = { url: '/iot/workRecord/add', // 修正为正确的添加接口 method: 'post', - data + data, + timeout: 60000, + }; - // 如果是 FormData,不需要设置 Content-Type,axios 会自动设置 - if (!(data instanceof FormData)) { - config.headers = { - 'Content-Type': 'application/json' - }; - } + return request(config); } diff --git a/src/api/request.ts b/src/api/request.ts index 2a629b1..9ef2968 100644 --- a/src/api/request.ts +++ b/src/api/request.ts @@ -23,6 +23,13 @@ api.interceptors.request.use( if (token && config.headers) { config.headers['Authorization'] = `Bearer ${token}`; } + + if (!(config.data instanceof FormData)) { + config.headers['Content-Type'] = 'application/json'; + } else { + // FormData 删除json头,交给axios自动生成multipart + delete config.headers['Content-Type']; + } return config; }, (error: AxiosError) => { diff --git a/src/components/devices/DeviceStatusPage.tsx b/src/components/devices/DeviceStatusPage.tsx index b5c57ff..e82b548 100644 --- a/src/components/devices/DeviceStatusPage.tsx +++ b/src/components/devices/DeviceStatusPage.tsx @@ -57,6 +57,7 @@ import dayjs from 'dayjs'; import { MowerAllView } from './MowerAllView'; import { useMqtt } from '@/hooks/useMqtt'; import envConfig from '../../../env'; +import { dataUrlToFile } from '@/lib/utils.ts'; const { RangePicker } = DatePicker; const { Text } = Typography; @@ -565,8 +566,8 @@ export default function DeviceStatusPage({ return; } const newPoint = { - lon: realtimePosition.lon, - lat: realtimePosition.lat, + lon: Number(realtimePosition.lon), + lat: Number(realtimePosition.lat), }; setMarkedPoints([...markedPoints, newPoint]); messageApi.success(`已标记第 ${markedPoints.length + 1} 个点`); @@ -619,10 +620,22 @@ export default function DeviceStatusPage({ const result = await response.json(); if (result) { - setPoints(result?.data?.points); + const path = result?.data?.path?.map(p => { + return { + lng: p.lon, + lat: p.lat + } + }) + setPoints(path); setSavePath({ - path: result?.data?.path, // 存储返回的路径结果 - outer: requestParams?.outer?.position, + path: path, // 存储返回的路径结果 + outer: requestParams?.outer?.position?.map(p => { + return { + lng: p.lon, + lat: p.lat + } + } + ), planModel: 0, }); setCompleteFlag(true); @@ -665,18 +678,29 @@ export default function DeviceStatusPage({ // 3. 添加文件 if (screenshotDataUrl) { // 将 dataUrl 转换为 Blob - const response = await fetch(screenshotDataUrl); - const blob = await response.blob(); - formData.append('file', blob, 'screenshot.jpg'); + const file = dataUrlToFile(screenshotDataUrl, "screenshot.jpg"); + console.log("blob", file) + + + if (file instanceof File) { + formData.append('file', file); + } } // 4. 添加 workRecord const workRecord = { workName: plotName, siteId: stationId, - jsonData: JSON.stringify(savePath), + jsonData: savePath, }; - formData.append('workRecord', JSON.stringify(workRecord)); + formData.append( + "workRecord", + new Blob([JSON.stringify(workRecord)], { + type: "application/json" + }) + ); + + //formData.append('workRecord', JSON.stringify(workRecord)); // 5. 调用保存接口 const res = await addRoute(formData); diff --git a/src/components/devices/RobotTaskPage.tsx b/src/components/devices/RobotTaskPage.tsx index 7799668..7cf4026 100644 --- a/src/components/devices/RobotTaskPage.tsx +++ b/src/components/devices/RobotTaskPage.tsx @@ -1008,11 +1008,11 @@ export default function RobotTaskPage() { {/* Space开启自动换行,小屏按钮自动折行 */} - + {/* - - */} + {/*