在文档审核对话框中,可以通过拖拽按钮将当前用户的昵称插入到 WPS 文档的任意位置。
审核人:[拖拽插入用户名]
审核时间:2025-12-29
审核意见:通过
[拖拽插入用户名] 于 2025-12-29 批注:
此处需要修改...
| 姓名 | 部门 | 审核意见 |
|---|---|---|
| [拖拽插入] | 技术部 | 通过 |
报告人:[拖拽插入用户名]
日期:2025-12-29
<el-button
draggable="true"
@dragstart="handleUserNameDragStart"
@dragend="handleUserNameDragEnd"
>
拖我到文档中
</el-button>
// 开始拖拽时设置数据
const handleUserNameDragStart = (e: DragEvent) => {
const userName = userStore.userName || '当前用户';
e.dataTransfer!.setData('text/plain', userName);
};
const selection = await app.ActiveDocument.Application.Selection;
await selection.TypeText(userName);
const activeCell = await app.ActiveCell;
await activeCell.put_Value(userName);
const selection = await app.ActiveWindow.Selection;
const textRange = await selection.TextRange;
await textRange.InsertAfter(userName);
userStore.userName 获取可能原因:
解决方法:
原因:
解决方法:
原因:
解决方法:
原因:
userStore.userName 为空解决方法:
答案:
| 特性 | 用户名拖拽 | 图片拖拽 |
|---|---|---|
| 拖拽源 | 按钮 | 外部文件 |
| 数据类型 | 文本 | 图片 |
| 插入方式 | 文本插入 | 图片插入 |
| Word | 光标位置 | 光标位置 |
| Excel | 单元格 | 浮动图片 |
| PPT | 文本框 | 幻灯片 |
| 不支持 | 不支持 |
| 浏览器 | 支持情况 | 备注 |
|---|---|---|
| Chrome 90+ | ✅ 完全支持 | 推荐使用 |
| Edge 90+ | ✅ 完全支持 | 推荐使用 |
| Firefox 88+ | ✅ 完全支持 | |
| Safari 14+ | ✅ 完全支持 | |
| IE 11 | ❌ 不支持 | 不支持拖放 API |
// 1. 开始拖拽
handleUserNameDragStart(e) {
const userName = userStore.userName || '当前用户';
e.dataTransfer.setData('text/plain', userName);
isDraggingUserName.value = true;
}
// 2. 拖拽到编辑器
handleDrop(e) {
const userName = e.dataTransfer.getData('text/plain');
if (isDraggingUserName.value && userName) {
await insertUserNameToWps(userName);
}
}
// 3. 插入到文档
async insertUserNameToWps(userName) {
const app = await wpsInstance.Application;
const selection = await app.ActiveDocument.Application.Selection;
await selection.TypeText(userName);
}
拖拽插入用户名功能让文档审核更加便捷:
现在就可以试试拖拽按钮到文档中!