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

  • 报完增值税就要清卡吗
  • 彩票税率税率
  • 一般纳税人资格证明在哪里查询
  • 劳务报酬个人所得税税率表
  • 现金流量表存货增加是负的
  • 军队票据可作税前扣除凭证吗
  • 坏账转销会计分录应收帐款金额怎么写
  • 核定征收企业有利润如何注销税务登记
  • 异地出租
  • 外币账户间互转流程
  • 银行承兑汇票利息怎么算
  • 复式记账法和会计分录
  • 花卉租赁的税率
  • 应税销售额含不含税
  • 账面价值大于计税基础产生什么差异
  • 小规模纳税人的好处
  • 专用发票的清单要开2张吗
  • 不计提盈余公积可以分红吗
  • 个人独资企业租车缴纳税金
  • 融资融券主要是哪些对象
  • 政府授权国企为基建项目建设单位
  • 登陆对话框不能输入
  • bash是什么命令
  • 合同预付款怎么做账
  • 营改增项目
  • php extract函数
  • 无偿划转长期股权投资
  • 逾期未收回包装物押金增值税
  • 若依框架权限控制
  • php判断查询是否有结果
  • vue–router
  • 微信小店的入口在哪里
  • 智能优化算法主要内容
  • 企业应采用
  • 高价值配件用入固定资产吗
  • 职工教育经费申报表如何填写
  • 实缴的钱注销后可以拿回来吗
  • 织梦模板安装完整教程
  • 办公费用开专票可以抵扣吗
  • 科目余额表和资产负债表的期末余额不一样,怎么办
  • 增值税抵扣凭证怎么做
  • 营改增后建筑企业财务核算
  • 销货方怎么开红字发票
  • 个税填在资产负债表哪个地方
  • 已执行新金融准则 本期金额
  • 预收账款的账务处理怎么对企业有利
  • 买一赠一销售额的确定
  • 发票冲销后还能用吗
  • 费用摊销怎么做分录
  • 简易征收增值税一般纳税人怎么报税
  • 会计软件什么范围分为单用户和多用户呢
  • mysql的crud
  • windows下启动mysql的命令是什么
  • sql基本教程
  • 微软桌面 ios
  • 电脑xp系统如何
  • mac怎么用知云翻译
  • bios如何设置
  • 加载dll错误是什么意思
  • win7一直配置
  • linux系统的配置
  • 在Linux命令行中快速删除光标前的快捷键是什么?
  • cocos安装
  • ztree getnodebytid
  • 12个超实用的JQuery代码片段
  • vue自定义过滤器的语法
  • jquery的实现原理
  • mac的命令
  • Python的flask框架教程
  • javascript如何定义一个函数
  • unity游戏开发的技术
  • js验证身份证合法性
  • jquery fadein不起作用
  • 树的python
  • 如何动态加载外部文件
  • 湖北省税务系统欠税管理工作指南
  • 知道税率怎么算成本
  • 公司税务风险情况说明怎么写
  • 税务退休工资
  • 出口退税正式申报资料上传
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设