Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
inscode
NodeJS_639770
提交
2d00872c
N
NodeJS_639770
项目概览
inscode
/
NodeJS_639770
与 Fork 源项目一致
Fork自
inscode / NodeJS
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
NodeJS_639770
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
2d00872c
编写于
5月 27, 2024
作者:
D
DebugIsFalse
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: 搜索结果
上级
b9a475b1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
61 addition
and
42 deletion
+61
-42
components/i/SearchHistory.vue
components/i/SearchHistory.vue
+3
-3
pages/search/[id].vue
pages/search/[id].vue
+58
-39
未找到文件。
components/i/SearchHistory.vue
浏览文件 @
2d00872c
...
@@ -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
>
pages/search/[id].vue
浏览文件 @
2d00872c
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录