@@ -137,8 +137,43 @@ flow-types (类型定义)
137137- ** 与用户沟通及编写文档时,所有内容必须使用中文表述**
138138- 前端包管理使用 pnpm(根据用户配置)
139139- 前端文件命名规范:使用小写字母 + 下划线组合(如 ` script_editor.tsx ` 、` variable_picker.tsx ` )
140+ - ** 前端导入规范** :使用 ` @/ ` 路径别名导入项目内部模块,避免使用相对路径导入
140141- 设计涉及流程或 UML 图形的解决方案时,使用 Mermaid Markdown 语法
141142- 在编写计划的时候要遵循 TDD 的开发规范,务必要在方案中进行对实现代码逻辑的单元测试设计。
142143- 在设计计划方案或执行方案过程中,对于代码的设计规划与调整修改要遵循本项目的代码风格和架构设计规则
143144- 设计的计划要保存到本地的 ` docs/ ` 目录下,每一个计划以时间+标题的方式命名创建文件夹,例如 ` 2026-02-26-xxxx ` ,文件夹下内容分为 ` plan.md ` 以及其他设计文件(如设计文件 xxx.pen 或其他设计内容信息)
144145
146+ ``` typescript
147+ // ✅ 正确:使用 @/ 路径别名
148+ import { GroovySyntaxConverter } from ' @/components/design-editor/script/service/groovy-syntax-converter' ;
149+ import { ScriptType } from ' @/components/design-editor/typings/groovy-script' ;
150+
151+ // ❌ 错误:避免使用相对路径
152+ import { GroovySyntaxConverter } from ' ../../../src/components/...' ;
153+ ```
154+
155+ ### 面向对象开发规范
156+
157+ 除前端 ** .tsx 组件** 以外的所有代码(Java 后端、TypeScript 非组件文件)均采用面向对象方式开发:
158+
159+ - ** Service 层** :使用 class 定义,通过依赖注入或单例模式使用
160+ - ** 工具类** :使用 class 定义,提供实例方法或静态方法
161+ - ** 适配器/转换器** :使用 class 实现,支持扩展
162+
163+ ``` typescript
164+ // ✅ 正确:使用 class 定义 Service
165+ export class GroovySyntaxConverter {
166+ private adapters: Map <ScriptType , ScriptAdapter > = new Map ();
167+
168+ public registerAdapter(adapter : ScriptAdapter ): void {
169+ this .adapters .set (adapter .scriptType , adapter );
170+ }
171+
172+ public toScript(...): string { ... }
173+ }
174+
175+ // ❌ 错误:避免直接使用函数导出
176+ export function toScript(...): string { ... }
177+ export const toScript = (... ): string => { ... };
178+ ```
179+
0 commit comments