diff --git a/.claude/settings.local.json b/.claude/settings.local.json index dc995866..0d243460 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -72,7 +72,9 @@ "Bash(do if [ -f \"$file\" ])", "Bash(else echo \"✗ $file NOT FOUND\")", "Bash(fi)", - "Bash(done)" + "Bash(done)", + "Bash(tasklist:*)", + "Bash(test:*)" ], "deny": [], "ask": [] diff --git a/structure.txt b/structure.txt deleted file mode 100644 index d2123b66..00000000 Binary files a/structure.txt and /dev/null differ diff --git a/WebSocket订阅机制审计报告.md b/zlt-business/device-center/src/main/resources/doc/WebSocket订阅机制审计报告.md similarity index 100% rename from WebSocket订阅机制审计报告.md rename to zlt-business/device-center/src/main/resources/doc/WebSocket订阅机制审计报告.md diff --git a/zlt-business/msg-center/Dockerfile b/zlt-business/msg-center/Dockerfile new file mode 100644 index 00000000..00d92abd --- /dev/null +++ b/zlt-business/msg-center/Dockerfile @@ -0,0 +1,13 @@ +FROM openjdk:8u292 + +LABEL MAINTAINER=Andy +WORKDIR /apps +ADD target/msg-center.jar /apps/ +CMD ["java","-jar","msg-center.jar"] +# docker run --name msg-center \ +# -e spring_cloud_nacos_server_addr=10.0.0.12:8848 \ +# -e zlt_datasource_ip=10.0.0.12 \ +# -e zlt_datasource_username=root \ +# -e zlt_datasource_password=redhat \ +# -e spring_redis_host=10.0.0.12 \ +# -d msg-center:6.0.0 diff --git a/zlt-business/msg-center/README.md b/zlt-business/msg-center/README.md new file mode 100644 index 00000000..46af43c1 --- /dev/null +++ b/zlt-business/msg-center/README.md @@ -0,0 +1,563 @@ +# 消息中心 (msg-center) + +消息中心是一个独立的微服务模块,提供短信、邮件、推送等消息发送功能。 + +## 功能特性 + +### 已实现功能 +- ✅ 腾讯云短信发送 +- ✅ 阿里云短信发送 +- ✅ **阿里云和腾讯云独立API接口(可分别调用)** +- ✅ 多服务商切换(支持动态配置) +- ✅ 短信发送记录保存到数据库 +- ✅ 验证码短信发送 +- ✅ RESTful API接口 +- ✅ 短信发送记录查询 + +### 计划功能 +- 📋 邮件发送 +- 📋 站内消息 +- 📋 APP推送通知 +- 📋 短信发送统计 + +## 快速开始 + +### 1. 数据库初始化 + +执行数据库初始化脚本创建短信发送记录表: + +```bash +mysql -u root -p your_database < db/init.sql +``` + +或手动执行 `db/init.sql` 中的SQL语句。 + +### 2. 配置短信服务商 + +支持两种短信服务商:**腾讯云** 和 **阿里云**。 + +**重要更新:** 现在支持**同时配置两个服务商**,并通过不同的API接口分别调用,无需切换配置! + +#### 同时配置腾讯云和阿里云 + +在 `application.yml` 中配置: + +```yaml +spring: + datasource: + url: jdbc:mysql://${zlt.datasource.ip}/msg-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai + username: ${zlt.datasource.username} + password: ${zlt.datasource.password} + driver-class-name: com.mysql.cj.jdbc.Driver + +sms: + # 默认服务商(用于通用接口 /sms/send) + provider: TENCENT + + # 腾讯云短信配置 + tencent: + app-id: 1400xxxxxx # 在腾讯云短信控制台获取 + secret-id: AKIDxxxxxxxx # 在腾讯云控制台获取 + secret-key: xxxxxxxx # 在腾讯云控制台获取 + sign-name: 您的签名 # 在腾讯云短信控制台配置 + verify-code-template-id: 1234567 # 腾讯云验证码模板ID + + # 阿里云短信配置 + aliyun: + access-key-id: LTAIxxxxxxxx # 在阿里云控制台获取 + access-key-secret: xxxxxxxx # 在阿里云控制台获取 + sign-name: 您的签名 # 在阿里云短信控制台配置 + verify-code-template-id: SMS_123456789 # 阿里云验证码模板CODE + + # 是否保存短信发送记录到数据库 + save-log: true +``` + +**环境变量配置(推荐):** + +```bash +# 数据库配置 +export zlt.datasource.ip=localhost:3306 +export zlt.datasource.username=root +export zlt.datasource.password=yourpassword + +# 默认服务商 +export SMS_PROVIDER=TENCENT + +# 腾讯云配置 +export SMS_TENCENT_APP_ID=1400xxxxxx +export SMS_TENCENT_SECRET_ID=AKIDxxxxxxxxxxxxxxxx +export SMS_TENCENT_SECRET_KEY=xxxxxxxxxxxxxxxx +export SMS_TENCENT_SIGN_NAME=您的签名 +export SMS_TENCENT_VERIFY_CODE_TEMPLATE_ID=1234567 + +# 阿里云配置 +export SMS_ALIYUN_ACCESS_KEY_ID=LTAIxxxxxxxx +export SMS_ALIYUN_ACCESS_KEY_SECRET=xxxxxxxxxxxxxxxx +export SMS_ALIYUN_SIGN_NAME=您的签名 +export SMS_ALIYUN_VERIFY_CODE_TEMPLATE_ID=SMS_123456789 +``` + +### 3. 获取配置参数 + +#### 腾讯云短信配置参数获取 + +1. 登录 [腾讯云短信控制台](https://console.cloud.tencent.com/smsv2) +2. 创建短信应用,获取 `app-id` +3. 前往 [API密钥管理](https://console.cloud.tencent.com/cam/capi) 获取 `secret-id` 和 `secret-key` +4. 在短信控制台配置短信签名,获取 `sign-name` +5. 创建短信模板,获取 `template-id` + +#### 阿里云短信配置参数获取 + +1. 登录 [阿里云短信控制台](https://dysms.console.aliyun.com/) +2. 前往 [AccessKey管理](https://ram.console.aliyun.com/manage/ak) 创建AccessKey,获取 `access-key-id` 和 `access-key-secret` +3. 在短信控制台申请短信签名,获取 `sign-name` +4. 创建短信模板,获取模板CODE(即 `template-id`,如:SMS_123456789) + +### 4. 启动服务 + +```bash +cd zlt-business/msg-center +mvn spring-boot:run +``` + +## API接口文档 + +服务启动后,访问 Swagger 文档: +``` +http://localhost:8080/doc.html +``` + +### 主要接口 + +#### 1. 发送短信(使用默认服务商) + +**接口地址:** `POST /sms/send` + +**说明:** 使用配置文件中 `sms.provider` 指定的默认服务商发送短信 + +**请求参数:** +```json +{ + "phone": "13800138000", + "templateId": "1234567", + "params": { + "code": "123456", + "time": "5" + } +} +``` + +**响应示例:** +```json +{ + "resp_code": 0, + "resp_msg": "success", + "datas": { + "success": true, + "message": "短信发送成功" + } +} +``` + +#### 2. 发送阿里云短信 + +**接口地址:** `POST /sms/aliyun/send` + +**说明:** 强制使用阿里云发送短信,不受默认配置影响 + +**请求参数:** +```json +{ + "phone": "13800138000", + "templateId": "SMS_123456789", + "params": { + "code": "123456", + "time": "5" + } +} +``` + +**响应示例:** +```json +{ + "resp_code": 0, + "resp_msg": "success", + "datas": { + "success": true, + "message": "阿里云短信发送成功" + } +} +``` + +#### 3. 发送腾讯云短信 + +**接口地址:** `POST /sms/tencent/send` + +**说明:** 强制使用腾讯云发送短信,不受默认配置影响 + +**请求参数:** +```json +{ + "phone": "13800138000", + "templateId": "1234567", + "params": { + "code": "123456", + "time": "5" + } +} +``` + +**响应示例:** +```json +{ + "resp_code": 0, + "resp_msg": "success", + "datas": { + "success": true, + "message": "腾讯云短信发送成功" + } +} +``` + +#### 4. 发送验证码(使用默认服务商) + +**接口地址:** `POST /sms/send-verify-code` + +**请求参数:** +- `phone`: 手机号(必填) +- `code`: 验证码(必填) + +**示例:** +``` +POST /sms/send-verify-code?phone=13800138000&code=123456 +``` + +**响应示例:** +```json +{ + "resp_code": 0, + "resp_msg": "success", + "datas": { + "success": true, + "message": "验证码发送成功" + } +} +``` + +#### 5. 发送阿里云验证码 + +**接口地址:** `POST /sms/aliyun/send-verify-code` + +**说明:** 强制使用阿里云发送验证码,使用阿里云配置的验证码模板 + +**请求参数:** +- `phone`: 手机号(必填) +- `code`: 验证码(必填) + +**示例:** +``` +POST /sms/aliyun/send-verify-code?phone=13800138000&code=123456 +``` + +#### 6. 发送腾讯云验证码 + +**接口地址:** `POST /sms/tencent/send-verify-code` + +**说明:** 强制使用腾讯云发送验证码,使用腾讯云配置的验证码模板 + +**请求参数:** +- `phone`: 手机号(必填) +- `code`: 验证码(必填) + +**示例:** +``` +POST /sms/tencent/send-verify-code?phone=13800138000&code=123456 +``` + +#### 7. 查询短信发送记录 + +**接口地址:** `GET /sms/logs` + +**请求参数:** +- `page`: 当前页(默认1) +- `size`: 每页大小(默认10) +- `phone`: 手机号(可选,模糊查询) +- `status`: 状态(可选,0-失败, 1-成功, 2-发送中) + +**示例:** +``` +GET /sms/logs?page=1&size=10&phone=138&status=1 +``` + +**响应示例:** +```json +{ + "resp_code": 0, + "resp_msg": "success", + "datas": { + "records": [...], + "total": 100, + "size": 10, + "current": 1, + "pages": 10 + } +} +``` + +## 短信模板参数说明 + +### 腾讯云模板示例 + +**模板内容:** +``` +{1}为您的登录验证码,请于{2}分钟内填写。如非本人操作,请忽略本短信。 +``` + +**对应参数:** +```json +{ + "params": { + "code": "123456", // {1} 验证码 + "time": "5" // {2} 有效期(分钟) + } +} +``` + +### 阿里云模板示例 + +**模板内容:** +``` +验证码${code},您正在进行身份验证,打死不告诉别人哦!有效期${time}分钟。 +``` + +**对应参数:** +```json +{ + "params": { + "code": "123456", // ${code} 验证码 + "time": "5" // ${time} 有效期(分钟) + } +} +``` + +**注意事项:** +- 腾讯云使用 `{1}`, `{2}` 这样的占位符,参数按顺序传入 +- 阿里云使用 `${变量名}` 这样的占位符,参数需要使用JSON格式的key-value对 + +## 数据库表结构 + +### sms_send_log - 短信发送记录表 + +| 字段 | 类型 | 说明 | +|------|------|------| +| id | bigint | 主键ID | +| phone | varchar(20) | 手机号 | +| template_id | varchar(50) | 短信模板ID | +| template_params | varchar(500) | 模板参数(JSON格式) | +| content | varchar(500) | 短信内容 | +| status | tinyint | 发送状态: 0-失败, 1-成功, 2-发送中 | +| provider | varchar(20) | 服务商: TENCENT, ALIYUN | +| request_id | varchar(100) | 服务商返回的请求ID | +| response_code | varchar(50) | 服务商返回的状态码 | +| response_message | varchar(200) | 服务商返回的消息 | +| error_message | varchar(500) | 错误信息 | +| tenant_id | varchar(32) | 租户ID | +| create_time | datetime | 创建时间 | +| update_time | datetime | 更新时间 | + +## 项目结构 + +``` +msg-center/ +├── db/ +│ └── init.sql # 数据库初始化脚本 +├── src/ +│ └── main/ +│ ├── java/com/central/ +│ │ ├── MsgCenterApp.java # 启动类 +│ │ └── msg/ +│ │ ├── config/ +│ │ │ └── SmsConfig.java +│ │ ├── controller/ +│ │ │ └── SmsController.java +│ │ ├── mapper/ +│ │ │ └── SmsSendLogMapper.java +│ │ ├── model/ +│ │ │ ├── dto/ +│ │ │ │ ├── SmsRequest.java +│ │ │ │ └── SmsResponse.java +│ │ │ └── entity/ +│ │ │ └── SmsSendLog.java +│ │ └── service/ +│ │ ├── MsgSmsService.java +│ │ └── impl/ +│ │ └── MsgSmsServiceImpl.java +│ └── resources/ +│ ├── application.yml # 配置文件 +│ ├── bootstrap.yml # 服务名称配置 +│ └── mapper/ +│ └── SmsSendLogMapper.xml +├── Dockerfile # Docker镜像构建文件 +├── pom.xml # Maven配置 +└── README.md # 本文档 +``` + +## 常见问题 + +### 1. 短信发送失败 + +**可能原因:** +- 配置参数错误(检查各项配置是否正确) +- 签名未审核通过 +- 模板未审核通过 +- 账户余额不足 +- 手机号格式错误 +- 发送频率过高(部分运营商有限制) + +**解决方法:** +- 查看日志中的详细错误信息 +- 登录服务商控制台检查签名和模板审核状态 +- 确认账户余额充足 +- 检查手机号格式是否正确 +- 调整发送频率 + +### 2. 数据库连接失败 + +确保在 `application.yml` 或 Nacos 配置中心配置了正确的数据库连接信息。 + +### 3. 如何在运行时切换短信服务商 + +**新版本:无需切换!** + +现在你可以**同时使用阿里云和腾讯云**,只需调用不同的API接口即可: + +- **阿里云短信:** `POST /sms/aliyun/send` 或 `POST /sms/aliyun/send-verify-code` +- **腾讯云短信:** `POST /sms/tencent/send` 或 `POST /sms/tencent/send-verify-code` +- **默认服务商:** `POST /sms/send` 或 `POST /sms/send-verify-code`(使用配置文件中的 `sms.provider`) + +**使用场景示例:** + +```bash +# 某个服务需要使用阿里云发送营销短信 +curl -X POST http://localhost:8080/sms/aliyun/send \ + -H "Content-Type: application/json" \ + -d '{ + "phone": "13800138000", + "templateId": "SMS_123456789", + "params": {"code": "123456", "time": "5"} + }' + +# 另一个服务需要使用腾讯云发送验证码 +curl -X POST http://localhost:8080/sms/tencent/send-verify-code \ + -d "phone=13900139000&code=654321" +``` + +**旧方法(仍然支持):** + +如果你只想使用一个服务商,可以通过修改配置切换: + +**方法一:修改配置文件** +```yaml +sms: + provider: ALIYUN # 将 TENCENT 改为 ALIYUN +``` + +**方法二:使用环境变量(推荐)** +```bash +export SMS_PROVIDER=ALIYUN +``` + +重启服务后生效。 + +### 4. 腾讯云和阿里云的区别 + +| 特性 | 腾讯云 | 阿里云 | +|------|--------|--------| +| 模板格式 | {1}, {2}, {3}... | ${变量名} | +| 参数格式 | 数组形式,按顺序 | JSON键值对 | +| 手机号格式 | 需要+86前缀 | 直接手机号 | +| SDK包名 | tencentcloud-sdk-java | aliyun-java-sdk-dysmsapi | + +### 5. 如何同时配置两个服务商并分别调用 + +**现在已经默认支持!** 无需任何特殊配置。 + +只需在配置文件中同时配置腾讯云和阿里云的参数: + +```yaml +sms: + provider: TENCENT # 默认服务商(用于 /sms/send 接口) + + tencent: + app-id: xxx + secret-id: xxx + secret-key: xxx + sign-name: xxx + verify-code-template-id: xxx + + aliyun: + access-key-id: xxx + access-key-secret: xxx + sign-name: xxx + verify-code-template-id: xxx +``` + +**然后直接调用对应的API接口:** + +```bash +# 使用阿里云发送 +POST /sms/aliyun/send + +# 使用腾讯云发送 +POST /sms/tencent/send + +# 使用默认服务商(TENCENT)发送 +POST /sms/send +``` + +**优势:** +- ✅ 不同服务可以选择不同的短信服务商 +- ✅ 无需重启服务即可使用不同的服务商 +- ✅ 可以根据成本、到达率等因素灵活选择 +- ✅ 支持灾备切换(一个服务商故障时使用另一个) + +**实际应用场景:** + +```java +// 服务A:使用阿里云发送营销短信 +POST /sms/aliyun/send + +// 服务B:使用腾讯云发送验证码 +POST /sms/tencent/send-verify-code + +// 服务C:使用默认配置发送通知短信 +POST /sms/send +``` + +## 开发计划 + +- [ ] 添加短信发送频率限制(防刷) +- [ ] 添加短信发送统计报表 +- [ ] 支持批量发送短信 +- [ ] 添加短信发送队列(异步发送) +- [ ] 支持更多短信服务商(华为云、七牛云等) +- [ ] 添加邮件发送功能 +- [ ] 添加消息模板管理 +- [ ] 添加短信发送失败重试机制 + +## 技术栈 + +- Spring Boot 3.1.6 +- Spring Cloud +- MyBatis Plus 3.5.4 +- 腾讯云短信 SDK 3.1.1040 +- 阿里云短信 SDK 2.1.0 +- MySQL 8.0 +- Redis 7.0 +- Nacos (服务注册与配置中心) + +## 联系方式 + +如有问题,请提交 Issue 或联系开发团队。 diff --git a/zlt-business/msg-center/db/init.sql b/zlt-business/msg-center/db/init.sql new file mode 100644 index 00000000..671da74d --- /dev/null +++ b/zlt-business/msg-center/db/init.sql @@ -0,0 +1,26 @@ +-- ============================================= +-- 消息中心 - 短信发送记录表 +-- ============================================= + +CREATE TABLE IF NOT EXISTS `sms_send_log` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `phone` varchar(20) NOT NULL COMMENT '手机号', + `template_id` varchar(50) NOT NULL COMMENT '短信模板ID', + `template_params` varchar(500) DEFAULT NULL COMMENT '模板参数(JSON格式)', + `content` varchar(500) DEFAULT NULL COMMENT '短信内容', + `status` tinyint(4) NOT NULL DEFAULT '2' COMMENT '发送状态: 0-失败, 1-成功, 2-发送中', + `provider` varchar(20) NOT NULL DEFAULT 'TENCENT' COMMENT '服务商: TENCENT, ALIYUN', + `request_id` varchar(100) DEFAULT NULL COMMENT '服务商返回的请求ID', + `response_code` varchar(50) DEFAULT NULL COMMENT '服务商返回的状态码', + `response_message` varchar(200) DEFAULT NULL COMMENT '服务商返回的消息', + `error_message` varchar(500) DEFAULT NULL COMMENT '错误信息', + `tenant_id` varchar(32) DEFAULT NULL COMMENT '租户ID', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + PRIMARY KEY (`id`), + KEY `idx_phone` (`phone`), + KEY `idx_template_id` (`template_id`), + KEY `idx_create_time` (`create_time`), + KEY `idx_status` (`status`), + KEY `idx_tenant_id` (`tenant_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='短信发送记录表'; diff --git a/zlt-business/msg-center/pom.xml b/zlt-business/msg-center/pom.xml new file mode 100644 index 00000000..c867b265 --- /dev/null +++ b/zlt-business/msg-center/pom.xml @@ -0,0 +1,130 @@ + + + 4.0.0 + + com.zlt + zlt-business + 6.0.0 + + msg-center + 消息中心 + + + + com.zlt + zlt-config + + + com.zlt + zlt-log-spring-boot-starter + + + com.zlt + zlt-common-spring-boot-starter + + + com.zlt + zlt-db-spring-boot-starter + + + com.zlt + zlt-redis-spring-boot-starter + + + com.zlt + zlt-loadbalancer-spring-boot-starter + + + com.zlt + zlt-sentinel-spring-boot-starter + + + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-web + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + org.springframework.boot + spring-boot-starter-actuator + + + + mysql + mysql-connector-java + + + + io.micrometer + micrometer-registry-prometheus + + + junit + junit + test + + + org.hibernate + hibernate-validator + + + + + com.zlt + zlt-sms-spring-boot-starter + ${project.version} + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + com.spotify + docker-maven-plugin + + ${docker.image.prefix}/${project.artifactId} + + ${project.version} + latest + + true + ${docker.baseImage} + ${docker.volumes} + + ${docker.java.opts} + + ["sh","-c","java $JAVA_OPTS ${docker.java.security.egd} -jar /${project.build.finalName}.jar"] + + + / + ${project.build.directory} + ${project.build.finalName}.jar + + + + + + ${project.artifactId} + + diff --git a/zlt-business/msg-center/src/main/java/com/central/MsgCenterApp.java b/zlt-business/msg-center/src/main/java/com/central/MsgCenterApp.java new file mode 100644 index 00000000..914f9727 --- /dev/null +++ b/zlt-business/msg-center/src/main/java/com/central/MsgCenterApp.java @@ -0,0 +1,21 @@ +package com.central; + +import com.central.common.lb.annotation.EnableFeignInterceptor; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +/** + * 消息中心启动类 + * @author system + */ +@EnableDiscoveryClient +@EnableTransactionManagement +@EnableFeignInterceptor +@SpringBootApplication +public class MsgCenterApp { + public static void main(String[] args) { + SpringApplication.run(MsgCenterApp.class, args); + } +} diff --git a/zlt-business/msg-center/src/main/java/com/central/msg/config/SmsConfig.java b/zlt-business/msg-center/src/main/java/com/central/msg/config/SmsConfig.java new file mode 100644 index 00000000..d3d3ce7d --- /dev/null +++ b/zlt-business/msg-center/src/main/java/com/central/msg/config/SmsConfig.java @@ -0,0 +1,14 @@ +package com.central.msg.config; + +import com.central.sms.config.SmsProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * 短信配置类 + * @author system + */ +@Configuration +@EnableConfigurationProperties(SmsProperties.class) +public class SmsConfig { +} diff --git a/zlt-business/msg-center/src/main/java/com/central/msg/controller/SmsController.java b/zlt-business/msg-center/src/main/java/com/central/msg/controller/SmsController.java new file mode 100644 index 00000000..ef83bb1f --- /dev/null +++ b/zlt-business/msg-center/src/main/java/com/central/msg/controller/SmsController.java @@ -0,0 +1,220 @@ +package com.central.msg.controller; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.central.common.model.Result; +import com.central.msg.model.dto.SmsRequest; +import com.central.msg.model.dto.SmsResponse; +import com.central.msg.model.entity.SmsSendLog; +import com.central.msg.service.MsgSmsService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * 短信发送Controller + * @author system + */ +@RestController +@RequestMapping("/sms") +@Tag(name = "短信服务", description = "短信发送相关接口") +public class SmsController { + + private static final Logger logger = LoggerFactory.getLogger(SmsController.class); + + @Autowired + private MsgSmsService msgSmsService; + + /** + * 发送短信(使用默认服务商) + */ + @PostMapping("/send") + @Operation(summary = "发送短信", description = "使用默认服务商发送模板短信") + public Result sendSms(@Valid @RequestBody SmsRequest request) { + logger.info("收到短信发送请求: {}", request); + + try { + boolean success = msgSmsService.sendSms( + request.getPhone(), + request.getTemplateId(), + request.getParams() + ); + + if (success) { + SmsResponse response = new SmsResponse(true, "短信发送成功"); + return Result.succeed(response); + } else { + SmsResponse response = new SmsResponse(false, "短信发送失败"); + return Result.failed(response,"短信发送失败!"); + } + } catch (Exception e) { + logger.error("短信发送异常: {}", e.getMessage(), e); + SmsResponse response = new SmsResponse(false, "短信发送异常: " + e.getMessage()); + return Result.failed(response,"短信发送失败!"); + } + } + + /** + * 发送阿里云短信 + */ + @PostMapping("/aliyun/send") + @Operation(summary = "发送阿里云短信", description = "使用阿里云发送模板短信") + public Result sendAliyunSms(@Valid @RequestBody SmsRequest request) { + logger.info("收到阿里云短信发送请求: {}", request); + + try { + boolean success = msgSmsService.sendAliyunSms( + request.getPhone(), + request.getTemplateId(), + request.getParams() + ); + + if (success) { + SmsResponse response = new SmsResponse(true, "阿里云短信发送成功"); + return Result.succeed(response); + } else { + SmsResponse response = new SmsResponse(false, "阿里云短信发送失败"); + return Result.failed(response,"短信发送失败!"); + } + } catch (Exception e) { + logger.error("阿里云短信发送异常: {}", e.getMessage(), e); + SmsResponse response = new SmsResponse(false, "阿里云短信发送异常: " + e.getMessage()); + return Result.failed(response,"短信发送失败!"); + } + } + + /** + * 发送腾讯云短信 + */ + @PostMapping("/tencent/send") + @Operation(summary = "发送腾讯云短信", description = "使用腾讯云发送模板短信") + public Result sendTencentSms(@Valid @RequestBody SmsRequest request) { + logger.info("收到腾讯云短信发送请求: {}", request); + + try { + boolean success = msgSmsService.sendTencentSms( + request.getPhone(), + request.getTemplateId(), + request.getParams() + ); + + if (success) { + SmsResponse response = new SmsResponse(true, "腾讯云短信发送成功"); + return Result.succeed(response); + } else { + SmsResponse response = new SmsResponse(false, "腾讯云短信发送失败"); + return Result.failed(response,"短信发送失败!"); + } + } catch (Exception e) { + logger.error("腾讯云短信发送异常: {}", e.getMessage(), e); + SmsResponse response = new SmsResponse(false, "腾讯云短信发送异常: " + e.getMessage()); + return Result.failed(response,"短信发送失败!"); + } + } + + /** + * 发送验证码(使用默认服务商) + */ + @PostMapping("/send-verify-code") + @Operation(summary = "发送验证码", description = "使用默认服务商发送验证码短信") + public Result sendVerifyCode( + @Parameter(description = "手机号", required = true) @RequestParam("phone") String phone, + @Parameter(description = "验证码", required = true) @RequestParam("code") String code) { + logger.info("收到验证码发送请求: phone={}, code={}", phone, code); + + try { + boolean success = msgSmsService.sendVerifyCode(phone, code); + + if (success) { + SmsResponse response = new SmsResponse(true, "验证码发送成功"); + return Result.succeed(response); + } else { + SmsResponse response = new SmsResponse(false, "验证码发送失败"); + return Result.failed(response,"短信发送失败!"); + } + } catch (Exception e) { + logger.error("验证码发送异常: {}", e.getMessage(), e); + SmsResponse response = new SmsResponse(false, "验证码发送异常: " + e.getMessage()); + return Result.failed(response,"短信发送失败!"); + } + } + + /** + * 发送阿里云验证码 + */ + @PostMapping("/aliyun/send-verify-code") + @Operation(summary = "发送阿里云验证码", description = "使用阿里云发送验证码短信") + public Result sendAliyunVerifyCode( + @Parameter(description = "手机号", required = true) @RequestParam("phone") String phone, + @Parameter(description = "验证码", required = true) @RequestParam("code") String code) { + logger.info("收到阿里云验证码发送请求: phone={}, code={}", phone, code); + + try { + boolean success = msgSmsService.sendAliyunVerifyCode(phone, code); + + if (success) { + SmsResponse response = new SmsResponse(true, "阿里云验证码发送成功"); + return Result.succeed(response); + } else { + SmsResponse response = new SmsResponse(false, "阿里云验证码发送失败"); + return Result.failed(response,"短信发送失败!"); + } + } catch (Exception e) { + logger.error("阿里云验证码发送异常: {}", e.getMessage(), e); + SmsResponse response = new SmsResponse(false, "阿里云验证码发送异常: " + e.getMessage()); + return Result.failed(response,"短信发送失败!"); + } + } + + /** + * 发送腾讯云验证码 + */ + @PostMapping("/tencent/send-verify-code") + @Operation(summary = "发送腾讯云验证码", description = "使用腾讯云发送验证码短信") + public Result sendTencentVerifyCode( + @Parameter(description = "手机号", required = true) @RequestParam("phone") String phone, + @Parameter(description = "验证码", required = true) @RequestParam("code") String code) { + logger.info("收到腾讯云验证码发送请求: phone={}, code={}", phone, code); + + try { + boolean success = msgSmsService.sendTencentVerifyCode(phone, code); + + if (success) { + SmsResponse response = new SmsResponse(true, "腾讯云验证码发送成功"); + return Result.succeed(response); + } else { + SmsResponse response = new SmsResponse(false, "腾讯云验证码发送失败"); + return Result.failed(response,"短信发送失败!"); + } + } catch (Exception e) { + logger.error("腾讯云验证码发送异常: {}", e.getMessage(), e); + SmsResponse response = new SmsResponse(false, "腾讯云验证码发送异常: " + e.getMessage()); + return Result.failed(response,"短信发送失败!"); + } + } + + /** + * 查询短信发送记录 + */ + @GetMapping("/logs") + @Operation(summary = "查询短信发送记录", description = "分页查询短信发送记录") + public Result> querySmsSendLog( + @Parameter(description = "当前页", required = true) @RequestParam(value = "page", defaultValue = "1") int page, + @Parameter(description = "每页大小", required = true) @RequestParam(value = "size", defaultValue = "10") int size, + @Parameter(description = "手机号") @RequestParam(value = "phone", required = false) String phone, + @Parameter(description = "状态: 0-失败, 1-成功, 2-发送中") @RequestParam(value = "status", required = false) Integer status) { + logger.info("查询短信发送记录: page={}, size={}, phone={}, status={}", page, size, phone, status); + + try { + Page result = msgSmsService.querySmsSendLog(page, size, phone, status); + return Result.succeed(result); + } catch (Exception e) { + logger.error("查询短信发送记录异常: {}", e.getMessage(), e); + return Result.failed("查询失败: " + e.getMessage()); + } + } +} diff --git a/zlt-business/msg-center/src/main/java/com/central/msg/mapper/SmsSendLogMapper.java b/zlt-business/msg-center/src/main/java/com/central/msg/mapper/SmsSendLogMapper.java new file mode 100644 index 00000000..a8c66066 --- /dev/null +++ b/zlt-business/msg-center/src/main/java/com/central/msg/mapper/SmsSendLogMapper.java @@ -0,0 +1,13 @@ +package com.central.msg.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.central.msg.model.entity.SmsSendLog; +import org.apache.ibatis.annotations.Mapper; + +/** + * 短信发送记录Mapper + * @author system + */ +@Mapper +public interface SmsSendLogMapper extends BaseMapper { +} diff --git a/zlt-business/msg-center/src/main/java/com/central/msg/model/dto/SmsRequest.java b/zlt-business/msg-center/src/main/java/com/central/msg/model/dto/SmsRequest.java new file mode 100644 index 00000000..4e718d5a --- /dev/null +++ b/zlt-business/msg-center/src/main/java/com/central/msg/model/dto/SmsRequest.java @@ -0,0 +1,60 @@ +package com.central.msg.model.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; + +import java.util.Map; + +/** + * 短信发送请求DTO + * @author system + */ +@Schema(description = "短信发送请求") +public class SmsRequest { + + @Schema(description = "手机号", required = true, example = "13800138000") + @NotBlank(message = "手机号不能为空") + @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确") + private String phone; + + @Schema(description = "短信模板ID", required = true, example = "123456") + @NotBlank(message = "模板ID不能为空") + private String templateId; + + @Schema(description = "模板参数", example = "{\"code\":\"1234\",\"time\":\"5\"}") + private Map params; + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getTemplateId() { + return templateId; + } + + public void setTemplateId(String templateId) { + this.templateId = templateId; + } + + public Map getParams() { + return params; + } + + public void setParams(Map params) { + this.params = params; + } + + @Override + public String toString() { + return "SmsRequest{" + + "phone='" + phone + '\'' + + ", templateId='" + templateId + '\'' + + ", params=" + params + + '}'; + } +} diff --git a/zlt-business/msg-center/src/main/java/com/central/msg/model/dto/SmsResponse.java b/zlt-business/msg-center/src/main/java/com/central/msg/model/dto/SmsResponse.java new file mode 100644 index 00000000..41334107 --- /dev/null +++ b/zlt-business/msg-center/src/main/java/com/central/msg/model/dto/SmsResponse.java @@ -0,0 +1,67 @@ +package com.central.msg.model.dto; + +import io.swagger.v3.oas.annotations.media.Schema; + +/** + * 短信发送响应DTO + * @author system + */ +@Schema(description = "短信发送响应") +public class SmsResponse { + + @Schema(description = "是否成功") + private boolean success; + + @Schema(description = "消息") + private String message; + + @Schema(description = "请求ID") + private String requestId; + + public SmsResponse() { + } + + public SmsResponse(boolean success, String message) { + this.success = success; + this.message = message; + } + + public SmsResponse(boolean success, String message, String requestId) { + this.success = success; + this.message = message; + this.requestId = requestId; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + @Override + public String toString() { + return "SmsResponse{" + + "success=" + success + + ", message='" + message + '\'' + + ", requestId='" + requestId + '\'' + + '}'; + } +} diff --git a/zlt-business/msg-center/src/main/java/com/central/msg/model/entity/SmsSendLog.java b/zlt-business/msg-center/src/main/java/com/central/msg/model/entity/SmsSendLog.java new file mode 100644 index 00000000..1a646178 --- /dev/null +++ b/zlt-business/msg-center/src/main/java/com/central/msg/model/entity/SmsSendLog.java @@ -0,0 +1,91 @@ +package com.central.msg.model.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 短信发送记录实体 + * @author system + */ +@Data +@TableName("sms_send_log") +public class SmsSendLog implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 手机号 + */ + private String phone; + + /** + * 短信模板ID + */ + private String templateId; + + /** + * 模板参数(JSON格式) + */ + private String templateParams; + + /** + * 短信内容 + */ + private String content; + + /** + * 发送状态: 0-失败, 1-成功, 2-发送中 + */ + private Integer status; + + /** + * 服务商: TENCENT, ALIYUN + */ + private String provider; + + /** + * 服务商返回的请求ID + */ + private String requestId; + + /** + * 服务商返回的状态码 + */ + private String responseCode; + + /** + * 服务商返回的消息 + */ + private String responseMessage; + + /** + * 错误信息 + */ + private String errorMessage; + + /** + * 租户ID + */ + private String tenantId; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date updateTime; +} diff --git a/zlt-business/msg-center/src/main/java/com/central/msg/service/MsgSmsService.java b/zlt-business/msg-center/src/main/java/com/central/msg/service/MsgSmsService.java new file mode 100644 index 00000000..a9ca8cf7 --- /dev/null +++ b/zlt-business/msg-center/src/main/java/com/central/msg/service/MsgSmsService.java @@ -0,0 +1,94 @@ +package com.central.msg.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.central.msg.model.entity.SmsSendLog; +import com.central.sms.enums.SmsProviderType; + +import java.util.Map; + +/** + * 消息中心短信服务接口 + * @author system + */ +public interface MsgSmsService { + + /** + * 发送短信(使用默认服务商) + * @param phone 手机号 + * @param templateId 模板ID + * @param params 模板参数 + * @return 是否发送成功 + */ + boolean sendSms(String phone, String templateId, Map params); + + /** + * 发送短信(指定服务商) + * @param phone 手机号 + * @param templateId 模板ID + * @param params 模板参数 + * @param provider 服务商类型 + * @return 是否发送成功 + */ + boolean sendSms(String phone, String templateId, Map params, SmsProviderType provider); + + /** + * 发送阿里云短信 + * @param phone 手机号 + * @param templateId 模板ID + * @param params 模板参数 + * @return 是否发送成功 + */ + boolean sendAliyunSms(String phone, String templateId, Map params); + + /** + * 发送腾讯云短信 + * @param phone 手机号 + * @param templateId 模板ID + * @param params 模板参数 + * @return 是否发送成功 + */ + boolean sendTencentSms(String phone, String templateId, Map params); + + /** + * 发送验证码短信(使用默认服务商) + * @param phone 手机号 + * @param code 验证码 + * @return 是否发送成功 + */ + boolean sendVerifyCode(String phone, String code); + + /** + * 发送验证码短信(指定服务商) + * @param phone 手机号 + * @param code 验证码 + * @param provider 服务商类型 + * @return 是否发送成功 + */ + boolean sendVerifyCode(String phone, String code, SmsProviderType provider); + + /** + * 发送阿里云验证码 + * @param phone 手机号 + * @param code 验证码 + * @return 是否发送成功 + */ + boolean sendAliyunVerifyCode(String phone, String code); + + /** + * 发送腾讯云验证码 + * @param phone 手机号 + * @param code 验证码 + * @return 是否发送成功 + */ + boolean sendTencentVerifyCode(String phone, String code); + + /** + * 分页查询短信发送记录 + * @param page 当前页 + * @param size 每页大小 + * @param phone 手机号(可选) + * @param status 状态(可选) + * @return 分页数据 + */ + Page querySmsSendLog(int page, int size, String phone, Integer status); +} diff --git a/zlt-business/msg-center/src/main/java/com/central/msg/service/impl/MsgSmsServiceImpl.java b/zlt-business/msg-center/src/main/java/com/central/msg/service/impl/MsgSmsServiceImpl.java new file mode 100644 index 00000000..054f7d2d --- /dev/null +++ b/zlt-business/msg-center/src/main/java/com/central/msg/service/impl/MsgSmsServiceImpl.java @@ -0,0 +1,205 @@ +package com.central.msg.service.impl; + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.central.msg.mapper.SmsSendLogMapper; +import com.central.msg.model.entity.SmsSendLog; +import com.central.msg.service.MsgSmsService; +import com.central.sms.config.SmsProperties; +import com.central.sms.enums.SmsProviderType; +import com.central.sms.service.ISmsService; +import com.central.sms.service.impl.AliyunSmsService; +import com.central.sms.service.impl.TencentSmsService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 消息中心短信服务实现类 + * @author system + */ +@Service +public class MsgSmsServiceImpl implements MsgSmsService { + + private static final Logger logger = LoggerFactory.getLogger(MsgSmsServiceImpl.class); + + @Autowired + private AliyunSmsService aliyunSmsService; + + @Autowired + private TencentSmsService tencentSmsService; + + @Autowired + private SmsSendLogMapper smsSendLogMapper; + + @Autowired + private SmsProperties smsProperties; + + @Value("${sms.save-log:true}") + private boolean saveLog; + + @Override + public boolean sendSms(String phone, String templateId, Map params) { + return sendSms(phone, templateId, params, smsProperties.getProvider()); + } + + @Override + public boolean sendSms(String phone, String templateId, Map params, SmsProviderType provider) { + SmsSendLog log = new SmsSendLog(); + log.setPhone(phone); + log.setTemplateId(templateId); + log.setTemplateParams(params != null ? JSON.toJSONString(params) : null); + log.setProvider(provider.name()); + log.setCreateTime(new Date()); + log.setUpdateTime(new Date()); + + try { + logger.info("开始发送短信: phone={}, templateId={}, params={}, provider={}", + phone, templateId, params, provider); + log.setStatus(2); // 发送中 + + ISmsService smsService = getSmsService(provider); + boolean result = smsService.sendSms(phone, templateId, params); + + if (result) { + logger.info("短信发送成功: phone={}, templateId={}, provider={}", phone, templateId, provider); + log.setStatus(1); // 成功 + log.setResponseCode("Ok"); + log.setResponseMessage("发送成功"); + } else { + logger.warn("短信发送失败: phone={}, templateId={}, provider={}", phone, templateId, provider); + log.setStatus(0); // 失败 + log.setResponseCode("Failed"); + log.setResponseMessage("发送失败"); + } + + // 保存发送记录 + if (saveLog) { + saveSendLog(log); + } + + return result; + } catch (Exception e) { + logger.error("短信发送异常: phone={}, templateId={}, provider={}, error={}", + phone, templateId, provider, e.getMessage(), e); + log.setStatus(0); // 失败 + log.setErrorMessage(e.getMessage()); + log.setResponseMessage("发送异常: " + e.getMessage()); + + // 保存发送记录 + if (saveLog) { + saveSendLog(log); + } + + return false; + } + } + + @Override + public boolean sendAliyunSms(String phone, String templateId, Map params) { + return sendSms(phone, templateId, params, SmsProviderType.ALIYUN); + } + + @Override + public boolean sendTencentSms(String phone, String templateId, Map params) { + return sendSms(phone, templateId, params, SmsProviderType.TENCENT); + } + + @Override + public boolean sendVerifyCode(String phone, String code) { + return sendVerifyCode(phone, code, smsProperties.getProvider()); + } + + @Override + public boolean sendVerifyCode(String phone, String code, SmsProviderType provider) { + String templateId = getVerifyCodeTemplateId(provider); + if (templateId == null || templateId.isEmpty()) { + logger.error("{}验证码模板ID未配置,无法发送验证码短信", provider.name()); + return false; + } + + Map params = new HashMap<>(); + params.put("code", code); + params.put("time", "5"); // 默认5分钟有效期 + + return sendSms(phone, templateId, params, provider); + } + + @Override + public boolean sendAliyunVerifyCode(String phone, String code) { + return sendVerifyCode(phone, code, SmsProviderType.ALIYUN); + } + + @Override + public boolean sendTencentVerifyCode(String phone, String code) { + return sendVerifyCode(phone, code, SmsProviderType.TENCENT); + } + + @Override + public Page querySmsSendLog(int page, int size, String phone, Integer status) { + Page pageParam = new Page<>(page, size); + + com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper wrapper = + new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>(); + + // 手机号模糊查询 + if (phone != null && !phone.isEmpty()) { + wrapper.like(SmsSendLog::getPhone, phone); + } + + // 状态查询 + if (status != null) { + wrapper.eq(SmsSendLog::getStatus, status); + } + + // 按创建时间倒序 + wrapper.orderByDesc(SmsSendLog::getCreateTime); + + return smsSendLogMapper.selectPage(pageParam, wrapper); + } + + /** + * 根据服务商类型获取短信服务实例 + */ + private ISmsService getSmsService(SmsProviderType provider) { + switch (provider) { + case ALIYUN: + return aliyunSmsService; + case TENCENT: + default: + return tencentSmsService; + } + } + + /** + * 获取验证码模板ID + */ + private String getVerifyCodeTemplateId(SmsProviderType provider) { + switch (provider) { + case ALIYUN: + return smsProperties.getAliyun().getVerifyCodeTemplateId(); + case TENCENT: + return smsProperties.getTencent().getVerifyCodeTemplateId(); + default: + return null; + } + } + + /** + * 保存短信发送记录 + */ + private void saveSendLog(SmsSendLog log) { + try { + smsSendLogMapper.insert(log); + } catch (Exception e) { + logger.error("保存短信发送记录失败: {}", e.getMessage(), e); + } + } +} diff --git a/zlt-business/msg-center/src/main/resources/application.yml b/zlt-business/msg-center/src/main/resources/application.yml new file mode 100644 index 00000000..6d9445ea --- /dev/null +++ b/zlt-business/msg-center/src/main/resources/application.yml @@ -0,0 +1,65 @@ + 已配置在nacos中,此配置文件作废 +# 消息中心配置文件 +#spring: +# datasource: +# url: jdbc:mysql://${zlt.datasource.ip}/msg-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai +# username: ${zlt.datasource.username} +# password: ${zlt.datasource.password} +# driver-class-name: com.mysql.cj.jdbc.Driver +# +#mybatis-plus: +# mapper-locations: classpath:/mapper/*Mapper.xml +# type-aliases-package: com.central.msg.model.entity +# global-config: +# db-config: +# id-type: auto +# +#springdoc: +# group-configs: +# - group: 'default' +# paths-to-match: '/**' +# packages-to-scan: com.central.msg.controller +# +#knife4j: +# enable: true +# setting: +# swagger-model-name: 消息中心接口文档 +# +## 短信服务配置 +#sms: +# # 短信服务提供商: TENCENT(腾讯云) 或 ALIYUN(阿里云) +# # 默认提供商,用于未指定提供商的接口 +# provider: ${SMS_PROVIDER :TENCENT} +# +# # 腾讯云短信配置 +# tencent: +# # 腾讯云短信应用ID (在腾讯云短信控制台获取) +# app-id: 1401077992 +# # 腾讯云SecretId (在腾讯云控制台获取) +# secret-id: AKIDuiNrAF7mETXO5au1vgFbjfOuCIG3cx62 +# # 腾讯云SecretKey (在腾讯云控制台获取) +# secret-key: nMkvsb6OSJwQjphLlxxmQsAGF6kBGF3d +# # 短信签名 (在腾讯云短信控制台配置) +# sign-name: 北京高飞智航科技 +# # 验证码模板ID +# verify-code-template-id: 2589777 +# +# # 阿里云短信配置 +# aliyun: +# # 阿里云AccessKeyId (在阿里云控制台获取) +# access-key-id: LTAI5tS3aRqJ4Et55s1g3Bkw +# # 阿里云AccessKeySecret (在阿里云控制台获取) +# access-key-secret: 0A7SumjhpzRmHEhK5aOkcysLu3zAcq +# # 短信签名 (在阿里云短信控制台配置) +# sign-name: 阿里云短信测试 +# # 验证码模板ID +# verify-code-template-id: SMS_154950909 +# +# # 是否保存短信发送记录到数据库 +# save-log: ${SMS_SAVE_LOG:true} +# +## 多租户配置 +#zlt: +# tenant: +# enable: true + diff --git a/zlt-business/msg-center/src/main/resources/bootstrap.yml b/zlt-business/msg-center/src/main/resources/bootstrap.yml new file mode 100644 index 00000000..dfbca1a7 --- /dev/null +++ b/zlt-business/msg-center/src/main/resources/bootstrap.yml @@ -0,0 +1,3 @@ +spring: + application: + name: msg-center diff --git a/zlt-business/msg-center/src/main/resources/mapper/SmsSendLogMapper.xml b/zlt-business/msg-center/src/main/resources/mapper/SmsSendLogMapper.xml new file mode 100644 index 00000000..4e1bb2a5 --- /dev/null +++ b/zlt-business/msg-center/src/main/resources/mapper/SmsSendLogMapper.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/zlt-business/pom.xml b/zlt-business/pom.xml index 06ea010c..346ad4fb 100644 --- a/zlt-business/pom.xml +++ b/zlt-business/pom.xml @@ -22,5 +22,7 @@ order-center coupon-center + + msg-center diff --git a/zlt-business/user-center/src/main/java/com/central/user/controller/SysUserController.java b/zlt-business/user-center/src/main/java/com/central/user/controller/SysUserController.java index 0d4f8a41..9c3ea295 100644 --- a/zlt-business/user-center/src/main/java/com/central/user/controller/SysUserController.java +++ b/zlt-business/user-center/src/main/java/com/central/user/controller/SysUserController.java @@ -120,6 +120,18 @@ public class SysUserController { return appUserService.findByOpenId(openId); } + /** + * 通过手机号注册用户 + * + * @param mobile 手机号 + * @return 注册后的用户信息(包含openId) + */ + @PostMapping(value = "/users-anon/register/mobile") + @Operation(summary = "通过手机号注册用户") + public SysUser registerByMobile(@RequestParam("mobile") String mobile) throws Exception { + return appUserService.registerByMobile(mobile); + } + /** * 根据WxOpenId查询用户信息 * diff --git a/zlt-business/user-center/src/main/java/com/central/user/service/ISysUserService.java b/zlt-business/user-center/src/main/java/com/central/user/service/ISysUserService.java index 0540606f..d3800bea 100644 --- a/zlt-business/user-center/src/main/java/com/central/user/service/ISysUserService.java +++ b/zlt-business/user-center/src/main/java/com/central/user/service/ISysUserService.java @@ -116,4 +116,12 @@ public interface ISysUserService extends ISuperService { * @return 删除结果 */ boolean completelyDeleteUser(Long userId); + + /** + * 通过手机号注册用户 + * @param mobile 手机号 + * @return 注册后的用户信息(包含openId) + * @throws Exception 注册异常 + */ + SysUser registerByMobile(String mobile) throws Exception; } diff --git a/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysUserServiceImpl.java b/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysUserServiceImpl.java index 2cff3106..72687f37 100644 --- a/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysUserServiceImpl.java +++ b/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysUserServiceImpl.java @@ -449,4 +449,41 @@ public class SysUserServiceImpl extends SuperServiceImpl } return sysUserExcels; } + + @Override + @Transactional(rollbackFor = Exception.class) + public SysUser registerByMobile(String mobile) throws Exception { + // 先检查手机号是否已注册 + SysUser existUser = this.selectByMobile(mobile); + if (existUser != null) { + // 已存在,直接返回 + return existUser; + } + + // 生成openId(使用UUID) + String openId = java.util.UUID.randomUUID().toString().replace("-", ""); + + // 创建新用户 + SysUser sysUser = new SysUser(); + sysUser.setMobile(mobile); + sysUser.setUsername(mobile); // 使用手机号作为用户名 + sysUser.setOpenId(openId); + sysUser.setType(UserType.APP.name()); + sysUser.setPassword(passwordEncoder.encode(openId)); // 使用openId作为初始密码 + sysUser.setEnabled(Boolean.TRUE); + + String username = sysUser.getUsername(); + boolean result = super.saveOrUpdateIdempotency(sysUser, lock, + LOCK_KEY_USERNAME + username, + new QueryWrapper().eq("username", username), + username + "已存在"); + + if (result) { + log.info("通过手机号注册用户成功,mobile:{}, openId:{}", mobile, openId); + return sysUser; + } else { + log.error("通过手机号注册用户失败,mobile:{}", mobile); + return null; + } + } } diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/ServiceNameConstants.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/ServiceNameConstants.java index 4ce7a657..81acfbb4 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/ServiceNameConstants.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/ServiceNameConstants.java @@ -24,4 +24,9 @@ public interface ServiceNameConstants { String FILE_SERVICE = "file-center"; String ORDER_SERVICE = "order-center"; + + /** + * 消息中心服务 + */ + String MSG_SERVICE = "msg-center"; } diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/MsgCenterService.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/MsgCenterService.java new file mode 100644 index 00000000..6cd02d04 --- /dev/null +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/MsgCenterService.java @@ -0,0 +1,45 @@ +package com.central.common.feign; + +import com.central.common.constant.ServiceNameConstants; +import com.central.common.feign.fallback.MsgCenterServiceFallbackFactory; +import com.central.common.model.Result; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * 消息中心服务 Feign客户端 + */ +@FeignClient(name = ServiceNameConstants.MSG_SERVICE, fallbackFactory = MsgCenterServiceFallbackFactory.class, dismiss404 = true) +public interface MsgCenterService { + + /** + * 发送验证码短信(使用默认服务商) + * + * @param phone 手机号 + * @param code 验证码 + * @return 发送结果 + */ + @PostMapping("/sms/send-verify-code") + Result sendVerifyCode(@RequestParam("phone") String phone, @RequestParam("code") String code); + + /** + * 发送验证码短信(使用腾讯云) + * + * @param phone 手机号 + * @param code 验证码 + * @return 发送结果 + */ + @PostMapping("/sms/tencent/send-verify-code") + Result sendTencentVerifyCode(@RequestParam("phone") String phone, @RequestParam("code") String code); + + /** + * 发送验证码短信(使用阿里云) + * + * @param phone 手机号 + * @param code 验证码 + * @return 发送结果 + */ + @PostMapping("/sms/aliyun/send-verify-code") + Result sendAliyunVerifyCode(@RequestParam("phone") String phone, @RequestParam("code") String code); +} diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/UserService.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/UserService.java index 67629ab4..2928f83c 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/UserService.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/UserService.java @@ -8,6 +8,7 @@ import com.central.common.model.SysUser; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -91,4 +92,13 @@ public interface UserService { */ @GetMapping(value = "/tenant/hierarchy/son/tenantId", params = "tenantId") List getSonTenantIds(@RequestParam("tenantId") String tenantId); + + /** + * 通过手机号注册用户(返回用户信息,包含openId) + * + * @param mobile 手机号 + * @return 注册后的用户信息 + */ + @PostMapping(value = "/users-anon/register/mobile") + SysUser registerByMobile(@RequestParam("mobile") String mobile); } diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/fallback/MsgCenterServiceFallbackFactory.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/fallback/MsgCenterServiceFallbackFactory.java new file mode 100644 index 00000000..68cfb9d3 --- /dev/null +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/fallback/MsgCenterServiceFallbackFactory.java @@ -0,0 +1,35 @@ +package com.central.common.feign.fallback; + +import com.central.common.feign.MsgCenterService; +import com.central.common.model.Result; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cloud.openfeign.FallbackFactory; + +/** + * MsgCenterService降级工厂 + */ +@Slf4j +public class MsgCenterServiceFallbackFactory implements FallbackFactory { + @Override + public MsgCenterService create(Throwable throwable) { + return new MsgCenterService() { + @Override + public Result sendVerifyCode(String phone, String code) { + log.error("发送验证码短信异常, phone:{}", phone, throwable); + return Result.failed("短信服务不可用"); + } + + @Override + public Result sendTencentVerifyCode(String phone, String code) { + log.error("发送腾讯云验证码短信异常, phone:{}", phone, throwable); + return Result.failed("腾讯云短信服务不可用"); + } + + @Override + public Result sendAliyunVerifyCode(String phone, String code) { + log.error("发送阿里云验证码短信异常, phone:{}", phone, throwable); + return Result.failed("阿里云短信服务不可用"); + } + }; + } +} diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/fallback/UserServiceFallbackFactory.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/fallback/UserServiceFallbackFactory.java index 0c5025aa..0aa96f07 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/fallback/UserServiceFallbackFactory.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/fallback/UserServiceFallbackFactory.java @@ -89,6 +89,12 @@ public class UserServiceFallbackFactory implements FallbackFactory log.error("获取自己以及子孙租户列表异常:{}", tenantId, throwable); return Collections.emptyList(); } + + @Override + public SysUser registerByMobile(String mobile) { + log.error("通过手机号注册用户异常:{}", mobile, throwable); + return null; + } }; } } diff --git a/zlt-commons/zlt-common-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/zlt-commons/zlt-common-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 1d4b07f4..cbfb568f 100644 --- a/zlt-commons/zlt-common-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/zlt-commons/zlt-common-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,2 +1,3 @@ com.central.common.feign.fallback.UserServiceFallbackFactory +com.central.common.feign.fallback.MsgCenterServiceFallbackFactory com.central.common.lock.LockAspect \ No newline at end of file diff --git a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/config/SmsProperties.java b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/config/SmsProperties.java index 34dde52e..f93f0871 100644 --- a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/config/SmsProperties.java +++ b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/config/SmsProperties.java @@ -21,6 +21,8 @@ public class SmsProperties { private String secretId; private String secretKey; private String signName; + private String verifyCodeTemplateId; + public String getAppId() { return appId; } public void setAppId(String appId) { this.appId = appId; } public String getSecretId() { return secretId; } @@ -29,17 +31,27 @@ public class SmsProperties { public void setSecretKey(String secretKey) { this.secretKey = secretKey; } public String getSignName() { return signName; } public void setSignName(String signName) { this.signName = signName; } + public String getVerifyCodeTemplateId() { return verifyCodeTemplateId; } + public void setVerifyCodeTemplateId(String verifyCodeTemplateId) { + this.verifyCodeTemplateId = verifyCodeTemplateId; + } } public static class AliyunConfig { private String accessKeyId; private String accessKeySecret; private String signName; + private String verifyCodeTemplateId; + public String getAccessKeyId() { return accessKeyId; } public void setAccessKeyId(String accessKeyId) { this.accessKeyId = accessKeyId; } public String getAccessKeySecret() { return accessKeySecret; } public void setAccessKeySecret(String accessKeySecret) { this.accessKeySecret = accessKeySecret; } public String getSignName() { return signName; } public void setSignName(String signName) { this.signName = signName; } + public String getVerifyCodeTemplateId() { return verifyCodeTemplateId; } + public void setVerifyCodeTemplateId(String verifyCodeTemplateId) { + this.verifyCodeTemplateId = verifyCodeTemplateId; + } } } \ No newline at end of file diff --git a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/AliyunSmsService.java b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/AliyunSmsService.java index 1f8dbf13..abf178d2 100644 --- a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/AliyunSmsService.java +++ b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/AliyunSmsService.java @@ -1,5 +1,6 @@ package com.central.sms.service.impl; +import com.alibaba.fastjson.JSON; import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; @@ -16,6 +17,10 @@ import org.springframework.stereotype.Service; import java.util.Map; +/** + * 阿里云短信服务实现 + * @author system + */ @Service public class AliyunSmsService implements ISmsService { @@ -26,30 +31,45 @@ public class AliyunSmsService implements ISmsService { @Override public boolean sendSms(String phone, String templateId, Map params) { - SmsProperties.AliyunConfig config = smsProperties.getAliyun(); - DefaultProfile profile = DefaultProfile.getProfile( - "cn-hangzhou", // 地域ID - config.getAccessKeyId(), - config.getAccessKeySecret() - ); - IAcsClient client = new DefaultAcsClient(profile); - - SendSmsRequest request = new SendSmsRequest(); - request.setPhoneNumbers(phone); - request.setSignName(config.getSignName()); - request.setTemplateCode(templateId); - // 阿里云短信模板参数为JSON字符串 - if (params != null && !params.isEmpty()) { - request.setTemplateParam(com.alibaba.fastjson.JSON.toJSONString(params)); - } - try { - logger.info("[阿里云短信] 发送请求: 手机号={}, 模板={}, 参数={}", phone, templateId, params); + SmsProperties.AliyunConfig config = smsProperties.getAliyun(); + logger.info("[短信发送][服务商:ALIYUN] 手机号={}, 模板ID={}, 参数={}", phone, templateId, params); + + // 创建DefaultAcsClient实例并初始化 + DefaultProfile profile = DefaultProfile.getProfile( + "cn-hangzhou", // 地域ID,固定值 + config.getAccessKeyId(), + config.getAccessKeySecret() + ); + IAcsClient client = new DefaultAcsClient(profile); + + // 组装请求对象 + SendSmsRequest request = new SendSmsRequest(); + request.setPhoneNumbers(phone); + request.setSignName(config.getSignName()); + request.setTemplateCode(templateId); + + // 阿里云短信模板参数为JSON字符串 + if (params != null && !params.isEmpty()) { + String templateParam = JSON.toJSONString(params); + request.setTemplateParam(templateParam); + logger.debug("[短信发送][服务商:ALIYUN] 模板参数JSON: {}", templateParam); + } + + // 发送短信 SendSmsResponse response = client.getAcsResponse(request); - logger.info("[阿里云短信] 发送结果: {}", response.getMessage()); + + logger.info("[短信发送][服务商:ALIYUN] 响应: code={}, message={}, requestId={}, bizId={}", + response.getCode(), response.getMessage(), response.getRequestId(), response.getBizId()); + return "OK".equalsIgnoreCase(response.getCode()); } catch (ClientException e) { - logger.error("[阿里云短信] 发送失败,手机号:{},模板:{},参数:{},异常:{}", phone, templateId, params, e.getMessage(), e); + logger.error("[短信发送][服务商:ALIYUN] SDK异常,手机号:{},模板ID:{},参数:{},错误码:{},异常:{}", + phone, templateId, params, e.getErrCode(), e.getMessage(), e); + throw new SmsSendException("阿里云短信发送失败: " + e.getMessage(), e); + } catch (Exception e) { + logger.error("[短信发送][服务商:ALIYUN] 失败,手机号:{},模板ID:{},参数:{},异常:{}", + phone, templateId, params, e.getMessage(), e); throw new SmsSendException("阿里云短信发送失败", e); } } diff --git a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/TencentSmsService.java b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/TencentSmsService.java index 2414b0ba..c2b58245 100644 --- a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/TencentSmsService.java +++ b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/TencentSmsService.java @@ -4,8 +4,13 @@ import com.central.sms.config.SmsProperties; import com.central.sms.exception.SmsSendException; import com.central.sms.service.ISmsService; import com.tencentcloudapi.common.Credential; +import com.tencentcloudapi.common.exception.TencentCloudSDKException; import com.tencentcloudapi.common.profile.ClientProfile; import com.tencentcloudapi.common.profile.HttpProfile; +import com.tencentcloudapi.sms.v20210111.SmsClient; +import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest; +import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse; +import com.tencentcloudapi.sms.v20210111.models.SendStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -26,26 +31,56 @@ public class TencentSmsService implements ISmsService { try { SmsProperties.TencentConfig config = smsProperties.getTencent(); logger.info("[短信发送][服务商:TENCENT] 手机号={}, 模板ID={}, 参数={}", phone, templateId, params); + + // 实例化认证对象 Credential cred = new Credential(config.getSecretId(), config.getSecretKey()); + + // 实例化http配置 HttpProfile httpProfile = new HttpProfile(); httpProfile.setEndpoint("sms.tencentcloudapi.com"); + + // 实例化客户端配置 ClientProfile clientProfile = new ClientProfile(); clientProfile.setHttpProfile(httpProfile); - /*SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile); + // 实例化SMS客户端 + SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile); + + // 实例化请求对象 SendSmsRequest req = new SendSmsRequest(); req.setSmsSdkAppId(config.getAppId()); req.setSignName(config.getSignName()); req.setTemplateId(templateId); - req.setPhoneNumberSet(new String[]{phone}); - req.setTemplateParamSet(params.values().toArray(new String[0])); + // 设置手机号(需要加+86前缀) + String[] phoneNumbers = new String[]{"+86" + phone}; + req.setPhoneNumberSet(phoneNumbers); + + // 设置模板参数 + if (params != null && !params.isEmpty()) { + req.setTemplateParamSet(params.values().toArray(new String[0])); + } + + // 发送短信 SendSmsResponse resp = client.SendSms(req); - logger.info("[短信发送][服务商:TENCENT] 响应: code={}, message={}", resp.getSendStatusSet()[0].getCode(), resp.getSendStatusSet()[0].getMessage()); - return "Ok".equalsIgnoreCase(resp.getSendStatusSet()[0].getCode());*/ - return true; + SendStatus[] statusSet = resp.getSendStatusSet(); + + if (statusSet != null && statusSet.length > 0) { + SendStatus status = statusSet[0]; + logger.info("[短信发送][服务商:TENCENT] 响应: code={}, message={}, requestId={}", + status.getCode(), status.getMessage(), resp.getRequestId()); + return "Ok".equalsIgnoreCase(status.getCode()); + } + + logger.warn("[短信发送][服务商:TENCENT] 响应状态集为空"); + return false; + } catch (TencentCloudSDKException e) { + logger.error("[短信发送][服务商:TENCENT] SDK异常,手机号:{},模板ID:{},参数:{},错误码:{},异常:{}", + phone, templateId, params, e.getErrorCode(), e.getMessage(), e); + throw new SmsSendException("腾讯云短信发送失败: " + e.getMessage(), e); } catch (Exception e) { - logger.error("[短信发送][服务商:TENCENT] 失败,手机号:{},模板ID:{},参数:{},异常:{}", phone, templateId, params, e.getMessage(), e); + logger.error("[短信发送][服务商:TENCENT] 失败,手机号:{},模板ID:{},参数:{},异常:{}", + phone, templateId, params, e.getMessage(), e); throw new SmsSendException("腾讯云短信发送失败", e); } } diff --git a/third-party-aerial-photography-flow.md b/zlt-doc/third-party-aerial-photography-flow.md similarity index 100% rename from third-party-aerial-photography-flow.md rename to zlt-doc/third-party-aerial-photography-flow.md diff --git a/zlt-uaa/src/main/java/com/central/oauth/controller/LoginController.java b/zlt-uaa/src/main/java/com/central/oauth/controller/LoginController.java index 923832a3..67080f0a 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/controller/LoginController.java +++ b/zlt-uaa/src/main/java/com/central/oauth/controller/LoginController.java @@ -1,8 +1,10 @@ package com.central.oauth.controller; import com.central.common.constant.SecurityConstants; +import com.central.common.feign.MsgCenterService; import com.central.common.model.CodeEnum; import com.central.common.model.Result; +import com.central.common.model.SysUser; import com.central.common.utils.RSAUtil; import com.central.common.utils.StringUtils; import com.central.oauth.model.Client; @@ -21,11 +23,14 @@ import com.central.oauth2.common.properties.SecurityProperties; import com.central.oauth2.common.token.OpenIdAuthenticationToken; import com.central.oauth2.common.token.TencentAuthenticationToken; import com.central.oauth2.common.util.AuthUtils; +import com.central.common.feign.UserService; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequestWrapper; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Lazy; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.oauth2.core.AuthorizationGrantType; import org.springframework.security.oauth2.core.ClientAuthenticationMethod; @@ -48,6 +53,8 @@ import java.time.temporal.ChronoUnit; import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.Random; +import java.util.concurrent.TimeUnit; @Tag(name = "登录接口") @RestController @@ -86,6 +93,31 @@ public class LoginController { @Resource private UnifiedLogoutService unifiedLogoutService; + @Resource + private StringRedisTemplate stringRedisTemplate; + + @Resource + private MsgCenterService msgCenterService; + + @Resource + private UserService userService; + + /** + * 短信验证码Redis Key前缀 + */ + private static final String SMS_CODE_PREFIX = "sms:code:"; + + /** + * 短信验证码有效期(分钟) + */ + private static final long SMS_CODE_EXPIRE_MINUTES = 5; + + /** + * 短信服务商类型:tencent-腾讯云, aliyun-阿里云 + */ + @org.springframework.beans.factory.annotation.Value("${sms.provider:tencent}") + private String smsProvider; + @PostMapping(value = "/login") public Result> login(@RequestBody LoginReq req) { try { @@ -133,6 +165,148 @@ public class LoginController { } } + /** + * 发送手机验证码 + * + * @param mobile 手机号 + * @return 发送结果 + */ + @Operation(summary = "发送手机验证码") + @PostMapping(value = "/sendSmsCode") + public Result sendSmsCode(@RequestParam("mobile") String mobile) { + try { + // 1) 校验手机号格式 + if (StringUtils.isBlank(mobile) || !mobile.matches("^1[3-9]\\d{9}$")) { + return Result.failed("手机号格式不正确"); + } + + // 2) 检查是否频繁发送(防刷) + String redisKey = SMS_CODE_PREFIX + mobile; + String existCode = stringRedisTemplate.opsForValue().get(redisKey); + if (StringUtils.isNotBlank(existCode)) { + Long ttl = stringRedisTemplate.getExpire(redisKey, TimeUnit.SECONDS); + if (ttl != null && ttl > (SMS_CODE_EXPIRE_MINUTES - 1) * 60) { + return Result.failed("验证码发送过于频繁,请稍后再试"); + } + } + + // 3) 生成4位随机验证码 + String code = String.format("%04d", new Random().nextInt(10000)); + + // 4) 根据配置选择短信服务商发送短信 + Result sendResult; + if ("aliyun".equalsIgnoreCase(smsProvider)) { + log.info("使用阿里云发送验证码,mobile:{}", mobile); + sendResult = msgCenterService.sendAliyunVerifyCode(mobile, code); + } else { + // 默认使用腾讯云 + log.info("使用腾讯云发送验证码,mobile:{}", mobile); + sendResult = msgCenterService.sendTencentVerifyCode(mobile, code); + } + if (sendResult == null || sendResult.getResp_code() != 0) { + log.error("发送短信验证码失败,mobile:{}, result:{}", mobile, sendResult); + return Result.failed("短信发送失败,请稍后重试"); + } + + // 5) 发送成功后存入Redis,设置有效期 + stringRedisTemplate.opsForValue().set(redisKey, code, SMS_CODE_EXPIRE_MINUTES, TimeUnit.MINUTES); + log.info("短信验证码发送成功,mobile:{}", mobile); + + return Result.succeed("验证码发送成功"); + } catch (Exception e) { + log.error("发送短信验证码异常,mobile:{}", mobile, e); + return Result.failed("短信发送失败:" + e.getMessage()); + } + } + + /** + * 手机号验证码登录 + * + * @param mobile 手机号 + * @param smsCode 短信验证码 + * @param clientId 客户端ID + * @return 登录结果(token) + */ + @Operation(summary = "手机号验证码登录") + @PostMapping(value = "/loginBySmsCode") + public Result> loginBySmsCode( + @RequestParam("mobile") String mobile, + @RequestParam("smsCode") String smsCode, + @RequestParam("clientId") String clientId) { + try { + // 1) 校验参数 + if (StringUtils.isBlank(mobile) || !mobile.matches("^1[3-9]\\d{9}$")) { + return Result.failed("手机号格式不正确"); + } + if (StringUtils.isBlank(smsCode)) { + return Result.failed("验证码不能为空"); + } + if (StringUtils.isBlank(clientId)) { + return Result.failed("客户端ID不能为空"); + } + + // 2) 从Redis获取验证码并校验 + String redisKey = SMS_CODE_PREFIX + mobile; + String cachedCode = stringRedisTemplate.opsForValue().get(redisKey); + if (StringUtils.isBlank(cachedCode)) { + return Result.failed("验证码已过期,请重新获取"); + } + if (!cachedCode.equals(smsCode)) { + return Result.failed("验证码错误"); + } + + // 3) 验证码校验成功后删除 + stringRedisTemplate.delete(redisKey); + + // 4) 查询用户是否已注册 + SysUser sysUser = userService.findByMobile(mobile); + String openId; + if (sysUser == null || sysUser.getId() == null) { + // 用户不存在,先注册 + log.info("用户不存在,进行注册,mobile:{}", mobile); + SysUser newUser = userService.registerByMobile(mobile); + if (newUser == null || StringUtils.isBlank(newUser.getOpenId())) { + return Result.failed("用户注册失败,请重试"); + } + openId = newUser.getOpenId(); + log.info("用户注册成功,mobile:{}, openId:{}", mobile, openId); + } else { + // 用户已存在 + openId = sysUser.getOpenId(); + if (StringUtils.isBlank(openId)) { + return Result.failed("用户信息异常,缺少openId"); + } + log.info("用户已存在,直接登录,mobile:{}, openId:{}", mobile, openId); + } + + // 5) 使用openId进行登录 + LoginReq loginReq = new LoginReq(); + loginReq.setGrantType("openId"); + loginReq.setOpenId(openId); + loginReq.setClientId(clientId); + + // 6) 客户端校验 + Client client = clientService.loadClientByClientId(clientId); + if (client == null) { + return Result.failed("所属客户端不存在"); + } + RegisteredClient registeredClient = registeredClientRepository.findByClientId(client.getClientId()); + if (registeredClient == null) { + return Result.failed("未注册的客户端"); + } + AuthorizationGrantType grantTypeToUse = new AuthorizationGrantType("openId"); + if (!registeredClient.getAuthorizationGrantTypes().contains(grantTypeToUse)) { + return Result.failed("客户端未开通openId授权类型"); + } + + // 7) 颁发令牌 + return issueTokenInternally(loginReq, registeredClient, null); + } catch (Exception e) { + log.error("手机号验证码登录异常,mobile:{}", mobile, e); + return Result.failed("登录失败:" + e.getMessage()); + } + } + @PostMapping(value = "/logout") public Result logOut(HttpServletRequest request) { String token = AuthUtils.extractHeaderToken(request); diff --git a/zlt-uaa/src/main/resources/application.yml b/zlt-uaa/src/main/resources/application.yml index 37f321ae..9c9f3c8d 100644 --- a/zlt-uaa/src/main/resources/application.yml +++ b/zlt-uaa/src/main/resources/application.yml @@ -63,3 +63,5 @@ zlt: # 鍏煎榛樿琛ㄥ崟鐧诲綍涓庡唴缃櫥鍑? - /user/login - /oauth/remove/token + - /oauth/sendSmsCode + - /oauth/loginBySmsCode diff --git a/zlt-web/yingyan/REFACTOR_PLAN.md b/zlt-web/yingyan/REFACTOR_PLAN.md deleted file mode 100644 index c4927f8b..00000000 --- a/zlt-web/yingyan/REFACTOR_PLAN.md +++ /dev/null @@ -1,69 +0,0 @@ -# 通用大屏 → 无人机智慧城市管控平台(重构计划表) - -> 目标:在不改变现有功能与数据接口的前提下,把 `/dashboard` 的“通用监控大屏”升级为更符合“无人机赋能智慧城市”的首页大屏:维度更丰富、信息架构更清晰、视觉更高级、交互更顺手。 - -## 0. 约束与边界(必须遵守) -- 不改路由与入口:仍然使用 `/dashboard`,`进入监控视图` 仍然跳转 `/map3d?from=dashboard`。 -- 不改现有接口/聚合逻辑:继续使用 `src/services/dashboard.ts` 的 `getDeviceStats/getTaskStats/getTrendData` 等(允许新增“可选增强”接口或派生数据)。 -- 不影响海事行业:`/maritime` 不做联动修改(仅做必要的“命名展示”区分时除外)。 -- 无数据也要好看:任何新模块在数据缺失时要有优雅的“空态/占位”,避免空白或布局塌陷。 - -## 1. 目标体验(验收口径) -1. 首页一眼看懂:顶部为“城市态势总览”,中间为“数字孪生/空域态势”,两侧为“运行体征/事件处置”。 -2. 统计维度丰富:至少覆盖「设备运行」「任务执行」「城市网格治理」「AI识别事件」「环境/交通态势(可派生/可模拟)」五大类。 -3. 视觉统一:同一套色板、间距、描边、阴影、字体层级,避免“拼贴感”。 -4. 交互轻快:鼠标悬停、点击、筛选都有明确反馈;滚动区域可控且不抢焦点。 - -## 2. 信息架构与模块清单(Dashboard) - -### 2.1 顶部(Header) -- 平台命名:`无人机智慧城市管控平台` -- 状态条:当前租户/范围、在线率、告警等级概览、当前时间(若页面本身不显示则放入大屏 Header) -- 快捷入口:进入 3D 监控、任务/设备(保持现有入口,不新增强绑定) - -### 2.2 左侧(城市运行体征) -- 城市网格治理(Radar):巡检覆盖、问题发现、处置效率、复核通过、重点区域关注 -- 环境感知(Line/Gauge/Liquid):PM2.5、噪声、热源异常趋势(允许派生/模拟,但要“稳定”) -- 交通与人流(Area/Heatmap):拥堵指数趋势、重点区域热度 TopN - -### 2.3 中间(全域态势 / 数字孪生入口) -- 核心态势 KPI(数字+发光强调):城市安全指数、今日识别事件、平均响应时长、闭环率 -- 数字孪生入口卡(保留进入 `/map3d`):升级为更“城市中枢”风格,增加图层提示文案(电子围栏/事件点位/航线) -- AI抓拍与隐患快照(Carousel/卡片流):违停、烟火、占道、河道漂浮物、工地未戴帽等(点击可弹出详情抽屉/弹窗) - -### 2.4 右侧(事件处置与运行调度) -- 事件类型分布(Pie/RadialBar):按“城市治理事件”分类统计(与告警/任务派生映射) -- 实时事件流(List):分级(一般/重要/紧急)+ 来源(无人机/摄像头/机库)+ 处理状态(待确认/已派单/处理中/已闭环) -- 任务执行(保留原筛选逻辑):日/月/年切换 + 状态占比 + 近 7 日趋势 + 异常原因分析(原模块“换皮+换语义”) - -## 3. 数据策略(不改功能前提下“做出新维度”) - -### 3.1 直接复用(已有) -- 设备:`DeviceStats.total/online/offline/fault/byType/onlineRate` -- 任务:`TaskStats.pending/running/completed/failed/successRate/todayNew` -- 趋势:`getTrendData(7)`(现为模拟,后续可接真实接口) -- 告警:`getMockAlerts()`(现为模拟) - -### 3.2 派生增强(推荐落地) -- 城市安全指数:由 `告警数量/等级` + `任务成功率` + `在线率` 计算得到(可解释、可复现)。 -- 事件类型分布:把告警/任务映射到“城市治理事件”类别(如:离线→关键设施告警、低电→保障能力风险)。 -- 网格治理/环境/交通:使用“可复现的稳定模拟”(基于 tenantId + 日期 hash),保证刷新时不跳变、截图时稳定。 - -## 4. 设计系统(落地规则) -- 色板:以 `--accent-blue/green/yellow/red` 为主,新增 1~2 个辅助色(紫/青)但必须有统一用途。 -- 卡片:统一玻璃拟态 + 细描边 + 角落高光;标题区高度统一;内容区保持最小可视高度。 -- 字体层级:KPI 数字使用等宽/半等宽(更有“仪表感”);正文保持 12~13px,标题 14~15px。 -- 动效:只用“微动效”(呼吸光、扫光、hover 抬升),避免大幅炫技影响可读性。 - -## 5. 实施里程碑(建议按顺序做) - -| 里程碑 | 目标 | 产出 | 涉及文件(示例) | 验收点 | -|---|---|---|---|---| -| M1 | 结构拆分 + 新布局骨架 | `Dashboard` 拆组件、三栏网格稳定 | `src/pages/dashboard/index.tsx`、`src/pages/dashboard/index.less`、`src/pages/dashboard/components/*` | 1920×1080 无挤压、无滚动条乱跳 | -| M2 | 智慧城市模块落地 | 城市 KPI/网格治理/环境交通/AI快照 | `src/services/dashboard.ts`(新增派生/稳定模拟)、`src/pages/dashboard/components/*` | 统计维度明显增加,空态不丑 | -| M3 | 视觉与交互精修 | 统一色板、排版、hover、空态、细节 | `src/global.less`(少量)、`src/pages/dashboard/*` | 一致性强、截图“像产品” | -| M4(可选) | 设备操控页 HUD 化 | 不改控制逻辑,只换布局与皮肤 |(按现有控制页位置确定)| 操控入口/功能不变、观感升级 | - -## 6. 风险与回退 -- 风险:新增模块依赖“模拟/派生数据”可能被误认为真实数据;处理:在不显眼处提供“数据口径说明”(抽屉/帮助提示)。 -- 回退:保留原统计卡片/图表配置为独立组件,可随时切回(通过组件替换,不删代码)。 diff --git a/zlt-web/yingyan/config/routes.ts b/zlt-web/yingyan/config/routes.ts index 65ab10cf..cdfa6b03 100644 --- a/zlt-web/yingyan/config/routes.ts +++ b/zlt-web/yingyan/config/routes.ts @@ -14,10 +14,10 @@ export default [ path: '/', component: '@/layouts/BlankLayout', routes: [ - // 默认跳转海事大屏 + // 默认跳转智慧城市大屏 { path: '/', - redirect: '/maritime', + redirect: '/dashboard', }, // 通用监控大屏首页 { diff --git a/zlt-web/yingyan/dist.zip b/zlt-web/yingyan/dist.zip index b2aa984c..718a0582 100644 Binary files a/zlt-web/yingyan/dist.zip and b/zlt-web/yingyan/dist.zip differ diff --git a/zlt-web/yingyan/src/global.less b/zlt-web/yingyan/src/global.less index c29975ee..2211eef5 100644 --- a/zlt-web/yingyan/src/global.less +++ b/zlt-web/yingyan/src/global.less @@ -57,12 +57,21 @@ body { /* Ant Design 覆盖 */ .ant-layout { background: var(--bg-primary) !important; + height: 100%; + min-height: 0; } .ant-layout-header { + flex: 0 0 auto; background: var(--bg-secondary) !important; } +.ant-layout-content { + flex: 1; + min-height: 0; + overflow: hidden; +} + .ant-card { background: var(--bg-card) !important; border-color: var(--border-color) !important; diff --git a/zlt-web/yingyan/src/layouts/BlankLayout.less b/zlt-web/yingyan/src/layouts/BlankLayout.less index 58ddcdcc..1fca8654 100644 --- a/zlt-web/yingyan/src/layouts/BlankLayout.less +++ b/zlt-web/yingyan/src/layouts/BlankLayout.less @@ -1,7 +1,13 @@ .blank-layout { - min-height: 100vh; + height: 100vh; + height: 100dvh; + max-height: 100vh; + max-height: 100dvh; + overflow: hidden; background: var(--bg-primary); - /* Dashboard 高度自适应:同一份变量同时驱动 Header 与 Content,避免“减去固定像素”导致不同屏幕被遮挡 */ + display: flex; + flex-direction: column; + /* Dashboard 高度自适应:同一份变量同时驱动 Header 与 Content,避免"减去固定像素"导致不同屏幕被遮挡 */ --dashboard-header-h: 80px; } @@ -18,6 +24,7 @@ } .blank-header { + flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; @@ -27,8 +34,7 @@ background: linear-gradient(180deg, rgba(19, 26, 61, 0.98) 0%, rgba(10, 14, 39, 0.95) 100%) !important; border-bottom: 1px solid var(--border-color); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); - position: sticky; - top: 0; + position: relative; z-index: 100; } @@ -100,18 +106,16 @@ } .blank-content { - height: calc(100vh - 56px); - height: calc(100dvh - 56px); + flex: 1; + min-height: 0; overflow: auto; background: var(--bg-primary); - min-height: 0; } .blank-content--dashboard { - height: calc(100vh - var(--dashboard-header-h)); - height: calc(100dvh - var(--dashboard-header-h)); - overflow: hidden; + flex: 1; min-height: 0; + overflow: hidden; display: flex; flex-direction: column; @@ -209,6 +213,7 @@ } .blank-header--dashboard { + flex: 0 0 var(--dashboard-header-h); height: var(--dashboard-header-h); line-height: var(--dashboard-header-h); padding: 0 22px; @@ -218,7 +223,7 @@ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.28), inset 0 -1px 0 rgba(0, 212, 255, 0.18); - position: sticky; + position: relative; &::before { content: ''; @@ -596,13 +601,25 @@ } .blank-content--maritime { + /* 参考智慧城市大屏:用明确高度约束内容区,保证子 Grid 的 fr 高度计算为“确定值”,避免卡片把容器撑高导致后续面板被裁剪 */ height: calc(100vh - 88px); + height: calc(100dvh - 88px); overflow: hidden; + min-height: 0; + width: 100%; + display: flex; + flex-direction: column; background: linear-gradient(180deg, #020c1b 0%, #071a2f 30%, #0c2340 60%, #0f2847 100%); + + > * { + flex: 1; + min-height: 0; + min-width: 0; + } } @keyframes maritimeSweep { diff --git a/zlt-web/yingyan/src/pages/dashboard/components/CityVitalCard.tsx b/zlt-web/yingyan/src/pages/dashboard/components/CityVitalCard.tsx new file mode 100644 index 00000000..e8c120f2 --- /dev/null +++ b/zlt-web/yingyan/src/pages/dashboard/components/CityVitalCard.tsx @@ -0,0 +1,84 @@ +import React from 'react'; +import { Card, Tabs } from 'antd'; +import { RadarChartOutlined } from '@ant-design/icons'; +import { Radar, Line, Heatmap } from '@ant-design/plots'; + +interface CityVitalCardProps { + radarConfig: any; + envLineConfig: any; + trafficHeatmapConfig: any; +} + +const CityVitalCard: React.FC = ({ + radarConfig, + envLineConfig, + trafficHeatmapConfig, +}) => { + return ( + + 城市运行体征 + + } + style={{ + height: '100%', + background: 'rgba(19, 26, 61, 0.7)', + border: '1px solid rgba(0, 212, 255, 0.15)', + borderRadius: 8, + display: 'flex', + flexDirection: 'column', + }} + styles={{ + header: { flex: '0 0 auto', minHeight: 40, padding: '0 12px', borderBottom: '1px solid rgba(0, 212, 255, 0.1)' }, + body: { flex: 1, padding: 12, overflow: 'hidden', display: 'flex', flexDirection: 'column', minHeight: 0 }, + }} + size="small" + > + +
覆盖、发现、处置、复核一体化评分
+
+ +
+ + ), + }, + { + key: 'env', + label: '环境感知', + children: ( +
+
空地协同采集 · 24 小时滚动
+
+ +
+
+ ), + }, + { + key: 'traffic', + label: '交通热力', + children: ( +
+
重点片区热度分布(网格化)
+
+ +
+
+ ), + }, + ]} + /> +
+ ); +}; + +export default CityVitalCard; diff --git a/zlt-web/yingyan/src/pages/dashboard/components/DispatchCard.tsx b/zlt-web/yingyan/src/pages/dashboard/components/DispatchCard.tsx new file mode 100644 index 00000000..581efd5b --- /dev/null +++ b/zlt-web/yingyan/src/pages/dashboard/components/DispatchCard.tsx @@ -0,0 +1,149 @@ +import React from 'react'; +import { Card, Space, Segmented, DatePicker } from 'antd'; +import { RocketOutlined } from '@ant-design/icons'; +import { Line } from '@ant-design/plots'; +import dayjs from 'dayjs'; +import './card.less'; + +interface TaskStats { + pending: number; + running: number; + completed: number; + failed: number; + successRate: number; +} + +interface TrendItem { + date: string; + type: string; + value: number; +} + +interface DispatchCardProps { + taskStats: TaskStats | null; + taskTrendData: TrendItem[]; + taskStatType: 'day' | 'month' | 'year'; + taskStatDate: dayjs.Dayjs; + onStatTypeChange: (type: 'day' | 'month' | 'year') => void; + onDateChange: (date: dayjs.Dayjs) => void; +} + +const DispatchCard: React.FC = ({ + taskStats, + taskTrendData, + taskStatType, + taskStatDate, + onStatTypeChange, + onDateChange, +}) => { + const taskPeriodText = React.useMemo(() => { + if (taskStatType === 'day') return '当日'; + if (taskStatType === 'month') return '当月'; + return '当年'; + }, [taskStatType]); + + const datePickerFormat = React.useMemo(() => { + if (taskStatType === 'day') return 'YYYY-MM-DD'; + if (taskStatType === 'month') return 'YYYY-MM'; + return 'YYYY'; + }, [taskStatType]); + + const dispatchTrendConfig: any = React.useMemo(() => { + return { + data: taskTrendData, + xField: 'date', + yField: 'value', + seriesField: 'type', + appendPadding: [2, 6, 6, 4], + smooth: true, + color: ['#00d4ff', '#00ff88', '#ffb800'], + xAxis: { + label: { style: { fill: 'rgba(255,255,255,0.62)', fontSize: 10 } }, + grid: null, + }, + yAxis: { + label: { style: { fill: 'rgba(255,255,255,0.62)', fontSize: 10 } }, + grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, + }, + legend: { + position: 'top-right', + itemName: { style: { fill: 'rgba(255,255,255,0.72)', fontSize: 10 } }, + itemSpacing: 8, + marker: { symbol: 'circle', style: { r: 4 } }, + }, + tooltip: { showMarkers: true }, + autoFit: true, + }; + }, [taskTrendData]); + + return ( + + {taskPeriodText}运行调度 + + } + className="dashboard-card glass-panel" + size="small" + style={{ height: '100%', minHeight: 0, maxHeight: '100%' }} + styles={{ + header: { flex: '0 0 auto', minHeight: 40, padding: '0 12px', borderBottom: '1px solid rgba(0, 212, 255, 0.1)' }, + body: { flex: 1, padding: 12, overflow: 'hidden', display: 'flex', flexDirection: 'column', minHeight: 0 }, + }} + extra={ + + onStatTypeChange(v as any)} + /> + v && onDateChange(v)} + picker={taskStatType === 'day' ? 'date' : taskStatType} + allowClear={false} + format={datePickerFormat} + disabledDate={(d) => !!d && d.isAfter(dayjs(), 'day')} + /> + + } + > +
+
+
{taskStats?.pending || 0}
+
待执行
+
+
+
{taskStats?.running || 0}
+
执行中
+
+
+
{taskStats?.completed || 0}
+
已完成
+
+
+
{taskStats?.failed || 0}
+
异常
+
+
+
{taskStats?.successRate || 0}%
+
成功率
+
+
+
+
近 7 日任务趋势
+
+ +
+
+
+ ); +}; + +export default DispatchCard; diff --git a/zlt-web/yingyan/src/pages/dashboard/components/DroneInsightCard.tsx b/zlt-web/yingyan/src/pages/dashboard/components/DroneInsightCard.tsx new file mode 100644 index 00000000..c611cc81 --- /dev/null +++ b/zlt-web/yingyan/src/pages/dashboard/components/DroneInsightCard.tsx @@ -0,0 +1,303 @@ +import React from 'react'; +import { Card, Tabs, Carousel, Empty, Tag, Progress } from 'antd'; +import { AlertOutlined } from '@ant-design/icons'; +import { Pie } from '@ant-design/plots'; +import './card.less'; + +interface AiSnapshot { + id: string; + tag: string; + timeText: string; + title: string; + location: string; + confidence: number; + severity: string; +} + +interface RegionCoverage { + id: string; + name: string; + coverage: number; + pending: number; + risk: string; + updatedAt: string; +} + +interface DroneInsightCardProps { + aiSnapshots: AiSnapshot[]; + fleet: { + avgBattery: number; + lowBatteryAlerts: number; + flightHoursToday: number; + flightMileageToday: number; + dockOnline: number; + dockTotal: number; + droneInFlight: number; + droneStandby: number; + droneMaintenance: number; + droneOnline: number; + droneTotal: number; + }; + airspace: { + complianceIndex: number; + safetyIndex: number; + geofenceTriggers: number; + noFlyWarnings: number; + approvalsToday: number; + approvalsPassRate: number; + }; + regionCoverage: RegionCoverage[]; + compactLevel: 0 | 1 | 2; + snapshotsPerPage: number; + airspaceGaugeSize: number; +} + +const regionRiskColor = (risk: string) => { + if (risk === 'critical') return '#ff4757'; + if (risk === 'warning') return '#ffb800'; + return '#00ff88'; +}; + +const DroneInsightCard: React.FC = ({ + aiSnapshots, + fleet, + airspace, + regionCoverage, + compactLevel, + snapshotsPerPage, + airspaceGaugeSize, +}) => { + const droneStatusPieConfig: any = React.useMemo(() => { + const total = fleet.droneInFlight + fleet.droneStandby + fleet.droneMaintenance; + if (!total) return {}; + return { + data: [ + { type: '在飞', value: fleet.droneInFlight }, + { type: '待命', value: fleet.droneStandby }, + { type: '维护', value: fleet.droneMaintenance }, + ], + angleField: 'value', + colorField: 'type', + radius: 0.92, + innerRadius: 0.62, + color: ['rgba(157, 78, 221, 0.95)', 'rgba(0, 212, 255, 0.9)', 'rgba(255, 184, 0, 0.92)'], + legend: false, + label: false, + statistic: { + title: false, + content: { + style: { color: 'rgba(255,255,255,0.88)', fontSize: 18, fontWeight: 700, whiteSpace: 'pre-line' }, + content: `${fleet.droneOnline}/${fleet.droneTotal}\n在线`, + }, + }, + autoFit: true, + }; + }, [fleet]); + + const visibleRegionCoverage = React.useMemo(() => { + const max = compactLevel === 2 ? 2 : compactLevel === 1 ? 4 : 6; + return regionCoverage.slice(0, max); + }, [regionCoverage, compactLevel]); + + return ( + + 无人机态势与AI洞察 + + } + className="dashboard-card glass-panel" + size="small" + style={{ height: '100%', minHeight: 0, maxHeight: '100%' }} + styles={{ + header: { flex: '0 0 auto', minHeight: 40, padding: '0 12px', borderBottom: '1px solid rgba(0, 212, 255, 0.1)' }, + body: { flex: 1, padding: 12, overflow: 'hidden', display: 'flex', flexDirection: 'column', minHeight: 0 }, + }} + > + +
+
+
平均电量
+
{fleet.avgBattery}%
+
低电 {fleet.lowBatteryAlerts} 起
+
+
+
飞行时长
+
{fleet.flightHoursToday}h
+
今日累计
+
+
+
飞行里程
+
{fleet.flightMileageToday}km
+
含航线复飞
+
+
+
可用机库
+
+ {fleet.dockOnline}/{fleet.dockTotal} +
+
在线/总量
+
+
+ +
+
+
机队状态占比
+
+ {Object.keys(droneStatusPieConfig).length ? ( + + ) : ( + + )} +
+
+
+
重点区域覆盖
+
+ {visibleRegionCoverage.map((r) => ( +
+
+ {r.name} + + + {r.risk === 'critical' ? '高风险' : r.risk === 'warning' ? '关注' : '正常'} + + {r.updatedAt} + +
+
+ + {r.coverage}% + 待处置 {r.pending} +
+
+ ))} +
+
+
+ + ), + }, + { + key: 'snap', + label: 'AI快照', + children: ( +
+ + {new Array(Math.max(1, Math.ceil(aiSnapshots.length / snapshotsPerPage))) + .fill(0) + .map((_, pageIdx) => { + const start = pageIdx * snapshotsPerPage; + const page = aiSnapshots.slice(start, start + snapshotsPerPage); + return ( +
+
+ {page.map((s) => ( +
+
+ {s.tag} + {s.timeText} +
+
{s.title}
+
+ {s.location} + 置信度 {s.confidence}% +
+
+ ))} +
+
+ ); + })} +
+
+ ), + }, + { + key: 'airspace', + label: '空域合规', + children: ( +
+
+
+ +
+
合规指数
+
围栏/禁飞/审批综合
+
城市安全指数 {airspace.safetyIndex}
+
+
+ +
+
+
{airspace.geofenceTriggers}
+
围栏触发
+
+
+
{airspace.noFlyWarnings}
+
禁飞预警
+
+
+
{airspace.approvalsToday}
+
今日审批
+
+
+
{airspace.approvalsPassRate}%
+
通过率
+
+
+
+ +
+
+ + 重点区域启用"低空走廊",优先保障应急任务快速通行。 +
+ {compactLevel === 2 ? null : ( + <> +
+ + 围栏触发或禁飞预警上升时,建议自动降级为"复核模式"。 +
+
+ + 审批通过率稳定后,可扩大夜航与多机协同策略的投放比例。 +
+ + )} +
+
+ ), + }, + ]} + /> +
+ ); +}; + +export default DroneInsightCard; diff --git a/zlt-web/yingyan/src/pages/dashboard/components/EventInsightCard.tsx b/zlt-web/yingyan/src/pages/dashboard/components/EventInsightCard.tsx new file mode 100644 index 00000000..1ba30183 --- /dev/null +++ b/zlt-web/yingyan/src/pages/dashboard/components/EventInsightCard.tsx @@ -0,0 +1,260 @@ +import React from 'react'; +import { Card, Tabs, Empty } from 'antd'; +import { EnvironmentOutlined } from '@ant-design/icons'; +import { Funnel, RadialBar, Pie, Column, Rose, Line } from '@ant-design/plots'; +import './card.less'; + +interface EventInsightCardProps { + eventFunnelData: any[]; + eventTypeData: any[]; + terminalPieData: any[]; + taskTypeData: any[]; + failureAnalysisData: any[]; + annualData: any[]; +} + +const EventInsightCard: React.FC = ({ + eventFunnelData, + eventTypeData, + terminalPieData, + taskTypeData, + failureAnalysisData, + annualData, +}) => { + const funnelConfig: any = React.useMemo(() => { + return { + data: eventFunnelData, + xField: 'stage', + yField: 'value', + legend: false, + conversionTag: false, + tooltip: { + formatter: (d: any) => ({ name: d?.stage ?? d?.name ?? '阶段', value: d?.value ?? 0 }), + }, + label: { + formatter: (d: any) => { + const stage = d?.stage ?? d?.name ?? d?.type ?? '阶段'; + const value = d?.value ?? d?.count ?? 0; + return `${stage} ${value}`; + }, + content: (d: any) => { + const stage = d?.stage ?? d?.name ?? d?.type ?? '阶段'; + const value = d?.value ?? d?.count ?? 0; + return `${stage} ${value}`; + }, + style: { fill: 'rgba(255,255,255,0.78)', fontSize: 12 }, + }, + color: ['#00d4ff', '#00ff88', '#ffb800', '#9d4edd', '#00d4ff'], + autoFit: true, + }; + }, [eventFunnelData]); + + const eventRadialConfig: any = React.useMemo(() => { + return { + data: eventTypeData, + xField: 'type', + yField: 'value', + radius: 0.88, + innerRadius: 0.25, + colorField: 'type', + color: ['#00d4ff', '#00ff88', '#ffb800', '#9d4edd', '#ff4757', '#13c2c2'], + legend: false, + label: { style: { fill: 'rgba(255,255,255,0.72)' } }, + autoFit: true, + }; + }, [eventTypeData]); + + const terminalPieConfig: any = React.useMemo(() => { + const data = terminalPieData || []; + return { + data, + angleField: 'count', + colorField: 'name', + radius: 0.8, + innerRadius: 0.58, + label: { + text: (datum: any) => { + const total = data.reduce((sum, d) => sum + (d.count || 0), 0); + const count = datum?.count ?? 0; + const percent = total > 0 ? ((count / total) * 100).toFixed(0) : '0'; + return `${datum?.name || ''} ${percent}%`; + }, + style: { fill: 'rgba(255,255,255,0.7)' }, + }, + legend: false, + autoFit: true, + }; + }, [terminalPieData]); + + const taskTypeColumnConfig: any = React.useMemo(() => { + return { + data: taskTypeData, + xField: 'type', + yField: 'value', + columnWidthRatio: 0.55, + color: ['#00d4ff'], + label: { style: { fill: 'rgba(255,255,255,0.85)' } }, + xAxis: { label: { style: { fill: 'rgba(255,255,255,0.62)' } } }, + yAxis: { + label: { style: { fill: 'rgba(255,255,255,0.62)' } }, + grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, + }, + legend: false, + autoFit: true, + }; + }, [taskTypeData]); + + const riskRoseConfig: any = React.useMemo(() => { + return { + data: failureAnalysisData, + xField: 'type', + yField: 'value', + seriesField: 'type', + radius: 0.85, + innerRadius: 0.25, + colorField: 'type', + color: ['#ffb800', '#00d4ff', '#00ff88', '#9d4edd', '#ff4757', '#13c2c2'], + label: { + content: (d: any) => `${d.type}\n${d.value}`, + style: { fill: 'rgba(255,255,255,0.72)' }, + }, + legend: false, + autoFit: true, + }; + }, [failureAnalysisData]); + + const annualLineConfig: any = React.useMemo(() => { + return { + data: annualData, + xField: 'month', + yField: 'value', + seriesField: 'type', + smooth: true, + color: ['#00d4ff', '#00ff88'], + areaStyle: { fillOpacity: 0.12 }, + xAxis: { label: { style: { fill: 'rgba(255,255,255,0.62)' } } }, + yAxis: { + label: { style: { fill: 'rgba(255,255,255,0.62)' } }, + grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, + }, + legend: { position: 'top', itemName: { style: { fill: 'rgba(255,255,255,0.72)' } } }, + autoFit: true, + }; + }, [annualData]); + + return ( + + 事件处置与洞察 + + } + className="dashboard-card glass-panel" + size="small" + style={{ height: '100%', minHeight: 0, maxHeight: '100%' }} + styles={{ + header: { flex: '0 0 auto', minHeight: 40, padding: '0 12px', borderBottom: '1px solid rgba(0, 212, 255, 0.1)' }, + body: { flex: 1, padding: 12, overflow: 'hidden', display: 'flex', flexDirection: 'column', minHeight: 0 }, + }} + > + +
+ +
+ + ), + }, + { + key: 'types', + label: '类型分布', + children: ( +
+
+ +
+
+ ), + }, + { + key: 'asset', + label: '资产构成', + children: terminalPieData?.length ? ( +
+
+ +
+
+ ) : ( +
+
+ +
+
+ ), + }, + { + key: 'capacity', + label: '作业结构', + children: taskTypeData?.length ? ( +
+
+ +
+
+ ) : ( +
+
+ +
+
+ ), + }, + { + key: 'risk', + label: '风险画像', + children: failureAnalysisData?.length ? ( +
+
+ +
+
+ ) : ( +
+
+ +
+
+ ), + }, + { + key: 'year', + label: '年度趋势', + children: annualData?.length ? ( +
+
+ +
+
+ ) : ( +
+
+ +
+
+ ), + }, + ]} + /> +
+ ); +}; + +export default EventInsightCard; diff --git a/zlt-web/yingyan/src/pages/dashboard/components/EventStreamCard.tsx b/zlt-web/yingyan/src/pages/dashboard/components/EventStreamCard.tsx new file mode 100644 index 00000000..c989714d --- /dev/null +++ b/zlt-web/yingyan/src/pages/dashboard/components/EventStreamCard.tsx @@ -0,0 +1,93 @@ +import React from 'react'; +import { Card, List, Tag, Empty } from 'antd'; +import { AlertOutlined } from '@ant-design/icons'; + +interface EventItem { + id: string; + title: string; + timeText: string; + location: string; + status: string; + source: string; + desc: string; + severity: string; +} + +interface EventStreamCardProps { + events: EventItem[]; +} + +const severityColor = (severity: string) => { + if (severity === 'critical') return '#ff4757'; + if (severity === 'warning') return '#ffb800'; + return '#00d4ff'; +}; + +const statusTagColor = (status: string) => { + if (status === '已闭环') return '#00ff88'; + if (status === '处理中') return '#9d4edd'; + if (status === '已派单') return '#00d4ff'; + return 'rgba(255,255,255,0.25)'; +}; + +const EventStreamCard: React.FC = ({ events }) => { + return ( + + 城市事件流 + + } + extra={实时} + style={{ + height: '100%', + background: 'rgba(19, 26, 61, 0.7)', + border: '1px solid rgba(0, 212, 255, 0.15)', + borderRadius: 8, + display: 'flex', + flexDirection: 'column', + }} + styles={{ + header: { flex: '0 0 auto', minHeight: 40, padding: '0 12px', borderBottom: '1px solid rgba(0, 212, 255, 0.1)' }, + body: { flex: 1, padding: 12, overflow: 'hidden', display: 'flex', flexDirection: 'column', minHeight: 0 }, + }} + size="small" + > +
+ }} + renderItem={(item) => ( + +
+
+
+
+ {item.title} + {item.timeText} +
+
+ {item.location} + {item.status} + {item.source} +
+
{item.desc}
+
+
+ + )} + /> +
+ + ); +}; + +export default EventStreamCard; diff --git a/zlt-web/yingyan/src/pages/dashboard/components/KpiStrip.tsx b/zlt-web/yingyan/src/pages/dashboard/components/KpiStrip.tsx new file mode 100644 index 00000000..3bca7c6d --- /dev/null +++ b/zlt-web/yingyan/src/pages/dashboard/components/KpiStrip.tsx @@ -0,0 +1,37 @@ +import React from 'react'; +import './card.less'; + +interface KpiItem { + key: string; + label: string; + value: string | number; + unit?: string; + sub?: string; + accent?: string; +} + +interface KpiStripProps { + kpis: KpiItem[]; +} + +const KpiStrip: React.FC = ({ kpis }) => { + return ( +
+ {kpis.map((kpi) => ( +
+
+ {kpi.label} + +
+
+ {kpi.value} + {kpi.unit ? {kpi.unit} : null} +
+ {kpi.sub ?
{kpi.sub}
: null} +
+ ))} +
+ ); +}; + +export default KpiStrip; diff --git a/zlt-web/yingyan/src/pages/dashboard/components/TwinPortal.tsx b/zlt-web/yingyan/src/pages/dashboard/components/TwinPortal.tsx new file mode 100644 index 00000000..4fc21880 --- /dev/null +++ b/zlt-web/yingyan/src/pages/dashboard/components/TwinPortal.tsx @@ -0,0 +1,99 @@ +import React from 'react'; +import { Button, Tag } from 'antd'; +import { SafetyCertificateOutlined, AimOutlined, EnvironmentOutlined } from '@ant-design/icons'; +import { history } from 'umi'; +import './card.less'; + +interface TwinPortalProps { + fleet: { + droneOnline: number; + droneInFlight: number; + dockOnline: number; + }; + airspace: { + complianceIndex: number; + }; + compactLevel: 0 | 1 | 2; +} + +const TwinPortal: React.FC = ({ fleet, airspace, compactLevel }) => { + const goTo3D = () => { + history.push('/map3d?from=dashboard'); + }; + + return ( +
+
+
+
+
+ {compactLevel === 2 ? ( +
+ 事件点位 + AI识别 +
+ ) : ( + <> +
+ 事件点位 + 航线叠加 + 电子围栏 + AI识别 +
+
+ + 安全态势 + + + 空域管理 + + + 数字孪生 + +
+ + )} +
+ +
+
全域数字孪生中枢
+
空地协同巡检 · 城市事件识别 · 应急快速响应
+ +
+ +
+
+ 在线无人机 + {fleet.droneOnline} +
+
+ 在飞架次 + {fleet.droneInFlight} +
+ {compactLevel === 2 ? null : ( + <> +
+ 可用机库 + {fleet.dockOnline} +
+
+ 合规指数 + + {airspace.complianceIndex} + +
+ + )} +
+
+
+ ); +}; + +export default TwinPortal; diff --git a/zlt-web/yingyan/src/pages/dashboard/components/card.less b/zlt-web/yingyan/src/pages/dashboard/components/card.less new file mode 100644 index 00000000..77dc6c44 --- /dev/null +++ b/zlt-web/yingyan/src/pages/dashboard/components/card.less @@ -0,0 +1,733 @@ +/* 组件级样式 - 每个卡片独立管理高度 */ + +.dashboard-card { + height: 100%; + min-height: 0; + max-height: 100%; + display: flex; + flex-direction: column; + background: transparent !important; + border-radius: 8px; + overflow: hidden; + + &.glass-panel { + position: relative; + background: rgba(19, 26, 61, 0.7) !important; + border: 1px solid rgba(0, 212, 255, 0.15) !important; + backdrop-filter: blur(8px); + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); + + &::before { + content: ''; + position: absolute; + inset: 0; + pointer-events: none; + background: + linear-gradient(90deg, rgba(0, 212, 255, 0.6), transparent 60px) top left / 60px 2px no-repeat, + linear-gradient(180deg, rgba(0, 212, 255, 0.6), transparent 60px) top left / 2px 60px no-repeat, + linear-gradient(270deg, rgba(0, 212, 255, 0.6), transparent 60px) top right / 60px 2px no-repeat, + linear-gradient(180deg, rgba(0, 212, 255, 0.6), transparent 60px) top right / 2px 60px no-repeat, + linear-gradient(90deg, rgba(0, 212, 255, 0.6), transparent 60px) bottom left / 60px 2px no-repeat, + linear-gradient(0deg, rgba(0, 212, 255, 0.6), transparent 60px) bottom left / 2px 60px no-repeat, + linear-gradient(270deg, rgba(0, 212, 255, 0.6), transparent 60px) bottom right / 60px 2px no-repeat, + linear-gradient(0deg, rgba(0, 212, 255, 0.6), transparent 60px) bottom right / 2px 60px no-repeat; + opacity: 0.35; + } + } + + :global(.ant-card-head) { + min-height: 40px; + padding: 0 12px; + border-bottom: 1px solid rgba(0, 212, 255, 0.1); + flex: 0 0 auto; + } + + :global(.ant-card-body) { + flex: 1; + padding: 12px; + overflow: hidden; + position: relative; + display: flex; + flex-direction: column; + min-height: 0; + } +} + +/* 事件列表滚动容器 */ +.event-list-scroll { + flex: 1; + min-height: 0; + overflow-x: hidden; + overflow-y: auto; + padding-right: 4px; + + &::-webkit-scrollbar { + width: 4px; + } + + &::-webkit-scrollbar-thumb { + background: rgba(0, 212, 255, 0.22); + border-radius: 2px; + } + + :global(.ant-list) { + height: auto; + } + + :global(.ant-spin-nested-loading), + :global(.ant-spin-container) { + height: auto; + } +} + +/* 通用样式复用 */ +.panel-title { + display: inline-flex; + align-items: center; + gap: 8px; + color: rgba(255, 255, 255, 0.92); + + :global(.anticon) { + color: rgba(0, 212, 255, 0.95); + } +} + +.panel-subtitle { + margin: -2px 0 8px; + font-size: 12px; + color: rgba(255, 255, 255, 0.55); + letter-spacing: 0.2px; +} + +.chart-wrapper { + flex: 1; + width: 100%; + min-height: 0; + overflow: hidden; + + > div { + width: 100%; + height: 100%; + } + + :global(canvas) { + max-width: 100%; + max-height: 100%; + } +} + +/* Tabs 样式 */ +.dash-tabs { + height: 100%; + min-height: 0; + display: flex; + flex-direction: column; + overflow: hidden; + + :global(.ant-tabs-nav) { + margin: 0 0 8px; + flex: 0 0 auto; + } + + :global(.ant-tabs-nav::before) { + border-bottom-color: rgba(0, 212, 255, 0.12); + } + + :global(.ant-tabs-tab) { + color: rgba(255, 255, 255, 0.62); + } + + :global(.ant-tabs-tab.ant-tabs-tab-active .ant-tabs-tab-btn) { + color: rgba(255, 255, 255, 0.92); + } + + :global(.ant-tabs-ink-bar) { + background: rgba(0, 212, 255, 0.9); + } + + :global(.ant-tabs-content-holder) { + flex: 1; + min-height: 0; + overflow: hidden; + } + + :global(.ant-tabs-content) { + height: 100%; + min-height: 0; + } + + :global(.ant-tabs-tabpane) { + height: 100%; + min-height: 0; + padding: 0; + overflow: hidden; + } +} + +.tab-pane { + height: 100%; + min-height: 0; + display: flex; + flex-direction: column; + overflow: hidden; +} + +.empty-holder { + height: 100%; + flex: 1; + min-height: 0; + display: flex; + align-items: center; + justify-content: center; + color: rgba(255, 255, 255, 0.55); +} + +/* 事件列表项样式 */ +.event-item { + padding: 10px 0 !important; + border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important; +} + +.event-item__row { + display: flex; + gap: 10px; + align-items: flex-start; + width: 100%; +} + +.event-item__badge { + width: 8px; + height: 8px; + border-radius: 50%; + margin-top: 6px; + box-shadow: 0 0 12px rgba(0, 0, 0, 0.22); + flex: 0 0 auto; +} + +.event-item__content { + flex: 1; + min-width: 0; +} + +.event-item__head { + display: flex; + justify-content: space-between; + gap: 10px; + margin-bottom: 4px; +} + +.event-item__title { + font-size: 13px; + font-weight: 600; + color: rgba(255, 255, 255, 0.92); + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.event-item__time { + font-size: 12px; + color: rgba(255, 255, 255, 0.55); + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; +} + +.event-item__meta { + display: flex; + flex-wrap: wrap; + gap: 6px; + align-items: center; + margin-bottom: 4px; +} + +.event-item__loc { + font-size: 12px; + color: rgba(255, 255, 255, 0.65); +} + +.event-item__tag { + margin-inline-end: 0 !important; + border: 1px solid rgba(255, 255, 255, 0.12) !important; + color: rgba(255, 255, 255, 0.82) !important; +} + +.event-item__desc { + font-size: 12px; + color: rgba(255, 255, 255, 0.56); + line-height: 1.3; + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + overflow: hidden; +} + +/* 任务筛选器样式 */ +.task-filter { + :global(.ant-segmented) { + background: rgba(0, 212, 255, 0.06); + border: 1px solid rgba(0, 212, 255, 0.18); + } + + :global(.ant-segmented-item-label) { + color: rgba(255, 255, 255, 0.75); + font-size: 12px; + } + + :global(.ant-segmented-item-selected) { + background: rgba(0, 212, 255, 0.22) !important; + } + + :global(.ant-picker) { + background: rgba(0, 212, 255, 0.06); + border: 1px solid rgba(0, 212, 255, 0.18); + color: rgba(255, 255, 255, 0.85); + } + + :global(.ant-picker-input > input) { + color: rgba(255, 255, 255, 0.85); + font-size: 12px; + } + + :global(.ant-picker-suffix) { + color: rgba(255, 255, 255, 0.55); + } +} + +/* Dispatch 样式 */ +.dispatch-grid { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 8px; + flex: 0 0 auto; +} + +.dispatch-stat { + padding: 8px 10px; + border-radius: 10px; + background: rgba(255, 255, 255, 0.04); + border: 1px solid rgba(255, 255, 255, 0.08); +} + +.dispatch-stat__val { + font-size: 18px; + font-weight: 800; + color: rgba(255, 255, 255, 0.92); + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; +} + +.dispatch-stat__lbl { + margin-top: 2px; + font-size: 11px; + color: rgba(255, 255, 255, 0.55); +} + +.dispatch-stat__val--pending { color: rgba(255, 184, 0, 0.92); } +.dispatch-stat__val--running { color: rgba(0, 212, 255, 0.92); } +.dispatch-stat__val--done { color: rgba(0, 255, 136, 0.92); } +.dispatch-stat__val--fail { color: rgba(255, 71, 87, 0.92); } + +.dispatch-highlight { + grid-column: 1 / -1; + padding: 8px 12px; + border-radius: 10px; + border: 1px solid rgba(0, 255, 136, 0.18); + background: + radial-gradient(circle at 20% 20%, rgba(0, 255, 136, 0.12), transparent 55%), + linear-gradient(180deg, rgba(19, 26, 61, 0.78), rgba(10, 14, 39, 0.62)); + display: flex; + align-items: baseline; + justify-content: space-between; +} + +.dispatch-highlight__val { + font-size: clamp(20px, 3vh, 28px); + font-weight: 900; + color: rgba(0, 255, 136, 0.92); + letter-spacing: 1px; +} + +.dispatch-highlight__lbl { + font-size: 11px; + color: rgba(255, 255, 255, 0.60); +} + +.dispatch-trend { + margin-top: 8px; + min-height: 0; + display: flex; + flex-direction: column; + flex: 1; + overflow: hidden; +} + +.dispatch-trend .chart-wrapper { + flex: 1; + min-height: 80px; + padding: 0 4px 4px; + box-sizing: border-box; + overflow: hidden; +} + +.dispatch-trend__title { + margin-bottom: 4px; + font-size: 11px; + color: rgba(255, 255, 255, 0.56); +} + +/* 机队态势样式 */ +.fleet-pane { + gap: 12px; + overflow: hidden; +} + +.fleet-metrics { + display: grid; + grid-template-columns: repeat(4, 1fr); + gap: 12px; +} + +.fleet-metric { + padding: 10px 12px; + border-radius: 12px; + border: 1px solid rgba(255, 255, 255, 0.10); + background: + radial-gradient(circle at 25% 20%, rgba(0, 212, 255, 0.14), transparent 55%), + linear-gradient(180deg, rgba(19, 26, 61, 0.74), rgba(10, 14, 39, 0.62)); +} + +.fleet-metric__label { + font-size: 12px; + color: rgba(255, 255, 255, 0.58); +} + +.fleet-metric__value { + margin-top: 6px; + font-size: 22px; + font-weight: 800; + color: rgba(255, 255, 255, 0.92); + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; +} + +.fleet-metric__sub { + margin-top: 4px; + font-size: 12px; + color: rgba(255, 255, 255, 0.52); +} + +.fleet-split { + flex: 1; + min-height: 0; + display: grid; + grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr); + gap: 12px; +} + +.fleet-split__left, +.fleet-split__right { + min-height: 0; + border-radius: 12px; + border: 1px solid rgba(255, 255, 255, 0.10); + background: rgba(255, 255, 255, 0.03); + padding: 10px 12px; + display: flex; + flex-direction: column; +} + +.region-list { + flex: 1; + min-height: 0; + overflow: hidden; + padding-right: 2px; + + &::-webkit-scrollbar { + width: 4px; + } + + &::-webkit-scrollbar-thumb { + background: rgba(0, 212, 255, 0.18); + border-radius: 2px; + } +} + +.region-item { + padding: 8px 10px 6px; + border-radius: 10px; + background: rgba(255, 255, 255, 0.02); + border: 1px solid rgba(255, 255, 255, 0.06); + margin-bottom: 8px; +} + +.region-item__head { + display: flex; + justify-content: space-between; + align-items: center; + gap: 10px; + margin-bottom: 6px; +} + +.region-item__name { + flex: 1; + min-width: 0; + font-size: 13px; + font-weight: 600; + color: rgba(255, 255, 255, 0.88); + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.region-item__meta { + display: inline-flex; + align-items: center; + gap: 8px; + flex: 0 0 auto; +} + +.region-item__tag { + margin-inline-end: 0 !important; + border: 1px solid rgba(255, 255, 255, 0.12) !important; + color: rgba(255, 255, 255, 0.86) !important; +} + +.region-item__time { + font-size: 12px; + color: rgba(255, 255, 255, 0.55); + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; +} + +.region-item__bar { + display: grid; + grid-template-columns: 1fr auto auto; + align-items: center; + gap: 8px; + + :global(.ant-progress) { + margin: 0; + } +} + +.region-item__pct { + width: 48px; + text-align: right; + font-size: 12px; + color: rgba(255, 255, 255, 0.72); + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; +} + +.region-item__pending { + font-size: 12px; + color: rgba(255, 255, 255, 0.52); + white-space: nowrap; +} + +/* 空域合规样式 */ +.airspace-pane { + gap: 12px; + overflow: hidden; +} + +.airspace-top { + display: grid; + grid-template-columns: 1.1fr 1fr; + gap: 12px; + min-height: 0; +} + +.airspace-score { + display: flex; + align-items: center; + gap: 12px; + padding: 10px 12px; + border-radius: 12px; + border: 1px solid rgba(255, 255, 255, 0.10); + background: + radial-gradient(circle at 18% 24%, rgba(0, 255, 136, 0.10), transparent 55%), + linear-gradient(180deg, rgba(19, 26, 61, 0.72), rgba(10, 14, 39, 0.62)); + + :global(.ant-progress) { + flex: 0 0 auto; + } +} + +.airspace-score__meta { + display: flex; + flex-direction: column; + gap: 4px; + min-width: 0; +} + +.airspace-score__title { + font-size: 14px; + font-weight: 700; + color: rgba(255, 255, 255, 0.9); +} + +.airspace-score__sub { + font-size: 12px; + color: rgba(255, 255, 255, 0.55); +} + +.airspace-metrics { + display: grid; + grid-template-columns: repeat(2, 1fr); + gap: 12px; +} + +.airspace-metric { + padding: 10px 12px; + border-radius: 12px; + border: 1px solid rgba(255, 255, 255, 0.10); + background: rgba(255, 255, 255, 0.03); +} + +.airspace-metric__val { + font-size: 22px; + font-weight: 800; + color: rgba(255, 255, 255, 0.92); + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; +} + +.airspace-metric__lbl { + margin-top: 4px; + font-size: 12px; + color: rgba(255, 255, 255, 0.55); +} + +.airspace-notes { + flex: 1; + min-height: 0; + padding: 10px 12px; + border-radius: 12px; + border: 1px solid rgba(255, 255, 255, 0.10); + background: rgba(255, 255, 255, 0.03); + display: flex; + flex-direction: column; + gap: 10px; +} + +.airspace-note { + display: flex; + gap: 10px; + align-items: flex-start; +} + +.airspace-note__dot { + width: 8px; + height: 8px; + border-radius: 50%; + margin-top: 6px; + background: rgba(0, 212, 255, 0.9); + box-shadow: 0 0 10px rgba(0, 212, 255, 0.25); + flex: 0 0 auto; +} + +.airspace-note__dot--warn { + background: rgba(255, 184, 0, 0.92); + box-shadow: 0 0 10px rgba(255, 184, 0, 0.25); +} + +.airspace-note__dot--ok { + background: rgba(0, 255, 136, 0.92); + box-shadow: 0 0 10px rgba(0, 255, 136, 0.25); +} + +.airspace-note__text { + font-size: 12px; + color: rgba(255, 255, 255, 0.62); + line-height: 1.35; +} + +/* AI快照样式 */ +.snapshot-carousel { + height: 100%; + flex: 1; + min-height: 0; + + :global(.slick-dots) { + bottom: -2px; + } + + :global(.slick-dots li button) { + background: rgba(255, 255, 255, 0.25) !important; + } + + :global(.slick-dots li.slick-active button) { + background: rgba(0, 212, 255, 0.85) !important; + } +} + +.snapshot-grid { + display: grid; + grid-template-columns: repeat(2, 1fr); + gap: 12px; +} + +.snapshot-card { + border-radius: 12px; + padding: 12px 12px 10px; + border: 1px solid rgba(0, 212, 255, 0.16); + background: + radial-gradient(circle at 20% 10%, rgba(0, 212, 255, 0.16), transparent 55%), + linear-gradient(180deg, rgba(19, 26, 61, 0.78), rgba(10, 14, 39, 0.62)); + box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22); + transition: transform 0.18s ease, border-color 0.18s ease; + + &:hover { + transform: translateY(-2px); + border-color: rgba(0, 212, 255, 0.28); + } +} + +.snapshot-card__head { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 8px; +} + +.snapshot-card__tag { + font-size: 12px; + color: rgba(255, 255, 255, 0.72); + padding: 2px 8px; + border-radius: 999px; + background: rgba(0, 212, 255, 0.10); + border: 1px solid rgba(0, 212, 255, 0.18); +} + +.snapshot-card__time { + font-size: 12px; + color: rgba(255, 255, 255, 0.55); + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; +} + +.snapshot-card__title { + font-size: clamp(13px, 1.8vh, 16px); + font-weight: 700; + color: rgba(255, 255, 255, 0.92); + margin-bottom: 6px; +} + +.snapshot-card__meta { + display: flex; + justify-content: space-between; + gap: 10px; + font-size: 12px; + color: rgba(255, 255, 255, 0.62); +} + +.snapshot-card--critical { border-color: rgba(255, 71, 87, 0.26); } +.snapshot-card--warning { border-color: rgba(255, 184, 0, 0.24); } +.snapshot-card--normal { border-color: rgba(0, 212, 255, 0.16); } + +@media (max-width: 1440px) { + .fleet-metrics { + grid-template-columns: repeat(2, 1fr); + } + + .fleet-split { + grid-template-columns: 1fr; + } + + .airspace-top { + grid-template-columns: 1fr; + } +} diff --git a/zlt-web/yingyan/src/pages/dashboard/components/index.ts b/zlt-web/yingyan/src/pages/dashboard/components/index.ts new file mode 100644 index 00000000..02a60cf8 --- /dev/null +++ b/zlt-web/yingyan/src/pages/dashboard/components/index.ts @@ -0,0 +1,7 @@ +export { default as CityVitalCard } from './CityVitalCard'; +export { default as EventStreamCard } from './EventStreamCard'; +export { default as KpiStrip } from './KpiStrip'; +export { default as TwinPortal } from './TwinPortal'; +export { default as DroneInsightCard } from './DroneInsightCard'; +export { default as DispatchCard } from './DispatchCard'; +export { default as EventInsightCard } from './EventInsightCard'; diff --git a/zlt-web/yingyan/src/pages/dashboard/index.legacy.tsx b/zlt-web/yingyan/src/pages/dashboard/index.legacy.tsx new file mode 100644 index 00000000..61d50f63 --- /dev/null +++ b/zlt-web/yingyan/src/pages/dashboard/index.legacy.tsx @@ -0,0 +1,507 @@ +// 旧版通用监控大屏(留档备查) +import React, { useState, useEffect, useCallback, useMemo } from 'react'; +import { Card, Button, List, Tag, Spin, message, DatePicker, Segmented, Space } from 'antd'; +import { + DesktopOutlined, + WarningOutlined, + RocketOutlined, + EnvironmentOutlined, + PieChartOutlined, + FieldTimeOutlined +} from '@ant-design/icons'; +import { Line, Pie, Column, Area, Rose } from '@ant-design/plots'; +import { history } from 'umi'; +import dayjs from 'dayjs'; +import { + getDeviceStats, + getTaskStats, + getTrendData, + getMockAlerts, + DeviceStats, + TaskStats, + TrendItem, + AlertItem, +} from '@/services/dashboard'; +import './index.less'; + +const Dashboard: React.FC = () => { + const [loading, setLoading] = useState(true); + const [deviceStats, setDeviceStats] = useState(null); + const [taskStats, setTaskStats] = useState(null); + const [taskTrend, setTaskTrend] = useState([]); + const [alerts, setAlerts] = useState([]); + const [annualData, setAnnualData] = useState([]); + const [failureAnalysisData, setFailureAnalysisData] = useState([]); + const [taskTypeData, setTaskTypeData] = useState([]); + const [taskStatType, setTaskStatType] = useState<'day' | 'month' | 'year'>('day'); + const [taskStatDate, setTaskStatDate] = useState(dayjs()); + const [tenantId, setTenantId] = useState(); + const [includeChildren, setIncludeChildren] = useState(true); + + useEffect(() => { + // 模拟年度数据 + const mockAnnual: any[] = []; + for (let i = 1; i <= 12; i++) { + mockAnnual.push({ + month: `${i}月`, + value: Math.floor(Math.random() * 500) + 100, + type: '任务总数', + }); + mockAnnual.push({ + month: `${i}月`, + value: Math.floor(Math.random() * 450) + 80, + type: '成功任务', + }); + } + setAnnualData(mockAnnual); + + // 模拟失败原因数据 + setFailureAnalysisData([ + { type: '信号丢失', value: 27 }, + { type: '电池不足', value: 25 }, + { type: '天气原因', value: 18 }, + { type: '机械故障', value: 15 }, + { type: '人为取消', value: 10 }, + { type: '其他', value: 5 }, + ]); + + // 任务类型分布数据 + setTaskTypeData([ + { type: '航线任务', value: 156 }, + { type: '一键起飞', value: 89 }, + { type: '手动控制', value: 45 }, + ]); + }, []); + + useEffect(() => { + const handler = (e: any) => { + const nextTenantId = e?.detail?.tenantId as string | undefined; + const nextIncludeChildren = !!e?.detail?.includeChildren; + setTenantId(nextTenantId); + setIncludeChildren(nextIncludeChildren); + }; + window.addEventListener('tenant-change', handler as any); + return () => window.removeEventListener('tenant-change', handler as any); + }, []); + + const fetchData = useCallback(async () => { + setLoading(true); + try { + const [deviceRes, taskRes, trendRes] = await Promise.all([ + getDeviceStats({ tenantId, includeChildren }), + getTaskStats({ + tenantId, + includeChildren, + statType: taskStatType, + date: + taskStatType === 'day' + ? taskStatDate.format('YYYY-MM-DD') + : taskStatType === 'month' + ? taskStatDate.format('YYYY-MM') + : taskStatDate.format('YYYY'), + }), + getTrendData(7), + ]); + setDeviceStats(deviceRes); + setTaskStats(taskRes); + setTaskTrend(trendRes.taskTrend); + setAlerts(getMockAlerts()); + } catch (error) { + console.error('获取数据失败:', error); + message.error('数据加载异常'); + } finally { + setLoading(false); + } + }, [includeChildren, taskStatDate, taskStatType, tenantId]); + + useEffect(() => { + if (!tenantId) return; + fetchData(); + }, [fetchData]); + + // 定时刷新和时间更新 + useEffect(() => { + const dataTimer = setInterval(fetchData, 30000); + return () => { + clearInterval(dataTimer); + }; + }, [fetchData]); + + const goTo3D = () => { + // 传递来源页面,以便从map3d返回时能回到正确的大屏 + history.push('/map3d?from=dashboard'); + }; + + // --- 图表配置 --- + + const taskTrendSeriesData = useMemo(() => { + return taskTrend.flatMap((t) => [ + { date: t.date, type: '创建', value: t.created || 0 }, + { date: t.date, type: '完成', value: t.completed || 0 }, + { date: t.date, type: '失败', value: t.failed || 0 }, + ]); + }, [taskTrend]); + + // 近7日任务完成数趋势数据 + const taskCompleteTrendData = useMemo(() => { + return taskTrend.map((t) => ({ + date: t.date, + value: t.completed || 0, + })); + }, [taskTrend]); + + const taskTrendConfig: any = { + data: taskTrendSeriesData, + xField: 'date', + yField: 'value', + seriesField: 'type', + smooth: true, + color: ['#00d4ff', '#00ff88', '#ffb800'], + areaStyle: { + fill: 'l(270) 0:#ffffff 0.5:#7ec2f3 1:#1890ff', + fillOpacity: 0.1, + }, + xAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } }, grid: null }, + yAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } }, grid: { line: { style: { stroke: 'rgba(255,255,255,0.1)' } } } }, + tooltip: { showMarkers: true }, + height: 180, + }; + + const pieConfig: any = { + data: deviceStats?.byType || [], + angleField: 'count', + colorField: 'name', + radius: 0.7, + innerRadius: 0.5, + label: { + text: (datum: any) => { + const name = datum?.name || ''; + const count = datum?.count ?? 0; + const data = (deviceStats?.byType || []) as { name: string; count: number }[]; + const total = data.reduce((sum, d) => sum + (d.count || 0), 0); + const percent = total > 0 ? ((count / total) * 100).toFixed(1) : 0; + return `${name} ${percent}%`; + }, + style: { fill: 'rgba(255,255,255,0.65)' }, + }, + legend: { position: 'bottom', itemValue: { style: { fill: 'rgba(255,255,255,0.65)' } }, itemName: { style: { fill: 'rgba(255,255,255,0.65)' } } }, + height: 200, + }; + + const columnConfig: any = { + data: taskTypeData, + xField: 'type', + yField: 'value', + seriesField: 'type', + color: ({ type }: any) => { + if(type === '航线任务') return '#00d4ff'; + if(type === '一键起飞') return '#00ff88'; + return '#ffb800'; + }, + label: { + text: (datum: any) => datum?.value?.toString() || '0', + style: { fill: '#fff' }, + }, + xAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } } }, + yAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } }, grid: { line: { style: { stroke: 'rgba(255,255,255,0.1)' } } } }, + legend: false, + height: 180, + }; + + const taskCompleteTrendConfig: any = { + data: taskCompleteTrendData, + xField: 'date', + yField: 'value', + smooth: true, + color: '#00ff88', + areaStyle: { fillOpacity: 0.15 }, + xAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } }, grid: null }, + yAxis: { + label: { style: { fill: 'rgba(255,255,255,0.65)' } }, + grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, + }, + tooltip: { showMarkers: true }, + height: 160, + }; + + const areaConfig: any = { + data: annualData, + xField: 'month', + yField: 'value', + seriesField: 'type', + color: ['#00d4ff', '#00ff88'], + areaStyle: { fillOpacity: 0.3 }, + xAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } } }, + yAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } }, grid: { line: { style: { stroke: 'rgba(255,255,255,0.1)' } } } }, + legend: { position: 'top-right', itemName: { style: { fill: '#fff' } } }, + smooth: true, + height: 220, + }; + + const roseConfig: any = { + data: failureAnalysisData, + xField: 'type', + yField: 'value', + seriesField: 'type', + radius: 0.9, + label: { + text: (datum: any) => datum?.type || '', + style: { fill: '#fff' }, + }, + legend: { position: 'bottom', itemName: { style: { fill: 'rgba(255,255,255,0.65)' } } }, + height: 200, + }; + + const taskStatusPieConfig: any = { + data: [ + { name: '待执行', value: taskStats?.pending || 0 }, + { name: '执行中', value: taskStats?.running || 0 }, + { name: '已完成', value: taskStats?.completed || 0 }, + { name: '已失败', value: taskStats?.failed || 0 }, + ], + angleField: 'value', + colorField: 'name', + radius: 0.85, + innerRadius: 0.55, + label: { + text: (datum: any) => { + const name = datum?.name || ''; + const value = datum?.value ?? 0; + const total = (taskStats?.pending || 0) + (taskStats?.running || 0) + (taskStats?.completed || 0) + (taskStats?.failed || 0); + const percent = total > 0 ? ((value / total) * 100).toFixed(1) : 0; + return `${name} ${percent}%`; + }, + style: { fill: 'rgba(255,255,255,0.65)' }, + }, + legend: { position: 'bottom', itemValue: { style: { fill: 'rgba(255,255,255,0.65)' } }, itemName: { style: { fill: 'rgba(255,255,255,0.65)' } } }, + height: 190, + }; + + const getAlertColor = (level: string) => { + switch (level) { + case 'critical': return 'red'; + case 'error': return 'orange'; + case 'warning': return 'gold'; + default: return 'blue'; + } + }; + + const taskPeriodText = useMemo(() => { + if (taskStatType === 'day') return '当日'; + if (taskStatType === 'month') return '当月'; + return '当年'; + }, [taskStatType]); + + const taskNewLabel = useMemo(() => { + if (taskStatType === 'day') return '当日任务'; + if (taskStatType === 'month') return '当月任务'; + return '当年任务'; + }, [taskStatType]); + + const datePickerFormat = useMemo(() => { + if (taskStatType === 'day') return 'YYYY-MM-DD'; + if (taskStatType === 'month') return 'YYYY-MM'; + return 'YYYY'; + }, [taskStatType]); + + return ( +
+
+ + +
+
+ + {/* 左侧栏:设备态势 */} +
+ +
+ +
+
+ + +
+ +
+
+ + +
+ +
+
+ + 实时告警} + className="panel-card glass-panel flex-grow" + size="small" + extra={Live} + > +
+ ( + +
+
+ {item.level.toUpperCase().slice(0,1)} +
+
+
+ {item.deviceName || item.taskName} + {dayjs(item.timestamp).format('HH:mm')} +
+
{item.message}
+
+
+
+ )} + /> +
+
+
+ + {/* 中间栏:核心监控 */} +
+ {/* 顶部KPI */} +
+
+
+
+
设备总数
+
{deviceStats?.total || 0}
+
+
+
+
+
+
景区总数
+
{deviceStats?.tourismCount || 0}
+
+
+
+
+
+
{taskNewLabel}
+
{taskStats?.todayNew || 0}
+
+
+
+
+
+
执行成功率
+
{taskStats?.successRate || 0}%
+
+
+
+ + {/* 地图/3D入口 */} +
+
+
+
+
+ +

