@ -86,6 +86,27 @@ function closeDetail() {
selectedDoc . value = null
selectedDoc . value = null
}
}
const deleting = ref ( false )
async function deleteDocument ( doc : AgentDocumentItem | DocDetail ) {
if ( ! confirm ( ` 确定删除「 ${ doc . title } 」吗? ` ) ) return
deleting . value = true
try {
await request < { code : number } > ( ` /api/agent-documents/ ${ doc . id } ` , {
method : 'DELETE' ,
} )
$toast . success ( '已删除' )
documents . value = documents . value . filter ( ( d ) => d . id !== doc . id )
if ( selectedDoc . value ? . id === doc . id ) {
selectedDoc . value = null
}
} catch {
$toast . error ( '删除失败' )
} finally {
deleting . value = false
}
}
function onFilterChange ( type : 'memory' | 'document' | '' ) {
function onFilterChange ( type : 'memory' | 'document' | '' ) {
typeFilter . value = type
typeFilter . value = type
fetchDocuments ( )
fetchDocuments ( )
@ -100,7 +121,7 @@ function onSearchInput() {
}
}
watch ( ( ) => props . show , ( val ) => {
watch ( ( ) => props . show , ( val ) => {
if ( val && documents . value . length === 0 ) {
if ( val ) {
fetchDocuments ( )
fetchDocuments ( )
}
}
} )
} )
@ -177,6 +198,13 @@ watch(() => props.show, (val) => {
{ { item . type === 'document' ? '文档' : '记忆' } }
{ { item . type === 'document' ? '文档' : '记忆' } }
< / span >
< / span >
< span class = "card-date" > { { new Date ( item . updatedAt ) . toLocaleDateString ( 'zh-CN' ) } } < / span >
< span class = "card-date" > { { new Date ( item . updatedAt ) . toLocaleDateString ( 'zh-CN' ) } } < / span >
< button
class = "card-delete-btn"
: disabled = "deleting"
@ click . stop = "deleteDocument(item)"
>
< Icon name = "lucide:trash-2" / >
< / button >
< / div >
< / div >
< h3 class = "card-title" > { { item . title } } < / h3 >
< h3 class = "card-title" > { { item . title } } < / h3 >
< p v-if ="item.summary" class="card-summary" > {{ item.summary }} < / p >
< p v-if ="item.summary" class="card-summary" > {{ item.summary }} < / p >
@ -192,6 +220,14 @@ watch(() => props.show, (val) => {
< Icon name = "lucide:arrow-left" / >
< Icon name = "lucide:arrow-left" / >
< span > 返回 < / span >
< span > 返回 < / span >
< / button >
< / button >
< button
class = "delete-btn"
: disabled = "deleting"
@ click = "deleteDocument(selectedDoc)"
>
< Icon name = "lucide:trash-2" / >
< span > { { deleting ? '删除中…' : '删除' } } < / span >
< / button >
< button class = "close-btn" @click ="emit('close')" >
< button class = "close-btn" @click ="emit('close')" >
< Icon name = "lucide:x" / >
< Icon name = "lucide:x" / >
< / button >
< / button >
@ -304,6 +340,57 @@ watch(() => props.show, (val) => {
color : var ( -- color - ink , # 141413 ) ;
color : var ( -- color - ink , # 141413 ) ;
}
}
. delete - btn {
display : flex ;
align - items : center ;
gap : 4 px ;
padding : 6 px 10 px ;
border : none ;
background : none ;
border - radius : 8 px ;
cursor : pointer ;
color : var ( -- color - muted , # 6 c6a64 ) ;
font - size : 13 px ;
transition : all 0.15 s ;
margin - left : auto ;
}
. delete - btn : hover : not ( : disabled ) {
background : # fde8e8 ;
color : # c0392b ;
}
. delete - btn : disabled {
opacity : 0.5 ;
cursor : not - allowed ;
}
. card - delete - btn {
display : flex ;
align - items : center ;
justify - content : center ;
width : 24 px ;
height : 24 px ;
border : none ;
background : none ;
border - radius : 6 px ;
cursor : pointer ;
color : var ( -- color - muted , # b8b2a6 ) ;
font - size : 14 px ;
transition : all 0.15 s ;
margin - left : auto ;
}
. card - delete - btn : hover : not ( : disabled ) {
background : # fde8e8 ;
color : # c0392b ;
}
. card - delete - btn : disabled {
opacity : 0.5 ;
cursor : not - allowed ;
}
. drawer - filters {
. drawer - filters {
display : flex ;
display : flex ;
align - items : center ;
align - items : center ;