@@ -891,10 +891,45 @@ const handleNodeSelected = (nodeId: string) => {
891891 activatePath (nodeId )
892892 currentNodeId .value = nodeId
893893
894- // 如果选中的是问题节点,恢复问题状态
895- if (targetNode .type === ' assistant' && targetNode .content .includes (' 问题' )) {
896- // 尝试解析并恢复问题状态
897- // 这里需要根据实际的问题格式来实现
894+ // 根据节点类型设置currentQuestion
895+ if (targetNode .type === ' assistant' ) {
896+ // 尝试恢复问题状态
897+ try {
898+ // 方法1: 尝试解析content中的JSON格式问题数据
899+ const questionData = JSON .parse (targetNode .content )
900+ if (questionData .type && [' input' , ' single' , ' multi' , ' form' ].includes (questionData .type )) {
901+ currentQuestion .value = questionData
902+ console .log (' 恢复问题状态:' , questionData )
903+ return
904+ }
905+ } catch (e ) {
906+ // 如果不是JSON格式,检查是否是问题文本格式
907+ console .log (' 非JSON格式,检查是否为问题文本' )
908+ }
909+
910+ // 方法2: 如果是问题文本但不是JSON格式,清除问题状态
911+ // 这种情况下显示为普通对话
912+ currentQuestion .value = null
913+ } else if (targetNode .type === ' user' ) {
914+ // 如果点击的是用户节点,查找对应的问题节点
915+ if (targetNode .parentId ) {
916+ const questionNode = conversationTree .value .get (targetNode .parentId )
917+ if (questionNode && questionNode .type === ' assistant' ) {
918+ try {
919+ // 尝试解析父节点(问题节点)的问题数据
920+ const questionData = JSON .parse (questionNode .content )
921+ if (questionData .type && [' input' , ' single' , ' multi' , ' form' ].includes (questionData .type )) {
922+ currentQuestion .value = questionData
923+ console .log (' 从用户回答节点恢复问题状态:' , questionData )
924+ return
925+ }
926+ } catch (e ) {
927+ console .log (' 用户节点对应的问题节点不是JSON格式' )
928+ }
929+ }
930+ }
931+ // 如果无法找到对应的问题,清除问题状态
932+ currentQuestion .value = null
898933 }
899934 }
900935}
0 commit comments