From 7bb557be01033c6fb07a94e4b63d5addda3b4ea1 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:20:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(M3.6):=20=E7=82=B9=E5=87=BB=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E6=9F=A5=E8=AF=8D=EF=BC=88Mock=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=EF=BC=89=20(v0.2.6)?= 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/content/selection.js | 41 +++++++++++++++++++++++++++++++++++++++- 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/docs/QUICK_REF.md b/docs/QUICK_REF.md index a45d27f..46d86ee 100644 --- a/docs/QUICK_REF.md +++ b/docs/QUICK_REF.md @@ -7,7 +7,7 @@ ## 版本速查 ### 当前版本 -`0.2.5` → 下一目标 `0.2.6` ([M3.6](./M3.md)) +`0.2.6` → 下一目标 `0.2.7` ([M3.7](./M3.md)) ### 模块版本范围 diff --git a/docs/README.md b/docs/README.md index b6b9654..3748609 100644 --- a/docs/README.md +++ b/docs/README.md @@ -65,9 +65,9 @@ M11.10完成 → 1.0.0 (正式发布) ## 当前状态 -**当前版本**: `0.2.5` -**当前进度**: 19/97 (20%) -**下一任务**: [M3.6 点击图标查词(Mock数据)](./M3.md#m36-点击图标查词mock数据--目标版本-026) +**当前版本**: `0.2.6` +**当前进度**: 20/97 (21%) +**下一任务**: [M3.7 必应词典真实API](./M3.md#m37-必应词典真实api--目标版本-027) --- diff --git a/docs/VERSION.md b/docs/VERSION.md index 69ce5dc..583fdea 100644 --- a/docs/VERSION.md +++ b/docs/VERSION.md @@ -41,7 +41,7 @@ | M3.3 | 0.2.3 | 必应词典(Mock) | ✅ | 2026-02-11 | | M3.4 | 0.2.4 | 后台查询接口 | ✅ | 2026-02-11 | | M3.5 | 0.2.5 | 结果展示组件 | ✅ | 2026-02-11 | -| M3.6 | 0.2.6 | 点击图标查词(Mock) | ⬜ | - | +| M3.6 | 0.2.6 | 点击图标查词(Mock) | ✅ | 2026-02-11 | | M3.7 | 0.2.7 | 必应词典真实API | ⬜ | - | | M3.8 | 0.2.8 | 加载状态显示 | ⬜ | - | | M3.9 | 0.2.9 | 有道词典实现 | ⬜ | - | diff --git a/manifest.json b/manifest.json index ba6a4e4..2894845 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "沙拉查词", - "version": "0.2.5", + "version": "0.2.6", "description": "聚合词典划词翻译", "permissions": [ "storage", diff --git a/package.json b/package.json index b3f0edf..ecab8af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salad-dict", - "version": "0.2.5", + "version": "0.2.6", "description": "聚合词典划词翻译", "private": true, "type": "module", diff --git a/src/content/selection.js b/src/content/selection.js index a4012c6..1cf9bb5 100644 --- a/src/content/selection.js +++ b/src/content/selection.js @@ -7,6 +7,7 @@ import { logger } from './logger.js'; import { createSaladIcon } from './components/SaladIcon.js'; import { DictPanel } from './components/DictPanel.js'; import { ConfigManager, isSelectionEnabled } from '../shared/config.js'; +import { messaging } from '../shared/messaging.js'; let currentIcon = null; let currentPanel = null; @@ -146,9 +147,12 @@ function showSaladIcon(x, y) { // 创建新图标,传入点击回调 currentIcon = createSaladIcon(x, y, { - onClick: (event) => { + onClick: async (event) => { logger.info('Icon clicked, showing panel'); + // 获取选中的文本 + const selectedText = getSelectedText(); + // 图标消失 if (currentIcon) { currentIcon.destroy(); @@ -161,6 +165,41 @@ function showSaladIcon(x, y) { currentPanel = new DictPanel(); currentPanel.show(panelX, panelY); console.log('[SaladDict] Panel shown at:', panelX, panelY); + + // 执行词典查询 + if (selectedText) { + try { + console.log('[SaladDict] Searching for:', selectedText); + const response = await messaging.sendToBackground('DICT.SEARCH', { + word: selectedText + }); + + console.log('[SaladDict] Search response:', response); + + // 显示查询结果 + if (response?.results && response.results.length > 0) { + const firstResult = response.results[0].result; + currentPanel.renderResult(firstResult); + logger.info('Search result rendered:', firstResult.word); + } else { + currentPanel.renderResult({ + word: selectedText, + phonetic: '', + meanings: [{ partOfSpeech: 'n.', definitions: ['暂无释义'] }], + examples: [] + }); + logger.warn('No search results for:', selectedText); + } + } catch (error) { + console.error('[SaladDict] Search failed:', error); + currentPanel.renderResult({ + word: selectedText, + phonetic: '', + meanings: [{ partOfSpeech: 'n.', definitions: ['查询失败,请重试'] }], + examples: [] + }); + } + } } });