From 1b34134418fdb523409b8527486e5274cd892b97 Mon Sep 17 00:00:00 2001 From: DebugIsFalse <511418503@qq.com> Date: Mon, 3 Jun 2024 11:54:12 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E6=9B=B4=E6=96=B0=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E6=A0=87?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composables/useLibraryRequest.js | 5 +++-- pages/search/[id].vue | 20 +++++++++++++++++++- stores/search.js | 9 +++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/composables/useLibraryRequest.js b/composables/useLibraryRequest.js index d3cf64e..ee5a28d 100644 --- a/composables/useLibraryRequest.js +++ b/composables/useLibraryRequest.js @@ -1,7 +1,8 @@ export default () => { // 查询主题列表 - const getThreadsList = async () => { - const { data, error } = await useRequest('/v1/chat/completion/list') + const getThreadsList = async (c_id) => { + let query = c_id ? `?c_id=${c_id}` : '' + const { data, error } = await useRequest(`/v1/chat/completion/list${query}`) if (error.value) { return [] } diff --git a/pages/search/[id].vue b/pages/search/[id].vue index 049388d..402b82e 100644 --- a/pages/search/[id].vue +++ b/pages/search/[id].vue @@ -53,7 +53,8 @@ const route = useRoute() const { y } = useWindowScroll({ behavior: 'smooth' }) const { directions } = useScroll(window) const { $firstRecordTitle } = storeToRefs(useSearchStore()) -const { $setFirstRecordTitle, $setSearchHistory } = useSearchStore() +const { $setFirstRecordTitle, $setSearchHistory, $updateSearchHistory } = useSearchStore() +const { getThreadsList } = useLibraryRequest() const state = reactive({ title: '', query: '', @@ -74,6 +75,8 @@ let asking = ref(false) // 处理ai generate let aiChatController = null // 用户取消操作方法 const markedEnd = '[DONE]' +// 是否是第一次生成记录 +const isFirstCreate = $firstRecordTitle.value !== '' function initSearchItemInfo (info, records) { const { title, repo_name, repo_path, repo_branch, is_public } = info @@ -246,8 +249,23 @@ const handleFormFetchData = (fetchData) => { resetAutoBottom() } } +const handleCreateAiTitle = () => { + if (isFirstCreate) { + // todo 需要延迟2s获取title + setTimeout(async () => { + const records = await getThreadsList(state.id) + const currentCollection = records.find( item => item.c_id === state.id) + if (currentCollection) { + state.title = currentCollection.title + $updateSearchHistory(currentCollection) + + } + }, 2000) + } +} const handleMessage = (event) => { if (event.data === markedEnd) { + handleCreateAiTitle() asking.value = false resetAnsLoading() handleStopGenerate() diff --git a/stores/search.js b/stores/search.js index e11c5b5..8082ea7 100644 --- a/stores/search.js +++ b/stores/search.js @@ -12,6 +12,14 @@ export const useSearchStore = defineStore('search', () => { history.push(item) searchHistory.value = JSON.stringify(history) } + function $updateSearchHistory (item) { + const history = searchHistory.value ? JSON.parse(searchHistory.value) : [] + const historyItem = history.find(i => i.c_id === item.c_id) + if (historyItem) { + Object.assign(historyItem, item) + } + searchHistory.value = JSON.stringify(history) + } function $clearSearchHistory () { searchHistory.value = '' } @@ -23,6 +31,7 @@ export const useSearchStore = defineStore('search', () => { return { $searchHistory, $setSearchHistory, + $updateSearchHistory, $clearSearchHistory, $firstRecordTitle, $setFirstRecordTitle -- GitLab