From 553cc0586397c8cf22a421c619c8b1cc5d8f4eb1 Mon Sep 17 00:00:00 2001 From: lbw_9527443 <780139497@qq.com> Date: Fri, 6 Feb 2026 18:34:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(lead-detail):=20=E5=9C=A8=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=AF=A6=E6=83=85=E9=A1=B5=E6=B7=BB=E5=8A=A0=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E6=95=B0=E6=8D=AE=E5=B1=95=E7=A4=BA=E5=8C=BA=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 API 类型定义中新增 `UserFormItem` 和 `UserFormAnswer` 类型 - 添加 `getUserForms` API 函数用于获取指定用户的表单数据 - 在用户详情面板中新增表单数据展示区域,支持加载状态、错误处理和空状态 - 添加 `getQuestionLabel` 和 `getAnswerText` 工具函数来格式化表单答案的显示 - 当选中不同用户时,自动获取并展示对应的表单数据 - 为现有 `LeadItem` 类型的部分字段添加中文注释以提升代码可读性 --- 247_Contry/src/api/index.ts | 39 +++++++++--- 247_Contry/src/views/index/index.vue | 88 +++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 10 deletions(-) diff --git a/247_Contry/src/api/index.ts b/247_Contry/src/api/index.ts index b11e78c..462f813 100644 --- a/247_Contry/src/api/index.ts +++ b/247_Contry/src/api/index.ts @@ -12,19 +12,19 @@ export type LeadItem = { hook_user_id: string id: number avatar_url: string - sex: number - follow_up_user_id: string - wechat_add_time: string + sex: number // 性别 0: 未知, 1: 男, 2: 女 + follow_up_user_id: string // 跟进人ID + wechat_add_time: string // 微信添加时间 auto_status: number - is_synced: number + is_synced: number // 是否同步到服务器 0: 未同步, 1: 已同步 created_at: string nickname: string phone: string follow_up_name: string - source_type: number - status: number - wechat_status: number - extended_info: Record + source_type: number //内外联系人 1: 外部联系人, 0: 内部联系人 + status: number // 状态 0: 正常, 1: 禁用 + wechat_status: number // 微信状态 0: 正常, 1: 已删除 + extended_info: Record // updated_at: string last_active_at: string | null } @@ -36,6 +36,29 @@ export type LeadListResponse = { items: LeadItem[] } +export type UserFormAnswer = { + question_label?: string + answer?: unknown + [key: string]: unknown +} + +export type UserFormItem = { + form_id: string + form_title: string + answers: UserFormAnswer[] + created_at: string + updated_at: string + [key: string]: unknown +} + +export const getUserForms = (userId: string) => { + return http.get('/api/v1/admin/user/form', { + params: { + user_id: userId, + }, + }) +} + export const getAdminUserStatus = (params: AdminUserStatusParams = {}) => { return http.get('/api/v1/admin/user/status', { params: { diff --git a/247_Contry/src/views/index/index.vue b/247_Contry/src/views/index/index.vue index 040efd7..3198cca 100644 --- a/247_Contry/src/views/index/index.vue +++ b/247_Contry/src/views/index/index.vue @@ -134,6 +134,42 @@ {{ formatTime(selectedLead.updated_at) }} + + +
+
+ 表单数据 + {{ userForms.length }} +
+ +
+ +
+ +
+ {{ formsError }} +
+ +
+ 暂无表单记录 +
+ +
+
+
+
{{ form.form_title || '未命名表单' }}
+
{{ formatTime(form.created_at).split(' ')[0] }}
+
+
+
+
{{ getQuestionLabel(answer) }}
+
{{ getAnswerText(answer) }}
+
+
+
暂无答案
+
+
+
@@ -156,8 +192,8 @@ import SidebarNav from './components/SidebarNav.vue'; import DashboardView from './components/DashboardView.vue'; import StrategyView from './components/StrategyView.vue'; import MonitorView from './components/MonitorView.vue'; -import { getAdminUserStatus } from '@/api'; -import type { LeadListResponse, LeadItem } from '@/api'; +import { getAdminUserStatus, getUserForms } from '@/api'; +import type { LeadListResponse, LeadItem, UserFormAnswer, UserFormItem } from '@/api'; const router = useRouter(); const route = useRoute(); @@ -211,6 +247,20 @@ const formatTime = (value: string | null) => { return Number.isNaN(date.getTime()) ? value : date.toLocaleString(); }; +const getQuestionLabel = (answer: UserFormAnswer) => { + const label = answer.question_label; + if (typeof label === 'string' && label.trim()) return label; + return '问题'; +}; + +const getAnswerText = (answer: UserFormAnswer) => { + const value = answer.answer; + if (Array.isArray(value)) return value.join('、'); + if (value === null || value === undefined || value === '') return '-'; + if (typeof value === 'object') return JSON.stringify(value); + return String(value); +}; + const fetchLeads = async () => { if (leadsLoading.value) return; leadsLoading.value = true; @@ -227,6 +277,40 @@ const fetchLeads = async () => { } }; +const userForms = ref([]); +const formsLoading = ref(false); +const formsError = ref(''); + +const fetchUserForms = async (userId: string) => { + formsLoading.value = true; + formsError.value = ''; + userForms.value = []; + try { + const res = await getUserForms(userId); + console.log('getUserForms response:', res); + if (Array.isArray(res.data)) { + userForms.value = res.data; + } else { + userForms.value = []; + formsError.value = '表单数据格式错误'; + } + console.log('userForms:', userForms.value); + } catch (error) { + formsError.value = error instanceof Error ? error.message : '获取表单失败'; + console.error('Fetch forms error:', error); + } finally { + formsLoading.value = false; + } +}; + +watch(selectedLead, (newLead) => { + if (newLead) { + fetchUserForms(newLead.hook_user_id); + } else { + userForms.value = []; + } +}); + // 1. 销售阶段 (SOP) const salesStages = [ { id: 'connect', name: '1. 浅建联 (加微/破冰)', desc: '初步接触,建立信任,发送欢迎语' },