From cb3309295bd3c7e108cec5841ce5eb3db940c4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=84=AD=E6=B2=9B=E8=BB=92?= Date: Thu, 25 Sep 2025 01:57:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E8=A9=9E=E5=8D=A1=E5=9C=96=E7=89=87=E6=95=B4=E5=90=88=E8=88=87?= =?UTF-8?q?=E8=A9=9E=E6=80=A7=E7=B0=A1=E5=AF=AB=E9=A1=AF=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎉 前端詞卡管理功能完全整合後端圖片資料 **圖片整合功能**: - ✅ 更新Flashcard介面:添加exampleImages、hasExampleImage、primaryImageUrl欄位 - ✅ 取代硬編碼映射:getExampleImage和hasExampleImage改用API資料 - ✅ 詞卡列表頁面:完全使用動態圖片資料顯示 - ✅ 詞卡詳細頁面:修復資料載入邏輯使用列表API獲取圖片資訊 **詞性簡寫顯示**: - ✅ 全域詞性轉換函數:getPartOfSpeechDisplay() - ✅ 標準英語縮寫:noun→n., verb→v., adjective→adj.等 - ✅ 複合詞性處理:preposition/adverb→prep./adv. - ✅ 應用到所有詞性顯示位置:列表和詳細頁面 **系統整合成果**: - ✅ 完全移除硬編碼圖片映射依賴 - ✅ 前端直接使用後端API返回的圖片URL - ✅ 支援AI生成圖片的即時顯示 - ✅ Mock資料相容性:添加圖片欄位避免錯誤 前端詞卡管理系統現已完全整合AI圖片生成功能! 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- frontend/app/flashcards/[id]/page.tsx | 67 ++++++++++++++++++++------- frontend/app/flashcards/page.tsx | 46 +++++++++++------- frontend/lib/services/flashcards.ts | 17 ++++++- 3 files changed, 95 insertions(+), 35 deletions(-) diff --git a/frontend/app/flashcards/[id]/page.tsx b/frontend/app/flashcards/[id]/page.tsx index 9edfcdb..3fd50e4 100644 --- a/frontend/app/flashcards/[id]/page.tsx +++ b/frontend/app/flashcards/[id]/page.tsx @@ -50,7 +50,11 @@ function FlashcardDetailContent({ cardId }: { cardId: string }) { cardSet: { name: '基礎詞彙', color: 'bg-blue-500' }, difficultyLevel: 'A1', createdAt: '2025-09-17', - synonyms: ['hi', 'greetings', 'good day'] + synonyms: ['hi', 'greetings', 'good day'], + // 添加圖片欄位 + exampleImages: [], + hasExampleImage: false, + primaryImageUrl: null }, 'mock2': { id: 'mock2', @@ -68,7 +72,11 @@ function FlashcardDetailContent({ cardId }: { cardId: string }) { cardSet: { name: '高級詞彙', color: 'bg-purple-500' }, difficultyLevel: 'B2', createdAt: '2025-09-14', - synonyms: ['explain', 'detail', 'expand', 'clarify'] + synonyms: ['explain', 'detail', 'expand', 'clarify'], + // 添加圖片欄位 + exampleImages: [], + hasExampleImage: false, + primaryImageUrl: null } } @@ -86,13 +94,18 @@ function FlashcardDetailContent({ cardId }: { cardId: string }) { return } - // 載入真實詞卡 - const result = await flashcardsService.getFlashcard(cardId) + // 載入真實詞卡 - 使用列表 API 然後找到對應詞卡 (因為列表 API 有圖片資訊) + const result = await flashcardsService.getFlashcards() if (result.success && result.data) { - setFlashcard(result.data) - setEditedCard(result.data) + const targetCard = result.data.flashcards.find(card => card.id === cardId) + if (targetCard) { + setFlashcard(targetCard) + setEditedCard(targetCard) + } else { + throw new Error('詞卡不存在') + } } else { - throw new Error(result.error || '詞卡不存在') + throw new Error(result.error || '載入詞卡失敗') } } catch (err) { setError('載入詞卡時發生錯誤') @@ -117,14 +130,34 @@ function FlashcardDetailContent({ cardId }: { cardId: string }) { } } - // 獲取例句圖片 - const getExampleImage = (word: string) => { - const imageMap: {[key: string]: string} = { - 'hello': '/images/examples/bring_up.png', - 'elaborate': '/images/examples/instinct.png', - 'beautiful': '/images/examples/warrant.png' + // 獲取例句圖片 - 使用 API 資料 + const getExampleImage = (card: Flashcard): string | null => { + return card.primaryImageUrl || null + } + + // 檢查詞彙是否有例句圖片 - 使用 API 資料 + const hasExampleImage = (card: Flashcard): boolean => { + return card.hasExampleImage + } + + // 詞性簡寫轉換 + const getPartOfSpeechDisplay = (partOfSpeech: string): string => { + const shortMap: {[key: string]: string} = { + 'noun': 'n.', + 'verb': 'v.', + 'adjective': 'adj.', + 'adverb': 'adv.', + 'preposition': 'prep.', + 'interjection': 'int.', + 'phrase': 'phr.' } - return imageMap[word?.toLowerCase()] || '/images/examples/bring_up.png' + + // 處理複合詞性 (如 "preposition/adverb") + if (partOfSpeech?.includes('/')) { + return partOfSpeech.split('/').map(p => shortMap[p.trim()] || p.trim()).join('/') + } + + return shortMap[partOfSpeech] || partOfSpeech || '' } // 處理收藏切換 @@ -277,7 +310,7 @@ function FlashcardDetailContent({ cardId }: { cardId: string }) {

{flashcard.word}

- {flashcard.partOfSpeech} + {getPartOfSpeechDisplay(flashcard.partOfSpeech)} {flashcard.pronunciation}