From 09f097802526f10fc7ec9a6dd1a1ed335882042e 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:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(M3.3):=20=E5=BF=85=E5=BA=94=E8=AF=8D?= =?UTF-8?q?=E5=85=B8=E5=AE=9E=E7=8E=B0=EF=BC=88Mock=E7=89=88=EF=BC=89=20(v?= =?UTF-8?q?0.2.3)?= 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/shared/dictionary/bing.js | 144 ++++++++++++++++++++++++++++++++++ 6 files changed, 151 insertions(+), 7 deletions(-) create mode 100644 src/shared/dictionary/bing.js diff --git a/docs/QUICK_REF.md b/docs/QUICK_REF.md index 262dd83..b3f39c7 100644 --- a/docs/QUICK_REF.md +++ b/docs/QUICK_REF.md @@ -7,7 +7,7 @@ ## 版本速查 ### 当前版本 -`0.2.2` → 下一目标 `0.2.3` ([M3.3](./M3.md)) +`0.2.3` → 下一目标 `0.2.4` ([M3.4](./M3.md)) ### 模块版本范围 diff --git a/docs/README.md b/docs/README.md index 0b17515..e157caf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -65,9 +65,9 @@ M11.10完成 → 1.0.0 (正式发布) ## 当前状态 -**当前版本**: `0.2.2` -**当前进度**: 16/97 (16%) -**下一任务**: [M3.3 必应词典实现(Mock版)](./M3.md#m33-必应词典实现mock版--目标版本-023) +**当前版本**: `0.2.3` +**当前进度**: 17/97 (18%) +**下一任务**: [M3.4 后台查询接口](./M3.md#m34-后台查询接口--目标版本-024) --- diff --git a/docs/VERSION.md b/docs/VERSION.md index 36ad522..4153939 100644 --- a/docs/VERSION.md +++ b/docs/VERSION.md @@ -38,7 +38,7 @@ |------|------|------|------|------| | M3.1 | 0.2.1 | 词典接口基类 | ✅ | 2026-02-11 | | M3.2 | 0.2.2 | 词典管理器 | ✅ | 2026-02-11 | -| M3.3 | 0.2.3 | 必应词典(Mock) | ⬜ | - | +| M3.3 | 0.2.3 | 必应词典(Mock) | ✅ | 2026-02-11 | | M3.4 | 0.2.4 | 后台查询接口 | ⬜ | - | | M3.5 | 0.2.5 | 结果展示组件 | ⬜ | - | | M3.6 | 0.2.6 | 点击图标查词(Mock) | ⬜ | - | diff --git a/manifest.json b/manifest.json index a508792..61a622f 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "沙拉查词", - "version": "0.2.2", + "version": "0.2.3", "description": "聚合词典划词翻译", "permissions": [ "storage", diff --git a/package.json b/package.json index 3accd74..7a96fec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salad-dict", - "version": "0.2.2", + "version": "0.2.3", "description": "聚合词典划词翻译", "private": true, "type": "module", diff --git a/src/shared/dictionary/bing.js b/src/shared/dictionary/bing.js new file mode 100644 index 0000000..f7d32d6 --- /dev/null +++ b/src/shared/dictionary/bing.js @@ -0,0 +1,144 @@ +/** + * @file 必应词典实现(Mock版) + * @description 必应词典的 Mock 实现,返回模拟数据 + */ + +import { DictionaryBase, createResult, createMeaning, createExample } from './base.js'; + +/** + * 必应词典 Mock 实现 + */ +export class BingDictionary extends DictionaryBase { + constructor(config = {}) { + super({ + name: '必应词典', + icon: 'icons/bing.png', + languages: ['en', 'zh'], + ...config + }); + } + + /** + * 查询单词(Mock 实现) + * @param {string} word - 要查询的单词 + * @returns {Promise} 模拟查询结果 + */ + async search(word) { + if (!word?.trim()) { + throw new Error('Word is empty'); + } + + const trimmedWord = word.trim(); + + // 模拟网络延迟 + await this._delay(100); + + // 返回模拟数据 + return createResult({ + word: trimmedWord, + phonetic: this._getMockPhonetic(trimmedWord), + meanings: this._getMockMeanings(trimmedWord), + examples: this._getMockExamples(trimmedWord), + url: `https://cn.bing.com/dict/search?q=${encodeURIComponent(trimmedWord)}` + }); + } + + /** + * 模拟延迟 + * @private + * @param {number} ms - 延迟毫秒数 + * @returns {Promise} + */ + _delay(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + /** + * 获取模拟音标 + * @private + * @param {string} word - 单词 + * @returns {string} 音标 + */ + _getMockPhonetic(word) { + const phonetics = { + 'hello': '/həˈləʊ/', + 'world': '/wɜːld/', + 'apple': '/ˈæpl/', + 'computer': '/kəmˈpjuːtə(r)/', + 'dictionary': '/ˈdɪkʃənri/' + }; + + return phonetics[word.toLowerCase()] || `/${word.toLowerCase()}/`; + } + + /** + * 获取模拟释义 + * @private + * @param {string} word - 单词 + * @returns {Array} 释义列表 + */ + _getMockMeanings(word) { + const meaningsMap = { + 'hello': [ + createMeaning('int.', ['你好', '喂', '嘿']), + createMeaning('n.', ['问候', '招呼']) + ], + 'world': [ + createMeaning('n.', ['世界', '地球', '天下', '界']) + ], + 'apple': [ + createMeaning('n.', ['苹果', '苹果公司']) + ], + 'computer': [ + createMeaning('n.', ['计算机', '电脑']) + ], + 'dictionary': [ + createMeaning('n.', ['词典', '字典', '辞典']) + ] + }; + + return meaningsMap[word.toLowerCase()] || [ + createMeaning('n.', [`${word} 的中文释义`]), + createMeaning('v.', [`${word} 的动词释义`]) + ]; + } + + /** + * 获取模拟例句 + * @private + * @param {string} word - 单词 + * @returns {Array} 例句列表 + */ + _getMockExamples(word) { + const examplesMap = { + 'hello': [ + createExample('Hello, how are you?', '你好,你好吗?'), + createExample('She said hello to everyone.', '她向每个人问好。') + ], + 'world': [ + createExample('The world is getting smaller.', '世界变得越来越小。'), + createExample('He wants to travel around the world.', '他想环游世界。') + ], + 'apple': [ + createExample('An apple a day keeps the doctor away.', '一天一苹果,医生远离我。'), + createExample('She took a bite of the apple.', '她咬了一口苹果。') + ], + 'computer': [ + createExample('I use a computer for work.', '我用电脑工作。'), + createExample('The computer is running slowly.', '电脑运行很慢。') + ], + 'dictionary': [ + createExample('I looked it up in the dictionary.', '我在词典里查了一下。'), + createExample('This is an English-Chinese dictionary.', '这是一本英汉词典。') + ] + }; + + return examplesMap[word.toLowerCase()] || [ + createExample(`This is a sentence with "${word}".`, `这是一个包含"${word}"的句子。`), + createExample(`Can you use "${word}" in a sentence?`, `你能用"${word}"造句吗?`) + ]; + } +} + +// 导出单例实例 +export const bingDictionary = new BingDictionary();