Files
airz-uniapp/pages/assistant/assistant.uvue
T

68 lines
4.8 KiB
Plaintext
Raw Normal View History

2026-09-10 10:57:40 +08:00
<template>
<view class="assistant-page page" :style="pageStyle()">
2026-09-10 10:57:40 +08:00
<AppHeader title="AI融资助手" />
<scroll-view scroll-y class="chat-scroll" :scroll-into-view="lastMessageId" :style="contentStyle(210, false)">
2026-09-10 10:57:40 +08:00
<view class="chat-content">
<view class="assistant-intro"><image src="/static/mobile/images/robot.png" mode="aspectFit" class="assistant-intro-image"></image><view class="assistant-bubble"><text>您好!我是AI融资助手,可以帮您解答融资相关问题。</text></view></view>
2026-09-10 10:57:40 +08:00
<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/mobile/images/robot.png" mode="aspectFit"></image>
2026-09-10 10:57:40 +08:00
<view :class="item.role == 'user' ? 'message-bubble user-bubble' : 'message-bubble'"><text>{{ item.text }}</text></view>
</view>
<view v-if="errorMessage.length > 0" class="assistant-error"><text>{{ errorMessage }}</text><text @click="retry" class="assistant-error-text-last-child">重试</text></view>
2026-09-10 10:57:40 +08:00
</view>
</scroll-view>
<view class="chat-input" :style="bottomStyle(17)"><input v-model="draft" confirm-type="send" @confirm="send" placeholder="请输入您的问题..." class="chat-input-input" /><button @click="send" class="chat-input-button"><AppIcon name="send" :size="34" /></button></view>
2026-09-10 10:57:40 +08:00
</view>
</template>
<script setup lang="uts">
import { usePageLayout } from '@/services/layout.uts'
const { bottomStyle, contentStyle, pageStyle } = usePageLayout()
2026-09-10 10:57:40 +08:00
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 lastQuestion = ref('')
const sending = ref(false)
const errorMessage = ref('')
2026-09-10 10:57:40 +08:00
const send = async () => {
const text = draft.value.trim()
if (text.length == 0 || sending.value) return
lastQuestion.value = text
2026-09-10 10:57:40 +08:00
messages.value.push({ role: 'user', text: text })
draft.value = ''
sending.value = true
errorMessage.value = ''
try { const answer = await sendAssistantMessage(text); messages.value.push({ role: 'assistant', text: answer }); lastMessageId.value = 'message-' + (messages.value.length - 1) } catch (error) { errorMessage.value = '消息发送失败,请稍后重试' }
sending.value = false
2026-09-10 10:57:40 +08:00
}
const ask = (text: string) => { draft.value = text; send() }
const retry = () => { draft.value = lastQuestion.value; errorMessage.value = ''; send() }
2026-09-10 10:57:40 +08:00
</script>
<style>
.assistant-page { background-color: #f4f7fb; }
.chat-scroll { }
.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; 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; }
.assistant-error { margin: 18rpx 0 0 94rpx; color: #e05a5a; font-size: 21rpx; flex-direction: row; justify-content: space-between; }
.assistant-error-text-last-child { color: #0868f7; margin-left: 18rpx; }
2026-09-10 10:57:40 +08:00
</style>