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

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

上级 9b22c32c
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 []
}
......
......@@ -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()
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册