全域数字孪生监控中心

+ +
+
+
+ + {/* 底部年度统计 */} + +
+ +
+
+
+ + {/* 右侧栏:任务与运维 */} +
+ + setTaskStatType(v as any)} + /> + v && setTaskStatDate(v)} + picker={taskStatType === 'day' ? 'date' : taskStatType} + allowClear={false} + format={datePickerFormat} + disabledDate={(d) => !!d && d.isAfter(dayjs(), 'day')} + /> + + } + > +
+
+
{taskStats?.pending || 0}
+
待执行
+
+
+
{taskStats?.running || 0}
+
执行中
+
+
+
{taskStats?.completed || 0}
+
已完成
+
+
+
{taskStats?.failed || 0}
+
已失败
+
+
+
+
+ {taskStats?.successRate || 0}% +
+
+ {taskPeriodText}成功率 +
+
+
+ + +
+ +
+
+ + +
+ +
+
+ + +
+ +
+
+
+ +
+
+
+
+ ); +}; + +export default Dashboard; diff --git a/zlt-web/yingyan/src/pages/dashboard/index.less b/zlt-web/yingyan/src/pages/dashboard/index.less index 6c0dfc83..7278d281 100644 --- a/zlt-web/yingyan/src/pages/dashboard/index.less +++ b/zlt-web/yingyan/src/pages/dashboard/index.less @@ -1,10 +1,24 @@ +/* Dashboard 主布局样式 - 仅处理页面级布局 */ + +/* Spin wrapper 样式 - 确保不影响高度 */ +:global(.dashboard-spin-wrapper) { + height: 100%; + + :global(.ant-spin-nested-loading), + :global(.ant-spin-container) { + height: 100%; + min-height: 0; + } +} + .dashboard-page { position: relative; width: 100%; height: 100%; + --dash-frame-h: clamp(14px, 2vh, 22px); + --dash-frame-gap: clamp(4px, 0.6vh, 8px); background: var(--bg-primary); - overflow-x: hidden; - overflow-y: hidden; + overflow: hidden; display: flex; flex-direction: column; flex: 1; @@ -25,7 +39,7 @@ .dashboard-bg-animation { position: absolute; inset: 0; - background-image: + background-image: linear-gradient(rgba(0, 212, 255, 0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 212, 255, 0.05) 1px, transparent 1px); background-size: 40px 40px; @@ -35,7 +49,6 @@ } } -/* Main Content Grid */ .dashboard-spin { height: 100%; display: block; @@ -54,53 +67,122 @@ } } -.dashboard-page::-webkit-scrollbar { - width: 6px; -} - -.dashboard-page::-webkit-scrollbar-thumb { - background: rgba(0, 212, 255, 0.18); - border-radius: 3px; -} - - .dashboard-content { flex: 1; - padding: 16px 18px; - overflow-x: hidden; - overflow-y: hidden; + padding: 12px 16px; + padding-bottom: calc(10px + var(--dash-frame-h) + var(--dash-frame-gap)); + overflow: hidden; position: relative; z-index: 1; min-height: 0; - display: flex; - flex-direction: column; + display: grid; + grid-template-rows: 1fr; box-sizing: border-box; } -/* 说明:通用大屏不做“整体缩放舞台”,避免在不同浏览器/缩放下出现渲染空白; - 屏幕适配沿用海事首页的思路:固定 100% 高度链路 + 内部网格自适应压缩。 */ +.dashboard-bottom-frame { + position: absolute; + left: clamp(12px, 1.6vw, 24px); + right: clamp(12px, 1.6vw, 24px); + bottom: clamp(6px, 0.8vh, 12px); + height: var(--dash-frame-h); + border-radius: 12px; + z-index: 2; + pointer-events: none; + background: + linear-gradient( + 90deg, + rgba(0, 212, 255, 0.08), + rgba(0, 212, 255, 0.65) 32%, + rgba(0, 255, 136, 0.55) 50%, + rgba(0, 212, 255, 0.65) 68%, + rgba(0, 212, 255, 0.08) + ) bottom/100% 2px no-repeat, + linear-gradient(90deg, rgba(0, 212, 255, 0.85), transparent 90px) bottom left/90px 2px no-repeat, + linear-gradient(270deg, rgba(0, 212, 255, 0.85), transparent 90px) bottom right/90px 2px no-repeat, + linear-gradient(180deg, rgba(0, 212, 255, 0.6), transparent 80%) bottom left/2px 100% no-repeat, + linear-gradient(180deg, rgba(0, 212, 255, 0.6), transparent 80%) bottom right/2px 100% no-repeat; + filter: drop-shadow(0 -6px 16px rgba(0, 212, 255, 0.2)); + &::before { + content: ''; + position: absolute; + left: 50%; + bottom: 6px; + width: clamp(120px, 18vw, 220px); + height: 6px; + transform: translateX(-50%); + border-radius: 999px; + background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.85), transparent); + box-shadow: 0 0 12px rgba(0, 212, 255, 0.4); + opacity: 0.85; + } +} + +/* 三列网格布局 */ .dashboard-grid { display: grid; grid-template-columns: minmax(0, 25%) minmax(0, 50%) minmax(0, 25%); - grid-template-rows: minmax(0, 1fr); + grid-template-rows: 1fr; gap: 14px; - flex: 1; min-height: 0; height: 100%; width: 100%; } +/* 核心:每列使用CSS Grid强制分配高度 */ .grid-col { - display: flex; - flex-direction: column; - gap: 16px; + display: grid; + gap: 12px; height: 100%; min-height: 0; - overflow: visible; + overflow: hidden; } -/* 宽度自适应:根据屏幕宽度逐级重排,避免笔记本/小屏左右被挤爆 */ +/* 左侧列:两个卡片各占50% */ +.grid-col.left-col { + grid-template-rows: 1fr 1fr; +} + +/* 中间列:KPI固定 + 两个卡片各占剩余空间的50% */ +.grid-col.center-col { + grid-template-rows: auto 1fr 1fr; +} + +/* 右侧列:40%和60%分配 */ +.grid-col.right-col { + grid-template-rows: 2fr 3fr; +} + +/* 所有Grid子元素必须遵守高度约束 */ +.grid-col > * { + min-height: 0; + max-height: 100%; + overflow: hidden; +} + +/* SmartCity 主题变量 */ +.dashboard-page--smartcity { + font-size: clamp(12px, 1.15vh, 14px); + --dash-pad-x: clamp(8px, 1.0vw, 14px); + --dash-pad-y: clamp(6px, 0.7vh, 10px); + --dash-gap: clamp(6px, 0.8vw, 10px); + + .dashboard-content { + padding: var(--dash-pad-y) var(--dash-pad-x); + padding-bottom: calc(var(--dash-pad-y) + var(--dash-frame-h) + var(--dash-frame-gap)); + } + + .dashboard-grid { + gap: var(--dash-gap); + } + + .grid-col { + gap: var(--dash-gap); + } +} + +/* 响应式布局 */ @media (max-width: 1680px) { .dashboard-grid { grid-template-columns: minmax(0, 28%) minmax(0, 44%) minmax(0, 28%); @@ -114,522 +196,54 @@ } } -/* 说明:大屏场景保持三列结构,不做“改列/改行”的重排,避免造成视觉割裂与高度不可控。 */ - -.dashboard-page--smartcity { - /* 以视口为基准的密度系统:不写死屏幕尺寸,随窗口自动收缩/放大 */ - font-size: clamp(12px, 1.15vh, 14px); - --dash-pad-x: clamp(8px, 1.0vw, 14px); - --dash-pad-y: clamp(6px, 0.7vh, 10px); - --dash-gap: clamp(6px, 0.8vw, 10px); - --dash-head-h: clamp(28px, 3.1vh, 34px); - --dash-body-pad: clamp(6px, 0.8vh, 9px); - --dash-kpi-h: clamp(50px, 6.4vh, 76px); - --dash-kpi-num: clamp(16px, 2.4vh, 24px); - --dash-title: clamp(20px, 2.8vh, 24px); - --dash-sub: clamp(11px, 1.4vh, 12px); - - /* 关键:用变量控制“上大框/下内容”高度配比,随屏幕高度自动调整,不需要按某个分辨率写死 */ - --left-top-flex: 0.82; - --left-bottom-flex: 1.58; - --center-portal-flex: 1.18; - --center-bottom-flex: 1.62; - - .dashboard-content { - padding: var(--dash-pad-y) var(--dash-pad-x); - } - - .dashboard-grid { - gap: var(--dash-gap); - } - - .grid-col { - display: flex; - flex-direction: column; - gap: var(--dash-gap); - min-height: 0; - } - - .left-col, - .center-col, - .right-col { - min-height: 0; - } - - .panel-card, - .chart-wrapper { - min-height: 0; - } - - .panel-card :global(.ant-card-head) { - min-height: var(--dash-head-h); - } - - .panel-card :global(.ant-card-body) { - padding: var(--dash-body-pad); - } - - /* 按列控制高度配比:压缩上半区,给下半区留出空间,避免底部卡片“看不见” */ - .left-col .panel-card--left-tabs { flex: var(--left-top-flex); min-height: 0; } - .left-col .panel-card--events { flex: var(--left-bottom-flex); min-height: 0; } - - .center-col .kpi-strip { flex: 0 0 var(--dash-kpi-h); } - .center-col .twin-portal { flex: var(--center-portal-flex); min-height: 0; } - .center-col .panel-card--snap { flex: var(--center-bottom-flex); min-height: 0; } - - .right-col .panel-card--dispatch { flex: 1.1; } - .right-col .panel-card--right-tabs { flex: 1.9; } -} - - -/* 小屏/系统缩放下做“密度压缩”,避免底部裁切(不做整体缩放) */ +/* 小屏高度适配 */ @media (max-height: 900px) { .dashboard-page--smartcity { - overflow-y: hidden; - - /* 仅通过变量压缩密度,避免“写死高度”在不同电脑上失真 */ --dash-pad-x: clamp(8px, 0.9vw, 12px); --dash-pad-y: clamp(4px, 0.6vh, 8px); --dash-gap: clamp(6px, 0.7vw, 9px); - --dash-head-h: clamp(28px, 3.0vh, 34px); - --dash-body-pad: clamp(6px, 0.8vh, 9px); - --dash-kpi-h: clamp(44px, 5.8vh, 66px); - --dash-kpi-num: clamp(14px, 2.0vh, 20px); - --dash-title: clamp(18px, 2.4vh, 22px); - - /* 小高度:进一步压缩“城市体征/孪生中枢”,确保底部卡片可见 */ - --left-top-flex: 0.68; - --left-bottom-flex: 1.72; - --center-portal-flex: 0.92; - --center-bottom-flex: 1.88; - } - - .panel-card :global(.ant-card-head) { - min-height: 36px; - } - - .panel-card :global(.ant-card-body) { - padding: 10px; + --dash-frame-h: clamp(12px, 1.8vh, 18px); + --dash-frame-gap: clamp(3px, 0.5vh, 6px); } } -@media (max-height: 760px) { - .dashboard-page--smartcity { - --dash-kpi-h: clamp(42px, 5.4vh, 60px); - --left-top-flex: 0.60; - --left-bottom-flex: 1.80; - --center-portal-flex: 0.80; - --center-bottom-flex: 2.00; +/* 紧凑模式 */ +.dashboard-page--compact-1 { + .grid-col { + gap: 8px; } } -/* Panel Card Styles */ -.panel-card { - background: transparent !important; - border-radius: 8px; - display: flex; - flex-direction: column; - - &.glass-panel { - position: relative; - background: rgba(19, 26, 61, 0.7) !important; - border: 1px solid rgba(0, 212, 255, 0.15) !important; - backdrop-filter: blur(8px); - box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); - overflow: hidden; - - &::before { - content: ''; - position: absolute; - inset: 0; - pointer-events: none; - background: - linear-gradient(90deg, rgba(0, 212, 255, 0.6), transparent 60px) top left / 60px 2px no-repeat, - linear-gradient(180deg, rgba(0, 212, 255, 0.6), transparent 60px) top left / 2px 60px no-repeat, - linear-gradient(270deg, rgba(0, 212, 255, 0.6), transparent 60px) top right / 60px 2px no-repeat, - linear-gradient(180deg, rgba(0, 212, 255, 0.6), transparent 60px) top right / 2px 60px no-repeat, - linear-gradient(90deg, rgba(0, 212, 255, 0.6), transparent 60px) bottom left / 60px 2px no-repeat, - linear-gradient(0deg, rgba(0, 212, 255, 0.6), transparent 60px) bottom left / 2px 60px no-repeat, - linear-gradient(270deg, rgba(0, 212, 255, 0.6), transparent 60px) bottom right / 60px 2px no-repeat, - linear-gradient(0deg, rgba(0, 212, 255, 0.6), transparent 60px) bottom right / 2px 60px no-repeat; - opacity: 0.35; - } +.dashboard-page--compact-2 { + .grid-col { + gap: 6px; } - :global(.ant-card-head) { - min-height: 40px; - padding: 0 12px; - border-bottom: 1px solid rgba(0, 212, 255, 0.1); - - .ant-card-head-title { - font-size: 15px; - color: #fff; - padding: 8px 0; - } - } - - :global(.ant-card-body) { - flex: 1; - padding: 12px; - overflow: hidden; - position: relative; - display: flex; - flex-direction: column; - } -} - -.chart-wrapper { - flex: 1; - width: 100%; - position: relative; - min-height: 0; /* Important for flex child */ - - > div { - height: 100% !important; - } -} - -.flex-grow { - flex: 1; -} - -.fill-bottom { - flex: 1; -} - -/* Alert List */ -.alert-list-container { - height: 100%; - overflow: hidden; - - &::-webkit-scrollbar { - width: 4px; - } - &::-webkit-scrollbar-thumb { - background: rgba(0, 212, 255, 0.2); - border-radius: 2px; - } -} - -.alert-item { - padding: 8px 0 !important; - border-bottom: 1px solid rgba(255,255,255,0.05) !important; - - .alert-row { - display: flex; - width: 100%; - align-items: flex-start; - - .alert-badge { - margin-right: 8px; - margin-top: 2px; - } - - .alert-content { - flex: 1; - - .alert-head { - display: flex; - justify-content: space-between; - margin-bottom: 2px; - - .alert-name { color: #fff; font-weight: 500; font-size: 13px; } - .alert-time { color: var(--accent-blue); font-size: 12px; font-family: monospace; } - } - - .alert-msg { - color: rgba(255,255,255,0.6); - font-size: 12px; - line-height: 1.2; - } - } - } -} - -/* Center Column Specifics */ -.kpi-row { - display: grid; - grid-template-columns: repeat(4, 1fr); - gap: 12px; - height: 80px; -} - -.kpi-card { - background: rgba(19, 26, 61, 0.7); - border: 1px solid rgba(0, 212, 255, 0.15); - border-radius: 6px; - display: flex; - align-items: center; - padding: 0 16px; - - .kpi-icon { - font-size: 24px; - margin-right: 12px; - width: 40px; - height: 40px; - border-radius: 50%; - display: flex; - align-items: center; - justify-content: center; - background: rgba(255,255,255,0.05); - - &.blue { color: #00d4ff; box-shadow: 0 0 10px rgba(0, 212, 255, 0.2); } - &.green { color: #00ff88; box-shadow: 0 0 10px rgba(0, 255, 136, 0.2); } - &.yellow { color: #ffb800; box-shadow: 0 0 10px rgba(255, 184, 0, 0.2); } - &.purple { color: #9d4edd; box-shadow: 0 0 10px rgba(157, 78, 221, 0.2); } - } - - .kpi-info { - .label { font-size: 12px; color: rgba(255,255,255,0.6); } - .value { font-size: 24px; font-weight: bold; color: #fff; font-family: 'Segoe UI', sans-serif; line-height: 1.2; } - small { font-size: 14px; margin-left: 2px; } - } -} - -.map-portal-wrapper { - flex: 2; /* Occupy most space */ - position: relative; - background: rgba(0,0,0,0.2); - border: 1px solid rgba(0, 212, 255, 0.3); - border-radius: 12px; - overflow: hidden; - display: flex; - justify-content: center; - align-items: center; - - /* Grid Background */ - .map-bg-grid { - position: absolute; - inset: 0; - background-image: - linear-gradient(rgba(0, 212, 255, 0.2) 1px, transparent 1px), - linear-gradient(90deg, rgba(0, 212, 255, 0.2) 1px, transparent 1px); - background-size: 80px 80px; - perspective: 1000px; - transform: perspective(500px) rotateX(20deg) scale(1.5); - opacity: 0.3; - animation: gridMove 20s linear infinite; - } - - .map-content { - position: relative; - z-index: 3; - display: flex; - justify-content: center; - align-items: center; - } - - .radar-sweep { - position: absolute; - inset: 0; - z-index: 2; - pointer-events: none; - display: flex; - align-items: center; - justify-content: center; - - &::before { - content: ''; - width: 520px; - height: 520px; - border-radius: 50%; - background: - repeating-radial-gradient(circle, rgba(0, 212, 255, 0.22) 0 1px, transparent 1px 28px), - radial-gradient(circle, rgba(0, 212, 255, 0.18), transparent 62%), - radial-gradient(circle, rgba(0, 255, 136, 0.10), transparent 70%); - filter: drop-shadow(0 0 18px rgba(0, 212, 255, 0.25)); - opacity: 0.55; - } - - &::after { - content: ''; - position: absolute; - width: 520px; - height: 520px; - border-radius: 50%; - background: conic-gradient( - from 0deg, - rgba(0, 212, 255, 0.00) 0deg, - rgba(0, 212, 255, 0.28) 18deg, - rgba(0, 212, 255, 0.06) 45deg, - rgba(0, 212, 255, 0.00) 75deg, - rgba(0, 212, 255, 0.00) 360deg - ); - mix-blend-mode: screen; - animation: radarRotate 2.8s linear infinite; - opacity: 0.9; - } - } - - .portal-center { - text-align: center; - width: 340px; - height: 340px; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - background: rgba(10, 14, 39, 0.78); - padding: 0 34px; - border-radius: 50%; - border: 1px solid var(--accent-blue); - box-shadow: 0 0 30px rgba(0, 212, 255, 0.2); - backdrop-filter: blur(5px); - position: relative; - overflow: hidden; - - &::before { - content: ''; - position: absolute; - inset: 10px; - border-radius: 50%; - background: - radial-gradient(circle at 30% 30%, rgba(0, 212, 255, 0.22), transparent 45%), - radial-gradient(circle at 70% 70%, rgba(0, 255, 136, 0.12), transparent 50%); - opacity: 0.6; - pointer-events: none; - } - - .portal-title { - color: #fff; - margin-bottom: 24px; - font-size: 22px; - letter-spacing: 2px; - text-shadow: 0 0 10px var(--accent-blue); - } - - .portal-btn { - height: 44px; - padding: 0 32px; - font-size: 16px; - background: linear-gradient(90deg, #00d4ff, #007aff); - border: none; - box-shadow: 0 4px 15px rgba(0, 212, 255, 0.4); - transition: all 0.3s; - - &:hover { - transform: translateY(-2px); - box-shadow: 0 8px 25px rgba(0, 212, 255, 0.6); - } - } - } -} - -.task-filter { - :global(.ant-segmented) { - background: rgba(0, 212, 255, 0.06); - border: 1px solid rgba(0, 212, 255, 0.18); - } - - :global(.ant-segmented-item-label) { - color: rgba(255, 255, 255, 0.75); - font-size: 12px; - } - - :global(.ant-segmented-item-selected) { - background: rgba(0, 212, 255, 0.22) !important; - } - - :global(.ant-picker) { - background: rgba(0, 212, 255, 0.06); - border: 1px solid rgba(0, 212, 255, 0.18); - color: rgba(255, 255, 255, 0.85); - } - - :global(.ant-picker-input > input) { - color: rgba(255, 255, 255, 0.85); - font-size: 12px; - } - - :global(.ant-picker-suffix) { - color: rgba(255, 255, 255, 0.55); - } -} - -/* Right Column */ -.task-overview-grid { - display: grid; - grid-template-columns: 1fr 1fr; - gap: 8px; - - .task-stat-box { - background: rgba(255,255,255,0.03); - padding: 8px; - text-align: center; - border-radius: 4px; - - .val { font-size: 18px; font-weight: bold; color: #fff; } - .lbl { font-size: 11px; color: rgba(255,255,255,0.5); } - - .val.pending { color: var(--accent-yellow); } - .val.running { color: var(--accent-blue); } - .val.completed { color: var(--accent-green); } - .val.failed { color: var(--accent-red); } - } -} - -/* Smart City New UI */ -.panel-title { - display: inline-flex; - align-items: center; - gap: 8px; - color: rgba(255, 255, 255, 0.92); - - :global(.anticon) { - color: rgba(0, 212, 255, 0.95); - } -} - -.panel-subtitle { - margin: -2px 0 8px; - font-size: var(--dash-sub, 12px); - color: rgba(255, 255, 255, 0.55); - letter-spacing: 0.2px; -} - -.panel-card--tight { - :global(.ant-card-body) { - padding-top: 10px; + .grid-col.center-col { + grid-template-rows: auto 1fr 1fr; } } +/* KPI Strip 样式 */ .kpi-strip { display: grid; grid-template-columns: repeat(5, 1fr); - gap: var(--dash-gap, 10px); - height: var(--dash-kpi-h, 96px); + gap: 10px; + height: auto; + min-height: 60px; + max-height: 80px; } .kpi-tile { position: relative; border-radius: 10px; - padding: 12px 14px; + padding: 10px 12px; border: 1px solid rgba(0, 212, 255, 0.14); background: radial-gradient(circle at 20% 20%, rgba(0, 212, 255, 0.18), transparent 52%), linear-gradient(180deg, rgba(19, 26, 61, 0.86), rgba(10, 14, 39, 0.74)); box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22); overflow: hidden; - transition: transform 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease; - - &:hover { - transform: translateY(-2px); - border-color: rgba(0, 212, 255, 0.26); - box-shadow: 0 14px 30px rgba(0, 0, 0, 0.28); - } - - &::after { - content: ''; - position: absolute; - top: -60%; - left: -40%; - width: 120%; - height: 120%; - background: radial-gradient(circle, rgba(255, 255, 255, 0.10), transparent 55%); - transform: rotate(18deg); - opacity: 0.45; - pointer-events: none; - } .kpi-tile__head { display: flex; @@ -640,7 +254,6 @@ .kpi-tile__label { font-size: 12px; color: rgba(255, 255, 255, 0.64); - letter-spacing: 0.4px; } .kpi-tile__dot { @@ -652,19 +265,18 @@ } .kpi-tile__value { - margin-top: 6px; + margin-top: 4px; display: inline-flex; align-items: baseline; - gap: 6px; + gap: 4px; } .kpi-tile__num { - font-size: var(--dash-kpi-num, 28px); + font-size: clamp(16px, 2.2vh, 24px); line-height: 1.1; font-weight: 700; color: rgba(255, 255, 255, 0.92); - font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; - text-shadow: 0 0 18px rgba(0, 212, 255, 0.18); + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; } .kpi-tile__unit { @@ -673,8 +285,8 @@ } .kpi-tile__sub { - margin-top: 4px; - font-size: 12px; + margin-top: 2px; + font-size: 11px; color: rgba(255, 255, 255, 0.52); } } @@ -684,17 +296,20 @@ .kpi-tile--red .kpi-tile__dot { background: rgba(255, 71, 87, 0.92); box-shadow: 0 0 12px rgba(255, 71, 87, 0.26); } .kpi-tile--purple .kpi-tile__dot { background: rgba(157, 78, 221, 0.92); box-shadow: 0 0 12px rgba(157, 78, 221, 0.26); } +/* Twin Portal 样式 */ .twin-portal { - flex: 2; position: relative; border-radius: 14px; border: 1px solid rgba(0, 212, 255, 0.28); overflow: hidden; + min-height: 0; + height: 100%; background: radial-gradient(circle at 30% 20%, rgba(0, 212, 255, 0.18), transparent 55%), radial-gradient(circle at 80% 70%, rgba(0, 255, 136, 0.10), transparent 60%), linear-gradient(180deg, rgba(6, 10, 24, 0.85), rgba(10, 14, 39, 0.62)); - box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28); + box-shadow: 0 12px 22px rgba(0, 0, 0, 0.22); + --twin-sweep-size: clamp(200px, 35vh, 400px); } .twin-portal__grid { @@ -713,22 +328,20 @@ position: absolute; inset: 0; pointer-events: none; - opacity: 0.9; + opacity: 0.78; &::before { content: ''; position: absolute; left: 50%; top: 50%; - width: 520px; - height: 520px; + width: var(--twin-sweep-size); + height: var(--twin-sweep-size); transform: translate(-50%, -50%); border-radius: 50%; background: repeating-radial-gradient(circle, rgba(0, 212, 255, 0.22) 0 1px, transparent 1px 28px), - radial-gradient(circle, rgba(0, 212, 255, 0.16), transparent 62%), - radial-gradient(circle, rgba(0, 255, 136, 0.10), transparent 70%); - filter: drop-shadow(0 0 18px rgba(0, 212, 255, 0.20)); + radial-gradient(circle, rgba(0, 212, 255, 0.16), transparent 62%); opacity: 0.6; } @@ -737,8 +350,8 @@ position: absolute; left: 50%; top: 50%; - width: 520px; - height: 520px; + width: var(--twin-sweep-size); + height: var(--twin-sweep-size); transform: translate(-50%, -50%); border-radius: 50%; background: conic-gradient( @@ -749,7 +362,6 @@ rgba(0, 212, 255, 0.00) 75deg, rgba(0, 212, 255, 0.00) 360deg ); - mix-blend-mode: screen; animation: radarRotate 2.8s linear infinite; opacity: 0.95; } @@ -759,7 +371,7 @@ position: relative; z-index: 2; height: 100%; - padding: var(--dash-body-pad, 10px); + padding: 10px; display: flex; flex-direction: column; justify-content: space-between; @@ -804,11 +416,10 @@ .twin-portal__center { text-align: center; - margin-top: 4px; } .twin-portal__title { - font-size: var(--dash-title, 24px); + font-size: clamp(18px, 2.5vh, 24px); font-weight: 700; letter-spacing: 2px; color: rgba(255, 255, 255, 0.94); @@ -816,33 +427,25 @@ } .twin-portal__desc { - margin-top: 6px; - font-size: clamp(12px, 1.5vh, 13px); + margin-top: 4px; + font-size: clamp(11px, 1.3vh, 13px); color: rgba(255, 255, 255, 0.65); - letter-spacing: 0.6px; } .twin-portal__btn { - margin-top: 10px; - height: clamp(32px, 3.8vh, 38px); - padding: 0 clamp(16px, 2.0vw, 30px); - font-size: clamp(12px, 1.6vh, 14px); + margin-top: 8px; + height: clamp(28px, 3.5vh, 36px); + padding: 0 clamp(14px, 1.8vw, 28px); + font-size: clamp(11px, 1.4vh, 14px); background: linear-gradient(90deg, #00d4ff, #007aff) !important; border: none !important; box-shadow: 0 10px 24px rgba(0, 212, 255, 0.25); - transition: transform 0.25s ease, box-shadow 0.25s ease; - - &:hover { - transform: translateY(-1px); - box-shadow: 0 14px 32px rgba(0, 212, 255, 0.34); - } } .twin-portal__bottom { display: grid; grid-template-columns: repeat(4, 1fr); - gap: var(--dash-gap, 10px); - margin-top: 6px; + gap: 8px; } .mini-metric { @@ -852,698 +455,38 @@ border: 1px solid rgba(255, 255, 255, 0.08); display: flex; flex-direction: column; - gap: 4px; + gap: 2px; } .mini-metric__label { - font-size: 12px; + font-size: 11px; color: rgba(255, 255, 255, 0.55); } .mini-metric__value { - font-size: clamp(14px, 2.0vh, 18px); + font-size: clamp(13px, 1.8vh, 18px); font-weight: 700; color: rgba(255, 255, 255, 0.90); - font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; } .mini-metric__value--warn { color: rgba(255, 184, 0, 0.92); } -.panel-card--snap { - :global(.ant-card-body) { - padding: 10px 12px 12px; - } -} - -.snapshot-carousel { - height: 100%; - flex: 1; - min-height: 0; - - :global(.slick-dots) { - bottom: -2px; - } - - :global(.slick-dots li button) { - background: rgba(255, 255, 255, 0.25) !important; - } - - :global(.slick-dots li.slick-active button) { - background: rgba(0, 212, 255, 0.85) !important; - } -} - -.snapshot-grid { - display: grid; - grid-template-columns: repeat(2, 1fr); - gap: var(--dash-gap, 12px); -} - -.snapshot-card { - border-radius: 12px; - padding: 12px 12px 10px; - border: 1px solid rgba(0, 212, 255, 0.16); - background: - radial-gradient(circle at 20% 10%, rgba(0, 212, 255, 0.16), transparent 55%), - linear-gradient(180deg, rgba(19, 26, 61, 0.78), rgba(10, 14, 39, 0.62)); - box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22); - transition: transform 0.18s ease, border-color 0.18s ease; - - &:hover { - transform: translateY(-2px); - border-color: rgba(0, 212, 255, 0.28); - } -} - -.snapshot-card__head { - display: flex; - justify-content: space-between; - align-items: center; - margin-bottom: 8px; -} - -.snapshot-card__tag { - font-size: 12px; - color: rgba(255, 255, 255, 0.72); - padding: 2px 8px; - border-radius: 999px; - background: rgba(0, 212, 255, 0.10); - border: 1px solid rgba(0, 212, 255, 0.18); -} - -.snapshot-card__time { - font-size: 12px; - color: rgba(255, 255, 255, 0.55); - font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; -} - -.snapshot-card__title { - font-size: clamp(13px, 1.8vh, 16px); - font-weight: 700; - color: rgba(255, 255, 255, 0.92); - margin-bottom: 6px; -} - -.snapshot-card__meta { - display: flex; - justify-content: space-between; - gap: 10px; - font-size: 12px; - color: rgba(255, 255, 255, 0.62); -} - -.snapshot-card--critical { border-color: rgba(255, 71, 87, 0.26); } -.snapshot-card--warning { border-color: rgba(255, 184, 0, 0.24); } -.snapshot-card--normal { border-color: rgba(0, 212, 255, 0.16); } - -/* 机队态势 */ -.fleet-pane { - gap: var(--dash-gap, 12px); -} - -.fleet-metrics { - display: grid; - grid-template-columns: repeat(4, 1fr); - gap: var(--dash-gap, 12px); -} - -.fleet-metric { - padding: 10px 12px; - border-radius: 12px; - border: 1px solid rgba(255, 255, 255, 0.10); - background: - radial-gradient(circle at 25% 20%, rgba(0, 212, 255, 0.14), transparent 55%), - linear-gradient(180deg, rgba(19, 26, 61, 0.74), rgba(10, 14, 39, 0.62)); -} - -.fleet-metric__label { - font-size: 12px; - color: rgba(255, 255, 255, 0.58); -} - -.fleet-metric__value { - margin-top: 6px; - font-size: 22px; - font-weight: 800; - color: rgba(255, 255, 255, 0.92); - font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; -} - -.fleet-metric__sub { - margin-top: 4px; - font-size: 12px; - color: rgba(255, 255, 255, 0.52); -} - -.fleet-split { - flex: 1; - min-height: 0; - display: grid; - grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr); - gap: var(--dash-gap, 12px); -} - -.fleet-split__left, -.fleet-split__right { - min-height: 0; - border-radius: 12px; - border: 1px solid rgba(255, 255, 255, 0.10); - background: rgba(255, 255, 255, 0.03); - padding: 10px 12px; - display: flex; - flex-direction: column; -} - -.region-list { - flex: 1; - min-height: 0; - overflow: hidden; - padding-right: 2px; - - &::-webkit-scrollbar { - width: 4px; - } - - &::-webkit-scrollbar-thumb { - background: rgba(0, 212, 255, 0.18); - border-radius: 2px; - } -} - -.region-item { - padding: 8px 10px 6px; - border-radius: 10px; - background: rgba(255, 255, 255, 0.02); - border: 1px solid rgba(255, 255, 255, 0.06); - margin-bottom: 8px; -} - -.region-item__head { - display: flex; - justify-content: space-between; - align-items: center; - gap: 10px; - margin-bottom: 6px; -} - -.region-item__name { - flex: 1; - min-width: 0; - font-size: 13px; - font-weight: 600; - color: rgba(255, 255, 255, 0.88); - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} - -.region-item__meta { - display: inline-flex; - align-items: center; - gap: 8px; - flex: 0 0 auto; -} - -.region-item__tag { - margin-inline-end: 0 !important; - border: 1px solid rgba(255, 255, 255, 0.12) !important; - color: rgba(255, 255, 255, 0.86) !important; -} - -.region-item__time { - font-size: 12px; - color: rgba(255, 255, 255, 0.55); - font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; -} - -.region-item__bar { - display: grid; - grid-template-columns: 1fr auto auto; - align-items: center; - gap: 8px; - - :global(.ant-progress) { - margin: 0; - } -} - -.region-item__pct { - width: 48px; - text-align: right; - font-size: 12px; - color: rgba(255, 255, 255, 0.72); - font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; -} - -.region-item__pending { - font-size: 12px; - color: rgba(255, 255, 255, 0.52); - white-space: nowrap; -} - -/* 空域合规 */ -.airspace-pane { - gap: var(--dash-gap, 12px); -} - -.airspace-top { - display: grid; - grid-template-columns: 1.1fr 1fr; - gap: var(--dash-gap, 12px); - min-height: 0; -} - -.airspace-score { - display: flex; - align-items: center; - gap: 12px; - padding: 10px 12px; - border-radius: 12px; - border: 1px solid rgba(255, 255, 255, 0.10); - background: - radial-gradient(circle at 18% 24%, rgba(0, 255, 136, 0.10), transparent 55%), - linear-gradient(180deg, rgba(19, 26, 61, 0.72), rgba(10, 14, 39, 0.62)); - - :global(.ant-progress) { - flex: 0 0 auto; - } -} - -.airspace-score__meta { - display: flex; - flex-direction: column; - gap: 4px; - min-width: 0; -} - -.airspace-score__title { - font-size: 14px; - font-weight: 700; - color: rgba(255, 255, 255, 0.9); -} - -.airspace-score__sub { - font-size: 12px; - color: rgba(255, 255, 255, 0.55); -} - -.airspace-metrics { - display: grid; - grid-template-columns: repeat(2, 1fr); - gap: var(--dash-gap, 12px); -} - -.airspace-metric { - padding: 10px 12px; - border-radius: 12px; - border: 1px solid rgba(255, 255, 255, 0.10); - background: rgba(255, 255, 255, 0.03); -} - -.airspace-metric__val { - font-size: 22px; - font-weight: 800; - color: rgba(255, 255, 255, 0.92); - font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; -} - -.airspace-metric__lbl { - margin-top: 4px; - font-size: 12px; - color: rgba(255, 255, 255, 0.55); -} - -.airspace-notes { - flex: 1; - min-height: 0; - padding: 10px 12px; - border-radius: 12px; - border: 1px solid rgba(255, 255, 255, 0.10); - background: rgba(255, 255, 255, 0.03); - display: flex; - flex-direction: column; - gap: 10px; -} - -.airspace-note { - display: flex; - gap: 10px; - align-items: flex-start; -} - -.airspace-note__dot { - width: 8px; - height: 8px; - border-radius: 50%; - margin-top: 6px; - background: rgba(0, 212, 255, 0.9); - box-shadow: 0 0 10px rgba(0, 212, 255, 0.25); - flex: 0 0 auto; -} - -.airspace-note__dot--warn { - background: rgba(255, 184, 0, 0.92); - box-shadow: 0 0 10px rgba(255, 184, 0, 0.25); -} - -.airspace-note__dot--ok { - background: rgba(0, 255, 136, 0.92); - box-shadow: 0 0 10px rgba(0, 255, 136, 0.25); -} - -.airspace-note__text { - font-size: 12px; - color: rgba(255, 255, 255, 0.62); - line-height: 1.35; -} - -@media (max-width: 1440px) { - .fleet-metrics { - grid-template-columns: repeat(2, 1fr); - } - - .fleet-split { - grid-template-columns: 1fr; - } - - .airspace-top { - grid-template-columns: 1fr; - } -} - -.event-list-container { - flex: 1; - min-height: 0; - overflow: hidden; - - &::-webkit-scrollbar { - width: 4px; - } - &::-webkit-scrollbar-thumb { - background: rgba(0, 212, 255, 0.22); - border-radius: 2px; - } -} - -.event-item { - padding: 10px 0 !important; - border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important; -} - -.event-item__row { - display: flex; - gap: 10px; - align-items: flex-start; - width: 100%; -} - -.event-item__badge { - width: 8px; - height: 8px; - border-radius: 50%; - margin-top: 6px; - box-shadow: 0 0 12px rgba(0, 0, 0, 0.22); - flex: 0 0 auto; -} - -.event-item__content { - flex: 1; - min-width: 0; -} - -.event-item__head { - display: flex; - justify-content: space-between; - gap: 10px; - margin-bottom: 4px; -} - -.event-item__title { - font-size: 13px; - font-weight: 600; - color: rgba(255, 255, 255, 0.92); - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} - -.event-item__time { - font-size: 12px; - color: rgba(255, 255, 255, 0.55); - font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; -} - -.event-item__meta { - display: flex; - flex-wrap: wrap; - gap: 6px; - align-items: center; - margin-bottom: 4px; -} - -.event-item__loc { - font-size: 12px; - color: rgba(255, 255, 255, 0.65); -} - -.event-item__tag { - margin-inline-end: 0 !important; - border: 1px solid rgba(255, 255, 255, 0.12) !important; - color: rgba(255, 255, 255, 0.82) !important; -} - -.event-item__desc { - font-size: 12px; - color: rgba(255, 255, 255, 0.56); - line-height: 1.3; -} - -.panel-card--dispatch { - :global(.ant-card-body) { - padding-top: 12px; - } -} - -.dispatch-grid { - display: grid; - grid-template-columns: 1fr 1fr; - gap: 10px; -} - -.dispatch-stat { - padding: 10px 12px; - border-radius: 10px; - background: rgba(255, 255, 255, 0.04); - border: 1px solid rgba(255, 255, 255, 0.08); -} - -.dispatch-stat__val { - font-size: 22px; - font-weight: 800; - color: rgba(255, 255, 255, 0.92); - font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; -} - -.dispatch-stat__lbl { - margin-top: 4px; - font-size: 12px; - color: rgba(255, 255, 255, 0.55); -} - -.dispatch-stat__val--pending { color: rgba(255, 184, 0, 0.92); } -.dispatch-stat__val--running { color: rgba(0, 212, 255, 0.92); } -.dispatch-stat__val--done { color: rgba(0, 255, 136, 0.92); } -.dispatch-stat__val--fail { color: rgba(255, 71, 87, 0.92); } - -.dispatch-highlight { - grid-column: 1 / -1; - padding: 12px 14px; - border-radius: 12px; - border: 1px solid rgba(0, 255, 136, 0.18); - background: - radial-gradient(circle at 20% 20%, rgba(0, 255, 136, 0.12), transparent 55%), - linear-gradient(180deg, rgba(19, 26, 61, 0.78), rgba(10, 14, 39, 0.62)); - display: flex; - align-items: baseline; - justify-content: space-between; -} - -.dispatch-highlight__val { - font-size: clamp(26px, 3.6vh, 34px); - font-weight: 900; - color: rgba(0, 255, 136, 0.92); - letter-spacing: 1px; -} - -.dispatch-highlight__lbl { - font-size: 12px; - color: rgba(255, 255, 255, 0.60); -} - -.dispatch-trend { - margin-top: 12px; - min-height: 0; -} - -.dispatch-trend__title { - margin-bottom: 6px; - font-size: 12px; - color: rgba(255, 255, 255, 0.56); -} - -/* 旧的洞察卡片样式已合并到右侧 Tabs 卡片中(保留空定义避免历史引用报错) */ -.panel-card--insights {} - -/* Tabs 必须占满卡片剩余高度(否则看起来“框很大内容很小”,小屏还容易溢出被裁切) */ -.dash-tabs { - height: 100%; - min-height: 0; - display: flex; - flex-direction: column; - - :global(.ant-tabs-nav) { - margin: 0 0 8px; - } - - :global(.ant-tabs-nav::before) { - border-bottom-color: rgba(0, 212, 255, 0.12); - } - - :global(.ant-tabs-tab) { - color: rgba(255, 255, 255, 0.62); - } - - :global(.ant-tabs-tab.ant-tabs-tab-active .ant-tabs-tab-btn) { - color: rgba(255, 255, 255, 0.92); - } - - :global(.ant-tabs-ink-bar) { - background: rgba(0, 212, 255, 0.9); - } - - :global(.ant-tabs-content-holder) { - flex: 1; - min-height: 0; - } - - :global(.ant-tabs-content) { - height: 100%; - } - - :global(.ant-tabs-tabpane) { - height: 100%; - min-height: 0; - padding: 0; - } -} - -.tab-pane { - height: 100%; - min-height: 0; - display: flex; - flex-direction: column; -} - -.empty-holder { - height: 100%; - flex: 1; - min-height: 0; - display: flex; - align-items: center; - justify-content: center; - color: rgba(255, 255, 255, 0.55); -} - -/* Animation Keyframes */ +/* 动画 */ @keyframes gridMove { 0% { background-position: 0 0; } 100% { background-position: 0 80px; } } @keyframes radarRotate { - 0% { transform: rotate(0deg); } - 100% { transform: rotate(360deg); } -} - -/* 响应式布局已在上方按 1680/1440/1280/960 统一收敛,避免重复规则互相覆盖。 */ - -/* 无滚动模式:通过“内容裁剪 + 密度压缩”保证一屏显示 */ -.dashboard-page--compact-1 { - .panel-subtitle { - margin-bottom: 6px; - } - - .snapshot-card { - padding: 10px 10px 8px; - } - - .fleet-metric { - padding: 8px 10px; - } - - .event-item__desc { - display: -webkit-box; - -webkit-box-orient: vertical; - -webkit-line-clamp: 2; - overflow: hidden; - } + 0% { transform: translate(-50%, -50%) rotate(0deg); } + 100% { transform: translate(-50%, -50%) rotate(360deg); } } +/* 紧凑模式下Twin Portal底部只显示2列 */ .dashboard-page--compact-2 { - .panel-subtitle { - margin-bottom: 4px; - } - - .kpi-tile { - padding: 8px 10px; - } - - .snapshot-grid { - gap: 8px; - } - - .snapshot-card { - padding: 8px 10px 6px; - - .snapshot-card__head { - margin-bottom: 6px; - } - - .snapshot-card__title { - margin-bottom: 4px; - } - } - - .fleet-metrics { - gap: 8px; - } - - .fleet-metric { - padding: 6px 8px; - - .fleet-metric__sub { - margin-top: 2px; - } - } - - .region-item { - padding: 6px 8px 4px; - margin-bottom: 6px; - } - - .event-item { - padding: 6px 0 !important; - } - - .event-item__desc { - display: -webkit-box; - -webkit-box-orient: vertical; - -webkit-line-clamp: 1; - overflow: hidden; - } - .twin-portal__bottom { grid-template-columns: repeat(2, 1fr); } diff --git a/zlt-web/yingyan/src/pages/dashboard/index.tsx b/zlt-web/yingyan/src/pages/dashboard/index.tsx index 363dfc3c..166de6d9 100644 --- a/zlt-web/yingyan/src/pages/dashboard/index.tsx +++ b/zlt-web/yingyan/src/pages/dashboard/index.tsx @@ -1,19 +1,18 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; -import { Button, Card, Carousel, DatePicker, Empty, List, Progress, Segmented, Space, Spin, Tabs, Tag, message } from 'antd'; -import { - AimOutlined, - AlertOutlined, - EnvironmentOutlined, - RadarChartOutlined, - RocketOutlined, - SafetyCertificateOutlined, -} from '@ant-design/icons'; -import { Column, Funnel, Heatmap, Line, Pie, Radar, RadialBar, Rose } from '@ant-design/plots'; -import { history } from 'umi'; +import { Spin, message } from 'antd'; import dayjs from 'dayjs'; import type { AlertItem, DeviceStats, TaskStats, TrendItem } from '@/services/dashboard'; import { getDeviceStats, getMockAlerts, getTaskStats, getTrendData } from '@/services/dashboard'; import { buildSmartCityModels } from './smartCity'; +import { + CityVitalCard, + EventStreamCard, + KpiStrip, + TwinPortal, + DroneInsightCard, + DispatchCard, + EventInsightCard, +} from './components'; import './index.less'; const Dashboard: React.FC = () => { @@ -130,12 +129,9 @@ const Dashboard: React.FC = () => { }; }, [fetchData]); - const goTo3D = () => { - // 传递来源页面,以便从map3d返回时能回到正确的大屏 - history.push('/map3d?from=dashboard'); - }; - - // --- 图表配置 --- + const smartModels = useMemo(() => { + return buildSmartCityModels({ tenantId, deviceStats, taskStats, taskTrend, alerts }); + }, [alerts, deviceStats, taskStats, taskTrend, tenantId]); const taskTrendSeriesData = useMemo(() => { return taskTrend.flatMap((t) => [ @@ -145,42 +141,6 @@ const Dashboard: React.FC = () => { ]); }, [taskTrend]); - const taskPeriodText = useMemo(() => { - if (taskStatType === 'day') return '当日'; - if (taskStatType === 'month') return '当月'; - return '当年'; - }, [taskStatType]); - - const datePickerFormat = useMemo(() => { - if (taskStatType === 'day') return 'YYYY-MM-DD'; - if (taskStatType === 'month') return 'YYYY-MM'; - return 'YYYY'; - }, [taskStatType]); - - const smartModels = useMemo(() => { - return buildSmartCityModels({ tenantId, deviceStats, taskStats, taskTrend, alerts }); - }, [alerts, deviceStats, taskStats, taskTrend, tenantId]); - - const maxEvents = useMemo(() => { - if (compactLevel === 2) return 5; - if (compactLevel === 1) return 7; - return 9; - }, [compactLevel]); - - const visibleEvents = useMemo(() => { - return (smartModels.eventList || []).slice(0, maxEvents); - }, [maxEvents, smartModels.eventList]); - - const regionCoverageMax = useMemo(() => { - if (compactLevel === 2) return 2; - if (compactLevel === 1) return 4; - return 6; - }, [compactLevel]); - - const visibleRegionCoverage = useMemo(() => { - return (smartModels.regionCoverage || []).slice(0, regionCoverageMax); - }, [regionCoverageMax, smartModels.regionCoverage]); - const snapshotsPerPage = useMemo(() => { if (compactLevel === 2) return 2; if (compactLevel === 1) return 3; @@ -193,818 +153,160 @@ const Dashboard: React.FC = () => { return 160; }, [compactLevel]); - const radarConfig: any = useMemo(() => { - return { - data: smartModels.gridRadarData, - xField: 'item', - yField: 'score', - seriesField: 'type', - area: { style: { fillOpacity: 0.12 } }, - point: { size: 2, style: { fill: '#00d4ff' } }, - color: ['#00d4ff'], - xAxis: { - grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, - label: { style: { fill: 'rgba(255,255,255,0.72)' } }, - }, - yAxis: { grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, label: false }, - legend: false, - autoFit: true, - }; - }, [smartModels.gridRadarData]); - - const envLineConfig: any = useMemo(() => { - return { - data: smartModels.envTrendData, - xField: 'time', - yField: 'value', - seriesField: 'type', - smooth: true, - color: ['#00ff88', '#00d4ff'], - xAxis: { label: { style: { fill: 'rgba(255,255,255,0.62)' } }, grid: null }, - yAxis: { - label: { style: { fill: 'rgba(255,255,255,0.62)' } }, - grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, - }, - legend: { position: 'top', itemName: { style: { fill: 'rgba(255,255,255,0.72)' } } }, - tooltip: { showMarkers: true }, - autoFit: true, - }; - }, [smartModels.envTrendData]); - - const trafficHeatmapConfig: any = useMemo(() => { - return { - data: smartModels.trafficHeatmapData, - xField: 'x', - yField: 'y', - colorField: 'value', - legend: { position: 'top', itemName: { style: { fill: 'rgba(255,255,255,0.72)' } } }, - tooltip: { formatter: (d: any) => ({ name: '热度', value: `${d.value}` }) }, - heatmapStyle: { stroke: 'rgba(255,255,255,0.08)', lineWidth: 1 }, - color: ['#0b1b2d', '#003a5a', '#00aaff', '#00ff88', '#ffb800', '#ff4757'], - xAxis: { label: false, grid: null, line: null }, - yAxis: { label: false, grid: null, line: null }, - autoFit: true, - }; - }, [smartModels.trafficHeatmapData]); - - const eventRadialConfig: any = useMemo(() => { - return { - data: smartModels.eventTypeData, - xField: 'type', - yField: 'value', - radius: 0.88, - innerRadius: 0.25, - colorField: 'type', - color: ['#00d4ff', '#00ff88', '#ffb800', '#9d4edd', '#ff4757', '#13c2c2'], - legend: false, + // 图表配置 + const radarConfig: any = useMemo(() => ({ + data: smartModels.gridRadarData, + xField: 'item', + yField: 'score', + seriesField: 'type', + appendPadding: [8, 10, 8, 10], + area: { style: { fillOpacity: 0.12 } }, + point: { size: 2, style: { fill: '#00d4ff' } }, + color: ['#00d4ff'], + xAxis: { + grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, label: { style: { fill: 'rgba(255,255,255,0.72)' } }, - autoFit: true, - }; - }, [smartModels.eventTypeData]); + }, + yAxis: { grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, label: false }, + legend: false, + autoFit: true, + }), [smartModels.gridRadarData]); - const funnelConfig: any = useMemo(() => { - return { - data: smartModels.eventFunnelData, - xField: 'stage', - yField: 'value', - legend: false, - conversionTag: false, - tooltip: { - formatter: (d: any) => ({ name: d?.stage ?? d?.name ?? '阶段', value: d?.value ?? 0 }), - }, - label: { - formatter: (d: any) => { - const stage = d?.stage ?? d?.name ?? d?.type ?? '阶段'; - const value = d?.value ?? d?.count ?? 0; - return `${stage} ${value}`; - }, - content: (d: any) => { - const stage = d?.stage ?? d?.name ?? d?.type ?? '阶段'; - const value = d?.value ?? d?.count ?? 0; - return `${stage} ${value}`; - }, - style: { fill: 'rgba(255,255,255,0.78)', fontSize: 12 }, - }, - color: ['#00d4ff', '#00ff88', '#ffb800', '#9d4edd', '#00d4ff'], - autoFit: true, - }; - }, [smartModels.eventFunnelData]); + const envLineConfig: any = useMemo(() => ({ + data: smartModels.envTrendData, + xField: 'time', + yField: 'value', + seriesField: 'type', + appendPadding: [6, 10, 12, 8], + smooth: true, + color: ['#00ff88', '#00d4ff'], + xAxis: { label: { style: { fill: 'rgba(255,255,255,0.62)' } }, grid: null }, + yAxis: { + label: { style: { fill: 'rgba(255,255,255,0.62)' } }, + grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, + }, + legend: { position: 'top', itemName: { style: { fill: 'rgba(255,255,255,0.72)' } } }, + tooltip: { showMarkers: true }, + autoFit: true, + }), [smartModels.envTrendData]); - const dispatchTrendConfig: any = useMemo(() => { - return { - data: taskTrendSeriesData, - xField: 'date', - yField: 'value', - seriesField: 'type', - smooth: true, - color: ['#00d4ff', '#00ff88', '#ffb800'], - xAxis: { label: { style: { fill: 'rgba(255,255,255,0.62)' } }, grid: null }, - yAxis: { - label: { style: { fill: 'rgba(255,255,255,0.62)' } }, - grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, - }, - legend: { position: 'top', itemName: { style: { fill: 'rgba(255,255,255,0.72)' } } }, - tooltip: { showMarkers: true }, - autoFit: true, - }; - }, [taskTrendSeriesData]); + const trafficHeatmapConfig: any = useMemo(() => ({ + data: smartModels.trafficHeatmapData, + xField: 'x', + yField: 'y', + colorField: 'value', + appendPadding: [6, 8, 6, 8], + legend: { position: 'top', itemName: { style: { fill: 'rgba(255,255,255,0.72)' } } }, + tooltip: { formatter: (d: any) => ({ name: '热度', value: `${d.value}` }) }, + heatmapStyle: { stroke: 'rgba(255,255,255,0.08)', lineWidth: 1 }, + color: ['#0b1b2d', '#003a5a', '#00aaff', '#00ff88', '#ffb800', '#ff4757'], + xAxis: { label: false, grid: null, line: null }, + yAxis: { label: false, grid: null, line: null }, + autoFit: true, + }), [smartModels.trafficHeatmapData]); - const terminalPieConfig: any = useMemo(() => { - const data = smartModels.terminalPieData || []; - return { - data, - angleField: 'count', - colorField: 'name', - radius: 0.8, - innerRadius: 0.58, - label: { - text: (datum: any) => { - const total = data.reduce((sum, d) => sum + (d.count || 0), 0); - const count = datum?.count ?? 0; - const percent = total > 0 ? ((count / total) * 100).toFixed(0) : '0'; - return `${datum?.name || ''} ${percent}%`; - }, - style: { fill: 'rgba(255,255,255,0.7)' }, - }, - legend: false, - autoFit: true, - }; - }, [smartModels.terminalPieData]); - - const droneStatusPieConfig: any = useMemo(() => { - const fleet = smartModels.fleet; - const total = fleet.droneInFlight + fleet.droneStandby + fleet.droneMaintenance; - if (!total) return {}; - return { - data: [ - { type: '在飞', value: fleet.droneInFlight }, - { type: '待命', value: fleet.droneStandby }, - { type: '维护', value: fleet.droneMaintenance }, - ], - angleField: 'value', - colorField: 'type', - radius: 0.92, - innerRadius: 0.62, - color: ['rgba(157, 78, 221, 0.95)', 'rgba(0, 212, 255, 0.9)', 'rgba(255, 184, 0, 0.92)'], - legend: false, - label: false, - statistic: { - title: false, - content: { - style: { color: 'rgba(255,255,255,0.88)', fontSize: 18, fontWeight: 700, whiteSpace: 'pre-line' }, - content: `${fleet.droneOnline}/${fleet.droneTotal}\n在线`, - }, - }, - autoFit: true, - }; - }, [ - smartModels.fleet.droneInFlight, - smartModels.fleet.droneMaintenance, - smartModels.fleet.droneOnline, - smartModels.fleet.droneStandby, - smartModels.fleet.droneTotal, - ]); - - const taskTypeColumnConfig: any = useMemo(() => { - return { - data: taskTypeData, - xField: 'type', - yField: 'value', - columnWidthRatio: 0.55, - color: ['#00d4ff'], - label: { style: { fill: 'rgba(255,255,255,0.85)' } }, - xAxis: { label: { style: { fill: 'rgba(255,255,255,0.62)' } } }, - yAxis: { - label: { style: { fill: 'rgba(255,255,255,0.62)' } }, - grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, - }, - legend: false, - autoFit: true, - }; - }, [taskTypeData]); - - const annualLineConfig: any = useMemo(() => { - return { - data: annualData, - xField: 'month', - yField: 'value', - seriesField: 'type', - smooth: true, - color: ['#00d4ff', '#00ff88'], - areaStyle: { fillOpacity: 0.12 }, - xAxis: { label: { style: { fill: 'rgba(255,255,255,0.62)' } } }, - yAxis: { - label: { style: { fill: 'rgba(255,255,255,0.62)' } }, - grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } }, - }, - legend: { position: 'top', itemName: { style: { fill: 'rgba(255,255,255,0.72)' } } }, - autoFit: true, - }; - }, [annualData]); - - const riskRoseConfig: any = useMemo(() => { - return { - data: failureAnalysisData, - xField: 'type', - yField: 'value', - seriesField: 'type', - radius: 0.85, - innerRadius: 0.25, - colorField: 'type', - color: ['#ffb800', '#00d4ff', '#00ff88', '#9d4edd', '#ff4757', '#13c2c2'], - label: { - content: (d: any) => `${d.type}\n${d.value}`, - style: { fill: 'rgba(255,255,255,0.72)' }, - }, - legend: false, - autoFit: true, - }; - }, [failureAnalysisData]); - - const severityColor = (severity: string) => { - if (severity === 'critical') return '#ff4757'; - if (severity === 'warning') return '#ffb800'; - return '#00d4ff'; - }; - - const statusTagColor = (status: string) => { - if (status === '已闭环') return '#00ff88'; - if (status === '处理中') return '#9d4edd'; - if (status === '已派单') return '#00d4ff'; - return 'rgba(255,255,255,0.25)'; - }; - - const regionRiskColor = (risk: string) => { - if (risk === 'critical') return '#ff4757'; - if (risk === 'warning') return '#ffb800'; - return '#00ff88'; - }; - - // 运营洞察已合并进右侧“事件处置与洞察”卡片的 Tabs,避免小屏纵向堆叠过高导致裁切。 + // 使用 CSS Grid 强制分配高度 + const gap = 12; return ( -
-
- - -
-
- - {/* 左侧栏:城市体征 */} -
- - 城市运行体征 - - } - className="panel-card glass-panel panel-card--left-tabs" - size="small" - > - -
覆盖、发现、处置、复核一体化评分
-
- -
-
- ), - }, - { - key: 'env', - label: '环境感知', - children: ( -
-
空地协同采集 · 24 小时滚动
-
- -
-
- ), - }, - { - key: 'traffic', - label: '交通热力', - children: ( -
-
重点片区热度分布(网格化)
-
- -
-
- ), - }, - ]} - /> - - - - 城市事件流 - - } - className="panel-card glass-panel panel-card--events" - size="small" - extra={实时} - > -
- }} - renderItem={(item) => ( - -
-
-
-
- {item.title} - {item.timeText} -
-
- {item.location} - - {item.status} - - - {item.source} - -
-
{item.desc}
-
-
- - )} - /> -
- +
+ +
+ {/* 左侧栏 - CSS Grid 强制 1:1 分配 */} +
+
+
- - {/* 中间栏:核心监控 */} -
- {/* 顶部KPI */} -
- {smartModels.kpis.map((kpi) => ( -
-
- {kpi.label} - -
-
- {kpi.value} - {kpi.unit ? {kpi.unit} : null} -
- {kpi.sub ?
{kpi.sub}
: null} -
- ))} -
- - {/* 地图/3D入口 */} -
-
-
-
-
- {compactLevel === 2 ? ( -
- 事件点位 - AI识别 -
- ) : ( - <> -
- 事件点位 - 航线叠加 - 电子围栏 - AI识别 -
-
- - 安全态势 - - - 空域管理 - - - 数字孪生 - -
- - )} -
- -
-
全域数字孪生中枢
-
空地协同巡检 · 城市事件识别 · 应急快速响应
- -
- -
-
- 在线无人机 - {smartModels.fleet.droneOnline} -
-
- 在飞架次 - {smartModels.fleet.droneInFlight} -
- {compactLevel === 2 ? null : ( - <> -
- 可用机库 - {smartModels.fleet.dockOnline} -
-
- 合规指数 - - {smartModels.airspace.complianceIndex} - -
- - )} -
-
-
- - - 无人机态势与AI洞察 - - } - className="panel-card glass-panel fill-bottom panel-card--snap" - size="small" - > - - - {new Array(Math.max(1, Math.ceil(smartModels.aiSnapshots.length / snapshotsPerPage))) - .fill(0) - .map((_, pageIdx) => { - const start = pageIdx * snapshotsPerPage; - const page = smartModels.aiSnapshots.slice(start, start + snapshotsPerPage); - return ( -
-
- {page.map((s) => ( -
-
- {s.tag} - {s.timeText} -
-
{s.title}
-
- {s.location} - 置信度 {s.confidence}% -
-
- ))} -
-
- ); - })} -
-
- ), - }, - { - key: 'fleet', - label: '机队态势', - children: ( -
-
-
-
平均电量
-
{smartModels.fleet.avgBattery}%
-
低电 {smartModels.fleet.lowBatteryAlerts} 起
-
-
-
飞行时长
-
{smartModels.fleet.flightHoursToday}h
-
今日累计
-
-
-
飞行里程
-
{smartModels.fleet.flightMileageToday}km
-
含航线复飞
-
-
-
可用机库
-
- {smartModels.fleet.dockOnline}/{smartModels.fleet.dockTotal} -
-
在线/总量
-
-
- -
-
-
机队状态占比
-
- {Object.keys(droneStatusPieConfig).length ? ( - - ) : ( - - )} -
-
-
-
重点区域覆盖
-
- {visibleRegionCoverage.map((r) => ( -
-
- {r.name} - - - {r.risk === 'critical' ? '高风险' : r.risk === 'warning' ? '关注' : '正常'} - - {r.updatedAt} - -
-
- - {r.coverage}% - 待处置 {r.pending} -
-
- ))} -
-
-
-
- ), - }, - { - key: 'airspace', - label: '空域合规', - children: ( -
-
-
- -
-
合规指数
-
围栏/禁飞/审批综合
-
城市安全指数 {smartModels.airspace.safetyIndex}
-
-
- -
-
-
{smartModels.airspace.geofenceTriggers}
-
围栏触发
-
-
-
{smartModels.airspace.noFlyWarnings}
-
禁飞预警
-
-
-
{smartModels.airspace.approvalsToday}
-
今日审批
-
-
-
{smartModels.airspace.approvalsPassRate}%
-
通过率
-
-
-
- -
-
- - 重点区域启用“低空走廊”,优先保障应急任务快速通行。 -
- {compactLevel === 2 ? null : ( - <> -
- - 围栏触发或禁飞预警上升时,建议自动降级为“复核模式”。 -
-
- - 审批通过率稳定后,可扩大夜航与多机协同策略的投放比例。 -
- - )} -
-
- ), - }, - ]} - /> - +
+
+
- {/* 右侧栏:任务与运维 */} -
- - {taskPeriodText}运行调度 - - } - className="panel-card glass-panel panel-card--dispatch" - size="small" - extra={ - - setTaskStatType(v as any)} - /> - v && setTaskStatDate(v)} - picker={taskStatType === 'day' ? 'date' : taskStatType} - allowClear={false} - format={datePickerFormat} - disabledDate={(d) => !!d && d.isAfter(dayjs(), 'day')} - /> - - } - > -
-
-
{taskStats?.pending || 0}
-
待执行
-
-
-
{taskStats?.running || 0}
-
执行中
-
-
-
{taskStats?.completed || 0}
-
已完成
-
-
-
{taskStats?.failed || 0}
-
异常
-
-
-
{taskStats?.successRate || 0}%
-
成功率
-
-
-
-
近 7 日任务趋势
-
- -
-
-
- - - 事件处置与洞察 - - } - className="panel-card glass-panel flex-grow panel-card--right-tabs" - size="small" - > - -
- -
-
- ), - }, - { - key: 'types', - label: '类型分布', - children: ( -
-
- -
-
- ), - }, - { - key: 'asset', - label: '资产构成', - children: smartModels.terminalPieData?.length ? ( -
-
- -
-
- ) : ( -
-
- -
-
- ), - }, - { - key: 'capacity', - label: '作业结构', - children: taskTypeData?.length ? ( -
-
- -
-
- ) : ( -
-
- -
-
- ), - }, - { - key: 'risk', - label: '风险画像', - children: failureAnalysisData?.length ? ( -
-
- -
-
- ) : ( -
-
- -
-
- ), - }, - { - key: 'year', - label: '年度趋势', - children: annualData?.length ? ( -
-
- -
-
- ) : ( -
-
- -
-
- ), - }, - ]} - /> - + {/* 中间栏 - KPI固定70px + 剩余空间1:1分配 */} +
+
+
+
+ +
+
+ +
+
+ {/* 右侧栏 - CSS Grid 各50% */} +
+
+ +
+
+ +
diff --git a/zlt-web/yingyan/src/pages/dashboard/smartCity.ts b/zlt-web/yingyan/src/pages/dashboard/smartCity.ts new file mode 100644 index 00000000..e6bf1dcd --- /dev/null +++ b/zlt-web/yingyan/src/pages/dashboard/smartCity.ts @@ -0,0 +1,401 @@ +import dayjs from 'dayjs'; +import type { AlertItem, DeviceStats, TaskStats, TrendItem } from '@/services/dashboard'; + +type Severity = 'normal' | 'warning' | 'critical'; + +export interface SmartCityKpiItem { + key: string; + label: string; + value: number | string; + unit?: string; + accent?: 'blue' | 'green' | 'yellow' | 'red' | 'purple'; + sub?: string; +} + +export interface SmartCityEventItem { + id: string; + title: string; + location: string; + source: '无人机' | '摄像头' | '机库' | '多源融合'; + severity: Severity; + status: '待确认' | '已派单' | '处理中' | '已闭环'; + timeText: string; + desc: string; +} + +export interface SmartCityModels { + kpis: SmartCityKpiItem[]; + fleet: { + droneTotal: number; + droneOnline: number; + droneInFlight: number; + droneStandby: number; + droneMaintenance: number; + dockTotal: number; + dockOnline: number; + cameraTotal: number; + cameraOnline: number; + lowBatteryAlerts: number; + avgBattery: number; + flightHoursToday: number; + flightMileageToday: number; + }; + airspace: { + safetyIndex: number; + complianceIndex: number; + geofenceTriggers: number; + noFlyWarnings: number; + approvalsToday: number; + approvalsPassRate: number; + }; + regionCoverage: Array<{ + id: string; + name: string; + coverage: number; + pending: number; + risk: Severity; + updatedAt: string; + }>; + terminalPieData: { name: string; count: number }[]; + onlineRate: number; + liquidRate: number; + gridRadarData: { item: string; score: number; type: '当前' }[]; + envTrendData: { time: string; type: string; value: number }[]; + trafficHeatmapData: { x: string; y: string; value: number }[]; + eventTypeData: { type: string; value: number }[]; + eventFunnelData: { stage: string; value: number }[]; + eventList: SmartCityEventItem[]; + aiSnapshots: Array<{ + id: string; + title: string; + location: string; + tag: string; + confidence: number; + timeText: string; + severity: Severity; + }>; +} + +function hashStringToSeed(text: string): number { + let hash = 2166136261; + for (let i = 0; i < text.length; i++) { + hash ^= text.charCodeAt(i); + hash = Math.imul(hash, 16777619); + } + return hash >>> 0; +} + +function createRng(seedText: string) { + let seed = hashStringToSeed(seedText) || 1; + return () => { + seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0; + return seed / 4294967296; + }; +} + +function clampNumber(value: number, min: number, max: number) { + return Math.max(min, Math.min(max, value)); +} + +function pickOne(rng: () => number, items: T[]): T { + return items[Math.floor(rng() * items.length)]; +} + +function mapAlertToEvent(alert: AlertItem): Omit & { + severity: Severity; + title: string; +} { + const severity: Severity = + alert.level === 'critical' ? 'critical' : alert.level === 'error' ? 'warning' : 'normal'; + + if (alert.type === 'device_offline') { + return { + id: alert.id, + title: '关键点位离线预警', + severity, + timeText: dayjs(alert.timestamp).format('HH:mm'), + desc: alert.message, + }; + } + if (alert.type === 'low_battery') { + return { + id: alert.id, + title: '保障能力风险提示', + severity: severity === 'normal' ? 'warning' : severity, + timeText: dayjs(alert.timestamp).format('HH:mm'), + desc: alert.message, + }; + } + if (alert.type === 'task_failed') { + return { + id: alert.id, + title: '巡检任务异常', + severity, + timeText: dayjs(alert.timestamp).format('HH:mm'), + desc: alert.message, + }; + } + return { + id: alert.id, + title: '终端运行异常', + severity: severity === 'normal' ? 'warning' : severity, + timeText: dayjs(alert.timestamp).format('HH:mm'), + desc: alert.message, + }; +} + +function calcSafetyIndex(params: { + deviceStats?: DeviceStats | null; + taskStats?: TaskStats | null; + alerts?: AlertItem[]; + baseSeed: string; +}) { + const rng = createRng(`${params.baseSeed}:safety`); + const onlineRate = params.deviceStats?.onlineRate ?? 0; + const successRate = params.taskStats?.successRate ?? 0; + const alerts = params.alerts || []; + + const critical = alerts.filter((a) => a.level === 'critical').length; + const error = alerts.filter((a) => a.level === 'error').length; + const warning = alerts.filter((a) => a.level === 'warning').length; + + const baseline = 90 + Math.round(rng() * 4); + const penalty = critical * 6 + error * 4 + warning * 2 + Math.round((100 - onlineRate) * 0.18); + const bonus = Math.round((successRate - 80) * 0.15); + + return clampNumber(baseline - penalty + bonus, 60, 99); +} + +export function buildSmartCityModels(params: { + tenantId?: string; + deviceStats?: DeviceStats | null; + taskStats?: TaskStats | null; + taskTrend?: TrendItem[]; + alerts?: AlertItem[]; +}): SmartCityModels { + const todayKey = dayjs().format('YYYY-MM-DD'); + const baseSeed = `${params.tenantId || 'default'}:${todayKey}`; + const rng = createRng(baseSeed); + + const deviceStats = params.deviceStats; + const taskStats = params.taskStats; + const taskTrend = params.taskTrend || []; + const alerts = params.alerts || []; + + const onlineRate = deviceStats?.onlineRate ?? 0; + const safetyIndex = calcSafetyIndex({ deviceStats, taskStats, alerts, baseSeed }); + + const eventCount = alerts.length + 6 + Math.floor(rng() * 6); + const avgResponse = clampNumber(8 + Math.round((1 - (taskStats?.successRate ?? 0) / 100) * 12) + Math.round(rng() * 4), 6, 28); + const closedLoopRate = clampNumber( + taskStats?.total ? Math.round(((taskStats.completed || 0) / taskStats.total) * 100) : 70 + Math.round(rng() * 18), + 40, + 99, + ); + + const byType = deviceStats?.byType || []; + const droneTotal = byType.find((d) => d.type === 'drone')?.count || 0; + const dockTotal = byType.find((d) => d.type === 'dock')?.count || 0; + const cameraTotal = byType.find((d) => d.type === 'camera')?.count || 0; + + const ratio = clampNumber((onlineRate || 0) / 100, 0, 1); + const droneOnline = clampNumber(Math.round(droneTotal * ratio * (0.94 + rng() * 0.12)), 0, droneTotal); + const dockOnline = clampNumber(Math.round(dockTotal * ratio * (0.92 + rng() * 0.14)), 0, dockTotal); + const cameraOnline = clampNumber(Math.round(cameraTotal * ratio * (0.90 + rng() * 0.16)), 0, cameraTotal); + + const runningTasks = taskStats?.running || 0; + const droneInFlight = clampNumber(Math.min(droneOnline, Math.max(0, runningTasks) + Math.round(rng() * 2)), 0, droneOnline); + const droneMaintenance = clampNumber(Math.round(droneTotal * (0.06 + rng() * 0.09)), 0, droneTotal); + const droneStandby = clampNumber(droneOnline - droneInFlight - Math.min(droneMaintenance, droneOnline), 0, droneOnline); + + const lowBatteryAlerts = alerts.filter((a) => a.type === 'low_battery').length; + const avgBattery = clampNumber(62 + Math.round(rng() * 28) - lowBatteryAlerts * 3, 18, 98); + const flightHoursToday = clampNumber(6 + Math.round((taskStats?.total || 0) * 0.55) + Math.round(rng() * 4), 0, 78); + const flightMileageToday = clampNumber(28 + Math.round((taskStats?.total || 0) * 2.2) + Math.round(rng() * 12), 0, 420); + + const critical = alerts.filter((a) => a.level === 'critical').length; + const error = alerts.filter((a) => a.level === 'error').length; + const warning = alerts.filter((a) => a.level === 'warning').length; + + const complianceIndex = clampNumber(95 - critical * 6 - error * 3 - warning * 1 - Math.round((100 - onlineRate) * 0.12) + Math.round(rng() * 2), 60, 99); + const geofenceTriggers = clampNumber(Math.round(rng() * 5) + critical + Math.floor(error / 2), 0, 12); + const noFlyWarnings = clampNumber(Math.round(rng() * 3) + Math.floor(warning / 2), 0, 10); + const approvalsToday = clampNumber(18 + Math.round(rng() * 28), 0, 120); + const approvalsPassRate = clampNumber(92 - critical * 2 - error + Math.round(rng() * 4), 70, 99); + + const fleet = { + droneTotal, + droneOnline, + droneInFlight, + droneStandby, + droneMaintenance, + dockTotal, + dockOnline, + cameraTotal, + cameraOnline, + lowBatteryAlerts, + avgBattery, + flightHoursToday, + flightMileageToday, + }; + + const airspace = { + safetyIndex, + complianceIndex, + geofenceTriggers, + noFlyWarnings, + approvalsToday, + approvalsPassRate, + }; + + const kpis: SmartCityKpiItem[] = [ + { key: 'air', label: '空域合规指数', value: complianceIndex, unit: '', accent: complianceIndex >= 92 ? 'green' : complianceIndex >= 82 ? 'yellow' : 'red', sub: '围栏/禁飞/链路综合' }, + { key: 'flight', label: '在飞无人机', value: droneInFlight, unit: '架', accent: 'purple', sub: `在线 ${droneOnline}/${droneTotal}` }, + { key: 'sortie', label: '今日出动任务', value: taskStats?.todayNew ?? 0, unit: '次', accent: 'blue', sub: '巡检/应急/处置' }, + { key: 'closed', label: '问题闭环率', value: closedLoopRate, unit: '%', accent: closedLoopRate >= 85 ? 'green' : 'yellow', sub: '发现→处置→复核' }, + { key: 'online', label: '终端在线率', value: onlineRate, unit: '%', accent: onlineRate >= 90 ? 'green' : onlineRate >= 75 ? 'yellow' : 'red', sub: `低电 ${lowBatteryAlerts} 起` }, + ]; + + const terminalPieData = (deviceStats?.byType || []).map((d) => ({ name: d.name, count: d.count })); + + const regionCoverage = (() => { + const regions = ['政务中心片区', '滨河公园带', '高新大道走廊', '老城商圈', '西站枢纽', '南湖片区', '工业园北区', '东门立交']; + const picked = regions.slice(0, 6); + return picked.map((name, idx) => { + const coverage = clampNumber(72 + Math.round(rng() * 26) - idx * 2, 45, 99); + const pending = clampNumber(Math.round(rng() * 8) + (idx % 2 === 0 ? 1 : 0), 0, 18); + const risk: Severity = coverage >= 88 ? 'normal' : coverage >= 76 ? 'warning' : 'critical'; + const updatedAt = dayjs().subtract(5 + Math.round(rng() * 55), 'minute').format('HH:mm'); + return { id: `region-${idx}`, name, coverage, pending, risk, updatedAt }; + }); + })(); + + const gridRadarData = [ + { item: '巡检覆盖', score: clampNumber(70 + Math.round(rng() * 24), 55, 98), type: '当前' as const }, + { item: '问题发现', score: clampNumber(62 + Math.round(rng() * 30), 50, 98), type: '当前' as const }, + { item: '处置效率', score: clampNumber(68 + Math.round(rng() * 22), 50, 98), type: '当前' as const }, + { item: '复核通过', score: clampNumber(72 + Math.round(rng() * 18), 55, 99), type: '当前' as const }, + { item: '重点关注', score: clampNumber(58 + Math.round(rng() * 34), 45, 98), type: '当前' as const }, + ]; + + const envTrendData: { time: string; type: string; value: number }[] = []; + const startHour = dayjs().startOf('day'); + const pmBase = clampNumber(22 + Math.round(rng() * 26), 15, 60); + const noiseBase = clampNumber(52 + Math.round(rng() * 10), 45, 70); + for (let i = 0; i < 24; i++) { + const time = startHour.add(i, 'hour').format('HH:00'); + const wave = Math.sin((i / 24) * Math.PI * 2); + const pm = clampNumber(pmBase + wave * 10 + (rng() - 0.5) * 6, 8, 85); + const noise = clampNumber(noiseBase + Math.abs(wave) * 9 + (rng() - 0.5) * 4, 35, 85); + envTrendData.push({ time, type: 'PM2.5', value: Number(pm.toFixed(1)) }); + envTrendData.push({ time, type: '噪声(dB)', value: Number(noise.toFixed(1)) }); + } + + const trafficHeatmapData: { x: string; y: string; value: number }[] = []; + const cols = 10; + const rows = 6; + for (let y = 0; y < rows; y++) { + for (let x = 0; x < cols; x++) { + const centerBias = 1 - Math.abs(x - (cols - 1) / 2) / cols; + const value = clampNumber(12 + centerBias * 36 + rng() * 18 + (y % 2 === 0 ? 2 : -2), 0, 100); + trafficHeatmapData.push({ x: `${x + 1}`, y: `${rows - y}`, value: Math.round(value) }); + } + } + + const locations = ['政务中心', '滨河公园', '高新大道', '老城商圈', '西站枢纽', '南湖片区', '工业园北区', '东门立交']; + const sources: SmartCityEventItem['source'][] = ['无人机', '摄像头', '机库', '多源融合']; + const statuses: SmartCityEventItem['status'][] = ['待确认', '已派单', '处理中', '已闭环']; + + const eventListFromAlerts: SmartCityEventItem[] = alerts.slice(0, 8).map((a, idx) => { + const base = mapAlertToEvent(a); + const status = idx === 0 ? '处理中' : idx === 1 ? '待确认' : pickOne(rng, statuses); + const source = idx % 2 === 0 ? '无人机' : '机库'; + return { + ...base, + location: pickOne(rng, locations), + source, + status, + }; + }); + + const aiEventTypes = ['违停抓拍', '烟火识别', '占道经营', '河道漂浮物', '工地未戴帽', '夜间聚集']; + const aiSnapshots = new Array(10).fill(0).map((_, i) => { + const type = aiEventTypes[i % aiEventTypes.length]; + const confidence = clampNumber(78 + Math.round(rng() * 20), 60, 99); + const severity: Severity = confidence >= 92 ? 'critical' : confidence >= 84 ? 'warning' : 'normal'; + const timeText = dayjs().subtract(Math.round(rng() * 65), 'minute').format('HH:mm'); + return { + id: `snap-${todayKey}-${i}`, + title: type, + location: pickOne(rng, locations), + tag: pickOne(rng, ['AI识别', '多源融合', '重点区域', '高频点位']), + confidence, + timeText, + severity, + }; + }); + + const eventListGenerated: SmartCityEventItem[] = aiSnapshots.slice(0, 6).map((s, idx) => { + const severity: Severity = s.severity; + const status = idx < 2 ? '待确认' : idx < 4 ? '已派单' : pickOne(rng, statuses); + const source = idx % 3 === 0 ? '无人机' : idx % 3 === 1 ? '摄像头' : '多源融合'; + return { + id: `evt-${s.id}`, + title: s.title, + location: s.location, + source, + severity, + status, + timeText: s.timeText, + desc: `疑似${s.title}(置信度 ${s.confidence}%)`, + }; + }); + + const eventList = [...eventListGenerated, ...eventListFromAlerts].slice(0, 12); + + const eventTypeCounts: Record = {}; + eventList.forEach((e) => { + const key = e.title; + eventTypeCounts[key] = (eventTypeCounts[key] || 0) + 1; + }); + const eventTypeData = Object.entries(eventTypeCounts) + .map(([type, value]) => ({ type, value })) + .sort((a, b) => b.value - a.value) + .slice(0, 6); + + const eventFunnelData = (() => { + const total = eventCount; + const confirmed = clampNumber(Math.round(total * (0.78 + rng() * 0.08)), 0, total); + const assigned = clampNumber(Math.round(confirmed * (0.75 + rng() * 0.1)), 0, confirmed); + const processing = clampNumber(Math.round(assigned * (0.72 + rng() * 0.12)), 0, assigned); + const closed = clampNumber(Math.round(processing * (0.78 + rng() * 0.12)), 0, processing); + return [ + { stage: '识别', value: total }, + { stage: '确认', value: confirmed }, + { stage: '派单', value: assigned }, + { stage: '处置', value: processing }, + { stage: '闭环', value: closed }, + ]; + })(); + + const liquidRate = clampNumber((onlineRate || 0) / 100, 0, 1); + + void taskTrend; + + return { + kpis, + fleet, + airspace, + regionCoverage, + terminalPieData, + onlineRate, + liquidRate, + gridRadarData, + envTrendData, + trafficHeatmapData, + eventTypeData, + eventFunnelData, + eventList, + aiSnapshots, + }; +} diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/AnnualTrendCard.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/components/AnnualTrendCard.tsx new file mode 100644 index 00000000..2e7192d2 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/AnnualTrendCard.tsx @@ -0,0 +1,186 @@ +import React from 'react'; +import { Card } from 'antd'; +import { BarChartOutlined } from '@ant-design/icons'; +import { Area, Column } from '@ant-design/plots'; + +interface AnnualTrendCardProps { + annualData: any[]; + taskTypeData: any[]; +} + +const AnnualTrendCard: React.FC = ({ annualData, taskTypeData }) => { + const areaConfig: any = { + data: annualData, + xField: 'month', + yField: 'value', + seriesField: 'type', + color: ['#00b4d8', '#00e5a0'], + areaStyle: { fillOpacity: 0.3 }, + line: { + style: { lineWidth: 2 }, + }, + point: { + size: 3, + shape: 'circle', + style: { + fill: '#fff', + stroke: '#00b4d8', + lineWidth: 2, + }, + }, + xAxis: { + label: { + style: { fill: 'rgba(200,230,255,0.75)', fontSize: 11 }, + }, + line: { + style: { stroke: 'rgba(0,180,216,0.2)' }, + }, + tickLine: null, + }, + yAxis: { + label: { + style: { fill: 'rgba(200,230,255,0.75)', fontSize: 11 }, + }, + grid: { + line: { style: { stroke: 'rgba(0,150,200,0.15)', lineDash: [4, 4] } }, + }, + line: null, + tickLine: null, + }, + legend: { + position: 'top', + itemName: { + style: { fill: 'rgba(200,230,255,0.85)', fontSize: 12, fontWeight: 600 }, + }, + marker: { + symbol: 'circle', + style: { r: 4 }, + }, + itemSpacing: 16, + }, + smooth: true, + animation: { + appear: { + animation: 'wave-in', + duration: 1000, + }, + }, + tooltip: { + showMarkers: true, + marker: { + fill: '#00b4d8', + }, + domStyles: { + 'g2-tooltip': { + background: 'rgba(10, 30, 50, 0.95)', + boxShadow: '0 4px 12px rgba(0,0,0,0.3)', + border: '1px solid rgba(0,180,216,0.3)', + }, + 'g2-tooltip-title': { + color: 'rgba(200,230,255,0.95)', + }, + 'g2-tooltip-list-item': { + color: 'rgba(200,230,255,0.85)', + }, + }, + }, + autoFit: true, + }; + + const columnConfig: any = { + data: taskTypeData, + xField: 'type', + yField: 'value', + seriesField: 'type', + color: ({ type }: any) => { + if (type === '航线巡检') return '#00b4d8'; + if (type === '定点监测') return '#00e5a0'; + return '#ff9f43'; + }, + columnStyle: { + radius: [6, 6, 0, 0], + }, + label: { + text: (datum: any) => datum?.value?.toString() || '0', + style: { + fill: '#fff', + fontSize: 12, + fontWeight: 600, + textAlign: 'center', + }, + position: 'top', + offset: 8, + }, + xAxis: { + label: { + style: { fill: 'rgba(200,230,255,0.75)', fontSize: 11 }, + }, + line: { + style: { stroke: 'rgba(0,180,216,0.2)' }, + }, + tickLine: null, + }, + yAxis: { + label: { + style: { fill: 'rgba(200,230,255,0.75)', fontSize: 11 }, + }, + grid: { + line: { style: { stroke: 'rgba(0,150,200,0.15)', lineDash: [4, 4] } }, + }, + line: null, + tickLine: null, + }, + legend: false, + animation: { + appear: { + animation: 'scale-in-y', + duration: 800, + }, + }, + tooltip: { + domStyles: { + 'g2-tooltip': { + background: 'rgba(10, 30, 50, 0.95)', + boxShadow: '0 4px 12px rgba(0,0,0,0.3)', + border: '1px solid rgba(0,180,216,0.3)', + }, + 'g2-tooltip-title': { + color: 'rgba(200,230,255,0.95)', + }, + 'g2-tooltip-list-item': { + color: 'rgba(200,230,255,0.85)', + }, + }, + }, + autoFit: true, + }; + + return ( + + 年度巡检任务趋势与任务类型 + + } + className="maritime-card" + size="small" + > +
+
+
年度巡检趋势
+
+ +
+
+
+
任务类型统计
+
+ +
+
+
+
+ ); +}; + +export default AnnualTrendCard; diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/AnnualTrendChart.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/components/AnnualTrendChart.tsx new file mode 100644 index 00000000..eecc1743 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/AnnualTrendChart.tsx @@ -0,0 +1,116 @@ +import React from 'react'; +import { Card } from 'antd'; +import { LineChartOutlined } from '@ant-design/icons'; +import { Area } from '@ant-design/plots'; + +interface AnnualTrendChartProps { + annualData: any[]; +} + +const AnnualTrendChart: React.FC = ({ annualData }) => { + const areaConfig: any = { + data: annualData, + xField: 'month', + yField: 'value', + seriesField: 'type', + color: ['#00b4d8', '#00e5a0'], + appendPadding: [20, 10, 10, 10], + areaStyle: { fillOpacity: 0.25 }, + line: { + style: { lineWidth: 2 }, + }, + point: { + size: 2, + shape: 'circle', + style: { + fill: '#fff', + stroke: '#00b4d8', + lineWidth: 1.5, + }, + }, + xAxis: { + label: { + style: { fill: 'rgba(200,230,255,0.75)', fontSize: 10 }, + autoRotate: false, + autoHide: true, + }, + line: { + style: { stroke: 'rgba(0,180,216,0.2)' }, + }, + tickLine: null, + }, + yAxis: { + label: { + style: { fill: 'rgba(200,230,255,0.75)', fontSize: 10 }, + }, + grid: { + line: { style: { stroke: 'rgba(0,150,200,0.15)', lineDash: [4, 4] } }, + }, + line: null, + tickLine: null, + }, + legend: { + position: 'top-left', + offsetY: -5, + itemName: { + style: { fill: 'rgba(200,230,255,0.85)', fontSize: 11, fontWeight: 600 }, + }, + marker: { + symbol: 'circle', + style: { r: 3 }, + }, + itemSpacing: 12, + }, + smooth: true, + animation: { + appear: { + animation: 'wave-in', + duration: 1000, + }, + }, + tooltip: { + showMarkers: true, + marker: { + fill: '#00b4d8', + }, + domStyles: { + 'g2-tooltip': { + background: 'rgba(10, 30, 50, 0.95)', + boxShadow: '0 4px 12px rgba(0,0,0,0.3)', + border: '1px solid rgba(0,180,216,0.3)', + }, + 'g2-tooltip-title': { + color: 'rgba(200,230,255,0.95)', + }, + 'g2-tooltip-list-item': { + color: 'rgba(200,230,255,0.85)', + }, + }, + }, + autoFit: true, + }; + + return ( + + 年度巡检任务趋势 + + } + className="maritime-card" + size="small" + styles={{ + body: { + padding: '8px 8px 4px 8px', + overflow: 'visible', + }, + }} + > +
+ +
+
+ ); +}; + +export default AnnualTrendChart; diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/DeviceTypeCard.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/components/DeviceTypeCard.tsx new file mode 100644 index 00000000..94678a14 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/DeviceTypeCard.tsx @@ -0,0 +1,106 @@ +import React from 'react'; +import { Card } from 'antd'; +import { AppstoreOutlined } from '@ant-design/icons'; +import { Pie } from '@ant-design/plots'; +import type { DeviceStats } from '@/services/dashboard'; + +interface DeviceTypeCardProps { + deviceStats: DeviceStats | null; +} + +const DeviceTypeCard: React.FC = ({ deviceStats }) => { + const usvTypeData = (deviceStats?.byType || [ + { name: '巡检型', count: 12 }, + { name: '监测型', count: 8 }, + { name: '救援型', count: 5 }, + { name: '测量型', count: 3 }, + ]).map(item => ({ name: item.name, count: item.count })); + + const pieConfig: any = { + data: usvTypeData, + angleField: 'count', + colorField: 'name', + radius: 0.7, + innerRadius: 0.5, + color: ['#00b4d8', '#0096c7', '#00e5a0', '#48cae4'], + appendPadding: [20, 10, 5, 10], + label: { + text: (datum: any) => { + const name = datum?.name || ''; + const count = datum?.count ?? 0; + const total = usvTypeData.reduce((sum, d) => sum + (d.count || 0), 0); + const percent = total > 0 ? ((count / total) * 100).toFixed(1) : 0; + return `${name}\n${percent}%`; + }, + style: { + fill: 'rgba(200,230,255,0.95)', + fontSize: 10, + fontWeight: 600, + textAlign: 'center', + }, + offset: 20, + }, + legend: { + position: 'bottom', + offsetY: -10, + itemValue: { + style: { fill: 'rgba(200,230,255,0.75)', fontSize: 10 } + }, + itemName: { + style: { fill: 'rgba(200,230,255,0.75)', fontSize: 10 } + }, + itemSpacing: 6, + layout: 'horizontal', + }, + statistic: { + title: { + style: { fontSize: 11, fill: 'rgba(200,230,255,0.65)' }, + content: '设备总数', + }, + content: { + style: { fontSize: 16, fontWeight: 'bold', fill: '#00e5a0' }, + formatter: () => { + const total = usvTypeData.reduce((sum, d) => sum + (d.count || 0), 0); + return `${total}`; + }, + }, + }, + autoFit: true, + }; + + return ( + + 设备类型分布 + + } + className="maritime-card" + size="small" + styles={{ + body: { + padding: 0, + display: 'flex', + flexDirection: 'column', + alignItems: 'center', + justifyContent: 'flex-start', + overflow: 'visible', + height: '100%', + }, + }} + > +
+ +
+
+ ); +}; + +export default DeviceTypeCard; diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/MaritimeAlertCard.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/components/MaritimeAlertCard.tsx new file mode 100644 index 00000000..08f205e8 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/MaritimeAlertCard.tsx @@ -0,0 +1,58 @@ +import React from 'react'; +import { Card, List, Tag } from 'antd'; +import { WarningOutlined } from '@ant-design/icons'; +import dayjs from 'dayjs'; +import type { AlertItem } from '@/services/dashboard'; + +interface MaritimeAlertCardProps { + alerts: AlertItem[]; +} + +const getAlertColor = (level: string) => { + switch (level) { + case 'critical': return '#ff4757'; + case 'error': return '#ff9f43'; + case 'warning': return '#feca57'; + default: return '#54a0ff'; + } +}; + +const MaritimeAlertCard: React.FC = ({ alerts }) => { + return ( + + 实时告警 + + } + extra={LIVE} + className="maritime-card" + size="small" + > +
+ ( + +
+
+ {item.level.toUpperCase().slice(0, 1)} +
+
+
+ {item.deviceName || item.taskName} + {dayjs(item.timestamp).format('HH:mm')} +
+
{item.message}
+
+
+
+ )} + /> +
+
+ ); +}; + +export default MaritimeAlertCard; diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/MaritimeInsightCard.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/components/MaritimeInsightCard.tsx new file mode 100644 index 00000000..e79dd668 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/MaritimeInsightCard.tsx @@ -0,0 +1,146 @@ +import React from 'react'; +import { Card, Tabs } from 'antd'; +import { FundOutlined } from '@ant-design/icons'; +import { Line, Pie, Rose } from '@ant-design/plots'; +import type { TaskStats, TrendItem } from '@/services/dashboard'; + +interface MaritimeInsightCardProps { + taskStats: TaskStats | null; + taskTrend: TrendItem[]; + violationAnalysisData: any[]; +} + +const MaritimeInsightCard: React.FC = ({ + taskStats, + taskTrend, + violationAnalysisData, +}) => { + // 任务趋势配置 + const taskTrendSeriesData = taskTrend.flatMap((t) => [ + { date: t.date, type: '下发', value: t.created || 0 }, + { date: t.date, type: '完成', value: t.completed || 0 }, + { date: t.date, type: '失败', value: t.failed || 0 }, + ]); + + const taskTrendConfig: any = { + data: taskTrendSeriesData, + xField: 'date', + yField: 'value', + seriesField: 'type', + smooth: true, + color: ['#00b4d8', '#00e5a0', '#ff9f43'], + areaStyle: { + fill: 'l(270) 0:#ffffff 0.5:#7ec2f3 1:#0077b6', + fillOpacity: 0.1, + }, + xAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } }, grid: null }, + yAxis: { + label: { style: { fill: 'rgba(200,230,255,0.65)' } }, + grid: { line: { style: { stroke: 'rgba(0,150,200,0.1)' } } }, + }, + tooltip: { showMarkers: true }, + autoFit: true, + }; + + // 任务状态饼图配置 + const taskStatusPieConfig: any = { + data: [ + { name: '待执行', value: taskStats?.pending || 0 }, + { name: '执行中', value: taskStats?.running || 0 }, + { name: '已完成', value: taskStats?.completed || 0 }, + { name: '已失败', value: taskStats?.failed || 0 }, + ], + angleField: 'value', + colorField: 'name', + radius: 0.85, + innerRadius: 0.55, + color: ['#ffa502', '#00b4d8', '#00e5a0', '#ff6b6b'], + label: { + text: (datum: any) => { + const name = datum?.name || ''; + const value = datum?.value ?? 0; + const total = + (taskStats?.pending || 0) + + (taskStats?.running || 0) + + (taskStats?.completed || 0) + + (taskStats?.failed || 0); + const percent = total > 0 ? ((value / total) * 100).toFixed(1) : 0; + return `${name} ${percent}%`; + }, + style: { fill: 'rgba(200,230,255,0.85)', fontSize: 12, fontWeight: 600 }, + }, + legend: { + position: 'bottom', + itemValue: { style: { fill: 'rgba(200,230,255,0.75)' } }, + itemName: { style: { fill: 'rgba(200,230,255,0.75)' } }, + }, + autoFit: true, + }; + + // 违规分析玫瑰图配置 + const roseConfig: any = { + data: violationAnalysisData, + xField: 'type', + yField: 'value', + seriesField: 'type', + radius: 0.9, + color: ['#ff6b6b', '#ffa502', '#ff9f43', '#00b4d8', '#48cae4', '#90e0ef'], + label: { + text: (datum: any) => datum?.type || '', + style: { fill: '#fff', fontSize: 10 }, + }, + legend: { + position: 'bottom', + itemName: { style: { fill: 'rgba(200,230,255,0.75)' } }, + }, + autoFit: true, + }; + + return ( + + 综合分析洞察 + + } + className="maritime-card maritime-insight-card" + size="small" + > + + +
+ ), + }, + { + key: 'status', + label: '任务状态占比', + children: ( +
+ +
+ ), + }, + { + key: 'violation', + label: '违规类型分析', + children: ( +
+ +
+ ), + }, + ]} + /> + + ); +}; + +export default MaritimeInsightCard; diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/MaritimeKpiStrip.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/components/MaritimeKpiStrip.tsx new file mode 100644 index 00000000..9639e339 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/MaritimeKpiStrip.tsx @@ -0,0 +1,77 @@ +import React from 'react'; +import { EnvironmentOutlined, RocketOutlined, PieChartOutlined } from '@ant-design/icons'; +import './maritime-card.less'; + +// 无人船图标组件 +const USVIcon = () => ( + + + +); + +interface MaritimeKpiStripProps { + deviceTotal: number; + seaAreaCount: number; + todayNew: number; + successRate: number; + taskNewLabel?: string; +} + +const MaritimeKpiStrip: React.FC = ({ + deviceTotal, + seaAreaCount, + todayNew, + successRate, + taskNewLabel = '当日任务', +}) => { + const kpis = [ + { + key: 'ship', + label: '设备总数', + value: deviceTotal, + icon: , + accent: 'ship', + }, + { + key: 'area', + label: '海域总数', + value: seaAreaCount, + icon: , + accent: 'anchor', + }, + { + key: 'task', + label: taskNewLabel, + value: todayNew, + icon: , + accent: 'alert', + }, + { + key: 'rate', + label: '执行成功率', + value: successRate, + unit: '%', + icon: , + accent: 'route', + }, + ]; + + return ( +
+ {kpis.map((kpi) => ( +
+
{kpi.icon}
+
+
{kpi.label}
+
+ {kpi.value} + {kpi.unit && {kpi.unit}} +
+
+
+ ))} +
+ ); +}; + +export default MaritimeKpiStrip; diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/PortStatusCard.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/components/PortStatusCard.tsx new file mode 100644 index 00000000..e18227a8 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/PortStatusCard.tsx @@ -0,0 +1,81 @@ +import React, { useMemo } from 'react'; +import { Card } from 'antd'; +import { AimOutlined } from '@ant-design/icons'; +import type { DeviceStats, TaskStats, AlertItem } from '@/services/dashboard'; + +interface PortStatusCardProps { + deviceStats: DeviceStats | null; + taskStats: TaskStats | null; + alerts: AlertItem[]; +} + +const PortStatusCard: React.FC = ({ + deviceStats, + taskStats, + alerts, +}) => { + const portStatusData = useMemo(() => { + const totalShips = deviceStats?.total || 24; + const pendingTasks = taskStats?.pending || 6; + const runningTasks = taskStats?.running || 3; + const alertBase = alerts.length || 4; + const baseShips = Math.max(6, Math.round(totalShips / 3)); + + return [ + { + name: '东港枢纽', + ships: baseShips + 3, + tasks: pendingTasks + 2, + alerts: Math.max(1, Math.round(alertBase * 0.4)), + }, + { + name: '西湾港区', + ships: baseShips + 1, + tasks: Math.max(1, pendingTasks + 1), + alerts: Math.max(1, Math.round(alertBase * 0.3)), + }, + { + name: '南航道', + ships: Math.max(4, baseShips - 1), + tasks: Math.max(1, runningTasks + 1), + alerts: Math.max(0, Math.round(alertBase * 0.2)), + }, + ]; + }, [alerts.length, deviceStats, taskStats]); + + return ( + + 重点港口状态 + + } + className="maritime-card" + size="small" + > +
+ {portStatusData.map((item) => ( +
+
{item.name}
+
+
+
{item.ships}
+
在线船只
+
+
+
{item.tasks}
+
巡检任务
+
+
+
{item.alerts}
+
告警
+
+
+
+ ))} +
+
+ ); +}; + +export default PortStatusCard; diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/SeaAreaPortal.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/components/SeaAreaPortal.tsx new file mode 100644 index 00000000..3471c781 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/SeaAreaPortal.tsx @@ -0,0 +1,28 @@ +import React from 'react'; +import { Button } from 'antd'; +import { CompassOutlined } from '@ant-design/icons'; +import { history } from 'umi'; + +const SeaAreaPortal: React.FC = () => { + const goTo3D = () => { + history.push('/map3d?from=maritime'); + }; + + return ( +
+
+
+
+
+ +

海域智慧巡检监控中心

+ +
+
+
+ ); +}; + +export default SeaAreaPortal; diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/TaskOverviewCard.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/components/TaskOverviewCard.tsx new file mode 100644 index 00000000..0da4c723 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/TaskOverviewCard.tsx @@ -0,0 +1,185 @@ +import React, { useMemo } from 'react'; +import { Card, DatePicker, Segmented, Space, Progress } from 'antd'; +import { LineChartOutlined, RiseOutlined, FallOutlined } from '@ant-design/icons'; +import type { Dayjs } from 'dayjs'; +import type { TaskStats } from '@/services/dashboard'; + +interface TaskOverviewCardProps { + taskStats: TaskStats | null; + taskStatType: 'day' | 'month' | 'year'; + taskStatDate: Dayjs; + onStatTypeChange: (type: 'day' | 'month' | 'year') => void; + onDateChange: (date: Dayjs) => void; +} + +const TaskOverviewCard: React.FC = ({ + taskStats, + taskStatType, + taskStatDate, + onStatTypeChange, + onDateChange, +}) => { + const taskPeriodText = useMemo(() => { + if (taskStatType === 'day') return '当日'; + if (taskStatType === 'month') return '当月'; + return '当年'; + }, [taskStatType]); + + const datePickerFormat = useMemo(() => { + if (taskStatType === 'day') return 'YYYY-MM-DD'; + if (taskStatType === 'month') return 'YYYY-MM'; + return 'YYYY'; + }, [taskStatType]); + + // 计算额外统计数据 + const extraStats = useMemo(() => { + const total = (taskStats?.pending || 0) + (taskStats?.running || 0) + + (taskStats?.completed || 0) + (taskStats?.failed || 0); + const completed = taskStats?.completed || 0; + const failed = taskStats?.failed || 0; + const running = taskStats?.running || 0; + + // 模拟同比增长率 + const growthRate = Math.floor(Math.random() * 30) - 10; // -10% ~ +20% + + // 计算完成率 + const completionRate = total > 0 ? Math.round((completed / total) * 100) : 0; + + // 计算失败率 + const failureRate = total > 0 ? Math.round((failed / total) * 100) : 0; + + // 计算平均响应时间(分钟) + const avgResponseTime = Math.floor(Math.random() * 20) + 10; // 10-30分钟 + + return { + total, + growthRate, + completionRate, + failureRate, + avgResponseTime, + }; + }, [taskStats]); + + return ( + + {taskPeriodText}巡检任务概览 + + } + extra={ + + onStatTypeChange(v as any)} + /> + v && onDateChange(v)} + picker={taskStatType === 'day' ? 'date' : taskStatType} + allowClear={false} + format={datePickerFormat} + /> + + } + className="maritime-card" + size="small" + > + {/* 主要状态网格 */} +
+
+
{taskStats?.pending || 0}
+
待执行
+
+
+
{taskStats?.running || 0}
+
执行中
+
+
+
{taskStats?.completed || 0}
+
已完成
+
+
+
{taskStats?.failed || 0}
+
已失败
+
+
+ + {/* 成功率展示 */} +
+
{taskStats?.successRate || 0}%
+
{taskPeriodText}成功率
+
+ + {/* 新增:详细统计信息 */} +
+
+
+
+ 任务总量 + {extraStats.growthRate >= 0 ? ( + + ) : ( + + )} +
+
{extraStats.total}
+
= 0 ? '#00e5a0' : '#ff6b6b' }}> + 同比 {extraStats.growthRate >= 0 ? '+' : ''}{extraStats.growthRate}% +
+
+
+
平均响应
+
{extraStats.avgResponseTime}分
+
任务平均响应时间
+
+
+ + {/* 完成率和失败率进度条 */} +
+
+
+ 完成率 + {extraStats.completionRate}% +
+ +
+
+
+ 失败率 + {extraStats.failureRate}% +
+ +
+
+
+
+ ); +}; + +export default TaskOverviewCard; diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/TaskTypeChart.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/components/TaskTypeChart.tsx new file mode 100644 index 00000000..c92c9a68 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/TaskTypeChart.tsx @@ -0,0 +1,105 @@ +import React from 'react'; +import { Card } from 'antd'; +import { BarChartOutlined } from '@ant-design/icons'; +import { Column } from '@ant-design/plots'; + +interface TaskTypeChartProps { + taskTypeData: any[]; +} + +const TaskTypeChart: React.FC = ({ taskTypeData }) => { + const columnConfig: any = { + data: taskTypeData, + xField: 'type', + yField: 'value', + seriesField: 'type', + appendPadding: [20, 10, 10, 10], + color: ({ type }: any) => { + if (type === '航线巡检') return '#00b4d8'; + if (type === '定点监测') return '#00e5a0'; + return '#ff9f43'; + }, + columnStyle: { + radius: [6, 6, 0, 0], + }, + label: { + text: (datum: any) => datum?.value?.toString() || '0', + style: { + fill: '#fff', + fontSize: 11, + fontWeight: 600, + textAlign: 'center', + }, + position: 'top', + offset: 6, + }, + xAxis: { + label: { + style: { fill: 'rgba(200,230,255,0.75)', fontSize: 10 }, + autoRotate: false, + autoHide: false, + }, + line: { + style: { stroke: 'rgba(0,180,216,0.2)' }, + }, + tickLine: null, + }, + yAxis: { + label: { + style: { fill: 'rgba(200,230,255,0.75)', fontSize: 10 }, + }, + grid: { + line: { style: { stroke: 'rgba(0,150,200,0.15)', lineDash: [4, 4] } }, + }, + line: null, + tickLine: null, + }, + legend: false, + animation: { + appear: { + animation: 'scale-in-y', + duration: 800, + }, + }, + tooltip: { + domStyles: { + 'g2-tooltip': { + background: 'rgba(10, 30, 50, 0.95)', + boxShadow: '0 4px 12px rgba(0,0,0,0.3)', + border: '1px solid rgba(0,180,216,0.3)', + }, + 'g2-tooltip-title': { + color: 'rgba(200,230,255,0.95)', + }, + 'g2-tooltip-list-item': { + color: 'rgba(200,230,255,0.85)', + }, + }, + }, + autoFit: true, + }; + + return ( + + 任务类型统计 + + } + className="maritime-card" + size="small" + styles={{ + body: { + padding: '8px 8px 4px 8px', + overflow: 'visible', + }, + }} + > +
+ +
+
+ ); +}; + +export default TaskTypeChart; diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/WeatherCard.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/components/WeatherCard.tsx new file mode 100644 index 00000000..b0b65d28 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/WeatherCard.tsx @@ -0,0 +1,41 @@ +import React, { useMemo } from 'react'; +import { Card } from 'antd'; +import { + CloudOutlined, + CompassOutlined, + DashboardOutlined, + RiseOutlined, +} from '@ant-design/icons'; + +const WeatherCard: React.FC = () => { + const weatherMetrics = useMemo(() => ([ + { label: '风速', value: '4.6 m/s', icon: }, + { label: '浪高', value: '1.2 m', icon: }, + { label: '能见度', value: '7.8 km', icon: }, + { label: '潮位', value: '2.4 m', icon: }, + ]), []); + + return ( + + 海况与气象 + + } + className="maritime-card" + size="small" + > +
+ {weatherMetrics.map((item) => ( +
+
{item.icon}
+
{item.value}
+
{item.label}
+
+ ))} +
+
+ ); +}; + +export default WeatherCard; diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/index.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/components/index.tsx new file mode 100644 index 00000000..a0e6e179 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/index.tsx @@ -0,0 +1,10 @@ +export { default as MaritimeKpiStrip } from './MaritimeKpiStrip'; +export { default as DeviceTypeCard } from './DeviceTypeCard'; +export { default as PortStatusCard } from './PortStatusCard'; +export { default as MaritimeAlertCard } from './MaritimeAlertCard'; +export { default as WeatherCard } from './WeatherCard'; +export { default as SeaAreaPortal } from './SeaAreaPortal'; +export { default as AnnualTrendChart } from './AnnualTrendChart'; +export { default as TaskTypeChart } from './TaskTypeChart'; +export { default as TaskOverviewCard } from './TaskOverviewCard'; +export { default as MaritimeInsightCard } from './MaritimeInsightCard'; diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/components/maritime-card.less b/zlt-web/yingyan/src/pages/maritime/dashboard/components/maritime-card.less new file mode 100644 index 00000000..63baa6a7 --- /dev/null +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/components/maritime-card.less @@ -0,0 +1,623 @@ +/* 海事大屏组件样式 */ + +.maritime-card { + height: 100%; + min-height: 0; + max-height: 100%; + display: flex; + flex-direction: column; + background: rgba(14, 34, 64, 0.75) !important; + border: 1px solid rgba(0, 180, 216, 0.2) !important; + border-radius: 8px; + overflow: hidden; + backdrop-filter: blur(8px); + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); + + &::before { + content: ''; + position: absolute; + inset: 0; + pointer-events: none; + background: + linear-gradient(90deg, rgba(0, 180, 216, 0.5), transparent 50px) top left / 50px 2px no-repeat, + linear-gradient(180deg, rgba(0, 180, 216, 0.5), transparent 50px) top left / 2px 50px no-repeat, + linear-gradient(270deg, rgba(0, 180, 216, 0.5), transparent 50px) top right / 50px 2px no-repeat, + linear-gradient(180deg, rgba(0, 180, 216, 0.5), transparent 50px) top right / 2px 50px no-repeat, + linear-gradient(90deg, rgba(0, 180, 216, 0.5), transparent 50px) bottom left / 50px 2px no-repeat, + linear-gradient(0deg, rgba(0, 180, 216, 0.5), transparent 50px) bottom left / 2px 50px no-repeat, + linear-gradient(270deg, rgba(0, 180, 216, 0.5), transparent 50px) bottom right / 50px 2px no-repeat, + linear-gradient(0deg, rgba(0, 180, 216, 0.5), transparent 50px) bottom right / 2px 50px no-repeat; + opacity: 0.4; + } + + :global(.ant-card-head) { + min-height: 40px; + padding: 0 12px; + border-bottom: 1px solid rgba(0, 180, 216, 0.15); + flex: 0 0 auto; + } + + :global(.ant-card-body) { + flex: 1; + padding: 12px; + overflow: hidden; + position: relative; + display: flex; + flex-direction: column; + min-height: 0; + } +} + +/* KPI 指标条样式 */ +.maritime-kpi-strip { + display: grid; + grid-template-columns: repeat(4, 1fr); + gap: 12px; + width: 100%; + padding: 0; +} + +.maritime-kpi-tile { + display: flex; + align-items: center; + gap: 12px; + padding: 12px 16px; + border-radius: 8px; + background: rgba(14, 34, 64, 0.7); + border: 1px solid rgba(0, 180, 216, 0.18); + transition: all 0.3s ease; + + &:hover { + transform: translateY(-2px); + border-color: rgba(0, 180, 216, 0.35); + box-shadow: 0 6px 16px rgba(0, 180, 216, 0.15); + } + + &--ship .maritime-kpi-tile__icon { + color: #00b4d8; + background: rgba(0, 180, 216, 0.15); + } + + &--anchor .maritime-kpi-tile__icon { + color: #00e5a0; + background: rgba(0, 229, 160, 0.15); + } + + &--alert .maritime-kpi-tile__icon { + color: #ff9f43; + background: rgba(255, 159, 67, 0.15); + } + + &--route .maritime-kpi-tile__icon { + color: #48cae4; + background: rgba(72, 202, 228, 0.15); + } +} + +.maritime-kpi-tile__icon { + flex: 0 0 auto; + width: 40px; + height: 40px; + display: flex; + align-items: center; + justify-content: center; + font-size: 20px; + border-radius: 8px; +} + +.maritime-kpi-tile__info { + flex: 1; + min-width: 0; +} + +.maritime-kpi-tile__label { + font-size: 13px; + color: rgba(200, 230, 255, 0.75); + line-height: 1.3; +} + +.maritime-kpi-tile__value { + font-size: 24px; + font-weight: 800; + color: rgba(255, 255, 255, 0.95); + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; + margin-top: 2px; + + small { + font-size: 16px; + font-weight: 700; + margin-left: 2px; + } +} + +/* 图表容器样式 */ +.maritime-chart-wrapper { + flex: 1; + width: 100%; + min-height: 0; + overflow: hidden; + + > div { + width: 100%; + height: 100%; + } + + :global(canvas) { + max-width: 100%; + max-height: 100%; + } +} + +/* 港口状态列表样式 */ +.port-status-list { + display: flex; + flex-direction: column; + gap: 12px; +} + +.port-item { + padding: 12px; + border-radius: 8px; + background: rgba(255, 255, 255, 0.03); + border: 1px solid rgba(0, 180, 216, 0.12); +} + +.port-name { + font-size: 14px; + font-weight: 600; + color: rgba(200, 230, 255, 0.92); + margin-bottom: 10px; +} + +.port-stats { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 8px; + + .stat { + text-align: center; + + .num { + font-size: 20px; + font-weight: 800; + color: #00b4d8; + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; + } + + .txt { + font-size: 11px; + color: rgba(200, 230, 255, 0.65); + margin-top: 4px; + } + } +} + +/* 告警列表样式 */ +.alert-list-container { + flex: 1; + min-height: 0; + overflow-y: auto; + overflow-x: hidden; + padding-right: 4px; + + &::-webkit-scrollbar { + width: 4px; + } + + &::-webkit-scrollbar-thumb { + background: rgba(0, 180, 216, 0.3); + border-radius: 2px; + } +} + +.maritime-alert-item { + padding: 10px 0 !important; + border-bottom: 1px solid rgba(0, 180, 216, 0.08) !important; + + .alert-row { + display: flex; + gap: 10px; + align-items: flex-start; + width: 100%; + } + + .alert-badge { + flex: 0 0 auto; + } + + .alert-content { + flex: 1; + min-width: 0; + } + + .alert-head { + display: flex; + justify-content: space-between; + gap: 10px; + margin-bottom: 4px; + } + + .alert-name { + font-size: 13px; + font-weight: 600; + color: rgba(200, 230, 255, 0.92); + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } + + .alert-time { + font-size: 12px; + color: rgba(200, 230, 255, 0.55); + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; + } + + .alert-msg { + font-size: 12px; + color: rgba(200, 230, 255, 0.65); + line-height: 1.4; + } +} + +/* 天气面板样式 */ +.weather-panel { + display: grid; + grid-template-columns: repeat(2, 1fr); + gap: 12px; +} + +.weather-item { + display: flex; + flex-direction: column; + align-items: center; + padding: 16px 12px; + border-radius: 8px; + background: rgba(255, 255, 255, 0.03); + border: 1px solid rgba(0, 180, 216, 0.12); + transition: all 0.3s ease; + + &:hover { + background: rgba(255, 255, 255, 0.05); + border-color: rgba(0, 180, 216, 0.25); + } + + .weather-icon { + font-size: 28px; + color: #00b4d8; + margin-bottom: 8px; + } + + .weather-value { + font-size: 18px; + font-weight: 800; + color: rgba(255, 255, 255, 0.95); + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; + margin-bottom: 4px; + } + + .weather-label { + font-size: 12px; + color: rgba(200, 230, 255, 0.65); + } +} + +/* 海域门户样式 */ +.sea-area-portal { + position: relative; + height: 100%; + min-height: 0; + background: rgba(14, 34, 64, 0.75); + border: 1px solid rgba(0, 180, 216, 0.2); + border-radius: 8px; + overflow: hidden; + display: flex; + align-items: center; + justify-content: center; + + .nautical-grid { + position: absolute; + inset: 0; + background-image: + linear-gradient(rgba(0, 180, 216, 0.12) 1px, transparent 1px), + linear-gradient(90deg, rgba(0, 180, 216, 0.12) 1px, transparent 1px); + background-size: 40px 40px; + opacity: 0.4; + } + + .compass-sweep { + position: absolute; + inset: 0; + background: radial-gradient(circle at center, rgba(0, 180, 216, 0.18), transparent 60%); + animation: pulse 3s ease-in-out infinite; + } + + .portal-content { + position: relative; + z-index: 2; + text-align: center; + } + + .portal-center { + display: flex; + flex-direction: column; + align-items: center; + } + + .portal-title { + font-size: 22px; + font-weight: 700; + color: rgba(255, 255, 255, 0.92); + margin-bottom: 20px; + text-shadow: 0 2px 8px rgba(0, 180, 216, 0.3); + } + + .portal-btn { + background: linear-gradient(135deg, #00b4d8, #0096c7); + border: none; + box-shadow: 0 4px 16px rgba(0, 180, 216, 0.3); + transition: all 0.3s ease; + + &:hover { + transform: translateY(-2px); + box-shadow: 0 6px 20px rgba(0, 180, 216, 0.4); + } + } +} + +@keyframes pulse { + 0%, 100% { opacity: 0.3; } + 50% { opacity: 0.5; } +} + +/* 面板分割样式 */ +.panel-split { + flex: 1; + min-height: 0; + display: grid; + grid-template-columns: 1fr 1fr; + gap: 12px; + overflow: hidden; +} + +.panel-section { + min-height: 0; + display: flex; + flex-direction: column; + overflow: hidden; +} + +.panel-subtitle { + margin: 0 0 8px; + font-size: 12px; + color: rgba(200, 230, 255, 0.65); + letter-spacing: 0.2px; + flex: 0 0 auto; +} + +/* 任务筛选器样式 */ +.task-filter { + :global(.ant-segmented) { + background: rgba(0, 180, 216, 0.08); + border: 1px solid rgba(0, 180, 216, 0.2); + } + + :global(.ant-segmented-item-label) { + color: rgba(200, 230, 255, 0.85); + font-size: 12px; + } + + :global(.ant-segmented-item-selected) { + background: rgba(0, 180, 216, 0.25) !important; + } + + :global(.ant-picker) { + background: rgba(0, 180, 216, 0.08); + border: 1px solid rgba(0, 180, 216, 0.2); + color: rgba(200, 230, 255, 0.85); + } + + :global(.ant-picker-input > input) { + color: rgba(200, 230, 255, 0.85); + font-size: 12px; + } + + :global(.ant-picker-suffix) { + color: rgba(200, 230, 255, 0.65); + } +} + +/* 船只状态网格 */ +.ship-status-grid { + display: grid; + grid-template-columns: repeat(4, 1fr); + gap: 12px; + margin-bottom: 16px; +} + +.ship-stat-box { + padding: 12px; + border-radius: 8px; + background: rgba(255, 255, 255, 0.03); + border: 1px solid rgba(0, 180, 216, 0.12); + text-align: center; + + .val { + font-size: 24px; + font-weight: 800; + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; + margin-bottom: 4px; + + &.sailing { color: #ffa502; } + &.anchored { color: #00b4d8; } + &.docked { color: #00e5a0; } + &.warning { color: #ff6b6b; } + } + + .lbl { + font-size: 12px; + color: rgba(200, 230, 255, 0.65); + } +} + +/* 任务成功率 */ +.task-success { + padding: 16px; + border-radius: 8px; + background: linear-gradient(135deg, rgba(0, 229, 160, 0.12), rgba(0, 180, 216, 0.08)); + border: 1px solid rgba(0, 229, 160, 0.2); + text-align: center; + margin-bottom: 16px; + + .rate { + font-size: 32px; + font-weight: 900; + color: #00e5a0; + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; + text-shadow: 0 2px 8px rgba(0, 229, 160, 0.3); + } + + .label { + font-size: 13px; + color: rgba(200, 230, 255, 0.75); + margin-top: 4px; + } +} + +/* 任务详细统计 */ +.task-detail-stats { + display: flex; + flex-direction: column; + gap: 12px; + + .stat-row { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 12px; + } + + .stat-item { + padding: 12px; + border-radius: 8px; + background: rgba(255, 255, 255, 0.03); + border: 1px solid rgba(0, 180, 216, 0.12); + text-align: center; + + .stat-label { + font-size: 12px; + color: rgba(200, 230, 255, 0.65); + margin-bottom: 6px; + display: flex; + align-items: center; + justify-content: center; + } + + .stat-value { + font-size: 22px; + font-weight: 800; + color: #00b4d8; + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; + margin-bottom: 4px; + + .stat-unit { + font-size: 12px; + margin-left: 2px; + color: rgba(200, 230, 255, 0.75); + } + } + + .stat-sub { + font-size: 11px; + color: rgba(200, 230, 255, 0.55); + } + } + + .progress-row { + display: flex; + flex-direction: column; + gap: 12px; + } + + .progress-item { + padding: 12px; + border-radius: 8px; + background: rgba(255, 255, 255, 0.03); + border: 1px solid rgba(0, 180, 216, 0.12); + + .progress-label { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 8px; + font-size: 12px; + color: rgba(200, 230, 255, 0.75); + + .progress-percent { + font-size: 13px; + font-weight: 700; + color: rgba(255, 255, 255, 0.85); + } + } + + :global(.ant-progress-bg) { + border-radius: 4px; + } + } +} + +/* Tabs 样式 */ +.maritime-tabs { + height: 100%; + min-height: 0; + display: flex; + flex-direction: column; + overflow: hidden; + + :global(.ant-tabs-nav) { + margin: 0 0 8px; + flex: 0 0 auto; + } + + :global(.ant-tabs-nav::before) { + border-bottom-color: rgba(0, 180, 216, 0.15); + } + + :global(.ant-tabs-tab) { + color: rgba(200, 230, 255, 0.65); + } + + :global(.ant-tabs-tab.ant-tabs-tab-active .ant-tabs-tab-btn) { + color: rgba(200, 230, 255, 0.95); + } + + :global(.ant-tabs-ink-bar) { + background: #00b4d8; + } + + :global(.ant-tabs-content-holder) { + flex: 1; + min-height: 0; + overflow: hidden; + } + + :global(.ant-tabs-content) { + height: 100%; + min-height: 0; + } + + :global(.ant-tabs-tabpane) { + height: 100%; + min-height: 0; + padding: 0; + overflow: hidden; + display: flex; + flex-direction: column; + } +} + +.maritime-insight-card { + :global(.ant-card-body) { + display: flex; + flex-direction: column; + min-height: 0; + } +} diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/index.less b/zlt-web/yingyan/src/pages/maritime/dashboard/index.less index 26076528..de622f9d 100644 --- a/zlt-web/yingyan/src/pages/maritime/dashboard/index.less +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/index.less @@ -1,10 +1,27 @@ /* 海事智慧监控服务平台 - 主题样式 */ /* 采用深海蓝色调 + 波浪动效 + 海事元素 - 区别于通用大屏 */ +/* 导入组件样式 */ +@import './components/maritime-card.less'; + .maritime-dashboard { position: relative; width: 100%; height: 100%; + min-height: 0; + min-width: 0; + flex: 1; + font-size: clamp(11px, 1.0vh, 13px); + --mar-pad-x: clamp(10px, 1.1vw, 14px); + --mar-pad-y: clamp(8px, 0.9vh, 12px); + --mar-gap: clamp(8px, 0.9vh, 12px); + --mar-kpi-h: clamp(62px, 7.2vh, 78px); + --mar-card-head-h: clamp(32px, 3.6vh, 38px); + --mar-card-body-pad: clamp(6px, 0.9vh, 10px); + --mar-frame-h: clamp(14px, 2.0vh, 20px); + --mar-frame-gap: clamp(4px, 0.6vh, 8px); + /* 重要:避免中心入口的 min-height 撑破网格,导致底部卡片被挤出屏幕 */ + --mar-map-min: 0px; background: linear-gradient(180deg, #020c1b 0%, #051525 25%, @@ -107,42 +124,146 @@ } } +.maritime-dashboard--compact-1 { + --mar-pad-x: clamp(8px, 0.95vw, 12px); + --mar-pad-y: clamp(6px, 0.75vh, 10px); + --mar-gap: clamp(6px, 0.75vh, 10px); + --mar-kpi-h: clamp(56px, 6.4vh, 70px); + --mar-card-head-h: clamp(30px, 3.2vh, 36px); + --mar-card-body-pad: clamp(6px, 0.75vh, 9px); + --mar-frame-h: clamp(12px, 1.8vh, 18px); + --mar-frame-gap: clamp(3px, 0.5vh, 7px); + --mar-map-min: 0px; +} + +.maritime-dashboard--compact-2 { + --mar-pad-x: clamp(6px, 0.85vw, 10px); + --mar-pad-y: clamp(4px, 0.65vh, 8px); + --mar-gap: clamp(5px, 0.65vh, 8px); + --mar-kpi-h: clamp(52px, 6vh, 64px); + --mar-card-head-h: clamp(28px, 3.0vh, 34px); + --mar-card-body-pad: clamp(5px, 0.65vh, 8px); + --mar-frame-h: clamp(10px, 1.6vh, 16px); + --mar-frame-gap: clamp(3px, 0.45vh, 6px); + --mar-map-min: 0px; +} + /* 主内容区域 */ .maritime-spin { height: 100%; + min-height: 0; + display: block; + flex: 1; + width: 100%; :global(.ant-spin-container) { height: 100%; display: flex; flex-direction: column; + min-height: 0; + width: 100%; } } .maritime-content { flex: 1; - padding: 16px 18px; + padding: var(--mar-pad-y) var(--mar-pad-x); + /* 参考智慧城市:底部装饰条保留但尽量少占内容区高度 */ + padding-bottom: calc(var(--mar-pad-y) + var(--mar-frame-h)); overflow: hidden; position: relative; z-index: 1; height: 100%; + min-height: 0; + display: flex; + flex-direction: column; + width: 100%; + box-sizing: border-box; +} + +.maritime-bottom-frame { + position: absolute; + left: clamp(12px, 1.6vw, 26px); + right: clamp(12px, 1.6vw, 26px); + bottom: clamp(6px, 0.8vh, 12px); + height: var(--mar-frame-h); + border-radius: 12px; + z-index: 2; + pointer-events: none; + background: + linear-gradient( + 90deg, + rgba(0, 120, 180, 0.08), + rgba(0, 180, 230, 0.7) 34%, + rgba(0, 229, 160, 0.45) 50%, + rgba(0, 180, 230, 0.7) 66%, + rgba(0, 120, 180, 0.08) + ) bottom/100% 2px no-repeat, + linear-gradient(90deg, rgba(0, 220, 255, 0.85), transparent 90px) bottom left/90px 2px no-repeat, + linear-gradient(270deg, rgba(0, 220, 255, 0.85), transparent 90px) bottom right/90px 2px no-repeat, + linear-gradient(180deg, rgba(0, 180, 230, 0.6), transparent 80%) bottom left/2px 100% no-repeat, + linear-gradient(180deg, rgba(0, 180, 230, 0.6), transparent 80%) bottom right/2px 100% no-repeat; + box-shadow: 0 -6px 18px rgba(0, 120, 180, 0.3); + + &::before { + content: ''; + position: absolute; + left: 50%; + bottom: 6px; + width: clamp(120px, 18vw, 220px); + height: 6px; + transform: translateX(-50%); + border-radius: 999px; + background: linear-gradient(90deg, transparent, rgba(0, 220, 255, 0.85), transparent); + box-shadow: 0 0 12px rgba(0, 180, 230, 0.4); + opacity: 0.85; + } } .maritime-grid { display: grid; - grid-template-columns: 25% 50% 25%; - grid-template-rows: 100%; - gap: 14px; + grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr); + grid-template-rows: minmax(0, 1fr); + gap: var(--mar-gap); + /* 只用 flex 约束高度,避免百分比高度在某些容器链路下变成不确定值 */ + flex: 1; + width: 100%; + min-height: 0; + min-width: 0; + justify-items: stretch; + align-items: stretch; +} + +.maritime-dashboard .grid-col { + display: grid; + gap: var(--mar-gap); height: 100%; + overflow: hidden; + min-height: 0; + min-width: 0; width: 100%; } -.grid-col { - display: flex; - flex-direction: column; - gap: 14px; - height: 100%; +.maritime-dashboard .grid-col > * { + min-height: 0; + max-height: 100%; overflow: hidden; } +.maritime-dashboard .grid-col.left-col { + /* 4张卡片:上两张偏“静态概览”稍矮,告警为主要信息流更高,海况为补充更矮 */ + grid-template-rows: minmax(0, 0.9fr) minmax(0, 0.85fr) minmax(0, 1.35fr) minmax(0, 0.55fr); +} + +.maritime-dashboard .grid-col.right-col { + /* 4张卡片:概览较高,其余三张均衡 */ + grid-template-rows: minmax(0, 1.15fr) minmax(0, 0.95fr) minmax(0, 1fr) minmax(0, 0.9fr); +} + +.maritime-dashboard .grid-col.center-col { + /* 参考智慧城市:固定 KPI + 其余区域按比例分配,避免底部卡片被挤出屏幕 */ + grid-template-rows: var(--mar-kpi-h) minmax(0, 1.35fr) minmax(0, 0.85fr); +} + /* 海事风格玻璃面板 */ .panel-card { background: transparent !important; @@ -180,22 +301,22 @@ } :global(.ant-card-head) { - min-height: 42px; - padding: 0 14px; + min-height: var(--mar-card-head-h); + padding: 0 12px; border-bottom: 1px solid rgba(0, 180, 230, 0.15); background: linear-gradient(90deg, rgba(0, 100, 150, 0.2), transparent); .ant-card-head-title { - font-size: 15px; + font-size: 13px; color: #e0f7ff; - padding: 10px 0; + padding: 8px 0; letter-spacing: 1px; } } :global(.ant-card-body) { flex: 1; - padding: 12px; + padding: var(--mar-card-body-pad); overflow: hidden; position: relative; display: flex; @@ -203,6 +324,49 @@ } } +.panel-block { + height: 100%; + min-height: 0; +} + +.panel-split { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: var(--mar-gap); + height: 100%; + min-height: 0; +} + +.panel-split--ratio { + grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr); +} + +.panel-stack { + display: grid; + grid-template-rows: repeat(2, minmax(0, 1fr)); + gap: var(--mar-gap); + height: 100%; + min-height: 0; +} + +.panel-stack--alert { + grid-template-rows: minmax(0, 1.3fr) minmax(0, 0.7fr); +} + +.panel-section { + display: flex; + flex-direction: column; + min-height: 0; + overflow: hidden; +} + +.panel-subtitle { + font-size: 12px; + color: rgba(200, 230, 255, 0.7); + letter-spacing: 1px; + margin-bottom: 6px; +} + .chart-wrapper { flex: 1; width: 100%; @@ -222,8 +386,8 @@ .kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); - gap: 12px; - height: 85px; + gap: var(--mar-gap); + height: var(--mar-kpi-h); } .kpi-card { @@ -232,7 +396,7 @@ border-radius: 8px; display: flex; align-items: center; - padding: 0 16px; + padding: 0 12px; position: relative; overflow: hidden; @@ -248,10 +412,10 @@ } .kpi-icon { - font-size: 26px; - margin-right: 14px; - width: 46px; - height: 46px; + font-size: 22px; + margin-right: 10px; + width: 40px; + height: 40px; border-radius: 50%; display: flex; align-items: center; @@ -267,7 +431,7 @@ .kpi-info { .label { font-size: 12px; color: rgba(200, 230, 255, 0.7); } .value { - font-size: 26px; + font-size: 22px; font-weight: bold; color: #fff; font-family: 'Segoe UI', sans-serif; @@ -281,6 +445,8 @@ /* 中央海图监控区域 */ .map-portal-wrapper { flex: 2; + min-height: var(--mar-map-min); + height: 100%; position: relative; background: linear-gradient(180deg, rgba(0, 40, 80, 0.5) 0%, rgba(0, 60, 100, 0.3) 100%); border: 1px solid rgba(0, 180, 230, 0.35); @@ -353,8 +519,8 @@ .portal-center { text-align: center; - width: 320px; - height: 320px; + width: clamp(240px, 16vw, 300px); + height: clamp(240px, 16vw, 300px); display: flex; flex-direction: column; align-items: center; @@ -385,16 +551,16 @@ .portal-title { color: #e0f7ff; - margin-bottom: 20px; - font-size: 20px; + margin-bottom: 14px; + font-size: 18px; letter-spacing: 3px; text-shadow: 0 0 15px rgba(0, 200, 255, 0.5); } .portal-btn { - height: 46px; - padding: 0 36px; - font-size: 15px; + height: 42px; + padding: 0 30px; + font-size: 14px; background: linear-gradient(135deg, #0096c7 0%, #0077b6 100%); border: none; box-shadow: 0 4px 20px rgba(0, 150, 200, 0.4); @@ -412,6 +578,8 @@ /* 告警列表 - 海事风格 */ .alert-list-container { + flex: 1; + min-height: 0; height: 100%; overflow-y: auto; @@ -487,11 +655,31 @@ } } +.task-success { + margin-top: 16px; + text-align: center; + + .rate { + font-size: 32px; + font-weight: bold; + color: #00e5a0; + } + + .label { + font-size: 14px; + color: #e0f7ff; + margin-top: 4px; + } +} + /* 气象信息面板 */ .weather-panel { display: flex; flex-wrap: wrap; gap: 12px; + flex: 1; + min-height: 0; + align-content: flex-start; .weather-item { flex: 1; @@ -524,6 +712,13 @@ /* 港口状态 */ .port-status-list { + display: flex; + flex-direction: column; + gap: 8px; + flex: 1; + min-height: 0; + overflow-y: auto; + .port-item { display: flex; align-items: center; @@ -531,7 +726,7 @@ padding: 10px 12px; background: rgba(0, 80, 120, 0.25); border-radius: 6px; - margin-bottom: 8px; + margin-bottom: 0; border-left: 3px solid #00b4d8; .port-name { @@ -635,9 +830,19 @@ } /* 响应式布局 */ -@media (max-width: 1400px) { +@media (max-width: 1680px) { .maritime-grid { - grid-template-columns: 28% 44% 28%; + grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.8fr) minmax(0, 1.1fr); + } +} + + + + + +@media (max-width: 1440px) { + .maritime-grid { + grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.6fr) minmax(0, 1.2fr); } } @@ -657,7 +862,10 @@ grid-template-rows: auto; } - .grid-col { + .maritime-dashboard .grid-col { + display: flex; + flex-direction: column; + gap: var(--mar-gap); height: auto; min-height: 400px; } diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/index.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/index.tsx index 45472e12..a90113f8 100644 --- a/zlt-web/yingyan/src/pages/maritime/dashboard/index.tsx +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/index.tsx @@ -1,34 +1,22 @@ import React, { useState, useEffect, useCallback, useMemo } from 'react'; -import { Card, Button, List, Tag, Spin, message, DatePicker, Segmented, Space } from 'antd'; -import { - WarningOutlined, - RocketOutlined, - CompassOutlined, - PieChartOutlined, - EnvironmentOutlined, -} from '@ant-design/icons'; -import { Line, Pie, Column, Area, Rose } from '@ant-design/plots'; -import { history } from 'umi'; +import { Spin, message } from 'antd'; import dayjs from 'dayjs'; +import type { AlertItem, DeviceStats, TaskStats, TrendItem } from '@/services/dashboard'; +import { getDeviceStats, getTaskStats, getTrendData } from '@/services/dashboard'; import { - getDeviceStats, - getTaskStats, - getTrendData, - getMockAlerts, - DeviceStats, - TaskStats, - TrendItem, - AlertItem, -} from '@/services/dashboard'; + MaritimeKpiStrip, + DeviceTypeCard, + PortStatusCard, + MaritimeAlertCard, + WeatherCard, + SeaAreaPortal, + AnnualTrendChart, + TaskTypeChart, + TaskOverviewCard, + MaritimeInsightCard, +} from './components'; import './index.less'; -// 无人船图标组件 -const USVIcon = () => ( - - - -); - const MaritimeDashboard: React.FC = () => { const [loading, setLoading] = useState(true); const [deviceStats, setDeviceStats] = useState(null); @@ -43,6 +31,18 @@ const MaritimeDashboard: React.FC = () => { const [tenantId, setTenantId] = useState(); const [includeChildren, setIncludeChildren] = useState(true); + // 海事专用告警数据 + const getMaritimeAlerts = useCallback((): AlertItem[] => { + return [ + { id: '1', type: 'device_fault', level: 'critical', deviceName: '巡检船-01', message: '检测到船只超速航行,航速28节', timestamp: new Date(Date.now() - 120000).toISOString() }, + { id: '2', type: 'device_offline', level: 'error', deviceName: '巡检船-03', message: '设备信号丢失超过10分钟', timestamp: new Date(Date.now() - 300000).toISOString() }, + { id: '3', type: 'task_failed', level: 'warning', taskName: '巡检任务#1024', message: '发现违规锚泊船只1艘', timestamp: new Date(Date.now() - 600000).toISOString() }, + { id: '4', type: 'low_battery', level: 'warning', deviceName: '巡检船-02', message: '电池电量低于20%', timestamp: new Date(Date.now() - 900000).toISOString() }, + { id: '5', type: 'task_failed', level: 'warning', taskName: '巡检任务#1023', message: '巡检完成,未发现违规', timestamp: new Date(Date.now() - 1200000).toISOString() }, + ]; + }, []); + + // 初始化模拟数据 useEffect(() => { // 模拟年度数据 const mockAnnual: any[] = []; @@ -78,6 +78,7 @@ const MaritimeDashboard: React.FC = () => { ]); }, []); + // 监听租户变化 useEffect(() => { const handler = (e: any) => { const nextTenantId = e?.detail?.tenantId as string | undefined; @@ -89,6 +90,7 @@ const MaritimeDashboard: React.FC = () => { return () => window.removeEventListener('tenant-change', handler as any); }, []); + // 获取数据 const fetchData = useCallback(async () => { setLoading(true); try { @@ -110,7 +112,6 @@ const MaritimeDashboard: React.FC = () => { setDeviceStats(deviceRes); setTaskStats(taskRes); setTaskTrend(trendRes.taskTrend); - // 模拟海事告警数据 setAlerts(getMaritimeAlerts()); } catch (error) { console.error('获取数据失败:', error); @@ -118,418 +119,141 @@ const MaritimeDashboard: React.FC = () => { } finally { setLoading(false); } - }, [includeChildren, taskStatDate, taskStatType, tenantId]); - - // 海事专用告警数据 - const getMaritimeAlerts = (): AlertItem[] => { - return [ - { id: '1', type: 'device_fault', level: 'critical', deviceName: '巡检船-01', message: '检测到船只超速航行,航速28节', timestamp: new Date(Date.now() - 120000).toISOString() }, - { id: '2', type: 'device_offline', level: 'error', deviceName: '巡检船-03', message: '设备信号丢失超过10分钟', timestamp: new Date(Date.now() - 300000).toISOString() }, - { id: '3', type: 'task_failed', level: 'warning', taskName: '巡检任务#1024', message: '发现违规锚泊船只1艘', timestamp: new Date(Date.now() - 600000).toISOString() }, - { id: '4', type: 'low_battery', level: 'warning', deviceName: '巡检船-02', message: '电池电量低于20%', timestamp: new Date(Date.now() - 900000).toISOString() }, - { id: '5', type: 'task_failed', level: 'warning', taskName: '巡检任务#1023', message: '巡检完成,未发现违规', timestamp: new Date(Date.now() - 1200000).toISOString() }, - ]; - }; + }, [getMaritimeAlerts, includeChildren, taskStatDate, taskStatType, tenantId]); + // 初始化和定时刷新数据 useEffect(() => { - if (!tenantId) return; fetchData(); - }, [fetchData]); - - // 定时刷新 - useEffect(() => { const dataTimer = setInterval(fetchData, 30000); return () => { clearInterval(dataTimer); }; }, [fetchData]); - const goTo3D = () => { - // 传递来源页面,以便从map3d返回时能回到正确的大屏 - history.push('/map3d?from=maritime'); - }; - - // --- 图表配置 --- - - const taskTrendSeriesData = useMemo(() => { - return taskTrend.flatMap((t) => [ - { date: t.date, type: '下发', value: t.created || 0 }, - { date: t.date, type: '完成', value: t.completed || 0 }, - { date: t.date, type: '失败', value: t.failed || 0 }, - ]); - }, [taskTrend]); - - // 近7日任务完成数趋势数据 - const taskCompleteTrendData = useMemo(() => { - return taskTrend.map((t) => ({ - date: t.date, - value: t.completed || 0, - })); - }, [taskTrend]); - - const taskTrendConfig: any = { - data: taskTrendSeriesData, - xField: 'date', - yField: 'value', - seriesField: 'type', - smooth: true, - color: ['#00b4d8', '#00e5a0', '#ff9f43'], - areaStyle: { - fill: 'l(270) 0:#ffffff 0.5:#7ec2f3 1:#0077b6', - fillOpacity: 0.1, - }, - xAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } }, grid: null }, - yAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } }, grid: { line: { style: { stroke: 'rgba(0,150,200,0.1)' } } } }, - tooltip: { showMarkers: true }, - height: 180, - }; - - // 设备类型分布 - 模拟数据 - const usvTypeData: { name: string; count: number }[] = useMemo(() => { - return (deviceStats?.byType || [ - { name: '巡检型', count: 12 }, - { name: '监测型', count: 8 }, - { name: '救援型', count: 5 }, - { name: '测量型', count: 3 }, - ]).map(item => ({ name: item.name, count: item.count })); - }, [deviceStats]); - - const pieConfig: any = { - data: usvTypeData, - angleField: 'count', - colorField: 'name', - radius: 0.7, - innerRadius: 0.5, - color: ['#00b4d8', '#0096c7', '#00e5a0', '#48cae4'], - label: { - text: (datum: any) => { - const name = datum?.name || ''; - const count = datum?.count ?? 0; - const data = usvTypeData as { name: string; count: number }[]; - const total = data.reduce((sum, d) => sum + (d.count || 0), 0); - const percent = total > 0 ? ((count / total) * 100).toFixed(1) : 0; - return `${name} ${percent}%`; - }, - style: { fill: 'rgba(200,230,255,0.65)' }, - }, - legend: { position: 'bottom', itemValue: { style: { fill: 'rgba(200,230,255,0.65)' } }, itemName: { style: { fill: 'rgba(200,230,255,0.65)' } } }, - height: 200, - }; - - const columnConfig: any = { - data: taskTypeData, - xField: 'type', - yField: 'value', - seriesField: 'type', - color: ({ type }: any) => { - if (type === '航线巡检') return '#00b4d8'; - if (type === '定点监测') return '#00e5a0'; - return '#ff9f43'; - }, - label: { - text: (datum: any) => datum?.value?.toString() || '0', - style: { fill: '#fff' }, - }, - xAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } } }, - yAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } }, grid: { line: { style: { stroke: 'rgba(0,150,200,0.1)' } } } }, - legend: false, - height: 180, - }; - - const taskCompleteTrendConfig: any = { - data: taskCompleteTrendData, - xField: 'date', - yField: 'value', - smooth: true, - color: '#00e5a0', - areaStyle: { fillOpacity: 0.2 }, - xAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } }, grid: null }, - yAxis: { - label: { style: { fill: 'rgba(200,230,255,0.65)' } }, - grid: { line: { style: { stroke: 'rgba(0,150,200,0.08)' } } }, - }, - tooltip: { showMarkers: true }, - height: 160, - }; - - const areaConfig: any = { - data: annualData, - xField: 'month', - yField: 'value', - seriesField: 'type', - color: ['#00b4d8', '#00e5a0'], - areaStyle: { fillOpacity: 0.25 }, - xAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } } }, - yAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } }, grid: { line: { style: { stroke: 'rgba(0,150,200,0.1)' } } } }, - legend: { position: 'top-right', itemName: { style: { fill: 'rgba(200,230,255,0.8)' } } }, - smooth: true, - height: 220, - }; - - const roseConfig: any = { - data: violationAnalysisData, - xField: 'type', - yField: 'value', - seriesField: 'type', - radius: 0.9, - color: ['#ff6b6b', '#ffa502', '#ff9f43', '#00b4d8', '#48cae4', '#90e0ef'], - label: { - text: (datum: any) => datum?.type || '', - style: { fill: '#fff', fontSize: 10 }, - }, - legend: { position: 'bottom', itemName: { style: { fill: 'rgba(200,230,255,0.65)' } } }, - height: 200, - }; - - const taskStatusPieConfig: any = { - data: [ - { name: '待执行', value: taskStats?.pending || 0 }, - { name: '执行中', value: taskStats?.running || 0 }, - { name: '已完成', value: taskStats?.completed || 0 }, - { name: '已失败', value: taskStats?.failed || 0 }, - ], - angleField: 'value', - colorField: 'name', - radius: 0.85, - innerRadius: 0.55, - color: ['#ffa502', '#00b4d8', '#00e5a0', '#ff6b6b'], - label: { - text: (datum: any) => { - const name = datum?.name || ''; - const value = datum?.value ?? 0; - const total = (taskStats?.pending || 0) + (taskStats?.running || 0) + (taskStats?.completed || 0) + (taskStats?.failed || 0); - const percent = total > 0 ? ((value / total) * 100).toFixed(1) : 0; - return `${name} ${percent}%`; - }, - style: { fill: 'rgba(200,230,255,0.65)' }, - }, - legend: { position: 'bottom', itemValue: { style: { fill: 'rgba(200,230,255,0.65)' } }, itemName: { style: { fill: 'rgba(200,230,255,0.65)' } } }, - height: 190, - }; - - const getAlertColor = (level: string) => { - switch (level) { - case 'critical': return '#ff4757'; - case 'error': return '#ff9f43'; - case 'warning': return '#feca57'; - default: return '#54a0ff'; - } - }; - - const taskPeriodText = useMemo(() => { - if (taskStatType === 'day') return '当日'; - if (taskStatType === 'month') return '当月'; - return '当年'; - }, [taskStatType]); - const taskNewLabel = useMemo(() => { if (taskStatType === 'day') return '当日任务'; if (taskStatType === 'month') return '当月任务'; return '当年任务'; }, [taskStatType]); - const datePickerFormat = useMemo(() => { - if (taskStatType === 'day') return 'YYYY-MM-DD'; - if (taskStatType === 'month') return 'YYYY-MM'; - return 'YYYY'; - }, [taskStatType]); + // 使用 CSS Grid 强制分配高度(类似智慧城市首页) + const gap = 12; return ( -
+
+ {/* 保留海事背景装饰 */}
+