From 556c371eef85192de2b27f1295e3c79ad963516d Mon Sep 17 00:00:00 2001 From: KirisameVanilla <118162831+KirisameVanilla@users.noreply.github.com> Date: Tue, 9 Sep 2025 15:08:39 +0800 Subject: [PATCH] feat: search --- src/api/dict.ts | 42 +++++++-- src/components/SearchBar.vue | 100 +++++++++++++++++++- src/views/DictPage.vue | 173 ++++++++++++++++++++++++++++------- 3 files changed, 269 insertions(+), 46 deletions(-) diff --git a/src/api/dict.ts b/src/api/dict.ts index 73d2cd6..994d699 100644 --- a/src/api/dict.ts +++ b/src/api/dict.ts @@ -1,24 +1,48 @@ import apiClient from './client' -export interface WordDefinition { - word: string - part_of_speech: string - meaning: string +export interface WordContent { + chi_exp: string example: string } +export interface WordDefinition { + query: string + pos: string[] + contents: WordContent[] +} + export interface SearchParams { lang_pref: string query_word: string } +export interface SearchSuggestParams { + query: string + language: string +} + +export interface SearchSuggestResponse { + list: string[] +} + // 搜索单词 -export const searchWord = async (params: SearchParams): Promise => { - const response = await apiClient.get('/search', { - params: { - lang_pref: params.lang_pref, - query_word: params.query_word +export const searchWord = async (params: SearchParams): Promise => { + const packet = { + language: params.lang_pref, + query: params.query_word, + sort: "relevance", + order: "asc" } + const response = await apiClient.post('/search', packet) + console.log(response) + return response.data +} + +// 搜索推荐 +export const searchSuggest = async (params: SearchSuggestParams): Promise => { + const response = await apiClient.post('/search/list', { + query: params.query, + language: params.language }) return response.data } diff --git a/src/components/SearchBar.vue b/src/components/SearchBar.vue index 96a5667..2c43cc9 100644 --- a/src/components/SearchBar.vue +++ b/src/components/SearchBar.vue @@ -5,12 +5,15 @@ v-model="selectedLang" class="top-1/2 left-0 z-10 absolute bg-blue-700 px-8 py-3 border-none rounded-full outline-none text-white -translate-y-1/2 appearance-none cursor-pointer" > + - + + +
+
+ {{ suggestion }} +
+
\ No newline at end of file diff --git a/src/views/DictPage.vue b/src/views/DictPage.vue index 1341236..a95ebd6 100644 --- a/src/views/DictPage.vue +++ b/src/views/DictPage.vue @@ -6,19 +6,40 @@
-

法语词典查询

-

输入法语单词,获取详细释义和例句

+

多语言词典查询

+

输入单词,获取详细释义和例句

-
- +
+
+ + + +
+
+ {{ suggestion }} +
+
+
+
@@ -45,25 +66,39 @@ {{ error }}
-
+

搜索结果

-
+
-

{{ result.word }}

- - {{ result.part_of_speech }} - +

{{ searchResult.query }}

+
+ + {{ pos }} + +
-
-

释义:

-

{{ result.meaning }}

-
- -
-

例句:

-

{{ result.example }}

+
+
+
+

释义:

+

{{ content.chi_exp }}

+
+ +
+

例句:

+

{{ content.example }}

+
+
@@ -76,8 +111,8 @@
🔍
-

开始您的法语词汇探索之旅

-

在上方输入框中输入法语单词进行查询

+

开始您的词汇探索之旅

+

在上方输入框中输入单词进行查询

@@ -87,19 +122,82 @@ \ No newline at end of file