|
|
1 nedēļu atpakaļ | |
|---|---|---|
| .github | 1 mēnesi atpakaļ | |
| deploy | 1 mēnesi atpakaļ | |
| docs | 1 nedēļu atpakaļ | |
| projects | 1 nedēļu atpakaļ | |
| scripts | 1 mēnesi atpakaļ | |
| src | 1 nedēļu atpakaļ | |
| tests | 1 nedēļu atpakaļ | |
| .gitignore | 2 mēneši atpakaļ | |
| CLAUDE.md | 3 mēneši atpakaļ | |
| Dockerfile | 1 mēnesi atpakaļ | |
| README.md | 1 nedēļu atpakaļ | |
| YZWater3.sln | 1 mēnesi atpakaļ | |
| docker-compose.yml | 1 mēnesi atpakaļ | |
| findings.md | 1 mēnesi atpakaļ | |
| progress.md | 1 mēnesi atpakaļ | |
| task_plan.md | 1 mēnesi atpakaļ | |
| yzwater-config.template.json | 1 nedēļu atpakaļ |
基于 Avalonia UI 的跨平台污水处理厂监控系统,支持 Windows、Linux 和 macOS。
| 组件 | 技术方案 |
|---|---|
| UI 框架 | Avalonia UI 12.1.1 |
| 运行时 | .NET 8.0 |
| MVVM 框架 | CommunityToolkit.Mvvm 8.4.2 |
| PLC 通信 | HslCommunication 12.9.2 |
| 数据库 | SqlSugar 5.1.4 + SQLite |
| 图表 | LiveCharts2 2.1.0 |
| 日志 | Serilog 4.4.0 |
| UI 控件库 | Semi.Avalonia 12.1.0 |
| 报表 | ReportService(HTML 日报/月报) |
| 中控通信 | WebSocket Hub(Server/Client 模式) |
YZWater3/
├── src/
│ ├── YZWater.Core/ # 核心业务逻辑(UI 无关)
│ │ ├── Models/ # 数据模型(SqlSugar ORM)
│ │ │ ├── Person.cs # 人员模型
│ │ │ ├── AlarmRecord.cs # 报警记录
│ │ │ ├── FlowRecord.cs # 流量记录
│ │ │ ├── AnalogRecord.cs # 模拟量记录
│ │ │ ├── EquipmentStatus.cs # 设备状态
│ │ │ ├── AuditLog.cs # 审计日志
│ │ │ ├── ProjectProfile.cs # 项目档案
│ │ │ └── SystemConfig.cs # 系统配置
│ │ ├── Services/ # 服务层(单例/静态模式)
│ │ │ ├── PlcService.cs # PLC 通信(西门子 S7)
│ │ │ ├── PlcPollingService.cs # PLC 轮询(单例)
│ │ │ ├── MockPlcService.cs # 模拟 PLC 数据
│ │ │ ├── AlarmService.cs # 报警服务(单例)
│ │ │ ├── DataLoggingService.cs # 数据日志
│ │ │ ├── AuthService.cs # 认证(PBKDF2)
│ │ │ ├── ConfigService.cs # JSON 配置
│ │ │ ├── DatabaseService.cs # SqlSugar + SQLite
│ │ │ ├── HubServer.cs # WebSocket 服务端
│ │ │ ├── HubClient.cs # WebSocket 客户端
│ │ │ ├── ReportService.cs # HTML 报表
│ │ │ ├── BackupService.cs # 数据库备份/还原
│ │ │ ├── AuditService.cs # 审计日志
│ │ │ ├── LanguageService.cs # 中/英双语
│ │ │ ├── ThemeService.cs # 深色/浅色主题
│ │ │ ├── ProjectService.cs # 多项目管理
│ │ │ └── LogService.cs # Serilog 初始化
│ │ ├── ViewModels/ # ViewModel 层
│ │ │ ├── MainViewModel.cs # 主窗口(Tab 导航)
│ │ │ ├── LoginViewModel.cs # 登录
│ │ │ ├── ViewAViewModel.cs # 主工艺(接 PLC 实时数据)
│ │ │ ├── ViewBViewModel.cs # 参数设置
│ │ │ ├── ViewCViewModel.cs # 流量记录(图表+导出)
│ │ │ ├── ViewDViewModel.cs # 报警记录
│ │ │ ├── ViewEViewModel.cs # 关于
│ │ │ ├── ViewFViewModel.cs # 审计日志
│ │ │ └── ProjectViewModel.cs # 项目档案
│ │ └── Utils/ # 工具类
│ │ ├── ResolutionManager.cs # 分辨率管理
│ │ └── WinSize.cs # 窗口尺寸
│ │
│ └── YZWater.Avalonia/ # Avalonia UI 项目
│ ├── Views/ # AXAML 视图
│ │ ├── MainWindow.axaml # 主窗口
│ │ ├── LoginView.axaml # 登录窗口
│ │ ├── ViewAView.axaml # 主工艺(工业控件)
│ │ ├── ViewBView.axaml # 参数设置
│ │ ├── ViewCView.axaml # 流量记录
│ │ ├── ViewDView.axaml # 报警记录
│ │ ├── ViewEView.axaml # 关于
│ │ ├── ViewFView.axaml # 审计日志
│ │ └── ProjectView.axaml # 项目档案
│ ├── Controls/ # 自定义工业控件(Render 绘制)
│ │ ├── WaterTankControl.cs # 水箱液位
│ │ ├── PumpControl.cs # 泵(旋转动画)
│ │ ├── FanControl.cs # 风扇(旋转动画)
│ │ ├── PipeLineControl.cs # 管道(流动虚线)
│ │ ├── ValveControl.cs # 阀门(三态)
│ │ ├── GaugeControl.cs # 仪表
│ │ ├── StatusCard.cs # 状态卡片
│ │ └── PumpStation3DControl.cs # 泵站 3D 视图
│ ├── Themes/ # 深色/浅色主题
│ │ ├── IndustrialTheme.axaml
│ │ ├── IndustrialThemeLight.axaml
│ │ └── IndustrialStyles.axaml
│ ├── Converters/ # 值转换器
│ └── Assets/ # 资源文件
│
├── tests/
│ └── YZWater.Core.Tests/ # xUnit 单元测试
├── docs/ # 文档
└── YZWater3.sln # 解决方案
克隆仓库
git clone <repository-url>
cd YZWater3
还原依赖
dotnet restore
构建项目
dotnet build
运行应用
dotnet run --project src/YZWater.Avalonia
yzwater-config.json → RunMode 配置)| 模式 | 说明 |
|---|---|
Direct |
直连 PLC(默认) |
Server |
连 PLC + 启动 WebSocket 服务端(端口 8765) |
Client |
连接 WebSocket 服务端接收数据,不直连 PLC |
Mock |
无 PLC 时使用模拟数据 |
默认配置文件:yzwater-config.json
{
"PlcIp": "192.168.2.100",
"PlcPort": 102,
"AutoConnect": true,
"LevelHighAlarm": 80.0,
"LevelLowAlarm": 20.0,
"FlowHighAlarm": 100.0,
"FlowLowAlarm": 0.0,
"PumpFrequency": 50.0,
"SystemName": "污水处理监控系统",
"CompanyName": "扬州旭轩科技有限公司",
"ContactPerson": "赵经理",
"ContactPhone": "18115099090",
"RunMode": "Direct",
"HubPort": 8765,
"HubServerUrl": "",
"HubToken": "",
"IsDarkTheme": false,
"IsChinese": true,
"PlcAddresses": {}
}
数据库文件:yzwater.db(SQLite,SqlSugar ORM)
自动创建以下表:
users - 用户表(含角色、密码哈希、盐值)persons - 人员表alarm_records - 报警记录表flow_records - 流量记录表analog_records - 模拟量记录表equipment_statuses - 设备状态表audit_logs - 审计日志表项目使用 AdaptiveContainer 控件实现解析度自适应:
┌─────────────────────────────────────────────────────────────┐
│ 窗口实际大小 (1920 x 1080) │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ 缩放后的内容区域 (1280 x 800 * 1.25) │ │
│ │ ┌─────────────────────────────────────────────┐ │ │
│ │ │ 设计内容 (1280 x 800) │ │ │
│ │ │ - 所有控件使用固定坐标 │ │ │
│ │ │ - 由容器统一缩放 │ │ │
│ │ └─────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
<!-- 在 MainWindow.axaml 中 -->
<controls:AdaptiveContainer DesignWidth="1280" DesignHeight="800"
Stretch="Uniform" MinScale="0.6" MaxScale="1.5">
<!-- 所有内容放在这里 -->
</controls:AdaptiveContainer>
ResolutionManager 提供全局分辨率信息:
// 获取当前缩放比例
var scale = ResolutionManager.Instance.UniformScale;
// 计算缩放后的尺寸
var scaledWidth = ResolutionManager.Instance.Scale(100);
// 计算缩放后的字体大小
var fontSize = ResolutionManager.Instance.ScaleFontSize(14);
支持文字标签
<controls:WaterTankControl WaterLevel="75" Text="入口池" WaterColor="#178187"/>
支持多颜色配置
<controls:PumpControl IsRunning="{Binding Pump1Running}" Speed="2" Text="泵1"/>
支持文字标签
<controls:FanControl IsRunning="{Binding Fan1Running}" Speed="1" Text="风扇1"/>
可配置管道颜色和水流颜色
<controls:PipeLineControl IsFlow="True" IsHorizontal="True"/>
支持文字标签
<controls:ValveControl Status="{Binding Valve1Status}" Text="进水阀"/>
| 特性 | YZWater2 (WPF) | YZWater3 (Avalonia) |
|---|---|---|
| 跨平台 | ❌ 仅 Windows | ✅ Windows/Linux/macOS |
| UI 框架 | WPF | Avalonia UI 12 |
| 运行时 | .NET Framework 4.8 | .NET 8.0 |
| MVVM | Caliburn.Micro | CommunityToolkit.Mvvm |
| 图表 | LiveCharts.Wpf | LiveCharts2 |
| 控件库 | HandyControl | Semi.Avalonia |
| 日志 | NLog | Serilog |
| 工业控件 | HslControls | 自定义控件 |
YZWater.Core/ViewModels 中创建 ViewModelYZWater.Avalonia/Views 中创建对应的 ViewMainViewModel 中添加视图切换逻辑MainWindow.axaml 中添加 TabItem在 YZWater.Avalonia/Controls 目录中创建自定义控件,例如:
使用 CommunityToolkit.Mvvm 的源生成器:
public partial class MyViewModel : ObservableObject
{
[ObservableProperty]
private string _name = string.Empty;
[RelayCommand]
private async Task SaveAsync()
{
// 保存逻辑
}
}
yzwater.db 文件重新启动© 2024-2026 扬州旭轩科技有限公司