diff --git a/composables/useLibraryRequest.js b/composables/useLibraryRequest.js index d3cf64e53128db76ddb0d0d8d8a79965e3c56f90..ee5a28db467511114f69d838019c2c8b18778c3a 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 049388d6ed386b623e80dd75df4b6843b8f173a0..402b82e993be17969c09e0689f0fe5ad3b58928d 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 e11c5b547590385e7d89508171167827a1088b4f..8082ea7d7898d8a5942e1ec4fb97824de1b88ffa 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