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/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..9c375267 --- /dev/null +++ b/zlt-business/msg-center/src/main/resources/application.yml @@ -0,0 +1,64 @@ +# 消息中心配置文件 +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: ${SMS_TENCENT_APP_ID:} + # 腾讯云SecretId (在腾讯云控制台获取) + secret-id: ${SMS_TENCENT_SECRET_ID:} + # 腾讯云SecretKey (在腾讯云控制台获取) + secret-key: ${SMS_TENCENT_SECRET_KEY:} + # 短信签名 (在腾讯云短信控制台配置) + sign-name: ${SMS_TENCENT_SIGN_NAME:} + # 验证码模板ID + verify-code-template-id: ${SMS_TENCENT_VERIFY_CODE_TEMPLATE_ID:} + + # 阿里云短信配置 + aliyun: + # 阿里云AccessKeyId (在阿里云控制台获取) + access-key-id: ${SMS_ALIYUN_ACCESS_KEY_ID:} + # 阿里云AccessKeySecret (在阿里云控制台获取) + access-key-secret: ${SMS_ALIYUN_ACCESS_KEY_SECRET:} + # 短信签名 (在阿里云短信控制台配置) + sign-name: ${SMS_ALIYUN_SIGN_NAME:} + # 验证码模板ID + verify-code-template-id: ${SMS_ALIYUN_VERIFY_CODE_TEMPLATE_ID:} + + # 是否保存短信发送记录到数据库 + 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-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/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..4e88893f 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..abe9ff75 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: ''; @@ -597,12 +602,23 @@ .blank-content--maritime { 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/index.less b/zlt-web/yingyan/src/pages/maritime/dashboard/index.less index 26076528..52b29ae8 100644 --- a/zlt-web/yingyan/src/pages/maritime/dashboard/index.less +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/index.less @@ -5,6 +5,19 @@ position: relative; width: 100%; height: 100%; + min-height: 0; + min-width: 0; + flex: 1; + font-size: clamp(12px, 1.1vh, 14px); + --mar-pad-x: clamp(12px, 1.4vw, 18px); + --mar-pad-y: clamp(10px, 1.2vh, 16px); + --mar-gap: clamp(10px, 1.2vh, 14px); + --mar-kpi-h: clamp(70px, 9vh, 85px); + --mar-card-head-h: clamp(36px, 4.4vh, 42px); + --mar-card-body-pad: clamp(8px, 1.1vh, 12px); + --mar-frame-h: clamp(18px, 2.6vh, 28px); + --mar-frame-gap: clamp(6px, 0.9vh, 12px); + --mar-map-min: clamp(240px, 33vh, 360px); background: linear-gradient(180deg, #020c1b 0%, #051525 25%, @@ -107,40 +120,115 @@ } } +.maritime-dashboard--compact-1 { + --mar-pad-x: clamp(10px, 1.1vw, 16px); + --mar-pad-y: clamp(8px, 1.0vh, 12px); + --mar-gap: clamp(8px, 1.0vh, 12px); + --mar-kpi-h: clamp(64px, 8vh, 78px); + --mar-card-head-h: clamp(34px, 4.0vh, 40px); + --mar-card-body-pad: clamp(6px, 0.9vh, 10px); + --mar-frame-h: clamp(16px, 2.2vh, 24px); + --mar-frame-gap: clamp(4px, 0.7vh, 10px); + --mar-map-min: clamp(220px, 30vh, 320px); +} + +.maritime-dashboard--compact-2 { + --mar-pad-x: clamp(8px, 1.0vw, 14px); + --mar-pad-y: clamp(6px, 0.8vh, 10px); + --mar-gap: clamp(6px, 0.9vh, 10px); + --mar-kpi-h: clamp(58px, 7vh, 70px); + --mar-card-head-h: clamp(32px, 3.6vh, 38px); + --mar-card-body-pad: clamp(6px, 0.8vh, 9px); + --mar-frame-h: clamp(14px, 2.0vh, 22px); + --mar-frame-gap: clamp(4px, 0.6vh, 8px); + --mar-map-min: clamp(200px, 28vh, 300px); +} + /* 主内容区域 */ .maritime-spin { height: 100%; + min-height: 0; + display: flex; + flex: 1; :global(.ant-spin-container) { height: 100%; display: flex; flex-direction: column; + min-height: 0; } } .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) + var(--mar-frame-gap)); overflow: hidden; position: relative; z-index: 1; height: 100%; + min-height: 0; + display: flex; + flex-direction: column; +} + +.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, 25%) minmax(0, 50%) minmax(0, 25%); + grid-template-rows: minmax(0, 1fr); + gap: var(--mar-gap); height: 100%; width: 100%; + min-height: 0; + min-width: 0; + flex: 1; } .grid-col { display: flex; flex-direction: column; - gap: 14px; + gap: var(--mar-gap); height: 100%; overflow: hidden; + min-height: 0; } /* 海事风格玻璃面板 */ @@ -180,7 +268,7 @@ } :global(.ant-card-head) { - min-height: 42px; + min-height: var(--mar-card-head-h); padding: 0 14px; border-bottom: 1px solid rgba(0, 180, 230, 0.15); background: linear-gradient(90deg, rgba(0, 100, 150, 0.2), transparent); @@ -195,7 +283,7 @@ :global(.ant-card-body) { flex: 1; - padding: 12px; + padding: var(--mar-card-body-pad); overflow: hidden; position: relative; display: flex; @@ -222,8 +310,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 { @@ -281,6 +369,7 @@ /* 中央海图监控区域 */ .map-portal-wrapper { flex: 2; + min-height: var(--mar-map-min); 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); diff --git a/zlt-web/yingyan/src/pages/maritime/dashboard/index.tsx b/zlt-web/yingyan/src/pages/maritime/dashboard/index.tsx index 45472e12..322e279c 100644 --- a/zlt-web/yingyan/src/pages/maritime/dashboard/index.tsx +++ b/zlt-web/yingyan/src/pages/maritime/dashboard/index.tsx @@ -42,6 +42,18 @@ const MaritimeDashboard: React.FC = () => { const [taskStatDate, setTaskStatDate] = useState(dayjs()); const [tenantId, setTenantId] = useState(); const [includeChildren, setIncludeChildren] = useState(true); + const [compactLevel, setCompactLevel] = useState<0 | 1 | 2>(0); + + useEffect(() => { + const calc = () => { + const height = window?.innerHeight || 0; + const next: 0 | 1 | 2 = height <= 760 ? 2 : height <= 900 ? 1 : 0; + setCompactLevel(next); + }; + calc(); + window.addEventListener('resize', calc); + return () => window.removeEventListener('resize', calc); + }, []); useEffect(() => { // 模拟年度数据 @@ -167,6 +179,40 @@ const MaritimeDashboard: React.FC = () => { })); }, [taskTrend]); + const chartHeights = useMemo(() => { + if (compactLevel === 2) { + return { + taskTrend: 140, + pie: 160, + column: 140, + taskComplete: 120, + area: 170, + rose: 160, + taskStatus: 150, + }; + } + if (compactLevel === 1) { + return { + taskTrend: 160, + pie: 180, + column: 160, + taskComplete: 140, + area: 190, + rose: 180, + taskStatus: 170, + }; + } + return { + taskTrend: 180, + pie: 200, + column: 180, + taskComplete: 160, + area: 220, + rose: 200, + taskStatus: 190, + }; + }, [compactLevel]); + const taskTrendConfig: any = { data: taskTrendSeriesData, xField: 'date', @@ -181,7 +227,7 @@ const MaritimeDashboard: React.FC = () => { 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, + height: chartHeights.taskTrend, }; // 设备类型分布 - 模拟数据 @@ -213,7 +259,7 @@ const MaritimeDashboard: React.FC = () => { 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, + height: chartHeights.pie, }; const columnConfig: any = { @@ -233,7 +279,7 @@ const MaritimeDashboard: React.FC = () => { 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, + height: chartHeights.column, }; const taskCompleteTrendConfig: any = { @@ -249,7 +295,7 @@ const MaritimeDashboard: React.FC = () => { grid: { line: { style: { stroke: 'rgba(0,150,200,0.08)' } } }, }, tooltip: { showMarkers: true }, - height: 160, + height: chartHeights.taskComplete, }; const areaConfig: any = { @@ -263,7 +309,7 @@ const MaritimeDashboard: React.FC = () => { 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, + height: chartHeights.area, }; const roseConfig: any = { @@ -278,7 +324,7 @@ const MaritimeDashboard: React.FC = () => { style: { fill: '#fff', fontSize: 10 }, }, legend: { position: 'bottom', itemName: { style: { fill: 'rgba(200,230,255,0.65)' } } }, - height: 200, + height: chartHeights.rose, }; const taskStatusPieConfig: any = { @@ -304,7 +350,7 @@ const MaritimeDashboard: React.FC = () => { 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, + height: chartHeights.taskStatus, }; const getAlertColor = (level: string) => { @@ -335,11 +381,12 @@ const MaritimeDashboard: React.FC = () => { }, [taskStatType]); return ( -
+
+