位置: IT常识 - 正文

vue 模拟 chatgpt 聊天效果:js 实现逐字显示、延时函数模拟对话(vue 模拟遥控按钮)

编辑:rootadmin
vue 模拟 chatgpt 聊天效果:js 实现逐字显示、延时函数模拟对话 vue 模拟 chatgpt 聊天效果:js 实现逐字显示、延时函数模拟对话

推荐整理分享vue 模拟 chatgpt 聊天效果:js 实现逐字显示、延时函数模拟对话(vue 模拟遥控按钮),希望有所帮助,仅作参考,欢迎阅读内容。

vue 模拟 chatgpt 聊天效果:js 实现逐字显示、延时函数模拟对话(vue 模拟遥控按钮)

文章相关热门搜索词:vue 模拟设备操作界面,vue 模拟excel 撤回恢复,vue 模拟数据,vue 模拟接口数据,vue 模拟短视频平台,vue 模拟excel 撤回恢复,vue 模拟控制台界面,vue 模拟数据,内容如对您有帮助,希望把文章链接给更多的朋友!

模拟 chatgpt 聊天功能,展示对话效果。其中比较有意义的技术点是:js 实现逐字显示、延时函数,同步遍历。

<template> <div class="chat-gpt"> <div id="chat-dialog" class="chat-dialog" ref="chatDialogRef"> <div id="chat-list" class="chat-list" ref="chatListRef"> <div v-for="(item, index) in chatList" :key="index"> <img v-if="item.status && index % 2 == 0" src="../../public/img/speak1.gif" alt="" /> <div :class="index % 2 == 0 ? 'odd' : 'even'">{{ item.content }}</div> </div> </div> </div> </div></template><script>export default { data() { return { textCount: 0, timer: null, chatBaseList: [ "以今日5辆满电无人车,运输5小时能运完50吨货物的标准,已知每辆无人车运输1小时耗电10%,运输效率是多少,每辆无人车耗电多少?花费多长时间?", "运输效率:50吨/5小时=10顿/小时,每辆无人车耗电:10%×5小时=50%,需花费5小时。", "以现有运输效率前提下,再增加5辆无人运输车,完成共计150吨物资的运输任务,整体效率会提高到多少?每辆无人车耗电又是多少?共花费多长时间?", "增加到10辆无人车,完成共计150吨物资运输任务,整体效率会提高到15顿/小时,每辆无人车耗电百分比是15%。运完150吨的话,总共要耗用1.5小时。", "我来想想是否确认执行此调配操作?", "您好,请您慎重考虑。我们将根据您的确认来决定是否执行此调配操作。", "是" ], chatList: [] }; }, mounted() { this.initGPT(); }, methods: { // 延时函数 sleep(delaytime = 10000) { return new Promise(resolve => setTimeout(resolve, delaytime)); }, // 同步遍历,自定义延时时间 async delayDo( iterList, callback = data => console.log(`数据:${data}`), delaytimeList ) { let len = iterList.length; for (let i = 0; i < len; i++) { callback(iterList[i], i); await this.sleep(delaytimeList[i]); } }, // 逐字显示内容 getChatContent(text, index) { this.timer = setInterval(() => { this.textCount++; if (this.textCount == text.length + 1) { this.textCount = 0; this.chatList.splice(index, 1, { content: text, status: false }); clearInterval(this.timer); return; } // 取字符串子串 let nowStr = text.substring(0, this.textCount); this.chatList.splice(index, 1, { content: nowStr, status: true }); }, 200); }, // 点击开始聊天 initGPT() { // const delaytimeList = [11000, 8000, 6000, 15000, 4000]; const delaytimeList = [16000, 11000, 16000, 16000, 5000, 7000]; this.delayDo( this.chatBaseList, (item, i) => { this.getChatContent(item, i); }, delaytimeList ); } }};</script><style lang="scss" scoped>.chat-gpt { width: 33rem; height: 43rem; .chat-dialog { position: relative; height: 43rem; background: 0/33rem url("../../public/img/chat-bg.png") no-repeat; overflow: hidden; .close-icon { position: absolute; top: 1rem; right: 1rem; width: 3.4rem; height: 3.4rem; img { width: 100%; height: 100%; } } .chat-list { display: flex; flex-direction: column; width: 90%; margin: 0 auto; margin-top: 2rem; overflow: auto; >div { display: flex; margin-top: 1rem; >div { max-width: 19rem; padding: 0.6rem; opacity: 0.8; font-size: 0.9rem; font-family: FZLanTingHei-L-GBK; font-weight: 400; color: #c5e7ff; text-align: start; } .odd { align-self: flex-start; background: #435e6f; border-radius: 0px 16px 16px 16px; } .even { align-self: flex-end; background: #31b8c8; border-radius: 16px 0px 16px 16px; } img { width: 2rem; height: 2rem; margin-right: 1rem; } } >div:nth-of-type(odd) { align-self: flex-start; } >div:nth-of-type(even) { align-self: flex-end; } } } .chat-tips { display: flex; height: 5.82rem; margin-top: 1rem; .gpt-icon { height: 100%; img { height: 100%; } } }}</style>

chatgpt 聊天效果

本文链接地址:https://www.jiuchutong.com/zhishi/281433.html 转载请保留说明!

上一篇:Mac 键盘快捷键大全(mac键盘快捷键设置)

下一篇:Javascript Object和Map之间的转换

  • 文化建设费征收依据
  • 领增值税专票需要发票吗
  • 怎么识别发票是否含税
  • 税屋网官网房屋
  • 认缴注册资本的风险
  • 股票投资收益是指投资者从购入股票开始到出售为止整
  • 购买的固定资产什么时候折旧
  • 保障房异地建设费缴纳契税吗?
  • 保险收入如何做账务处理?
  • 支付保险费发票怎么入账
  • 企业发工资交税
  • 公司筹建期间发生的费用没有发票
  • 不合规进项税如何账务处理
  • 税款滞纳金可以退吗
  • 年薪12万如何申报个人所得税
  • 土地增值税清算方法与技巧
  • 公司给供电局转账违法吗
  • 发票经手人和经办人的区别
  • 政府高薪补贴
  • 个人独资企业查账征收个人所得税汇算清缴
  • 企业收到财政资金
  • 上期有留抵进项税额会计分录
  • PHP:Memcached::add()的用法_Memcached类
  • 电脑故障检测与维护方法
  • Windows11报sill idealTree buildDeps安装慢或者卡顿解决方案
  • 债权类股票有哪些
  • 计算机网络的基本概念
  • 工厂土地被抵押厂房怎么办
  • 最快超级计算机我国
  • 微信公众号web开发
  • 外商投资企业需要备案吗
  • 配置nginx支持php
  • 电子发票能否作废
  • 计提的增值税可以扣除吗
  • 蓝色龙舌兰花语
  • php购物车及订单思路
  • 待抵扣进项税额的分录
  • 公司租车公司
  • 持有至到期投资科目被取消了吗
  • 公对公二手车交易税
  • 个税申报表中的年金是什么意思?
  • sql优化的方法及思路
  • 股票手续费如何计算公式
  • linux安装ms
  • 销售折扣购物卡对公司财务的好处
  • 汇算清缴退税怎么回事
  • 公司临时工的车可以买吗
  • 开办费怎么做帐
  • 预付账款转入其他应付款会计分录
  • 出口未申报退税罚款多少
  • 咨询服务费可以全额扣除吗
  • 自产自用进项税额
  • 冲销销售收入分录
  • 代扣代缴增值税税率
  • mysql函数大全以及举例
  • service login
  • windowsserver2008密码规则
  • centos禁止用户登录
  • fedora最新版本
  • windows 11安全模式
  • windows磁盘如何分区
  • linux rmdir
  • linux查看mtime的命令
  • 利用命令查看虚拟机的信息
  • 三分钟教你学会骑女式摩托车,连菜鸟都能学会
  • pim架构
  • Linux系统怎么设置中文输入法
  • unity 链表
  • ES6 javascript的异步操作实例详解
  • android Unable to execute dex问题的解决
  • shell脚本判断字符串是否为空
  • pyqt用法
  • python中deque
  • 开票软件连接服务器失败什么原因
  • 上海税务ca证书更新
  • 厦门象屿正式员工招聘
  • 车位过户需要契税发票吗
  • 国地税账号密码
  • 纳税人分类分级管理办法
  • 国税软件下载
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设