feat: 修改ai学习助手接口
This commit is contained in:
@@ -89,12 +89,12 @@
|
||||
<scroll-view class="quick-actions" scroll-x>
|
||||
<view class="quick-row">
|
||||
<button
|
||||
v-for="action in quickActions"
|
||||
:key="action"
|
||||
class="quick-chip"
|
||||
@click="useQuickAction(action)"
|
||||
:class="{ disabled: sending }"
|
||||
:disabled="sending"
|
||||
@click="handleClinicalBooks"
|
||||
>
|
||||
{{ action }}
|
||||
临床思维训练书籍
|
||||
</button>
|
||||
</view>
|
||||
</scroll-view>
|
||||
@@ -175,6 +175,7 @@
|
||||
import { nextTick, onMounted, onUnmounted, ref } from 'vue'
|
||||
import {
|
||||
createLearningAssistantSession,
|
||||
runClinicalThinkingBooksWorkflow,
|
||||
streamLearningAssistantChat,
|
||||
type LearningAssistantSession
|
||||
} from '../../api/learning-assistant'
|
||||
@@ -195,7 +196,7 @@ const emit = defineEmits<{
|
||||
|
||||
const goHome = createHomeNavigator(emit)
|
||||
|
||||
const quickActions = ['更新指南', '风险评估量表', '药理学详情', '病例研讨']
|
||||
const clinicalBooksAction = '临床思维训练书籍'
|
||||
|
||||
const pathwaySteps = [
|
||||
{ index: '1', title: '早期识别', description: '10分钟内完成12导联心电图。' },
|
||||
@@ -216,15 +217,41 @@ const sending = ref(false)
|
||||
|
||||
let toastTimer: ReturnType<typeof setTimeout> | null = null
|
||||
let streamAbortController: AbortController | null = null
|
||||
let workflowAbortController: AbortController | null = null
|
||||
|
||||
function useQuickAction(action: string) {
|
||||
const prompts: Record<string, string> = {
|
||||
更新指南: '请帮我梳理 ACS 最新指南中需要重点关注的更新。',
|
||||
风险评估量表: '请列出 ACS 常用风险评估量表及适用场景。',
|
||||
药理学详情: '请说明 ACS 常用抗血小板药物的适应证和注意事项。',
|
||||
病例研讨: '请用病例研讨形式带我复盘一例胸痛患者。'
|
||||
async function handleClinicalBooks() {
|
||||
if (sending.value) return
|
||||
|
||||
messages.value.push({
|
||||
id: `user-${Date.now()}`,
|
||||
role: 'user',
|
||||
content: clinicalBooksAction
|
||||
})
|
||||
typingVisible.value = true
|
||||
sending.value = true
|
||||
scrollToBottom()
|
||||
|
||||
const assistantMessageIndex = messages.value.length
|
||||
messages.value.push({
|
||||
id: `assistant-${Date.now()}`,
|
||||
role: 'assistant',
|
||||
variant: 'simple',
|
||||
content: ''
|
||||
})
|
||||
|
||||
try {
|
||||
workflowAbortController?.abort()
|
||||
workflowAbortController = new AbortController()
|
||||
const output = await runClinicalThinkingBooksWorkflow(workflowAbortController.signal)
|
||||
messages.value[assistantMessageIndex].content = output
|
||||
} catch (error) {
|
||||
messages.value[assistantMessageIndex].content = error instanceof Error ? error.message : '临床思维训练书籍生成失败'
|
||||
showToast(messages.value[assistantMessageIndex].content)
|
||||
} finally {
|
||||
typingVisible.value = false
|
||||
sending.value = false
|
||||
scrollToBottom()
|
||||
}
|
||||
draft.value = prompts[action] || action
|
||||
}
|
||||
|
||||
async function handleSend() {
|
||||
@@ -324,6 +351,7 @@ onMounted(() => {
|
||||
|
||||
onUnmounted(() => {
|
||||
streamAbortController?.abort()
|
||||
workflowAbortController?.abort()
|
||||
if (toastTimer) clearTimeout(toastTimer)
|
||||
})
|
||||
</script>
|
||||
@@ -712,27 +740,39 @@ page {
|
||||
|
||||
.quick-row {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
|
||||
.quick-chip {
|
||||
box-sizing: border-box;
|
||||
min-height: 32px;
|
||||
padding: 6px 16px;
|
||||
border: 1px solid #c2c6d4;
|
||||
border-radius: 12px;
|
||||
background: #ecedf6;
|
||||
color: #424752;
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
font-weight: 500;
|
||||
width: auto;
|
||||
flex: 0 0 auto;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0;
|
||||
min-height: 36px;
|
||||
padding: 8px 18px;
|
||||
border: 1px solid rgba(0, 71, 141, 0.28);
|
||||
border-radius: 8px;
|
||||
background: #eef5ff;
|
||||
color: #00478d;
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.quick-chip.disabled {
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.quick-chip:active {
|
||||
background: #e7e8f0;
|
||||
background: #dcecff;
|
||||
}
|
||||
|
||||
.composer {
|
||||
|
||||
Reference in New Issue
Block a user