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

  • 异地存货怎么审计
  • 小规模纳税人转让不动产增值税
  • 280元抵减税控设备
  • 什么是免税合并
  • 实收资本印花税如何申报
  • 出售股东
  • 劳务公司包工包料的法律法规
  • 公司内部人员发言稿
  • 建筑工地加油计入什么科目
  • 小规模纳税人收入账务处理
  • 财务公司承兑汇票是商票还是银票
  • 预付款期末有结余年末如何做账务处理?
  • 原材料呆滞物料处理方法
  • 去年的成本没有入账
  • 企业返利如何处理
  • 河道维护中心职责
  • 软件技术服务费算无形资产吗
  • 个人遗失的定义
  • 开公司后如何报个税申报
  • 查账征收所得税计税依据
  • 企业预缴所得税
  • 环保设备的折旧计入
  • 工商年报员工人数怎么算
  • 贷款减值损失的计提规则
  • 外币报表折算差额怎么算
  • 个体工商户怎么办对公账户
  • 财务费用错记制造费用
  • 社会保险费缴费凭据在哪查
  • 一般纳税人免税申报表怎么填
  • 季度申报利润表怎么填
  • 微信收款会计分录,然后提现有手续费
  • 生产车间折旧为0的原因
  • 增值税预缴税款表电子版下载
  • 电脑重装系统如何分区?
  • 合伙企业股东个税税率表
  • 苹果客服人工24小时
  • 以前年度少计收入 会计怎么处理
  • 免购车税政策
  • 语音处理算法
  • 金融性资产有哪些
  • vue项目创建流程
  • php模板引擎原理
  • html-css
  • php调试函数
  • 基于深度学习的车型识别系统(Python+清新界面+数据集)
  • 没有初级会计证可以从事会计工作吗
  • 电子专用发票抵扣
  • 固定资金是什么科目
  • 去年的预提费用今年进来了怎么入账
  • 支付宝企业账户怎么注销
  • 接受捐赠的增值税计入会计利润吗
  • 金税四期可以查香港银行卡吗
  • 以无形资产换入固定资产发生的净损益
  • 固定资产采购需要走什么流程
  • 递延收益什么科目
  • 逾期交房违约金 已支付金额
  • 负数发票开错了是否可以作废?
  • 加计抵扣会计处理
  • 购买土地的入账价值包括什么
  • 费用化是计入当期损益吗
  • 政府补助的内容
  • 如何定义是应付还是应付
  • 2020年工伤赔偿标准表
  • system表空间满了怎么处理
  • mysql null+1
  • win8.1使用技巧
  • win73d设置怎么设置
  • win10周年版
  • win7文件和打印机共享
  • 快速掌握阅读题的技巧
  • 安装node-sass报错
  • unity视频播放
  • 深入理解linux内核第三版
  • jquery实现表格隔行换色
  • python怎么用数组
  • 小规模纳税人税率2024
  • 婚前买房婚后个人还贷卖房怎么签字
  • 怎么打印纳税申报表带章的
  • 廉政谈话什么是廉政?
  • 云旅游存在的问题及解决措施
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设