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

  • 私立幼儿园需要纳税吗
  • 一般纳税人销售货物税率
  • 进项票管理软件
  • 车船使用税会打折么
  • 捐赠资产管理办法
  • 税控盘退费怎么做会计分录
  • 食堂买菜费用如何做会计
  • 弥补以前年度亏损会计分录
  • 坏账的处理方法包括
  • 企业优化什么意思
  • 一般纳税人在国家电子税务局里面如何添加银行账户
  • 消费金融服务要交税吗
  • 收入与应收款
  • 企业的经济成本由什么构成
  • 应收账款坏账收回会计处理
  • 小规模纳税人免税额度是多少
  • 收到发票对方已红冲是否退回?
  • 固定资产少计提了怎么办
  • win10任务栏不显示最近
  • 债券的到期收益率取决于
  • 安全库存的三种算法
  • 企业报税流程图
  • 不动产租赁如何缴纳增值税
  • PHP:xml_get_current_column_number()的用法_XML解析器函数
  • php数组函数,选班长
  • php写post接口
  • 股票的交易费用多少
  • 电梯安装包工头赚多少
  • PHP:curl_version()的用法_cURL函数
  • PHP:escapeshellcmd()的用法_命令行函数
  • 固定资产折旧怎么做账务处理
  • 分公司可以给总公司开发票么
  • vue 自动部署
  • 捐赠支出如何做账
  • 母公司收取子公司管理费的税率
  • 收到质量赔款做什么会计科目
  • 单位缴费基数申报提交了能改吗
  • 进出口公司如何做账
  • 人力资源外包可以去吗
  • 泛微oa二次开发难吗
  • 公允价值变动损益
  • 不动产物权归属和内容的根据是什么?
  • 矿产资源补偿费计入税金及附加吗
  • 你必须了解的最大的问题
  • 织梦专题页模板
  • 减免税款账务处理
  • 增值税专用发票是干什么用的
  • 运输服务是什么
  • 委托银行贷款利息发票谁提供
  • 出货后90天付款
  • 材料暂估入库的附件需要哪些资料
  • 销售商品房适用的增值税税率是多少
  • 企业用现金支付本企业职工工资时应
  • 工程预付款入账
  • 支付的员工餐费怎么记账
  • 企业向福利院捐款属于 公共关系
  • 发票金额与实际金额不符怎么举报
  • 采购方退货的会计分录
  • 利润表期初余额怎么填
  • 关于合同履约成本的表述错误的有
  • 结汇时和月底结转汇兑损益
  • 以销定产会计怎么做账科目
  • 餐饮店原材料表格
  • “制造费用”账户如何设置明细账?
  • php mysql连接
  • centos下安装jdk
  • win7怎么打开程序
  • Win10预览版桌面图标和任务栏不翼而飞怎么办?
  • linux系统怎么共享
  • 电脑系统垃圾
  • jquery的checked
  • css浮动和清除浮动
  • vue+vue-validator 表单验证功能的实现代码
  • 原生javascript+css3编写的3D魔方动画旋扭特效
  • js class实现原理
  • jquery用法
  • 横向对比分析两个人关系的意义
  • js跨域解决方案
  • 云南省国家税务总局
  • 报税日期2023年
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设