diff --git a/env.js b/env.js new file mode 100644 index 0000000..89c425e --- /dev/null +++ b/env.js @@ -0,0 +1,23 @@ +// 环境枚举 +const ENV = { + DEV: 'development', + PROD: 'production', +}; + +const currentEnv = import.meta.env?.MODE || process.env.NODE_ENV; + +// 环境配置映射 +const envConfig = { + [ENV.DEV]: { + baseURL: 'http://192.168.2.56:8081',//http://192.168.2.56:8081 + WS_URL: 'ws://192.168.2.56:9002/ws/', + }, + [ENV.PROD]: { + // baseURL: 'http://192.168.2.56:8081', + baseURL: 'https://serviceri.satabot.com', + WS_URL: 'wss://ri.satabot.com/ws/' + }, +}; + +// 导出当前环境的配置 +export default envConfig[currentEnv] || envConfig[ENV.DEV]; diff --git a/package-lock.json b/package-lock.json index cd2f03f..01ea515 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "clsx": "^2.1.1", "dotenv": "^17.2.3", "express": "^4.21.2", + "js-cookie": "^3.0.5", "lucide-react": "^0.546.0", "motion": "^12.23.24", "qrcode": "^1.5.4", @@ -3532,6 +3533,15 @@ "jiti": "lib/jiti-cli.mjs" } }, + "node_modules/js-cookie": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz", + "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/package.json b/package.json index fdded4e..95b5ac6 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "clsx": "^2.1.1", "dotenv": "^17.2.3", "express": "^4.21.2", + "js-cookie": "^3.0.5", "lucide-react": "^0.546.0", "motion": "^12.23.24", "qrcode": "^1.5.4", diff --git a/src/api/api.ts b/src/api/api.ts new file mode 100644 index 0000000..7975b9f --- /dev/null +++ b/src/api/api.ts @@ -0,0 +1,342 @@ +import api from './request'; + + +export function getDeviceListApi(data){ + return api({ + url: `/iot/device/userDevice?tenantName=${data.tenantName}&deptId=${data.deptId}`, + method: 'get', + }); +} + +export function getUserList(params) { + return api({ + url: '/system/user/list', + method: 'get', + params + }) +} + + + // 作业列表 +export function getWorkList(data) { + return api({ + url: `/iot/workRecord/selectByUserId?userId=${data.userId}`, + method: 'get', + }) +} + +// /iot/deviceTask/save 新建路线 +export function saveDeviceTask(data) { + return api({ + url: `/iot/deviceTask/save`, + method: 'post', + data + }) +} + + +// 获取任务列表 +export function getDeviceTask(data) { + return api({ + url: `/iot/deviceTask/getDevicePlan`, + method: 'post', + data + }) +} + +// 获取任务分布/iot/deviceTask/devicePlanStatistics + +export function getTaskDistribution(params) { + return api({ + url: `/iot/deviceTask/devicePlanStatistics`, + method: 'get', + params + }) +} + +//选择某一个数据https://serviceri.satabot.com/iot/workRecord/selectByWorkName?workName=${workName}&_t=${Date.now()} +export function getSingleWork(data) { + return api({ + url: `/iot/workRecord/selectByWorkName?workName=${data.workName}`, + method: 'get', + }) +} + +// 执行结果/iot/deviceTask/devicePlanTaskStatistics +export function getDevicePlanTaskStatistics(params) { + return api({ + url: `/iot/deviceTask/devicePlanTaskStatistics`, + method: 'get', + params + }) +} + +// 获取当前的设备运行路线/iot/deviceTask/concurrentDeviceRoute +export function getConcurrentDeviceRoute (params) { + return api({ + url: `/iot/deviceTask/concurrentDeviceRoute`, + method: 'get', + params + }) +} +// 获取作业数据/iot/deviceTask/workStatistics +export function getWorkStatistics(params) { + return api({ + url: `/iot/deviceTask/workStatistics`, + method: 'get', + params + }) +} + + +// 判断是否能控制 +export function getControlRight(params) { + const dataStr = localStorage.getItem('userInfo'); + let parse = JSON.parse(dataStr); + var token=parse?.token; + return api({ + url: `/websocket/judgeConnection`, + method: 'get', + headers: { + Authorization: token // token 正常带上 + }, + params + }) +} + + +// 登录 +export function loginApi(data) { + return api({ + url: '/login', + method: 'post', + data + }) +} + +// 可视化面板获取无人机信息 + +export function getPlaneDeviceList() { + return api({ + url: '/iot/UAV/getProjectDeviceList', + method: 'get', + }) +} + + +// 获取所有航线 + +export function getsinglePlan(data) { + return api({ + url: `/iot/UAV/getFlightTask?sn=${data.gateway_sn}`, + method: 'get', + }) +} + +// 获取航线轨迹 iot/UAV/getFlightTaskTrack + +export function getsinglePlanTrack(data) { + return api({ + url: `/iot/UAV/getFlightTaskTrack?taskId=${data.uuid}`, + method: 'get', + }) +} + +//上传航线 + +export function uploadWayLine(data) { + return api({ + url: '/iot/UAV/uploadWayline', + method: 'post', + data: data, // 上传文件必须用 data,不能用 params + headers: { + 'Content-Type': 'multipart/form-data' // 上传文件必加! + } + }) +} + +//创建航线任务 +export function createWaylineTask(data) { + return api({ + url: '/iot/UAV/createFlightTask', + method: 'post', + data: data, + }) +} + + + +export function updateFlightTaskStatus(taskId, status) { + return api({ + url: '/iot/UAV/updateFlightTaskStatus', + method: 'post', + params: { taskId, status } + }) +} + +export function getFlightTaskDetail(taskId) { + return api({ + url: '/iot/UAV/getFlightTaskDetail', + method: 'get', + params: { taskId } + }) +} + +/// 航线列表 +export function getWayLine() { + return api({ + url: '/iot/UAV/getWayline', + method: 'get', + }) +} +//直播流 + +export function getLiveStream(data) { + return api({ + url: '/iot/UAV/liveStream', + method: 'post', + data + }) +} +///iot/UAV/flightTaskCommand +export function postFlightCommmand(data) { + return api({ + url: '/iot/UAV/flightTaskCommand', + method: 'post', + data + }) +} + +//切换相机 + +export function changeCamera(data) { + return api({ + url: '/iot/UAV/changeCamera', + method: 'post', + data + }) +} + +//直播心跳 + +export function postLiveHeartbeat(data) { + return api({ + url: `/iot/UAV/liveHeartbeat?sn=${data.sn}&cameraIndex=${data.cameraIndex}`, + method: 'post', + }) +} + +//热成像分析 + +export function getThermalDefault() { + return api({ + url: `/api/thermal/defaults`, + method: 'get', + }) +} + +//点击分析 + +export function getThermalAnalyzelt(data) { + return api({ + url: `/api/thermal/analyze`, + method: 'post', + data + }) +} + +//像素点信息/api/thermal/probe + +export function getThermalProbe(data) { + return api({ + url: `/api/thermal/probe`, + method: 'post', + data + }) +} + +//获取报告 +export function getThermalReport(data) { + return api({ + url: `/api/thermal/downloadReport`, + method: 'get', + data + }) +} +//下载报告 +export function downloadReport(data) { + return api({ + url: `/api/thermal/report`, + method: 'get', + params: data, + }) +} + +//获取 用户设备任务列表 + +export function getUserWorkRecord(params) { + return api({ + url: `/iot/workRecord/selectByUserId`, + method: 'get', + params + }) +} + +//获取 任务数据 +export function getWorkData(params) { + return api({ + url: `/iot/workRecord/selectByWorkName`, + method: 'get', + params + }) +} + + +export function getAlimage(params) { + return api({ + url: `/api/thermal/image`, + method: 'get', + params, + //responseType: "blob", // 必须加这个 + }) +} + +// 远程遥控 判断是否有权限/forward/device/remoteControl platform:web +export function getJurisdiction(data) { + return api({ + url: '/forward/device/remoteControl', + method: 'post', + data + }) +} + + +//下载割草任务记录 +// +export function downloadOperationReport() { + return api({ + url: '/iot/device/generateOperationReport', + method: 'get', + responseType: 'arraybuffer' // 👈 只需要加这一行! + }) +} + +// +export function getDeviceIntradayData(params) { + return api({ + url: '/iot/device/getDeviceIntradayData', + method: 'get', + params + }) +} + + + +//释放控制权限/forward/device/releaseControl +export function releaseControl(data) { + return api({ + url: '/forward/device/releaseControl', + method: 'post', + data + }) +} diff --git a/src/api/login/index.ts b/src/api/login/index.ts new file mode 100644 index 0000000..cbe3d7c --- /dev/null +++ b/src/api/login/index.ts @@ -0,0 +1,22 @@ +import request from '../request'; + +//username, password, code, uuid, sourceType +export function login(data) { + return request({ + url: '/login', + headers: { + isToken: false, + }, + method: 'post', + data: data, + }); +} + +// 退出方法 +export function logout() { + return request({ + url: '/logout', + method: 'post', + }); +} + diff --git a/src/api/reportDownloader.ts b/src/api/reportDownloader.ts new file mode 100644 index 0000000..522e073 --- /dev/null +++ b/src/api/reportDownloader.ts @@ -0,0 +1,319 @@ +// reportDownloader.ts +export interface ReportData { + title: string; + metrics: { + label: string; + value: string; + }[]; + bestTime: { + label: string; + value: string; + desc: string; + }; + taskList: { + area: string; + [key: string]: string; // 适配割草(植被高度)、清洗(灰损率)的不同字段 + lossPower: string; + priority: string; + }[]; + taskTableHeader: string[]; + taskTableKeys: string[]; + processSteps: string[]; + processTitle: string; +} + +/** + * 生成HTML报告并下载 + * @param reportData 报告数据 + * @param fileName 下载文件名 + */ +export const downloadHTMLReport = (reportData: ReportData, fileName: string) => { + // HTML报告模板(深蓝色科技主题,专业可视化) + const htmlContent = ` + + + + + ${reportData.title} + + + +
+

