From fde62ba8fb3ed78d5f9e0773739a184264ade5a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B2=A9=E5=B2=A9?= Date: Wed, 11 Feb 2026 14:19:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(M3.4):=20=E5=90=8E=E5=8F=B0=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=8E=A5=E5=8F=A3=20(v0.2.4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/QUICK_REF.md | 2 +- docs/README.md | 6 +++--- docs/VERSION.md | 2 +- manifest.json | 2 +- package.json | 2 +- src/background/index.js | 39 +++++++++++++++++++++++++++++++--- src/shared/dictionary/index.js | 8 +++++++ 7 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 src/shared/dictionary/index.js diff --git a/docs/QUICK_REF.md b/docs/QUICK_REF.md index b3f39c7..3348a74 100644 --- a/docs/QUICK_REF.md +++ b/docs/QUICK_REF.md @@ -7,7 +7,7 @@ ## 版本速查 ### 当前版本 -`0.2.3` → 下一目标 `0.2.4` ([M3.4](./M3.md)) +`0.2.4` → 下一目标 `0.2.5` ([M3.5](./M3.md)) ### 模块版本范围 diff --git a/docs/README.md b/docs/README.md index e157caf..6e37797 100644 --- a/docs/README.md +++ b/docs/README.md @@ -65,9 +65,9 @@ M11.10完成 → 1.0.0 (正式发布) ## 当前状态 -**当前版本**: `0.2.3` -**当前进度**: 17/97 (18%) -**下一任务**: [M3.4 后台查询接口](./M3.md#m34-后台查询接口--目标版本-024) +**当前版本**: `0.2.4` +**当前进度**: 18/97 (19%) +**下一任务**: [M3.5 结果展示组件(静态)](./M3.md#m35-结果展示组件静态--目标版本-025) --- diff --git a/docs/VERSION.md b/docs/VERSION.md index 4153939..9f3c9c6 100644 --- a/docs/VERSION.md +++ b/docs/VERSION.md @@ -39,7 +39,7 @@ | M3.1 | 0.2.1 | 词典接口基类 | ✅ | 2026-02-11 | | M3.2 | 0.2.2 | 词典管理器 | ✅ | 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.6 | 0.2.6 | 点击图标查词(Mock) | ⬜ | - | | M3.7 | 0.2.7 | 必应词典真实API | ⬜ | - | diff --git a/manifest.json b/manifest.json index 61a622f..d686860 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "沙拉查词", - "version": "0.2.3", + "version": "0.2.4", "description": "聚合词典划词翻译", "permissions": [ "storage", diff --git a/package.json b/package.json index 7a96fec..1479fb8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salad-dict", - "version": "0.2.3", + "version": "0.2.4", "description": "聚合词典划词翻译", "private": true, "type": "module", diff --git a/src/background/index.js b/src/background/index.js index 4055966..4a47037 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,5 +1,6 @@ // Background Service Worker import { backgroundHandler } from '../shared/messaging.js'; +import { dictionaryManager, bingDictionary } from '../shared/dictionary/index.js'; console.log('[SaladDict] Background service worker started'); @@ -11,7 +12,39 @@ chrome.runtime.onInstalled.addListener((details) => { // BackgroundHandler 自动初始化消息监听 console.log('[SaladDict] Message handler initialized'); -// 注册自定义消息处理器示例 -backgroundHandler.register('ECHO', async (payload) => { - return { echo: payload }; +// 注册词典到管理器 +dictionaryManager.register('bing', bingDictionary); +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'); diff --git a/src/shared/dictionary/index.js b/src/shared/dictionary/index.js new file mode 100644 index 0000000..70adae6 --- /dev/null +++ b/src/shared/dictionary/index.js @@ -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';