问题修复记录-2025-11-02.md 6.2 KB

问题修复记录 - 2025年11月2日

🐛 发现的问题

1. Parse SDK 使用错误 ✅ 已修复

错误信息createWithoutData is not a function

位置src/app/services/designer-task.service.ts:82

原因:Parse SDK 使用方式不正确

修复

// 修复前
productQuery.equalTo('profile', this.Parse.Object.extend('Profile').createWithoutData(designerId));

// 修复后
const ProfileClass = this.Parse.Object.extend('Profile');
const profilePointer = new ProfileClass();
profilePointer.id = designerId;
productQuery.equalTo('profile', profilePointer);

2. 用户名显示"未知用户" ⚠️ 增强中

问题:导航条显示"未知用户",Profile 表中所有用户字段都是 undefined

原因

  • Profile 表中没有存储用户的姓名、头像等信息
  • 只有 userid,没有 name/realname/username 等字段

修复措施

2.1 添加企微用户信息同步

// 新增方法:syncWxworkUserInfo()
private async syncWxworkUserInfo(profile: FmodeObject): Promise<void> {
  // 检查 Profile 是否已有用户名
  const existingName = profile.get('name') || profile.get('realname');
  if (existingName) return;
  
  // 从企微获取用户信息
  const userInfo = await this.wxAuth?.getUserInfo();
  
  if (userInfo) {
    // 更新并保存 Profile
    if (userInfo.name) profile.set('name', userInfo.name);
    if (userInfo.avatar) profile.set('avatar', userInfo.avatar);
    // ... 更多字段
    await profile.save();
  }
}

2.2 增强 mapProfileToUser 方法

private async mapProfileToUser(profile: FmodeObject): Promise<CurrentUser> {
  // 1. 尝试从 Profile 获取
  let name = profile.get('name') || profile.get('realname') || ...;
  let avatar = profile.get('avatar') || profile.get('avatarUrl') || ...;
  
  // 2. 如果没有,从 wxAuth 获取
  if (!name || !avatar) {
    const wxUserInfo = await this.wxAuth?.getUserInfo();
    if (wxUserInfo) {
      name = name || wxUserInfo.name;
      avatar = avatar || wxUserInfo.avatar;
    }
  }
  
  // 3. 最终降级到默认值
  name = name || '未知用户';
  avatar = avatar || this.getDefaultAvatar();
  
  return { userid, name, avatar, roleName, ... };
}

2.3 添加详细调试日志

console.log('📋 完整 Profile 对象:', profile);
console.log('📋 完整 User 对象:', user);
console.log('📋 从 wxAuth 获取用户信息:', wxUserInfo);
console.log('📋 Profile 字段调试:', {
  name, realname, username, avatar, ...
  '最终使用的name': name,
  '最终使用的avatar': avatar
});

3. 设计师中外任务失败 ⚠️ 增强错误日志

错误信息Error: [object Object]

修复:增强错误日志输出

catch (error: any) {
  console.error('❌ 获取设计师任务失败:', error);
  console.error('❌ 错误详情:', error.message || error.toString());
  console.error('❌ 错误堆栈:', error.stack);
  return [];
}

🧪 测试步骤

步骤 1: 清除缓存并刷新

# 按 Ctrl+Shift+R 或 Cmd+Shift+R 强制刷新

步骤 2: 查看控制台日志

打开浏览器开发者工具(F12),查找以下日志:

✅ 设计师端企微认证初始化成功,CID: cDL6R1hgSi
✅ 设计师登录成功: xxx
✅ Profile ID: m9xAo3sPLu
📋 完整 Profile 对象: Parse.Object {_objCount: ...}
📋 完整 User 对象: Parse.User {_objCount: ...}
🔄 开始同步企微用户信息...
📋 企微用户信息: { name: '王刚', avatar: '...', ... }
✅ 用户信息已同步到 Profile
📋 从 wxAuth 获取用户信息: { name: '王刚', ... }
📋 Profile 字段调试: {
  name: '王刚',
  realname: '王刚',
  avatar: 'http://...',
  最终使用的name: '王刚',
  最终使用的avatar: 'http://...'
}
✅ 用户信息映射完成: {userid: '...', name: '王刚', ...}

步骤 3: 检查导航条

  • 是否显示真实用户名(不再是"未知用户")?
  • 是否显示用户头像?
  • 头像是圆形,有白色边框?

步骤 4: 检查错误

  • 是否还有"createWithoutData"错误?
  • "设计师中外任务失败"错误的详细信息是什么?

📋 需要用户提供的信息

刷新页面后,请在控制台中查找并截图:

1. 企微用户信息日志

📋 企微用户信息: { ... }

2. Profile 字段调试日志

📋 Profile 字段调试: {
  name: ...,
  realname: ...,
  最终使用的name: ...,
  最终使用的avatar: ...
}

3. 如果还有错误,请提供:

❌ 获取设计师任务失败: ...
❌ 错误详情: ...
❌ 错误堆栈: ...

🔍 可能的问题原因

如果仍然显示"未知用户"

  1. wxAuth.getUserInfo() 返回 null

    • 企微 API 未正确配置
    • 权限不足
  2. Profile 表权限问题

    • 无法保存用户信息
    • 需要检查 Parse 服务器的 ACL 权限
  3. 企微 API 未提供用户名

    • 企微应用权限配置不完整
    • 需要在企微管理后台开启相应权限

🚀 后续优化

如果企微 API 无法提供用户名

可以考虑以下方案:

方案 A: 手动输入用户名

在首次登录时,弹出模态框让用户输入姓名

方案 B: 从其他数据源获取

  • 从 User 表的 username 字段
  • 从项目分配记录中反推
  • 从请假记录中获取

方案 C: 使用 userid 作为显示名

name = name || `用户_${profile.get('userid')?.slice(-6)}`;

✅ 已完成的修复

  • 修复 Parse SDK createWithoutData 错误
  • 添加企微用户信息同步功能
  • 增强 mapProfileToUser 方法,支持多种数据源
  • 添加详细的调试日志
  • 增强错误日志输出

📌 注意事项

  1. 不要清除 localStorage

    • 会导致企微认证失效
    • 只需刷新页面即可
  2. 查看完整的控制台日志

    • 包括所有的 📋、✅、⚠️、❌ 开头的日志
    • 这些日志会帮助定位问题
  3. 如果头像无法显示

    • 检查头像 URL 是否有效
    • 检查是否跨域问题
    • 会自动降级到默认头像

现在请刷新页面,并将控制台的日志截图发给我!🔍