45 lines
3.8 KiB
Plaintext
45 lines
3.8 KiB
Plaintext
<template>
|
|||
|
|
<view class="assistant-page page">
|
||
|
|
<AppHeader title="AI融资助手" />
|
||
|
|
<scroll-view scroll-y class="chat-scroll" :scroll-into-view="lastMessageId">
|
||
|
|
<view class="chat-content">
|
||
|
|
<view class="assistant-intro"><image src="/static/images/robot.png" mode="aspectFit"></image><view class="assistant-bubble"><text>您好!我是AI融资助手,可以帮您解答融资相关问题。</text></view></view>
|
||
|
|
<view class="quick-questions">
|
||
|
|
<view class="question" v-for="item in questions" :key="item" @click="ask(item)"><text>{{ item }}</text><AppIcon name="chevron-right" :size="28" muted /></view>
|
||
|
|
</view>
|
||
|
|
<view v-for="(item,index) in messages" :key="index" :id="'message-' + index" :class="item.role == 'user' ? 'message-row user-row' : 'message-row'">
|
||
|
|
<image v-if="item.role == 'assistant'" class="message-avatar" src="/static/images/robot.png" mode="aspectFit"></image>
|
||
|
|
<view :class="item.role == 'user' ? 'message-bubble user-bubble' : 'message-bubble'"><text>{{ item.text }}</text></view>
|
||
|
|
</view>
|
||
|
|
</view>
|
||
|
|
</scroll-view>
|
||
|
|
<view class="chat-input"><input v-model="draft" confirm-type="send" @confirm="send" placeholder="请输入您的问题..." /><button @click="send"><AppIcon name="send" :size="34" /></button></view>
|
||
|
|
</view>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<script setup lang="uts">
|
||
|
|
import AppHeader from '@/components/AppHeader.uvue'
|
||
|
|
import AppIcon from '@/components/AppIcon.uvue'
|
||
|
|
import { sendAssistantMessage } from '@/services/api.uts'
|
||
|
|
const questions = ['我的融资额度受哪些因素影响?', '如何提高贷款通过率?', '企业融资需要哪些材料?', '有哪些适合我的方案?']
|
||
|
|
const messages = ref<UTSJSONObject[]>([])
|
||
|
|
const draft = ref('')
|
||
|
|
const lastMessageId = ref('')
|
||
|
|
const ask = (text: string) => { draft.value = text; send() }
|
||
|
|
const send = async () => {
|
||
|
|
const text = draft.value.trim()
|
||
|
|
if (text.length == 0) return
|
||
|
|
messages.value.push({ role: 'user', text: text })
|
||
|
|
draft.value = ''
|
||
|
|
const answer = await sendAssistantMessage(text)
|
||
|
|
messages.value.push({ role: 'assistant', text: answer })
|
||
|
|
lastMessageId.value = 'message-' + (messages.value.length - 1)
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<style>
|
||
|
|
.assistant-page { background-color: #f4f7fb; }.chat-scroll { height: calc(100vh - var(--status-bar-height) - 210rpx); }.chat-content { padding: 28rpx 26rpx 50rpx; }.assistant-intro { flex-direction: row; align-items: flex-start; }.assistant-intro image, .message-avatar { width: 78rpx; height: 78rpx; border-radius: 24rpx; background-color: #e7f2ff; margin-right: 16rpx; }.assistant-bubble, .message-bubble { max-width: 530rpx; padding: 24rpx; border-radius: 8rpx 22rpx 22rpx 22rpx; background-color: #fff; color: #344259; font-size: 25rpx; line-height: 42rpx; border: 1rpx solid #e4ebf5; }
|
||
|
|
.quick-questions { margin: 25rpx 0 36rpx 94rpx; }.question { min-height: 72rpx; margin-top: 13rpx; padding: 14rpx 18rpx; border-radius: 16rpx; border: 2rpx solid #bcd9ff; background-color: #eef6ff; color: #0868f7; font-size: 23rpx; flex-direction: row; align-items: center; justify-content: space-between; }.question-arrow { font-size: 34rpx; }.message-row { margin-top: 22rpx; flex-direction: row; align-items: flex-start; }.user-row { justify-content: flex-end; }.user-bubble { color: #fff; background-color: #0868f7; border-color: #0868f7; border-radius: 22rpx 8rpx 22rpx 22rpx; }
|
||
|
|
.chat-input { position: fixed; left: 0; right: 0; bottom: 0; min-height: 114rpx; padding: 17rpx 24rpx calc(17rpx + env(safe-area-inset-bottom)); background-color: #fff; border-top: 1rpx solid #e3eaf4; flex-direction: row; align-items: center; }.chat-input input { flex: 1; height: 78rpx; border-radius: 39rpx; background-color: #f2f5f9; padding: 0 28rpx; font-size: 25rpx; }.chat-input button { width: 76rpx; height: 76rpx; line-height: 76rpx; border-radius: 50%; margin-left: 15rpx; padding: 0; background-color: #0868f7; color: #fff; font-size: 29rpx; }
|
||
|
|
</style>
|