@@ -137,31 +137,35 @@ flow-types (类型定义)
137137- ** 与用户沟通及编写文档时,所有内容必须使用中文表述**
138138- 前端包管理使用 pnpm(根据用户配置)
139139- 前端文件命名规范:使用小写字母 + 下划线组合(如 ` script_editor.tsx ` 、` variable_picker.tsx ` )
140- - ** 前端导入规范** :使用 ` @ /` 路径别名导入项目内部模块,避免使用相对路径导入
140+ - ** 前端导入规范** :引入当前文件夹下的内容使用 ` . /` 相对路径,引入其他模块的代码使用 ` @/ ` 路径别名
141141- 设计涉及流程或 UML 图形的解决方案时,使用 Mermaid Markdown 语法
142142- 在编写计划的时候要遵循 TDD 的开发规范,务必要在方案中进行对实现代码逻辑的单元测试设计。
143143- 在设计计划方案或执行方案过程中,对于代码的设计规划与调整修改要遵循本项目的代码风格和架构设计规则
144144- 设计的计划要保存到本地的 ` docs/ ` 目录下,每一个计划以时间+标题的方式命名创建文件夹,例如 ` 2026-02-26-xxxx ` ,文件夹下内容分为 ` plan.md ` 以及其他设计文件(如设计文件 xxx.pen 或其他设计内容信息)
145145
146146``` typescript
147- // ✅ 正确:使用 @/ 路径别名
147+ // ✅ 正确:使用 @/ 路径别名引入其他模块的代码
148148import { GroovySyntaxConverter } from ' @/components/design-editor/script/service/groovy-syntax-converter' ;
149149import { ScriptType } from ' @/components/design-editor/typings/groovy-script' ;
150150
151- // ❌ 错误:避免使用相对路径
151+ // ✅ 正确:引入当前文件夹下的内容使用相对路径
152+ import { LocalHelper } from ' ./local-helper' ;
153+ import { AnotherUtil } from ' ./utils/another-util' ;
154+
155+ // ❌ 错误:避免跨目录使用相对路径
152156import { GroovySyntaxConverter } from ' ../../../src/components/...' ;
153157```
154158
155159### 面向对象开发规范
156160
157- 除前端 ** .tsx 组件 ** 以外的所有代码(Java 后端、 TypeScript 非组件文件)均采用面向对象方式开发 :
161+ TypeScript 代码根据类型采用不同的开发风格 :
158162
159- - ** Service 层 ** :使用 class 定义,通过依赖注入或单例模式使用
160- - ** 工具类 ** :使用 class 定义,提供实例方法或静态方法
161- - ** 适配器/转换器 ** :使用 class 实现,支持扩展
163+ - ** Service、Context、Convert、Utils 等业务处理类 ** :使用 class 面向对象方式定义,支持依赖注入和扩展
164+ - ** Hooks ** :使用函数式方式定义,遵循 React Hooks 规范
165+ - ** 工具函数 ** :根据场景选择,复杂逻辑使用 class,简单工具可用函数式
162166
163167``` typescript
164- // ✅ 正确:使用 class 定义 Service
168+ // ✅ 正确:使用 class 定义业务处理类
165169export class GroovySyntaxConverter {
166170 private adapters: Map <ScriptType , ScriptAdapter > = new Map ();
167171
@@ -172,8 +176,16 @@ export class GroovySyntaxConverter {
172176 public toScript(...): string { ... }
173177}
174178
175- // ❌ 错误:避免直接使用函数导出
176- export function toScript(...): string { ... }
177- export const toScript = (... ): string => { ... };
179+ // ✅ 正确:Hooks 使用函数式定义
180+ export const useFlowDesigner = () => {
181+ const [nodes, setNodes] = useState <Node []>([]);
182+ // ...
183+ return { nodes , setNodes };
184+ };
185+
186+ // ✅ 正确:简单的工具函数可用函数式
187+ export const formatDate = (date : Date ): string => {
188+ return date .toLocaleDateString ();
189+ };
178190```
179191
0 commit comments