Skip to content

Commit edd5deb

Browse files
committed
Initial commit: Takt SMEs Platform
0 parents  commit edd5deb

File tree

456 files changed

+121674
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

456 files changed

+121674
-0
lines changed

.cursor/rules/architecture.mdc

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
alwaysApply: true
3+
---
4+
5+
# 架构规范
6+
7+
## 分层架构原则
8+
9+
项目采用 Clean Architecture(清洁架构),依赖方向只能向下:
10+
11+
```
12+
Fluent (表现层) -> Application (应用层) -> Domain (领域层) -> Infrastructure (基础设施层) -> Common (通用层)
13+
```
14+
15+
**项目命名空间前缀**:`Takt.*`
16+
17+
**文件位置**:
18+
- 表现层:@src/Takt.Fluent/
19+
- 应用层:@src/Takt.Application/
20+
- 领域层:@src/Takt.Domain/
21+
- 基础设施层:@src/Takt.Infrastructure/
22+
- 通用层:@src/Takt.Common/
23+
24+
## 各层职责
25+
26+
### Takt.Fluent (表现层)
27+
- **职责**: UI展示、用户交互、视图逻辑
28+
- **包含**: Views, ViewModels, UI Services, Helpers, Models
29+
- **示例**: @src/Takt.Fluent/Views/MainWindow.xaml, @src/Takt.Fluent/ViewModels/MainWindowViewModel.cs
30+
31+
### Takt.Application (应用层)
32+
- **职责**: 业务逻辑编排、应用服务
33+
- **包含**: Services, DTOs, Mappers
34+
- **示例**: @src/Takt.Application/Services/
35+
36+
### Takt.Domain (领域层)
37+
- **职责**: 领域模型、业务规则
38+
- **包含**: Entities, Repository Interfaces
39+
- **示例**: @src/Takt.Domain/Entities/
40+
41+
### Takt.Infrastructure (基础设施层)
42+
- **职责**: 数据访问、外部服务集成
43+
- **包含**: Data Access, Repository Implementation
44+
- **示例**: @src/Takt.Infrastructure/Data/
45+
46+
### Takt.Common (通用层)
47+
- **职责**: 共享组件、工具类
48+
- **包含**: Logging, Helpers, Results
49+
- **示例**: @src/Takt.Common/Logging/
50+
51+
## 禁止事项
52+
53+
- ❌ 表现层不能直接调用基础设施层
54+
- ❌ 不能跨层调用
55+
- ❌ 不能违反依赖方向
56+
57+
## 代码示例
58+
59+
```csharp
60+
// ✅ 正确:ViewModel 调用应用层服务
61+
public class UserViewModel : ViewModelBase
62+
{
63+
private readonly IHbtUserService _userService; // 应用层接口
64+
65+
public UserViewModel(IHbtUserService userService)
66+
{
67+
_userService = userService;
68+
}
69+
}
70+
71+
// ❌ 错误:ViewModel 直接调用基础设施层
72+
public class UserViewModel : ViewModelBase
73+
{
74+
private readonly IUserRepository _repository; // ❌ 基础设施层
75+
}
76+
```

.cursor/rules/async.mdc

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
alwaysApply: true
3+
---
4+
5+
# 异步编程规范
6+
7+
## 异步方法命名
8+
9+
**强制要求**:异步方法必须以 `Async` 结尾
10+
11+
```csharp
12+
// ✅ 正确
13+
public async Task<List<UserDto>> GetUsersAsync() { }
14+
public async Task<UserDto> GetUserByIdAsync(int id) { }
15+
16+
// ❌ 错误
17+
public async Task<List<UserDto>> GetUsers() { } // 缺少 Async 后缀
18+
```
19+
20+
**示例文件**:
21+
- @src/Takt.Application/Services/(查看实际异步方法)
22+
23+
## 异步调用规范
24+
25+
**禁止使用 `.Result` 或 `.Wait()`**:
26+
27+
```csharp
28+
// ✅ 正确:使用 async/await
29+
private async Task LoadUsersAsync()
30+
{
31+
var result = await _userService.GetListAsync();
32+
if (result.Success)
33+
{
34+
Users = new ObservableCollection<UserDto>(result.Data);
35+
}
36+
}
37+
38+
// ❌ 错误:使用 .Result 或 .Wait()
39+
private void LoadUsers()
40+
{
41+
var result = _userService.GetListAsync().Result; // ❌ 死锁风险
42+
_userService.GetListAsync().Wait(); // ❌ 死锁风险
43+
}
44+
```
45+
46+
## UI 线程操作
47+
48+
**规范**:在后台线程执行,回到 UI 线程更新
49+
50+
```csharp
51+
// ✅ 正确
52+
private async Task LoadUsersAsync()
53+
{
54+
var users = await _userService.GetListAsync(); // 后台线程
55+
56+
// 自动回到 UI 线程(如果 ViewModel 在 UI 线程创建)
57+
Users = new ObservableCollection<UserDto>(users);
58+
59+
// 或者显式调度到 UI 线程
60+
Application.Current.Dispatcher.Invoke(() =>
61+
{
62+
Users = new ObservableCollection<UserDto>(users);
63+
});
64+
}
65+
```

