Merge pull request 'feat: 删除没用的项目' (#44) from feature_dzc into test
Reviewed-on: http://220.205.16.27:18081/goflytec/GoFly-platform-services/pulls/44
@@ -14,6 +14,5 @@
|
||||
|
||||
<modules>
|
||||
<!-- React开发的前端(Ant Design) -->
|
||||
<module>react-web</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
**/node
|
||||
**/node_modules
|
||||
# roadhog-api-doc ignore
|
||||
/src/utils/request-temp.js
|
||||
_roadhog-api-doc
|
||||
|
||||
# production
|
||||
**/dist
|
||||
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
npm-debug.log*
|
||||
yarn-error.log
|
||||
|
||||
/coverage
|
||||
.idea
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
*bak
|
||||
|
||||
|
||||
# visual studio code
|
||||
.vscode
|
||||
.history
|
||||
*.log
|
||||
functions/*
|
||||
.temp/**
|
||||
|
||||
# umi
|
||||
.umi
|
||||
.umi-production
|
||||
|
||||
# screenshot
|
||||
screenshot
|
||||
.firebase
|
||||
.eslintcache
|
||||
|
||||
# maven
|
||||
target
|
||||
build
|
||||
@@ -1,125 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>zlt-web</artifactId>
|
||||
<groupId>com.zlt</groupId>
|
||||
<version>6.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>react-web</artifactId>
|
||||
<description>React开发的前端(Ant Design)</description>
|
||||
|
||||
<properties>
|
||||
<node.version>v16.13.2</node.version>
|
||||
<yarn.version>v1.22.19</yarn.version>
|
||||
</properties>
|
||||
<!--<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>-->
|
||||
<!--<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.github.eirslett</groupId>
|
||||
<artifactId>frontend-maven-plugin</artifactId>
|
||||
<version>1.12.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>install node and yarn</id>
|
||||
<goals>
|
||||
<goal>install-node-and-yarn</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<nodeVersion>${node.version}</nodeVersion>
|
||||
<yarnVersion>${yarn.version}</yarnVersion>
|
||||
<installDirectory>src/main/frontend</installDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>yarn install</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>yarn</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<arguments>install</arguments>
|
||||
<workingDirectory>src/main/frontend</workingDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>yarn run build</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>yarn</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<arguments>run build</arguments>
|
||||
<workingDirectory>src/main/frontend</workingDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<includeEmptyDirs>true</includeEmptyDirs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>resources</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot-dependencies.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/frontend/dist</directory>
|
||||
<targetPath>META-INF/central-platform-ui</targetPath>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>noNode</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.github.eirslett</groupId>
|
||||
<artifactId>frontend-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>-->
|
||||
|
||||
</project>
|
||||
@@ -1,16 +0,0 @@
|
||||
# http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
@@ -1,8 +0,0 @@
|
||||
/lambda/
|
||||
/scripts
|
||||
/config
|
||||
.history
|
||||
public
|
||||
dist
|
||||
.umi
|
||||
mock
|
||||
@@ -1,8 +0,0 @@
|
||||
module.exports = {
|
||||
extends: [require.resolve('@umijs/fabric/dist/eslint')],
|
||||
globals: {
|
||||
ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: true,
|
||||
page: true,
|
||||
REACT_APP_ENV: true,
|
||||
},
|
||||
};
|
||||
@@ -1,23 +0,0 @@
|
||||
**/*.svg
|
||||
package.json
|
||||
.umi
|
||||
.umi-production
|
||||
/dist
|
||||
.dockerignore
|
||||
.DS_Store
|
||||
.eslintignore
|
||||
*.png
|
||||
*.toml
|
||||
docker
|
||||
.editorconfig
|
||||
Dockerfile*
|
||||
.gitignore
|
||||
.prettierignore
|
||||
LICENSE
|
||||
.eslintcache
|
||||
*.lock
|
||||
yarn-error.log
|
||||
.history
|
||||
CNAME
|
||||
/build
|
||||
/public
|
||||
@@ -1,5 +0,0 @@
|
||||
const fabric = require('@umijs/fabric');
|
||||
|
||||
module.exports = {
|
||||
...fabric.prettier,
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = {
|
||||
extends: [require.resolve('@umijs/fabric/dist/stylelint')],
|
||||
};
|
||||
@@ -1,15 +0,0 @@
|
||||
# 使用轻量级的 nginx 镜像
|
||||
FROM nginx:alpine
|
||||
|
||||
# 复制构建后的文件到 nginx 目录
|
||||
COPY dist/ /usr/share/nginx/html/
|
||||
|
||||
# 复制 nginx 配置文件
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# 设置正确的权限
|
||||
RUN chown -R nginx:nginx /usr/share/nginx/html && \
|
||||
chmod -R 755 /usr/share/nginx/html
|
||||
|
||||
# 暴露 8080 端口
|
||||
EXPOSE 8080
|
||||
@@ -1,59 +0,0 @@
|
||||
# Central-Platform UI
|
||||
|
||||
这个项目是基于`企业级微服务框架`后端 API 所开发的前端代码。
|
||||
|
||||
技术采用
|
||||
|
||||
## Environment Prepare
|
||||
|
||||
Install `node_modules`:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```bash
|
||||
yarn
|
||||
```
|
||||
|
||||
## Provided Scripts
|
||||
|
||||
Ant Design Pro provides some useful script to help you quick start and build with web project, code style check and test.
|
||||
|
||||
Scripts provided in `package.json`. It's safe to modify or add additional script:
|
||||
|
||||
### Start project
|
||||
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
|
||||
### Build project
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Check code style
|
||||
|
||||
```bash
|
||||
npm run lint
|
||||
```
|
||||
|
||||
You can also use script to auto fix some lint error:
|
||||
|
||||
```bash
|
||||
npm run lint:fix
|
||||
```
|
||||
|
||||
### Test code
|
||||
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
|
||||
## More
|
||||
|
||||
You can view full document on our [official website](https://pro.ant.design). And welcome any feedback in our [github](https://github.com/ant-design/ant-design-pro).
|
||||
@@ -1,606 +0,0 @@
|
||||
# WebSocket接口协议文档
|
||||
|
||||
## 概述
|
||||
|
||||
本文档描述了设备运维平台中使用的WebSocket接口协议,用于实时设备监控、控制和数据通信。
|
||||
|
||||
## 服务器信息
|
||||
|
||||
- **WebSocket服务器地址**: `ws://119.45.169.13:8848/messaging/{token}`
|
||||
- **Token获取地址**: `http://119.45.169.13:9900/api-device/token/query`
|
||||
- **Token有效期**: 默认3600秒(1小时),可配置
|
||||
|
||||
## 连接流程
|
||||
|
||||
### 1. 获取Token
|
||||
|
||||
**请求方式**: GET
|
||||
**URL**: `/api-device/token/query`
|
||||
**参数**:
|
||||
- `expires`: Token有效期(秒),可选,默认3600
|
||||
|
||||
**响应格式**:
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "success",
|
||||
"data": {
|
||||
"result": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||
"message": "success",
|
||||
"status": 200,
|
||||
"timestamp": 1640995200000,
|
||||
"expires": 3600
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 建立WebSocket连接
|
||||
|
||||
**连接URL**: `ws://119.45.169.13:8848/messaging/{token}`
|
||||
|
||||
**连接状态**:
|
||||
- `WebSocket.OPEN`: 连接已建立
|
||||
- `WebSocket.CLOSED`: 连接已关闭
|
||||
- `WebSocket.CONNECTING`: 正在连接
|
||||
- `WebSocket.CLOSING`: 正在关闭
|
||||
|
||||
## 消息格式
|
||||
|
||||
### 通用消息结构
|
||||
|
||||
所有WebSocket消息都遵循以下JSON格式:
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "消息类型",
|
||||
"topic": "主题路径",
|
||||
"parameter": {
|
||||
"messageType": "消息类型",
|
||||
"properties": {
|
||||
"method": "方法名",
|
||||
"data": {}
|
||||
},
|
||||
"headers": {
|
||||
"async": false
|
||||
}
|
||||
},
|
||||
"id": "唯一标识符"
|
||||
}
|
||||
```
|
||||
|
||||
## 消息类型
|
||||
|
||||
### 1. 订阅消息 (sub)
|
||||
|
||||
用于订阅设备状态、属性上报、事件等消息。
|
||||
|
||||
#### 设备属性上报订阅
|
||||
```json
|
||||
{
|
||||
"type": "sub",
|
||||
"topic": "/device/*/*/message/property/report",
|
||||
"parameter": {},
|
||||
"id": "sub_property_all_{timestamp}"
|
||||
}
|
||||
```
|
||||
|
||||
#### 设备事件订阅
|
||||
```json
|
||||
{
|
||||
"type": "sub",
|
||||
"topic": "/device/*/*/message/event/fire_alarm",
|
||||
"parameter": {},
|
||||
"id": "sub_event_all_{timestamp}"
|
||||
}
|
||||
```
|
||||
|
||||
#### 设备上线状态订阅
|
||||
```json
|
||||
{
|
||||
"type": "sub",
|
||||
"topic": "/device/*/*/online",
|
||||
"parameter": {},
|
||||
"id": "sub_online_all_{timestamp}"
|
||||
}
|
||||
```
|
||||
|
||||
#### 设备离线状态订阅
|
||||
```json
|
||||
{
|
||||
"type": "sub",
|
||||
"topic": "/device/*/*/offline",
|
||||
"parameter": {},
|
||||
"id": "sub_offline_all_{timestamp}"
|
||||
}
|
||||
```
|
||||
|
||||
#### 指定设备订阅
|
||||
```json
|
||||
{
|
||||
"type": "sub",
|
||||
"topic": "/device/*/{deviceSn}/message/property/report",
|
||||
"parameter": {},
|
||||
"id": "property-sub-{timestamp}-{deviceSn}"
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 取消订阅消息 (unsub)
|
||||
|
||||
用于取消已订阅的消息。
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "unsub",
|
||||
"id": "订阅ID"
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 设备控制消息
|
||||
|
||||
用于向设备发送控制指令。
|
||||
|
||||
#### 通用控制指令
|
||||
```json
|
||||
{
|
||||
"type": "sub",
|
||||
"topic": "/device-message-sender/D-Dock2/{deviceSn}",
|
||||
"parameter": {
|
||||
"messageType": "WRITE_PROPERTY",
|
||||
"properties": {
|
||||
"method": "方法名",
|
||||
"data": {}
|
||||
},
|
||||
"headers": {
|
||||
"async": false
|
||||
}
|
||||
},
|
||||
"id": "control_{method}_{deviceSn}_{timestamp}"
|
||||
}
|
||||
```
|
||||
|
||||
#### 摇杆控制指令
|
||||
```json
|
||||
{
|
||||
"type": "sub",
|
||||
"topic": "/device-message-sender/D-Dock2/{deviceSn}",
|
||||
"parameter": {
|
||||
"messageType": "WRITE_PROPERTY",
|
||||
"properties": {
|
||||
"method": "stick_control",
|
||||
"data": {
|
||||
"roll": 1024, // 右手左右控制(范围:0-2048,1024为中立位)
|
||||
"pitch": 1024, // 右手上下控制(范围:0-2048,1024为中立位)
|
||||
"throttle": 1024, // 左手上下控制(范围:0-2048,1024为中立位)
|
||||
"yaw": 1024, // 左手左右控制(范围:1024±100)
|
||||
"gimbal_pitch": 1024 // 云台画面上下划(范围:0-2048,1024为中立位)
|
||||
}
|
||||
},
|
||||
"headers": {
|
||||
"async": false
|
||||
}
|
||||
},
|
||||
"id": "control_stick_control_{deviceSn}_{timestamp}"
|
||||
}
|
||||
```
|
||||
|
||||
### 4. 心跳消息 (ping/pong)
|
||||
|
||||
用于保持连接活跃。
|
||||
|
||||
**发送心跳**:
|
||||
```json
|
||||
{
|
||||
"type": "ping",
|
||||
"timestamp": 1640995200000
|
||||
}
|
||||
```
|
||||
|
||||
**心跳响应**:
|
||||
```json
|
||||
{
|
||||
"type": "pong"
|
||||
}
|
||||
```
|
||||
|
||||
## 响应消息
|
||||
|
||||
### 1. 订阅结果响应
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "result",
|
||||
"topic": "/device/{productId}/{deviceSn}/message/property/report",
|
||||
"payload": {
|
||||
"headers": {
|
||||
"deviceName": "设备名称",
|
||||
"productName": "产品名称",
|
||||
"productId": "产品ID"
|
||||
},
|
||||
"messageId": "消息ID",
|
||||
"deviceId": "设备ID",
|
||||
"timestamp": 1640995200000,
|
||||
"data": {
|
||||
"data": {
|
||||
// 环境数据
|
||||
"temperature": 25.5,
|
||||
"humidity": 60.2,
|
||||
"wind_speed": 3.2,
|
||||
"rainfall": 0.0,
|
||||
"environment_temperature": 26.1,
|
||||
"latitude": 39.9042,
|
||||
"longitude": 116.4074,
|
||||
"height": 100.5,
|
||||
"heading": 180.0,
|
||||
|
||||
// 设备状态
|
||||
"drone_charge_state": {
|
||||
"capacity_percent": 85,
|
||||
"state": 1
|
||||
},
|
||||
"position_state": {
|
||||
"is_calibration": 0,
|
||||
"rtk_number": 8,
|
||||
"gps_number": 12,
|
||||
"is_fixed": 1,
|
||||
"quality": 95
|
||||
},
|
||||
"network_state": {
|
||||
"rate": 1000,
|
||||
"type": 1,
|
||||
"quality": 90
|
||||
},
|
||||
"drone_in_dock": 1,
|
||||
|
||||
// 飞行任务数据
|
||||
"flighttask_step_code": 0,
|
||||
"sdr": {
|
||||
"frequency_band": 2,
|
||||
"up_quality": 95,
|
||||
"down_quality": 92
|
||||
},
|
||||
"tilt_angle": {
|
||||
"valid": 1,
|
||||
"value": 0.5
|
||||
},
|
||||
"wireless_link": {
|
||||
"sdr_link_state": 1,
|
||||
"4g_freq_band": 1,
|
||||
"4g_quality": 85,
|
||||
"link_workmode": 1,
|
||||
"sdr_quality": 90,
|
||||
"4g_uav_quality": 88,
|
||||
"sdr_freq_band": 2,
|
||||
"4g_link_state": 1,
|
||||
"4g_gnd_quality": 87,
|
||||
"dongle_number": 1
|
||||
}
|
||||
},
|
||||
"deviceId": "设备ID",
|
||||
"timestamp": 1640995200000
|
||||
},
|
||||
"messageType": "REPORT_PROPERTY"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 设备事件响应
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "result",
|
||||
"topic": "/device/{productId}/{deviceSn}/message/event/fire_alarm",
|
||||
"payload": {
|
||||
"headers": {
|
||||
"deviceName": "设备名称",
|
||||
"productName": "产品名称",
|
||||
"productId": "产品ID"
|
||||
},
|
||||
"messageId": "消息ID",
|
||||
"deviceId": "设备ID",
|
||||
"timestamp": 1640995200000,
|
||||
"event": "fire_alarm",
|
||||
"data": {
|
||||
"alarm_level": 1,
|
||||
"alarm_type": "smoke",
|
||||
"location": "building_1",
|
||||
"description": "烟雾报警"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 设备状态响应
|
||||
|
||||
#### 设备上线
|
||||
```json
|
||||
{
|
||||
"type": "result",
|
||||
"topic": "/device/{productId}/{deviceSn}/online",
|
||||
"payload": {
|
||||
"deviceId": "设备ID",
|
||||
"timestamp": 1640995200000,
|
||||
"status": "online"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 设备离线
|
||||
```json
|
||||
{
|
||||
"type": "result",
|
||||
"topic": "/device/{productId}/{deviceSn}/offline",
|
||||
"payload": {
|
||||
"deviceId": "设备ID",
|
||||
"timestamp": 1640995200000,
|
||||
"status": "offline"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 主题路径说明
|
||||
|
||||
### 主题格式
|
||||
|
||||
```
|
||||
/device/{productId}/{deviceSn}/{messageType}/{eventType}
|
||||
```
|
||||
|
||||
### 主题示例
|
||||
|
||||
- `/device/D-Dock2/DEVICE001/message/property/report` - 设备属性上报
|
||||
- `/device/D-Dock2/DEVICE001/message/event/fire_alarm` - 火警事件
|
||||
- `/device/D-Dock2/DEVICE001/online` - 设备上线
|
||||
- `/device/D-Dock2/DEVICE001/offline` - 设备离线
|
||||
|
||||
### 通配符使用
|
||||
|
||||
- `*` - 匹配任意字符串
|
||||
- `/device/*/*/message/property/report` - 订阅所有设备的属性上报
|
||||
- `/device/*/*/online` - 订阅所有设备的上线状态
|
||||
|
||||
## 错误处理
|
||||
|
||||
### 连接错误
|
||||
|
||||
当WebSocket连接出现错误时,系统会自动尝试重连:
|
||||
|
||||
1. 连接断开后等待5秒
|
||||
2. 自动重新获取Token
|
||||
3. 重新建立WebSocket连接
|
||||
4. 重新订阅之前的消息
|
||||
|
||||
### 消息错误
|
||||
|
||||
如果消息格式错误或处理失败,服务器会返回错误响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "error",
|
||||
"id": "消息ID",
|
||||
"error": {
|
||||
"code": "ERROR_CODE",
|
||||
"message": "错误描述"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 最佳实践
|
||||
|
||||
### 1. 连接管理
|
||||
|
||||
- 实现自动重连机制
|
||||
- 定期发送心跳保持连接
|
||||
- 在页面卸载时正确关闭连接
|
||||
|
||||
### 2. 消息处理
|
||||
|
||||
- 为每个消息生成唯一的ID
|
||||
- 实现消息超时处理
|
||||
- 正确处理异步消息
|
||||
|
||||
### 3. 错误处理
|
||||
|
||||
- 实现完善的错误处理机制
|
||||
- 记录错误日志便于调试
|
||||
- 提供用户友好的错误提示
|
||||
|
||||
### 4. 性能优化
|
||||
|
||||
- 合理使用通配符订阅
|
||||
- 及时取消不需要的订阅
|
||||
- 避免频繁发送控制指令
|
||||
|
||||
## 示例代码
|
||||
|
||||
### JavaScript/TypeScript 示例
|
||||
|
||||
```typescript
|
||||
class WebSocketClient {
|
||||
private ws: WebSocket | null = null;
|
||||
private token: string = '';
|
||||
private reconnectTimer: NodeJS.Timeout | null = null;
|
||||
private heartbeatTimer: NodeJS.Timeout | null = null;
|
||||
|
||||
// 获取Token
|
||||
async getToken(): Promise<string> {
|
||||
const response = await fetch('/api-device/token/query?expires=3600');
|
||||
const data = await response.json();
|
||||
if (data.resp_code === 0) {
|
||||
return data.data.result;
|
||||
}
|
||||
throw new Error('获取Token失败');
|
||||
}
|
||||
|
||||
// 连接WebSocket
|
||||
async connect(): Promise<void> {
|
||||
try {
|
||||
this.token = await this.getToken();
|
||||
const wsUrl = `ws://119.45.169.13:8848/messaging/${this.token}`;
|
||||
|
||||
this.ws = new WebSocket(wsUrl);
|
||||
|
||||
this.ws.onopen = () => {
|
||||
console.log('WebSocket连接已建立');
|
||||
this.startHeartbeat();
|
||||
this.subscribeToMessages();
|
||||
};
|
||||
|
||||
this.ws.onmessage = (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
this.handleMessage(data);
|
||||
};
|
||||
|
||||
this.ws.onclose = () => {
|
||||
console.log('WebSocket连接已关闭');
|
||||
this.scheduleReconnect();
|
||||
};
|
||||
|
||||
this.ws.onerror = (error) => {
|
||||
console.error('WebSocket错误:', error);
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('连接失败:', error);
|
||||
this.scheduleReconnect();
|
||||
}
|
||||
}
|
||||
|
||||
// 发送消息
|
||||
sendMessage(message: any): void {
|
||||
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
||||
this.ws.send(JSON.stringify(message));
|
||||
}
|
||||
}
|
||||
|
||||
// 订阅消息
|
||||
subscribeToMessages(): void {
|
||||
const subscriptions = [
|
||||
{
|
||||
type: 'sub',
|
||||
topic: '/device/*/*/message/property/report',
|
||||
id: `sub_property_${Date.now()}`
|
||||
},
|
||||
{
|
||||
type: 'sub',
|
||||
topic: '/device/*/*/online',
|
||||
id: `sub_online_${Date.now()}`
|
||||
}
|
||||
];
|
||||
|
||||
subscriptions.forEach(sub => this.sendMessage(sub));
|
||||
}
|
||||
|
||||
// 发送控制指令
|
||||
sendControlCommand(deviceSn: string, method: string, data: any = {}): void {
|
||||
const message = {
|
||||
type: 'sub',
|
||||
topic: `/device-message-sender/D-Dock2/${deviceSn}`,
|
||||
parameter: {
|
||||
messageType: 'WRITE_PROPERTY',
|
||||
properties: { method, data },
|
||||
headers: { async: false }
|
||||
},
|
||||
id: `control_${method}_${deviceSn}_${Date.now()}`
|
||||
};
|
||||
|
||||
this.sendMessage(message);
|
||||
}
|
||||
|
||||
// 心跳检测
|
||||
startHeartbeat(): void {
|
||||
this.heartbeatTimer = setInterval(() => {
|
||||
this.sendMessage({
|
||||
type: 'ping',
|
||||
timestamp: Date.now()
|
||||
});
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
// 重连机制
|
||||
scheduleReconnect(): void {
|
||||
if (this.reconnectTimer) {
|
||||
clearTimeout(this.reconnectTimer);
|
||||
}
|
||||
|
||||
this.reconnectTimer = setTimeout(() => {
|
||||
console.log('尝试重新连接...');
|
||||
this.connect();
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
// 处理消息
|
||||
handleMessage(data: any): void {
|
||||
switch (data.type) {
|
||||
case 'result':
|
||||
this.handleResultMessage(data);
|
||||
break;
|
||||
case 'pong':
|
||||
console.log('收到心跳响应');
|
||||
break;
|
||||
case 'error':
|
||||
console.error('收到错误消息:', data.error);
|
||||
break;
|
||||
default:
|
||||
console.log('收到未知消息:', data);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理结果消息
|
||||
handleResultMessage(data: any): void {
|
||||
const { topic, payload } = data;
|
||||
|
||||
if (topic.includes('/message/property/report')) {
|
||||
console.log('设备属性上报:', payload);
|
||||
} else if (topic.includes('/online')) {
|
||||
console.log('设备上线:', payload);
|
||||
} else if (topic.includes('/offline')) {
|
||||
console.log('设备离线:', payload);
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭连接
|
||||
disconnect(): void {
|
||||
if (this.heartbeatTimer) {
|
||||
clearInterval(this.heartbeatTimer);
|
||||
}
|
||||
if (this.reconnectTimer) {
|
||||
clearTimeout(this.reconnectTimer);
|
||||
}
|
||||
if (this.ws) {
|
||||
this.ws.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 使用示例
|
||||
const wsClient = new WebSocketClient();
|
||||
wsClient.connect();
|
||||
|
||||
// 发送控制指令
|
||||
wsClient.sendControlCommand('DEVICE001', 'stick_control', {
|
||||
roll: 1024,
|
||||
pitch: 1024,
|
||||
throttle: 1024,
|
||||
yaw: 1024
|
||||
});
|
||||
|
||||
// 页面卸载时关闭连接
|
||||
window.addEventListener('beforeunload', () => {
|
||||
wsClient.disconnect();
|
||||
});
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **Token管理**: Token有过期时间,需要定期刷新
|
||||
2. **连接稳定性**: 实现自动重连和心跳机制
|
||||
3. **消息处理**: 正确处理各种类型的消息
|
||||
4. **错误处理**: 完善的错误处理机制
|
||||
5. **资源清理**: 及时清理定时器和连接
|
||||
6. **安全性**: 确保Token的安全性,不要在客户端存储敏感信息
|
||||
|
||||
## 更新日志
|
||||
|
||||
- **v1.0.0**: 初始版本,包含基本的连接、订阅、控制功能
|
||||
- **v1.1.0**: 添加心跳机制和自动重连
|
||||
- **v1.2.0**: 完善错误处理和消息格式
|
||||
- **v1.3.0**: 添加设备状态监控和事件处理
|
||||
@@ -1 +0,0 @@
|
||||
npm run build
|
||||
@@ -1,15 +0,0 @@
|
||||
// https://umijs.org/config/
|
||||
import { defineConfig } from 'umi';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
// https://github.com/zthxxx/react-dev-inspector
|
||||
'react-dev-inspector/plugins/umi/react-inspector',
|
||||
],
|
||||
// https://github.com/zthxxx/react-dev-inspector#inspector-loader-props
|
||||
inspectorConfig: {
|
||||
exclude: [],
|
||||
babelPlugins: [],
|
||||
babelOptions: {},
|
||||
},
|
||||
});
|
||||
@@ -1,80 +0,0 @@
|
||||
// https://umijs.org/config/
|
||||
import { defineConfig } from 'umi';
|
||||
import { join } from 'path';
|
||||
|
||||
import defaultSettings from './defaultSettings';
|
||||
import proxy from './proxy';
|
||||
import routes from './routes';
|
||||
|
||||
const { REACT_APP_ENV } = process.env;
|
||||
|
||||
export default defineConfig({
|
||||
hash: true,
|
||||
publicPath:"./",
|
||||
antd: {},
|
||||
dva: {
|
||||
hmr: true,
|
||||
},
|
||||
layout: {
|
||||
// https://umijs.org/zh-CN/plugins/plugin-layout
|
||||
locale: false,
|
||||
siderWidth: 208,
|
||||
...defaultSettings,
|
||||
},
|
||||
// https://umijs.org/zh-CN/plugins/plugin-locale
|
||||
locale: {
|
||||
// default zh-CN
|
||||
default: 'zh-CN',
|
||||
antd: true,
|
||||
// default true, when it is true, will use `navigator.language` overwrite default
|
||||
baseNavigator: true,
|
||||
},
|
||||
dynamicImport: {
|
||||
loading: '@ant-design/pro-layout/es/PageLoading',
|
||||
},
|
||||
targets: {
|
||||
ie: 11,
|
||||
},
|
||||
// umi routes: https://umijs.org/docs/routing
|
||||
routes,
|
||||
access: {},
|
||||
// Theme for antd: https://ant.design/docs/react/customize-theme-cn
|
||||
theme: {
|
||||
// 如果不想要 configProvide 动态设置主题需要把这个设置为 default
|
||||
// 只有设置为 variable, 才能使用 configProvide 动态设置主色调
|
||||
// https://ant.design/docs/react/customize-theme-variable-cn
|
||||
'root-entry-name': 'variable',
|
||||
},
|
||||
// esbuild is father build tools
|
||||
// https://umijs.org/plugins/plugin-esbuild
|
||||
esbuild: {},
|
||||
title: false,
|
||||
ignoreMomentLocale: true,
|
||||
proxy: proxy[REACT_APP_ENV || 'dev'],
|
||||
manifest: {
|
||||
basePath: '/',
|
||||
},
|
||||
// Fast Refresh 热更新
|
||||
fastRefresh: {},
|
||||
openAPI: [
|
||||
{
|
||||
requestLibPath: "import { request } from 'umi'",
|
||||
// 或者使用在线的版本
|
||||
// schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json"
|
||||
schemaPath: join(__dirname, 'oneapi.json'),
|
||||
mock: false,
|
||||
},
|
||||
{
|
||||
requestLibPath: "import { request } from 'umi'",
|
||||
schemaPath: 'https://gw.alipayobjects.com/os/antfincdn/CA1dOm%2631B/openapi.json',
|
||||
projectName: 'swagger',
|
||||
},
|
||||
],
|
||||
nodeModulesTransform: { type: 'none' },
|
||||
mfsu: false,
|
||||
webpack5: {},
|
||||
exportStatic: {},
|
||||
history: {
|
||||
type: 'hash',
|
||||
},
|
||||
});
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Settings as LayoutSettings } from '@ant-design/pro-components';
|
||||
|
||||
const Settings: LayoutSettings & {
|
||||
pwa?: boolean;
|
||||
logo?: string;
|
||||
} = {
|
||||
navTheme: 'dark',
|
||||
// 拂晓蓝
|
||||
primaryColor: '#1890ff',
|
||||
layout: 'mix',
|
||||
contentWidth: 'Fluid',
|
||||
fixedHeader: false,
|
||||
fixSiderbar: true,
|
||||
colorWeak: false,
|
||||
title: 'G-Fly',
|
||||
pwa: false,
|
||||
logo: './logo.png',
|
||||
iconfontUrl: '',
|
||||
};
|
||||
|
||||
export default Settings;
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"openapi": "3.0.1",
|
||||
"info": {
|
||||
"title": "zlt-web",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "http://localhost:8000/"
|
||||
},
|
||||
{
|
||||
"url": "https://localhost:8000/"
|
||||
}
|
||||
],
|
||||
"paths": {}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/**
|
||||
* 在生产环境 代理是无法生效的,所以这里没有生产环境的配置
|
||||
* -------------------------------
|
||||
* The agent cannot take effect in the production environment
|
||||
* so there is no configuration of the production environment
|
||||
* For details, please see
|
||||
* https://pro.ant.design/docs/deploy
|
||||
*/
|
||||
export default {
|
||||
dev: {
|
||||
'/api-uaa/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://local.goflytec.com:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-user/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://local.goflytec.com:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-log/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://local.goflytec.com:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-search/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://local.goflytec.com:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-generator/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://local.goflytec.com:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-file/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://local.goflytec.com:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-order/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://local.goflytec.com:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-device/': {
|
||||
//target: 'http://119.45.169.13:9900',
|
||||
target: 'http://local.goflytec.com:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
test: {
|
||||
'/api/': {
|
||||
target: 'https://proapi.azurewebsites.net',
|
||||
changeOrigin: true,
|
||||
pathRewrite: { '^': '' },
|
||||
},
|
||||
},
|
||||
pre: {
|
||||
'/api/': {
|
||||
target: 'your pre url',
|
||||
changeOrigin: true,
|
||||
pathRewrite: { '^': '' },
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,237 +0,0 @@
|
||||
export default [
|
||||
{
|
||||
path: '/user',
|
||||
layout: false,
|
||||
routes: [
|
||||
{
|
||||
name: 'login',
|
||||
path: '/user/login',
|
||||
component: './user/Login',
|
||||
},
|
||||
{
|
||||
component: './404',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/system',
|
||||
routes: [
|
||||
{
|
||||
path: '/system/user.html',
|
||||
component: './system/User',
|
||||
},
|
||||
{
|
||||
path: '/system/tenant.html',
|
||||
component: './system/TenantManage',
|
||||
},
|
||||
{
|
||||
path: '/system/role.html',
|
||||
component: './system/Role',
|
||||
},
|
||||
{
|
||||
path: '/system/tokens.html',
|
||||
component: './system/Token',
|
||||
},
|
||||
{
|
||||
path: '/system/menus.html',
|
||||
component: './system/Menu',
|
||||
},
|
||||
{
|
||||
path: '/system/myInfo.html',
|
||||
component: './system/UserInfo',
|
||||
},
|
||||
{
|
||||
path: '/system/miniApp.html',
|
||||
component: './system/MiniApp',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/files',
|
||||
routes: [
|
||||
{
|
||||
path: '/files/files.html',
|
||||
component: './files/File',
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/device',
|
||||
routes: [
|
||||
{
|
||||
path: '/device/wayline.html',
|
||||
component: './device/Wayline',
|
||||
},
|
||||
{
|
||||
path: '/device/device.html',
|
||||
component: './device/Device',
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/message',
|
||||
routes: [
|
||||
{
|
||||
path: '/message/message.html',
|
||||
component: './message/index',
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/orders',
|
||||
routes: [
|
||||
{
|
||||
path: '/orders/order.html',
|
||||
component: './orders/Order',
|
||||
},
|
||||
{
|
||||
path: '/orders/orderFiles.html',
|
||||
component: './orders/OrderFile',
|
||||
},
|
||||
{
|
||||
path: '/orders/tourism.html',
|
||||
component: './orders/Tourism',
|
||||
},
|
||||
{
|
||||
path: '/orders/qrcode.html',
|
||||
component: './orders/Qrcode',
|
||||
},
|
||||
{
|
||||
path: '/orders/tourismFile.html',
|
||||
component: './orders/TourismFile',
|
||||
},
|
||||
{
|
||||
path: '/orders/homeCarousel.html',
|
||||
component: './orders/HomeCarousel',
|
||||
},
|
||||
{
|
||||
path: '/orders/refund.html',
|
||||
component: './orders/Refund',
|
||||
},
|
||||
{
|
||||
path: '/orders/statistics.html',
|
||||
component: './orders/statistics',
|
||||
},
|
||||
{
|
||||
path: '/orders/profitSharing.html',
|
||||
component: './orders/ProfitSharing',
|
||||
},
|
||||
{
|
||||
path: '/orders/profit-sharing/statistics.html',
|
||||
component: './orders/ProfitSharing/Statistics',
|
||||
},
|
||||
{
|
||||
path: '/orders/videoTemplate.html',
|
||||
component: './orders/VideoTemplate',
|
||||
},
|
||||
{
|
||||
path: '/orders/editTask.html',
|
||||
component: './orders/EditTask',
|
||||
},
|
||||
{
|
||||
path: '/orders/wxMessage.html',
|
||||
component: './orders/WxMessage',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/search',
|
||||
routes: [
|
||||
{
|
||||
path: '/search/index_manager.html',
|
||||
component: './search/Index',
|
||||
},
|
||||
{
|
||||
path: '/search/user_search.html',
|
||||
component: './search/User',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/log',
|
||||
routes: [
|
||||
{
|
||||
path: '/log/sysLog.html',
|
||||
component: './log/SysLog',
|
||||
},
|
||||
{
|
||||
path: '/log/auditLog.html',
|
||||
component: './log/AuditLog',
|
||||
},
|
||||
{
|
||||
path: '/log/slowQueryLog.html',
|
||||
component: './log/SlowSqlLog',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/attestation/app.html',
|
||||
component: './system/App',
|
||||
},
|
||||
{
|
||||
path: '/generator/list.html',
|
||||
component: './system/Generator',
|
||||
},
|
||||
{
|
||||
path: '/welcome',
|
||||
name: 'welcome',
|
||||
icon: 'smile',
|
||||
component: './Welcome',
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/welcome',
|
||||
},
|
||||
{
|
||||
path: '/orders/edit-task',
|
||||
name: '剪辑任务管理',
|
||||
icon: 'VideoCameraOutlined',
|
||||
component: './orders/EditTask',
|
||||
},
|
||||
{
|
||||
path: '/device-ops',
|
||||
name: '设备运维',
|
||||
icon: 'monitor',
|
||||
routes: [
|
||||
{
|
||||
path: '/device-ops/device.html',
|
||||
name: '设备管理',
|
||||
component: './device-ops/device',
|
||||
},
|
||||
{
|
||||
path: '/device-ops/map-dashboard.html',
|
||||
name: '地图仪表板',
|
||||
component: './device-ops/map-dashboard',
|
||||
},
|
||||
{
|
||||
path: '/device-ops/device/:id',
|
||||
name: '设备详情',
|
||||
component: './device-ops/device/detail',
|
||||
hideInMenu: true,
|
||||
},
|
||||
{
|
||||
path: '/device-ops/group.html',
|
||||
name: '分组管理',
|
||||
component: './device-ops/group',
|
||||
},
|
||||
{
|
||||
path: '/device-ops/maintenance.html',
|
||||
name: '运维管理',
|
||||
component: './device-ops/maintenance',
|
||||
},
|
||||
{
|
||||
path: '/device-ops/monitor.html',
|
||||
name: '设备监控',
|
||||
component: './device-ops/monitor',
|
||||
},
|
||||
{
|
||||
path: '/device-ops/statistics.html',
|
||||
name: '统计分析',
|
||||
component: './device-ops/statistics',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
component: './404',
|
||||
},
|
||||
];
|
||||
@@ -1,51 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "开始部署前端项目..."
|
||||
|
||||
# 首先构建项目
|
||||
echo "构建前端项目..."
|
||||
npm run build
|
||||
|
||||
# 检查构建是否成功
|
||||
if [ ! -d "dist" ]; then
|
||||
echo "错误:dist 目录不存在,构建可能失败"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查必要文件
|
||||
if [ ! -f "dist/index.html" ]; then
|
||||
echo "错误:index.html 不存在,构建可能不完整"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "开始 Docker 部署..."
|
||||
|
||||
# 停止并删除旧容器
|
||||
docker compose down
|
||||
|
||||
# 清理旧的构建缓存
|
||||
docker builder prune -f
|
||||
|
||||
# 重新构建并启动
|
||||
docker compose up -d --build
|
||||
|
||||
# 检查容器状态
|
||||
docker compose ps
|
||||
|
||||
# 验证部署
|
||||
echo "验证部署..."
|
||||
curl -I http://localhost:8080
|
||||
|
||||
echo "部署完成!项目已启动在 8080 端口"
|
||||
|
||||
# 显示容器日志
|
||||
docker compose logs frontend
|
||||
|
||||
# 进入容器检查文件
|
||||
docker exec frontend ls -la /usr/share/nginx/html
|
||||
|
||||
# 检查 nginx 配置
|
||||
docker exec frontend nginx -t
|
||||
|
||||
# 查看 nginx 日志
|
||||
docker exec frontend cat /var/log/nginx/error.log
|
||||
@@ -1,18 +0,0 @@
|
||||
version: '3'
|
||||
services:
|
||||
frontend:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: frontend
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
restart: always
|
||||
networks:
|
||||
- app-network
|
||||
|
||||
networks:
|
||||
app-network:
|
||||
driver: bridge
|
||||
@@ -1 +0,0 @@
|
||||
npm install
|
||||
@@ -1,9 +0,0 @@
|
||||
module.exports = {
|
||||
testURL: 'http://localhost:8000',
|
||||
verbose: false,
|
||||
extraSetupFiles: ['./tests/setupTests.js'],
|
||||
globals: {
|
||||
ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false,
|
||||
localStorage: null,
|
||||
},
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
import { Request, Response } from 'express';
|
||||
import moment from 'moment';
|
||||
import { parse } from 'url';
|
||||
|
||||
// mock tableListDataSource
|
||||
const genList = (current: number, pageSize: number) => {
|
||||
const tableListDataSource: API.RuleListItem[] = [];
|
||||
|
||||
for (let i = 0; i < pageSize; i += 1) {
|
||||
const index = (current - 1) * 10 + i;
|
||||
tableListDataSource.push({
|
||||
key: index,
|
||||
disabled: i % 6 === 0,
|
||||
href: 'https://ant.design',
|
||||
avatar: [
|
||||
'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
|
||||
'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
|
||||
][i % 2],
|
||||
name: `TradeCode ${index}`,
|
||||
owner: '曲丽丽',
|
||||
desc: '这是一段描述',
|
||||
callNo: Math.floor(Math.random() * 1000),
|
||||
status: Math.floor(Math.random() * 10) % 4,
|
||||
updatedAt: moment().format('YYYY-MM-DD'),
|
||||
createdAt: moment().format('YYYY-MM-DD'),
|
||||
progress: Math.ceil(Math.random() * 100),
|
||||
});
|
||||
}
|
||||
tableListDataSource.reverse();
|
||||
return tableListDataSource;
|
||||
};
|
||||
|
||||
let tableListDataSource = genList(1, 100);
|
||||
|
||||
function getRule(req: Request, res: Response, u: string) {
|
||||
let realUrl = u;
|
||||
if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') {
|
||||
realUrl = req.url;
|
||||
}
|
||||
const { current = 1, pageSize = 10 } = req.query;
|
||||
const params = parse(realUrl, true).query as unknown as API.PageParams &
|
||||
API.RuleListItem & {
|
||||
sorter: any;
|
||||
filter: any;
|
||||
};
|
||||
|
||||
let dataSource = [...tableListDataSource].slice(
|
||||
((current as number) - 1) * (pageSize as number),
|
||||
(current as number) * (pageSize as number),
|
||||
);
|
||||
if (params.sorter) {
|
||||
const sorter = JSON.parse(params.sorter);
|
||||
dataSource = dataSource.sort((prev, next) => {
|
||||
let sortNumber = 0;
|
||||
Object.keys(sorter).forEach((key) => {
|
||||
if (sorter[key] === 'descend') {
|
||||
if (prev[key] - next[key] > 0) {
|
||||
sortNumber += -1;
|
||||
} else {
|
||||
sortNumber += 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (prev[key] - next[key] > 0) {
|
||||
sortNumber += 1;
|
||||
} else {
|
||||
sortNumber += -1;
|
||||
}
|
||||
});
|
||||
return sortNumber;
|
||||
});
|
||||
}
|
||||
if (params.filter) {
|
||||
const filter = JSON.parse(params.filter as any) as {
|
||||
[key: string]: string[];
|
||||
};
|
||||
if (Object.keys(filter).length > 0) {
|
||||
dataSource = dataSource.filter((item) => {
|
||||
return Object.keys(filter).some((key) => {
|
||||
if (!filter[key]) {
|
||||
return true;
|
||||
}
|
||||
if (filter[key].includes(`${item[key]}`)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (params.name) {
|
||||
dataSource = dataSource.filter((data) => data?.name?.includes(params.name || ''));
|
||||
}
|
||||
const result = {
|
||||
data: dataSource,
|
||||
total: tableListDataSource.length,
|
||||
success: true,
|
||||
pageSize,
|
||||
current: parseInt(`${params.current}`, 10) || 1,
|
||||
};
|
||||
|
||||
return res.json(result);
|
||||
}
|
||||
|
||||
function postRule(req: Request, res: Response, u: string, b: Request) {
|
||||
let realUrl = u;
|
||||
if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') {
|
||||
realUrl = req.url;
|
||||
}
|
||||
|
||||
const body = (b && b.body) || req.body;
|
||||
const { method, name, desc, key } = body;
|
||||
|
||||
switch (method) {
|
||||
/* eslint no-case-declarations:0 */
|
||||
case 'delete':
|
||||
tableListDataSource = tableListDataSource.filter((item) => key.indexOf(item.key) === -1);
|
||||
break;
|
||||
case 'post':
|
||||
(() => {
|
||||
const i = Math.ceil(Math.random() * 10000);
|
||||
const newRule: API.RuleListItem = {
|
||||
key: tableListDataSource.length,
|
||||
href: 'https://ant.design',
|
||||
avatar: [
|
||||
'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
|
||||
'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
|
||||
][i % 2],
|
||||
name,
|
||||
owner: '曲丽丽',
|
||||
desc,
|
||||
callNo: Math.floor(Math.random() * 1000),
|
||||
status: Math.floor(Math.random() * 10) % 2,
|
||||
updatedAt: moment().format('YYYY-MM-DD'),
|
||||
createdAt: moment().format('YYYY-MM-DD'),
|
||||
progress: Math.ceil(Math.random() * 100),
|
||||
};
|
||||
tableListDataSource.unshift(newRule);
|
||||
return res.json(newRule);
|
||||
})();
|
||||
return;
|
||||
|
||||
case 'update':
|
||||
(() => {
|
||||
let newRule = {};
|
||||
tableListDataSource = tableListDataSource.map((item) => {
|
||||
if (item.key === key) {
|
||||
newRule = { ...item, desc, name };
|
||||
return { ...item, desc, name };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
return res.json(newRule);
|
||||
})();
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const result = {
|
||||
list: tableListDataSource,
|
||||
pagination: {
|
||||
total: tableListDataSource.length,
|
||||
},
|
||||
};
|
||||
|
||||
res.json(result);
|
||||
}
|
||||
|
||||
export default {
|
||||
'GET /api/rule': getRule,
|
||||
'POST /api/rule': postRule,
|
||||
};
|
||||
@@ -1,107 +0,0 @@
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
const getNotices = (req: Request, res: Response) => {
|
||||
res.json({
|
||||
data: [
|
||||
{
|
||||
id: '000000001',
|
||||
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png',
|
||||
title: '你收到了 14 份新周报',
|
||||
datetime: '2017-08-09',
|
||||
type: 'notification',
|
||||
},
|
||||
{
|
||||
id: '000000002',
|
||||
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/OKJXDXrmkNshAMvwtvhu.png',
|
||||
title: '你推荐的 曲妮妮 已通过第三轮面试',
|
||||
datetime: '2017-08-08',
|
||||
type: 'notification',
|
||||
},
|
||||
{
|
||||
id: '000000003',
|
||||
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/kISTdvpyTAhtGxpovNWd.png',
|
||||
title: '这种模板可以区分多种通知类型',
|
||||
datetime: '2017-08-07',
|
||||
read: true,
|
||||
type: 'notification',
|
||||
},
|
||||
{
|
||||
id: '000000004',
|
||||
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/GvqBnKhFgObvnSGkDsje.png',
|
||||
title: '左侧图标用于区分不同的类型',
|
||||
datetime: '2017-08-07',
|
||||
type: 'notification',
|
||||
},
|
||||
{
|
||||
id: '000000005',
|
||||
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png',
|
||||
title: '内容不要超过两行字,超出时自动截断',
|
||||
datetime: '2017-08-07',
|
||||
type: 'notification',
|
||||
},
|
||||
{
|
||||
id: '000000006',
|
||||
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
|
||||
title: '曲丽丽 评论了你',
|
||||
description: '描述信息描述信息描述信息',
|
||||
datetime: '2017-08-07',
|
||||
type: 'message',
|
||||
clickClose: true,
|
||||
},
|
||||
{
|
||||
id: '000000007',
|
||||
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
|
||||
title: '朱偏右 回复了你',
|
||||
description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像',
|
||||
datetime: '2017-08-07',
|
||||
type: 'message',
|
||||
clickClose: true,
|
||||
},
|
||||
{
|
||||
id: '000000008',
|
||||
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
|
||||
title: '标题',
|
||||
description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像',
|
||||
datetime: '2017-08-07',
|
||||
type: 'message',
|
||||
clickClose: true,
|
||||
},
|
||||
{
|
||||
id: '000000009',
|
||||
title: '任务名称',
|
||||
description: '任务需要在 2017-01-12 20:00 前启动',
|
||||
extra: '未开始',
|
||||
status: 'todo',
|
||||
type: 'event',
|
||||
},
|
||||
{
|
||||
id: '000000010',
|
||||
title: '第三方紧急代码变更',
|
||||
description: '冠霖提交于 2017-01-06,需在 2017-01-07 前完成代码变更任务',
|
||||
extra: '马上到期',
|
||||
status: 'urgent',
|
||||
type: 'event',
|
||||
},
|
||||
{
|
||||
id: '000000011',
|
||||
title: '信息安全考试',
|
||||
description: '指派竹尔于 2017-01-09 前完成更新并发布',
|
||||
extra: '已耗时 8 天',
|
||||
status: 'doing',
|
||||
type: 'event',
|
||||
},
|
||||
{
|
||||
id: '000000012',
|
||||
title: 'ABCD 版本发布',
|
||||
description: '冠霖提交于 2017-01-06,需在 2017-01-07 前完成代码变更任务',
|
||||
extra: '进行中',
|
||||
status: 'processing',
|
||||
type: 'event',
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
export default {
|
||||
'GET /api/notices': getNotices,
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
export default {
|
||||
'/api/auth_routes': {
|
||||
'/form/advanced-form': { authority: ['admin', 'user'] },
|
||||
},
|
||||
};
|
||||
@@ -1,203 +0,0 @@
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
const waitTime = (time: number = 100) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(true);
|
||||
}, time);
|
||||
});
|
||||
};
|
||||
|
||||
async function getFakeCaptcha(req: Request, res: Response) {
|
||||
await waitTime(2000);
|
||||
return res.json('captcha-xxx');
|
||||
}
|
||||
|
||||
const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION } = process.env;
|
||||
|
||||
/**
|
||||
* 当前用户的权限,如果为空代表没登录
|
||||
* current user access, if is '', user need login
|
||||
* 如果是 pro 的预览,默认是有权限的
|
||||
*/
|
||||
let access = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site' ? 'admin' : '';
|
||||
|
||||
const getAccess = () => {
|
||||
return access;
|
||||
};
|
||||
|
||||
// 代码中会兼容本地 service mock 以及部署站点的静态数据
|
||||
export default {
|
||||
// 支持值为 Object 和 Array
|
||||
'GET /api/currentUser': (req: Request, res: Response) => {
|
||||
if (!getAccess()) {
|
||||
res.status(401).send({
|
||||
data: {
|
||||
isLogin: false,
|
||||
},
|
||||
errorCode: '401',
|
||||
errorMessage: '请先登录!',
|
||||
success: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
res.send({
|
||||
success: true,
|
||||
data: {
|
||||
name: 'Serati Ma',
|
||||
avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
|
||||
userid: '00000001',
|
||||
email: 'antdesign@alipay.com',
|
||||
signature: '海纳百川,有容乃大',
|
||||
title: '交互专家',
|
||||
group: '蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED',
|
||||
tags: [
|
||||
{
|
||||
key: '0',
|
||||
label: '很有想法的',
|
||||
},
|
||||
{
|
||||
key: '1',
|
||||
label: '专注设计',
|
||||
},
|
||||
{
|
||||
key: '2',
|
||||
label: '辣~',
|
||||
},
|
||||
{
|
||||
key: '3',
|
||||
label: '大长腿',
|
||||
},
|
||||
{
|
||||
key: '4',
|
||||
label: '川妹子',
|
||||
},
|
||||
{
|
||||
key: '5',
|
||||
label: '海纳百川',
|
||||
},
|
||||
],
|
||||
notifyCount: 12,
|
||||
unreadCount: 11,
|
||||
country: 'China',
|
||||
access: getAccess(),
|
||||
geographic: {
|
||||
province: {
|
||||
label: '浙江省',
|
||||
key: '330000',
|
||||
},
|
||||
city: {
|
||||
label: '杭州市',
|
||||
key: '330100',
|
||||
},
|
||||
},
|
||||
address: '西湖区工专路 77 号',
|
||||
phone: '0752-268888888',
|
||||
},
|
||||
});
|
||||
},
|
||||
// GET POST 可省略
|
||||
'GET /api/users': [
|
||||
{
|
||||
key: '1',
|
||||
name: 'John Brown',
|
||||
age: 32,
|
||||
address: 'New York No. 1 Lake Park',
|
||||
},
|
||||
{
|
||||
key: '2',
|
||||
name: 'Jim Green',
|
||||
age: 42,
|
||||
address: 'London No. 1 Lake Park',
|
||||
},
|
||||
{
|
||||
key: '3',
|
||||
name: 'Joe Black',
|
||||
age: 32,
|
||||
address: 'Sidney No. 1 Lake Park',
|
||||
},
|
||||
],
|
||||
'POST /api/login/account': async (req: Request, res: Response) => {
|
||||
const { password, username, type } = req.body;
|
||||
await waitTime(2000);
|
||||
if (password === 'ant.design' && username === 'admin') {
|
||||
res.send({
|
||||
status: 'ok',
|
||||
type,
|
||||
currentAuthority: 'admin',
|
||||
});
|
||||
access = 'admin';
|
||||
return;
|
||||
}
|
||||
if (password === 'ant.design' && username === 'user') {
|
||||
res.send({
|
||||
status: 'ok',
|
||||
type,
|
||||
currentAuthority: 'user',
|
||||
});
|
||||
access = 'user';
|
||||
return;
|
||||
}
|
||||
if (type === 'mobile') {
|
||||
res.send({
|
||||
status: 'ok',
|
||||
type,
|
||||
currentAuthority: 'admin',
|
||||
});
|
||||
access = 'admin';
|
||||
return;
|
||||
}
|
||||
|
||||
res.send({
|
||||
status: 'error',
|
||||
type,
|
||||
currentAuthority: 'guest',
|
||||
});
|
||||
access = 'guest';
|
||||
},
|
||||
'POST /api/login/outLogin': (req: Request, res: Response) => {
|
||||
access = '';
|
||||
res.send({ data: {}, success: true });
|
||||
},
|
||||
'POST /api/register': (req: Request, res: Response) => {
|
||||
res.send({ status: 'ok', currentAuthority: 'user', success: true });
|
||||
},
|
||||
'GET /api/500': (req: Request, res: Response) => {
|
||||
res.status(500).send({
|
||||
timestamp: 1513932555104,
|
||||
status: 500,
|
||||
error: 'error',
|
||||
message: 'error',
|
||||
path: '/base/category/list',
|
||||
});
|
||||
},
|
||||
'GET /api/404': (req: Request, res: Response) => {
|
||||
res.status(404).send({
|
||||
timestamp: 1513932643431,
|
||||
status: 404,
|
||||
error: 'Not Found',
|
||||
message: 'No message available',
|
||||
path: '/base/category/list/2121212',
|
||||
});
|
||||
},
|
||||
'GET /api/403': (req: Request, res: Response) => {
|
||||
res.status(403).send({
|
||||
timestamp: 1513932555104,
|
||||
status: 403,
|
||||
error: 'Forbidden',
|
||||
message: 'Forbidden',
|
||||
path: '/base/category/list',
|
||||
});
|
||||
},
|
||||
'GET /api/401': (req: Request, res: Response) => {
|
||||
res.status(401).send({
|
||||
timestamp: 1513932555104,
|
||||
status: 401,
|
||||
error: 'Unauthorized',
|
||||
message: 'Unauthorized',
|
||||
path: '/base/category/list',
|
||||
});
|
||||
},
|
||||
|
||||
'GET /api/login/captcha': getFakeCaptcha,
|
||||
};
|
||||
@@ -1,122 +0,0 @@
|
||||
server {
|
||||
listen 8080;
|
||||
server_name localhost;
|
||||
|
||||
# gzip 配置
|
||||
gzip on;
|
||||
gzip_min_length 1k;
|
||||
gzip_comp_level 6;
|
||||
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
|
||||
root /usr/share/nginx/html/react-web;
|
||||
index index.html;
|
||||
|
||||
# 支持 history 路由
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
|
||||
# 添加必要的跨域和缓存控制头
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
# 调整缓存策略,例如对于静态资源可以缓存
|
||||
location ~* \.(css|js|svg|png|jpg|jpeg)$ {
|
||||
expires 365d;
|
||||
}
|
||||
|
||||
# 添加安全相关头
|
||||
add_header X-Frame-Options SAMEORIGIN;
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
}
|
||||
|
||||
# API-UAA 服务代理
|
||||
location /api-uaa/ {
|
||||
proxy_pass http://119.45.169.13:9900/api-uaa/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
# 确保 Authorization 头可以传递
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
proxy_pass_header Authorization;
|
||||
|
||||
# 处理 OPTIONS 请求
|
||||
if ($request_method = 'OPTIONS') {
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
|
||||
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
|
||||
return 204;
|
||||
}
|
||||
}
|
||||
|
||||
# 用户服务代理
|
||||
location /api-user/ {
|
||||
proxy_pass http://119.45.169.13:9900/api-user/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
# 确保 Authorization 头可以传递
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
proxy_pass_header Authorization;
|
||||
|
||||
# 处理 OPTIONS 请求
|
||||
if ($request_method = 'OPTIONS') {
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
|
||||
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
|
||||
return 204;
|
||||
}
|
||||
}
|
||||
|
||||
# 其他 API 服务代理(如果需要)
|
||||
location /api/ {
|
||||
proxy_pass http://119.45.169.13:9900/; # 替换为实际的后端地址
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
# 添加跨域头
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
|
||||
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
|
||||
|
||||
# 处理 OPTIONS 请求
|
||||
if ($request_method = 'OPTIONS') {
|
||||
return 204;
|
||||
}
|
||||
}
|
||||
|
||||
# API 代理配置
|
||||
location /api-order/ {
|
||||
proxy_pass http://119.45.169.13:9900/api-order/; # 替换为您的后端API地址
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
# 处理 OPTIONS 请求
|
||||
if ($request_method = 'OPTIONS') {
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
|
||||
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
|
||||
return 204;
|
||||
}
|
||||
}
|
||||
|
||||
# API 代理配置
|
||||
location /api-device/ {
|
||||
proxy_pass http://119.45.169.13:9900/api-device/; # 替换为您的后端API地址
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
# 处理 OPTIONS 请求
|
||||
if ($request_method = 'OPTIONS') {
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
|
||||
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
|
||||
return 204;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
{
|
||||
"name": "zlt-web",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"analyze": "cross-env ANALYZE=1 umi build",
|
||||
"build": "set NODE_OPTIONS=--openssl-legacy-provider && umi build",
|
||||
"deploy": "npm run build && npm run gh-pages",
|
||||
"dev": "npm run start:dev",
|
||||
"gh-pages": "gh-pages -d dist",
|
||||
"i18n-remove": "pro i18n-remove --locale=zh-CN --write",
|
||||
"postinstall": "umi g tmp",
|
||||
"lint": "umi g tmp && npm run lint:js && npm run lint:style && npm run lint:prettier && npm run tsc",
|
||||
"lint-staged": "lint-staged",
|
||||
"lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ",
|
||||
"lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src && npm run lint:style",
|
||||
"lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
|
||||
"lint:prettier": "prettier -c --write \"src/**/*\" --end-of-line auto",
|
||||
"lint:style": "stylelint --fix \"src/**/*.less\" --syntax less",
|
||||
"openapi": "umi openapi",
|
||||
"playwright": "playwright install && playwright test",
|
||||
"prettier": "prettier -c --write \"src/**/*\"",
|
||||
"serve": "umi-serve",
|
||||
"start": "set NODE_OPTIONS=--openssl-legacy-provider && cross-env UMI_ENV=dev umi dev --port=8066",
|
||||
"start:dev": "set NODE_OPTIONS=--openssl-legacy-provider && cross-env REACT_APP_ENV=dev MOCK=none UMI_ENV=dev umi dev",
|
||||
"start:no-mock": "cross-env MOCK=none UMI_ENV=dev umi dev",
|
||||
"start:no-ui": "cross-env UMI_UI=none UMI_ENV=dev umi dev",
|
||||
"start:pre": "cross-env REACT_APP_ENV=pre UMI_ENV=dev umi dev",
|
||||
"start:test": "cross-env REACT_APP_ENV=test MOCK=none UMI_ENV=dev umi dev",
|
||||
"test": "umi test",
|
||||
"test:component": "umi test ./src/components",
|
||||
"test:e2e": "node ./tests/run-tests.js",
|
||||
"tsc": "tsc --noEmit"
|
||||
},
|
||||
"lint-staged": {
|
||||
"**/*.less": "stylelint --syntax less",
|
||||
"**/*.{js,jsx,ts,tsx}": "npm run lint-staged:js",
|
||||
"**/*.{js,jsx,tsx,ts,less,md,json}": [
|
||||
"prettier --write"
|
||||
]
|
||||
},
|
||||
"browserslist": [
|
||||
"> 1%",
|
||||
"last 2 versions",
|
||||
"not ie <= 10"
|
||||
],
|
||||
"dependencies": {
|
||||
"@amap/amap-react": "^0.1.5",
|
||||
"@ant-design/charts": "^1.4.2",
|
||||
"@ant-design/icons": "^4.7.0",
|
||||
"@ant-design/pro-components": "1.1.1",
|
||||
"@babel/runtime": "^7.27.0",
|
||||
"@types/file-saver": "^2.0.7",
|
||||
"@types/styled-components": "^5.1.34",
|
||||
"@umijs/route-utils": "^2.0.0",
|
||||
"antd": "^4.20.0",
|
||||
"classnames": "^2.3.0",
|
||||
"echarts": "^5.6.0",
|
||||
"echarts-for-react": "^3.0.2",
|
||||
"file-saver": "^2.0.5",
|
||||
"lodash": "^4.17.21",
|
||||
"moment": "^2.29.0",
|
||||
"omit.js": "^2.0.2",
|
||||
"rc-menu": "^9.1.0",
|
||||
"rc-resize-observer": "^1.2.0",
|
||||
"rc-util": "^5.16.0",
|
||||
"react": "^17.0.0",
|
||||
"react-dev-inspector": "^1.7.0",
|
||||
"react-dom": "^17.0.0",
|
||||
"react-helmet-async": "^1.2.0",
|
||||
"react-intl": "6.4.4",
|
||||
"react-json-tree": "^0.17.0",
|
||||
"react-player": "^2.16.0",
|
||||
"spark-md5": "^3.0.2",
|
||||
"styled-components": "^6.1.18",
|
||||
"treeify-js": "^1.0.8",
|
||||
"umi": "^3.5.0",
|
||||
"uuid": "^9.0.0",
|
||||
"xlsx": "^0.18.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ant-design/pro-cli": "^2.1.0",
|
||||
"@playwright/test": "^1.17.0",
|
||||
"@types/classnames": "^2.3.1",
|
||||
"@types/express": "^4.17.0",
|
||||
"@types/history": "^4.7.0",
|
||||
"@types/jest": "^26.0.0",
|
||||
"@types/lodash": "^4.14.0",
|
||||
"@types/react": "^17.0.0",
|
||||
"@types/react-dom": "^17.0.0",
|
||||
"@types/react-helmet": "^6.1.0",
|
||||
"@types/uuid": "^8.3.4",
|
||||
"@umijs/fabric": "^2.11.1",
|
||||
"@umijs/openapi": "^1.6.0",
|
||||
"@umijs/plugin-blocks": "^2.2.0",
|
||||
"@umijs/plugin-esbuild": "^1.4.0",
|
||||
"@umijs/plugin-openapi": "^1.3.3",
|
||||
"@umijs/preset-ant-design-pro": "^1.3.0",
|
||||
"@umijs/preset-dumi": "^1.1.0",
|
||||
"@umijs/preset-react": "^2.1.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"cross-port-killer": "^1.3.0",
|
||||
"detect-installer": "^1.0.0",
|
||||
"eslint": "^7.32.0",
|
||||
"gh-pages": "^3.2.0",
|
||||
"jsdom-global": "^3.0.0",
|
||||
"lint-staged": "^10.0.0",
|
||||
"mockjs": "^1.1.0",
|
||||
"prettier": "^2.5.0",
|
||||
"stylelint": "^13.0.0",
|
||||
"swagger-ui-dist": "^4.12.0",
|
||||
"typescript": "^4.5.0",
|
||||
"umi-serve": "^1.9.10"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
// playwright.config.ts
|
||||
import type { PlaywrightTestConfig } from '@playwright/test';
|
||||
import { devices } from '@playwright/test';
|
||||
|
||||
const config: PlaywrightTestConfig = {
|
||||
forbidOnly: !!process.env.CI,
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
use: {
|
||||
trace: 'on-first-retry',
|
||||
},
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
{
|
||||
name: 'firefox',
|
||||
use: { ...devices['Desktop Firefox'] },
|
||||
},
|
||||
],
|
||||
};
|
||||
export default config;
|
||||
@@ -1 +0,0 @@
|
||||
preview.pro.ant.design
|
||||
@@ -1 +0,0 @@
|
||||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1664604355459" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6163" width="128" height="128" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M832 64H192c-70.4 0-128 57.6-128 128v640c0 70.4 57.6 128 128 128h640c70.4 0 128-57.6 128-128V192c0-70.4-57.6-128-128-128z m-32 447.8H320v320h-64v-640h544l-161.3 160 161.3 160z" fill="#92d050" p-id="6164"></path></svg>
|
||||
|
Before Width: | Height: | Size: 550 B |
|
Before Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 3.6 KiB |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200" version="1.1" viewBox="0 0 200 200"><title>Group 28 Copy 5</title><desc>Created with Sketch.</desc><defs><linearGradient id="linearGradient-1" x1="62.102%" x2="108.197%" y1="0%" y2="37.864%"><stop offset="0%" stop-color="#4285EB"/><stop offset="100%" stop-color="#2EC7FF"/></linearGradient><linearGradient id="linearGradient-2" x1="69.644%" x2="54.043%" y1="0%" y2="108.457%"><stop offset="0%" stop-color="#29CDFF"/><stop offset="37.86%" stop-color="#148EFF"/><stop offset="100%" stop-color="#0A60FF"/></linearGradient><linearGradient id="linearGradient-3" x1="69.691%" x2="16.723%" y1="-12.974%" y2="117.391%"><stop offset="0%" stop-color="#FA816E"/><stop offset="41.473%" stop-color="#F74A5C"/><stop offset="100%" stop-color="#F51D2C"/></linearGradient><linearGradient id="linearGradient-4" x1="68.128%" x2="30.44%" y1="-35.691%" y2="114.943%"><stop offset="0%" stop-color="#FA8E7D"/><stop offset="51.264%" stop-color="#F74A5C"/><stop offset="100%" stop-color="#F51D2C"/></linearGradient></defs><g id="Page-1" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><g id="logo" transform="translate(-20.000000, -20.000000)"><g id="Group-28-Copy-5" transform="translate(20.000000, 20.000000)"><g id="Group-27-Copy-3"><g id="Group-25" fill-rule="nonzero"><g id="2"><path id="Shape" fill="url(#linearGradient-1)" d="M91.5880863,4.17652823 L4.17996544,91.5127728 C-0.519240605,96.2081146 -0.519240605,103.791885 4.17996544,108.487227 L91.5880863,195.823472 C96.2872923,200.518814 103.877304,200.518814 108.57651,195.823472 L145.225487,159.204632 C149.433969,154.999611 149.433969,148.181924 145.225487,143.976903 C141.017005,139.771881 134.193707,139.771881 129.985225,143.976903 L102.20193,171.737352 C101.032305,172.906015 99.2571609,172.906015 98.0875359,171.737352 L28.285908,101.993122 C27.1162831,100.824459 27.1162831,99.050775 28.285908,97.8821118 L98.0875359,28.1378823 C99.2571609,26.9692191 101.032305,26.9692191 102.20193,28.1378823 L129.985225,55.8983314 C134.193707,60.1033528 141.017005,60.1033528 145.225487,55.8983314 C149.433969,51.69331 149.433969,44.8756232 145.225487,40.6706018 L108.58055,4.05574592 C103.862049,-0.537986846 96.2692618,-0.500797906 91.5880863,4.17652823 Z"/><path id="Shape" fill="url(#linearGradient-2)" d="M91.5880863,4.17652823 L4.17996544,91.5127728 C-0.519240605,96.2081146 -0.519240605,103.791885 4.17996544,108.487227 L91.5880863,195.823472 C96.2872923,200.518814 103.877304,200.518814 108.57651,195.823472 L145.225487,159.204632 C149.433969,154.999611 149.433969,148.181924 145.225487,143.976903 C141.017005,139.771881 134.193707,139.771881 129.985225,143.976903 L102.20193,171.737352 C101.032305,172.906015 99.2571609,172.906015 98.0875359,171.737352 L28.285908,101.993122 C27.1162831,100.824459 27.1162831,99.050775 28.285908,97.8821118 L98.0875359,28.1378823 C100.999864,25.6271836 105.751642,20.541824 112.729652,19.3524487 C117.915585,18.4685261 123.585219,20.4140239 129.738554,25.1889424 C125.624663,21.0784292 118.571995,14.0340304 108.58055,4.05574592 C103.862049,-0.537986846 96.2692618,-0.500797906 91.5880863,4.17652823 Z"/></g><path id="Shape" fill="url(#linearGradient-3)" d="M153.685633,135.854579 C157.894115,140.0596 164.717412,140.0596 168.925894,135.854579 L195.959977,108.842726 C200.659183,104.147384 200.659183,96.5636133 195.960527,91.8688194 L168.690777,64.7181159 C164.472332,60.5180858 157.646868,60.5241425 153.435895,64.7316526 C149.227413,68.936674 149.227413,75.7543607 153.435895,79.9593821 L171.854035,98.3623765 C173.02366,99.5310396 173.02366,101.304724 171.854035,102.473387 L153.685633,120.626849 C149.47715,124.83187 149.47715,131.649557 153.685633,135.854579 Z"/></g><ellipse id="Combined-Shape" cx="100.519" cy="100.437" fill="url(#linearGradient-4)" rx="23.6" ry="23.581"/></g></g></g></g></svg>
|
||||
|
Before Width: | Height: | Size: 3.8 KiB |
@@ -1,5 +0,0 @@
|
||||
<svg width="42" height="42" xmlns="http://www.w3.org/2000/svg">
|
||||
<g>
|
||||
<path fill="#070707" d="m6.717392,13.773912l5.6,0c2.8,0 4.7,1.9 4.7,4.7c0,2.8 -2,4.7 -4.9,4.7l-2.5,0l0,4.3l-2.9,0l0,-13.7zm2.9,2.2l0,4.9l1.9,0c1.6,0 2.6,-0.9 2.6,-2.4c0,-1.6 -0.9,-2.4 -2.6,-2.4l-1.9,0l0,-0.1zm8.9,11.5l2.7,0l0,-5.7c0,-1.4 0.8,-2.3 2.2,-2.3c0.4,0 0.8,0.1 1,0.2l0,-2.4c-0.2,-0.1 -0.5,-0.1 -0.8,-0.1c-1.2,0 -2.1,0.7 -2.4,2l-0.1,0l0,-1.9l-2.7,0l0,10.2l0.1,0zm11.7,0.1c-3.1,0 -5,-2 -5,-5.3c0,-3.3 2,-5.3 5,-5.3s5,2 5,5.3c0,3.4 -1.9,5.3 -5,5.3zm0,-2.1c1.4,0 2.2,-1.1 2.2,-3.2c0,-2 -0.8,-3.2 -2.2,-3.2c-1.4,0 -2.2,1.2 -2.2,3.2c0,2.1 0.8,3.2 2.2,3.2z" class="st0" id="Ant-Design-Pro"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 677 B |
@@ -1,9 +0,0 @@
|
||||
/**
|
||||
* @see https://umijs.org/zh-CN/plugins/plugin-access
|
||||
* */
|
||||
export default function access(initialState: { currentUser?: API.CurrentUser } | undefined) {
|
||||
const { currentUser } = initialState ?? {};
|
||||
return {
|
||||
canAdmin: currentUser ,
|
||||
};
|
||||
}
|
||||
@@ -1,316 +0,0 @@
|
||||
import Footer from '@/components/Footer';
|
||||
import RightContent from '@/components/RightContent';
|
||||
import {
|
||||
AppstoreOutlined,
|
||||
MenuOutlined,
|
||||
TeamOutlined,
|
||||
SettingOutlined,
|
||||
UserOutlined,
|
||||
CaretDownFilled,
|
||||
CrownOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import type { MenuDataItem, Settings as LayoutSettings } from '@ant-design/pro-components';
|
||||
import { PageLoading, SettingDrawer } from '@ant-design/pro-components';
|
||||
import { Divider, Dropdown, Menu, Space } from 'antd';
|
||||
import type { RequestConfig, RunTimeLayoutConfig } from 'umi';
|
||||
import { history } from 'umi';
|
||||
import defaultSettings from '../config/defaultSettings';
|
||||
import { currentUser as queryCurrentUser, fetchMenuData } from './services/login/api';
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
const loginPath = '/user/login';
|
||||
|
||||
/** 获取用户信息比较慢的时候会展示一个 loading */
|
||||
export const initialStateConfig = {
|
||||
loading: <PageLoading />,
|
||||
};
|
||||
|
||||
/**
|
||||
* @see https://umijs.org/zh-CN/plugins/plugin-initial-state
|
||||
* */
|
||||
export async function getInitialState(): Promise<{
|
||||
settings?: Partial<LayoutSettings>;
|
||||
currentUser?: API.CurrentUser;
|
||||
loading?: boolean;
|
||||
fetchUserInfo?: () => Promise<API.CurrentUser | undefined>;
|
||||
}> {
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const msg = await queryCurrentUser();
|
||||
// TODO
|
||||
return msg.data;
|
||||
} catch (error) {
|
||||
history.push(loginPath);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
// 如果不是登录页面,执行
|
||||
if (history.location.pathname !== loginPath) {
|
||||
const currentUser = await fetchUserInfo();
|
||||
return {
|
||||
fetchUserInfo,
|
||||
currentUser,
|
||||
settings: defaultSettings,
|
||||
};
|
||||
}
|
||||
return {
|
||||
fetchUserInfo,
|
||||
settings: defaultSettings,
|
||||
};
|
||||
}
|
||||
|
||||
// ProLayout 支持的api https://procomponents.ant.design/components/layout
|
||||
export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
|
||||
return {
|
||||
rightContentRender: () => <RightContent />,
|
||||
disableContentMargin: false,
|
||||
waterMarkProps: {
|
||||
content: initialState?.currentUser?.username,
|
||||
},
|
||||
footerRender: () => <Footer />,
|
||||
onPageChange: () => {
|
||||
const { location } = history;
|
||||
// 如果没有登录,重定向到 login
|
||||
if (!initialState?.currentUser && location.pathname !== loginPath) {
|
||||
history.push(loginPath);
|
||||
}
|
||||
},
|
||||
links: isDev
|
||||
? [
|
||||
// <Link key="openapi" to="/umi/plugin/openapi" target="_blank">
|
||||
// <LinkOutlined />
|
||||
// <span>OpenAPI 文档</span>
|
||||
// </Link>,
|
||||
// <Link to="/~docs" key="docs">
|
||||
// <BookOutlined />
|
||||
// <span>业务组件文档</span>
|
||||
// </Link>,
|
||||
]
|
||||
: [],
|
||||
menuHeaderRender: undefined,
|
||||
|
||||
menu: {
|
||||
// 每当 initialState?.currentUser?.userid 发生修改时重新执行 request
|
||||
params: {
|
||||
userId: initialState?.currentUser?.userId,
|
||||
// 添加一个时间戳来强制重新加载菜单
|
||||
timestamp: initialState?.currentUser ? Date.now() : 0,
|
||||
},
|
||||
request: async () => {
|
||||
try {
|
||||
// initialState.currentUser 中包含了所有用户信息
|
||||
const menuData = await fetchMenuData();
|
||||
|
||||
const mapIcon = (css: string | undefined) => {
|
||||
switch (css) {
|
||||
case 'layui-icon-set':
|
||||
return <SettingOutlined />;
|
||||
case 'layui-icon-friends':
|
||||
return <UserOutlined />;
|
||||
case 'layui-icon-user':
|
||||
return <TeamOutlined />;
|
||||
case 'layui-icon-menu-fill':
|
||||
return <MenuOutlined />;
|
||||
default:
|
||||
return <AppstoreOutlined />;
|
||||
}
|
||||
};
|
||||
|
||||
const mapMenu = (value: API.Menu[]): MenuDataItem[] => {
|
||||
return value.map((item) => {
|
||||
return {
|
||||
key: item.id + '',
|
||||
name: item.name,
|
||||
locale: false,
|
||||
path:
|
||||
item.path?.endsWith('.html') || item.path?.startsWith('http')
|
||||
? item.path
|
||||
: undefined,
|
||||
icon: mapIcon(item.css),
|
||||
children: item.subMenus && mapMenu(item.subMenus),
|
||||
};
|
||||
});
|
||||
};
|
||||
const menus = mapMenu(menuData);
|
||||
return [
|
||||
{ key: 'welcome', name: '首页', path: '/welcome', icon: <CrownOutlined /> },
|
||||
...menus,
|
||||
];
|
||||
} catch (error) {
|
||||
console.error('获取菜单数据失败:', error);
|
||||
return [];
|
||||
}
|
||||
},
|
||||
},
|
||||
headerContentRender: () => {
|
||||
return (
|
||||
<Space>
|
||||
<Divider type="vertical" />
|
||||
{/* 注释掉相关链接下拉菜单
|
||||
<Dropdown
|
||||
placement="top"
|
||||
overlay={
|
||||
<Menu
|
||||
items={[
|
||||
{
|
||||
key: '1',
|
||||
label: (
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href="https://www.kancloud.cn/zlt2000/microservices-platform/936235"
|
||||
>
|
||||
项目更新日志
|
||||
</a>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: '2',
|
||||
label: (
|
||||
<a target="_blank" rel="noopener noreferrer" href="http://zlt2000.gitee.io/">
|
||||
个人博客
|
||||
</a>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: '3',
|
||||
label: (
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href="https://gitee.com/zlt2000/"
|
||||
>
|
||||
个人公众号
|
||||
</a>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: '4',
|
||||
label: (
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href="https://gitbook.cn/gitchat/author/5b2362320398d50d7b7ab29e"
|
||||
>
|
||||
GitChat
|
||||
</a>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: '5',
|
||||
label: (
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href="https://www.aliyun.com/minisite/goods?userCode=dickv1kw&share_source=copy_link"
|
||||
>
|
||||
阿里云优惠
|
||||
</a>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: '6',
|
||||
label: (
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href="https://cloud.tencent.com/act/cps/redirect?redirect=1074&cps_key=5516bbd5876cd224d90bd41d53d3f7fe&from=console"
|
||||
>
|
||||
腾讯云优惠
|
||||
</a>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: '7',
|
||||
label: (
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href="https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=a87e1945-e6c4-4e04-bb43-e0472a54e454&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905"
|
||||
>
|
||||
华为云优惠
|
||||
</a>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<a onClick={(e) => e.preventDefault()}>
|
||||
<Space size="small">
|
||||
相关链接
|
||||
<CaretDownFilled />
|
||||
</Space>
|
||||
</a>
|
||||
</Dropdown>
|
||||
*/}
|
||||
</Space>
|
||||
);
|
||||
},
|
||||
// 自定义 403 页面
|
||||
// unAccessible: <div>unAccessible</div>,
|
||||
// 增加一个 loading 的状态
|
||||
childrenRender: (children, props) => {
|
||||
if (initialState?.loading) return <PageLoading />;
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
{!props.location?.pathname?.includes('/login') && (
|
||||
<SettingDrawer
|
||||
disableUrlParams
|
||||
enableDarkTheme
|
||||
settings={initialState?.settings}
|
||||
onSettingChange={(settings) => {
|
||||
setInitialState((preInitialState) => ({
|
||||
...preInitialState,
|
||||
settings,
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
},
|
||||
...initialState?.settings,
|
||||
};
|
||||
};
|
||||
|
||||
const authHeaderInterceptor = (url: string, options: RequestConfig) => {
|
||||
const accessToken = sessionStorage.getItem('access_token');
|
||||
const authHeader = {};
|
||||
if (accessToken && !url.includes('/api-uaa/oauth/token')) {
|
||||
authHeader.Authorization = `Bearer ${accessToken}`;
|
||||
}
|
||||
const newHeaders = { ...options.headers, ...authHeader };
|
||||
return {
|
||||
url,
|
||||
options: { ...options, interceptors: true, headers: newHeaders },
|
||||
};
|
||||
};
|
||||
|
||||
const unauthorizedInterceptor = (response: Response) => {
|
||||
if (response.status === 401) {
|
||||
const { location } = history;
|
||||
// 如果没有登录,重定向到 login
|
||||
if (location.pathname !== loginPath) {
|
||||
history.push(loginPath);
|
||||
}
|
||||
}
|
||||
return response;
|
||||
};
|
||||
|
||||
export const request: RequestConfig = {
|
||||
// 新增自动添加AccessToken的请求前拦截器
|
||||
requestInterceptors: [authHeaderInterceptor],
|
||||
responseInterceptors: [unauthorizedInterceptor],
|
||||
errorConfig: {
|
||||
adaptor: (resData) => {
|
||||
return {
|
||||
...resData,
|
||||
errorMessage: '请重新登录',
|
||||
};
|
||||
},
|
||||
},
|
||||
// 生产环境使用相对路径,开发环境使用代理
|
||||
baseURL: process.env.NODE_ENV === 'production' ? '/' : undefined,
|
||||
};
|
||||
@@ -1,35 +0,0 @@
|
||||
import { GithubOutlined } from '@ant-design/icons';
|
||||
import { DefaultFooter } from '@ant-design/pro-components';
|
||||
import { useIntl } from 'umi';
|
||||
|
||||
const Footer: React.FC = () => {
|
||||
const intl = useIntl();
|
||||
const defaultMessage = intl.formatMessage({
|
||||
id: 'app.copyright.produced',
|
||||
defaultMessage: '版权所有:https://gitee.com/L-Shilin/go-fly-platform-services.git',
|
||||
});
|
||||
|
||||
// const currentYear = new Date().getFullYear();
|
||||
|
||||
return (
|
||||
<DefaultFooter
|
||||
copyright={`${2025} ${defaultMessage}`}
|
||||
links={[
|
||||
{
|
||||
key: 'github',
|
||||
title: <GithubOutlined />,
|
||||
href: 'https://gitee.com/L-Shilin/go-fly-platform-services.git',
|
||||
blankTarget: true,
|
||||
},
|
||||
// {
|
||||
// key: 'beian',
|
||||
// title: '粤ICP备19081412号',
|
||||
// href: 'https://beian.miit.gov.cn/',
|
||||
// blankTarget: true,
|
||||
// },
|
||||
]}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default Footer;
|
||||
@@ -1,16 +0,0 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
|
||||
.container > * {
|
||||
background-color: @popover-bg;
|
||||
border-radius: 4px;
|
||||
box-shadow: @shadow-1-down;
|
||||
}
|
||||
|
||||
@media screen and (max-width: @screen-xs) {
|
||||
.container {
|
||||
width: 100% !important;
|
||||
}
|
||||
.container > * {
|
||||
border-radius: 0 !important;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Dropdown } from 'antd';
|
||||
import type { DropDownProps } from 'antd/es/dropdown';
|
||||
import classNames from 'classnames';
|
||||
import React from 'react';
|
||||
import styles from './index.less';
|
||||
|
||||
export type HeaderDropdownProps = {
|
||||
overlayClassName?: string;
|
||||
overlay: React.ReactNode | (() => React.ReactNode) | any;
|
||||
placement?: 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topCenter' | 'topRight' | 'bottomCenter';
|
||||
} & Omit<DropDownProps, 'overlay'>;
|
||||
|
||||
const HeaderDropdown: React.FC<HeaderDropdownProps> = ({ overlayClassName: cls, ...restProps }) => (
|
||||
<Dropdown overlayClassName={classNames(styles.container, cls)} {...restProps} />
|
||||
);
|
||||
|
||||
export default HeaderDropdown;
|
||||
@@ -1,25 +0,0 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
|
||||
.headerSearch {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
.input {
|
||||
width: 0;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
background: transparent;
|
||||
border-radius: 0;
|
||||
transition: width 0.3s, margin-left 0.3s;
|
||||
:global(.ant-select-selection) {
|
||||
background: transparent;
|
||||
}
|
||||
input {
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
&.show {
|
||||
width: 210px;
|
||||
margin-left: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
import { SearchOutlined } from '@ant-design/icons';
|
||||
import type { InputRef } from 'antd';
|
||||
import { AutoComplete, Input } from 'antd';
|
||||
import type { AutoCompleteProps } from 'antd/es/auto-complete';
|
||||
import classNames from 'classnames';
|
||||
import useMergedState from 'rc-util/es/hooks/useMergedState';
|
||||
import React, { useRef } from 'react';
|
||||
import styles from './index.less';
|
||||
|
||||
export type HeaderSearchProps = {
|
||||
onSearch?: (value?: string) => void;
|
||||
onChange?: (value?: string) => void;
|
||||
onVisibleChange?: (b: boolean) => void;
|
||||
className?: string;
|
||||
placeholder?: string;
|
||||
options: AutoCompleteProps['options'];
|
||||
defaultVisible?: boolean;
|
||||
visible?: boolean;
|
||||
defaultValue?: string;
|
||||
value?: string;
|
||||
};
|
||||
|
||||
const HeaderSearch: React.FC<HeaderSearchProps> = (props) => {
|
||||
const {
|
||||
className,
|
||||
defaultValue,
|
||||
onVisibleChange,
|
||||
placeholder,
|
||||
visible,
|
||||
defaultVisible,
|
||||
...restProps
|
||||
} = props;
|
||||
|
||||
const inputRef = useRef<InputRef | null>(null);
|
||||
|
||||
const [value, setValue] = useMergedState<string | undefined>(defaultValue, {
|
||||
value: props.value,
|
||||
onChange: props.onChange,
|
||||
});
|
||||
|
||||
const [searchMode, setSearchMode] = useMergedState(defaultVisible ?? false, {
|
||||
value: props.visible,
|
||||
onChange: onVisibleChange,
|
||||
});
|
||||
|
||||
const inputClass = classNames(styles.input, {
|
||||
[styles.show]: searchMode,
|
||||
});
|
||||
return (
|
||||
<div
|
||||
className={classNames(className, styles.headerSearch)}
|
||||
onClick={() => {
|
||||
setSearchMode(true);
|
||||
if (searchMode && inputRef.current) {
|
||||
inputRef.current.focus();
|
||||
}
|
||||
}}
|
||||
onTransitionEnd={({ propertyName }) => {
|
||||
if (propertyName === 'width' && !searchMode) {
|
||||
if (onVisibleChange) {
|
||||
onVisibleChange(searchMode);
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<SearchOutlined
|
||||
key="Icon"
|
||||
style={{
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
/>
|
||||
<AutoComplete
|
||||
key="AutoComplete"
|
||||
className={inputClass}
|
||||
value={value}
|
||||
options={restProps.options}
|
||||
onChange={(completeValue) => setValue(completeValue)}
|
||||
>
|
||||
<Input
|
||||
size="small"
|
||||
ref={inputRef}
|
||||
defaultValue={defaultValue}
|
||||
aria-label={placeholder}
|
||||
placeholder={placeholder}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
if (restProps.onSearch) {
|
||||
restProps.onSearch(value);
|
||||
}
|
||||
}
|
||||
}}
|
||||
onBlur={() => {
|
||||
setSearchMode(false);
|
||||
}}
|
||||
/>
|
||||
</AutoComplete>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default HeaderSearch;
|
||||
@@ -1,108 +0,0 @@
|
||||
import { outLogin } from '@/services/login/api';
|
||||
import { LogoutOutlined, UserOutlined } from '@ant-design/icons';
|
||||
import { Avatar, Menu, Spin } from 'antd';
|
||||
import type { ItemType } from 'antd/lib/menu/hooks/useItems';
|
||||
import { stringify } from 'querystring';
|
||||
import type { MenuInfo } from 'rc-menu/lib/interface';
|
||||
import React, { useCallback } from 'react';
|
||||
import { history, useModel } from 'umi';
|
||||
import HeaderDropdown from '../HeaderDropdown';
|
||||
import styles from './index.less';
|
||||
|
||||
export type GlobalHeaderRightProps = {
|
||||
menu?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* 退出登录,并且将当前的 url 保存
|
||||
*/
|
||||
const loginOut = async () => {
|
||||
await outLogin();
|
||||
const { query = {}, search, pathname } = history.location;
|
||||
const { redirect } = query;
|
||||
// Note: There may be security issues, please note
|
||||
if (window.location.pathname !== '/user/login' && !redirect) {
|
||||
history.replace({
|
||||
pathname: '/user/login',
|
||||
search: stringify({
|
||||
redirect: pathname + search,
|
||||
}),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu }) => {
|
||||
const { initialState, setInitialState } = useModel('@@initialState');
|
||||
|
||||
const onMenuClick = useCallback(
|
||||
(event: MenuInfo) => {
|
||||
const { key } = event;
|
||||
if (key === 'logout') {
|
||||
setInitialState((s) => ({ ...s, currentUser: undefined }));
|
||||
loginOut();
|
||||
return;
|
||||
} else if (key === 'center') {
|
||||
history.push('/system/myInfo.html');
|
||||
}
|
||||
},
|
||||
[setInitialState],
|
||||
);
|
||||
|
||||
const loading = (
|
||||
<span className={`${styles.action} ${styles.account}`}>
|
||||
<Spin
|
||||
size="small"
|
||||
style={{
|
||||
marginLeft: 8,
|
||||
marginRight: 8,
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
);
|
||||
|
||||
if (!initialState) {
|
||||
return loading;
|
||||
}
|
||||
|
||||
const { currentUser } = initialState;
|
||||
|
||||
if (!currentUser || !currentUser.nickname) {
|
||||
return loading;
|
||||
}
|
||||
|
||||
const menuItems: ItemType[] = [
|
||||
...(menu
|
||||
? [
|
||||
{
|
||||
key: 'center',
|
||||
icon: <UserOutlined />,
|
||||
label: '个人中心',
|
||||
},
|
||||
{
|
||||
type: 'divider' as const,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
|
||||
{
|
||||
key: 'logout',
|
||||
icon: <LogoutOutlined />,
|
||||
label: '退出登录',
|
||||
},
|
||||
];
|
||||
|
||||
const menuHeaderDropdown = (
|
||||
<Menu className={styles.menu} selectedKeys={[]} onClick={onMenuClick} items={menuItems} />
|
||||
);
|
||||
|
||||
return (
|
||||
<HeaderDropdown overlay={menuHeaderDropdown}>
|
||||
<span className={`${styles.action} ${styles.account}`}>
|
||||
<Avatar size="small" className={styles.avatar} src={currentUser.headImgUrl} alt="avatar" />
|
||||
<span className={`${styles.name} anticon`}>{currentUser.nickname}</span>
|
||||
</span>
|
||||
</HeaderDropdown>
|
||||
);
|
||||
};
|
||||
|
||||
export default AvatarDropdown;
|
||||
@@ -1,84 +0,0 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
|
||||
@pro-header-hover-bg: rgba(0, 0, 0, 0.025);
|
||||
|
||||
.menu {
|
||||
:global(.anticon) {
|
||||
margin-right: 8px;
|
||||
}
|
||||
:global(.ant-dropdown-menu-item) {
|
||||
min-width: 160px;
|
||||
}
|
||||
}
|
||||
|
||||
.right {
|
||||
display: flex;
|
||||
float: right;
|
||||
height: 48px;
|
||||
margin-left: auto;
|
||||
overflow: hidden;
|
||||
.action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 48px;
|
||||
padding: 0 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
> span {
|
||||
vertical-align: middle;
|
||||
}
|
||||
&:hover {
|
||||
background: @pro-header-hover-bg;
|
||||
}
|
||||
&:global(.opened) {
|
||||
background: @pro-header-hover-bg;
|
||||
}
|
||||
}
|
||||
.search {
|
||||
padding: 0 12px;
|
||||
&:hover {
|
||||
background: transparent;
|
||||
}
|
||||
}
|
||||
.account {
|
||||
.avatar {
|
||||
margin-right: 8px;
|
||||
color: @primary-color;
|
||||
vertical-align: top;
|
||||
background: rgba(255, 255, 255, 0.85);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dark {
|
||||
.action {
|
||||
&:hover {
|
||||
background: #252a3d;
|
||||
}
|
||||
&:global(.opened) {
|
||||
background: #252a3d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (max-width: @screen-md) {
|
||||
:global(.ant-divider-vertical) {
|
||||
vertical-align: unset;
|
||||
}
|
||||
.name {
|
||||
display: none;
|
||||
}
|
||||
.right {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 12px;
|
||||
.account {
|
||||
.avatar {
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
.search {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
import { GithubOutlined, QuestionCircleOutlined, BellOutlined } from '@ant-design/icons';
|
||||
import { Space, Badge } from 'antd';
|
||||
import React from 'react';
|
||||
import { useModel } from 'umi';
|
||||
import AvatarDropdown from './AvatarDropdown';
|
||||
import styles from './index.less';
|
||||
import { history } from 'umi';
|
||||
|
||||
export type SiderTheme = 'light' | 'dark';
|
||||
|
||||
const GlobalHeaderRight: React.FC = () => {
|
||||
const { initialState } = useModel('@@initialState');
|
||||
const { unreadCount } = useModel('useMessage');
|
||||
|
||||
if (!initialState || !initialState.settings) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { navTheme, layout } = initialState.settings;
|
||||
let className = styles.right;
|
||||
|
||||
if ((navTheme === 'dark' && layout === 'top') || layout === 'mix') {
|
||||
className = `${styles.right} ${styles.dark}`;
|
||||
}
|
||||
return (
|
||||
<Space className={className}>
|
||||
{/* <HeaderSearch
|
||||
className={`${styles.action} ${styles.search}`}
|
||||
placeholder="站内搜索"
|
||||
defaultValue="umi ui"
|
||||
options={[
|
||||
{ label: <a href="https://umijs.org/zh/guide/umi-ui.html">umi ui</a>, value: 'umi ui' },
|
||||
{
|
||||
label: <a href="next.ant.design">Ant Design</a>,
|
||||
value: 'Ant Design',
|
||||
},
|
||||
{
|
||||
label: <a href="https://protable.ant.design/">Pro Table</a>,
|
||||
value: 'Pro Table',
|
||||
},
|
||||
{
|
||||
label: <a href="https://prolayout.ant.design/">Pro Layout</a>,
|
||||
value: 'Pro Layout',
|
||||
},
|
||||
]}
|
||||
onSearch={value => {
|
||||
console.log('input', value);
|
||||
}}
|
||||
/> */}
|
||||
{/* 注释掉帮助链接
|
||||
<span
|
||||
className={styles.action}
|
||||
onClick={() => {
|
||||
window.open('https://www.kancloud.cn/zlt2000/microservices-platform');
|
||||
}}
|
||||
>
|
||||
<QuestionCircleOutlined />
|
||||
</span>
|
||||
*/}
|
||||
{/* 注释掉GitHub链接
|
||||
<span
|
||||
className={styles.action}
|
||||
onClick={() => {
|
||||
window.open('https://github.com/zlt2000/microservices-platform');
|
||||
}}
|
||||
>
|
||||
<GithubOutlined />
|
||||
</span>
|
||||
*/}
|
||||
<span
|
||||
className={styles.action}
|
||||
onClick={() => history.push('/message')}
|
||||
>
|
||||
<Badge count={unreadCount}>
|
||||
<BellOutlined className={styles.icon} />
|
||||
</Badge>
|
||||
</span>
|
||||
<AvatarDropdown menu />
|
||||
</Space>
|
||||
);
|
||||
};
|
||||
export default GlobalHeaderRight;
|
||||
@@ -1,48 +0,0 @@
|
||||
.tenantSelector {
|
||||
.currentInfo {
|
||||
margin-bottom: 8px;
|
||||
padding: 4px 8px;
|
||||
background: #f6f8fa;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #e1e8ed;
|
||||
}
|
||||
|
||||
.dropdownFooter {
|
||||
padding: 8px 12px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
background: #fafafa;
|
||||
|
||||
a {
|
||||
color: #1890ff;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: #40a9ff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tenantInfo {
|
||||
padding: 8px 12px;
|
||||
background: #f6f8fa;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #e1e8ed;
|
||||
}
|
||||
|
||||
// 全局样式优化
|
||||
:global {
|
||||
.ant-select-tree-treenode .ant-select-tree-title {
|
||||
.anticon {
|
||||
margin-right: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-tag {
|
||||
border-radius: 10px;
|
||||
font-size: 11px;
|
||||
padding: 0 6px;
|
||||
line-height: 18px;
|
||||
}
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { TreeSelect, Space, Typography, Tag, Spin, message } from 'antd';
|
||||
import { BuildOutlined, SwapOutlined } from '@ant-design/icons';
|
||||
import { tenantApi } from '@/services/tenant';
|
||||
import styles from './index.less';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
interface TenantTreeNode {
|
||||
tenantId: string;
|
||||
tenantName: string;
|
||||
parentTenantId?: string;
|
||||
tenantType: string;
|
||||
tenantLevel: number;
|
||||
status: number;
|
||||
enabled: boolean;
|
||||
description?: string;
|
||||
children?: TenantTreeNode[];
|
||||
hasChildren?: boolean;
|
||||
childrenCount?: number;
|
||||
}
|
||||
|
||||
interface TenantInfo {
|
||||
tenantId: string;
|
||||
tenantName: string;
|
||||
parentTenantId?: string;
|
||||
parentTenantName?: string;
|
||||
tenantLevel: number;
|
||||
tenantPath: string;
|
||||
tenantType: string;
|
||||
description?: string;
|
||||
status: number;
|
||||
statusText: string;
|
||||
hasChildren?: boolean;
|
||||
childrenCount?: number;
|
||||
}
|
||||
|
||||
interface TenantSelectorProps {
|
||||
onChange?: (tenantId: string) => void;
|
||||
placeholder?: string;
|
||||
showCurrentInfo?: boolean;
|
||||
style?: React.CSSProperties;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
const TenantSelector: React.FC<TenantSelectorProps> = ({
|
||||
onChange,
|
||||
placeholder = "选择查询租户范围",
|
||||
showCurrentInfo = true,
|
||||
style = { width: 300 },
|
||||
disabled = false,
|
||||
}) => {
|
||||
const [tenantTree, setTenantTree] = useState<any[]>([]);
|
||||
const [currentTenant, setCurrentTenant] = useState<TenantInfo | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [canSwitch, setCanSwitch] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
loadTenantData();
|
||||
}, []);
|
||||
|
||||
const loadTenantData = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
// 并行加载可访问租户和当前租户信息
|
||||
const [accessibleResult, currentResult] = await Promise.all([
|
||||
tenantApi.getAccessibleTenants(),
|
||||
tenantApi.getCurrentTenant()
|
||||
]);
|
||||
|
||||
if (accessibleResult.success) {
|
||||
const treeData = buildTreeData(accessibleResult.data);
|
||||
setTenantTree(treeData);
|
||||
setCanSwitch(accessibleResult.data.length > 1);
|
||||
}
|
||||
|
||||
if (currentResult.success) {
|
||||
setCurrentTenant(currentResult.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载租户数据失败:', error);
|
||||
message.error('加载租户数据失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const buildTreeData = (tenants: TenantTreeNode[]): any[] => {
|
||||
return tenants.map(tenant => ({
|
||||
title: (
|
||||
<Space>
|
||||
<BuildOutlined />
|
||||
<span>{tenant.tenantName}</span>
|
||||
<Tag size="small" color={getTenantTypeColor(tenant.tenantType)}>
|
||||
{getTenantTypeText(tenant.tenantType)}
|
||||
</Tag>
|
||||
</Space>
|
||||
),
|
||||
value: tenant.tenantId,
|
||||
key: tenant.tenantId,
|
||||
children: tenant.children ? buildTreeData(tenant.children) : undefined
|
||||
}));
|
||||
};
|
||||
|
||||
const getTenantTypeColor = (type: string): string => {
|
||||
const colorMap: Record<string, string> = {
|
||||
'PLATFORM': 'purple',
|
||||
'GROUP': 'blue',
|
||||
'COMPANY': 'green',
|
||||
'DEPARTMENT': 'orange',
|
||||
};
|
||||
return colorMap[type] || 'default';
|
||||
};
|
||||
|
||||
const getTenantTypeText = (type: string): string => {
|
||||
const textMap: Record<string, string> = {
|
||||
'PLATFORM': '平台',
|
||||
'GROUP': '集团',
|
||||
'COMPANY': '公司',
|
||||
'DEPARTMENT': '部门',
|
||||
};
|
||||
return textMap[type] || type;
|
||||
};
|
||||
|
||||
const handleTenantChange = async (tenantId: string) => {
|
||||
if (!tenantId) {
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const result = await tenantApi.switchTenant(tenantId);
|
||||
if (result.success) {
|
||||
message.success('切换租户成功');
|
||||
|
||||
// 更新当前租户信息
|
||||
const currentResult = await tenantApi.getCurrentTenant();
|
||||
if (currentResult.success) {
|
||||
setCurrentTenant(currentResult.data);
|
||||
}
|
||||
|
||||
// 通知父组件
|
||||
onChange?.(tenantId);
|
||||
} else {
|
||||
message.error(result.msg || '切换租户失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('切换租户失败:', error);
|
||||
message.error('切换租户失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 重置到默认租户
|
||||
const handleReset = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const result = await tenantApi.resetToDefaultTenant();
|
||||
if (result.success) {
|
||||
message.success('重置到默认租户成功');
|
||||
await loadTenantData();
|
||||
onChange?.(currentTenant?.tenantId || '');
|
||||
} else {
|
||||
message.error(result.msg || '重置失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('重置失败:', error);
|
||||
message.error('重置失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (!canSwitch) {
|
||||
// 不能切换租户时显示当前租户信息
|
||||
return showCurrentInfo && currentTenant ? (
|
||||
<div className={styles.tenantInfo}>
|
||||
<Space>
|
||||
<Text type="secondary">当前租户:</Text>
|
||||
<Tag icon={<BuildOutlined />} color={getTenantTypeColor(currentTenant.tenantType)}>
|
||||
{currentTenant.tenantName}
|
||||
</Tag>
|
||||
</Space>
|
||||
</div>
|
||||
) : null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.tenantSelector}>
|
||||
{showCurrentInfo && currentTenant && (
|
||||
<div className={styles.currentInfo}>
|
||||
<Space>
|
||||
<Text type="secondary">数据范围:</Text>
|
||||
<Tag
|
||||
icon={<BuildOutlined />}
|
||||
color={getTenantTypeColor(currentTenant.tenantType)}
|
||||
>
|
||||
{currentTenant.tenantName}
|
||||
</Tag>
|
||||
{currentTenant.childrenCount && currentTenant.childrenCount > 0 && (
|
||||
<Text type="secondary">
|
||||
(含{currentTenant.childrenCount}个子租户)
|
||||
</Text>
|
||||
)}
|
||||
</Space>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<TreeSelect
|
||||
style={style}
|
||||
value={currentTenant?.tenantId}
|
||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||
treeData={tenantTree}
|
||||
placeholder={placeholder}
|
||||
treeDefaultExpandAll
|
||||
onChange={handleTenantChange}
|
||||
allowClear={false}
|
||||
loading={loading}
|
||||
disabled={disabled}
|
||||
suffixIcon={<SwapOutlined spin={loading} />}
|
||||
showSearch
|
||||
treeNodeFilterProp="title"
|
||||
size="middle"
|
||||
dropdownRender={(menu) => (
|
||||
<div>
|
||||
{menu}
|
||||
<div className={styles.dropdownFooter}>
|
||||
<a onClick={handleReset}>重置为默认租户</a>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TenantSelector;
|
||||
@@ -1,4 +0,0 @@
|
||||
export const AUTH_CONFIG = {
|
||||
basicToken: 'Basic d2ViQXBwOndlYkFwcA==',
|
||||
// basicToken: 'Basic Z2ZhcHA6SWtpbmd0ZWNAMjAyMA==', // 备用token
|
||||
};
|
||||
@@ -1,45 +0,0 @@
|
||||
import type { Page } from '@playwright/test';
|
||||
import { expect, test } from '@playwright/test';
|
||||
const { uniq } = require('lodash');
|
||||
const RouterConfig = require('../../config/routes').default;
|
||||
|
||||
const BASE_URL = `http://localhost:${process.env.PORT || 8001}`;
|
||||
|
||||
function formatter(routes: any, parentPath = ''): string[] {
|
||||
const fixedParentPath = parentPath.replace(/\/{1,}/g, '/');
|
||||
let result: string[] = [];
|
||||
routes.forEach((item: { path: string; routes: string }) => {
|
||||
if (item.path && !item.path.startsWith('/')) {
|
||||
result.push(`${fixedParentPath}/${item.path}`.replace(/\/{1,}/g, '/'));
|
||||
}
|
||||
if (item.path && item.path.startsWith('/')) {
|
||||
result.push(`${item.path}`.replace(/\/{1,}/g, '/'));
|
||||
}
|
||||
if (item.routes) {
|
||||
result = result.concat(
|
||||
formatter(item.routes, item.path ? `${fixedParentPath}/${item.path}` : parentPath),
|
||||
);
|
||||
}
|
||||
});
|
||||
return uniq(result.filter((item) => !!item));
|
||||
}
|
||||
|
||||
const testPage = (path: string, page: Page) => async () => {
|
||||
await page.evaluate(() => {
|
||||
localStorage.setItem('antd-pro-authority', '["admin"]');
|
||||
});
|
||||
await page.goto(`${BASE_URL}${path}`);
|
||||
await page.waitForSelector('footer', {
|
||||
timeout: 2000,
|
||||
});
|
||||
const haveFooter = await page.evaluate(() => document.getElementsByTagName('footer').length > 0);
|
||||
expect(haveFooter).toBeTruthy();
|
||||
};
|
||||
|
||||
const routers = formatter(RouterConfig);
|
||||
|
||||
routers.forEach((route) => {
|
||||
test(`test route page ${route}`, async ({ page }) => {
|
||||
await testPage(route, page);
|
||||
});
|
||||
});
|
||||
@@ -1,78 +0,0 @@
|
||||
@import '~antd/es/style/variable.less';
|
||||
|
||||
html,
|
||||
body,
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.colorWeak {
|
||||
filter: invert(80%);
|
||||
}
|
||||
|
||||
.ant-layout {
|
||||
min-height: 100vh;
|
||||
}
|
||||
.ant-pro-sider.ant-layout-sider.ant-pro-sider-fixed {
|
||||
left: unset;
|
||||
}
|
||||
|
||||
|
||||
.hightligh{
|
||||
background-color: @yellow-2 !important;
|
||||
}
|
||||
|
||||
mark {
|
||||
background-color: @gold-3;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
|
||||
body {
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
ul,
|
||||
ol {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.ant-layout-content {
|
||||
.query-filter {
|
||||
margin-bottom: @margin-md;
|
||||
padding: @padding-lg;
|
||||
padding-bottom: 0;
|
||||
background: @component-background;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@media (max-width: @screen-xs) {
|
||||
.ant-table {
|
||||
width: 100%;
|
||||
overflow-x: auto;
|
||||
&-thead > tr,
|
||||
&-tbody > tr {
|
||||
> th,
|
||||
> td {
|
||||
white-space: pre;
|
||||
> span {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Compatible with IE11
|
||||
@media screen and(-ms-high-contrast: active), (-ms-high-contrast: none) {
|
||||
body .ant-design-pro > .ant-layout {
|
||||
min-height: 100vh;
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
import { Button, message, notification } from 'antd';
|
||||
import { useIntl } from 'umi';
|
||||
import defaultSettings from '../config/defaultSettings';
|
||||
|
||||
const { pwa } = defaultSettings;
|
||||
const isHttps = document.location.protocol === 'https:';
|
||||
|
||||
const clearCache = () => {
|
||||
// remove all caches
|
||||
if (window.caches) {
|
||||
caches
|
||||
.keys()
|
||||
.then((keys) => {
|
||||
keys.forEach((key) => {
|
||||
caches.delete(key);
|
||||
});
|
||||
})
|
||||
.catch((e) => console.log(e));
|
||||
}
|
||||
};
|
||||
|
||||
// if pwa is true
|
||||
if (pwa) {
|
||||
// Notify user if offline now
|
||||
window.addEventListener('sw.offline', () => {
|
||||
message.warning(useIntl().formatMessage({ id: 'app.pwa.offline' }));
|
||||
});
|
||||
|
||||
// Pop up a prompt on the page asking the user if they want to use the latest version
|
||||
window.addEventListener('sw.updated', (event: Event) => {
|
||||
const e = event as CustomEvent;
|
||||
const reloadSW = async () => {
|
||||
// Check if there is sw whose state is waiting in ServiceWorkerRegistration
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
|
||||
const worker = e.detail && e.detail.waiting;
|
||||
if (!worker) {
|
||||
return true;
|
||||
}
|
||||
// Send skip-waiting event to waiting SW with MessageChannel
|
||||
await new Promise((resolve, reject) => {
|
||||
const channel = new MessageChannel();
|
||||
channel.port1.onmessage = (msgEvent) => {
|
||||
if (msgEvent.data.error) {
|
||||
reject(msgEvent.data.error);
|
||||
} else {
|
||||
resolve(msgEvent.data);
|
||||
}
|
||||
};
|
||||
worker.postMessage({ type: 'skip-waiting' }, [channel.port2]);
|
||||
});
|
||||
|
||||
clearCache();
|
||||
window.location.reload();
|
||||
return true;
|
||||
};
|
||||
const key = `open${Date.now()}`;
|
||||
const btn = (
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
notification.close(key);
|
||||
reloadSW();
|
||||
}}
|
||||
>
|
||||
{useIntl().formatMessage({ id: 'app.pwa.serviceworker.updated.ok' })}
|
||||
</Button>
|
||||
);
|
||||
notification.open({
|
||||
message: useIntl().formatMessage({ id: 'app.pwa.serviceworker.updated' }),
|
||||
description: useIntl().formatMessage({ id: 'app.pwa.serviceworker.updated.hint' }),
|
||||
btn,
|
||||
key,
|
||||
onClose: async () => null,
|
||||
});
|
||||
});
|
||||
} else if ('serviceWorker' in navigator && isHttps) {
|
||||
// unregister service worker
|
||||
const { serviceWorker } = navigator;
|
||||
if (serviceWorker.getRegistrations) {
|
||||
serviceWorker.getRegistrations().then((sws) => {
|
||||
sws.forEach((sw) => {
|
||||
sw.unregister();
|
||||
});
|
||||
});
|
||||
}
|
||||
serviceWorker.getRegistration().then((sw) => {
|
||||
if (sw) sw.unregister();
|
||||
});
|
||||
|
||||
clearCache();
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import component from './zh-CN/component';
|
||||
import globalHeader from './zh-CN/globalHeader';
|
||||
import menu from './zh-CN/menu';
|
||||
import pages from './zh-CN/pages';
|
||||
import pwa from './zh-CN/pwa';
|
||||
import settingDrawer from './zh-CN/settingDrawer';
|
||||
import settings from './zh-CN/settings';
|
||||
|
||||
export default {
|
||||
'navBar.lang': '语言',
|
||||
'layout.user.link.help': '帮助',
|
||||
'layout.user.link.privacy': '隐私',
|
||||
'layout.user.link.terms': '条款',
|
||||
'app.copyright.produced': '版权所有:https://gitee.com/L-Shilin/go-fly-platform-services.git',
|
||||
'app.preview.down.block': '下载此页面到本地项目',
|
||||
'app.welcome.link.fetch-blocks': '获取全部区块',
|
||||
'app.welcome.link.block-list': '基于 block 开发,快速构建标准页面',
|
||||
...pages,
|
||||
...globalHeader,
|
||||
...menu,
|
||||
...settingDrawer,
|
||||
...settings,
|
||||
...pwa,
|
||||
...component,
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
export default {
|
||||
'component.tagSelect.expand': '展开',
|
||||
'component.tagSelect.collapse': '收起',
|
||||
'component.tagSelect.all': '全部',
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
export default {
|
||||
'component.globalHeader.search': '站内搜索',
|
||||
'component.globalHeader.search.example1': '搜索提示一',
|
||||
'component.globalHeader.search.example2': '搜索提示二',
|
||||
'component.globalHeader.search.example3': '搜索提示三',
|
||||
'component.globalHeader.help': '使用文档',
|
||||
'component.globalHeader.notification': '通知',
|
||||
'component.globalHeader.notification.empty': '你已查看所有通知',
|
||||
'component.globalHeader.message': '消息',
|
||||
'component.globalHeader.message.empty': '您已读完所有消息',
|
||||
'component.globalHeader.event': '待办',
|
||||
'component.globalHeader.event.empty': '你已完成所有待办',
|
||||
'component.noticeIcon.clear': '清空',
|
||||
'component.noticeIcon.cleared': '清空了',
|
||||
'component.noticeIcon.empty': '暂无数据',
|
||||
'component.noticeIcon.view-more': '查看更多',
|
||||
};
|
||||
@@ -1,60 +0,0 @@
|
||||
export default {
|
||||
'menu.welcome': '首页',
|
||||
'menu.more-blocks': '更多区块',
|
||||
'menu.home': '首页',
|
||||
'menu.admin': '管理页',
|
||||
'menu.admin.sub-page': '二级管理页',
|
||||
'menu.login': '登录',
|
||||
'menu.register': '注册',
|
||||
'menu.register-result': '注册结果',
|
||||
'menu.dashboard': 'Dashboard',
|
||||
'menu.dashboard.analysis': '分析页',
|
||||
'menu.dashboard.monitor': '监控页',
|
||||
'menu.dashboard.workplace': '工作台',
|
||||
'menu.exception.403': '403',
|
||||
'menu.exception.404': '404',
|
||||
'menu.exception.500': '500',
|
||||
'menu.form': '表单页',
|
||||
'menu.form.basic-form': '基础表单',
|
||||
'menu.form.step-form': '分步表单',
|
||||
'menu.form.step-form.info': '分步表单(填写转账信息)',
|
||||
'menu.form.step-form.confirm': '分步表单(确认转账信息)',
|
||||
'menu.form.step-form.result': '分步表单(完成)',
|
||||
'menu.form.advanced-form': '高级表单',
|
||||
'menu.list': '列表页',
|
||||
'menu.list.table-list': '查询表格',
|
||||
'menu.list.basic-list': '标准列表',
|
||||
'menu.list.card-list': '卡片列表',
|
||||
'menu.list.search-list': '搜索列表',
|
||||
'menu.list.search-list.articles': '搜索列表(文章)',
|
||||
'menu.list.search-list.projects': '搜索列表(项目)',
|
||||
'menu.list.search-list.applications': '搜索列表(应用)',
|
||||
'menu.profile': '详情页',
|
||||
'menu.profile.basic': '基础详情页',
|
||||
'menu.profile.advanced': '高级详情页',
|
||||
'menu.result': '结果页',
|
||||
'menu.result.success': '成功页',
|
||||
'menu.result.fail': '失败页',
|
||||
'menu.exception': '异常页',
|
||||
'menu.exception.not-permission': '403',
|
||||
'menu.exception.not-find': '404',
|
||||
'menu.exception.server-error': '500',
|
||||
'menu.exception.trigger': '触发错误',
|
||||
'menu.account': '个人页',
|
||||
'menu.account.center': '个人中心',
|
||||
'menu.account.settings': '个人设置',
|
||||
'menu.account.trigger': '触发报错',
|
||||
'menu.account.logout': '退出登录',
|
||||
'menu.editor': '图形编辑器',
|
||||
'menu.editor.flow': '流程编辑器',
|
||||
'menu.editor.mind': '脑图编辑器',
|
||||
'menu.editor.koni': '拓扑编辑器',
|
||||
'menu.首页': '首页',
|
||||
'menu.设备运维': '设备运维',
|
||||
'menu.设备运维.设备管理': '设备管理',
|
||||
'menu.设备运维.分组管理': '分组管理',
|
||||
'menu.设备运维.运维管理': '运维管理',
|
||||
'menu.设备运维.设备监控': '设备监控',
|
||||
'menu.设备运维.统计分析': '统计分析',
|
||||
'menu.设备运维.设备详情': '设备详情',
|
||||
};
|
||||
@@ -1,65 +0,0 @@
|
||||
export default {
|
||||
'pages.layouts.userLayout.title': '前后端分离的微服务架构',
|
||||
'pages.login.accountLogin.tab': '账户密码登录',
|
||||
'pages.login.accountLogin.errorMessage': '错误的账号和密码(admin/ant.design)',
|
||||
'pages.login.failure': '登录失败,请重试!',
|
||||
'pages.login.success': '登录成功!',
|
||||
'pages.login.username.placeholder': '账号',
|
||||
'pages.login.username.required': '账号是必填项!',
|
||||
'pages.login.password.placeholder': '密码',
|
||||
'pages.login.password.required': '密码是必填项!',
|
||||
'pages.login.phoneLogin.tab': '手机号登录',
|
||||
'pages.login.phoneLogin.errorMessage': '验证码错误',
|
||||
'pages.login.phoneNumber.placeholder': '请输入手机号!',
|
||||
'pages.login.phoneNumber.required': '手机号是必填项!',
|
||||
'pages.login.phoneNumber.invalid': '不合法的手机号!',
|
||||
'pages.login.captcha.placeholder': '请输入验证码!',
|
||||
'pages.login.captcha.required': '验证码是必填项!',
|
||||
'pages.login.phoneLogin.getVerificationCode': '获取验证码',
|
||||
'pages.getCaptchaSecondText': '秒后重新获取',
|
||||
'pages.login.rememberMe': '自动登录',
|
||||
'pages.login.forgotPassword': '忘记密码 ?',
|
||||
'pages.login.submit': '登录',
|
||||
'pages.login.loginWith': '其他登录方式 :',
|
||||
'pages.login.registerAccount': '注册账户',
|
||||
'pages.welcome.link': '欢迎使用',
|
||||
'pages.welcome.alertMessage': '更快更强的重型组件,已经发布。',
|
||||
'pages.admin.subPage.title': ' 这个页面只有 admin 权限才能查看',
|
||||
'pages.admin.subPage.alertMessage': 'umi ui 现已发布,欢迎使用 npm run ui 启动体验。',
|
||||
'pages.searchTable.createForm.newRule': '新建规则',
|
||||
'pages.searchTable.updateForm.ruleConfig': '规则配置',
|
||||
'pages.searchTable.updateForm.basicConfig': '基本信息',
|
||||
'pages.searchTable.updateForm.ruleName.nameLabel': '规则名称',
|
||||
'pages.searchTable.updateForm.ruleName.nameRules': '请输入规则名称!',
|
||||
'pages.searchTable.updateForm.ruleDesc.descLabel': '规则描述',
|
||||
'pages.searchTable.updateForm.ruleDesc.descPlaceholder': '请输入至少五个字符',
|
||||
'pages.searchTable.updateForm.ruleDesc.descRules': '请输入至少五个字符的规则描述!',
|
||||
'pages.searchTable.updateForm.ruleProps.title': '配置规则属性',
|
||||
'pages.searchTable.updateForm.object': '监控对象',
|
||||
'pages.searchTable.updateForm.ruleProps.templateLabel': '规则模板',
|
||||
'pages.searchTable.updateForm.ruleProps.typeLabel': '规则类型',
|
||||
'pages.searchTable.updateForm.schedulingPeriod.title': '设定调度周期',
|
||||
'pages.searchTable.updateForm.schedulingPeriod.timeLabel': '开始时间',
|
||||
'pages.searchTable.updateForm.schedulingPeriod.timeRules': '请选择开始时间!',
|
||||
'pages.searchTable.titleDesc': '描述',
|
||||
'pages.searchTable.ruleName': '规则名称为必填项',
|
||||
'pages.searchTable.titleCallNo': '服务调用次数',
|
||||
'pages.searchTable.titleStatus': '状态',
|
||||
'pages.searchTable.nameStatus.default': '关闭',
|
||||
'pages.searchTable.nameStatus.running': '运行中',
|
||||
'pages.searchTable.nameStatus.online': '已上线',
|
||||
'pages.searchTable.nameStatus.abnormal': '异常',
|
||||
'pages.searchTable.titleUpdatedAt': '上次调度时间',
|
||||
'pages.searchTable.exception': '请输入异常原因!',
|
||||
'pages.searchTable.titleOption': '操作',
|
||||
'pages.searchTable.config': '配置',
|
||||
'pages.searchTable.subscribeAlert': '订阅警报',
|
||||
'pages.searchTable.title': '查询表格',
|
||||
'pages.searchTable.new': '新建',
|
||||
'pages.searchTable.chosen': '已选择',
|
||||
'pages.searchTable.item': '项',
|
||||
'pages.searchTable.totalServiceCalls': '服务调用次数总计',
|
||||
'pages.searchTable.tenThousand': '万',
|
||||
'pages.searchTable.batchDeletion': '批量删除',
|
||||
'pages.searchTable.batchApproval': '批量审批',
|
||||
};
|
||||
@@ -1,6 +0,0 @@
|
||||
export default {
|
||||
'app.pwa.offline': '当前处于离线状态',
|
||||
'app.pwa.serviceworker.updated': '有新内容',
|
||||
'app.pwa.serviceworker.updated.hint': '请点击“刷新”按钮或者手动刷新页面',
|
||||
'app.pwa.serviceworker.updated.ok': '刷新',
|
||||
};
|
||||
@@ -1,31 +0,0 @@
|
||||
export default {
|
||||
'app.setting.pagestyle': '整体风格设置',
|
||||
'app.setting.pagestyle.dark': '暗色菜单风格',
|
||||
'app.setting.pagestyle.light': '亮色菜单风格',
|
||||
'app.setting.content-width': '内容区域宽度',
|
||||
'app.setting.content-width.fixed': '定宽',
|
||||
'app.setting.content-width.fluid': '流式',
|
||||
'app.setting.themecolor': '主题色',
|
||||
'app.setting.themecolor.dust': '薄暮',
|
||||
'app.setting.themecolor.volcano': '火山',
|
||||
'app.setting.themecolor.sunset': '日暮',
|
||||
'app.setting.themecolor.cyan': '明青',
|
||||
'app.setting.themecolor.green': '极光绿',
|
||||
'app.setting.themecolor.daybreak': '拂晓蓝(默认)',
|
||||
'app.setting.themecolor.geekblue': '极客蓝',
|
||||
'app.setting.themecolor.purple': '酱紫',
|
||||
'app.setting.navigationmode': '导航模式',
|
||||
'app.setting.sidemenu': '侧边菜单布局',
|
||||
'app.setting.topmenu': '顶部菜单布局',
|
||||
'app.setting.fixedheader': '固定 Header',
|
||||
'app.setting.fixedsidebar': '固定侧边菜单',
|
||||
'app.setting.fixedsidebar.hint': '侧边菜单布局时可配置',
|
||||
'app.setting.hideheader': '下滑时隐藏 Header',
|
||||
'app.setting.hideheader.hint': '固定 Header 时可配置',
|
||||
'app.setting.othersettings': '其他设置',
|
||||
'app.setting.weakmode': '色弱模式',
|
||||
'app.setting.copy': '拷贝设置',
|
||||
'app.setting.copyinfo': '拷贝成功,请到 config/defaultSettings.js 中替换默认配置',
|
||||
'app.setting.production.hint':
|
||||
'配置栏只在开发环境用于预览,生产环境不会展现,请拷贝后手动修改配置文件',
|
||||
};
|
||||
@@ -1,55 +0,0 @@
|
||||
export default {
|
||||
'app.settings.menuMap.basic': '基本设置',
|
||||
'app.settings.menuMap.security': '安全设置',
|
||||
'app.settings.menuMap.binding': '账号绑定',
|
||||
'app.settings.menuMap.notification': '新消息通知',
|
||||
'app.settings.basic.avatar': '头像',
|
||||
'app.settings.basic.change-avatar': '更换头像',
|
||||
'app.settings.basic.email': '邮箱',
|
||||
'app.settings.basic.email-message': '请输入您的邮箱!',
|
||||
'app.settings.basic.nickname': '昵称',
|
||||
'app.settings.basic.nickname-message': '请输入您的昵称!',
|
||||
'app.settings.basic.profile': '个人简介',
|
||||
'app.settings.basic.profile-message': '请输入个人简介!',
|
||||
'app.settings.basic.profile-placeholder': '个人简介',
|
||||
'app.settings.basic.country': '国家/地区',
|
||||
'app.settings.basic.country-message': '请输入您的国家或地区!',
|
||||
'app.settings.basic.geographic': '所在省市',
|
||||
'app.settings.basic.geographic-message': '请输入您的所在省市!',
|
||||
'app.settings.basic.address': '街道地址',
|
||||
'app.settings.basic.address-message': '请输入您的街道地址!',
|
||||
'app.settings.basic.phone': '联系电话',
|
||||
'app.settings.basic.phone-message': '请输入您的联系电话!',
|
||||
'app.settings.basic.update': '更新基本信息',
|
||||
'app.settings.security.strong': '强',
|
||||
'app.settings.security.medium': '中',
|
||||
'app.settings.security.weak': '弱',
|
||||
'app.settings.security.password': '账户密码',
|
||||
'app.settings.security.password-description': '当前密码强度',
|
||||
'app.settings.security.phone': '密保手机',
|
||||
'app.settings.security.phone-description': '已绑定手机',
|
||||
'app.settings.security.question': '密保问题',
|
||||
'app.settings.security.question-description': '未设置密保问题,密保问题可有效保护账户安全',
|
||||
'app.settings.security.email': '备用邮箱',
|
||||
'app.settings.security.email-description': '已绑定邮箱',
|
||||
'app.settings.security.mfa': 'MFA 设备',
|
||||
'app.settings.security.mfa-description': '未绑定 MFA 设备,绑定后,可以进行二次确认',
|
||||
'app.settings.security.modify': '修改',
|
||||
'app.settings.security.set': '设置',
|
||||
'app.settings.security.bind': '绑定',
|
||||
'app.settings.binding.taobao': '绑定淘宝',
|
||||
'app.settings.binding.taobao-description': '当前未绑定淘宝账号',
|
||||
'app.settings.binding.alipay': '绑定支付宝',
|
||||
'app.settings.binding.alipay-description': '当前未绑定支付宝账号',
|
||||
'app.settings.binding.dingding': '绑定钉钉',
|
||||
'app.settings.binding.dingding-description': '当前未绑定钉钉账号',
|
||||
'app.settings.binding.bind': '绑定',
|
||||
'app.settings.notification.password': '账户密码',
|
||||
'app.settings.notification.password-description': '其他用户的消息将以站内信的形式通知',
|
||||
'app.settings.notification.messages': '系统消息',
|
||||
'app.settings.notification.messages-description': '系统消息将以站内信的形式通知',
|
||||
'app.settings.notification.todo': '待办任务',
|
||||
'app.settings.notification.todo-description': '待办任务将以站内信的形式通知',
|
||||
'app.settings.open': '开',
|
||||
'app.settings.close': '关',
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"name": "Ant Design Pro",
|
||||
"short_name": "Ant Design Pro",
|
||||
"display": "standalone",
|
||||
"start_url": "./?utm_source=homescreen",
|
||||
"theme_color": "#002140",
|
||||
"background_color": "#001529",
|
||||
"icons": [
|
||||
{
|
||||
"src": "icons/icon-192x192.png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-128x128.png",
|
||||
"sizes": "128x128"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-512x512.png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { getMessages } from '@/services/message/api';
|
||||
import { useModel } from 'umi';
|
||||
|
||||
export default () => {
|
||||
const [unreadCount, setUnreadCount] = useState<number>(0);
|
||||
const { initialState } = useModel('@@initialState');
|
||||
|
||||
const fetchUnreadCount = async () => {
|
||||
// 如果未登录,不请求站内信
|
||||
if (!initialState?.currentUser) {
|
||||
setUnreadCount(0);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await getMessages({ status: 0, pageSize: 1 });
|
||||
setUnreadCount(response.total || 0);
|
||||
} catch (error) {
|
||||
console.error('获取未读消息数量失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchUnreadCount();
|
||||
// 设置定时刷新
|
||||
const timer = setInterval(fetchUnreadCount, 60000); // 每分钟刷新一次
|
||||
return () => clearInterval(timer);
|
||||
}, [initialState?.currentUser]); // 添加currentUser作为依赖,当登录状态改变时重新获取
|
||||
|
||||
return {
|
||||
unreadCount,
|
||||
refreshUnreadCount: fetchUnreadCount,
|
||||
};
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Button, Result } from 'antd';
|
||||
import React from 'react';
|
||||
import { history } from 'umi';
|
||||
|
||||
const NoFoundPage: React.FC = () => (
|
||||
<Result
|
||||
status="404"
|
||||
title="404"
|
||||
subTitle="Sorry, the page you visited does not exist."
|
||||
extra={
|
||||
<Button type="primary" onClick={() => history.push('/')}>
|
||||
Back Home
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
export default NoFoundPage;
|
||||
@@ -1,45 +0,0 @@
|
||||
import { HeartTwoTone, SmileTwoTone } from '@ant-design/icons';
|
||||
import { PageHeaderWrapper } from '@ant-design/pro-components';
|
||||
import { Alert, Card, Typography } from 'antd';
|
||||
import React from 'react';
|
||||
import { useIntl } from 'umi';
|
||||
|
||||
const Admin: React.FC = () => {
|
||||
const intl = useIntl();
|
||||
return (
|
||||
<PageHeaderWrapper
|
||||
content={intl.formatMessage({
|
||||
id: 'pages.admin.subPage.title',
|
||||
defaultMessage: 'This page can only be viewed by admin',
|
||||
})}
|
||||
>
|
||||
<Card>
|
||||
<Alert
|
||||
message={intl.formatMessage({
|
||||
id: 'pages.welcome.alertMessage',
|
||||
defaultMessage: 'Faster and stronger heavy-duty components have been released.',
|
||||
})}
|
||||
type="success"
|
||||
showIcon
|
||||
banner
|
||||
style={{
|
||||
margin: -12,
|
||||
marginBottom: 48,
|
||||
}}
|
||||
/>
|
||||
<Typography.Title level={2} style={{ textAlign: 'center' }}>
|
||||
<SmileTwoTone /> Ant Design Pro <HeartTwoTone twoToneColor="#eb2f96" /> You
|
||||
</Typography.Title>
|
||||
</Card>
|
||||
<p style={{ textAlign: 'center', marginTop: 24 }}>
|
||||
Want to add more pages? Please refer to{' '}
|
||||
<a href="https://pro.ant.design/docs/block-cn" target="_blank" rel="noopener noreferrer">
|
||||
use block
|
||||
</a>
|
||||
。
|
||||
</p>
|
||||
</PageHeaderWrapper>
|
||||
);
|
||||
};
|
||||
|
||||
export default Admin;
|
||||
@@ -1,294 +0,0 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
@import '~antd/es/style/themes/default.less';
|
||||
|
||||
.container {
|
||||
padding: 24px;
|
||||
background: #f0f2f5;
|
||||
min-height: calc(100vh - 48px);
|
||||
|
||||
:global {
|
||||
.ant-card {
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
|
||||
transition: all 0.3s;
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.09);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.statCard {
|
||||
height: auto;
|
||||
min-height: 180px;
|
||||
|
||||
.statHeader {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 16px;
|
||||
|
||||
span {
|
||||
margin-left: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.subStats {
|
||||
margin-top: 16px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-end;
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
|
||||
:global {
|
||||
.ant-statistic {
|
||||
flex: 1;
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
.ant-progress {
|
||||
width: 100px;
|
||||
margin-left: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 图标样式
|
||||
.iconOrders {
|
||||
font-size: 24px;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.iconIncome {
|
||||
font-size: 24px;
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.iconWayline {
|
||||
font-size: 24px;
|
||||
color: #722ed1;
|
||||
}
|
||||
|
||||
.iconDevice {
|
||||
font-size: 24px;
|
||||
color: #faad14;
|
||||
}
|
||||
|
||||
.trend {
|
||||
font-size: 14px;
|
||||
margin-left: 8px;
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.chartsRow {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.businessRow {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.rankList {
|
||||
.rankItem {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.rankNum {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
text-align: center;
|
||||
background: #fafafa;
|
||||
border-radius: 10px;
|
||||
margin-right: 16px;
|
||||
font-size: 12px;
|
||||
color: #8c8c8c;
|
||||
|
||||
&.topThree {
|
||||
color: #fff;
|
||||
&:nth-child(1) { background: #f5222d; }
|
||||
&:nth-child(2) { background: #fa8c16; }
|
||||
&:nth-child(3) { background: #faad14; }
|
||||
}
|
||||
}
|
||||
|
||||
.rankName {
|
||||
flex: 1;
|
||||
color: rgba(0, 0, 0, 0.85);
|
||||
}
|
||||
|
||||
.rankValue {
|
||||
color: rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 响应式调整
|
||||
@media screen and (max-width: 768px) {
|
||||
.container {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.statCard {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.chartsRow, .businessRow {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.subStats {
|
||||
:global {
|
||||
.ant-statistic {
|
||||
min-width: 100px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.pie {
|
||||
margin-top: @margin-md;
|
||||
}
|
||||
|
||||
.chartCard {
|
||||
margin: 24px 0;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
|
||||
|
||||
:global {
|
||||
.ant-tabs-nav {
|
||||
margin-bottom: 16px;
|
||||
padding: 0 24px;
|
||||
}
|
||||
|
||||
.ant-tabs-tab {
|
||||
padding: 12px 0;
|
||||
font-size: 15px;
|
||||
|
||||
&:hover {
|
||||
color: @primary-color;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-tabs-tab-active {
|
||||
.ant-tabs-tab-btn {
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-empty {
|
||||
padding: 32px 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.pieRow {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.pieCard {
|
||||
height: 100%;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
|
||||
|
||||
:global {
|
||||
.ant-card-head {
|
||||
padding: 0 24px;
|
||||
border-bottom: 1px solid @border-color-split;
|
||||
|
||||
.ant-card-head-title {
|
||||
padding: 16px 0;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-card-body {
|
||||
padding: 24px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:global {
|
||||
.ant-pro-card {
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.ant-statistic-title {
|
||||
font-size: 15px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.ant-statistic-content {
|
||||
font-size: 24px;
|
||||
font-weight: 500;
|
||||
|
||||
&-value {
|
||||
color: @heading-color;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-pro-card-statistic-description {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.ant-skeleton {
|
||||
padding: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: @screen-md) {
|
||||
.pieRow {
|
||||
.pieCard {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.statisticIcon {
|
||||
color: #1890ff;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.statisticGroup {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.chartRow {
|
||||
margin-top: 24px;
|
||||
|
||||
.ant-card {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.tourismCard {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
// 响应式调整
|
||||
@media screen and (max-width: 768px) {
|
||||
.statisticGroup {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.chartRow {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.tourismCard {
|
||||
margin-top: 16px;
|
||||
}
|
||||
}
|
||||
@@ -1,754 +0,0 @@
|
||||
import { PageContainer } from '@ant-design/pro-components';
|
||||
import { Card, Row, Col, Statistic, Progress, Typography, Select, DatePicker, Space, Button, Switch, Pagination } from 'antd';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { dashboard, getQrcodeOptions, getDashboardOrders } from '@/services/orders/api';
|
||||
import { Line, Column, Pie } from '@ant-design/plots';
|
||||
import ReactECharts from 'echarts-for-react';
|
||||
import {
|
||||
ShoppingCartOutlined,
|
||||
PayCircleOutlined,
|
||||
RiseOutlined,
|
||||
FilterOutlined,
|
||||
ReloadOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import styles from './Welcome.less';
|
||||
|
||||
const { Title } = Typography;
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
// 平台分账比例选项
|
||||
const PLATFORM_RATE_OPTIONS = [
|
||||
{ label: '90% (平台90%)', value: 0.9 },
|
||||
{ label: '85% (平台85%)', value: 0.85 },
|
||||
{ label: '80% (平台80%)', value: 0.8 },
|
||||
{ label: '75% (平台75%)', value: 0.75 },
|
||||
{ label: '70% (平台70%)', value: 0.7 },
|
||||
{ label: '65% (平台65%)', value: 0.65 },
|
||||
{ label: '60% (平台60%)', value: 0.6 },
|
||||
{ label: '55% (平台55%)', value: 0.55 },
|
||||
{ label: '50% (平台50%)', value: 0.5 },
|
||||
{ label: '45% (平台45%)', value: 0.45 },
|
||||
{ label: '40% (平台40%)', value: 0.4 },
|
||||
{ label: '35% (平台35%)', value: 0.35 },
|
||||
{ label: '30% (平台30%)', value: 0.3 },
|
||||
{ label: '25% (平台25%)', value: 0.25 },
|
||||
{ label: '20% (平台20%)', value: 0.2 },
|
||||
{ label: '15% (平台15%)', value: 0.15 },
|
||||
{ label: '10% (平台10%)', value: 0.1 },
|
||||
{ label: '5% (平台5%)', value: 0.05 },
|
||||
];
|
||||
|
||||
interface Statistics {
|
||||
orderStats: {
|
||||
totalOrders: number;
|
||||
todayOrders: number;
|
||||
orderGrowth: number;
|
||||
completionRate: number;
|
||||
refundedOrders: number; // 退款订单数
|
||||
completedOrders: number; // 总完成订单数
|
||||
totalPaidOrders: number; // 总收款订单数
|
||||
todayPaidOrders: number; // 今日收款订单数
|
||||
// 对账相关字段
|
||||
totalAmount: number; // 订单总金额(分)
|
||||
refundAmount: number; // 退款金额(分)
|
||||
netIncome: number; // 净收入(分)
|
||||
};
|
||||
// 移除设备和航线统计
|
||||
chartStats: {
|
||||
orderTrend: {
|
||||
date: string;
|
||||
type: string;
|
||||
value: number;
|
||||
}[];
|
||||
orderDistribution: {
|
||||
type: string;
|
||||
value: number;
|
||||
}[];
|
||||
incomeBreakdown: {
|
||||
type: string;
|
||||
value: number;
|
||||
}[];
|
||||
qrcodeOrderCount: {
|
||||
qrcodeName: string;
|
||||
qrcodeId: string;
|
||||
orderCount: number;
|
||||
}[];
|
||||
};
|
||||
// 新增筛选维度数据
|
||||
filterOptions: {
|
||||
tourismList: { label: string; value: number; }[];
|
||||
qrcodeList: { label: string; value: string; }[];
|
||||
deviceList: { label: string; value: string; }[];
|
||||
};
|
||||
}
|
||||
|
||||
const Welcome: React.FC = () => {
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [statistics, setStatistics] = useState<any>({});
|
||||
// 只保留景区筛选
|
||||
const [selectedTourism, setSelectedTourism] = useState<number | undefined>();
|
||||
// 新增二维码筛选
|
||||
const [selectedQrcode, setSelectedQrcode] = useState<string | undefined>();
|
||||
// 新增平台分账比例,默认70%
|
||||
const [platformRate, setPlatformRate] = useState<number>(0.7);
|
||||
// 新增时间区间筛选
|
||||
const [timeRange, setTimeRange] = useState<[string, string]>(['', '']);
|
||||
// 新增是否包含测试二维码筛选,默认不包含
|
||||
const [includeTestQrcodes, setIncludeTestQrcodes] = useState<boolean>(false);
|
||||
// 订单列表数据
|
||||
const [orderList, setOrderList] = useState<any[]>([]);
|
||||
const [orderPagination, setOrderPagination] = useState({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const params = {
|
||||
tourismId: selectedTourism,
|
||||
qrcodeId: selectedQrcode,
|
||||
startTime: timeRange[0],
|
||||
endTime: timeRange[1],
|
||||
includeTestQrcodes: includeTestQrcodes,
|
||||
};
|
||||
const result = await dashboard(params);
|
||||
if (result.resp_code === 0) {
|
||||
setStatistics(result.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取统计数据失败:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchOrderList = async (page = 1) => {
|
||||
try {
|
||||
const params = {
|
||||
tourismId: selectedTourism,
|
||||
qrcodeId: selectedQrcode,
|
||||
startTime: timeRange[0],
|
||||
endTime: timeRange[1],
|
||||
includeTestQrcodes: includeTestQrcodes,
|
||||
page: page,
|
||||
limit: orderPagination.pageSize,
|
||||
};
|
||||
const result = await getDashboardOrders(params);
|
||||
if (result.resp_code === 0) {
|
||||
setOrderList(result.data?.data || []);
|
||||
setOrderPagination(prev => ({
|
||||
...prev,
|
||||
current: page,
|
||||
total: result.data?.count || 0,
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取订单列表失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
fetchOrderList(1); // 重置到第一页
|
||||
}, [selectedTourism, selectedQrcode, timeRange, includeTestQrcodes]);
|
||||
|
||||
// 处理景区选择变化
|
||||
const handleTourismChange = (tourismId: number | undefined) => {
|
||||
setSelectedTourism(tourismId);
|
||||
// 当景区变化时,清空二维码选择
|
||||
setSelectedQrcode(undefined);
|
||||
// 重新获取二维码选项
|
||||
fetchQrcodeOptions(tourismId);
|
||||
};
|
||||
|
||||
// 获取当前景区下的二维码选项
|
||||
const getCurrentTourismQrcodes = () => {
|
||||
if (!selectedTourism) return [];
|
||||
// 从筛选选项中获取当前景区的二维码
|
||||
return filterOptions.qrcodeList || [];
|
||||
};
|
||||
|
||||
// 获取二维码列表
|
||||
const fetchQrcodeOptions = async (tourismId: number | undefined) => {
|
||||
if (!tourismId) return;
|
||||
try {
|
||||
const params = {
|
||||
tourismId: tourismId,
|
||||
includeTestQrcodes: includeTestQrcodes,
|
||||
};
|
||||
const result = await getQrcodeOptions(params);
|
||||
if (result.resp_code === 0 && result.data?.qrcodeList) {
|
||||
// 更新二维码选项
|
||||
setStatistics((prev: any) => ({
|
||||
...prev,
|
||||
filterOptions: {
|
||||
...prev.filterOptions,
|
||||
qrcodeList: result.data.qrcodeList
|
||||
}
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取二维码列表失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 更新数据访问方式
|
||||
const orderStats = statistics.orderStats || {};
|
||||
const chartStats = statistics.chartStats || {};
|
||||
const filterOptions = statistics.filterOptions || {};
|
||||
|
||||
// 使用后端返回的基础数据
|
||||
// 订单总金额:orderStatus=3+orderStatus=8的总金额(包含逻辑删除记录)
|
||||
// 退款金额:orderStatus=8的总金额(包含逻辑删除记录)
|
||||
// 净收入:总金额 - 退款金额
|
||||
const totalAmount = orderStats.totalAmount || 0;
|
||||
const refundAmount = orderStats.refundAmount || 0;
|
||||
const netIncome = orderStats.netIncome || 0;
|
||||
|
||||
// 判断是否选择了时间区间
|
||||
const hasTimeRange = timeRange[0] && timeRange[1];
|
||||
|
||||
// 根据时间筛选状态动态显示标题
|
||||
const getOrderTitle = () => {
|
||||
if (hasTimeRange) {
|
||||
return '区间收款数量';
|
||||
}
|
||||
return '总收款数量';
|
||||
};
|
||||
|
||||
const getTodayTitle = () => {
|
||||
if (hasTimeRange) {
|
||||
return '区间总收款'; // 时间筛选时显示区间总收款
|
||||
}
|
||||
return '今日总收款'; // 无时间筛选时显示今日总收款
|
||||
};
|
||||
|
||||
const getTodayValue = () => {
|
||||
if (hasTimeRange) {
|
||||
return orderStats.totalOrders || 0; // 时间筛选时显示区间总订单数
|
||||
}
|
||||
return orderStats.todayOrders || 0; // 无时间筛选时显示今日订单数
|
||||
};
|
||||
|
||||
const getTodayRefundTitle = () => {
|
||||
return '今日退款订单';
|
||||
};
|
||||
|
||||
const getTodayRefundValue = () => {
|
||||
if (hasTimeRange) {
|
||||
return orderStats.refundedOrders || 0; // 时间筛选时显示区间退款订单数
|
||||
}
|
||||
return orderStats.todayRefundedOrders || 0; // 无时间筛选时显示今日退款订单数
|
||||
};
|
||||
|
||||
// 今日收款数量始终显示今日数据,不受时间范围影响
|
||||
const getTodayPaidValue = () => {
|
||||
if (hasTimeRange) {
|
||||
// 时间筛选时:区间收款订单数 = 区间总订单数 - 区间退款订单数
|
||||
const totalOrders = orderStats.totalOrders || 0;
|
||||
const refundedOrders = orderStats.refundedOrders || 0;
|
||||
return totalOrders - refundedOrders;
|
||||
}
|
||||
// 无时间筛选时:今日收款订单数 = 今日总订单数 - 今日退款订单数
|
||||
const todayOrders = orderStats.todayOrders || 0;
|
||||
const todayRefundedOrders = orderStats.todayRefundedOrders || 0;
|
||||
return todayOrders - todayRefundedOrders;
|
||||
};
|
||||
|
||||
// 获取今日收款数量标题
|
||||
const getTodayPaidTitle = () => {
|
||||
if (hasTimeRange) {
|
||||
return '区间净收款'; // 时间筛选时显示区间净收款
|
||||
}
|
||||
return '今日净收款'; // 无时间筛选时显示今日净收款
|
||||
};
|
||||
|
||||
// 获取订单状态文本
|
||||
const getOrderStatusText = (status: number) => {
|
||||
const statusMap: { [key: number]: string } = {
|
||||
0: '待支付',
|
||||
1: '已支付排队中',
|
||||
2: '已取消',
|
||||
3: '设备执行完成',
|
||||
4: '正在服务中',
|
||||
5: '素材上传中',
|
||||
6: '素材上传完成',
|
||||
7: '退款中',
|
||||
8: '已退款',
|
||||
9: '退款失败',
|
||||
};
|
||||
return statusMap[status] || '未知状态';
|
||||
};
|
||||
|
||||
// 时间快捷选择处理函数
|
||||
const handleQuickTimeSelect = (type: 'today' | 'week' | 'month') => {
|
||||
const now = new Date();
|
||||
let startDate: Date;
|
||||
let endDate: Date;
|
||||
|
||||
switch (type) {
|
||||
case 'today':
|
||||
// 自然日:当天 00:00:00 到 23:59:59
|
||||
startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59);
|
||||
console.log('今日筛选 - 当前时间:', now.toISOString());
|
||||
console.log('今日筛选 - 开始时间:', startDate.toISOString());
|
||||
console.log('今日筛选 - 结束时间:', endDate.toISOString());
|
||||
break;
|
||||
case 'week':
|
||||
// 自然周:本周一 00:00:00 到 本周日 23:59:59
|
||||
const dayOfWeek = now.getDay();
|
||||
const daysToMonday = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // 距离本周一的天数
|
||||
startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - daysToMonday);
|
||||
endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + (6 - dayOfWeek), 23, 59, 59);
|
||||
console.log('本周筛选 - 当前时间:', now.toISOString());
|
||||
console.log('本周筛选 - 开始时间:', startDate.toISOString());
|
||||
console.log('本周筛选 - 结束时间:', endDate.toISOString());
|
||||
break;
|
||||
case 'month':
|
||||
// 自然月:本月1号 00:00:00 到 本月最后一天 23:59:59
|
||||
startDate = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
endDate = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59);
|
||||
console.log('本月筛选 - 当前时间:', now.toISOString());
|
||||
console.log('本月筛选 - 开始时间:', startDate.toISOString());
|
||||
console.log('本月筛选 - 结束时间:', endDate.toISOString());
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用本地时间格式化,避免时区问题
|
||||
const formatLocalDateTime = (date: Date) => {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
};
|
||||
|
||||
const timeRangeStrings: [string, string] = [
|
||||
formatLocalDateTime(startDate),
|
||||
formatLocalDateTime(endDate)
|
||||
];
|
||||
|
||||
console.log('设置时间范围:', timeRangeStrings);
|
||||
setTimeRange(timeRangeStrings);
|
||||
};
|
||||
|
||||
// 动态分账金额计算(基于净收入和分账比例)
|
||||
const platformAmount = Math.round(netIncome * platformRate);
|
||||
const tourismAmount = netIncome - platformAmount;
|
||||
|
||||
// 订单趋势配置 - 改为折线图
|
||||
const orderTrendConfig = {
|
||||
data: chartStats.orderTrend || [],
|
||||
xField: 'date',
|
||||
yField: 'value',
|
||||
seriesField: 'type',
|
||||
smooth: true,
|
||||
animation: true,
|
||||
legend: {
|
||||
position: 'top' as const,
|
||||
},
|
||||
// 移除面积图样式,改为折线图
|
||||
line: {
|
||||
size: 2,
|
||||
},
|
||||
point: {
|
||||
size: 4,
|
||||
shape: 'circle',
|
||||
},
|
||||
color: ['#1890ff', '#52c41a', '#faad14'],
|
||||
xAxis: {
|
||||
type: 'time',
|
||||
tickCount: 7,
|
||||
},
|
||||
yAxis: {
|
||||
label: {
|
||||
formatter: (v: any) => `${v}单`,
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
shared: true,
|
||||
showCrosshairs: true,
|
||||
crosshairs: {
|
||||
type: 'xy' as const,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 二维码订单数量配置 - ECharts 横向柱状图(按数量降序排列)
|
||||
const qrcodeOrderData = (chartStats.qrcodeOrderCount || []).sort((a: any, b: any) => b.orderCount - a.orderCount);
|
||||
|
||||
// 确保数据按订单数量从多到少排列,最多的显示在最上面
|
||||
const sortedData = [...qrcodeOrderData].sort((a: any, b: any) => b.orderCount - a.orderCount);
|
||||
|
||||
const qrcodeOrderConfig = {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
axisPointer: {
|
||||
type: 'shadow'
|
||||
},
|
||||
formatter: function(params: any) {
|
||||
const data = params[0];
|
||||
const total = sortedData.reduce((sum: number, item: any) => sum + item.orderCount, 0);
|
||||
const percentage = ((data.value / total) * 100).toFixed(2);
|
||||
return `${data.name}<br/>订单数量: ${data.value}单<br/>占比: ${percentage}%`;
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
left: '15%',
|
||||
right: '15%',
|
||||
bottom: '3%',
|
||||
top: '3%',
|
||||
containLabel: true
|
||||
},
|
||||
xAxis: {
|
||||
type: 'value',
|
||||
name: '订单数量',
|
||||
axisLabel: {
|
||||
formatter: '{value}单',
|
||||
fontSize: 12
|
||||
},
|
||||
nameTextStyle: {
|
||||
fontSize: 12
|
||||
}
|
||||
},
|
||||
yAxis: {
|
||||
type: 'category',
|
||||
name: '二维码',
|
||||
data: sortedData.map((item: any) => item.qrcodeName),
|
||||
axisLabel: {
|
||||
width: 120,
|
||||
overflow: 'truncate',
|
||||
fontSize: 12
|
||||
},
|
||||
nameTextStyle: {
|
||||
fontSize: 12
|
||||
}
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '订单数量',
|
||||
type: 'bar',
|
||||
data: sortedData.map((item: any) => {
|
||||
const total = sortedData.reduce((sum: number, dataItem: any) => sum + dataItem.orderCount, 0);
|
||||
const percentage = ((item.orderCount / total) * 100).toFixed(2);
|
||||
return {
|
||||
value: item.orderCount,
|
||||
itemStyle: {
|
||||
color: '#52c41a' // 绿色,与图片中的颜色一致
|
||||
}
|
||||
};
|
||||
}),
|
||||
itemStyle: {
|
||||
color: '#52c41a'
|
||||
},
|
||||
label: {
|
||||
show: true,
|
||||
position: 'right',
|
||||
formatter: function(params: any) {
|
||||
const total = sortedData.reduce((sum: number, item: any) => sum + item.orderCount, 0);
|
||||
const percentage = ((params.value / total) * 100).toFixed(2);
|
||||
return `${params.value}单 (${percentage}%)`;
|
||||
},
|
||||
fontSize: 11,
|
||||
color: '#666'
|
||||
},
|
||||
barWidth: '60%'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<PageContainer className={styles.container}>
|
||||
|
||||
|
||||
{/* 筛选条件 */}
|
||||
<Card style={{ marginBottom: 16 }}>
|
||||
<Space size="large">
|
||||
<span>筛选条件:</span>
|
||||
<Select
|
||||
placeholder="选择景区"
|
||||
style={{ width: 200 }}
|
||||
allowClear
|
||||
options={filterOptions.tourismList || []}
|
||||
value={selectedTourism}
|
||||
onChange={handleTourismChange}
|
||||
/>
|
||||
{/* 新增二维码选择器 */}
|
||||
<Select
|
||||
placeholder="选择二维码"
|
||||
style={{ width: 250 }}
|
||||
allowClear
|
||||
disabled={!selectedTourism}
|
||||
options={getCurrentTourismQrcodes()}
|
||||
value={selectedQrcode}
|
||||
onChange={setSelectedQrcode}
|
||||
showSearch
|
||||
optionFilterProp="label"
|
||||
filterOption={(input, option) =>
|
||||
(String(option?.label) ?? '').toLowerCase().includes(input.toLowerCase())
|
||||
}
|
||||
/>
|
||||
{/* 新增平台分账比例选择 */}
|
||||
<span>平台分账比例:</span>
|
||||
<Select
|
||||
style={{ width: 140 }}
|
||||
value={platformRate}
|
||||
onChange={setPlatformRate}
|
||||
showSearch
|
||||
placeholder="选择分账比例"
|
||||
optionFilterProp="label"
|
||||
filterOption={(input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
|
||||
}
|
||||
options={PLATFORM_RATE_OPTIONS}
|
||||
/>
|
||||
<span style={{ color: '#666', fontSize: '12px' }}>
|
||||
(当前:平台{Math.round(platformRate * 100)}% | 景区{Math.round((1 - platformRate) * 100)}%)
|
||||
</span>
|
||||
|
||||
{/* 时间快捷选择 */}
|
||||
<Space size="small">
|
||||
<span style={{ color: '#666', fontSize: '12px' }}>时间快捷选择:</span>
|
||||
{[
|
||||
{ key: 'today', label: '今日' },
|
||||
{ key: 'week', label: '本周' },
|
||||
{ key: 'month', label: '本月' }
|
||||
].map(item => (
|
||||
<Button
|
||||
key={item.key}
|
||||
size="small"
|
||||
type={timeRange[0] && timeRange[1] ? 'primary' : 'default'}
|
||||
onClick={() => handleQuickTimeSelect(item.key as 'today' | 'week' | 'month')}
|
||||
style={{ fontSize: '11px', padding: '0 6px' }}
|
||||
>
|
||||
{item.label}
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
{/* 新增时间区间筛选 */}
|
||||
<RangePicker
|
||||
placeholder={['开始时间', '结束时间']}
|
||||
onChange={(dates) => {
|
||||
if (dates) {
|
||||
setTimeRange([
|
||||
dates[0]?.format('YYYY-MM-DD HH:mm:ss') || '',
|
||||
dates[1]?.format('YYYY-MM-DD HH:mm:ss') || ''
|
||||
]);
|
||||
} else {
|
||||
setTimeRange(['', '']);
|
||||
}
|
||||
}}
|
||||
showTime
|
||||
style={{ width: 300 }}
|
||||
/>
|
||||
<Button
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={fetchData}
|
||||
type="primary"
|
||||
>
|
||||
刷新
|
||||
</Button>
|
||||
{/* 新增测试二维码筛选开关 */}
|
||||
<span>包含测试二维码:</span>
|
||||
<Switch
|
||||
checked={includeTestQrcodes}
|
||||
onChange={setIncludeTestQrcodes}
|
||||
checkedChildren="是"
|
||||
unCheckedChildren="否"
|
||||
/>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
{/* 核心指标 */}
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Card className={styles.statCard} loading={loading}>
|
||||
<div className={styles.statHeader}>
|
||||
<ShoppingCartOutlined className={styles.iconOrders} />
|
||||
<span>订单总览</span>
|
||||
</div>
|
||||
<div className="subStats___2WPW1">
|
||||
<Statistic
|
||||
title={getOrderTitle()}
|
||||
value={orderStats.totalOrders || 0}
|
||||
/>
|
||||
<Statistic
|
||||
title={hasTimeRange ? "区间净收款数量" : "总净收款数量"}
|
||||
value={(orderStats.totalOrders || 0) - (orderStats.refundedOrders || 0)}
|
||||
/>
|
||||
<Statistic
|
||||
title={hasTimeRange ? "区间退款订单数" : "总退款订单数"}
|
||||
value={orderStats.refundedOrders || 0}
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.subStats}>
|
||||
<Statistic title={getTodayTitle()} value={getTodayValue()} />
|
||||
<Statistic
|
||||
title={getTodayPaidTitle()}
|
||||
value={getTodayPaidValue()}
|
||||
/>
|
||||
<Statistic
|
||||
title={getTodayRefundTitle()}
|
||||
value={getTodayRefundValue()}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Card className={styles.statCard} loading={loading}>
|
||||
<div className={styles.statHeader}>
|
||||
<PayCircleOutlined className={styles.iconIncome} />
|
||||
<span>收入统计</span>
|
||||
</div>
|
||||
<Statistic
|
||||
title="订单总金额 (有效订单)"
|
||||
value={(orderStats.totalAmount || 0) / 100}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
/>
|
||||
<div className={styles.subStats}>
|
||||
<Statistic
|
||||
title="净收入"
|
||||
value={netIncome / 100}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
/>
|
||||
<Statistic
|
||||
title="退款金额"
|
||||
value={(orderStats.refundAmount || 0) / 100}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
/>
|
||||
</div>
|
||||
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Card className={styles.statCard} loading={loading}>
|
||||
<div className={styles.statHeader}>
|
||||
<PayCircleOutlined className={styles.iconIncome} />
|
||||
<span>分账明细</span>
|
||||
</div>
|
||||
<Statistic
|
||||
title="平台分账"
|
||||
value={platformAmount / 100}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
/>
|
||||
<div className={styles.subStats}>
|
||||
<Statistic
|
||||
title="景区分账"
|
||||
value={tourismAmount / 100}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
/>
|
||||
<Progress
|
||||
percent={netIncome > 0 ? (tourismAmount / netIncome * 100) : 0}
|
||||
size="small"
|
||||
status="active"
|
||||
format={(percent) => `分账率 ${percent?.toFixed(1)}%`}
|
||||
/>
|
||||
|
||||
</div>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 图表展示 */}
|
||||
<Row gutter={[16, 16]} className={styles.chartsRow}>
|
||||
<Col xs={24} lg={16}>
|
||||
<Card title="订单趋势折线图(创建/完成/退款)" loading={loading}>
|
||||
<Line {...orderTrendConfig} height={300} />
|
||||
</Card>
|
||||
</Col>
|
||||
<Col xs={24} lg={8}>
|
||||
<Card title="二维码订单数量" loading={loading}>
|
||||
<ReactECharts
|
||||
option={qrcodeOrderConfig}
|
||||
style={{ height: '300px' }}
|
||||
notMerge={true}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 订单列表 */}
|
||||
<Row gutter={[16, 16]} style={{ marginTop: 24 }}>
|
||||
<Col xs={24}>
|
||||
<Card title="最新订单列表" loading={loading}>
|
||||
<div style={{ maxHeight: '400px', overflowY: 'auto' }}>
|
||||
{orderList.length > 0 ? (
|
||||
<div>
|
||||
{orderList.map((order, index) => (
|
||||
<div
|
||||
key={order.id || index}
|
||||
style={{
|
||||
padding: '12px',
|
||||
borderBottom: '1px solid #f0f0f0',
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
}}
|
||||
>
|
||||
<div style={{ flex: 1 }}>
|
||||
<div style={{ fontWeight: 'bold', marginBottom: '4px' }}>
|
||||
订单号: {order.orderNo}
|
||||
</div>
|
||||
<div style={{ fontSize: '12px', color: '#666' }}>
|
||||
创建时间: {order.createTime}
|
||||
</div>
|
||||
<div style={{ fontSize: '12px', color: '#666' }}>
|
||||
状态: {getOrderStatusText(order.orderStatus)}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ textAlign: 'right' }}>
|
||||
<div style={{ fontWeight: 'bold', color: '#1890ff' }}>
|
||||
¥{(order.orderAmount / 100).toFixed(2)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ textAlign: 'center', padding: '40px', color: '#999' }}>
|
||||
暂无订单数据
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{/* 分页组件 */}
|
||||
{orderPagination.total > 0 && (
|
||||
<div style={{ textAlign: 'center', marginTop: '16px' }}>
|
||||
<Pagination
|
||||
current={orderPagination.current}
|
||||
pageSize={orderPagination.pageSize}
|
||||
total={orderPagination.total}
|
||||
showSizeChanger={false}
|
||||
showQuickJumper
|
||||
showTotal={(total, range) =>
|
||||
`第 ${range[0]}-${range[1]} 条,共 ${total} 条`
|
||||
}
|
||||
onChange={(page) => {
|
||||
fetchOrderList(page);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default Welcome;
|
||||
@@ -1,248 +0,0 @@
|
||||
import React, { useState } from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import { Card, Row, Col, Descriptions, Tag, Timeline, Table, Statistic } from 'antd';
|
||||
import { Line } from '@ant-design/plots';
|
||||
import { useParams } from 'umi';
|
||||
|
||||
interface DeviceDetail {
|
||||
id: string;
|
||||
name: string;
|
||||
type: string;
|
||||
status: string;
|
||||
model: string;
|
||||
serialNumber: string;
|
||||
location: string;
|
||||
installDate: string;
|
||||
lastMaintenance: string;
|
||||
nextMaintenance: string;
|
||||
manufacturer: string;
|
||||
specifications: string;
|
||||
}
|
||||
|
||||
interface MaintenanceRecord {
|
||||
id: string;
|
||||
date: string;
|
||||
type: string;
|
||||
operator: string;
|
||||
description: string;
|
||||
result: string;
|
||||
}
|
||||
|
||||
interface AlertRecord {
|
||||
id: string;
|
||||
time: string;
|
||||
type: string;
|
||||
level: string;
|
||||
message: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
const mockDeviceDetail: DeviceDetail = {
|
||||
id: '1',
|
||||
name: '设备A',
|
||||
type: '传感器',
|
||||
status: '在线',
|
||||
model: 'SENSOR-2024',
|
||||
serialNumber: 'SN20240320001',
|
||||
location: '1号车间',
|
||||
installDate: '2024-01-15',
|
||||
lastMaintenance: '2024-02-15',
|
||||
nextMaintenance: '2024-04-15',
|
||||
manufacturer: '某某科技',
|
||||
specifications: '温度范围:-20℃~80℃,精度:±0.1℃',
|
||||
};
|
||||
|
||||
const mockMaintenanceRecords: MaintenanceRecord[] = [
|
||||
{
|
||||
id: '1',
|
||||
date: '2024-02-15',
|
||||
type: '定期保养',
|
||||
operator: '张三',
|
||||
description: '更换滤芯,校准参数',
|
||||
result: '正常',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
date: '2024-01-15',
|
||||
type: '安装调试',
|
||||
operator: '李四',
|
||||
description: '设备安装及初始调试',
|
||||
result: '正常',
|
||||
},
|
||||
];
|
||||
|
||||
const mockAlertRecords: AlertRecord[] = [
|
||||
{
|
||||
id: '1',
|
||||
time: '2024-03-20 09:30:00',
|
||||
type: '温度告警',
|
||||
level: '高',
|
||||
message: '设备温度超过阈值',
|
||||
status: '已处理',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
time: '2024-03-19 15:20:00',
|
||||
type: '通信告警',
|
||||
level: '中',
|
||||
message: '设备通信中断',
|
||||
status: '已处理',
|
||||
},
|
||||
];
|
||||
|
||||
// 模拟性能数据
|
||||
const generatePerformanceData = () => {
|
||||
const data = [];
|
||||
for (let i = 0; i < 24; i++) {
|
||||
data.push({
|
||||
time: `${i}:00`,
|
||||
value: Math.floor(Math.random() * 100),
|
||||
type: 'CPU使用率',
|
||||
});
|
||||
data.push({
|
||||
time: `${i}:00`,
|
||||
value: Math.floor(Math.random() * 100),
|
||||
type: '内存使用率',
|
||||
});
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
const DeviceDetailPage: React.FC = () => {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const [deviceDetail] = useState<DeviceDetail>(mockDeviceDetail);
|
||||
const [maintenanceRecords] = useState<MaintenanceRecord[]>(mockMaintenanceRecords);
|
||||
const [alertRecords] = useState<AlertRecord[]>(mockAlertRecords);
|
||||
const [performanceData] = useState(generatePerformanceData());
|
||||
|
||||
const getStatusColor = (status: string) => {
|
||||
return status === '在线' ? 'green' : 'red';
|
||||
};
|
||||
|
||||
const getAlertLevelColor = (level: string) => {
|
||||
const colorMap: Record<string, string> = {
|
||||
'高': 'red',
|
||||
'中': 'orange',
|
||||
'低': 'blue',
|
||||
};
|
||||
return colorMap[level] || 'default';
|
||||
};
|
||||
|
||||
const maintenanceColumns = [
|
||||
{ title: '日期', dataIndex: 'date' },
|
||||
{ title: '类型', dataIndex: 'type' },
|
||||
{ title: '操作人', dataIndex: 'operator' },
|
||||
{ title: '描述', dataIndex: 'description' },
|
||||
{ title: '结果', dataIndex: 'result' },
|
||||
];
|
||||
|
||||
const alertColumns = [
|
||||
{ title: '时间', dataIndex: 'time' },
|
||||
{ title: '类型', dataIndex: 'type' },
|
||||
{
|
||||
title: '级别',
|
||||
dataIndex: 'level',
|
||||
render: (level: string) => (
|
||||
<Tag color={getAlertLevelColor(level)}>{level}</Tag>
|
||||
),
|
||||
},
|
||||
{ title: '信息', dataIndex: 'message' },
|
||||
{ title: '状态', dataIndex: 'status' },
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={24}>
|
||||
<Card title="设备基本信息">
|
||||
<Descriptions bordered>
|
||||
<Descriptions.Item label="设备名称">{deviceDetail.name}</Descriptions.Item>
|
||||
<Descriptions.Item label="设备类型">{deviceDetail.type}</Descriptions.Item>
|
||||
<Descriptions.Item label="设备状态">
|
||||
<Tag color={getStatusColor(deviceDetail.status)}>{deviceDetail.status}</Tag>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="设备型号">{deviceDetail.model}</Descriptions.Item>
|
||||
<Descriptions.Item label="序列号">{deviceDetail.serialNumber}</Descriptions.Item>
|
||||
<Descriptions.Item label="安装位置">{deviceDetail.location}</Descriptions.Item>
|
||||
<Descriptions.Item label="安装日期">{deviceDetail.installDate}</Descriptions.Item>
|
||||
<Descriptions.Item label="上次维护">{deviceDetail.lastMaintenance}</Descriptions.Item>
|
||||
<Descriptions.Item label="下次维护">{deviceDetail.nextMaintenance}</Descriptions.Item>
|
||||
<Descriptions.Item label="制造商">{deviceDetail.manufacturer}</Descriptions.Item>
|
||||
<Descriptions.Item label="规格参数">{deviceDetail.specifications}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
|
||||
<Col span={8}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="运行时长"
|
||||
value={45}
|
||||
suffix="天"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="告警次数"
|
||||
value={alertRecords.length}
|
||||
valueStyle={{ color: alertRecords.length > 0 ? '#cf1322' : '#3f8600' }}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="维护次数"
|
||||
value={maintenanceRecords.length}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Card title="性能监控" style={{ marginTop: 16 }}>
|
||||
<Line
|
||||
data={performanceData}
|
||||
xField="time"
|
||||
yField="value"
|
||||
seriesField="type"
|
||||
smooth
|
||||
animation={{
|
||||
appear: {
|
||||
animation: 'path-in',
|
||||
duration: 1000,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
|
||||
<Col span={12}>
|
||||
<Card title="维护记录">
|
||||
<Table
|
||||
dataSource={maintenanceRecords}
|
||||
columns={maintenanceColumns}
|
||||
rowKey="id"
|
||||
pagination={false}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Card title="告警记录">
|
||||
<Table
|
||||
dataSource={alertRecords}
|
||||
columns={alertColumns}
|
||||
rowKey="id"
|
||||
pagination={false}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default DeviceDetailPage;
|
||||
@@ -1,471 +0,0 @@
|
||||
import React, { useRef, useState, useEffect } from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import type { ProColumns} from '@ant-design/pro-components';
|
||||
import { ProTable, ModalForm, ProFormText, ProFormSelect, ProFormUploadButton } from '@ant-design/pro-components';
|
||||
import { Button, Space, message, Popconfirm, Tag, Select, Modal, Dropdown, Menu, Upload, Card, Row, Col, Statistic } from 'antd';
|
||||
import { history } from 'umi';
|
||||
import { DownOutlined, UploadOutlined, DownloadOutlined, FileExcelOutlined, CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons';
|
||||
import type { UploadFile } from 'antd/es/upload/interface';
|
||||
import * as XLSX from 'xlsx';
|
||||
import { Pie, Column } from '@ant-design/plots';
|
||||
import { device, saveOrUpdateDevice, deleteDevice } from '@/services/device/api';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
interface Device {
|
||||
deviceSn: string;
|
||||
deviceName: string;
|
||||
nickname: string;
|
||||
deviceType: number;
|
||||
firmwareVersion: string;
|
||||
compatibleStatus: number;
|
||||
boundStatus: number;
|
||||
createTime: string;
|
||||
loginTime: string;
|
||||
}
|
||||
|
||||
const DEVICE_TYPE = {
|
||||
DOCK: 1,
|
||||
DRONE: 2,
|
||||
REMOTE_CONTROL: 3,
|
||||
} as const;
|
||||
|
||||
const DEVICE_TYPE_OPTIONS = [
|
||||
{ label: '机场', value: DEVICE_TYPE.DOCK },
|
||||
{ label: '无人机', value: DEVICE_TYPE.DRONE },
|
||||
{ label: '遥控器', value: DEVICE_TYPE.REMOTE_CONTROL },
|
||||
];
|
||||
|
||||
const COMPATIBLE_STATUS = {
|
||||
INCONSISTENT: 0,
|
||||
CONSISTENT: 1,
|
||||
} as const;
|
||||
|
||||
const DeviceList: React.FC = () => {
|
||||
const [createModalVisible, setCreateModalVisible] = useState(false);
|
||||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||||
const [currentRow, setCurrentRow] = useState<Device>();
|
||||
const [selectedGroup, setSelectedGroup] = useState<string>('all');
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
|
||||
const [batchGroupModalVisible, setBatchGroupModalVisible] = useState(false);
|
||||
const [batchStatusModalVisible, setBatchStatusModalVisible] = useState(false);
|
||||
const [importModalVisible, setImportModalVisible] = useState(false);
|
||||
const [importFileList, setImportFileList] = useState<UploadFile[]>([]);
|
||||
const [statistics, setStatistics] = useState({
|
||||
total: 0,
|
||||
online: 0,
|
||||
offline: 0,
|
||||
byType: {} as Record<string, number>,
|
||||
});
|
||||
const actionRef = useRef<any>();
|
||||
|
||||
// 计算统计数据
|
||||
const calculateStatistics = (data: Device[]) => {
|
||||
const stats = {
|
||||
total: data.length,
|
||||
online: data.filter(item => item.boundStatus === 1).length,
|
||||
offline: data.filter(item => item.boundStatus === 0).length,
|
||||
byType: {} as Record<string, number>,
|
||||
};
|
||||
|
||||
// 按类型统计
|
||||
data.forEach(item => {
|
||||
const typeName = DEVICE_TYPE_OPTIONS.find(opt => opt.value === item.deviceType)?.label || '未知';
|
||||
stats.byType[typeName] = (stats.byType[typeName] || 0) + 1;
|
||||
});
|
||||
|
||||
return stats;
|
||||
};
|
||||
|
||||
const handleAdd = async (values: any) => {
|
||||
try {
|
||||
const response = await saveOrUpdateDevice({
|
||||
...values,
|
||||
deviceType: Number(values.deviceType),
|
||||
});
|
||||
if (response.resp_code === 0) {
|
||||
message.success('新增成功');
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
message.error(response.resp_msg || '新增失败');
|
||||
return false;
|
||||
} catch (error) {
|
||||
message.error('新增失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = async (values: any) => {
|
||||
try {
|
||||
const response = await saveOrUpdateDevice({
|
||||
...values,
|
||||
deviceType: Number(values.deviceType),
|
||||
});
|
||||
if (response.resp_code === 0) {
|
||||
message.success('编辑成功');
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
message.error(response.resp_msg || '编辑失败');
|
||||
return false;
|
||||
} catch (error) {
|
||||
message.error('编辑失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (deviceSn: string) => {
|
||||
try {
|
||||
const response = await deleteDevice(deviceSn);
|
||||
if (response.resp_code === 0) {
|
||||
message.success('删除成功');
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
} else {
|
||||
message.error(response.resp_msg || '删除失败');
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleBatchDelete = async () => {
|
||||
if (selectedRowKeys.length === 0) {
|
||||
message.warning('请选择要删除的设备');
|
||||
return;
|
||||
}
|
||||
Modal.confirm({
|
||||
title: '批量删除',
|
||||
content: `确定要删除选中的 ${selectedRowKeys.length} 个设备吗?`,
|
||||
onOk: async () => {
|
||||
try {
|
||||
const promises = selectedRowKeys.map(key => deleteDevice(key));
|
||||
await Promise.all(promises);
|
||||
message.success('批量删除成功');
|
||||
setSelectedRowKeys([]);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('批量删除失败');
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const columns: ProColumns<Device>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 48,
|
||||
},
|
||||
{
|
||||
title: '设备序列号',
|
||||
dataIndex: 'deviceSn',
|
||||
copyable: true,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
title: '设备名称',
|
||||
dataIndex: 'deviceName',
|
||||
},
|
||||
{
|
||||
title: '昵称',
|
||||
dataIndex: 'nickname',
|
||||
},
|
||||
{
|
||||
title: '设备类型',
|
||||
dataIndex: 'deviceType',
|
||||
valueType: 'select',
|
||||
valueEnum: {
|
||||
[DEVICE_TYPE.DOCK]: { text: '机场' },
|
||||
[DEVICE_TYPE.DRONE]: { text: '无人机' },
|
||||
[DEVICE_TYPE.REMOTE_CONTROL]: { text: '遥控器' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '固件版本',
|
||||
dataIndex: 'firmwareVersion',
|
||||
},
|
||||
{
|
||||
title: '固件状态',
|
||||
dataIndex: 'compatibleStatus',
|
||||
valueType: 'select',
|
||||
valueEnum: {
|
||||
[COMPATIBLE_STATUS.CONSISTENT]: { text: '一致', status: 'Success' },
|
||||
[COMPATIBLE_STATUS.INCONSISTENT]: { text: '不一致', status: 'Error' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '绑定状态',
|
||||
dataIndex: 'boundStatus',
|
||||
render: (_, record) => (
|
||||
<Tag color={record.boundStatus === 1 ? 'green' : 'red'}>
|
||||
{record.boundStatus === 1 ? <CheckCircleOutlined /> : <CloseCircleOutlined />}
|
||||
{record.boundStatus === 1 ? '已绑定' : '未绑定'}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '最后登录',
|
||||
dataIndex: 'loginTime',
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
valueType: 'option',
|
||||
render: (_, record) => [
|
||||
<a
|
||||
key="edit"
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
setEditModalVisible(true);
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</a>,
|
||||
<Popconfirm
|
||||
key="delete"
|
||||
title="确定要删除这个设备吗?"
|
||||
onConfirm={() => handleDelete(record.deviceSn)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>,
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
{/* 统计卡片 */}
|
||||
<Row gutter={16} style={{ marginBottom: 24 }}>
|
||||
<Col span={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="设备总数"
|
||||
value={statistics.total}
|
||||
suffix="台"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="在线设备"
|
||||
value={statistics.online}
|
||||
suffix="台"
|
||||
valueStyle={{ color: '#3f8600' }}
|
||||
prefix={<CheckCircleOutlined />}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="离线设备"
|
||||
value={statistics.offline}
|
||||
suffix="台"
|
||||
valueStyle={{ color: '#cf1322' }}
|
||||
prefix={<CloseCircleOutlined />}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="设备类型数"
|
||||
value={Object.keys(statistics.byType).length}
|
||||
suffix="种"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<ProTable<Device>
|
||||
headerTitle="设备管理"
|
||||
actionRef={actionRef}
|
||||
rowKey="deviceSn"
|
||||
search={{
|
||||
labelWidth: 120,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button
|
||||
key="button"
|
||||
icon={<DownloadOutlined />}
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
// 导出功能待实现
|
||||
message.info('导出功能开发中');
|
||||
}}
|
||||
>
|
||||
导出
|
||||
</Button>,
|
||||
<Button
|
||||
key="button"
|
||||
icon={<UploadOutlined />}
|
||||
onClick={() => {
|
||||
setImportModalVisible(true);
|
||||
}}
|
||||
>
|
||||
导入
|
||||
</Button>,
|
||||
<Button
|
||||
key="button"
|
||||
icon={<FileExcelOutlined />}
|
||||
onClick={() => {
|
||||
// 下载模板功能待实现
|
||||
message.info('下载模板功能开发中');
|
||||
}}
|
||||
>
|
||||
下载模板
|
||||
</Button>,
|
||||
<Button
|
||||
key="button"
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
setCreateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
新增
|
||||
</Button>,
|
||||
]}
|
||||
request={async (params) => {
|
||||
const response = await device({
|
||||
page: params.current,
|
||||
limit: params.pageSize,
|
||||
searchKey: params.searchKey,
|
||||
searchValue: params.searchValue,
|
||||
});
|
||||
|
||||
if (response.resp_code === 0) {
|
||||
const data = response.data || [];
|
||||
setStatistics(calculateStatistics(data));
|
||||
return {
|
||||
data,
|
||||
success: true,
|
||||
total: response.count || 0,
|
||||
};
|
||||
}
|
||||
return {
|
||||
data: [],
|
||||
success: false,
|
||||
total: 0,
|
||||
};
|
||||
}}
|
||||
columns={columns}
|
||||
rowSelection={{
|
||||
selectedRowKeys,
|
||||
onChange: (keys) => setSelectedRowKeys(keys as string[]),
|
||||
}}
|
||||
/>
|
||||
|
||||
<ModalForm
|
||||
title="新增设备"
|
||||
width="400px"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={setCreateModalVisible}
|
||||
onFinish={handleAdd}
|
||||
>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '请输入设备序列号' }]}
|
||||
label="设备序列号"
|
||||
name="deviceSn"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '请输入设备名称' }]}
|
||||
label="设备名称"
|
||||
name="deviceName"
|
||||
/>
|
||||
<ProFormText
|
||||
label="昵称"
|
||||
name="nickname"
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '请选择设备类型' }]}
|
||||
label="设备类型"
|
||||
name="deviceType"
|
||||
options={DEVICE_TYPE_OPTIONS}
|
||||
/>
|
||||
<ProFormText
|
||||
label="固件版本"
|
||||
name="firmwareVersion"
|
||||
/>
|
||||
</ModalForm>
|
||||
|
||||
<ModalForm
|
||||
title="编辑设备"
|
||||
width="400px"
|
||||
visible={editModalVisible}
|
||||
onVisibleChange={setEditModalVisible}
|
||||
onFinish={handleEdit}
|
||||
initialValues={currentRow}
|
||||
>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '请输入设备序列号' }]}
|
||||
label="设备序列号"
|
||||
name="deviceSn"
|
||||
disabled
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '请输入设备名称' }]}
|
||||
label="设备名称"
|
||||
name="deviceName"
|
||||
/>
|
||||
<ProFormText
|
||||
label="昵称"
|
||||
name="nickname"
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '请选择设备类型' }]}
|
||||
label="设备类型"
|
||||
name="deviceType"
|
||||
options={DEVICE_TYPE_OPTIONS}
|
||||
/>
|
||||
<ProFormText
|
||||
label="固件版本"
|
||||
name="firmwareVersion"
|
||||
/>
|
||||
</ModalForm>
|
||||
|
||||
<Modal
|
||||
title="导入设备"
|
||||
visible={importModalVisible}
|
||||
onCancel={() => setImportModalVisible(false)}
|
||||
footer={null}
|
||||
>
|
||||
<Upload
|
||||
fileList={importFileList}
|
||||
onChange={({ fileList }) => setImportFileList(fileList)}
|
||||
beforeUpload={() => false}
|
||||
>
|
||||
<Button icon={<UploadOutlined />}>选择文件</Button>
|
||||
</Upload>
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
// 导入功能待实现
|
||||
message.info('导入功能开发中');
|
||||
setImportModalVisible(false);
|
||||
}}
|
||||
>
|
||||
开始导入
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default DeviceList;
|
||||
@@ -1,300 +0,0 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import type { ProColumns} from '@ant-design/pro-components';
|
||||
import { ProTable, ModalForm, ProFormText, ProFormSelect } from '@ant-design/pro-components';
|
||||
import { Button, Space, message, Popconfirm, Tag, Card, Row, Col, Statistic } from 'antd';
|
||||
import { Pie } from '@ant-design/plots';
|
||||
import { device } from '@/services/device/api';
|
||||
|
||||
interface Device {
|
||||
deviceSn: string;
|
||||
deviceName: string;
|
||||
deviceType: number;
|
||||
boundStatus: number;
|
||||
createTime: string;
|
||||
loginTime: string;
|
||||
}
|
||||
|
||||
interface DeviceGroup {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
deviceCount: number;
|
||||
createTime: string;
|
||||
}
|
||||
|
||||
const DEVICE_TYPE = {
|
||||
DOCK: 1,
|
||||
DRONE: 2,
|
||||
REMOTE_CONTROL: 3,
|
||||
} as const;
|
||||
|
||||
const DEVICE_TYPE_OPTIONS = [
|
||||
{ label: '机场', value: DEVICE_TYPE.DOCK },
|
||||
{ label: '无人机', value: DEVICE_TYPE.DRONE },
|
||||
{ label: '遥控器', value: DEVICE_TYPE.REMOTE_CONTROL },
|
||||
];
|
||||
|
||||
const DeviceGroup: React.FC = () => {
|
||||
const [createModalVisible, setCreateModalVisible] = useState(false);
|
||||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||||
const [currentRow, setCurrentRow] = useState<DeviceGroup>();
|
||||
const [deviceList, setDeviceList] = useState<Device[]>([]);
|
||||
const [statistics, setStatistics] = useState({
|
||||
totalGroups: 0,
|
||||
totalDevices: 0,
|
||||
byType: {} as Record<string, number>,
|
||||
});
|
||||
const actionRef = useRef<any>();
|
||||
|
||||
// 获取设备列表
|
||||
const fetchDeviceList = async () => {
|
||||
try {
|
||||
const response = await device({
|
||||
page: 1,
|
||||
limit: 1000,
|
||||
});
|
||||
if (response.resp_code === 0) {
|
||||
const data = response.data || [];
|
||||
setDeviceList(data);
|
||||
|
||||
// 计算统计数据
|
||||
const stats = {
|
||||
totalGroups: 0, // 待实现
|
||||
totalDevices: data.length,
|
||||
byType: {} as Record<string, number>,
|
||||
};
|
||||
|
||||
// 按类型统计
|
||||
data.forEach((item: Device) => {
|
||||
const typeName = DEVICE_TYPE_OPTIONS.find(opt => opt.value === item.deviceType)?.label || '未知';
|
||||
stats.byType[typeName] = (stats.byType[typeName] || 0) + 1;
|
||||
});
|
||||
|
||||
setStatistics(stats);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取设备列表失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAdd = async (values: any) => {
|
||||
try {
|
||||
// 待实现:调用创建分组API
|
||||
message.success('新增成功');
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
message.error('新增失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = async (values: any) => {
|
||||
try {
|
||||
// 待实现:调用更新分组API
|
||||
message.success('编辑成功');
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
message.error('编辑失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
try {
|
||||
// 待实现:调用删除分组API
|
||||
message.success('删除成功');
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
const columns: ProColumns<DeviceGroup>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 48,
|
||||
},
|
||||
{
|
||||
title: '分组名称',
|
||||
dataIndex: 'name',
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'description',
|
||||
},
|
||||
{
|
||||
title: '设备数量',
|
||||
dataIndex: 'deviceCount',
|
||||
sorter: (a, b) => a.deviceCount - b.deviceCount,
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
valueType: 'option',
|
||||
render: (_, record) => [
|
||||
<a
|
||||
key="edit"
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
setEditModalVisible(true);
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</a>,
|
||||
<Popconfirm
|
||||
key="delete"
|
||||
title="确定要删除这个分组吗?"
|
||||
onConfirm={() => handleDelete(record.id)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>,
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
// 准备图表数据
|
||||
const typeChartData = Object.entries(statistics.byType).map(([type, count]) => ({
|
||||
type,
|
||||
value: count,
|
||||
}));
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
{/* 统计卡片 */}
|
||||
<Row gutter={16} style={{ marginBottom: 24 }}>
|
||||
<Col span={8}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="分组总数"
|
||||
value={statistics.totalGroups}
|
||||
suffix="个"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="设备总数"
|
||||
value={statistics.totalDevices}
|
||||
suffix="台"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="设备类型数"
|
||||
value={Object.keys(statistics.byType).length}
|
||||
suffix="种"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 设备类型分布图 */}
|
||||
<Row gutter={16} style={{ marginBottom: 24 }}>
|
||||
<Col span={24}>
|
||||
<Card title="设备类型分布">
|
||||
<Pie
|
||||
data={typeChartData}
|
||||
angleField="value"
|
||||
colorField="type"
|
||||
radius={0.8}
|
||||
label={{
|
||||
type: 'outer',
|
||||
content: '{name} {percentage}',
|
||||
}}
|
||||
interactions={[
|
||||
{
|
||||
type: 'element-active',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<ProTable<DeviceGroup>
|
||||
headerTitle="设备分组"
|
||||
actionRef={actionRef}
|
||||
rowKey="id"
|
||||
search={{
|
||||
labelWidth: 120,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button
|
||||
key="button"
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
setCreateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
新增分组
|
||||
</Button>,
|
||||
]}
|
||||
request={async (params) => {
|
||||
// 待实现:调用获取分组列表API
|
||||
return {
|
||||
data: [],
|
||||
success: true,
|
||||
total: 0,
|
||||
};
|
||||
}}
|
||||
columns={columns}
|
||||
/>
|
||||
|
||||
<ModalForm
|
||||
title="新增分组"
|
||||
width="400px"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={setCreateModalVisible}
|
||||
onFinish={handleAdd}
|
||||
>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '请输入分组名称' }]}
|
||||
label="分组名称"
|
||||
name="name"
|
||||
/>
|
||||
<ProFormText
|
||||
label="描述"
|
||||
name="description"
|
||||
/>
|
||||
</ModalForm>
|
||||
|
||||
<ModalForm
|
||||
title="编辑分组"
|
||||
width="400px"
|
||||
visible={editModalVisible}
|
||||
onVisibleChange={setEditModalVisible}
|
||||
onFinish={handleEdit}
|
||||
initialValues={currentRow}
|
||||
>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '请输入分组名称' }]}
|
||||
label="分组名称"
|
||||
name="name"
|
||||
/>
|
||||
<ProFormText
|
||||
label="描述"
|
||||
name="description"
|
||||
/>
|
||||
</ModalForm>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default DeviceGroup;
|
||||
@@ -1,276 +0,0 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import type { ProColumns} from '@ant-design/pro-components';
|
||||
import { ProTable, ModalForm, ProFormText, ProFormSelect, ProFormDatePicker } from '@ant-design/pro-components';
|
||||
import { Button, Space, message, Popconfirm, Tag } from 'antd';
|
||||
|
||||
interface MaintenanceTask {
|
||||
id: string;
|
||||
deviceName: string;
|
||||
taskType: string;
|
||||
status: string;
|
||||
priority: string;
|
||||
assignee: string;
|
||||
startTime: string;
|
||||
endTime?: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
const TASK_TYPE_OPTIONS = [
|
||||
{ label: '日常巡检', value: '日常巡检' },
|
||||
{ label: '故障维修', value: '故障维修' },
|
||||
{ label: '设备保养', value: '设备保养' },
|
||||
{ label: '系统升级', value: '系统升级' },
|
||||
];
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ label: '待处理', value: '待处理' },
|
||||
{ label: '进行中', value: '进行中' },
|
||||
{ label: '已完成', value: '已完成' },
|
||||
{ label: '已取消', value: '已取消' },
|
||||
];
|
||||
|
||||
const PRIORITY_OPTIONS = [
|
||||
{ label: '高', value: '高' },
|
||||
{ label: '中', value: '中' },
|
||||
{ label: '低', value: '低' },
|
||||
];
|
||||
|
||||
const initialMockData: MaintenanceTask[] = [
|
||||
{
|
||||
id: '1',
|
||||
deviceName: '设备A',
|
||||
taskType: '日常巡检',
|
||||
status: '待处理',
|
||||
priority: '高',
|
||||
assignee: '张三',
|
||||
startTime: '2024-03-20 10:00:00',
|
||||
description: '定期设备巡检',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
deviceName: '设备B',
|
||||
taskType: '故障维修',
|
||||
status: '进行中',
|
||||
priority: '高',
|
||||
assignee: '李四',
|
||||
startTime: '2024-03-19 14:30:00',
|
||||
description: '设备异常报警处理',
|
||||
},
|
||||
];
|
||||
|
||||
const MaintenanceList: React.FC = () => {
|
||||
const [data, setData] = useState<MaintenanceTask[]>(initialMockData);
|
||||
const [createModalVisible, setCreateModalVisible] = useState(false);
|
||||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||||
const [currentRow, setCurrentRow] = useState<MaintenanceTask | undefined>();
|
||||
const actionRef = useRef<any>();
|
||||
|
||||
const handleAdd = async (values: MaintenanceTask) => {
|
||||
setData([...data, { ...values, id: Date.now().toString() }]);
|
||||
message.success('新增成功');
|
||||
return true;
|
||||
};
|
||||
|
||||
const handleEdit = async (values: MaintenanceTask) => {
|
||||
setData(data.map((item) => (item.id === values.id ? { ...item, ...values } : item)));
|
||||
message.success('编辑成功');
|
||||
return true;
|
||||
};
|
||||
|
||||
const handleDelete = async (record: MaintenanceTask) => {
|
||||
setData(data.filter((item) => item.id !== record.id));
|
||||
message.success('删除成功');
|
||||
};
|
||||
|
||||
const getStatusColor = (status: string) => {
|
||||
const colorMap: Record<string, string> = {
|
||||
'待处理': 'orange',
|
||||
'进行中': 'blue',
|
||||
'已完成': 'green',
|
||||
'已取消': 'red',
|
||||
};
|
||||
return colorMap[status] || 'default';
|
||||
};
|
||||
|
||||
const getPriorityColor = (priority: string) => {
|
||||
const colorMap: Record<string, string> = {
|
||||
'高': 'red',
|
||||
'中': 'orange',
|
||||
'低': 'green',
|
||||
};
|
||||
return colorMap[priority] || 'default';
|
||||
};
|
||||
|
||||
const columns: ProColumns<MaintenanceTask>[] = [
|
||||
{ title: '设备名称', dataIndex: 'deviceName' },
|
||||
{ title: '任务类型', dataIndex: 'taskType' },
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
render: (_, record) => (
|
||||
<Tag color={getStatusColor(record.status)}>{record.status}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '优先级',
|
||||
dataIndex: 'priority',
|
||||
render: (_, record) => (
|
||||
<Tag color={getPriorityColor(record.priority)}>{record.priority}</Tag>
|
||||
),
|
||||
},
|
||||
{ title: '负责人', dataIndex: 'assignee' },
|
||||
{ title: '开始时间', dataIndex: 'startTime' },
|
||||
{ title: '结束时间', dataIndex: 'endTime' },
|
||||
{ title: '描述', dataIndex: 'description', ellipsis: true },
|
||||
{
|
||||
title: '操作',
|
||||
valueType: 'option',
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<a
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
setEditModalVisible(true);
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</a>
|
||||
<Popconfirm title="确定要删除吗?" onConfirm={() => handleDelete(record)}>
|
||||
<a style={{ color: 'red' }}>删除</a>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<ProTable<MaintenanceTask>
|
||||
headerTitle="运维任务列表"
|
||||
rowKey="id"
|
||||
search={false}
|
||||
dataSource={data}
|
||||
columns={columns}
|
||||
actionRef={actionRef}
|
||||
toolBarRender={() => [
|
||||
<Button type="primary" key="add" onClick={() => setCreateModalVisible(true)}>
|
||||
新增任务
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
{/* 新增任务弹窗 */}
|
||||
<ModalForm
|
||||
title="新增运维任务"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={setCreateModalVisible}
|
||||
onFinish={async (values) => {
|
||||
await handleAdd(values as MaintenanceTask);
|
||||
setCreateModalVisible(false);
|
||||
return true;
|
||||
}}
|
||||
>
|
||||
<ProFormText
|
||||
name="deviceName"
|
||||
label="设备名称"
|
||||
rules={[{ required: true, message: '请输入设备名称' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="taskType"
|
||||
label="任务类型"
|
||||
options={TASK_TYPE_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择任务类型' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="status"
|
||||
label="状态"
|
||||
options={STATUS_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="priority"
|
||||
label="优先级"
|
||||
options={PRIORITY_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择优先级' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
name="assignee"
|
||||
label="负责人"
|
||||
rules={[{ required: true, message: '请输入负责人' }]}
|
||||
/>
|
||||
<ProFormDatePicker
|
||||
name="startTime"
|
||||
label="开始时间"
|
||||
rules={[{ required: true, message: '请选择开始时间' }]}
|
||||
/>
|
||||
<ProFormDatePicker
|
||||
name="endTime"
|
||||
label="结束时间"
|
||||
/>
|
||||
<ProFormText
|
||||
name="description"
|
||||
label="描述"
|
||||
rules={[{ required: true, message: '请输入任务描述' }]}
|
||||
/>
|
||||
</ModalForm>
|
||||
{/* 编辑任务弹窗 */}
|
||||
<ModalForm
|
||||
title="编辑运维任务"
|
||||
visible={editModalVisible}
|
||||
onVisibleChange={setEditModalVisible}
|
||||
initialValues={currentRow}
|
||||
onFinish={async (values) => {
|
||||
await handleEdit({ ...currentRow, ...values } as MaintenanceTask);
|
||||
setEditModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
return true;
|
||||
}}
|
||||
>
|
||||
<ProFormText
|
||||
name="deviceName"
|
||||
label="设备名称"
|
||||
rules={[{ required: true, message: '请输入设备名称' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="taskType"
|
||||
label="任务类型"
|
||||
options={TASK_TYPE_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择任务类型' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="status"
|
||||
label="状态"
|
||||
options={STATUS_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="priority"
|
||||
label="优先级"
|
||||
options={PRIORITY_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择优先级' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
name="assignee"
|
||||
label="负责人"
|
||||
rules={[{ required: true, message: '请输入负责人' }]}
|
||||
/>
|
||||
<ProFormDatePicker
|
||||
name="startTime"
|
||||
label="开始时间"
|
||||
rules={[{ required: true, message: '请选择开始时间' }]}
|
||||
/>
|
||||
<ProFormDatePicker
|
||||
name="endTime"
|
||||
label="结束时间"
|
||||
/>
|
||||
<ProFormText
|
||||
name="description"
|
||||
label="描述"
|
||||
rules={[{ required: true, message: '请输入任务描述' }]}
|
||||
/>
|
||||
</ModalForm>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default MaintenanceList;
|
||||
@@ -1,217 +0,0 @@
|
||||
import moment from 'moment';
|
||||
|
||||
// 设备状态枚举
|
||||
export enum DeviceStatus {
|
||||
TASK = 'task', // 任务中 - 绿色
|
||||
STANDBY = 'standby', // 待机 - 蓝色
|
||||
MAINTENANCE = 'maintenance', // 维护 - 橙色
|
||||
ERROR = 'error', // 异常 - 红色
|
||||
OFFLINE = 'offline' // 离线 - 灰色
|
||||
}
|
||||
|
||||
// 设备状态配置
|
||||
export const DEVICE_STATUS_CONFIG = {
|
||||
[DeviceStatus.TASK]: {
|
||||
color: '#52c41a',
|
||||
icon: '▶️',
|
||||
text: '任务中',
|
||||
bgColor: '#f6ffed'
|
||||
},
|
||||
[DeviceStatus.STANDBY]: {
|
||||
color: '#1890ff',
|
||||
icon: '⏰',
|
||||
text: '待机',
|
||||
bgColor: '#f0f8ff'
|
||||
},
|
||||
[DeviceStatus.MAINTENANCE]: {
|
||||
color: '#fa8c16',
|
||||
icon: '🔧',
|
||||
text: '维护',
|
||||
bgColor: '#fff7e6'
|
||||
},
|
||||
[DeviceStatus.ERROR]: {
|
||||
color: '#ff4d4f',
|
||||
icon: '⚠️',
|
||||
text: '异常',
|
||||
bgColor: '#fff2f0'
|
||||
},
|
||||
[DeviceStatus.OFFLINE]: {
|
||||
color: '#8c8c8c',
|
||||
icon: '❌',
|
||||
text: '离线',
|
||||
bgColor: '#f5f5f5'
|
||||
}
|
||||
};
|
||||
|
||||
// 设备类型
|
||||
export interface Device {
|
||||
id: string;
|
||||
name: string;
|
||||
sn: string;
|
||||
type: string;
|
||||
status: DeviceStatus;
|
||||
location: {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
altitude?: number;
|
||||
};
|
||||
battery: number;
|
||||
signal: number;
|
||||
temperature: number;
|
||||
humidity: number;
|
||||
lastUpdate: string;
|
||||
group?: string;
|
||||
description?: string;
|
||||
// 新增字段
|
||||
batteryCycles?: number; // 电池循环次数
|
||||
flightHours?: number; // 飞行时长
|
||||
lastMaintenance?: string; // 最后维护时间
|
||||
nextMaintenance?: string; // 下次维护时间
|
||||
operator?: string; // 操作员
|
||||
ipAddress?: string; // IP地址
|
||||
firmwareVersion?: string; // 固件版本
|
||||
}
|
||||
|
||||
// 景区位置数据(北京周边景区)
|
||||
const SCENIC_SPOTS = [
|
||||
{ name: '颐和园', lat: 39.9999, lng: 116.2755, group: '颐和园景区' },
|
||||
{ name: '天坛公园', lat: 39.8822, lng: 116.4066, group: '天坛景区' },
|
||||
{ name: '故宫博物院', lat: 39.9163, lng: 116.3972, group: '故宫景区' },
|
||||
{ name: '八达岭长城', lat: 40.3569, lng: 116.0200, group: '长城景区' },
|
||||
{ name: '圆明园', lat: 40.0084, lng: 116.2995, group: '圆明园景区' },
|
||||
{ name: '香山公园', lat: 39.9944, lng: 116.1955, group: '香山景区' },
|
||||
{ name: '北海公园', lat: 39.9254, lng: 116.3897, group: '北海景区' },
|
||||
{ name: '景山公园', lat: 39.9244, lng: 116.3974, group: '景山景区' },
|
||||
{ name: '天安门广场', lat: 39.9054, lng: 116.3976, group: '天安门景区' },
|
||||
{ name: '奥林匹克公园', lat: 40.0024, lng: 116.3974, group: '奥体景区' },
|
||||
];
|
||||
|
||||
// 设备类型配置
|
||||
const DEVICE_TYPES = [
|
||||
{ type: '无人机', prefix: 'UAV', description: '航拍无人机设备' },
|
||||
{ type: '摄像头', prefix: 'CAM', description: '监控摄像头设备' },
|
||||
{ type: '传感器', prefix: 'SEN', description: '环境监测传感器' },
|
||||
{ type: '控制器', prefix: 'CTL', description: '智能控制器设备' },
|
||||
{ type: '基站', prefix: 'BS', description: '通信基站设备' },
|
||||
];
|
||||
|
||||
// 生成随机位置(在指定景区附近)
|
||||
const generateLocation = (scenicSpot: any) => {
|
||||
// 在景区周围500米范围内随机生成位置
|
||||
const radius = 0.005; // 约500米
|
||||
const angle = Math.random() * 2 * Math.PI;
|
||||
const distance = Math.random() * radius;
|
||||
|
||||
const lat = scenicSpot.lat + distance * Math.cos(angle);
|
||||
const lng = scenicSpot.lng + distance * Math.sin(angle);
|
||||
|
||||
return {
|
||||
latitude: lat,
|
||||
longitude: lng,
|
||||
altitude: Math.floor(Math.random() * 100) + 50
|
||||
};
|
||||
};
|
||||
|
||||
// 生成模拟设备数据
|
||||
export const generateMockDevices = (): Device[] => {
|
||||
const mockDevices: Device[] = [];
|
||||
|
||||
// 为每个景区生成2-4个设备
|
||||
SCENIC_SPOTS.forEach((spot, spotIndex) => {
|
||||
const deviceCount = Math.floor(Math.random() * 3) + 2; // 2-4个设备
|
||||
|
||||
for (let i = 1; i <= deviceCount; i++) {
|
||||
const deviceType = DEVICE_TYPES[Math.floor(Math.random() * DEVICE_TYPES.length)];
|
||||
const status = Object.values(DeviceStatus)[Math.floor(Math.random() * Object.values(DeviceStatus).length)];
|
||||
const deviceId = `${spotIndex + 1}_${i}`;
|
||||
|
||||
// 生成设备编号
|
||||
const sn = `${deviceType.prefix}${(spotIndex + 1).toString().padStart(2, '0')}${i.toString().padStart(2, '0')}`;
|
||||
|
||||
// 生成位置
|
||||
const location = generateLocation(spot);
|
||||
|
||||
// 生成电池循环次数(仅无人机)
|
||||
const batteryCycles = deviceType.type === '无人机' ? Math.floor(Math.random() * 200) + 1 : undefined;
|
||||
|
||||
// 生成飞行时长(仅无人机)
|
||||
const flightHours = deviceType.type === '无人机' ? Math.floor(Math.random() * 1000) + 10 : undefined;
|
||||
|
||||
// 生成维护时间
|
||||
const lastMaintenance = moment().subtract(Math.floor(Math.random() * 30), 'days').format('YYYY-MM-DD');
|
||||
const nextMaintenance = moment().add(Math.floor(Math.random() * 30) + 7, 'days').format('YYYY-MM-DD');
|
||||
|
||||
mockDevices.push({
|
||||
id: `device_${deviceId}`,
|
||||
name: `${deviceType.type}${deviceId}`,
|
||||
sn,
|
||||
type: deviceType.type,
|
||||
status,
|
||||
location,
|
||||
battery: Math.floor(Math.random() * 100) + 1,
|
||||
signal: Math.floor(Math.random() * 100) + 1,
|
||||
temperature: Math.floor(Math.random() * 40) + 10,
|
||||
humidity: Math.floor(Math.random() * 60) + 20,
|
||||
lastUpdate: moment().subtract(Math.floor(Math.random() * 60), 'minutes').format('YYYY-MM-DD HH:mm:ss'),
|
||||
group: spot.group,
|
||||
description: `${deviceType.description},位于${spot.name}`,
|
||||
batteryCycles,
|
||||
flightHours,
|
||||
lastMaintenance,
|
||||
nextMaintenance,
|
||||
operator: `操作员${Math.floor(Math.random() * 10) + 1}`,
|
||||
ipAddress: `192.168.${Math.floor(Math.random() * 255) + 1}.${Math.floor(Math.random() * 255) + 1}`,
|
||||
firmwareVersion: `v${Math.floor(Math.random() * 5) + 1}.${Math.floor(Math.random() * 10)}.${Math.floor(Math.random() * 10)}`
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return mockDevices;
|
||||
};
|
||||
|
||||
// 设备统计接口
|
||||
export interface DeviceStats {
|
||||
total: number;
|
||||
online: number;
|
||||
offline: number;
|
||||
task: number;
|
||||
standby: number;
|
||||
maintenance: number;
|
||||
error: number;
|
||||
byGroup: Record<string, number>;
|
||||
byType: Record<string, number>;
|
||||
}
|
||||
|
||||
// 计算设备统计
|
||||
export const calculateDeviceStats = (devices: Device[]): DeviceStats => {
|
||||
const stats: DeviceStats = {
|
||||
total: devices.length,
|
||||
online: devices.filter(d => d.status !== DeviceStatus.OFFLINE).length,
|
||||
offline: devices.filter(d => d.status === DeviceStatus.OFFLINE).length,
|
||||
task: devices.filter(d => d.status === DeviceStatus.TASK).length,
|
||||
standby: devices.filter(d => d.status === DeviceStatus.STANDBY).length,
|
||||
maintenance: devices.filter(d => d.status === DeviceStatus.MAINTENANCE).length,
|
||||
error: devices.filter(d => d.status === DeviceStatus.ERROR).length,
|
||||
byGroup: {},
|
||||
byType: {}
|
||||
};
|
||||
|
||||
// 按分组统计
|
||||
devices.forEach(device => {
|
||||
if (device.group) {
|
||||
stats.byGroup[device.group] = (stats.byGroup[device.group] || 0) + 1;
|
||||
}
|
||||
stats.byType[device.type] = (stats.byType[device.type] || 0) + 1;
|
||||
});
|
||||
|
||||
return stats;
|
||||
};
|
||||
|
||||
// 获取景区列表
|
||||
export const getScenicSpots = () => {
|
||||
return SCENIC_SPOTS.map(spot => ({
|
||||
name: spot.name,
|
||||
group: spot.group,
|
||||
location: { latitude: spot.lat, longitude: spot.lng }
|
||||
}));
|
||||
};
|
||||
@@ -1,44 +0,0 @@
|
||||
import { getDeviceList } from '../services/api';
|
||||
|
||||
export interface Device {
|
||||
id: string;
|
||||
name: string;
|
||||
type: string;
|
||||
status: string;
|
||||
group?: string;
|
||||
}
|
||||
|
||||
export interface DeviceModelState {
|
||||
deviceList: Device[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
const DeviceModel = {
|
||||
namespace: 'deviceOpsDevice',
|
||||
state: {
|
||||
deviceList: [],
|
||||
total: 0,
|
||||
},
|
||||
effects: {
|
||||
*fetchDeviceList({ payload }: any, { call, put }: any): any {
|
||||
const response = yield call(getDeviceList, payload);
|
||||
yield put({
|
||||
type: 'saveDeviceList',
|
||||
payload: {
|
||||
deviceList: response?.data?.records || [],
|
||||
total: response?.data?.total || 0,
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
reducers: {
|
||||
saveDeviceList(state: any, { payload }: any): any {
|
||||
return {
|
||||
...state,
|
||||
...payload,
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default DeviceModel;
|
||||
@@ -1,32 +0,0 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
// 设备列表
|
||||
export async function getDeviceList(params?: any) {
|
||||
return request('/api/device-ops/device/list', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
// 新增设备
|
||||
export async function addDevice(data: any) {
|
||||
return request('/api/device-ops/device', {
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
// 编辑设备
|
||||
export async function updateDevice(data: any) {
|
||||
return request('/api/device-ops/device', {
|
||||
method: 'PUT',
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
// 删除设备
|
||||
export async function deleteDevice(id: string) {
|
||||
return request(`/api/device-ops/device/${id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
@@ -1,282 +0,0 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import { Card, Row, Col, DatePicker, Select, Space, Statistic, message } from 'antd';
|
||||
import { Line, Column } from '@ant-design/plots';
|
||||
import moment from 'moment';
|
||||
import { CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons';
|
||||
import { device } from '@/services/device/api';
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
interface Device {
|
||||
deviceSn: string;
|
||||
deviceName: string;
|
||||
deviceType: number;
|
||||
boundStatus: number;
|
||||
createTime: string;
|
||||
loginTime: string;
|
||||
}
|
||||
|
||||
interface TrendData {
|
||||
date: string;
|
||||
value: number;
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface DeviceGrowth {
|
||||
date: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
interface PerformanceData {
|
||||
time: string;
|
||||
value: number;
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface StatisticsData {
|
||||
totalDevices: number;
|
||||
averageOnlineRate: number;
|
||||
totalGrowth: number;
|
||||
}
|
||||
|
||||
const DeviceStatistics: React.FC = () => {
|
||||
const [timeRange, setTimeRange] = useState<[moment.Moment, moment.Moment]>([
|
||||
moment().subtract(30, 'days'),
|
||||
moment(),
|
||||
]);
|
||||
const [selectedDevice, setSelectedDevice] = useState<string>('all');
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [deviceList, setDeviceList] = useState<Device[]>([]);
|
||||
const [statusTrendData, setStatusTrendData] = useState<TrendData[]>([]);
|
||||
const [deviceGrowthData, setDeviceGrowthData] = useState<DeviceGrowth[]>([]);
|
||||
const [performanceData, setPerformanceData] = useState<PerformanceData[]>([]);
|
||||
const [statistics, setStatistics] = useState<StatisticsData>({
|
||||
totalDevices: 0,
|
||||
averageOnlineRate: 0,
|
||||
totalGrowth: 0,
|
||||
});
|
||||
|
||||
// 获取设备列表
|
||||
const fetchDeviceList = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await device({
|
||||
page: 1,
|
||||
limit: 1000,
|
||||
searchKey: selectedDevice === 'all' ? undefined : 'deviceSn',
|
||||
searchValue: selectedDevice === 'all' ? undefined : selectedDevice,
|
||||
});
|
||||
|
||||
if (response.resp_code === 0) {
|
||||
const data = response.data || [];
|
||||
setDeviceList(data);
|
||||
|
||||
// 计算统计数据
|
||||
const totalDevices = data.length;
|
||||
const onlineDevices = data.filter((item: Device) => item.boundStatus === 1).length;
|
||||
const averageOnlineRate = totalDevices > 0 ? (onlineDevices / totalDevices) * 100 : 0;
|
||||
const totalGrowth = data.filter((item: Device) =>
|
||||
moment(item.createTime).isBetween(timeRange[0], timeRange[1])
|
||||
).length;
|
||||
|
||||
setStatistics({
|
||||
totalDevices,
|
||||
averageOnlineRate,
|
||||
totalGrowth,
|
||||
});
|
||||
|
||||
// 生成状态趋势数据
|
||||
const statusTrend: TrendData[] = Array.from({ length: 30 }, (_, i) => {
|
||||
const date = moment().subtract(29 - i, 'days');
|
||||
const devicesOnDay = data.filter((item: Device) =>
|
||||
moment(item.createTime).isSameOrBefore(date) &&
|
||||
(item.boundStatus === 1 || moment(item.loginTime).isSameOrAfter(date))
|
||||
);
|
||||
return {
|
||||
date: date.format('YYYY-MM-DD HH:mm:ss'),
|
||||
value: devicesOnDay.length > 0 ? (devicesOnDay.filter((d: Device) => d.boundStatus === 1).length / devicesOnDay.length) * 100 : 0,
|
||||
type: '在线率',
|
||||
};
|
||||
});
|
||||
|
||||
// 生成设备增长数据
|
||||
const growthTrend: DeviceGrowth[] = Array.from({ length: 30 }, (_, i) => {
|
||||
const date = moment().subtract(29 - i, 'days');
|
||||
return {
|
||||
date: date.format('YYYY-MM-DD HH:mm:ss'),
|
||||
count: data.filter((item: Device) =>
|
||||
moment(item.createTime).isSame(date, 'day')
|
||||
).length,
|
||||
};
|
||||
});
|
||||
|
||||
// 生成性能指标数据
|
||||
const performanceTrend: PerformanceData[] = Array.from({ length: 24 }, (_, i) => [
|
||||
{
|
||||
time: moment().subtract(23 - i, 'hours').format('YYYY-MM-DD HH:mm:ss'),
|
||||
value: Math.floor(Math.random() * 100),
|
||||
type: 'CPU使用率',
|
||||
},
|
||||
{
|
||||
time: moment().subtract(23 - i, 'hours').format('YYYY-MM-DD HH:mm:ss'),
|
||||
value: Math.floor(Math.random() * 100),
|
||||
type: '内存使用率',
|
||||
},
|
||||
{
|
||||
time: moment().subtract(23 - i, 'hours').format('YYYY-MM-DD HH:mm:ss'),
|
||||
value: Math.floor(Math.random() * 50) + 20,
|
||||
type: '温度',
|
||||
},
|
||||
]).flat();
|
||||
|
||||
setStatusTrendData(statusTrend);
|
||||
setDeviceGrowthData(growthTrend);
|
||||
setPerformanceData(performanceTrend);
|
||||
} else {
|
||||
message.error(response.resp_msg || '获取数据失败');
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取数据失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchDeviceList();
|
||||
}, [timeRange, selectedDevice]);
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={24}>
|
||||
<Card>
|
||||
<Space style={{ marginBottom: 16 }}>
|
||||
<Select
|
||||
style={{ width: 200 }}
|
||||
value={selectedDevice}
|
||||
onChange={setSelectedDevice}
|
||||
loading={loading}
|
||||
>
|
||||
<Select.Option value="all">所有设备</Select.Option>
|
||||
{deviceList.map(device => (
|
||||
<Select.Option key={device.deviceSn} value={device.deviceSn}>
|
||||
{device.deviceName}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
<RangePicker
|
||||
showTime
|
||||
value={timeRange}
|
||||
onChange={(dates) => {
|
||||
if (dates && dates[0] && dates[1]) {
|
||||
setTimeRange([dates[0], dates[1]]);
|
||||
}
|
||||
}}
|
||||
disabled={loading}
|
||||
/>
|
||||
</Space>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
{/* 统计卡片 */}
|
||||
<Col span={8}>
|
||||
<Card loading={loading}>
|
||||
<Statistic
|
||||
title="设备总数"
|
||||
value={statistics.totalDevices}
|
||||
suffix="台"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card loading={loading}>
|
||||
<Statistic
|
||||
title="平均在线率"
|
||||
value={statistics.averageOnlineRate}
|
||||
precision={2}
|
||||
suffix="%"
|
||||
valueStyle={{ color: statistics.averageOnlineRate > 80 ? '#3f8600' : '#cf1322' }}
|
||||
prefix={statistics.averageOnlineRate > 80 ? <CheckCircleOutlined /> : <CloseCircleOutlined />}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card loading={loading}>
|
||||
<Statistic
|
||||
title="设备增长"
|
||||
value={statistics.totalGrowth}
|
||||
suffix="台"
|
||||
valueStyle={{ color: statistics.totalGrowth > 0 ? '#3f8600' : '#cf1322' }}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
{/* 设备状态趋势 */}
|
||||
<Col span={24}>
|
||||
<Card title="设备状态趋势" loading={loading}>
|
||||
<Line
|
||||
data={statusTrendData}
|
||||
xField="date"
|
||||
yField="value"
|
||||
seriesField="type"
|
||||
xAxis={{
|
||||
type: 'time',
|
||||
mask: 'YYYY-MM-DD',
|
||||
}}
|
||||
yAxis={{
|
||||
label: {
|
||||
formatter: (v) => `${v}%`,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
{/* 设备增长趋势 */}
|
||||
<Col span={24}>
|
||||
<Card title="设备增长趋势" loading={loading}>
|
||||
<Column
|
||||
data={deviceGrowthData}
|
||||
xField="date"
|
||||
yField="count"
|
||||
xAxis={{
|
||||
type: 'time',
|
||||
mask: 'YYYY-MM-DD',
|
||||
}}
|
||||
yAxis={{
|
||||
label: {
|
||||
formatter: (v) => `${v}台`,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
{/* 性能指标趋势 */}
|
||||
<Col span={24}>
|
||||
<Card title="性能指标趋势" loading={loading}>
|
||||
<Line
|
||||
data={performanceData}
|
||||
xField="time"
|
||||
yField="value"
|
||||
seriesField="type"
|
||||
xAxis={{
|
||||
type: 'time',
|
||||
mask: 'HH:mm',
|
||||
}}
|
||||
yAxis={{
|
||||
label: {
|
||||
formatter: (v) => `${v}%`,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default DeviceStatistics;
|
||||
@@ -1,27 +0,0 @@
|
||||
.videoCard {
|
||||
margin-bottom: 16px;
|
||||
|
||||
:global {
|
||||
.ant-card-body {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.controlCard {
|
||||
margin-bottom: 16px;
|
||||
|
||||
:global {
|
||||
.ant-space {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.statusCard {
|
||||
:global {
|
||||
.ant-statistic {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,231 +0,0 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { Modal, Tabs, Button, Space, Card, Row, Col, Statistic, message, Badge } from 'antd';
|
||||
import {
|
||||
PlayCircleOutlined,
|
||||
PauseOutlined,
|
||||
CameraOutlined,
|
||||
VideoCameraOutlined,
|
||||
HomeOutlined,
|
||||
PauseCircleOutlined,
|
||||
ControlOutlined
|
||||
} from '@ant-design/icons';
|
||||
import ReactPlayer from 'react-player';
|
||||
import { getStreamUrls } from '@/services/device/api';
|
||||
import styles from './DeviceControlPanel.less';
|
||||
|
||||
interface DeviceControlPanelProps {
|
||||
visible: boolean;
|
||||
onClose: () => void;
|
||||
deviceSn: string;
|
||||
}
|
||||
|
||||
const DeviceControlPanel: React.FC<DeviceControlPanelProps> = ({ visible, onClose, deviceSn }) => {
|
||||
const [streamUrls, setStreamUrls] = useState<any>(null);
|
||||
const [isPlaying, setIsPlaying] = useState(true);
|
||||
const [cameraMode, setCameraMode] = useState(0); // 0=拍照,1=录像
|
||||
const [isRecording, setIsRecording] = useState(false);
|
||||
const [wsConnected, setWsConnected] = useState(false);
|
||||
const wsRef = useRef<WebSocket | null>(null);
|
||||
const playerRef = useRef<any>(null);
|
||||
|
||||
// 初始化WebSocket连接
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
const ws = new WebSocket('ws://your-websocket-server');
|
||||
wsRef.current = ws;
|
||||
|
||||
ws.onopen = () => {
|
||||
setWsConnected(true);
|
||||
message.success('设备连接成功');
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
setWsConnected(false);
|
||||
message.error('设备连接断开');
|
||||
};
|
||||
|
||||
ws.onerror = (error) => {
|
||||
console.error('WebSocket错误:', error);
|
||||
message.error('设备连接错误');
|
||||
};
|
||||
|
||||
return () => {
|
||||
ws.close();
|
||||
};
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
// 获取视频流地址
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
getStreamUrls(deviceSn).then(res => {
|
||||
if (res.resp_code === 0) {
|
||||
setStreamUrls(res.data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [visible, deviceSn]);
|
||||
|
||||
// 发送控制指令
|
||||
const sendControlCommand = (method: string, data: any = {}) => {
|
||||
if (!wsRef.current || wsRef.current.readyState !== WebSocket.OPEN) {
|
||||
message.error('设备未连接');
|
||||
return;
|
||||
}
|
||||
|
||||
const command = {
|
||||
type: 'sub',
|
||||
topic: `/device-message-sender/D-Dock2/${deviceSn}`,
|
||||
parameter: {
|
||||
messageType: 'WRITE_PROPERTY',
|
||||
properties: {
|
||||
method,
|
||||
data
|
||||
},
|
||||
headers: {
|
||||
async: false
|
||||
}
|
||||
},
|
||||
id: `cmd_${Date.now()}`
|
||||
};
|
||||
|
||||
wsRef.current.send(JSON.stringify(command));
|
||||
};
|
||||
|
||||
// 控制按钮事件处理
|
||||
const handleTakePhoto = () => {
|
||||
sendControlCommand('camera_photo_take');
|
||||
message.success('拍照指令已发送');
|
||||
};
|
||||
|
||||
const handleStartRecording = () => {
|
||||
sendControlCommand('camera_recording_start');
|
||||
setIsRecording(true);
|
||||
message.success('开始录像');
|
||||
};
|
||||
|
||||
const handleStopRecording = () => {
|
||||
sendControlCommand('camera_recording_stop');
|
||||
setIsRecording(false);
|
||||
message.success('停止录像');
|
||||
};
|
||||
|
||||
const handleReturnHome = () => {
|
||||
sendControlCommand('return_home');
|
||||
message.success('返航指令已发送');
|
||||
};
|
||||
|
||||
const handlePauseTask = () => {
|
||||
sendControlCommand('flighttask_pause');
|
||||
message.success('暂停任务指令已发送');
|
||||
};
|
||||
|
||||
const handleEnterDRCMode = () => {
|
||||
sendControlCommand('drc_mode_enter');
|
||||
message.success('进入指令飞行模式');
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={
|
||||
<Space>
|
||||
<span>设备控制面板</span>
|
||||
<Badge
|
||||
status={wsConnected ? 'success' : 'error'}
|
||||
text={wsConnected ? '已连接' : '未连接'}
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
open={visible}
|
||||
onCancel={onClose}
|
||||
width={1200}
|
||||
footer={null}
|
||||
>
|
||||
<Row gutter={16}>
|
||||
<Col span={16}>
|
||||
<Card title="视频流" className={styles.videoCard}>
|
||||
{streamUrls && (
|
||||
<ReactPlayer
|
||||
ref={playerRef}
|
||||
url={streamUrls.playFlvUrl}
|
||||
controls
|
||||
width="100%"
|
||||
height={450}
|
||||
playing={isPlaying}
|
||||
/>
|
||||
)}
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card title="设备控制" className={styles.controlCard}>
|
||||
<Space direction="vertical" style={{ width: '100%' }}>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={isPlaying ? <PauseOutlined /> : <PlayCircleOutlined />}
|
||||
onClick={() => setIsPlaying(!isPlaying)}
|
||||
block
|
||||
>
|
||||
{isPlaying ? '暂停' : '播放'}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
icon={<CameraOutlined />}
|
||||
onClick={handleTakePhoto}
|
||||
block
|
||||
>
|
||||
拍照
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
type={isRecording ? 'primary' : 'default'}
|
||||
icon={<VideoCameraOutlined />}
|
||||
onClick={isRecording ? handleStopRecording : handleStartRecording}
|
||||
block
|
||||
>
|
||||
{isRecording ? '停止录像' : '开始录像'}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
icon={<HomeOutlined />}
|
||||
onClick={handleReturnHome}
|
||||
block
|
||||
>
|
||||
返航
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
icon={<PauseCircleOutlined />}
|
||||
onClick={handlePauseTask}
|
||||
block
|
||||
>
|
||||
暂停任务
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
icon={<ControlOutlined />}
|
||||
onClick={handleEnterDRCMode}
|
||||
block
|
||||
>
|
||||
指令飞行
|
||||
</Button>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
<Card title="设备状态" className={styles.statusCard}>
|
||||
<Statistic title="设备SN" value={deviceSn} />
|
||||
<Statistic
|
||||
title="相机模式"
|
||||
value={cameraMode === 0 ? '拍照模式' : '录像模式'}
|
||||
/>
|
||||
<Statistic
|
||||
title="录像状态"
|
||||
value={isRecording ? '录制中' : '未录制'}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default DeviceControlPanel;
|
||||
@@ -1,91 +0,0 @@
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
ProFormSelect,
|
||||
ProFormTextArea,
|
||||
} from '@ant-design/pro-components';
|
||||
import React from 'react';
|
||||
|
||||
// 设备类型常量
|
||||
const DEVICE_TYPE = {
|
||||
DOCK: 1,
|
||||
DRONE: 2,
|
||||
REMOTE_CONTROL: 3,
|
||||
} as const;
|
||||
|
||||
export type FormValueType = {
|
||||
id?: string;
|
||||
deviceSn?: string;
|
||||
deviceName?: string;
|
||||
nickname?: string;
|
||||
deviceType?: number;
|
||||
firmwareVersion?: string;
|
||||
deviceDesc?: string;
|
||||
} & Partial<DEVICE.Device>;
|
||||
|
||||
export type UpdateFormProps = {
|
||||
onSubmit: (values: FormValueType) => Promise<void>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
updateModalVisible: boolean;
|
||||
values: Partial<DEVICE.Device>;
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const { updateModalVisible, onVisibleChange, onSubmit, values } = props;
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改设备"
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={onSubmit}
|
||||
initialValues={values}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '设备序列号不能为空' }]}
|
||||
width="md"
|
||||
name="deviceSn"
|
||||
label="设备序列号"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '设备名称不能为空' }]}
|
||||
width="md"
|
||||
name="deviceName"
|
||||
label="设备名称"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '设备昵称不能为空' }]}
|
||||
width="md"
|
||||
name="nickname"
|
||||
label="设备昵称"
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '设备类型不能为空' }]}
|
||||
width="md"
|
||||
name="deviceType"
|
||||
label="设备类型"
|
||||
options={[
|
||||
{ label: '机场', value: DEVICE_TYPE.DOCK },
|
||||
{ label: '无人机', value: DEVICE_TYPE.DRONE },
|
||||
{ label: '遥控器', value: DEVICE_TYPE.REMOTE_CONTROL },
|
||||
]}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="firmwareVersion"
|
||||
label="固件版本"
|
||||
/>
|
||||
<ProFormTextArea
|
||||
name="deviceDesc"
|
||||
label="设备描述"
|
||||
placeholder="请输入设备描述"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateForm;
|
||||
@@ -1,20 +0,0 @@
|
||||
.playerContainer {
|
||||
.controls {
|
||||
margin-bottom: 16px;
|
||||
padding: 8px;
|
||||
background: #f5f5f5;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
:global {
|
||||
.ant-tabs-content {
|
||||
background: #000;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ant-tabs-tab {
|
||||
margin: 0 16px 0 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { Modal, Tabs, Button, Space, Select, message, Badge } from 'antd';
|
||||
import ReactPlayer from 'react-player';
|
||||
import { VideoCameraOutlined, DownloadOutlined, PauseOutlined, PlayCircleOutlined } from '@ant-design/icons';
|
||||
import styles from './VideoPlayer.less';
|
||||
|
||||
interface VideoPlayerProps {
|
||||
visible: boolean;
|
||||
onClose: () => void;
|
||||
streamUrls: {
|
||||
playFlvUrl: string;
|
||||
playM3u8Url: string;
|
||||
playRtmpUrl: string;
|
||||
};
|
||||
deviceSn: string;
|
||||
}
|
||||
|
||||
const VideoPlayer: React.FC<VideoPlayerProps> = ({ visible, onClose, streamUrls, deviceSn }) => {
|
||||
const [activeTab, setActiveTab] = useState('flv');
|
||||
const [isPlaying, setIsPlaying] = useState(true);
|
||||
const [isRecording, setIsRecording] = useState(false);
|
||||
const [streamStatus, setStreamStatus] = useState<'online' | 'offline'>('offline');
|
||||
const [quality, setQuality] = useState('high');
|
||||
const playerRef = useRef<any>(null);
|
||||
const mediaRecorderRef = useRef<MediaRecorder | null>(null);
|
||||
const recordedChunksRef = useRef<Blob[]>([]);
|
||||
|
||||
// 检查流状态
|
||||
const checkStreamStatus = async () => {
|
||||
try {
|
||||
const response = await fetch(streamUrls.playFlvUrl, { method: 'HEAD' });
|
||||
setStreamStatus(response.ok ? 'online' : 'offline');
|
||||
} catch (error) {
|
||||
setStreamStatus('offline');
|
||||
}
|
||||
};
|
||||
|
||||
// 定期检查流状态
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
checkStreamStatus();
|
||||
const interval = setInterval(checkStreamStatus, 30000); // 每30秒检查一次
|
||||
return () => clearInterval(interval);
|
||||
}
|
||||
}, [visible, streamUrls]);
|
||||
|
||||
// 开始录制
|
||||
const startRecording = () => {
|
||||
if (playerRef.current) {
|
||||
const stream = playerRef.current.getInternalPlayer().captureStream();
|
||||
const mediaRecorder = new MediaRecorder(stream, {
|
||||
mimeType: 'video/webm;codecs=vp9',
|
||||
});
|
||||
|
||||
mediaRecorder.ondataavailable = (event) => {
|
||||
if (event.data.size > 0) {
|
||||
recordedChunksRef.current.push(event.data);
|
||||
}
|
||||
};
|
||||
|
||||
mediaRecorder.onstop = () => {
|
||||
const blob = new Blob(recordedChunksRef.current, { type: 'video/webm' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `recording-${deviceSn}-${new Date().toISOString()}.webm`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
recordedChunksRef.current = [];
|
||||
};
|
||||
|
||||
mediaRecorderRef.current = mediaRecorder;
|
||||
mediaRecorder.start();
|
||||
setIsRecording(true);
|
||||
}
|
||||
};
|
||||
|
||||
// 停止录制
|
||||
const stopRecording = () => {
|
||||
if (mediaRecorderRef.current && isRecording) {
|
||||
mediaRecorderRef.current.stop();
|
||||
setIsRecording(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 处理播放器错误
|
||||
const handleError = (error: any) => {
|
||||
console.error('播放器错误:', error);
|
||||
message.error('视频流播放出错,请检查网络连接或刷新重试');
|
||||
};
|
||||
|
||||
// 处理播放器就绪
|
||||
const handleReady = () => {
|
||||
message.success('视频流已就绪');
|
||||
};
|
||||
|
||||
// 获取当前播放的URL
|
||||
const getCurrentUrl = () => {
|
||||
switch (activeTab) {
|
||||
case 'flv':
|
||||
return streamUrls.playFlvUrl;
|
||||
case 'hls':
|
||||
return streamUrls.playM3u8Url;
|
||||
case 'rtmp':
|
||||
return streamUrls.playRtmpUrl;
|
||||
default:
|
||||
return streamUrls.playFlvUrl;
|
||||
}
|
||||
};
|
||||
|
||||
// 根据质量设置播放器配置
|
||||
const getPlayerConfig = () => {
|
||||
const baseConfig = {
|
||||
controls: true,
|
||||
width: '100%',
|
||||
height: 450,
|
||||
playing: isPlaying,
|
||||
onError: handleError,
|
||||
onReady: handleReady,
|
||||
ref: playerRef,
|
||||
};
|
||||
|
||||
switch (quality) {
|
||||
case 'low':
|
||||
return {
|
||||
...baseConfig,
|
||||
config: {
|
||||
file: {
|
||||
attributes: {
|
||||
style: {
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
},
|
||||
},
|
||||
forceVideo: true,
|
||||
forceHLS: true,
|
||||
hlsOptions: {
|
||||
maxBufferLength: 30,
|
||||
maxMaxBufferLength: 60,
|
||||
maxBufferSize: 0,
|
||||
maxBufferHole: 0.5,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
case 'high':
|
||||
default:
|
||||
return baseConfig;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={
|
||||
<Space>
|
||||
<span>设备视频流</span>
|
||||
<Badge
|
||||
status={streamStatus === 'online' ? 'success' : 'error'}
|
||||
text={streamStatus === 'online' ? '在线' : '离线'}
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
open={visible}
|
||||
onCancel={onClose}
|
||||
width={800}
|
||||
footer={null}
|
||||
>
|
||||
<div className={styles.playerContainer}>
|
||||
<div className={styles.controls}>
|
||||
<Space>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={isPlaying ? <PauseOutlined /> : <PlayCircleOutlined />}
|
||||
onClick={() => setIsPlaying(!isPlaying)}
|
||||
>
|
||||
{isPlaying ? '暂停' : '播放'}
|
||||
</Button>
|
||||
<Button
|
||||
type={isRecording ? 'primary' : 'default'}
|
||||
icon={<DownloadOutlined />}
|
||||
onClick={isRecording ? stopRecording : startRecording}
|
||||
>
|
||||
{isRecording ? '停止录制' : '开始录制'}
|
||||
</Button>
|
||||
<Select
|
||||
value={quality}
|
||||
onChange={setQuality}
|
||||
options={[
|
||||
{ label: '高质量', value: 'high' },
|
||||
{ label: '低质量', value: 'low' },
|
||||
]}
|
||||
/>
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
<Tabs
|
||||
activeKey={activeTab}
|
||||
onChange={setActiveTab}
|
||||
items={[
|
||||
{
|
||||
key: 'flv',
|
||||
label: 'FLV',
|
||||
children: (
|
||||
<ReactPlayer
|
||||
url={getCurrentUrl()}
|
||||
{...getPlayerConfig()}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'hls',
|
||||
label: 'HLS',
|
||||
children: (
|
||||
<ReactPlayer
|
||||
url={getCurrentUrl()}
|
||||
{...getPlayerConfig()}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'rtmp',
|
||||
label: 'RTMP',
|
||||
children: (
|
||||
<ReactPlayer
|
||||
url={getCurrentUrl()}
|
||||
{...getPlayerConfig()}
|
||||
/>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoPlayer;
|
||||
@@ -1,441 +0,0 @@
|
||||
import {
|
||||
device,
|
||||
saveOrUpdateDevice,
|
||||
deleteDevice,
|
||||
updateDeviceBoundStatus,
|
||||
getStreamUrls,
|
||||
} from '@/services/device/api';
|
||||
import { PlusOutlined, ExportOutlined, ImportOutlined, DownloadOutlined, VideoCameraOutlined, ControlOutlined } from '@ant-design/icons';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
ModalForm,
|
||||
PageContainer,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
ProFormSelect,
|
||||
ProFormTextArea,
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, message, Space, Switch, Upload } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import moment from 'moment';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import VideoPlayer from './components/VideoPlayer';
|
||||
import DeviceControlPanel from './components/DeviceControlPanel';
|
||||
|
||||
const DEVICE_TYPE = {
|
||||
DOCK: 1,
|
||||
DRONE: 2,
|
||||
REMOTE_CONTROL: 3,
|
||||
} as const;
|
||||
|
||||
const COMPATIBLE_STATUS = {
|
||||
INCONSISTENT: 0,
|
||||
CONSISTENT: 1,
|
||||
} as const;
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const [searchParams, setSearchParams] = useState<Record<string, string | number>>({});
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<DEVICE.Device>();
|
||||
const [videoModalVisible, setVideoModalVisible] = useState<boolean>(false);
|
||||
const [streamUrls, setStreamUrls] = useState<any>(null);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [controlPanelVisible, setControlPanelVisible] = useState<boolean>(false);
|
||||
|
||||
// 统一的API请求处理函数
|
||||
const handleRequest = async (
|
||||
action: () => Promise<any>,
|
||||
loadingMessage: string,
|
||||
successMessage: string,
|
||||
) => {
|
||||
const hide = message.loading(loadingMessage);
|
||||
try {
|
||||
const result = await action();
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success(successMessage);
|
||||
return true;
|
||||
}
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error(`${successMessage}失败`);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 切换设备绑定状态
|
||||
const switchBoundStatus = async (record: DEVICE.Device) => {
|
||||
const success = await handleRequest(
|
||||
() => updateDeviceBoundStatus(record.deviceSn, record.boundStatus === 1 ? 0 : 1),
|
||||
'正在更新',
|
||||
'更新成功'
|
||||
);
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
};
|
||||
|
||||
// 导出处理函数
|
||||
const handleExport = () => {
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = '/api-device/device/export';
|
||||
form.style.display = 'none';
|
||||
|
||||
const token = sessionStorage.getItem('access_token');
|
||||
if (token) {
|
||||
const tokenInput = document.createElement('input');
|
||||
tokenInput.type = 'hidden';
|
||||
tokenInput.name = '_token';
|
||||
tokenInput.value = token;
|
||||
form.appendChild(tokenInput);
|
||||
}
|
||||
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
document.body.removeChild(form);
|
||||
};
|
||||
|
||||
// 模板下载函数
|
||||
const handleDownloadTemplate = () => {
|
||||
window.location.href = '/api-device/device/template';
|
||||
};
|
||||
|
||||
// 处理视频流播放
|
||||
const handlePlayVideo = async (deviceSn: string) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await getStreamUrls(deviceSn);
|
||||
if (res.resp_code === 0) {
|
||||
setStreamUrls(res.data);
|
||||
setVideoModalVisible(true);
|
||||
} else {
|
||||
message.error(res.resp_msg || '获取视频流地址失败');
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取视频流地址失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 表格列定义
|
||||
const columns: ProColumns<DEVICE.Device>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 48,
|
||||
},
|
||||
{
|
||||
title: '设备序列号',
|
||||
dataIndex: 'deviceSn',
|
||||
copyable: true,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
title: '设备名称',
|
||||
dataIndex: 'deviceName',
|
||||
},
|
||||
{
|
||||
title: '昵称',
|
||||
dataIndex: 'nickname',
|
||||
},
|
||||
{
|
||||
title: '设备类型',
|
||||
dataIndex: 'deviceType',
|
||||
valueType: 'select',
|
||||
valueEnum: {
|
||||
[DEVICE_TYPE.DOCK]: { text: '机场' },
|
||||
[DEVICE_TYPE.DRONE]: { text: '无人机' },
|
||||
[DEVICE_TYPE.REMOTE_CONTROL]: { text: '遥控器' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '固件版本',
|
||||
dataIndex: 'firmwareVersion',
|
||||
},
|
||||
{
|
||||
title: '固件状态',
|
||||
dataIndex: 'compatibleStatus',
|
||||
valueType: 'select',
|
||||
valueEnum: {
|
||||
[COMPATIBLE_STATUS.CONSISTENT]: { text: '一致', status: 'Success' },
|
||||
[COMPATIBLE_STATUS.INCONSISTENT]: { text: '不一致', status: 'Error' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '绑定状态',
|
||||
dataIndex: 'boundStatus',
|
||||
render: (_, record) => (
|
||||
<Switch
|
||||
checkedChildren="已绑定"
|
||||
unCheckedChildren="未绑定"
|
||||
checked={record.boundStatus === 1}
|
||||
onClick={() => switchBoundStatus(record)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '最后登录',
|
||||
dataIndex: 'loginTime',
|
||||
valueType: 'dateTime',
|
||||
render: (text) => (text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '-'),
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
render: (text) => (text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '-'),
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
dataIndex: 'option',
|
||||
valueType: 'option',
|
||||
fixed: 'right',
|
||||
width: 180,
|
||||
render: (_, record) => [
|
||||
<a
|
||||
key="video"
|
||||
onClick={() => handlePlayVideo(record.deviceSn)}
|
||||
>
|
||||
<VideoCameraOutlined /> 视频流
|
||||
</a>,
|
||||
<a
|
||||
key="control"
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
setControlPanelVisible(true);
|
||||
}}
|
||||
>
|
||||
<ControlOutlined /> 控制面板
|
||||
</a>,
|
||||
<a
|
||||
key="edit"
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</a>,
|
||||
<a
|
||||
key="delete"
|
||||
onClick={() => {
|
||||
handleRequest(
|
||||
() => deleteDevice(record.id),
|
||||
'正在删除',
|
||||
'删除成功'
|
||||
).then((success) => {
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
});
|
||||
}}
|
||||
>
|
||||
删除
|
||||
</a>,
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
// 表单字段定义
|
||||
const renderModalContent = () => (
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '设备序列号不能为空' }]}
|
||||
width="md"
|
||||
name="deviceSn"
|
||||
label="设备序列号"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '设备名称不能为空' }]}
|
||||
width="md"
|
||||
name="deviceName"
|
||||
label="设备名称"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '设备昵称不能为空' }]}
|
||||
width="md"
|
||||
name="nickname"
|
||||
label="设备昵称"
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '设备类型不能为空' }]}
|
||||
width="md"
|
||||
name="deviceType"
|
||||
label="设备类型"
|
||||
options={[
|
||||
{ label: '机场', value: DEVICE_TYPE.DOCK },
|
||||
{ label: '无人机', value: DEVICE_TYPE.DRONE },
|
||||
{ label: '遥控器', value: DEVICE_TYPE.REMOTE_CONTROL },
|
||||
]}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="firmwareVersion"
|
||||
label="固件版本"
|
||||
/>
|
||||
<ProFormTextArea
|
||||
name="deviceDesc"
|
||||
label="设备描述"
|
||||
placeholder="请输入设备描述"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
);
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '管理系统中的设备' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
onFinish={async (values) => setSearchParams(values)}
|
||||
>
|
||||
<ProFormSelect
|
||||
name="searchKey"
|
||||
label="搜索"
|
||||
valueEnum={{
|
||||
deviceSn: '设备序列号',
|
||||
deviceName: '设备名称',
|
||||
nickname: '昵称',
|
||||
}}
|
||||
/>
|
||||
<ProFormText name="searchValue" placeholder="请输入关键字" />
|
||||
</QueryFilter>
|
||||
|
||||
<ProTable<DEVICE.Device>
|
||||
rowKey="deviceSn"
|
||||
headerTitle="设备管理"
|
||||
actionRef={actionRef}
|
||||
request={async (params, sorter, filter) => {
|
||||
const res = await device({
|
||||
page: params.current,
|
||||
limit: params.pageSize,
|
||||
searchKey: params.searchKey,
|
||||
searchValue: params.searchValue,
|
||||
});
|
||||
|
||||
return {
|
||||
data: res.data || [],
|
||||
success: res.resp_code === 0,
|
||||
total: res.count || 0,
|
||||
};
|
||||
}}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={searchParams}
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button key="template" onClick={handleDownloadTemplate}>
|
||||
<DownloadOutlined /> 下载模板
|
||||
</Button>,
|
||||
<Button key="export" onClick={handleExport}>
|
||||
<ExportOutlined /> 导出
|
||||
</Button>,
|
||||
<Upload
|
||||
key="import"
|
||||
name="file"
|
||||
accept=".xlsx,.xls"
|
||||
maxCount={1}
|
||||
action="/api-device/device/import"
|
||||
showUploadList={false}
|
||||
onChange={(info) => {
|
||||
if (info.file.status === 'done') {
|
||||
if (info.file.response.resp_code === 0) {
|
||||
message.success('导入成功');
|
||||
actionRef.current?.reload();
|
||||
} else {
|
||||
message.error(info.file.response.resp_msg || '导入失败');
|
||||
}
|
||||
} else if (info.file.status === 'error') {
|
||||
message.error('导入失败');
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Button>
|
||||
<ImportOutlined /> 导入
|
||||
</Button>
|
||||
</Upload>,
|
||||
<Button type="primary" onClick={() => handleModalVisible(true)}>
|
||||
<PlusOutlined /> 新增
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
|
||||
<ModalForm
|
||||
title="新增设备"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={handleModalVisible}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (values) => {
|
||||
const success = await handleRequest(
|
||||
() => saveOrUpdateDevice(values),
|
||||
'正在添加',
|
||||
'添加成功'
|
||||
);
|
||||
if (success) {
|
||||
handleModalVisible(false);
|
||||
actionRef.current?.reload();
|
||||
}
|
||||
return success;
|
||||
}}
|
||||
>
|
||||
{renderModalContent()}
|
||||
</ModalForm>
|
||||
|
||||
{updateModalVisible && (
|
||||
<UpdateForm
|
||||
onSubmit={async (values) => {
|
||||
const success = await handleRequest(
|
||||
() => saveOrUpdateDevice({ ...values, id: currentRow?.id }),
|
||||
'正在更新',
|
||||
'更新成功'
|
||||
);
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
actionRef.current?.reload();
|
||||
}
|
||||
}}
|
||||
onVisibleChange={handleUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 添加视频播放弹窗 */}
|
||||
{streamUrls && (
|
||||
<VideoPlayer
|
||||
visible={videoModalVisible}
|
||||
onClose={() => {
|
||||
setVideoModalVisible(false);
|
||||
setStreamUrls(null);
|
||||
}}
|
||||
streamUrls={streamUrls}
|
||||
deviceSn={currentRow?.deviceSn || ''}
|
||||
/>
|
||||
)}
|
||||
|
||||
{currentRow && (
|
||||
<DeviceControlPanel
|
||||
visible={controlPanelVisible}
|
||||
onClose={() => {
|
||||
setControlPanelVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
}}
|
||||
deviceSn={currentRow.deviceSn}
|
||||
/>
|
||||
)}
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default TableList;
|
||||
@@ -1,182 +0,0 @@
|
||||
import { importImage } from '@/services/system/api';
|
||||
import { UploadOutlined } from '@ant-design/icons';
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormSelect,
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, Form, message, Upload } from 'antd';
|
||||
import type { RcFile } from 'antd/lib/upload';
|
||||
import { useState, useRef, useEffect } from 'react';
|
||||
import styles from '../index.less';
|
||||
import { TOURISM_OPTIONS, TYPE_OPTIONS, WORKSPACE_OPTIONS } from '../index';
|
||||
import SparkMD5 from 'spark-md5';
|
||||
|
||||
export type FormValueType = Partial<ORDERS.TourismFile>;
|
||||
|
||||
export type UpdateFormProps = {
|
||||
onSubmit: (values: Partial<DEVICE.Wayline>) => Promise<void>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
updateModalVisible: boolean;
|
||||
values?: DEVICE.Wayline;
|
||||
onUpload: (fileInfo: FileResponse) => void;
|
||||
};
|
||||
|
||||
const calculateFileMD5 = (file: File): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
const spark = new SparkMD5.ArrayBuffer();
|
||||
|
||||
reader.onload = (e) => {
|
||||
if (e.target?.result) {
|
||||
spark.append(e.target.result as ArrayBuffer);
|
||||
const md5 = spark.end();
|
||||
resolve(md5);
|
||||
} else {
|
||||
reject(new Error('Failed to read file'));
|
||||
}
|
||||
};
|
||||
|
||||
reader.onerror = (error) => reject(error);
|
||||
reader.readAsArrayBuffer(file);
|
||||
});
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const { onSubmit, onVisibleChange, updateModalVisible, values, onUpload } = props;
|
||||
const [fileInfo, setFileInfo] = useState<FileResponse | undefined>();
|
||||
const formRef = useRef<any>();
|
||||
|
||||
// 确保所有的hooks都在组件顶层
|
||||
useEffect(() => {
|
||||
if (values) {
|
||||
formRef.current?.setFieldsValue(values);
|
||||
}
|
||||
}, [values]);
|
||||
|
||||
const handleFileUpload = async (file: RcFile) => {
|
||||
const hide = message.loading('正在上传文件...');
|
||||
try {
|
||||
const sign = await calculateFileMD5(file);
|
||||
console.log('新文件签名:', sign);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('sign', sign);
|
||||
|
||||
const result = await importImage(formData);
|
||||
console.log('上传接口返回结果:', result);
|
||||
|
||||
if (!result || !result.id) {
|
||||
hide();
|
||||
message.error('上传失败:未获取到文件信息');
|
||||
return false;
|
||||
}
|
||||
|
||||
const newFileInfo = {
|
||||
id: result.id,
|
||||
name: result.name || file.name,
|
||||
url: result.url || '',
|
||||
sign: sign
|
||||
};
|
||||
|
||||
setFileInfo(newFileInfo);
|
||||
formRef.current?.setFieldsValue({
|
||||
waylineId: newFileInfo.id,
|
||||
name: newFileInfo.name,
|
||||
sign: newFileInfo.sign
|
||||
});
|
||||
|
||||
onUpload?.(newFileInfo);
|
||||
|
||||
hide();
|
||||
message.success('文件上传成功');
|
||||
return false;
|
||||
} catch (error: any) {
|
||||
hide();
|
||||
console.error('文件上传错误:', error);
|
||||
message.error('文件上传失败:' + (error?.message || '未知错误'));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改航线"
|
||||
formRef={formRef}
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={(visible) => {
|
||||
onVisibleChange?.(visible);
|
||||
if (!visible) {
|
||||
setFileInfo(undefined);
|
||||
}
|
||||
}}
|
||||
onFinish={async (values) => {
|
||||
if (onSubmit) {
|
||||
const updatedValues = {
|
||||
...values,
|
||||
...(fileInfo ? {
|
||||
waylineId: fileInfo.id,
|
||||
sign: fileInfo.sign
|
||||
} : {})
|
||||
};
|
||||
return onSubmit(updatedValues);
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '航线名称不能为空' }]}
|
||||
width="md"
|
||||
name="name"
|
||||
label="航线名称"
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '工作区不能为空' }]}
|
||||
width="md"
|
||||
name="workspaceId"
|
||||
label="工作区"
|
||||
options={WORKSPACE_OPTIONS}
|
||||
/>
|
||||
<ProFormText
|
||||
hidden
|
||||
name="waylineId"
|
||||
/>
|
||||
<ProFormText
|
||||
hidden
|
||||
name="sign"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<div style={{ width: '328px', marginBottom: 24 }}>
|
||||
<div style={{ marginBottom: 8 }}>航线文件:</div>
|
||||
<Upload
|
||||
maxCount={1}
|
||||
accept=".kmz,.kml"
|
||||
showUploadList={false}
|
||||
beforeUpload={handleFileUpload}
|
||||
>
|
||||
<Button icon={<UploadOutlined />}>
|
||||
重新上传航线文件
|
||||
</Button>
|
||||
</Upload>
|
||||
{fileInfo && (
|
||||
<div style={{ marginTop: 8 }}>
|
||||
<div style={{ color: '#52c41a' }}>
|
||||
已上传:{fileInfo.name}
|
||||
</div>
|
||||
<div style={{ color: '#666', fontSize: '12px' }}>
|
||||
文件签名:{fileInfo.sign}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateForm;
|
||||
@@ -1 +0,0 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
@@ -1,448 +0,0 @@
|
||||
import { deleteWayline, saveOrUpdateWayline, wayline } from '@/services/device/api';
|
||||
import { importImage } from '@/services/system/api';
|
||||
import { PlusOutlined, UploadOutlined } from '@ant-design/icons';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
ModalForm,
|
||||
PageContainer,
|
||||
ProForm,
|
||||
ProFormSelect,
|
||||
ProFormText,
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, Popconfirm, Space, message, Image, Button, Tag, Upload } from 'antd';
|
||||
import type { RcFile } from 'antd/lib/upload';
|
||||
import React, { useRef, useState, useCallback } from 'react';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import styles from './index.less';
|
||||
import SparkMD5 from 'spark-md5';
|
||||
import type { DefaultOptionType } from 'antd/es/select';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
// 状态映射
|
||||
const statusColorMap = {
|
||||
0: { color: 'green', text: '启用' },
|
||||
1: { color: 'red', text: '未启用' },
|
||||
};
|
||||
|
||||
// 提取常量
|
||||
export const WORKSPACE_OPTIONS: DefaultOptionType[] = [
|
||||
{ label: '工作区1', value: '1' },
|
||||
{ label: '工作区2', value: '2' },
|
||||
// ... 根据实际需求添加更多选项
|
||||
];
|
||||
|
||||
// 统一错误处理
|
||||
const handleApiRequest = async (
|
||||
apiCall: () => Promise<any>,
|
||||
loadingMessage: string,
|
||||
successMessage: string,
|
||||
) => {
|
||||
const hide = message.loading(loadingMessage);
|
||||
try {
|
||||
const result = await apiCall();
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success(successMessage);
|
||||
return true;
|
||||
}
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error(`${successMessage}失败`);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 处理函数优化
|
||||
const handleAdd = async (fields: DEVICE.Wayline) => {
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateWayline({ ...fields }),
|
||||
'正在添加',
|
||||
'添加成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleEdit = async (original: DEVICE.Wayline, fields: Partial<DEVICE.Wayline>) => {
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateWayline({
|
||||
id: original.id,
|
||||
...fields
|
||||
}),
|
||||
'正在更新',
|
||||
'修改成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleDelete = async (tourismFile: DEVICE.Wayline) => {
|
||||
return handleApiRequest(
|
||||
() => deleteWayline(tourismFile.id),
|
||||
'正在删除',
|
||||
'删除成功'
|
||||
);
|
||||
};
|
||||
|
||||
const calculateFileMD5 = (file: File): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
const spark = new SparkMD5.ArrayBuffer();
|
||||
|
||||
reader.onload = (e) => {
|
||||
if (e.target?.result) {
|
||||
spark.append(e.target.result as ArrayBuffer);
|
||||
const md5 = spark.end();
|
||||
resolve(md5);
|
||||
} else {
|
||||
reject(new Error('Failed to read file'));
|
||||
}
|
||||
};
|
||||
|
||||
reader.onerror = (error) => reject(error);
|
||||
reader.readAsArrayBuffer(file);
|
||||
});
|
||||
};
|
||||
|
||||
const checkSignExists = async (sign: string) => {
|
||||
const response = await fetch(`/api/wayline/check-sign?sign=${sign}`);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
interface FileResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
url: string;
|
||||
sign?: string;
|
||||
}
|
||||
|
||||
interface ExtendedWayline extends DEVICE.Wayline {
|
||||
fileUrl?: string;
|
||||
}
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<ExtendedWayline>();
|
||||
const [fileInfo, setFileInfo] = useState<FileResponse>();
|
||||
const formRef = useRef<any>();
|
||||
|
||||
const handleFileUpload = async (file: RcFile) => {
|
||||
const hide = message.loading('正在上传文件...');
|
||||
try {
|
||||
const sign = await calculateFileMD5(file);
|
||||
console.log('文件签名:', sign);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('sign', sign);
|
||||
|
||||
const result = await importImage(formData);
|
||||
console.log('上传接口返回结果:', result);
|
||||
|
||||
if (!result || !result.id) {
|
||||
hide();
|
||||
message.error('上传失败:未获取到文件信息');
|
||||
return false;
|
||||
}
|
||||
|
||||
const fileResponse: FileResponse = {
|
||||
id: result.id,
|
||||
name: result.name || file.name,
|
||||
url: result.url || '',
|
||||
sign: sign
|
||||
};
|
||||
|
||||
setFileInfo(fileResponse);
|
||||
formRef.current?.setFieldsValue({
|
||||
waylineId: fileResponse.id,
|
||||
name: fileResponse.name,
|
||||
sign: fileResponse.sign
|
||||
});
|
||||
|
||||
hide();
|
||||
message.success('文件上传成功');
|
||||
return false;
|
||||
} catch (error: any) {
|
||||
hide();
|
||||
console.error('文件上传错误:', error);
|
||||
message.error('文件上传失败:' + (error?.message || '未知错误'));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleTableAction = useCallback(async (
|
||||
action: 'add' | 'edit' | 'delete',
|
||||
record?: ExtendedWayline,
|
||||
values?: Partial<DEVICE.Wayline>
|
||||
): Promise<boolean> => {
|
||||
let success = false;
|
||||
switch (action) {
|
||||
case 'add':
|
||||
if (!fileInfo) {
|
||||
message.error('请上传航线文件');
|
||||
return false;
|
||||
}
|
||||
if (!fileInfo.sign) {
|
||||
message.error('文件签名获取失败');
|
||||
return false;
|
||||
}
|
||||
const waylineData: Omit<DEVICE.Wayline, 'id' | 'createTime' | 'tenantId' | 'updateTime'> = {
|
||||
waylineId: fileInfo.id,
|
||||
name: values?.name || fileInfo.name,
|
||||
sign: fileInfo.sign,
|
||||
droneModelKey: values?.droneModelKey || '',
|
||||
payloadModelKeys: values?.payloadModelKeys || '',
|
||||
workspaceId: values?.workspaceId || '',
|
||||
favorited: (values?.favorited?.toString() || '0') as string,
|
||||
templateTypes: values?.templateTypes || '',
|
||||
userName: values?.userName || ''
|
||||
};
|
||||
success = await handleAdd(waylineData as DEVICE.Wayline);
|
||||
if (success) {
|
||||
handleModalVisible(false);
|
||||
setFileInfo(undefined);
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
if (record) {
|
||||
const updateData = {
|
||||
...values,
|
||||
...(fileInfo ? {
|
||||
fileUrl: fileInfo.url,
|
||||
waylineId: fileInfo.id,
|
||||
sign: fileInfo.sign
|
||||
} : {})
|
||||
};
|
||||
success = await handleEdit(record, updateData);
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
setFileInfo(undefined);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if (record) {
|
||||
success = await handleDelete(record);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
return success;
|
||||
}, [fileInfo]);
|
||||
|
||||
const columns: ProColumns<ExtendedWayline>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
},
|
||||
{
|
||||
title: '航线名称',
|
||||
dataIndex: 'name',
|
||||
},
|
||||
{
|
||||
title: '航线id',
|
||||
dataIndex: 'waylineId',
|
||||
},
|
||||
{
|
||||
title: '地区ID',
|
||||
dataIndex: 'workspaceId',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '航线文件',
|
||||
dataIndex: 'fileUrl',
|
||||
render: (_, record) => record.fileUrl ? (
|
||||
<a
|
||||
href={record.fileUrl}
|
||||
download={record.name}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
const link = document.createElement('a');
|
||||
link.href = record.fileUrl || '';
|
||||
link.download = record.name || 'wayline.kmz';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}}
|
||||
>
|
||||
下载文件
|
||||
</a>
|
||||
) : '-'
|
||||
},
|
||||
{
|
||||
title: '文件签名',
|
||||
dataIndex: 'sign',
|
||||
copyable: true,
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, entity) =>
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(entity);
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除素材[${entity.id}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleTableAction('delete', entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '航线管理' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
span={6}
|
||||
className="query-filter"
|
||||
onFinish={async (values) => setParams(values)}
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
</QueryFilter>
|
||||
<ProTable<ExtendedWayline>
|
||||
rowKey="id"
|
||||
headerTitle="航线列表"
|
||||
request={wayline}
|
||||
actionRef={actionRef}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={params}
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button
|
||||
type="primary"
|
||||
key="add"
|
||||
onClick={() => {
|
||||
handleModalVisible(true);
|
||||
}}
|
||||
>
|
||||
<PlusOutlined /> 添加
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
<ModalForm
|
||||
title="添加航线"
|
||||
visible={createModalVisible}
|
||||
formRef={formRef}
|
||||
onVisibleChange={(visible) => {
|
||||
handleModalVisible(visible);
|
||||
if (!visible) {
|
||||
setFileInfo(undefined);
|
||||
}
|
||||
}}
|
||||
modalProps={{
|
||||
destroyOnClose: true,
|
||||
onCancel: () => {
|
||||
setFileInfo(undefined);
|
||||
}
|
||||
}}
|
||||
onFinish={async (values) => {
|
||||
if (!fileInfo) {
|
||||
message.error('请上传航线文件');
|
||||
return false;
|
||||
}
|
||||
return handleTableAction('add', undefined, values);
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '航线名称不能为空' }]}
|
||||
width="md"
|
||||
name="name"
|
||||
label="航线名称"
|
||||
placeholder="请输入航线名称"
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '工作区不能为空' }]}
|
||||
width="md"
|
||||
name="workspaceId"
|
||||
label="工作区"
|
||||
placeholder="请选择工作区"
|
||||
options={WORKSPACE_OPTIONS}
|
||||
/>
|
||||
<ProFormText
|
||||
hidden
|
||||
name="waylineId"
|
||||
/>
|
||||
<ProFormText
|
||||
hidden
|
||||
name="sign"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<div style={{ width: '328px', marginBottom: 24 }}>
|
||||
<div style={{ marginBottom: 8 }}>航线文件:</div>
|
||||
<Upload
|
||||
maxCount={1}
|
||||
accept=".kmz,.kml"
|
||||
showUploadList={false}
|
||||
beforeUpload={handleFileUpload}
|
||||
>
|
||||
<Button icon={<UploadOutlined />}>
|
||||
{fileInfo ? '重新上传' : '上传文件'}
|
||||
</Button>
|
||||
</Upload>
|
||||
{fileInfo && (
|
||||
<div style={{ marginTop: 8 }}>
|
||||
<div style={{ color: '#52c41a' }}>
|
||||
已上传:{fileInfo.name}
|
||||
</div>
|
||||
<div style={{ color: '#666', fontSize: '12px' }}>
|
||||
文件签名:{fileInfo.sign}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
<UpdateForm
|
||||
onSubmit={async (values) => {
|
||||
await handleTableAction('edit', currentRow, values);
|
||||
}}
|
||||
onVisibleChange={(visible) => {
|
||||
handleUpdateModalVisible(visible);
|
||||
if (!visible) {
|
||||
setFileInfo(undefined);
|
||||
}
|
||||
}}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
onUpload={setFileInfo}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default TableList;
|
||||
@@ -1,226 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="theme-color" content="#1890ff" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="keywords"
|
||||
content="antd,umi,umijs,ant design,Scaffolding, layout, Ant Design, project, Pro, admin, console, homepage, out-of-the-box, middle and back office, solution, component library" />
|
||||
<meta name="description" content="
|
||||
An out-of-box UI solution for enterprise applications as a React boilerplate." />
|
||||
<meta name="description" content="
|
||||
Out-of-the-box mid-stage front-end/design solution." />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
|
||||
<title>Iking-Platform</title>
|
||||
<link rel="icon" href="<%= context.config.publicPath +'favicon.ico'%>" type="image/x-icon" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript>
|
||||
<div class="noscript-container">
|
||||
Hi there! Please
|
||||
<div class="noscript-enableJS">
|
||||
<a href="https://www.enablejavascript.io/en" target="_blank" rel="noopener noreferrer">
|
||||
<b>enable Javascript</b>
|
||||
</a>
|
||||
</div>
|
||||
in your browser to use Ant Design, Out-of-the-box mid-stage front/design solution!
|
||||
</div>
|
||||
</noscript>
|
||||
<div id="root">
|
||||
<style>
|
||||
html,
|
||||
body,
|
||||
#root {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#root {
|
||||
background-repeat: no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
.noscript-container {
|
||||
display: flex;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
margin-top: 90px;
|
||||
font-size: 20px;
|
||||
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode',
|
||||
Geneva, Verdana, sans-serif;
|
||||
}
|
||||
|
||||
.noscript-enableJS {
|
||||
padding-right: 3px;
|
||||
padding-left: 3px;
|
||||
}
|
||||
|
||||
.page-loading-warp {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 98px;
|
||||
}
|
||||
|
||||
.ant-spin {
|
||||
position: absolute;
|
||||
display: none;
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: rgba(0, 0, 0, 0.65);
|
||||
color: #1890ff;
|
||||
font-size: 14px;
|
||||
font-variant: tabular-nums;
|
||||
line-height: 1.5;
|
||||
text-align: center;
|
||||
list-style: none;
|
||||
opacity: 0;
|
||||
-webkit-transition: -webkit-transform 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
|
||||
transition: -webkit-transform 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
|
||||
transition: transform 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
|
||||
transition: transform 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86),
|
||||
-webkit-transform 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
|
||||
-webkit-font-feature-settings: 'tnum';
|
||||
font-feature-settings: 'tnum';
|
||||
}
|
||||
|
||||
.ant-spin-spinning {
|
||||
position: static;
|
||||
display: inline-block;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.ant-spin-dot {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.ant-spin-dot-item {
|
||||
position: absolute;
|
||||
display: block;
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
background-color: #1890ff;
|
||||
border-radius: 100%;
|
||||
-webkit-transform: scale(0.75);
|
||||
-ms-transform: scale(0.75);
|
||||
transform: scale(0.75);
|
||||
-webkit-transform-origin: 50% 50%;
|
||||
-ms-transform-origin: 50% 50%;
|
||||
transform-origin: 50% 50%;
|
||||
opacity: 0.3;
|
||||
-webkit-animation: antspinmove 1s infinite linear alternate;
|
||||
animation: antSpinMove 1s infinite linear alternate;
|
||||
}
|
||||
|
||||
.ant-spin-dot-item:nth-child(1) {
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.ant-spin-dot-item:nth-child(2) {
|
||||
top: 0;
|
||||
right: 0;
|
||||
-webkit-animation-delay: 0.4s;
|
||||
animation-delay: 0.4s;
|
||||
}
|
||||
|
||||
.ant-spin-dot-item:nth-child(3) {
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
-webkit-animation-delay: 0.8s;
|
||||
animation-delay: 0.8s;
|
||||
}
|
||||
|
||||
.ant-spin-dot-item:nth-child(4) {
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
-webkit-animation-delay: 1.2s;
|
||||
animation-delay: 1.2s;
|
||||
}
|
||||
|
||||
.ant-spin-dot-spin {
|
||||
-webkit-transform: rotate(45deg);
|
||||
-ms-transform: rotate(45deg);
|
||||
transform: rotate(45deg);
|
||||
-webkit-animation: antrotate 1.2s infinite linear;
|
||||
animation: antRotate 1.2s infinite linear;
|
||||
}
|
||||
|
||||
.ant-spin-lg .ant-spin-dot {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.ant-spin-lg .ant-spin-dot i {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
|
||||
@media all and (-ms-high-contrast: none),
|
||||
(-ms-high-contrast: active) {
|
||||
.ant-spin-blur {
|
||||
background: #fff;
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
@-webkit-keyframes antSpinMove {
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes antSpinMove {
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@-webkit-keyframes antRotate {
|
||||
to {
|
||||
-webkit-transform: rotate(405deg);
|
||||
transform: rotate(405deg);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes antRotate {
|
||||
to {
|
||||
-webkit-transform: rotate(405deg);
|
||||
transform: rotate(405deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<div style="
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
min-height: 420px;
|
||||
">
|
||||
<img src="<%= context.config.publicPath +'campaign.svg'%>" alt="logo" width="256" />
|
||||
<div class="page-loading-warp">
|
||||
<div class="ant-spin ant-spin-lg ant-spin-spinning">
|
||||
<span class="ant-spin-dot ant-spin-dot-spin"><i class="ant-spin-dot-item"></i><i
|
||||
class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
<div style="display: flex; align-items: center; justify-content: center">
|
||||
<img src="/logo.png" width="32" style="margin-right: 8px" />
|
||||
microservices-platform
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,85 +0,0 @@
|
||||
.searchCard {
|
||||
margin-bottom: 16px;
|
||||
|
||||
.searchForm {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
|
||||
.searchLeft {
|
||||
flex: 1;
|
||||
min-width: 300px;
|
||||
}
|
||||
|
||||
.searchRight {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.actionCard {
|
||||
margin-bottom: 16px;
|
||||
|
||||
.actionBar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
.actionLeft {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.actionRight {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 状态样式
|
||||
:global {
|
||||
.status-success {
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.status-processing {
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.status-error {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.status-default {
|
||||
color: #666;
|
||||
}
|
||||
}
|
||||
|
||||
// 响应式设计
|
||||
@media (max-width: 768px) {
|
||||
.searchCard {
|
||||
.searchForm {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
.searchLeft,
|
||||
.searchRight {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.actionCard {
|
||||
.actionBar {
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
|
||||
.actionLeft,
|
||||
.actionRight {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,283 +0,0 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Card, Table, Space, Button, DatePicker, Input, message } from 'antd';
|
||||
import { SearchOutlined, ReloadOutlined, PlusOutlined } from '@ant-design/icons';
|
||||
import { PageContainer } from '@ant-design/pro-components';
|
||||
import TenantSelector from '@/components/TenantSelector';
|
||||
import { tenantApi } from '@/services/tenant';
|
||||
import styles from './index.less';
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
interface OrderItem {
|
||||
id: string;
|
||||
orderNo: string;
|
||||
orderAmount: number;
|
||||
orderStatus: string;
|
||||
createTime: string;
|
||||
tenantId: string;
|
||||
tenantName: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 租户选择器使用示例页面
|
||||
* 演示如何在订单管理页面中集成租户选择器
|
||||
*/
|
||||
const TenantExamplePage: React.FC = () => {
|
||||
const [orderList, setOrderList] = useState<OrderItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [currentTenant, setCurrentTenant] = useState<string>('');
|
||||
const [searchParams, setSearchParams] = useState({
|
||||
orderNo: '',
|
||||
dateRange: undefined as any,
|
||||
});
|
||||
const [pagination, setPagination] = useState({
|
||||
current: 1,
|
||||
pageSize: 20,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
loadCurrentTenant();
|
||||
loadOrderList();
|
||||
}, [pagination.current, pagination.pageSize, currentTenant]);
|
||||
|
||||
const loadCurrentTenant = async () => {
|
||||
try {
|
||||
const result = await tenantApi.getCurrentTenant();
|
||||
if (result.success) {
|
||||
setCurrentTenant(result.data.tenantId);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前租户失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const loadOrderList = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
// 模拟订单数据(实际项目中替换为真实API)
|
||||
const mockData: OrderItem[] = [
|
||||
{
|
||||
id: '1',
|
||||
orderNo: 'ORD202412190001',
|
||||
orderAmount: 1580.00,
|
||||
orderStatus: '已完成',
|
||||
createTime: '2024-12-19 10:30:00',
|
||||
tenantId: currentTenant,
|
||||
tenantName: '当前租户',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
orderNo: 'ORD202412190002',
|
||||
orderAmount: 2350.00,
|
||||
orderStatus: '处理中',
|
||||
createTime: '2024-12-19 11:15:00',
|
||||
tenantId: currentTenant,
|
||||
tenantName: '当前租户',
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
orderNo: 'ORD202412190003',
|
||||
orderAmount: 980.00,
|
||||
orderStatus: '已取消',
|
||||
createTime: '2024-12-19 14:20:00',
|
||||
tenantId: currentTenant,
|
||||
tenantName: '当前租户',
|
||||
},
|
||||
];
|
||||
|
||||
setOrderList(mockData);
|
||||
setPagination(prev => ({
|
||||
...prev,
|
||||
total: mockData.length,
|
||||
}));
|
||||
|
||||
message.success(`加载${mockData.length}条数据`);
|
||||
} catch (error) {
|
||||
console.error('加载订单列表失败:', error);
|
||||
message.error('加载数据失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 租户切换时重新加载数据
|
||||
const handleTenantChange = (tenantId: string) => {
|
||||
console.log('切换到租户:', tenantId);
|
||||
setCurrentTenant(tenantId);
|
||||
// 重置分页并重新加载数据
|
||||
setPagination(prev => ({ ...prev, current: 1 }));
|
||||
message.info(`已切换到租户: ${tenantId}`);
|
||||
};
|
||||
|
||||
const handleSearch = () => {
|
||||
setPagination(prev => ({ ...prev, current: 1 }));
|
||||
loadOrderList();
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
setSearchParams({
|
||||
orderNo: '',
|
||||
dateRange: undefined,
|
||||
});
|
||||
setPagination(prev => ({ ...prev, current: 1 }));
|
||||
loadOrderList();
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: '订单号',
|
||||
dataIndex: 'orderNo',
|
||||
key: 'orderNo',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '金额',
|
||||
dataIndex: 'orderAmount',
|
||||
key: 'orderAmount',
|
||||
width: 120,
|
||||
render: (amount: number) => `¥${amount.toFixed(2)}`,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'orderStatus',
|
||||
key: 'orderStatus',
|
||||
width: 100,
|
||||
render: (status: string) => {
|
||||
const colorMap: Record<string, string> = {
|
||||
'已完成': 'success',
|
||||
'处理中': 'processing',
|
||||
'已取消': 'error',
|
||||
};
|
||||
return (
|
||||
<span className={`status-${colorMap[status] || 'default'}`}>
|
||||
{status}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '所属租户',
|
||||
dataIndex: 'tenantName',
|
||||
key: 'tenantName',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 150,
|
||||
render: (_, record: OrderItem) => (
|
||||
<Space size="middle">
|
||||
<a onClick={() => message.info(`查看订单: ${record.orderNo}`)}>查看</a>
|
||||
<a onClick={() => message.info(`编辑订单: ${record.orderNo}`)}>编辑</a>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer
|
||||
title="订单管理(租户选择器示例)"
|
||||
content="演示如何在管理页面中集成租户选择器组件"
|
||||
>
|
||||
{/* 页面头部:租户选择器和搜索条件 */}
|
||||
<Card size="small" className={styles.searchCard}>
|
||||
<div className={styles.searchForm}>
|
||||
<div className={styles.searchLeft}>
|
||||
<TenantSelector
|
||||
onChange={handleTenantChange}
|
||||
showCurrentInfo={true}
|
||||
placeholder="选择查询租户范围"
|
||||
style={{ width: 320 }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className={styles.searchRight}>
|
||||
<Space size="middle">
|
||||
<Input
|
||||
placeholder="订单号"
|
||||
value={searchParams.orderNo}
|
||||
onChange={(e) => setSearchParams(prev => ({ ...prev, orderNo: e.target.value }))}
|
||||
style={{ width: 150 }}
|
||||
/>
|
||||
<RangePicker
|
||||
value={searchParams.dateRange}
|
||||
onChange={(dates) => setSearchParams(prev => ({ ...prev, dateRange: dates }))}
|
||||
style={{ width: 240 }}
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<SearchOutlined />}
|
||||
onClick={handleSearch}
|
||||
>
|
||||
查询
|
||||
</Button>
|
||||
<Button
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={handleReset}
|
||||
>
|
||||
重置
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* 操作栏 */}
|
||||
<Card size="small" className={styles.actionCard}>
|
||||
<div className={styles.actionBar}>
|
||||
<div className={styles.actionLeft}>
|
||||
<Space>
|
||||
<Button type="primary" icon={<PlusOutlined />}>
|
||||
新建订单
|
||||
</Button>
|
||||
<Button>批量导出</Button>
|
||||
</Space>
|
||||
</div>
|
||||
<div className={styles.actionRight}>
|
||||
<Button
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={() => loadOrderList()}
|
||||
loading={loading}
|
||||
>
|
||||
刷新数据
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* 数据表格 */}
|
||||
<Card>
|
||||
<Table
|
||||
dataSource={orderList}
|
||||
columns={columns}
|
||||
loading={loading}
|
||||
rowKey="id"
|
||||
pagination={{
|
||||
...pagination,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) =>
|
||||
`第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
onChange: (page, pageSize) => {
|
||||
setPagination(prev => ({
|
||||
...prev,
|
||||
current: page,
|
||||
pageSize: pageSize || 20,
|
||||
}));
|
||||
},
|
||||
}}
|
||||
scroll={{ x: 1000 }}
|
||||
/>
|
||||
</Card>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default TenantExamplePage;
|
||||
@@ -1 +0,0 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
@@ -1,119 +0,0 @@
|
||||
import { deleteFile, file } from '@/services/files/api';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
PageContainer,
|
||||
ProFormText,
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, message, Popconfirm, Image } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
const handleDelete = async (deletefile: FILES.File) => {
|
||||
const hide = message.loading('正在删除');
|
||||
try {
|
||||
const result = await deleteFile(deletefile.id);
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('删除File成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('删除File失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [params, setParams] = useState<Record<string, string | number>>({ });
|
||||
const columns: ProColumns<FILES.File>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
},
|
||||
{
|
||||
title: '流媒体名称',
|
||||
dataIndex: 'name',
|
||||
},
|
||||
{
|
||||
title: '文件大小(B)',
|
||||
dataIndex: 'size',
|
||||
valueType: 'digit',
|
||||
},
|
||||
{
|
||||
title: '文件预览',
|
||||
dataIndex: 'url',
|
||||
render: (url) => <Image src={url} width={100} />
|
||||
},
|
||||
{
|
||||
title: '媒体类型',
|
||||
dataIndex: 'contentType',
|
||||
},
|
||||
{
|
||||
title: '文件系统',
|
||||
dataIndex: 'grantType',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '内容',
|
||||
dataIndex: 'accountType',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, entity) => <Popconfirm
|
||||
title={`确认删除文件[${entity.name}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleDelete(entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '管理文件' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
span={6}
|
||||
className="query-filter"
|
||||
onFinish={async (values) => setParams(values)}
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
</QueryFilter>
|
||||
<ProTable<FILES.File>
|
||||
rowKey="id"
|
||||
headerTitle="文件管理"
|
||||
request={file}
|
||||
actionRef={actionRef}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={params}
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default TableList;
|
||||
@@ -1 +0,0 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
@@ -1,122 +0,0 @@
|
||||
import { auditlog } from '@/services/search/api';
|
||||
import type { ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
PageContainer,
|
||||
ProFormText,
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
ProFormSelect,
|
||||
} from '@ant-design/pro-components';
|
||||
import React, { useState } from 'react';
|
||||
import moment from 'moment';
|
||||
|
||||
const AuditLog: React.FC = () => {
|
||||
const [params, setParams] = useState<Record<string, string | number>>();
|
||||
|
||||
const columns: ProColumns<SEARCH.AuditLog>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 20,
|
||||
},
|
||||
{
|
||||
title: '日志时间',
|
||||
key: 'timestamp',
|
||||
width: 75,
|
||||
render(_, entity) {
|
||||
return moment(entity.timestamp).format('YYYY-MM-DD HH:mm:SS');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '用户id',
|
||||
dataIndex: 'userId',
|
||||
width: 30,
|
||||
},
|
||||
{
|
||||
title: '用户名',
|
||||
dataIndex: 'userName',
|
||||
width: 40,
|
||||
},
|
||||
{
|
||||
title: '租户id',
|
||||
dataIndex: 'clientId',
|
||||
width: 50,
|
||||
},
|
||||
{
|
||||
title: '操作信息',
|
||||
dataIndex: 'operation',
|
||||
width: 150,
|
||||
ellipsis: true,
|
||||
render: (_, entity) =>
|
||||
entity.operation && <span dangerouslySetInnerHTML={{ __html: entity.operation }} />,
|
||||
},
|
||||
{
|
||||
title: '应用名',
|
||||
dataIndex: 'appName',
|
||||
width: 50,
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '类名',
|
||||
dataIndex: 'className',
|
||||
width: 150,
|
||||
ellipsis: true,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '查看系统日志' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
span={8}
|
||||
className="query-filter"
|
||||
onFinish={async (values) => {
|
||||
let queryStr = '';
|
||||
const { searchKey, searchValue } = values;
|
||||
if (searchKey && searchValue) {
|
||||
if (searchKey === 'none') {
|
||||
queryStr = searchValue;
|
||||
} else {
|
||||
queryStr = `${searchKey}:${searchValue}`;
|
||||
}
|
||||
}
|
||||
setParams({ ...params, queryStr });
|
||||
}}
|
||||
// onReset={() => setParams({})}
|
||||
>
|
||||
<ProFormSelect
|
||||
name="searchKey"
|
||||
label="搜索"
|
||||
valueEnum={{
|
||||
none: '全文搜索',
|
||||
appName: '应用名',
|
||||
classname: '类别',
|
||||
methodName: '方法名',
|
||||
userId: '用户ID',
|
||||
userName: '用户名',
|
||||
clientId: '租户ID',
|
||||
operation: '操作信息',
|
||||
}}
|
||||
/>
|
||||
<ProFormText name="searchValue" />
|
||||
</QueryFilter>
|
||||
<ProTable<SEARCH.AuditLog>
|
||||
className="audit-log"
|
||||
rowKey="id"
|
||||
headerTitle="系统日志"
|
||||
request={auditlog}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={params}
|
||||
size="small"
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default AuditLog;
|
||||
@@ -1 +0,0 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
@@ -1,104 +0,0 @@
|
||||
import { slowQueryLog } from '@/services/search/api';
|
||||
import type { ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
PageContainer,
|
||||
ProFormText,
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
ProFormSelect,
|
||||
} from '@ant-design/pro-components';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
const SlowSqlLog: React.FC = () => {
|
||||
const [params, setParams] = useState<Record<string, string | number>>();
|
||||
|
||||
const columns: ProColumns<SEARCH.SlowSqlLog>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 20,
|
||||
},
|
||||
{
|
||||
title: '日志时间',
|
||||
key: 'timestamp',
|
||||
width: 75,
|
||||
},
|
||||
{
|
||||
title: '查询语句',
|
||||
dataIndex: 'userId',
|
||||
width: 30,
|
||||
},
|
||||
{
|
||||
title: '查询时间(ms)',
|
||||
dataIndex: 'userName',
|
||||
width: 40,
|
||||
},
|
||||
{
|
||||
title: '锁等待时间(ms)',
|
||||
dataIndex: 'clientId',
|
||||
width: 50,
|
||||
},
|
||||
{
|
||||
title: '返回行数',
|
||||
dataIndex: 'operation',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '优化器扫描行数',
|
||||
dataIndex: 'appName',
|
||||
width: 50,
|
||||
ellipsis: true,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '查看慢查询日志' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
span={8}
|
||||
className="query-filter"
|
||||
onFinish={async (values) => {
|
||||
let queryStr = '';
|
||||
const { searchKey, searchValue } = values;
|
||||
if (searchKey && searchValue) {
|
||||
if (searchKey === 'none') {
|
||||
queryStr = searchValue;
|
||||
} else {
|
||||
queryStr = `${searchKey}:${searchValue}`;
|
||||
}
|
||||
}
|
||||
setParams({ ...params, queryStr });
|
||||
}}
|
||||
// onReset={() => setParams({})}
|
||||
>
|
||||
<ProFormSelect
|
||||
name="searchKey"
|
||||
label="搜索"
|
||||
initialValue={['全文搜索']}
|
||||
valueEnum={{
|
||||
none: '全文搜索',
|
||||
query_str: '查询语句',
|
||||
}}
|
||||
/>
|
||||
<ProFormText name="searchValue" />
|
||||
</QueryFilter>
|
||||
<ProTable<SEARCH.SlowSqlLog>
|
||||
className="audit-log"
|
||||
rowKey="id"
|
||||
headerTitle="慢查询日志"
|
||||
request={slowQueryLog}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={params}
|
||||
size="small"
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default SlowSqlLog;
|
||||
@@ -1,76 +0,0 @@
|
||||
import { Button, Modal, Table } from 'antd';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { tracelog } from '@/services/search/api';
|
||||
import styles from '../index.less';
|
||||
import type { TableColumnType } from 'antd';
|
||||
import { treeify } from 'treeify-js';
|
||||
import { NodeIndexOutlined } from '@ant-design/icons';
|
||||
|
||||
type IndexViewProps = {
|
||||
traceId?: string;
|
||||
onCancel: () => void;
|
||||
open: boolean;
|
||||
};
|
||||
|
||||
const TraceView: React.FC<IndexViewProps> = (props) => {
|
||||
const [traces, setTraces] = useState<SEARCH.TraceLog[]>();
|
||||
const { traceId } = props;
|
||||
|
||||
const columns: TableColumnType<SEARCH.TraceLog>[] = [
|
||||
{
|
||||
title: '应用名',
|
||||
dataIndex: 'appName',
|
||||
},
|
||||
{
|
||||
title: 'spanId',
|
||||
dataIndex: 'spanId',
|
||||
},
|
||||
{
|
||||
title: '服务ip',
|
||||
dataIndex: 'serverIp',
|
||||
},
|
||||
{
|
||||
title: '服务端口',
|
||||
dataIndex: 'serverPort',
|
||||
},
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (traceId) {
|
||||
const data = (await tracelog(traceId)) ?? [];
|
||||
const treeData = treeify(data, { id: 'spanId', root: '-1', multi: true });
|
||||
setTraces(treeData);
|
||||
}
|
||||
})();
|
||||
}, [traceId]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={
|
||||
<>
|
||||
<NodeIndexOutlined />
|
||||
日志链路
|
||||
</>
|
||||
}
|
||||
className={styles.viewModal}
|
||||
width={800}
|
||||
open={props.open}
|
||||
onCancel={props.onCancel}
|
||||
footer={
|
||||
<Button type="primary" onClick={props.onCancel}>
|
||||
关闭
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Table<SEARCH.TraceLog>
|
||||
columns={columns}
|
||||
dataSource={traces}
|
||||
pagination={false}
|
||||
size="small"
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default TraceView;
|
||||