diff --git a/pages/search/[id].vue b/pages/search/[id].vue index b581ed697c54acc8a18cdbefc137aa754f1ee3b8..14993b726c280632ccb94dc0a8cd349d41d37c9c 100644 --- a/pages/search/[id].vue +++ b/pages/search/[id].vue @@ -54,6 +54,49 @@ const state = reactive({ branch: '', gitPath: '' }) +const data = ref([]) +const askingData = ref({ question: state.query, desLoading: true }) +const recommendQuestions = ref([]) +const askingRef = ref(null) +const historyAskRefs = ref([]) +let asking = ref(false) +// 处理ai generate +let aiChatController = null // 用户取消操作方法 +const markedEnd = '[DONE]' + +function initSearchItemInfo (info) { + const { title, repo_name, repo_path, repo_branch } = info + Object.assign(state, { query: title, repo: repo_name, gitPath: repo_path, branch: repo_branch }) +} +function initSearchRecords (records) { + data.value = records.map(item => { + let { answer, actions } = item + const historyItem = { article: answer, desLoading: false, searchLoading: false, ansLoading: false } + // console.log(`actions:`, typeof actions) + // todo ?action为啥成了string? + actions = typeof actions === 'string' ? JSON.parse(actions) : actions + // console.log(actions) + // 处理搜索过程 + actions && actions.forEach(child => { + const childAction = child.action + if (childAction === 'rephrase_question') { + historyItem.description = child.output + } else if (childAction === 'search_file') { + historyItem.source = handleFormatSource(child.output) + } + }) + return historyItem + }) +} +async function init () { + const { data, error } = await useRequest(`/v1/chat/${state.id}/history`) + if (error.value) return + const { info, records } = data.value && data.value.data + initSearchItemInfo(info) + initSearchRecords(records) +} +await init() + useHead({ title: `${state.query} - GitBot` }) @@ -85,21 +128,13 @@ const handleReGenerate = () => { generateFetchData(`根据上述回答,对问题"${question}"重新生成`) } -const data = ref([]) -const askingData = ref({ question: state.query, desLoading: true }) -const recommendQuestions = ref([]) -const askingRef = ref(null) -const historyAskRefs = ref([]) // git url const baseGitUrl = () => { const endWidthGit = state.gitPath.endsWith('.git') const baseUrl = endWidthGit ? state.gitPath.slice(0, state.gitPath.length - 4) : state.gitPath return baseUrl } -let asking = ref(false) -// 处理ai generate -let aiChatController = null // 用户取消操作方法 -const markedEnd = '[DONE]' + const handleCloseHistoryAsk = () => { historyAskRefs.value.forEach(item => { if (item && item.handleCollapse) { @@ -241,38 +276,7 @@ const generateFetchData = (query) => { // 重新生成相关问题 fetchLinkedQuestion(query) } -function initSearchItemInfo (info) { - const { title, repo_name, repo_path, repo_branch } = info - Object.assign(state, { query: title, repo: repo_name, gitPath: repo_path, branch: repo_branch }) -} -function initSearchRecords (records) { - data.value = records.map(item => { - let { answer, actions } = item - const historyItem = { article: answer, desLoading: false, searchLoading: false, ansLoading: false } - // console.log(`actions:`, typeof actions) - // todo ?action为啥成了string? - actions = typeof actions === 'string' ? JSON.parse(actions) : actions - // console.log(actions) - // 处理搜索过程 - actions && actions.forEach(child => { - const childAction = child.action - if (childAction === 'rephrase_question') { - historyItem.description = child.output - } else if (childAction === 'search_file') { - historyItem.source = handleFormatSource(child.output) - } - }) - return historyItem - }) -} -async function init () { - const { data, error } = await useRequest(`/v1/chat/${state.id}/history`) - if (error.value) return - const { info, records } = data.value && data.value.data - initSearchItemInfo(info) - initSearchRecords(records) -} -await init() + onMounted( () => { if (data.value.length === 0 && state.query) { generateFetchData(state.query)