+
+
+ {getEntityName(todo.targetEntity)}
+
+
+ {formatRelativeTime(todo.createdAt)}
+
+
+
+
{todo.title}
+
+ {todo.description && (
+
{todo.description}
+ )}
+
+
+
+ 需要操作:{getActionName(todo.action)}
+
+
+
+
+ );
+}
+```
+
+### 4.4 与消息通知集成
+
+待办功能可以配合消息推送使用:
+
+```typescript
+// 在创建待办后发送通知
+export const orderTriggers = {
+ afterCreate: async (params, context) => {
+ const { data } = params;
+
+ if (data.status === 'pending') {
+ // 创建待办
+ const created = await createToDo(
+ 'order',
+ { id: data.id },
+ 'approve',
+ context,
+ {
+ title: '订单待审批',
+ description: `订单号:${data.orderNo}`,
+ redirectTo: {
+ batchPath: '/order/approve'
+ },
+ entity: 'order',
+ entityId: data.id
+ }
+ );
+
+ // 发送消息通知
+ if (created > 0) {
+ await context.aspects.message.send({
+ type: 'todo',
+ title: '新的待办任务',
+ content: '您有新的订单需要审批',
+ data: {
+ todoId: data.id,
+ entity: 'order',
+ entityId: data.id
+ }
+ });
+ }
+ }
+ }
+};
+```
+
+### 4.5 移动端适配
+
+在小程序或移动端,可以使用类似的逻辑:
+
+```javascript
+// 小程序示例
+Page({
+ data: {
+ todos: [],
+ loading: false
+ },
+
+ onLoad() {
+ this.loadTodos();
+ },
+
+ async loadTodos() {
+ this.setData({ loading: true });
+
+ const context = getApp().context;
+ const result = await context.select('toDo', {
+ data: {
+ id: 1,
+ title: 1,
+ description: 1,
+ redirectTo: 1,
+ createdAt: 1
+ },
+ filter: {
+ iState: 'active',
+ 'relation.collaborator.userId': context.userId
+ }
+ });
+
+ this.setData({
+ todos: result.data,
+ loading: false
+ });
+ },
+
+ handleTodo(e) {
+ const todo = e.currentTarget.dataset.todo;
+ const path = todo.redirectTo.singlePath || todo.redirectTo.batchPath;
+
+ wx.navigateTo({
+ url: path + '?todoId=' + todo.id
+ });
+ }
+});
+```
+
+---
+
+## 5. 接入指南
+
+### 5.1 前置要求
+
+待办事项功能依赖于以下模块:
+
+- **oak-domain**:提供实体定义和基础功能
+- **用户系统**:需要用户认证和权限管理
+- **关系系统**:使用 UserRelation 管理协作者
+
+### 5.2 实体注册
+
+待办事项相关实体已在模块中注册,无需额外配置。确保您的项目已正确引入 `oak-general-business`:
+
+这样 `toDo` 和 `readRemark` 实体就会自动可用。
+
+### 5.3 在业务实体中集成待办功能
+
+#### 5.3.1 导入触发器函数
+
+```typescript
+import { createToDo, completeToDo } from 'oak-general-business/lib/triggers/toDo';
+```
+
+#### 5.3.2 在实体 Trigger 中使用
+
+以订单审批为例:
+
+```typescript
+// src/triggers/order.ts
+import { createToDo, completeToDo } from 'oak-general-business/lib/triggers/toDo';
+import { Trigger } from 'oak-domain/lib/types/Trigger';
+import { EntityDict } from '../oak-app-domain';
+
+export const orderTriggers: Trigger