feat: chat login

This commit is contained in:
2024-04-11 18:03:48 +08:00
parent f282d07360
commit 270f5e0199

View File

@@ -10,10 +10,10 @@ import {
llmModels, llmModels,
type ModelTag, type ModelTag,
} from '~/typings/llm' } from '~/typings/llm'
import {useHistory} from '~/composables/useHistory' import { useHistory } from '~/composables/useHistory'
import {uuidv4} from '@uniiem/uuid' import { uuidv4 } from '@uniiem/uuid'
import {useLLM} from '~/composables/useLLM' import { useLLM } from '~/composables/useLLM'
import {trimObject} from '@uniiem/object-trim' import { trimObject } from '@uniiem/object-trim'
import ModalAuthentication from '~/components/ModalAuthentication.vue' import ModalAuthentication from '~/components/ModalAuthentication.vue'
import NewSessionScreen from '~/components/aigc/chat/NewSessionScreen.vue' import NewSessionScreen from '~/components/aigc/chat/NewSessionScreen.vue'
@@ -26,8 +26,8 @@ const toast = useToast()
const modal = useModal() const modal = useModal()
const loginState = useLoginState() const loginState = useLoginState()
const historyStore = useHistory() const historyStore = useHistory()
const {chatSessions} = storeToRefs(historyStore) const { chatSessions } = storeToRefs(historyStore)
const {setChatSessions} = historyStore const { setChatSessions } = historyStore
const currentSessionId = ref<ChatSessionId | null>(null) const currentSessionId = ref<ChatSessionId | null>(null)
const messagesWrapperRef = ref<HTMLDivElement | null>(null) const messagesWrapperRef = ref<HTMLDivElement | null>(null)
@@ -123,7 +123,7 @@ const createSession = (assistant: Assistant | null) => {
insetMessage({ insetMessage({
id: uuidv4(), id: uuidv4(),
role: 'user', role: 'user',
content: `${currentAssistant.value?.target}${currentAssistant.value?.demand}`, content: `${ currentAssistant.value?.target }${ currentAssistant.value?.demand }`,
preset: true, preset: true,
}) })
insetMessage({ insetMessage({
@@ -267,7 +267,7 @@ onMounted(() => {
<TransitionGroup name="chat-item"> <TransitionGroup name="chat-item">
<div v-if="chatSessions.length === 0"> <div v-if="chatSessions.length === 0">
<div class="text-center text-neutral-400 dark:text-neutral-500 py-4 flex flex-col items-center gap-2"> <div class="text-center text-neutral-400 dark:text-neutral-500 py-4 flex flex-col items-center gap-2">
<Icon name="i-tabler-messages" class="text-2xl" /> <Icon name="i-tabler-messages" class="text-2xl"/>
<span>没有会话</span> <span>没有会话</span>
</div> </div>
</div> </div>
@@ -302,8 +302,18 @@ onMounted(() => {
<div class="h-[calc(100vh-4rem)] flex-1 bg-white dark:bg-neutral-900"> <div class="h-[calc(100vh-4rem)] flex-1 bg-white dark:bg-neutral-900">
<Transition name="message" mode="out-in"> <Transition name="message" mode="out-in">
<div v-if="!loginState.is_logged_in" class="w-full h-full">
<div class="w-full h-full flex flex-col justify-center items-center gap-2 bg-neutral-100 dark:bg-neutral-900">
<Icon name="i-tabler-user-circle" class="text-7xl text-neutral-300 dark:text-neutral-700"/>
<p class="text-sm text-neutral-500 dark:text-neutral-400">请登录后使用</p>
<UButton class="mt-2 font-bold" color="black" variant="solid" size="xs"
@click="modal.open(ModalAuthentication)">
登录
</UButton>
</div>
</div>
<NewSessionScreen <NewSessionScreen
v-if="modals.newSessionScreen || getSessionCopyById(currentSessionId!) === undefined" v-else-if="modals.newSessionScreen || getSessionCopyById(currentSessionId!) === undefined"
:non-back="!getSessionCopyById(currentSessionId!)" :non-back="!getSessionCopyById(currentSessionId!)"
@select="createSession" @select="createSession"
@cancel="modals.newSessionScreen = false" @cancel="modals.newSessionScreen = false"