@@ -128,6 +128,9 @@ Component({
128128 } ,
129129 voiceRecognizing : false ,
130130 speedList : [ 2 , 1.5 , 1.25 , 1 , 0.75 ] ,
131+
132+ showActionMenu : false , // 是否显示操作菜单
133+ selectedConversation : null , // 当前选中的会话
131134 } ,
132135 attached : async function ( ) {
133136 const chatMode = this . data . chatMode ;
@@ -482,7 +485,7 @@ Component({
482485 } ) ;
483486
484487 commonRequest ( {
485- path : `conversation/?botId= ${ botId } & limit=${ limit } &offset=${ offset } &isDefault=${ isDefault } ` ,
488+ path : `bots/ ${ botId } /conversation/? limit=${ limit } &offset=${ offset } &isDefault=${ isDefault } ` ,
486489 method : "GET" ,
487490 header : { } ,
488491 success : ( res ) => {
@@ -506,7 +509,7 @@ Component({
506509 // const { token } = await cloudInstance.extend.AI.bot.tokenManager.getToken();
507510 return new Promise ( ( resolve , reject ) => {
508511 commonRequest ( {
509- path : `conversation` ,
512+ path : `bots/ ${ this . data . agentConfig . botId } / conversation` ,
510513 header : {
511514 // Authorization: `Bearer ${token}`,
512515 } ,
@@ -524,6 +527,101 @@ Component({
524527 } ) ;
525528 } ) ;
526529 } ,
530+ deleteConversation : async function ( conversationId ) {
531+ return new Promise ( ( resolve , reject ) => {
532+ commonRequest ( {
533+ path : `bots/${ this . data . agentConfig . botId } /conversation/${ conversationId } ` ,
534+ method : "DELETE" ,
535+ success : ( res ) => {
536+ resolve ( res ) ;
537+ } ,
538+ fail ( e ) {
539+ console . log ( "delete conversation e" , e ) ;
540+ reject ( e ) ;
541+ } ,
542+ } ) ;
543+ } ) ;
544+ } ,
545+ handleDeleteConversation : async function ( e ) {
546+ const { conversation } = e . currentTarget . dataset ;
547+ const that = this ;
548+
549+ this . hideActionMenu ( ) ;
550+
551+ wx . showModal ( {
552+ title : "提示" ,
553+ content : "确认删除当前会话?" ,
554+ confirmText : "删除" ,
555+ confirmColor : "#ff303b" ,
556+ success : async function ( res ) {
557+ if ( res . confirm ) {
558+ // 删除会话
559+ try {
560+ const deleteRes = await that . deleteConversation ( conversation . conversationId ) ;
561+
562+ if ( deleteRes && ! deleteRes . code ) {
563+ // 删除成功后更新本地数据
564+ const updatedConversations = that . data . conversations . filter (
565+ item => item . conversationId !== conversation . conversationId
566+ ) ;
567+ that . setData ( {
568+ conversations : updatedConversations ,
569+ transformConversations : that . transformConversationList ( updatedConversations ) ,
570+ } ) ;
571+
572+ if ( that . data . conversation ?. conversationId === conversation . conversationId ) {
573+ that . clearChatRecords ( ) ;
574+ if ( updatedConversations . length > 0 ) {
575+ that . handleClickConversation ( {
576+ currentTarget : {
577+ dataset : {
578+ conversation : updatedConversations [ 0 ] ,
579+ } ,
580+ } ,
581+ } ) ;
582+ } else {
583+ that . setData ( {
584+ conversation : null ,
585+ } ) ;
586+ }
587+ }
588+
589+ wx . showToast ( {
590+ title : "删除成功" ,
591+ icon : "success" ,
592+ } ) ;
593+ } else {
594+ wx . showToast ( {
595+ title : "删除失败,请稍后重试" ,
596+ icon : "error" ,
597+ } ) ;
598+ }
599+ } catch ( error ) {
600+ console . error ( "删除会话失败" , error ) ;
601+ wx . showToast ( {
602+ title : "删除失败,请稍后重试" ,
603+ icon : "error" ,
604+ } ) ;
605+ }
606+ }
607+ } ,
608+ } ) ;
609+ } ,
610+ handleLongPressConversation : function ( e ) {
611+ // 长按会话,显示操作菜单
612+ const { conversation } = e . currentTarget . dataset ;
613+ this . setData ( {
614+ showActionMenu : true ,
615+ selectedConversation : conversation ,
616+ } ) ;
617+ } ,
618+ hideActionMenu : function ( ) {
619+ // 隐藏操作菜单
620+ this . setData ( {
621+ showActionMenu : false ,
622+ selectedConversation : null ,
623+ } ) ;
624+ } ,
527625 clickCreateInDrawer : function ( ) {
528626 this . setData ( {
529627 isDrawerShow : false ,
0 commit comments