Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.timemachinelab.controller;

import com.alibaba.fastjson2.JSON;
import io.github.timemachinelab.core.constant.AllPrompt;
import io.github.timemachinelab.core.session.application.MessageProcessingService;
import io.github.timemachinelab.core.session.application.SessionManagementService;
import io.github.timemachinelab.core.session.application.SseNotificationService;
Expand Down Expand Up @@ -294,7 +295,7 @@ public ResponseEntity<String> processAnswer(@Validated @RequestBody UnifiedAnswe
@PostMapping("/gen-prompt")
public ResponseEntity<String> genPrompt(@RequestBody GenPromptRequest request) {
GenPromptOperation.GpResponse gpResponse = new GenPromptOperation.GpResponse();
gpResponse.setGenPrompt("This is a test response for gen-prompt endpoint.");
gpResponse.setGenPrompt(AllPrompt.GEN_PROMPT_AGENT_PROMPT);
sseNotificationService.sendWelcomeMessage(request.getSessionId(), JSON.toJSONString(gpResponse));
return ResponseEntity.ok("生成提示词");
}
Expand Down
10 changes: 9 additions & 1 deletion prompto-lab-ui/src/components/Chat/AIChatPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const initializeSession = async () => {

// 处理SSE消息
const handleSSEMessage = (response: any) => {
// console.log('收到SSE消息:', response)
console.log('收到SSE消息:', response)

// 更新活跃时间
updateActivity()
Expand Down Expand Up @@ -306,10 +306,15 @@ const handleConnectionMessage = (response: any): boolean => {
// 处理生成提示词消息
const handleGenPromptMessage = (response: any): boolean => {
if (response.genPrompt) {
console.log('收到genPrompt数据:', response.genPrompt)
console.log('questionRendererRef.value:', questionRendererRef.value)

try {
// 通过ref调用子组件的setPromptResult方法显示提示词结果
if (questionRendererRef.value && questionRendererRef.value.setPromptResult) {
console.log('调用子组件setPromptResult方法')
questionRendererRef.value.setPromptResult(response.genPrompt)
console.log('setPromptResult调用完成')

toast.success({
title: '提示词生成成功',
Expand All @@ -318,6 +323,9 @@ const handleGenPromptMessage = (response: any): boolean => {
})
} else {
console.warn('QuestionRenderer组件引用不可用,无法显示提示词结果')
console.log('questionRendererRef.value存在:', !!questionRendererRef.value)
console.log('setPromptResult方法存在:', questionRendererRef.value && !!questionRendererRef.value.setPromptResult)

toast.error({
title: '显示失败',
message: '无法显示提示词结果,请重试',
Expand Down
71 changes: 67 additions & 4 deletions prompto-lab-ui/src/components/Chat/QuestionRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,20 @@

<!-- 提示词结果展示 -->
<div v-if="promptResult" class="prompt-result">
<!-- 调试信息 -->
<div style="display: none;">{{ console.log('模板中promptResult值:', promptResult) }}</div>
<div class="prompt-result-container">
<div class="prompt-result-header">
<h3 class="result-title">生成的提示词</h3>
<button @click="copyPrompt" class="copy-btn" :class="{ copied: copySuccess }">
<span class="btn-icon">{{ copySuccess ? '✅' : '📋' }}</span>
<span class="btn-text">{{ copySuccess ? '已复制' : '复制' }}</span>
</button>
<div class="header-actions">
<button @click="copyPrompt" class="copy-btn" :class="{ copied: copySuccess }">
<span class="btn-icon">{{ copySuccess ? '✅' : '📋' }}</span>
<span class="btn-text">{{ copySuccess ? '已复制' : '复制' }}</span>
</button>
<button @click="closePromptResult" class="close-btn" title="关闭">
<span class="btn-icon">✕</span>
</button>
</div>
</div>

<div class="prompt-content">
Expand Down Expand Up @@ -394,6 +401,12 @@ watch(() => props.currentQuestion, (newQuestion, oldQuestion) => {
}
}, { deep: true })

// 监听promptResult变化
watch(() => promptResult.value, (newValue, oldValue) => {
console.log('promptResult变化:', { oldValue, newValue })
console.log('promptResult是否为真值:', !!newValue)
}, { immediate: true })

// 方法
const resetAnswers = () => {
answers.input = ''
Expand Down Expand Up @@ -632,9 +645,24 @@ const copyPrompt = async () => {
}
}

// 关闭提示词结果
const closePromptResult = () => {
promptResult.value = ''
copySuccess.value = false
}

// 暴露设置提示词结果的方法
const setPromptResult = (result: string) => {
console.log('子组件setPromptResult被调用,参数:', result)
console.log('设置前promptResult.value:', promptResult.value)
promptResult.value = result
console.log('设置后promptResult.value:', promptResult.value)

// 使用nextTick确保DOM更新
nextTick(() => {
console.log('nextTick后promptResult.value:', promptResult.value)
console.log('DOM中是否存在.prompt-result元素:', !!document.querySelector('.prompt-result'))
})
}

// 暴露方法给父组件
Expand Down Expand Up @@ -1810,6 +1838,41 @@ defineExpose({
gap: 16px;
}

.header-actions {
display: flex;
align-items: center;
gap: 12px;
}

.close-btn {
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
background: rgba(15, 15, 15, 0.8);
border: 1px solid rgba(212, 175, 55, 0.2);
border-radius: 50%;
color: #e8e8e8;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
backdrop-filter: blur(10px);
}

.close-btn:hover {
border-color: rgba(239, 68, 68, 0.4);
background: rgba(239, 68, 68, 0.1);
color: #ef4444;
transform: scale(1.05);
}

.close-btn .btn-icon {
font-size: 18px;
line-height: 1;
}

.result-title {
margin: 0;
font-size: 24px;
Expand Down
Loading