| 学生姓名 | 邮箱 | 国家 | 大学 | 专业 | 状态 | 操作 |
|---|
下载并安装浏览器扩展插件后,即可使用表单自动化提交功能。插件会自动处理表单填充和提交流程。
form-helper-extension.zip 文件
chrome://extensions/ 或 edge://extensions/about:addons
以下代码展示了如何在管理系统中集成表单助手插件,实现填报任务发送和状态同步功能。
所有通信均通过 postMessage API 进行,确保页面与插件 Content Script 之间的消息传递。
// ==================== 发起填报任务 ====================
// 参考: PluginBody/src/background.ts line 831-904 (handleStartApplyFromWebpage)
// 参考: PluginBody/src/content-script.ts line 1518-1580 (处理网页消息)
// 发送填报消息到插件
window.postMessage({
type: 'FORM_HELPER_START_APPLY',
source: 'mock_admin',
data: {
// 学生对象(包含完整的 universityInfo)
student: {
id: 'demo_user_001',
name: '张三',
firstName: '张',
lastName: '三',
email: 'zhangsan@example.com',
universityInfo: {
flag: '🇭🇰',
country: '中国香港',
university: '香港大学',
major: '计算机科学',
// 表单步骤(唯一数据源)
formSteps: [
{
stepId: 'uuid-1',
name: '账号注册',
targetUrl: 'https://sweb.hku.hk/tola/servlet/CreateUserScreen/insertForm?curr=R393&mc=&pt=F',
formType: 'account_register'
}
]
}
},
// 本地记录 ID(用于状态回传,必须为字符串类型)
recordId: '1'
}
}, '*');
// ==================== 监听插件响应 ====================
// 参考: PluginBody/src/content-script.ts line 1524-1580
window.addEventListener('message', (event) => {
if (event.source !== window) return;
const { type, source, data } = event.data;
// 1. 填报进度更新 (source: 'form_helper_content_script')
if (type === 'FORM_HELPER_APPLY_PROGRESS' && source === 'form_helper_content_script') {
const { recordId, progress, message } = data;
console.log('[System] 填报进度:', progress + '%', message);
}
// 2. 填报结果 (source: 'form_helper_content_script')
if (type === 'FORM_HELPER_APPLY_RESULT' && source === 'form_helper_content_script') {
const { recordId, success, message } = data;
const item = mockData.find(item => item.id === recordId);
if (item) {
item.status = success ? 'completed' : 'failed';
renderTable();
}
}
});