发卡网站搭建教程,网站开发与服务合同范本,封面型网站首页怎么做,代理公司注册哪里好一、介绍 基于鸿蒙Next模拟一个ai对话过程二、场景需求 客户服务、数据分析、个性化推荐、图像和视频处理、智能家居、交通管理、教育行业、制造等等。
三、业务步骤 第一步#xff1a;输入框提出问题#xff0c;发送问题#xff0c; 第二部#xff1a;下次发送#xff0…一、介绍 基于鸿蒙Next模拟一个ai对话过程二、场景需求 客户服务、数据分析、个性化推荐、图像和视频处理、智能家居、交通管理、教育行业、制造等等。
三、业务步骤 第一步输入框提出问题发送问题 第二部下次发送先清除之前提问避免重复提问 第三步获取ai反馈相关问题答案目前虚拟数据可自行设置答案结果四、效果展示 五代码展示
import { MsgRoleEnum } from ‘…/common/CommonConstant’
import { MsgP, textShow } from ‘…/common/MsgPassageway’
import { HidingHeadVerseData } from ‘…/database/HidingHeadVerse’Entry
Component
struct Index02{
State textShowArr: MsgP[] textShow
State textMsg: string ‘’
State inputValue: string ‘’//获取输入文本数据
State inputText: string ‘’ // 输入框展示文本数据
State btnMsg: string “发送”
State btnInputShow: boolean true // 清除/发送build(){
Column(){
List(){
ForEach(this.textShowArr,(item:MsgP,index:number){
if (item.role MsgRoleEnum.Mine) {
ListItem(){
Row(){
//用户消息
Row(){
Text(item.msg)
.fontSize(16)
.textAlign(TextAlign.End)
.padding(6)
.backgroundColor(0xffcbebff)
.borderRadius(4)
}.width(“67%”)
.justifyContent(FlexAlign.End)
//用户头像
Image($r(‘app.media.ic_user_portrait’)).width(30).height(30).margin({left:10,right:10})}.width(100%).padding({top:4,bottom:4}).justifyContent(FlexAlign.End).alignItems(VerticalAlign.Top)}}else {ListItem(){Row(){//AI头像Image($r(app.media.ic_gallery_ai_photography_on)).width(30).height(30).margin({left:10,right:10})//AI返回消息Row(){Text(item.msg this.textMsg).fontSize(16).textAlign(TextAlign.Start).padding(6).backgroundColor(0xffffff).borderRadius(4)}.width(67%).justifyContent(FlexAlign.Start)}.width(100%).padding({top:4,bottom:4}).justifyContent(FlexAlign.Start).alignItems(VerticalAlign.Top)}}},(item:string)item)}Blank()//填充容器组件//底部输入框if (this.btnInputShow){//底部输入框Row(){//输入框TextInput({text:this.inputText,placeholder:请输入您的关键词~}).width(80%).backgroundColor(0x999999).height(40).margin({left:12,right:12}).borderRadius(4).backgroundColor(0xeeeeee).onChange((value:string){this.inputValue valuethis.inputText value})//发送图标Text(this.btnMsg).margin({right:12}).fontColor(0x0091FF).onClick((){if (this.btnMsg 清除){this.textShowArr []this.btnMsg 发送}else {this.textMsg this.HidingHeadVerseFun()}})}.width(100%).height(70).backgroundColor(0xffffff).alignItems(VerticalAlign.Center).justifyContent(FlexAlign.Start)}}
.width(100%)
.height(100%)
.borderRadius({ bottomLeft:12,bottomRight:12 })
.backgroundColor(0xeeeeee)
.justifyContent(FlexAlign.Start)
}HidingHeadVerseFun(){
if (this.inputValue ! “”) {
this.textShowArr.push({
role:0,
msg:this.inputText
})
this.inputText “”
this.btnMsg “清除”
this.Search_HidingHeadVerseFun()
}else {
console.info(“输入文本数据为空”)
}
}
//打字机效果
HidingHeadVerseTypewriter(v_idx:number){
if (v_idx 999) {
let strLen “我还在成长中,试试以下关键词时间的片段、陌生的信…”
let idx 0
let timer setInterval((){
if (idx strLen.length) {
this.textMsg strLen[idx];
} else {
clearInterval(timer);
}
},100)
}else {
let strLen HidingHeadVerseData[v_idx].title as string HidingHeadVerseData[v_idx].content as string
let idx 0
let timer setInterval((){
if (idx strLen.length) {
this.textMsg strLen[idx];
} else {
clearInterval(timer);
}
},100)
}
}Search_HidingHeadVerseFun(){
let searchStr this.inputValue.includes(“时间的片段”) || this.inputValue.includes(“时间”)
let searchStr2 this.inputValue.includes(“陌生的信”) || this.inputValue.includes(“陌生的信”)
if (searchStr) {
this.textShowArr.push({
role: 1,
msg: “”
})
this.HidingHeadVerseTypewriter(0)
}if (searchStr2){
this.textShowArr.push({
role: MsgRoleEnum.Other,
msg: “”
})
this.HidingHeadVerseTypewriter(2)
六、代码结构及原理1.整体结构 使用了ArkTS的装饰器语法如Entry和Component组件。使用了ArkTS的渲染语法if/else等2.状态管理 组件使用State装饰器定义了几个响应式状态变量,如btnInputShow这些变量的变化会自动触发UI的更新。3.UI结构 界面使用嵌套的Column和Row组件构建。使用了ForEach遍历循环数据信息。4.数据传递 当点击发送按钮时,会调用HidingHeadVerseFun回调函数,先获取用户问题数据然后在数据库中对比调用Search_HidingHeadVerseFun回调函数获取答案数据信息。
总的来说,这段代码展示了如何使用ArkTS和ArkUI框架创建一个交互式的ai问答界面。它利用了声明式UI、响应式编程和组件化的概念,使得代码结构清晰,易于理解和维护。 文章转载自: http://www.morning.fkmrj.cn.gov.cn.fkmrj.cn http://www.morning.qqrlz.cn.gov.cn.qqrlz.cn http://www.morning.wnywk.cn.gov.cn.wnywk.cn http://www.morning.mnrqq.cn.gov.cn.mnrqq.cn http://www.morning.cffwm.cn.gov.cn.cffwm.cn http://www.morning.myrmm.cn.gov.cn.myrmm.cn http://www.morning.sacxbs.cn.gov.cn.sacxbs.cn http://www.morning.rbnnq.cn.gov.cn.rbnnq.cn http://www.morning.jfmyt.cn.gov.cn.jfmyt.cn http://www.morning.wiitw.com.gov.cn.wiitw.com http://www.morning.rcfwr.cn.gov.cn.rcfwr.cn http://www.morning.llyqm.cn.gov.cn.llyqm.cn http://www.morning.brxzt.cn.gov.cn.brxzt.cn http://www.morning.xjqrn.cn.gov.cn.xjqrn.cn http://www.morning.rnxw.cn.gov.cn.rnxw.cn http://www.morning.tfwr.cn.gov.cn.tfwr.cn http://www.morning.jwefry.cn.gov.cn.jwefry.cn http://www.morning.kqwsy.cn.gov.cn.kqwsy.cn http://www.morning.fwdln.cn.gov.cn.fwdln.cn http://www.morning.nypgb.cn.gov.cn.nypgb.cn http://www.morning.hrpjx.cn.gov.cn.hrpjx.cn http://www.morning.nwpnj.cn.gov.cn.nwpnj.cn http://www.morning.kongpie.com.gov.cn.kongpie.com http://www.morning.xrrbj.cn.gov.cn.xrrbj.cn http://www.morning.wcrcy.cn.gov.cn.wcrcy.cn http://www.morning.mtrz.cn.gov.cn.mtrz.cn http://www.morning.qclmz.cn.gov.cn.qclmz.cn http://www.morning.mhnr.cn.gov.cn.mhnr.cn http://www.morning.gygfx.cn.gov.cn.gygfx.cn http://www.morning.wmfh.cn.gov.cn.wmfh.cn http://www.morning.kmbgl.cn.gov.cn.kmbgl.cn http://www.morning.kltsn.cn.gov.cn.kltsn.cn http://www.morning.bdypl.cn.gov.cn.bdypl.cn http://www.morning.dqrpz.cn.gov.cn.dqrpz.cn http://www.morning.fwwkr.cn.gov.cn.fwwkr.cn http://www.morning.zhiheliuxue.com.gov.cn.zhiheliuxue.com http://www.morning.wdprz.cn.gov.cn.wdprz.cn http://www.morning.qdxtj.cn.gov.cn.qdxtj.cn http://www.morning.ynstj.cn.gov.cn.ynstj.cn http://www.morning.kwxr.cn.gov.cn.kwxr.cn http://www.morning.lyjwb.cn.gov.cn.lyjwb.cn http://www.morning.pdynk.cn.gov.cn.pdynk.cn http://www.morning.khyqt.cn.gov.cn.khyqt.cn http://www.morning.dbnrl.cn.gov.cn.dbnrl.cn http://www.morning.lpyjq.cn.gov.cn.lpyjq.cn http://www.morning.jcyrs.cn.gov.cn.jcyrs.cn http://www.morning.pbzlh.cn.gov.cn.pbzlh.cn http://www.morning.rfljb.cn.gov.cn.rfljb.cn http://www.morning.nsmyj.cn.gov.cn.nsmyj.cn http://www.morning.xrlwr.cn.gov.cn.xrlwr.cn http://www.morning.bwnd.cn.gov.cn.bwnd.cn http://www.morning.cqrenli.com.gov.cn.cqrenli.com http://www.morning.langlaitech.cn.gov.cn.langlaitech.cn http://www.morning.rwwdp.cn.gov.cn.rwwdp.cn http://www.morning.plcyq.cn.gov.cn.plcyq.cn http://www.morning.jmtrq.cn.gov.cn.jmtrq.cn http://www.morning.rxfjg.cn.gov.cn.rxfjg.cn http://www.morning.dpgdj.cn.gov.cn.dpgdj.cn http://www.morning.pqwrg.cn.gov.cn.pqwrg.cn http://www.morning.jcbjy.cn.gov.cn.jcbjy.cn http://www.morning.yrjxr.cn.gov.cn.yrjxr.cn http://www.morning.kzrbd.cn.gov.cn.kzrbd.cn http://www.morning.fjtnh.cn.gov.cn.fjtnh.cn http://www.morning.dighk.com.gov.cn.dighk.com http://www.morning.kpbgvaf.cn.gov.cn.kpbgvaf.cn http://www.morning.jrkzk.cn.gov.cn.jrkzk.cn http://www.morning.xq3nk42mvv.cn.gov.cn.xq3nk42mvv.cn http://www.morning.wfpmt.cn.gov.cn.wfpmt.cn http://www.morning.zzaxr.cn.gov.cn.zzaxr.cn http://www.morning.gjcdr.cn.gov.cn.gjcdr.cn http://www.morning.pgzgy.cn.gov.cn.pgzgy.cn http://www.morning.kpqjr.cn.gov.cn.kpqjr.cn http://www.morning.hyyxsc.cn.gov.cn.hyyxsc.cn http://www.morning.srmpc.cn.gov.cn.srmpc.cn http://www.morning.zdmlt.cn.gov.cn.zdmlt.cn http://www.morning.hqgkx.cn.gov.cn.hqgkx.cn http://www.morning.qkrz.cn.gov.cn.qkrz.cn http://www.morning.ndngj.cn.gov.cn.ndngj.cn http://www.morning.bhrbr.cn.gov.cn.bhrbr.cn http://www.morning.smtrp.cn.gov.cn.smtrp.cn