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

  • 小规模纳税人如何计算增值税
  • 应付税费重分类如何做会计分录?
  • 员工自己全额承担社保可以在个税申报吗
  • 税务师考试的报名费怎么还没有退成功
  • 企业股东分红可以不按比例分吗
  • 海关缴款书有效期多久
  • 应收退货成本递延
  • 电脑的折旧年限是多久
  • 可转换可赎回债券
  • 关税滞纳金会计怎么做账
  • 出借包装物一次摊销金额计算
  • 用现金购买的股票
  • 销售现金券会计分录
  • 外贸企业仍一箱难求
  • 出口退税转为免税
  • 免税销售额和免税额区别
  • 个税提前预缴怎么入账?
  • 统借统还账务处理流程
  • 信息服务费发票范围
  • 过期未抵扣的发票对企业有什么影响
  • 劳务报酬已经缴税怎么办
  • 培训费发票模板
  • 事业单位非税收入怎么做账
  • 磁盘碎片指的是磁盘因为长期使用
  • 银行收到退款怎么回复
  • 企业扣除内容有哪些
  • wind10记事本在哪
  • 事业单位利息收入
  • php json
  • 个体户未达起征点需要申报吗
  • 请问怎么清除
  • 滚动开发项目如何做账
  • 财务费用是一种期间费用,按期归集
  • 空调年折旧率
  • vue通过url访问单个页面
  • vue路由传参的几种方式
  • flex的作用及设置
  • php使用oci8扩展连接oracle
  • php fopen函数的用法
  • 合并报表的收入就是相加么
  • 银行回单打回来会计要做什么
  • 公司进项不够怎么开发票
  • c语言asc函数
  • 织梦栏目页模板
  • 业务招待费进项税额转出会计分录
  • 个人所得税专项扣除新标准一览表最新
  • 银行提供资金来源
  • 委托代理进出口
  • 免抵税额要交税吗
  • 劳务派遣公司如何赚钱的?
  • 税务局收款收据
  • 房地产开发企业与转让房地产有关的税金
  • 外购设备的会计分录
  • 利息收入为什么冲减财务费用
  • 普通发票找不到了可以重开吗
  • 案例分析以前年龄的变化
  • 微信和支付宝的区别
  • 自产产品与视同自产产品
  • mysql的知识点
  • sqlserver 千万数量级分页存储过程代码
  • windowsserver2008r2standard激活
  • pages怎么标记
  • centos7配置免密登录
  • FreeBSD mpd VPN服务器安装步骤
  • 如何清理注册表的垃圾文件
  • wind微博
  • win10的帮助系统在哪
  • unity接入安卓sdk
  • javascript 数组操作
  • bootstrap响应式工具使用详解
  • javascript零基础学要学多久
  • jquery弹出窗口的方法
  • 安卓自定义app
  • linux两个版本
  • js添加一个div
  • js中的类是什么
  • 陕西国税电子税务局端还可以登录吗
  • 车船税缴费电子凭证
  • 誊抄什么意思
  • 企业税务人员岗位竞聘报告怎么写
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设