4850c92365
* feat(formRecognizer): 添加表单识别功能及相关组件 添加表单识别功能,包括以下内容: 1. 在路由配置中添加表单识别页面 2. 实现表单识别页面和侧边栏面板 3. 添加表单数据生成工具类 4. 实现与内容脚本的通信机制 5. 添加faker-js依赖用于生成测试数据 6. 支持不同入口点(popup/sidepanel)的组件渲染 * refactor(消息通信): 重构消息通信机制并集中管理消息协议 将分散的消息协议和通信逻辑集中到 utils/messages.ts 中 移除旧的 messages.tsx 文件并更新相关引用 添加消息动作枚举和类型定义,提高类型安全性 优化内容脚本注入失败时的处理逻辑 * feat(QR码): 添加粘贴图片功能并优化上传组件 添加全局粘贴事件监听,支持从剪贴板直接粘贴二维码图片进行解析。重构上传组件为独立组件QrCodeUploader,包含拖拽上传、预览、进度显示和错误处理功能。优化页面样式和用户体验。 - 在QrCodePage添加粘贴事件监听 - 创建QrCodeUploader组件整合上传功能 - 更新测试用例格式 - 调整多个页面的背景色样式 * feat(表单识别): 新增表单识别页面功能与模板管理 - 添加表单识别页面样式配置 - 实现表单字段扫描与展示功能 - 新增数据模板管理工具类 - 添加数据验证工具类 - 扩展表单识别页面功能,包括操作历史记录 - 支持模板的导入导出功能 - 优化表单填充操作的用户体验 * feat(消息系统): 添加标签页刷新功能 在消息系统中新增 RELOAD_TAB 动作类型和 tabId 字段,用于处理标签页刷新请求 修改 StorageCleanerPage 使用后台脚本发送刷新请求,确保弹窗关闭后仍能执行 在 background.ts 中添加标签页刷新处理逻辑,包括错误处理和响应返回 * refactor(theme): 重构主题颜色和样式配置 - 更新主题颜色以满足 WCAG AA 可访问性标准 - 提取全局样式配置到统一变量 - 使用语义化颜色变量替换硬编码值 - 为输入框样式创建统一配置 * feat: add URL entry management components and QR code generation feature - Introduced `UrlEntryItem` and `UrlEntryList` components for displaying and managing URL entries. - Added `UrlToQrCodeSection` component for generating QR codes from URLs with download and copy functionality. - Implemented `AutoRefreshToggle`, `CleaningResult`, `DomainHeader`, `ErrorDisplay`, `OptionItem`, and `StorageOptionsGrid` components for enhanced user interface in storage cleaning. - Created custom hooks `useStorageCleaner` and `useStorageState` for managing storage-related states and preferences. - Added utility hook `useUrlPreferences` for handling URL entry preferences. * feat: 新增时间戳转换器和相关组件,优化时间戳页面功能 * Refactor message handling and storage cleaning logic * feat: 添加 GitHub Actions CI/CD 工作流,支持自动化构建与发布
165 lines
3.8 KiB
TypeScript
165 lines
3.8 KiB
TypeScript
/**
|
|
* 数据模板管理工具
|
|
* 用于创建、编辑、保存和管理自定义测试数据模板
|
|
*/
|
|
|
|
import { FieldType } from './dummyDataGenerator';
|
|
|
|
/**
|
|
* 模板字段接口
|
|
*/
|
|
export interface TemplateField {
|
|
id: string;
|
|
name: string;
|
|
label: string;
|
|
fieldType: FieldType;
|
|
defaultValue: string;
|
|
rules: TemplateRule[];
|
|
}
|
|
|
|
/**
|
|
* 模板规则接口
|
|
*/
|
|
export interface TemplateRule {
|
|
type: 'required' | 'pattern' | 'minLength' | 'maxLength' | 'min' | 'max' | 'custom';
|
|
value: string | number;
|
|
message?: string;
|
|
}
|
|
|
|
/**
|
|
* 数据模板接口
|
|
*/
|
|
export interface DataTemplate {
|
|
id: string;
|
|
name: string;
|
|
description: string;
|
|
fields: TemplateField[];
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
/**
|
|
* 模板存储键名
|
|
*/
|
|
const TEMPLATE_STORAGE_KEY = 'dataTemplates';
|
|
|
|
/**
|
|
* 数据模板管理类
|
|
*/
|
|
export class DataTemplateManager {
|
|
/**
|
|
* 获取所有模板
|
|
*/
|
|
static async getAllTemplates(): Promise<DataTemplate[]> {
|
|
try {
|
|
const stored = await chrome.storage.local.get(TEMPLATE_STORAGE_KEY);
|
|
return (stored[TEMPLATE_STORAGE_KEY] as DataTemplate[]) || [];
|
|
} catch (error) {
|
|
console.error('获取模板失败:', error);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 保存模板
|
|
*/
|
|
static async saveTemplate(template: DataTemplate): Promise<boolean> {
|
|
try {
|
|
const templates = await this.getAllTemplates();
|
|
const existingIndex = templates.findIndex((t) => t.id === template.id);
|
|
|
|
if (existingIndex >= 0) {
|
|
templates[existingIndex] = {
|
|
...template,
|
|
updatedAt: new Date().toISOString(),
|
|
};
|
|
} else {
|
|
templates.push({
|
|
...template,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
});
|
|
}
|
|
|
|
await chrome.storage.local.set({ [TEMPLATE_STORAGE_KEY]: templates });
|
|
return true;
|
|
} catch (error) {
|
|
console.error('保存模板失败:', error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除模板
|
|
*/
|
|
static async deleteTemplate(templateId: string): Promise<boolean> {
|
|
try {
|
|
const templates = await this.getAllTemplates();
|
|
const filtered = templates.filter((t) => t.id !== templateId);
|
|
await chrome.storage.local.set({ [TEMPLATE_STORAGE_KEY]: filtered });
|
|
return true;
|
|
} catch (error) {
|
|
console.error('删除模板失败:', error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 导出模板
|
|
*/
|
|
static exportTemplates(templates: DataTemplate[]): string {
|
|
return JSON.stringify(templates, null, 2);
|
|
}
|
|
|
|
/**
|
|
* 导入模板
|
|
*/
|
|
static async importTemplates(jsonString: string): Promise<boolean> {
|
|
try {
|
|
const importedTemplates = JSON.parse(jsonString) as DataTemplate[];
|
|
if (!Array.isArray(importedTemplates)) {
|
|
return false;
|
|
}
|
|
|
|
const existingTemplates = await this.getAllTemplates();
|
|
const mergedTemplates = [...existingTemplates];
|
|
|
|
for (const template of importedTemplates) {
|
|
const existingIndex = mergedTemplates.findIndex((t) => t.id === template.id);
|
|
if (existingIndex >= 0) {
|
|
mergedTemplates[existingIndex] = template;
|
|
} else {
|
|
mergedTemplates.push(template);
|
|
}
|
|
}
|
|
|
|
await chrome.storage.local.set({ [TEMPLATE_STORAGE_KEY]: mergedTemplates });
|
|
return true;
|
|
} catch (error) {
|
|
console.error('导入模板失败:', error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 生成唯一ID
|
|
*/
|
|
static generateId(): string {
|
|
return `template_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
}
|
|
|
|
/**
|
|
* 创建空模板
|
|
*/
|
|
static createEmptyTemplate(name: string, description: string = ''): DataTemplate {
|
|
return {
|
|
id: this.generateId(),
|
|
name,
|
|
description,
|
|
fields: [],
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
};
|
|
}
|
|
}
|