.cursor/rules/context.mdc

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
alwaysApply: true
3+
---
4+
5+
# 上下文管理规范
6+
7+
## 上下文分类
8+
9+
**必须提供的信息**:
10+
11+
1. **代码上下文**(必须):
12+
```markdown
13+
**相关代码**:
14+
- @src/Takt.Fluent/Views/MainWindow.xaml
15+
- @src/Takt.Fluent/Models/AvalonDocument.cs:114
16+
```
17+
18+
2. **架构上下文**(必须):
19+
```markdown
20+
**架构上下文**:
21+
- 分层架构:Fluent -> Application -> Domain -> Infrastructure
22+
- MVVM 模式:View -> ViewModel -> Service -> Repository
23+
```
24+
25+
3. **当前状态**(必须):
26+
```markdown
27+
**当前状态**:
28+
- 已完成:图标转换逻辑已实现,IconSource 已正确设置
29+
- 存在问题:图标在 UI 中不显示
30+
- 已验证:日志显示 IconSource=RenderTargetBitmap, 16x16
31+
```
32+
33+
## 文件引用规范
34+
35+
**引用格式**:
36+
37+
- 完整文件:`@src/Takt.Fluent/Views/MainWindow.xaml`
38+
- 特定行:`@src/Takt.Fluent/Models/AvalonDocument.cs:114`
39+
- 行范围:`@src/Takt.Fluent/Models/AvalonDocument.cs:60-138`
40+
- 多文件:
41+
```markdown
42+
**相关文件**:
43+
- @src/Takt.Fluent/Views/MainWindow.xaml(DockingManager 配置)
44+
- @src/Takt.Fluent/Models/AvalonDocument.cs(图标转换逻辑)
45+
```
46+
47+
## 上下文完整性检查
48+
49+
**必须检查项**:
50+
51+
- [ ] 是否提供了项目名称、技术栈、架构模式?
52+
- [ ] 是否提供了所有相关文件的路径(使用 @ 符号)?
53+
- [ ] 是否说明了模块间的依赖关系?
54+
- [ ] 是否说明了当前实现状态和问题?
55+
- [ ] 是否提供了相关的日志输出?
56+
- [ ] 是否提供了可重现的测试步骤?
57+
58+
## 上下文更新规范
59+
60+
**更新时机**:
61+
62+
1. **代码变更后**(必须更新):
63+
```markdown
64+
**上下文更新**:
65+
- 更新原因:代码已修改,需要重新分析
66+
- 更新内容:@src/Takt.Fluent/Models/AvalonDocument.cs:114(已修改)
67+
```
68+
69+
2. **问题状态变化**(必须更新):
70+
```markdown
71+
**问题状态更新**:
72+
- 之前状态:图标不显示
73+
- 当前状态:图标已显示,但位置不正确
74+
```
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
alwaysApply: true
3+
---
4+
5+
# 依赖注入规范
6+
7+
## 服务注册
8+
9+
**文件位置**:@src/Takt.Fluent/App.xaml.cs
10+
11+
**示例**:
12+
```csharp
13+
// @src/Takt.Fluent/App.xaml.cs
14+
public partial class App : Application
15+
{
16+
public static IServiceProvider? Services { get; private set; }
17+
18+
protected override void OnStartup(StartupEventArgs e)
19+
{
20+
var services = new ServiceCollection();
21+
22+
// 注册服务
23+
services.AddScoped<ITaktUserService, TaktUserService>();
24+
services.AddTransient<UserViewModel>();
25+
services.AddTransient<UserView>();
26+
27+
Services = services.BuildServiceProvider();
28+
}
29+
}
30+
```
31+
32+
## 构造函数注入
33+
34+
**规范**:必须通过构造函数注入,禁止使用 ServiceLocator
35+
36+
```csharp
37+
// ✅ 正确:通过构造函数注入
38+
// @src/Takt.Fluent/ViewModels/Identity/UserViewModel.cs
39+
public class UserViewModel : ViewModelBase
40+
{
41+
private readonly ITaktUserService _userService;
42+
43+
public UserViewModel(ITaktUserService userService)
44+
{
45+
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
46+
}
47+
}
48+
49+
// ❌ 错误:使用 ServiceLocator 反模式
50+
public class UserViewModel : ViewModelBase
51+
{
52+
private readonly ITaktUserService _userService;
53+
54+
public UserViewModel()
55+
{
56+
_userService = App.Services.GetService<ITaktUserService>(); // ❌ 反模式
57+
}
58+
}
59+
```
60+
61+
## 服务生命周期
62+
63+
- `Singleton`:整个应用生命周期单例(如配置服务)
64+
- `Scoped`:每个请求/窗口一个实例(如业务服务)
65+
- `Transient`:每次获取都创建新实例(如 ViewModel、View)

