feat: 导出联系人标签和详细描述

扩展联系人读取与导出链路,新增 labels 和 detailDescription 字段的兼容提取,并同步更新通讯录缓存、详情展示与
  JSON/CSV/VCF 导出。
  Close #402
This commit is contained in:
姜北尘
2026-03-22 14:17:19 +08:00
parent 2e1c0e6c54
commit e12193aa40
5 changed files with 91 additions and 4 deletions

View File

@@ -153,6 +153,8 @@ export interface ContactInfo {
remark?: string
nickname?: string
alias?: string
labels?: string[]
detailDescription?: string
avatarUrl?: string
type: 'friend' | 'group' | 'official' | 'former_friend' | 'other'
}
@@ -1321,6 +1323,8 @@ class ChatService {
continue
}
const labels = this.parseContactLabels(row)
const detailDescription = this.getContactDetailDescription(row)
const displayName = row.remark || row.nick_name || row.alias || username
contacts.push({
@@ -1329,6 +1333,8 @@ class ChatService {
remark: row.remark || undefined,
nickname: row.nick_name || undefined,
alias: row.alias || undefined,
labels: labels.length > 0 ? labels : undefined,
detailDescription: detailDescription || undefined,
avatarUrl: undefined,
type,
lastContactTime: lastContactTimeMap.get(username) || 0
@@ -1880,6 +1886,59 @@ class ChatService {
return Number.isFinite(parsed) ? parsed : fallback
}
private parseContactLabels(row: Record<string, any>): string[] {
const raw = this.getRowField(row, [
'label_list', 'labelList', 'labels', 'label_names', 'labelNames', 'tags', 'tag_list', 'tagList'
])
const normalizedFromValue = (value: unknown): string[] => {
if (Array.isArray(value)) {
return Array.from(new Set(value.map((item) => String(item || '').trim()).filter(Boolean)))
}
const text = String(value || '').trim()
if (!text) return []
return Array.from(new Set(
text
.replace(/[;、|]+/g, ',')
.split(',')
.map((item) => item.trim())
.filter(Boolean)
))
}
const direct = normalizedFromValue(raw)
if (direct.length > 0) return direct
for (const [key, value] of Object.entries(row)) {
const normalizedKey = key.toLowerCase()
if (!normalizedKey.includes('label') && !normalizedKey.includes('tag')) continue
if (normalizedKey.includes('img') || normalizedKey.includes('head')) continue
const fallback = normalizedFromValue(value)
if (fallback.length > 0) return fallback
}
return []
}
private getContactDetailDescription(row: Record<string, any>): string {
const value = this.getRowField(row, [
'detail_description', 'detailDescription', 'description', 'desc', 'contact_description', 'contactDescription',
'profile', 'introduction', 'phone', 'mobile', 'telephone', 'tel', 'vcard', 'card_info', 'cardInfo'
])
const direct = String(value || '').trim()
if (direct) return direct
for (const [key, rawValue] of Object.entries(row)) {
const normalizedKey = key.toLowerCase()
const isCandidate = normalizedKey.includes('detail') || normalizedKey.includes('desc') || normalizedKey.includes('description') || normalizedKey.includes('profile') || normalizedKey.includes('intro') || normalizedKey.includes('phone') || normalizedKey.includes('mobile') || normalizedKey.includes('tel') || normalizedKey.includes('vcard') || normalizedKey.includes('card')
if (!isCandidate) continue
if (normalizedKey.includes('avatar') || normalizedKey.includes('img') || normalizedKey.includes('head')) continue
const text = String(rawValue || '').trim()
if (text) return text
}
return ''
}
private normalizeUnsignedIntegerToken(raw: any): string | undefined {
if (raw === undefined || raw === null || raw === '') return undefined

View File

@@ -93,6 +93,9 @@ class ContactExportService {
displayName: c.displayName,
remark: c.remark,
nickname: c.nickname,
alias: c.alias,
labels: Array.isArray(c.labels) ? c.labels : [],
detailDescription: c.detailDescription,
type: c.type
}))
}
@@ -103,12 +106,15 @@ class ContactExportService {
* 导出为CSV格式
*/
private async exportToCSV(contacts: any[], outputPath: string): Promise<void> {
const headers = ['用户名', '显示名称', '备注', '昵称', '类型']
const headers = ['用户名', '显示名称', '备注', '昵称', '微信号', '标签', '详细描述', '类型']
const rows = contacts.map(c => [
c.username || '',
c.displayName || '',
c.remark || '',
c.nickname || '',
c.alias || '',
Array.isArray(c.labels) ? c.labels.join(' | ') : '',
c.detailDescription || '',
this.getTypeLabel(c.type)
])
@@ -137,9 +143,13 @@ class ContactExportService {
lines.push(`NICKNAME:${c.nickname}`)
}
// 备注
if (c.remark) {
lines.push(`NOTE:${c.remark}`)
const noteParts = [
c.remark ? String(c.remark) : '',
Array.isArray(c.labels) && c.labels.length > 0 ? `标签: ${c.labels.join(', ')}` : '',
c.detailDescription ? `详细描述: ${c.detailDescription}` : ''
].filter(Boolean)
if (noteParts.length > 0) {
lines.push(`NOTE:${noteParts.join('\\n')}`)
}
// 微信ID

View File

@@ -397,6 +397,9 @@ function ContactsPage() {
displayName: contact.displayName,
remark: contact.remark,
nickname: contact.nickname,
alias: contact.alias,
labels: contact.labels,
detailDescription: contact.detailDescription,
type: contact.type
}))
).catch((error) => {
@@ -1110,6 +1113,9 @@ function ContactsPage() {
<div className="detail-row"><span className="detail-label"></span><span className="detail-value">{selectedContact.username}</span></div>
<div className="detail-row"><span className="detail-label"></span><span className="detail-value">{selectedContact.nickname || selectedContact.displayName}</span></div>
{selectedContact.remark && <div className="detail-row"><span className="detail-label"></span><span className="detail-value">{selectedContact.remark}</span></div>}
{selectedContact.alias && <div className="detail-row"><span className="detail-label"></span><span className="detail-value">{selectedContact.alias}</span></div>}
{selectedContact.labels && selectedContact.labels.length > 0 && <div className="detail-row"><span className="detail-label"></span><span className="detail-value">{selectedContact.labels.join('、')}</span></div>}
{selectedContact.detailDescription && <div className="detail-row"><span className="detail-label"></span><span className="detail-value">{selectedContact.detailDescription}</span></div>}
<div className="detail-row"><span className="detail-label"></span><span className="detail-value">{getContactTypeName(selectedContact.type)}</span></div>
{selectedContactSupportsSns && (
<div className="detail-row">

View File

@@ -663,6 +663,8 @@ export interface ContactsListCacheContact {
remark?: string
nickname?: string
alias?: string
labels?: string[]
detailDescription?: string
type: 'friend' | 'group' | 'official' | 'former_friend' | 'other'
}
@@ -1176,6 +1178,10 @@ export async function getContactsListCache(scopeKey: string): Promise<ContactsLi
remark: typeof item.remark === 'string' ? item.remark : undefined,
nickname: typeof item.nickname === 'string' ? item.nickname : undefined,
alias: typeof item.alias === 'string' ? item.alias : undefined,
labels: Array.isArray(item.labels)
? Array.from(new Set(item.labels.map((label) => String(label || '').trim()).filter(Boolean)))
: undefined,
detailDescription: typeof item.detailDescription === 'string' ? item.detailDescription : undefined,
type: (type === 'friend' || type === 'group' || type === 'official' || type === 'former_friend' || type === 'other')
? type
: 'other'
@@ -1210,6 +1216,10 @@ export async function setContactsListCache(scopeKey: string, contacts: ContactsL
remark: contact?.remark ? String(contact.remark) : undefined,
nickname: contact?.nickname ? String(contact.nickname) : undefined,
alias: contact?.alias ? String(contact.alias) : undefined,
labels: Array.isArray(contact?.labels)
? Array.from(new Set(contact.labels.map((label) => String(label || '').trim()).filter(Boolean)))
: undefined,
detailDescription: contact?.detailDescription ? String(contact.detailDescription) : undefined,
type
})
}

View File

@@ -37,6 +37,8 @@ export interface ContactInfo {
remark?: string
nickname?: string
alias?: string
labels?: string[]
detailDescription?: string
avatarUrl?: string
type: 'friend' | 'group' | 'official' | 'former_friend' | 'other'
}