位置: 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之间的转换

  • 税收收入包括哪些形式
  • 个人可以申请代收货款吗
  • 增值税纳税义务发生地点的规定
  • 没有工会的企业怎么发福利
  • 企业所得税成本费用大于发票金额的原因
  • 办公室提前退租未摊完的装修费如何处理
  • 餐饮业加计递减怎么算
  • 房地产开发企业土地增值税清算
  • 长期股权投资成本法转权益法追溯调整
  • 不动产在建工程使用的外购物资可以抵扣吗
  • 暂估入库已结转怎么处理
  • 小额开专票
  • 餐饮发票增值税税率是多少
  • 详解非税收入
  • 多交增值税如何退回
  • 存货计价方法的选择对利润表中的项目没有影响
  • 加工费计入应付账款可以吗
  • 应收账款的坏账处理方式有哪几种
  • 营改增后房地产公司税种及税率
  • 工资上浮20%怎么算
  • 单位内部控制
  • 白酒消费税最低计税价格
  • 销售赠送怎么做账
  • 修缮房屋的防水工程的账务处理?
  • 怎么在bios中开启硬件虚拟化
  • 注册会计师考试科目有哪些
  • 房地产转让的条件
  • 什么是文件扩展名dws
  • 企业转让股票交什么税费呢
  • 公司贷款过桥费合法吗
  • PHP clearstatcache()函数详解
  • nomoreporn.exe - nomoreporn是什么进程 有什么用
  • 年度所得税报表在哪里查到
  • 住房公积金怎么补缴费
  • seti@home.exe - seti@home是什么进程 有什么用
  • 增值税发票要审核成功才能开吗
  • 虚假财务报表的法律后果
  • .sfx.exe是什么文件
  • laravel 入门
  • php中imagestring
  • php sendmail
  • vue打包后请求不到数据
  • php支付功能
  • php xml转字符串
  • npm install或npm i后没有依赖包node_modules?
  • js去除属性
  • 苹果cmsv10官网
  • 个体开发票额度
  • 收取违约金能作为合同自动终止要件吗
  • mongodb添加环境变量
  • 营业收入的构成分析主要包括
  • 企业低值易耗品降成本措施
  • 报税合同
  • 付款方押金无法退还
  • 个人独资企业需要会计做账吗
  • 免税收入啥意思
  • 开发票的其他要求是?
  • 小企业建账流程图
  • 产成品核算的内容
  • SQL Server ltrim(rtrim()) 去不掉空格的原因分析
  • 苹果mac最新的系统
  • brasil.exe是什么进程
  • txt无法打开怎么弄
  • 怎么卸载电脑上的迅雷软件
  • linux 详解
  • pavsrv50.exe - pavsrv50进程管理信息
  • 邮件传输过程中都使用哪些协议
  • win11系统ie浏览器
  • javascript字符串大小写转换
  • python生成密钥
  • perl use cwd
  • unity 3d脚本编程
  • XMLHttpRequest Level 2 使用指南
  • angular.js
  • nodejs 代理请求
  • android基础入门教程
  • eclipse出现an error has occurred
  • js实现ping一个ip地址
  • 个人所得税父母双方专项扣除
  • 岗位练兵的作用
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设