${reportData.title}

+ + +
+ ${reportData.metrics + .map( + (metric) => ` +
+
${metric.label}
+
${metric.value}
+
+ ` + ) + .join('')} +
+ + +
+
+ ${reportData.bestTime.label} + ⏰ +
+
${reportData.bestTime.value}
+
${reportData.bestTime.desc}
+
+ + + + + + ${reportData.taskTableHeader + .map((header) => ``) + .join('')} + + + + ${reportData.taskList + .map( + (task) => ` + + ${reportData.taskTableKeys.map((key) => { + if (key === 'priority') { + let className = ''; + if (task[key] === '高') className = 'priority-high'; + else if (task[key] === '中') className = 'priority-medium'; + else className = 'priority-low'; + return ``; + } + return ``; + }).join('')} + + ` + ) + .join('')} + +
${header}
${task[key]}${task[key]}
+ + +
+
${reportData.processTitle}
+
+ ${reportData.processSteps + .map((step) => `
${step}
`) + .join('')} +
+
+
+ + + `; + + // 创建Blob并下载 + const blob = new Blob([htmlContent], { type: 'text/html; charset=utf-8' }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = `${fileName}.html`; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); +}; diff --git a/src/lib/http.ts b/src/api/request.ts similarity index 80% rename from src/lib/http.ts rename to src/api/request.ts index ff7cef2..0e61dbb 100644 --- a/src/lib/http.ts +++ b/src/api/request.ts @@ -1,17 +1,24 @@ -import axios, { AxiosInstance, AxiosResponse, AxiosError, InternalAxiosRequestConfig } from 'axios'; +import axios, { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios'; +import envConfig from '../../env'; +import Cookies from 'js-cookie'; import { message } from 'antd'; -// 创建 axios 实例 -const http: AxiosInstance = axios.create({ - baseURL: '/api', // 根据实际后端 API 路径调整 - timeout: 10000, + +const API_BASE_URL = envConfig.baseURL; + +const api = axios.create({ + baseURL: API_BASE_URL, + timeout: 20000, headers: { 'Content-Type': 'application/json', + }, + withCredentials: true, }); +// 请求拦截器:自动添加token // 请求拦截器 -http.interceptors.request.use( +api.interceptors.request.use( (config: InternalAxiosRequestConfig) => { // 从 localStorage 获取 token const token = localStorage.getItem('token'); @@ -27,7 +34,7 @@ http.interceptors.request.use( ); // 响应拦截器 -http.interceptors.response.use( +api.interceptors.response.use( (response: AxiosResponse) => { // 处理成功响应 const { data } = response; @@ -69,4 +76,4 @@ http.interceptors.response.use( } ); -export default http; +export default api;