DevCloudFE/MateChat:进度指示器

DevCloudFE/MateChat:进度指示器

【免费下载链接】MateChat 前端智能化场景解决方案UI库,轻松构建你的AI应用,我们将持续完善更新,欢迎你的使用与建议。 官网地址:https://matechat.gitcode.com 【免费下载链接】MateChat 项目地址: https://gitcode.com/DevCloudFE/MateChat

痛点:AI对话场景中的状态反馈难题

在构建AI对话应用时,你是否遇到过这样的困境:用户发送问题后,界面长时间没有响应,用户不知道系统是在思考、加载还是已经卡死?这种糟糕的用户体验往往导致用户流失和满意度下降。

传统的解决方案要么过于简单(一个静态的"加载中..."文字),要么实现复杂(需要自定义动画和状态管理)。MateChat的Bubble组件内置了智能进度指示器,完美解决了这个问题。

MateChat进度指示器核心特性

1. 内置智能Loading动画

MateChat为Bubble组件提供了优雅的三点闪烁动画,模拟AI思考过程:

mermaid

2. 灵活的配置选项

进度指示器支持多种配置方式:

配置方式适用场景优点
内置默认动画快速开发开箱即用,零配置
自定义Loading模板品牌定制完全控制样式和动画
组合使用复杂场景灵活应对不同需求

3. 完整的代码示例

基本用法 - 内置动画
<template>
  <McBubble 
    :content="'正在思考中...'" 
    :loading="true"
    :avatarConfig="{ imgSrc: '/logo.svg' }">
  </McBubble>
</template>

<script setup>
import { McBubble } from '@matechat/core';
</script>
自定义Loading模板
<template>
  <McBubble :content="'正在处理您的请求'" :loading="true">
    <template #loadingTpl>
      <div class="custom-loading">
        <div class="spinner"></div>
        <span>模型思考中,请稍候...</span>
      </div>
    </template>
  </McBubble>
</template>

<style scoped>
.custom-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #666;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #9880ff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>
完整对话场景示例
<template>
  <div class="chat-container">
    <!-- 用户消息 - 右侧对齐 -->
    <McBubble 
      :content="userMessage" 
      :align="'right'"
      :avatarConfig="userAvatar">
    </McBubble>

    <!-- AI回复 - 左侧对齐,带Loading状态 -->
    <McBubble 
      :content="aiResponse" 
      :loading="isThinking"
      :avatarConfig="aiAvatar">
      
      <template #top>
        <div class="thinking-header">
          <span>MateChat AI</span>
          <span class="thinking-time">{{ thinkingTime }}s</span>
        </div>
      </template>
      
      <template #loadingTpl>
        <div class="enhanced-loading">
          <div class="dot-flashing"></div>
          <span>深度思考中,请耐心等待...</span>
        </div>
      </template>
      
      <template #bottom>
        <div class="action-buttons">
          <button @click="copyResponse">复制</button>
          <button @click="regenerate">重新生成</button>
        </div>
      </template>
    </McBubble>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue';
import { McBubble } from '@matechat/core';

const userMessage = ref('请帮我写一篇关于人工智能的文章');
const aiResponse = ref('');
const isThinking = ref(true);
const startTime = ref(Date.now());

const thinkingTime = computed(() => {
  return Math.floor((Date.now() - startTime.value) / 1000);
});

const userAvatar = { imgSrc: '/user-avatar.png' };
const aiAvatar = { imgSrc: '/ai-avatar.png', displayName: 'MateChat' };

// 模拟AI思考过程
onMounted(async () => {
  setTimeout(() => {
    isThinking.value = false;
    aiResponse.value = '人工智能是计算机科学的一个分支,它企图了解智能的实质...';
  }, 3000);
});

const copyResponse = () => {
  navigator.clipboard.writeText(aiResponse.value);
};

const regenerate = () => {
  isThinking.value = true;
  startTime.value = Date.now();
  setTimeout(() => {
    isThinking.value = false;
    aiResponse.value = '重新生成的内容:人工智能的发展历程可以追溯到1956年...';
  }, 2000);
};
</script>

<style scoped>
.chat-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 800px;
  margin: 0 auto;
}

.thinking-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #666;
  margin-bottom: 8px;
}

.thinking-time {
  color: #9880ff;
  font-weight: bold;
}

.enhanced-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
}

.dot-flashing {
  display: flex;
  gap: 4px;
}

.dot-flashing::before,
.dot-flashing::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #9880ff;
  animation: dotFlashing 1.4s infinite ease-in-out both;
}

.dot-flashing::before {
  animation-delay: -0.32s;
}

.dot-flashing::after {
  animation-delay: -0.16s;
}

@keyframes dotFlashing {
  0%, 80%, 100% { opacity: 0; }
  40% { opacity: 1; }
}

.action-buttons {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.action-buttons button {
  padding: 4px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 12px;
}

.action-buttons button:hover {
  background: #f5f5f5;
}
</style>

技术实现原理

动画系统架构

mermaid

CSS动画关键代码

MateChat使用精心设计的CSS动画确保流畅的视觉效果:

.mc-bubble-loading .loading-dot {
  animation: dotFlashing 1s infinite linear alternate;
}

@keyframes dotFlashing {
  0% { background-color: #9880ff; }
  100% { background-color: #ebe6ff; }
}

最佳实践指南

1. 用户体验优化

场景推荐方案效果
短时等待(<2s)内置三点动画轻量级反馈
中时等待(2-5s)自定义动画+文字提示明确状态信息
长时等待(>5s)进度条+预计时间管理用户预期

2. 性能考虑

  • 动画性能:使用CSS动画而非JavaScript动画
  • 内存占用:轻量级实现,避免复杂DOM操作
  • 响应式设计:适配不同设备和屏幕尺寸

3. 无障碍访问

确保进度指示器对屏幕阅读器友好:

<template #loadingTpl>
  <div role="status" aria-live="polite">
    <div class="loading-animation" aria-hidden="true"></div>
    <span class="sr-only">内容加载中,请稍候</span>
  </div>
</template>

总结

MateChat的进度指示器不仅仅是一个简单的加载动画,而是一个完整的用户反馈系统。它通过:

  1. 视觉反馈:优雅的动画效果减轻等待焦虑
  2. 状态明确:清晰传达系统当前状态
  3. 高度可定制:满足不同场景和品牌需求
  4. 性能优化:轻量级实现不影响应用性能
  5. 无障碍支持:确保所有用户都能获得良好体验

无论是简单的聊天应用还是复杂的企业级AI平台,MateChat的进度指示器都能为你提供专业级的用户体验解决方案。开始使用MateChat,让你的AI应用拥有更智能、更友好的交互体验!

【免费下载链接】MateChat 前端智能化场景解决方案UI库,轻松构建你的AI应用,我们将持续完善更新,欢迎你的使用与建议。 官网地址:https://matechat.gitcode.com 【免费下载链接】MateChat 项目地址: https://gitcode.com/DevCloudFE/MateChat

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值