CONTACT-COMPONENT-FOLLOWUP-FIX.md 7.0 KB

客户画像组件跟进记录乱码修复

📋 修复日期

2025-10-29

🐛 问题描述

在wxwork项目模块的客户画像组件中,跟进记录显示企微userid乱码:

问题HTML结构

<div class="timeline-dot">
  <svg>...</svg>
  <span>woAs2qCQAA5dJhPfQ5soUVqPgcAHHzmQ</span>
  <p>woAs2qCQAA5dJhPfQ5soUVqPgcAHHzmQ 添加客户</p>
</div>
<div class="timeline-content">
  <div class="timeline-time">4/18</div>
  <div class="timeline-text">
    <strong>woAs2qCQAA5dJhPfQ5soUVqPgcAHHzmQ</strong>
    <p>woAs2qCQAA5dJhPfQ5soUVqPgcAHHzmQ 添加客户</p>
  </div>
</div>

问题分析

发现两个问题

问题1: HTML结构错误

.timeline-dot 内部错误地包含了 <span><p> 标签,导致:

  • ❌ 内容显示在圆点图标内部
  • ❌ 布局混乱
  • ❌ 样式应用错误

问题2: 数据处理错误

contact.component.ts 第351-352行直接使用企微 userid

content: `${fu.userid} 添加客户`,  // ❌ 直接显示userid
operator: fu.userid                 // ❌ 直接显示userid

✅ 修复方案

修复1: HTML结构调整

文件: contact.component.html

修复前:

<div class="timeline-dot">
  <svg>...</svg>
  <span>{{ record.operator }}</span>      ❌ 错误位置
  <p>{{ record.content }}</p>             ❌ 错误位置
</div>
<div class="timeline-content">
  <div class="timeline-time">{{ formatDate(record.time) }}</div>
  <div class="timeline-text">
    <strong>{{ record.operator }}</strong>
    <p>{{ record.content }}</p>
  </div>
</div>

修复后:

<div class="timeline-dot">
  <svg>...</svg>                          ✅ 只保留SVG图标
</div>
<div class="timeline-content">
  <div class="timeline-time">{{ formatDate(record.time) }}</div>
  <div class="timeline-text">
    <strong>{{ record.operator }}</strong> ✅ 正确位置
    <p>{{ record.content }}</p>            ✅ 正确位置
  </div>
</div>

修复2: 数据处理优化

文件: contact.component.ts

修复前:

this.profile.followUpRecords = followUsers.map((fu: any) => ({
  time: fu.createtime ? new Date(fu.createtime * 1000) : new Date(),
  type: 'follow',
  content: `${fu.userid} 添加客户`,  // ❌ userid乱码
  operator: fu.userid                 // ❌ userid乱码
}));

修复后:

this.profile.followUpRecords = followUsers.map((fu: any) => {
  // 处理操作员名称,避免显示企微userid
  let operatorName = '企微用户';
  if (fu.remark && fu.remark.length < 50) {
    operatorName = fu.remark;
  } else if (fu.name && fu.name.length < 50 && !fu.name.startsWith('woAs2q')) {
    operatorName = fu.name;
  }
  
  return {
    time: fu.createtime ? new Date(fu.createtime * 1000) : new Date(),
    type: 'follow',
    content: '添加客户',           // ✅ 简洁内容
    operator: operatorName          // ✅ 智能识别名称
  };
});

🔍 修复逻辑详解

操作员名称获取优先级

1. fu.remark        // 优先级1: 备注名(如果存在)
2. fu.name          // 优先级2: 名称(需验证不是userid)
3. '企微用户'        // 优先级3: 默认显示

验证规则

// 验证条件
✅ 名称长度 < 50 字符
✅ 不以 'woAs2q' 开头(企微userid特征)

// 如果不满足条件
❌ 显示为 "企微用户"

📊 修复效果对比

修复前

显示内容:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[●] woAs2qCQAA5dJhPfQ5soUVqPgcAHHzmQ
    woAs2qCQAA5dJhPfQ5soUVqPgcAHHzmQ 添加客户
    
    4/18
    woAs2qCQAA5dJhPfQ5soUVqPgcAHHzmQ
    woAs2qCQAA5dJhPfQ5soUVqPgcAHHzmQ 添加客户
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
问题:
❌ 乱码重复显示4次
❌ 布局混乱
❌ 内容在圆点内部

修复后

显示内容:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[●] 
    4/18
    企微用户
    添加客户
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
效果:
✅ 无乱码显示
✅ 布局正确
✅ 内容清晰简洁

🎯 设计决策

为什么移除 .timeline-dot 内的内容?

  1. 语义正确性: .timeline-dot 应该只是视觉标记(圆点 + 图标)
  2. 样式一致性: 所有内容应该在 .timeline-content
  3. 布局清晰: 分离视觉标记和内容区域

为什么显示"企微用户"而不是隐藏?

  1. 信息透明: 让用户知道有操作员,只是无法获取名称
  2. 避免空白: 比完全不显示更友好
  3. 统一体验: 与admin customers组件的处理方式一致

为什么简化content为"添加客户"?

  1. 去除冗余: 不再重复显示operator信息
  2. 内容清晰: 直接说明操作类型
  3. 视觉简洁: 减少文本噪音

📁 修改的文件

  1. contact.component.html (第246-261行)

    • 移除 .timeline-dot 内的 <span><p>
    • 保持 .timeline-content 结构不变
  2. contact.component.ts (第344-368行)

    • 增强操作员名称处理逻辑
    • 简化content内容
    • 添加智能识别逻辑

🔍 验证步骤

1. 访问页面

http://localhost:4200/wxwork/:cid/customer/:contactId

2. 检查跟进记录

观察以下内容:

  • ✅ 圆点只显示SVG图标
  • ✅ 操作员名称显示为"企微用户"或实际姓名
  • ✅ 内容显示为"添加客户"(无userid)
  • ✅ 时间显示正确
  • ✅ 布局整洁,无重复内容

3. 测试不同场景

数据情况 预期显示
fu.remark 显示备注名 ✅
fu.name (非userid) 显示名称 ✅
只有 fu.userid 显示"企微用户" ✅
无任何名称 显示"企微用户" ✅

🎨 样式说明

此次修复仅涉及HTML结构和数据处理,不修改CSS样式。

现有的 .timeline-dot.timeline-content 样式继续生效,布局会自动正确显示。

✅ 功能保持完整

所有原有功能均保持不变:

  • ✅ 跟进记录加载
  • ✅ 时间格式化
  • ✅ 记录类型显示
  • ✅ 空状态处理
  • ✅ ContactFollow 表优先级
  • ✅ data.follow_user 降级兼容

🔄 与其他组件对比

Admin Customers组件

  • 使用增强版HTML结构
  • 使用增强版样式(渐变、动画)
  • 同样的乱码处理逻辑 ✅

Contact组件(本次修复)

  • 使用原有HTML结构
  • 使用原有样式
  • 同样的乱码处理逻辑 ✅

一致性: 两个组件的数据处理逻辑保持一致,确保用户体验统一。

🎉 修复完成!

现在访问wxwork客户画像页面,跟进记录将:

  • ✅ 不再显示企微userid乱码
  • ✅ 布局结构正确
  • ✅ 内容清晰简洁
  • ✅ 与admin组件体验一致

文档版本: 1.0
最后更新: 2025-10-29
修复组件: src/modules/project/pages/contact/
影响页面: /wxwork/:cid/customer/:contactId