Files
vscode-workbench/.trae/documents/fix-bind-email-tasks-track-plan.md
T

3.0 KiB
Raw Blame History

修复绑定邮箱/手机功能 - 添加 tasks.track 调用

Summary

绑定邮箱和绑定手机功能在绑定成功后未调用 tasks.track 上报任务进度,导致用户无法完成"绑定邮箱"任务(获得奖励)。

Current State Analysis

后端状态:

  • TaskDefinition 模型已定义 bind 行为类型,描述为「绑定手机/邮箱」
  • 数据库迁移 0009_seed_initial_data.py 已存在名为「绑定邮箱」的 task definition(action_type='bind', task_type='special')
  • API 端点 POST /user/tasks/track/ 已实现,接收 { action_type, count } 参数

前端状态:

  • api_request.tasks.track({ action_type, count }) 已在 request.ts 中定义
  • EmailSettingCard.tsx 和 PhoneSettingCard.tsx 在绑定成功后均未调用 tasks.track

Proposed Changes

文件 1: EmailSettingCard.tsx

路径: chunyu_project_react/src/pages/Profile/components/EmailSettingCard.tsx

修改位置: 第 111 行 dispatch(updateUser(res.data.user)); 之后

修改内容:

// 原有代码
if (res?.code === 10008 && res?.data?.user) {
  dispatch(updateUser(res.data.user));
  setCurrentStep(2);
  message.success(t('emailSetting.emailChangeSuccess'));
}

// 修改为
if (res?.code === 10008 && res?.data?.user) {
  dispatch(updateUser(res.data.user));
  setCurrentStep(2);
  message.success(t('emailSetting.emailChangeSuccess'));
  // 上报绑定任务进度
  api_request.tasks.track({ action_type: 'bind' }).catch(() => {});
}

文件 2: PhoneSettingCard.tsx

路径: chunyu_project_react/src/pages/Profile/components/PhoneSettingCard.tsx

修改位置: 第 87 行 dispatch(updateUser(response.data.user)); 之后

修改内容:

// 原有代码
if (response?.data?.user) {
  dispatch(updateUser(response.data.user));
  setShowCaptcha(false);
  setCurrentStep(2);
  message.success(t('profile.phone.changeSuccess'));
}

// 修改为
if (response?.data?.user) {
  dispatch(updateUser(response.data.user));
  setShowCaptcha(false);
  setCurrentStep(2);
  message.success(t('profile.phone.changeSuccess'));
  // 上报绑定任务进度
  api_request.tasks.track({ action_type: 'bind' }).catch(() => {});
}

Assumptions & Decisions

决策 说明
使用 action_type: 'bind' 后端已定义该类型同时覆盖绑定手机和邮箱,无需新增类型
使用 .catch(() => {}) 静默处理失败 tasks.track 失败不应阻塞主流程,用户绑定已成功,任务上报为辅助功能
不显示 loading 状态 使用 request.normal.post,默认会显示 loading,但此处为辅助操作,静默失败即可

Verification

  1. 绑定新邮箱成功后,调用 api_request.tasks.track({ action_type: 'bind' })
  2. 绑定新手机成功后,调用 api_request.tasks.track({ action_type: 'bind' })
  3. 任务中心应能看到「绑定邮箱」任务进度更新为已完成
  4. 即使 tasks.track API 失败,绑定流程仍正常完成