From 544dda81c48a8296a1589130712146b32a13699f Mon Sep 17 00:00:00 2001 From: zthxxx Date: Thu, 7 Sep 2023 00:54:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=95=AA=E5=89=A7=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=A1=86=E6=8E=A5=E5=8F=A3=E4=BD=BF=E7=94=A8=E5=92=8C=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 三种搜索触发来源 - 输入中 debounce 600ms 后触发搜索 - 按回车或点击搜索 icon 按钮后触发搜索 - 切换 provider 源站时触发搜索 - 渲染的番剧信息列表样式待调整 - 搜索框 placeholder / provider 展示样式/i18n 待调整 --- .vscode/launch.json | 3 + backend/src/main.py | 2 +- webui/src/components/basic/ab-search.vue | 85 ++++++++++++------------ webui/src/store/search.ts | 45 ++++++------- 4 files changed, 66 insertions(+), 69 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 3accd58dc..c83587206 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,6 +10,9 @@ "request": "launch", "cwd": "${workspaceFolder}/backend/src", "program": "main.py", + "env": { + "HOST": "127.0.0.1", + }, "console": "integratedTerminal", "justMyCode": true } diff --git a/backend/src/main.py b/backend/src/main.py index 4638f9f27..581d21730 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -100,7 +100,7 @@ def index(): if os.getenv("IPV6"): host = "::" else: - host = "0.0.0.0" + host = os.getenv("HOST", "0.0.0.0") uvicorn.run( app, host=host, diff --git a/webui/src/components/basic/ab-search.vue b/webui/src/components/basic/ab-search.vue index 2827dfd8f..1734bdaa8 100644 --- a/webui/src/components/basic/ab-search.vue +++ b/webui/src/components/basic/ab-search.vue @@ -2,35 +2,39 @@ import {Down, Search} from '@icon-park/vue-next'; import {ref} from 'vue'; -const props = withDefaults( - defineProps<{ - value?: string; - placeholder?: string; - }>(), - { - value: '', - placeholder: '', - } -); -const emit = defineEmits(['update:value', 'click-search']); -const {site, providers, bangumiInfo$ } = storeToRefs(useSearchStore()); -const {getProviders, onInput} = useSearchStore(); +const inputValue = ref(''); +const selectingProvider = ref(false); +const {input$, provider, providers, getProviders, bangumiList } = useSearchStore(); -onMounted(() => { - getProviders(); -}); +/** + * - 输入中 debounce 600ms 后触发搜索 + * - 按回车或点击搜索 icon 按钮后触发搜索 + * - 切换 provider 源站时触发搜索 + */ -const selectedProvider = computed(() => { - return site.value || ''; -}); -const onSelect = ref(false); +function onInput (e: Event) { + const value = (e.target as HTMLInputElement).value; + input$.next(value); + inputValue.value = value; +} + +function onSearch () { + input$.next(inputValue.value); +} -function onSearch() { - emit('click-search', props.value); +function onSelect (site: string) { + provider.value = site; + selectingProvider.value = !selectingProvider.value + onSearch(); } + +onMounted(() => { + getProviders(); +}); + diff --git a/webui/src/store/search.ts b/webui/src/store/search.ts index 8c2acb375..7d779f7a0 100644 --- a/webui/src/store/search.ts +++ b/webui/src/store/search.ts @@ -1,19 +1,21 @@ +import {ref} from 'vue'; import { Subject, debounceTime, + filter, switchMap, tap, } from "rxjs"; import type {BangumiRule} from "#/bangumi"; -export const useSearchStore = defineStore('search', () => { - const input$ = new Subject(); - const onInput = (e: Event) => input$.next(e.target.value); +export function useSearchStore () { + const bangumiList = ref([]); + const providers = ref(['mikan', 'dmhy', 'nyaa']); - const site = ref('mikan'); + const provider = ref('mikan'); - const bangumiInfo$ = apiSearch.get('魔女之旅'); + const input$ = new Subject(); const {execute: getProviders, onResult: onGetProvidersResult} = useApi( apiSearch.getProvider @@ -23,34 +25,25 @@ export const useSearchStore = defineStore('search', () => { providers.value = res; }); - input$.pipe( - debounceTime(1000), - tap((input: string) => { - console.log('input', input) - // clear Search Result List - + const bangumiInfo$ = input$.pipe( + debounceTime(600), + tap(() => { + bangumiList.value = []; }), - switchMap((input: string) => apiSearch.get(input, site.value)), - tap((bangumi: BangumiRule) => console.log(bangumi)), + filter(Boolean), + switchMap((input: string) => apiSearch.get(input, provider.value)), tap((bangumi: BangumiRule) => { - console.log('bangumi', bangumi) - // set bangumi info to Search Result List + bangumiList.value.push(bangumi); }), - ).subscribe({ - complete() { - // end of stream, stop loading animation - } - }, (err) => { - console.error(err); - }); - + ) + .subscribe() return { input$, - onInput, bangumiInfo$, - site, + provider, getProviders, providers, + bangumiList, }; -}); \ No newline at end of file +} \ No newline at end of file