提交 2d00872c 编写于 作者: D DebugIsFalse

feature: 搜索结果

上级 b9a475b1
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
color="gray" color="gray"
variant="ghost" variant="ghost"
size="xs" size="xs"
:to="'/search/' + item.url" :to="`/search/${item.c_id}`"
@click="handleClickItem" @click="handleClickItem"
> >
<div class="truncate">{{ item.title }}</div> <div class="truncate">{{ item.title }}</div>
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
variant="ghost" variant="ghost"
long long
leading-icon="i-heroicons-document-text" leading-icon="i-heroicons-document-text"
:to="'/search/' + item.url" :to="`/search/${item.c_id}`"
@click="handleClose" @click="handleClose"
> >
<div class="truncate font-light">{{ item.title }}</div> <div class="truncate font-light">{{ item.title }}</div>
...@@ -91,6 +91,6 @@ async function getUserHistory () { ...@@ -91,6 +91,6 @@ async function getUserHistory () {
searchHistory.value = data.value && data.value.data || [] searchHistory.value = data.value && data.value.data || []
} }
nextTick(() => { nextTick(() => {
getUserHistory() $isSignIn && getUserHistory()
}) })
</script> </script>
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
<h2 class="text-3xl" :id="data.length + 1">{{ askingData.question }}</h2> <h2 class="text-3xl" :id="data.length + 1">{{ askingData.question }}</h2>
</div> </div>
<ISearchContent <ISearchContent
v-if="askingData.question"
:item="askingData" :item="askingData"
:asking="asking" :asking="asking"
ref="askingRef" ref="askingRef"
...@@ -44,41 +45,22 @@ ...@@ -44,41 +45,22 @@
</div> </div>
</template> </template>
<script setup> <script setup>
const { $setRepo, $repos } = useReposStore()
const route = useRoute() const route = useRoute()
const { fetchRequest } = useFetchRequest() const { fetchRequest } = useFetchRequest()
const { y } = useWindowScroll({ behavior: 'smooth' }) const { y } = useWindowScroll({ behavior: 'smooth' })
const { directions } = useScroll(window) const { directions } = useScroll(window)
if (!$repos.length) {
let repoData = await fetchRequest('/v1/chat/repository', {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).catch(()=> {})
repoData = repoData && repoData.data.map(item => {
return {
label: item.name,
url: item.path,
branch: item.branch
}
})
$setRepo(repoData)
}
const repoItem = $repos.find(item => route.query.repo === item.label) || {}
const state = reactive({ const state = reactive({
query: route.query.query || '', query: '',
repo: route.query.repo || '', repo: '',
id: route.params.id, id: route.params.id,
branch: route.query.branch || repoItem.branch, branch: '',
gitPath: route.query.gitPath || repoItem.url gitPath: ''
}) })
useHead({ useHead({
title: `${state.query} - GitBot` title: `${state.query} - GitBot`
}) })
function handleUpdateQuery(query) { function handleUpdateQuery(query) {
state.query = query; state.query = query
} }
// 是否停止自动滚动到底部 // 是否停止自动滚动到底部
const isAutoToBottom = ref(true) const isAutoToBottom = ref(true)
...@@ -92,7 +74,7 @@ watch( () => directions.top, ...@@ -92,7 +74,7 @@ watch( () => directions.top,
const scrollToView = () => { const scrollToView = () => {
if (!isAutoToBottom.value) return if (!isAutoToBottom.value) return
const $target = document.querySelector('#scrollElement') const $target = document.querySelector('#scrollElement')
if (!$target) return; if (!$target) return
const height = $target.clientHeight const height = $target.clientHeight
y.value = height y.value = height
} }
...@@ -111,11 +93,11 @@ const recommendQuestions = ref([]) ...@@ -111,11 +93,11 @@ const recommendQuestions = ref([])
const askingRef = ref(null) const askingRef = ref(null)
const historyAskRefs = ref([]) const historyAskRefs = ref([])
// git url // git url
const baseGitUrl = computed(() => { const baseGitUrl = () => {
const endWidthGit = state.gitPath.endsWith('.git') const endWidthGit = state.gitPath.endsWith('.git')
const baseUrl = endWidthGit ? state.gitPath.slice(0, state.gitPath.length - 4) : state.gitPath const baseUrl = endWidthGit ? state.gitPath.slice(0, state.gitPath.length - 4) : state.gitPath
return baseUrl return baseUrl
}) }
let asking = ref(false) let asking = ref(false)
// 处理ai generate // 处理ai generate
let aiChatController = null // 用户取消操作方法 let aiChatController = null // 用户取消操作方法
...@@ -137,7 +119,7 @@ const createGenerateInitItem = (question) => { ...@@ -137,7 +119,7 @@ const createGenerateInitItem = (question) => {
const handleContinueAsk = (question) => { const handleContinueAsk = (question) => {
if (asking.value) return if (asking.value) return
asking.value = true asking.value = true
askingRef.value.handleCollapse(true); askingRef.value.handleCollapse(true)
createGenerateInitItem(question) createGenerateInitItem(question)
generateFetchData(question) generateFetchData(question)
setTimeout(() => { setTimeout(() => {
...@@ -150,7 +132,18 @@ const resetAnsLoading = () => { ...@@ -150,7 +132,18 @@ const resetAnsLoading = () => {
} }
const resetAutoBottom = () => { const resetAutoBottom = () => {
nextTick(() => { nextTick(() => {
isAutoToBottom.value = true; isAutoToBottom.value = true
})
}
const handleFormatSource = (source) => {
const gitUrl = baseGitUrl()
return source.split('\n').map((item) => {
const isLink = item.indexOf('http') === 0
return {
repo: state.repo,
link: isLink ? item : `${gitUrl}/blob/${state.branch}/${item}`,
label: item
}
}) })
} }
const handleFormFetchData = (fetchData) => { const handleFormFetchData = (fetchData) => {
...@@ -180,14 +173,7 @@ const handleFormFetchData = (fetchData) => { ...@@ -180,14 +173,7 @@ const handleFormFetchData = (fetchData) => {
} }
if (meta.action === 'search_file') { if (meta.action === 'search_file') {
let source = choices[0].message.content let source = choices[0].message.content
source = source.split('\n').map((item) => { source = handleFormatSource(source)
const isLink = item.indexOf('http') === 0
return {
repo: state.repo,
link: isLink ? item : `${baseGitUrl.value}/blob/${state.branch}/${item}`,
label: item
}
})
Object.assign(askingData.value, { desLoading: true, source, searchLoading: true, desLoading: false }) Object.assign(askingData.value, { desLoading: true, source, searchLoading: true, desLoading: false })
resetAutoBottom() resetAutoBottom()
} }
...@@ -213,7 +199,7 @@ const handleStopGenerate = () => { ...@@ -213,7 +199,7 @@ const handleStopGenerate = () => {
const handleError = (event) => { const handleError = (event) => {
handleStopGenerate() handleStopGenerate()
if (event) { if (event) {
throw event; throw event
} }
} }
const fetchLinkedQuestion = (query) => { const fetchLinkedQuestion = (query) => {
...@@ -260,8 +246,41 @@ const generateFetchData = (query) => { ...@@ -260,8 +246,41 @@ const generateFetchData = (query) => {
// 重新生成相关问题 // 重新生成相关问题
fetchLinkedQuestion(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 => {
const { answer, actions } = item
const historyItem = { article: answer, desLoading: false, searchLoading: false, ansLoading: false }
// 处理搜索过程
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:responseData, error } = await useRequest(`/v1/chat/${state.id}/history`)
if (error.value) return
const { info, records } = responseData.value && responseData.value.data
initSearchItemInfo(info)
initSearchRecords(records)
}
await init()
onMounted(() => { onMounted(() => {
generateFetchData(state.query) if (data.value.length === 0) {
generateFetchData(state.query)
} else {
asking.value = false
askingData.value = {}
}
}) })
</script> </script>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册