提交 1b341344 编写于 作者: D DebugIsFalse

feature: 更新动态生成历史记录标题

上级 9b22c32c
export default () => { export default () => {
// 查询主题列表 // 查询主题列表
const getThreadsList = async () => { const getThreadsList = async (c_id) => {
const { data, error } = await useRequest('/v1/chat/completion/list') let query = c_id ? `?c_id=${c_id}` : ''
const { data, error } = await useRequest(`/v1/chat/completion/list${query}`)
if (error.value) { if (error.value) {
return [] return []
} }
......
...@@ -53,7 +53,8 @@ const route = useRoute() ...@@ -53,7 +53,8 @@ const route = useRoute()
const { y } = useWindowScroll({ behavior: 'smooth' }) const { y } = useWindowScroll({ behavior: 'smooth' })
const { directions } = useScroll(window) const { directions } = useScroll(window)
const { $firstRecordTitle } = storeToRefs(useSearchStore()) const { $firstRecordTitle } = storeToRefs(useSearchStore())
const { $setFirstRecordTitle, $setSearchHistory } = useSearchStore() const { $setFirstRecordTitle, $setSearchHistory, $updateSearchHistory } = useSearchStore()
const { getThreadsList } = useLibraryRequest()
const state = reactive({ const state = reactive({
title: '', title: '',
query: '', query: '',
...@@ -74,6 +75,8 @@ let asking = ref(false) ...@@ -74,6 +75,8 @@ let asking = ref(false)
// 处理ai generate // 处理ai generate
let aiChatController = null // 用户取消操作方法 let aiChatController = null // 用户取消操作方法
const markedEnd = '[DONE]' const markedEnd = '[DONE]'
// 是否是第一次生成记录
const isFirstCreate = $firstRecordTitle.value !== ''
function initSearchItemInfo (info, records) { function initSearchItemInfo (info, records) {
const { title, repo_name, repo_path, repo_branch, is_public } = info const { title, repo_name, repo_path, repo_branch, is_public } = info
...@@ -246,8 +249,23 @@ const handleFormFetchData = (fetchData) => { ...@@ -246,8 +249,23 @@ const handleFormFetchData = (fetchData) => {
resetAutoBottom() 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) => { const handleMessage = (event) => {
if (event.data === markedEnd) { if (event.data === markedEnd) {
handleCreateAiTitle()
asking.value = false asking.value = false
resetAnsLoading() resetAnsLoading()
handleStopGenerate() handleStopGenerate()
......
...@@ -12,6 +12,14 @@ export const useSearchStore = defineStore('search', () => { ...@@ -12,6 +12,14 @@ export const useSearchStore = defineStore('search', () => {
history.push(item) history.push(item)
searchHistory.value = JSON.stringify(history) 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 () { function $clearSearchHistory () {
searchHistory.value = '' searchHistory.value = ''
} }
...@@ -23,6 +31,7 @@ export const useSearchStore = defineStore('search', () => { ...@@ -23,6 +31,7 @@ export const useSearchStore = defineStore('search', () => {
return { return {
$searchHistory, $searchHistory,
$setSearchHistory, $setSearchHistory,
$updateSearchHistory,
$clearSearchHistory, $clearSearchHistory,
$firstRecordTitle, $firstRecordTitle,
$setFirstRecordTitle $setFirstRecordTitle
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册