# 企业微信拖拽数据结构分析文档
## 🎯 目标
记录从企业微信拖拽不同类型消息到AI对话区域时的完整数据结构,为功能实现提供准确的参考。
## 📊 测试方法
### 打印函数
```typescript
/**
* 详细打印拖拽数据结构
*/
private logDragDataStructure(event: DragEvent, context: string): void {
console.log(`\n========== [${context}] 拖拽数据结构分析 ==========`);
const dt = event.dataTransfer;
if (!dt) {
console.log('❌ dataTransfer 为空');
return;
}
// 1. 基本信息
console.log('\n📋 基本信息:');
console.log(' dropEffect:', dt.dropEffect);
console.log(' effectAllowed:', dt.effectAllowed);
console.log(' types:', Array.from(dt.types));
// 2. Files
console.log('\n📁 Files 对象:');
console.log(' files.length:', dt.files?.length || 0);
if (dt.files && dt.files.length > 0) {
for (let i = 0; i < dt.files.length; i++) {
const file = dt.files[i];
console.log(` [${i}] File对象:`, {
name: file.name,
size: file.size,
type: file.type,
lastModified: new Date(file.lastModified).toLocaleString(),
webkitRelativePath: (file as any).webkitRelativePath || ''
});
}
}
// 3. Items
console.log('\n📦 Items 对象:');
console.log(' items.length:', dt.items?.length || 0);
if (dt.items && dt.items.length > 0) {
for (let i = 0; i < dt.items.length; i++) {
const item = dt.items[i];
console.log(` [${i}] DataTransferItem:`, {
kind: item.kind,
type: item.type
});
// 尝试获取item的内容
if (item.kind === 'string') {
item.getAsString((str) => {
console.log(` → 字符串内容 (${item.type}):`, str.substring(0, 200));
});
} else if (item.kind === 'file') {
const file = item.getAsFile();
console.log(` → 文件对象:`, file);
}
}
}
// 4. 各种数据类型
console.log('\n📝 getData() 测试:');
const commonTypes = [
'text/plain',
'text/html',
'text/uri-list',
'text/rtf',
'application/json',
'Files'
];
for (const type of commonTypes) {
try {
const data = dt.getData(type);
if (data) {
console.log(` ${type}:`, data.length > 200 ? data.substring(0, 200) + '...' : data);
}
} catch (e) {
// 某些类型可能不可访问
}
}
// 5. 自定义数据类型
console.log('\n🔍 自定义数据类型:');
if (dt.types) {
for (const type of dt.types) {
if (!commonTypes.includes(type)) {
try {
const data = dt.getData(type);
console.log(` ${type}:`, data);
} catch (e) {
console.log(` ${type}: [无法读取]`);
}
}
}
}
console.log('\n========== 数据结构分析结束 ==========\n');
}
```
## 📂 测试场景与数据结构
### 场景1: 拖拽单张图片
**操作**: 从企业微信群聊拖拽一张JPG图片
**预期数据结构**:
```typescript
{
基本信息: {
dropEffect: "none",
effectAllowed: "all",
types: ["Files", "text/html", "text/plain"]
},
Files对象: {
length: 1,
[0]: {
name: "image.jpg",
size: 1234567, // 字节
type: "image/jpeg",
lastModified: "2025-12-03 10:30:00",
webkitRelativePath: ""
}
},
Items对象: {
length: 3,
[0]: { kind: "file", type: "" },
[1]: { kind: "string", type: "text/html" },
[2]: { kind: "string", type: "text/plain" }
},
getData测试: {
"text/plain": "[图片]",
"text/html": "",
"text/uri-list": ""
}
}
```
### 场景2: 拖拽多张图片
**操作**: 从企业微信群聊选择3张图片一起拖拽
**预期数据结构**:
```typescript
{
基本信息: {
types: ["Files", "text/html", "text/plain"]
},
Files对象: {
length: 3,
[0]: { name: "image1.jpg", size: 1234567, type: "image/jpeg" },
[1]: { name: "image2.png", size: 2345678, type: "image/png" },
[2]: { name: "image3.jpg", size: 3456789, type: "image/jpeg" }
},
Items对象: {
length: 5, // Files + HTML + Plain
[0]: { kind: "file", type: "" },
[1]: { kind: "file", type: "" },
[2]: { kind: "file", type: "" },
[3]: { kind: "string", type: "text/html" },
[4]: { kind: "string", type: "text/plain" }
},
getData测试: {
"text/plain": "[图片] [图片] [图片]",
"text/html": "
"
}
}
```
### 场景3: 拖拽纯文字消息
**操作**: 从企业微信群聊拖拽一条文字消息
**预期数据结构**:
```typescript
{
基本信息: {
types: ["text/html", "text/plain"]
},
Files对象: {
length: 0 // 没有文件
},
Items对象: {
length: 2,
[0]: { kind: "string", type: "text/html" },
[1]: { kind: "string", type: "text/plain" }
},
getData测试: {
"text/plain": "客户要求:现代简约风格,采光要好,预算20万",
"text/html": "