docs: harness 文档对齐新架构,忽略签名材料

This commit is contained in:
AndyChen1024
2026-09-11 16:22:45 +08:00
parent d179073e53
commit a91b4afdf2
5 changed files with 65 additions and 29 deletions

View File

@@ -21,25 +21,33 @@ ArkTS(TypeScript 的超集,HarmonyOS 严格类型方言)+ ArkUI 声明式
## 声明式 UI 与状态 Declarative UI & State
- UI 由状态驱动:改状态 → 自动重渲染,禁止命令式直接改 UI。
- 状态装饰器选择:
- 局部状态 `@State`
- 父子传递 `@Prop`(单向)/ `@Link`(双向)
- 跨层 `@Provide` / `@Consume`
- 避免不必要的重渲染:状态粒度要细,不要一个 `@State` 装一整个大对象。
- 状态管理**全量使用 StateManagement V2**(禁用 V1 装饰器):
- 组件/页面 `@ComponentV2`
- 局部状态 `@Local`
- 父子传递 `@Param`(单向输入)/ `@Event`(子→父回调,**不用 `@Link`**)
- 类可观察 `@ObservedV2` + `@Trace`(字段级精准刷新)
- 跨层共享 `@Provider` / `@Consumer`;变化监听 `@Monitor`
- 全局/持久化 `AppStorageV2` / `PersistenceV2`
- 避免不必要的重渲染:`@Trace` 字段粒度要细,不要一个大对象整体刷新。
## 资源 Resources
- 字符串、颜色、媒体一律 `$r('app.xxx')`(定义在 `resources/base/element/`)。
- 禁止在 `.ets` 里硬编码字符串、颜色值、路径。
- 颜色 / 间距 / 字号统一走 `uikit/theme/Theme.ets` 的 token(`AppColor` / `AppSpacing` / `AppFontSize`),禁止在组件里散落颜色/尺寸魔法值。
- 用户可见文案:优先 `$r('app.string.xxx')`(便于国际化);临时/演示文案可内联,正式功能应收口到资源。
- 图片/图标等媒体:`$r('app.media.xxx')`。
## 组件化 Components
- 页面:`@Entry` 组件,放 `pages/`。
- 复用组件:`@Component` 或 `@Reusable`(长列表复用),放 `components/`,通过 `@Prop`/事件回调与外界通信,不直接依赖业务层。
- 页面:`@Entry @ComponentV2`,放 `pages/`,仅编排(组合 view + viewmodel,不含业务逻辑)。
- 业务复用组件:`@ComponentV2`,放 `view/`,通过 `@Param`(输入)/ `@Event`(回调)与外界通信,不直接依赖业务层。
- 跨模块通用组件:下沉到 `uikit/`(`uikit/src/main/ets/components/`)。
- 长列表复用用 `@Reusable`。
## 分层与依赖方向 Layering
`pages → viewmodel → service → model`。禁止反向依赖(如 `model` import `service`)。
`pages → viewmodel → data(repository/api) → model`。禁止反向依赖(如 `model` import `repository`)。
- `viewmodel` 只依赖 `data/repository` 的抽象契约;`repository` 实现依赖 `data/api` + `common` 网络层。
- 跨模块依赖:`entry → common / uikit`;`common`、`uikit` 相互独立,禁止反向/循环依赖。
架构越界由约定 + 人工审查把关(ArkTS 侧暂无现成的依赖方向 linter)。
## 安全 Security