feat(M3.4): 后台查询接口 (v0.2.4)

This commit is contained in:
李岩岩 2026-02-11 14:19:30 +08:00
parent 09f0978025
commit fde62ba8fb
7 changed files with 51 additions and 10 deletions

View File

@ -7,7 +7,7 @@
## 版本速查 ## 版本速查
### 当前版本 ### 当前版本
`0.2.3` → 下一目标 `0.2.4` ([M3.4](./M3.md)) `0.2.4` → 下一目标 `0.2.5` ([M3.5](./M3.md))
### 模块版本范围 ### 模块版本范围

View File

@ -65,9 +65,9 @@ M11.10完成 → 1.0.0 (正式发布)
## 当前状态 ## 当前状态
**当前版本**: `0.2.3` **当前版本**: `0.2.4`
**当前进度**: 17/97 (18%) **当前进度**: 18/97 (19%)
**下一任务**: [M3.4 后台查询接口](./M3.md#m34-后台查询接口--目标版本-024) **下一任务**: [M3.5 结果展示组件(静态)](./M3.md#m35-结果展示组件静态--目标版本-025)
--- ---

View File

@ -39,7 +39,7 @@
| M3.1 | 0.2.1 | 词典接口基类 | ✅ | 2026-02-11 | | M3.1 | 0.2.1 | 词典接口基类 | ✅ | 2026-02-11 |
| M3.2 | 0.2.2 | 词典管理器 | ✅ | 2026-02-11 | | M3.2 | 0.2.2 | 词典管理器 | ✅ | 2026-02-11 |
| M3.3 | 0.2.3 | 必应词典(Mock) | ✅ | 2026-02-11 | | M3.3 | 0.2.3 | 必应词典(Mock) | ✅ | 2026-02-11 |
| M3.4 | 0.2.4 | 后台查询接口 | ⬜ | - | | M3.4 | 0.2.4 | 后台查询接口 | ✅ | 2026-02-11 |
| M3.5 | 0.2.5 | 结果展示组件 | ⬜ | - | | M3.5 | 0.2.5 | 结果展示组件 | ⬜ | - |
| M3.6 | 0.2.6 | 点击图标查词(Mock) | ⬜ | - | | M3.6 | 0.2.6 | 点击图标查词(Mock) | ⬜ | - |
| M3.7 | 0.2.7 | 必应词典真实API | ⬜ | - | | M3.7 | 0.2.7 | 必应词典真实API | ⬜ | - |

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "沙拉查词", "name": "沙拉查词",
"version": "0.2.3", "version": "0.2.4",
"description": "聚合词典划词翻译", "description": "聚合词典划词翻译",
"permissions": [ "permissions": [
"storage", "storage",

View File

@ -1,6 +1,6 @@
{ {
"name": "salad-dict", "name": "salad-dict",
"version": "0.2.3", "version": "0.2.4",
"description": "聚合词典划词翻译", "description": "聚合词典划词翻译",
"private": true, "private": true,
"type": "module", "type": "module",

View File

@ -1,5 +1,6 @@
// Background Service Worker // Background Service Worker
import { backgroundHandler } from '../shared/messaging.js'; import { backgroundHandler } from '../shared/messaging.js';
import { dictionaryManager, bingDictionary } from '../shared/dictionary/index.js';
console.log('[SaladDict] Background service worker started'); console.log('[SaladDict] Background service worker started');
@ -11,7 +12,39 @@ chrome.runtime.onInstalled.addListener((details) => {
// BackgroundHandler 自动初始化消息监听 // BackgroundHandler 自动初始化消息监听
console.log('[SaladDict] Message handler initialized'); console.log('[SaladDict] Message handler initialized');
// 注册自定义消息处理器示例 // 注册词典到管理器
backgroundHandler.register('ECHO', async (payload) => { dictionaryManager.register('bing', bingDictionary);
return { echo: payload }; console.log('[SaladDict] Registered dictionaries:', dictionaryManager.getNames());
// 注册词典查询处理器
backgroundHandler.register('DICT.SEARCH', async (payload) => {
const { word, dictNames = [] } = payload;
console.log('[Background] DICT.SEARCH:', word, dictNames);
try {
const { results, errors } = await dictionaryManager.search(word, dictNames);
console.log('[Background] Search results:', results);
if (errors.length > 0) {
console.warn('[Background] Search errors:', errors);
}
return { results, errors };
} catch (error) {
console.error('[Background] Search failed:', error);
throw error;
}
}); });
// 注册获取词典列表处理器
backgroundHandler.register('DICT.GET_LIST', async () => {
const dictionaries = dictionaryManager.getAll().map(({ name, dictionary }) => ({
name,
info: dictionary.getInfo()
}));
return { dictionaries };
});
console.log('[SaladDict] Message handlers registered');

View File

@ -0,0 +1,8 @@
/**
* @file 词典模块入口
* @description 导出词典基类管理器和具体实现
*/
export { DictionaryBase, createResult, createMeaning, createExample } from './base.js';
export { DictionaryManager, dictionaryManager } from './manager.js';
export { BingDictionary, bingDictionary } from './bing.js';