feat(M3.6): 点击图标查词(Mock数据) (v0.2.6)

This commit is contained in:
李岩岩 2026-02-11 14:20:28 +08:00
parent 70a76ac438
commit 7bb557be01
6 changed files with 47 additions and 8 deletions

View File

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

View File

@ -65,9 +65,9 @@ M11.10完成 → 1.0.0 (正式发布)
## 当前状态 ## 当前状态
**当前版本**: `0.2.5` **当前版本**: `0.2.6`
**当前进度**: 19/97 (20%) **当前进度**: 20/97 (21%)
**下一任务**: [M3.6 点击图标查词Mock数据](./M3.md#m36-点击图标查词mock数据--目标版本-026) **下一任务**: [M3.7 必应词典真实API](./M3.md#m37-必应词典真实api--目标版本-027)
--- ---

View File

@ -41,7 +41,7 @@
| M3.3 | 0.2.3 | 必应词典(Mock) | ✅ | 2026-02-11 | | M3.3 | 0.2.3 | 必应词典(Mock) | ✅ | 2026-02-11 |
| M3.4 | 0.2.4 | 后台查询接口 | ✅ | 2026-02-11 | | M3.4 | 0.2.4 | 后台查询接口 | ✅ | 2026-02-11 |
| M3.5 | 0.2.5 | 结果展示组件 | ✅ | 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.7 | 0.2.7 | 必应词典真实API | ⬜ | - |
| M3.8 | 0.2.8 | 加载状态显示 | ⬜ | - | | M3.8 | 0.2.8 | 加载状态显示 | ⬜ | - |
| M3.9 | 0.2.9 | 有道词典实现 | ⬜ | - | | M3.9 | 0.2.9 | 有道词典实现 | ⬜ | - |

View File

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

View File

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

View File

@ -7,6 +7,7 @@ import { logger } from './logger.js';
import { createSaladIcon } from './components/SaladIcon.js'; import { createSaladIcon } from './components/SaladIcon.js';
import { DictPanel } from './components/DictPanel.js'; import { DictPanel } from './components/DictPanel.js';
import { ConfigManager, isSelectionEnabled } from '../shared/config.js'; import { ConfigManager, isSelectionEnabled } from '../shared/config.js';
import { messaging } from '../shared/messaging.js';
let currentIcon = null; let currentIcon = null;
let currentPanel = null; let currentPanel = null;
@ -146,9 +147,12 @@ function showSaladIcon(x, y) {
// 创建新图标,传入点击回调 // 创建新图标,传入点击回调
currentIcon = createSaladIcon(x, y, { currentIcon = createSaladIcon(x, y, {
onClick: (event) => { onClick: async (event) => {
logger.info('Icon clicked, showing panel'); logger.info('Icon clicked, showing panel');
// 获取选中的文本
const selectedText = getSelectedText();
// 图标消失 // 图标消失
if (currentIcon) { if (currentIcon) {
currentIcon.destroy(); currentIcon.destroy();
@ -161,6 +165,41 @@ function showSaladIcon(x, y) {
currentPanel = new DictPanel(); currentPanel = new DictPanel();
currentPanel.show(panelX, panelY); currentPanel.show(panelX, panelY);
console.log('[SaladDict] Panel shown at:', 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: []
});
}
}
} }
}); });