feat: 新建会话id生成

This commit is contained in:
王天骄
2026-06-24 11:41:04 +08:00
parent 19c89a9b3d
commit 7f8c72409f
28 changed files with 74 additions and 61 deletions
+26 -13
View File
@@ -172,7 +172,8 @@
</template>
<script setup lang="ts">
import { nextTick, onMounted, onUnmounted, ref } from 'vue'
import { nextTick, onUnmounted, ref } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import {
createLearningAssistantSession,
runClinicalThinkingBooksWorkflow,
@@ -217,6 +218,7 @@ const selectedAssistantType = ref<'clinical-books' | ''>('')
let toastTimer: ReturnType<typeof setTimeout> | null = null
let streamAbortController: AbortController | null = null
let workflowAbortController: AbortController | null = null
let assistantSessionPromise: Promise<LearningAssistantSession> | null = null
function selectClinicalBooksType() {
if (sending.value) return
@@ -289,26 +291,37 @@ async function handleSend() {
async function ensureAssistantSession(title: string) {
if (assistantSession.value) return assistantSession.value
const session = await createLearningAssistantSession(title)
assistantSession.value = session
uni.setStorageSync('clinical-thinking-learning-assistant-session', session)
return session
if (assistantSessionPromise) return assistantSessionPromise
return createFreshAssistantSession(title)
}
async function initializeAssistantSession() {
try {
const storedSession = uni.getStorageSync('clinical-thinking-learning-assistant-session')
if (storedSession && typeof storedSession === 'object') {
assistantSession.value = storedSession as LearningAssistantSession
return
}
assistantSession.value = await createLearningAssistantSession('AI 学习助手')
uni.setStorageSync('clinical-thinking-learning-assistant-session', assistantSession.value)
assistantSession.value = null
await createFreshAssistantSession('AI 学习助手')
} catch (error) {
showToast(error instanceof Error ? error.message : '新建会话失败')
}
}
function createFreshAssistantSession(title: string) {
const request = createLearningAssistantSession(title)
assistantSessionPromise = request
return request
.then(session => {
if (assistantSessionPromise === request) {
assistantSession.value = session
}
return session
})
.catch(error => {
if (assistantSessionPromise === request) {
assistantSessionPromise = null
}
throw error
})
}
function scrollToBottom() {
nextTick(() => {
scrollTop.value += 1000
@@ -324,7 +337,7 @@ function showToast(message: string) {
}, 1800)
}
onMounted(() => {
onShow(() => {
void initializeAssistantSession()
})