Files
Store.Management/.agents/skills/add-module/SKILL.md
T
2026-10-27 19:01:56 +08:00

116 lines
3.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: add-module
description: >-
在 PipeReviewReport 客户端中添加一个新的功能模块,包含完整的目录结构、AppModule 元数据、
主视图和 ViewModel。当用户需要新建客户端模块时使用。
disable-model-invocation: false
---
# 添加客户端功能模块
## 目录结构
在 `Source/Modules/<模块名>/` 下创建:
```
PipeReviewReport.<模块名>/
├── PipeReviewReport.<模块名>.csproj
├── AppModule.cs
├── Views/
│ ├── <模块名>MainView.xaml
│ ├── <模块名>MainView.xaml.cs
│ ├── Dialogs/ # 可选:弹窗(Parameter + ViewModel 同 .xaml.cs)
│ └── Steps/ # 可选:向导步骤 UserControl(可共用父 VM)
└── ViewModels/
└── <模块名>MainViewModel.cs
```
复杂业务服务优先放 `Framework/Services/`(模块间共享);仅本模块私有的可放模块 `Services/`。
## Step 1 — 创建 .csproj
参考现有模块的 `.csproj`,核心是引用 Framework 项目。
## Step 2 — AppModule.cs
实现 `IAppModule` 接口:
```csharp
using PipeReviewReport.Shared;
using PipeReviewReport.<模块名>.Views;
using PipeReviewReport.Framework.Interfaces;
using PipeReviewReport.Resources.Fonts;
using System.Windows.Controls;
namespace PipeReviewReport.<模块名>;
public class AppModule : IAppModule
{
public string Key { get; } = ConstKeys.SK_XXX;
public string DisplayName { get; } = "XXX(简短说明)";
public string FullName { get; } = "模块完整中文名";
public string EnglishFullName { get; } = "Module English Name";
public string Description { get; } = "模块功能描述。";
// 用字体图标:侧栏选中态可随 Foreground 变白
public IconNameEnum Icon { get; } = IconNameEnum.Folder;
public ContentControl Content { get; } = new <模块名>MainView();
public bool IsEnabled { get; } = true;
public int Order { get; } = 10;
}
```
- `Key`:从 `PipeReviewReport.Shared.ConstKeys` 取对应的 `SK_XXX` 常量
- `Icon`:用 `IconNameEnum` 字体图标(不要用 PNG,否则侧栏选中态无法变色)
- `Order`:侧栏排序,数值越小越靠上;现有模块按 10/20/…/80 间隔,方便插入
## Step 3 — 主 ViewModel
```csharp
using PipeReviewReport.Framework.ViewModels;
namespace PipeReviewReport.<模块名>.ViewModels;
internal class <模块名>MainViewModel : ViewModelBaseEx
{
protected override void LoadedOnce()
{
// 首次加载初始化
}
}
```
## Step 4 — 主 View(XAML)
先读取 `Source/XAML_Preset.txt` 中 `View` 模板,复制 xmlns 引用,然后:
```xml
<UserControl
x:Class="PipeReviewReport.<模块名>.Views.<模块名>MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PipeReviewReport.<模块名>.Views"
xmlns:core="MAX.Core"
...(其余 xmlns 从 XAML_Preset.txt 复制)
d:DataContext="{d:DesignInstance Type=local:<模块名>MainViewModel}"
Style="{DynamicResource UserControlStyle}"
DataContext="{core:DISource Type=local:<模块名>MainViewModel}">
<Grid>
</Grid>
</UserControl>
```
## Step 5 — 添加到主程序
在 `Source/PipeReviewReport/PipeReviewReport.csproj` 中添加项目引用。
`AppModule` 会被主程序自动扫描,无需额外注册。
## 检查清单
- [ ] `AppModule` 实现 `IAppModule`,包含所有必要属性
- [ ] `Key` 使用 `ConstKeys.SK_XXX` 常量
- [ ] ViewModel 继承 `ViewModelBaseEx`
- [ ] View 使用 `DISource` 绑定 ViewModel,设置 `UserControlStyle`
- [ ] 主程序 `.csproj` 已添加项目引用
- [ ] 输入框已显式 `MaxLength="{x:Static shared:InputLimits.Path/Text}"`