.cursor/rules/mvvm.mdc

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
alwaysApply: true
3+
---
4+
5+
# MVVM 模式规范
6+
7+
## View(视图层)
8+
9+
**职责**:仅负责 UI 展示和用户交互,不包含业务逻辑
10+
11+
**文件位置**:@src/Takt.Fluent/Views/
12+
13+
**示例**:
14+
```xml
15+
<!-- ✅ 正确:View 只负责 UI -->
16+
<!-- @src/Takt.Fluent/Views/Identity/UserView.xaml -->
17+
<UserControl x:Class="Takt.Fluent.Views.Identity.UserView">
18+
<DataGrid ItemsSource="{Binding Users}"
19+
SelectedItem="{Binding SelectedUser, Mode=TwoWay}"/>
20+
</UserControl>
21+
```
22+
23+
```csharp
24+
// ❌ 错误:View 中包含业务逻辑
25+
// @src/Takt.Fluent/Views/Identity/UserView.xaml.cs
26+
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
27+
{
28+
// ❌ 不要在 View 中直接调用服务
29+
var service = App.Services.GetService<IUserService>();
30+
service.GetUsersAsync();
31+
}
32+
```
33+
34+
## ViewModel(视图模型层)
35+
36+
**职责**:管理 View 的状态和数据,处理用户交互命令
37+
38+
**文件位置**:@src/Takt.Fluent/ViewModels/
39+
40+
**示例**:
41+
```csharp
42+
// ✅ 正确:ViewModel 继承 ViewModelBase
43+
// @src/Takt.Fluent/ViewModels/Identity/UserViewModel.cs
44+
public class UserViewModel : ViewModelBase
45+
{
46+
private readonly IHbtUserService _userService;
47+
private ObservableCollection<UserDto> _users = new();
48+
49+
public ObservableCollection<UserDto> Users
50+
{
51+
get => _users;
52+
set => SetProperty(ref _users, value);
53+
}
54+
55+
public ICommand LoadUsersCommand { get; }
56+
57+
public UserViewModel(IHbtUserService userService)
58+
{
59+
_userService = userService;
60+
LoadUsersCommand = new RelayCommand(async () => await LoadUsersAsync());
61+
}
62+
63+
private async Task LoadUsersAsync()
64+
{
65+
var result = await _userService.GetListAsync();
66+
if (result.Success)
67+
{
68+
Users = new ObservableCollection<UserDto>(result.Data);
69+
}
70+
}
71+
}
72+
```
73+
74+
**关键要求**:
75+
- ✅ 必须通过构造函数注入依赖服务
76+
- ✅ 使用 `SetProperty` 方法更新属性以触发通知
77+
- ✅ 所有异步操作使用 `async/await`
78+
- ✅ 命令使用 `ICommand` 接口
79+
80+
## Model(模型层)
81+
82+
**职责**:定义数据模型(Entity、DTO)
83+
84+
**文件位置**:
85+
- Entity:@src/Takt.Domain/Entities/
86+
- DTO:@src/Takt.Application/Dtos/
87+
88+
**示例**:
89+
```csharp
90+
// ✅ 正确:Entity 定义
91+
// @src/Takt.Domain/Entities/Identity/User.cs
92+
public class User : EntityBase
93+
{
94+
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
95+
public int Id { get; set; }
96+
97+
[SugarColumn(Length = 50)]
98+
public string UserName { get; set; } = string.Empty;
99+
}
100+
```

0 commit comments

Comments
 (0)