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

feature: 搜索结果

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