虚拟主机 多个网站,建筑公司起名大全2021最新版的,上海十大装修公司品牌,平面设计是干嘛的简介
ChatUI#xff0c;是一个ArkTS编写的HarmonyOS原生聊天UI框架#xff0c;提供了开箱即用的聊天对话组件。 下载安装
ohpm install changwei/chatuiOpenHarmony ohpm 环境配置等更多内容#xff0c;请参考如何安装 OpenHarmony ohpm 包
接口和属性列表
接口列表
接…简介
ChatUI是一个ArkTS编写的HarmonyOS原生聊天UI框架提供了开箱即用的聊天对话组件。 下载安装
ohpm install changwei/chatuiOpenHarmony ohpm 环境配置等更多内容请参考如何安装 OpenHarmony ohpm 包
接口和属性列表
接口列表
接口参数功能setTyping(isTyping)isTyping布尔值显示/隐藏消息加载动画postMessage(msg,clearInput)msgChatMessage类型clearInput: boolean类型。在对话界面中显示消息指示展示消息时是否清空输入框内容默认清除。submitUserInput(userIputText)userIputTextstring类型。触发Chat组件用户发送消息事件onSendMessage(callback)callback:(ctl,message)void用户发送输入消息回调事件onClear(callback)callback:(event)void用户清空聊天记录回调事件
属性列表
属性描述messages聊天消息列表IChatDataSource类型。支持懒加载显示的数据源botAvatarchatbot头像可选。Resource类型userAvatar我的头像可选。Resource类型title标题栏标题。string类型needTitleBar是否显示标题栏。boolean类型welcomeMessagechatbot默认欢迎语。string类型botMessageBackgroundColorchatbot消息的背景颜色。string类型botMessageTextColorchatbot消息的文本颜色。string类型userMessageBackgroundColor用户消息的背景颜色。string类型userMessageTextColor用户消息的文本颜色。string类型messageFontSize消息文本的字体大小。number类型needBackButton是否显示顶部返回按钮。点击返回导航上一页。boolean类型needInputControl是否需要底部输入区域。 boolean类型InputControl底部输入区域BuilderParams类型。该区域可自定义为你自己的布局controller自定义输入控制器自定义输入区时必填。[ChatController](chatui/src/main/ets/components/Chat.ets · Codex/ChatUI - Gitee.com)类型backIcon返回按钮图标。Resource类型clearChatIcon清楚聊天按钮图标。Resource类型submitButtonText提交消息按钮文本。string类型inputTextPlaceHolder输入框提示文本。string类型inputTextPlaceHolderColor输入框提示文本的颜色。string类型inputTextColor输入文本的颜色。string类型needSubmitButton是否显示提交消息按钮。boolean类型useMarkdown是否渲染markdown消息。boolean类型
使用示例
这里演示简单的调用ChatUI组件
import { Chat, ChatRole, ChatMessage } from changwei/chatuiEntry
Component
struct Index {build() {Row() {Column() {Chat({title:demo chatbot,welcomeMessage: 我是你的测试bot,onSendMessage: (ctl, message) {//发送用户消息ctl.postMessage(message)//显示回复等待动画ctl.setTyping(true)//3秒后发送chatbot响应消息setTimeout(() {ctl.postMessage(new ChatMessage({role: ChatRole.Assistant,content: 这是一条测试回复}))// 图片消息ctl.postMessage(new ChatMessage({role:ChatRole.Assistant,picurl:https://foruda.gitee.com/avatar/1709712450038093632/8548349_changweizhang_1709712449.png}));}, 3000)}})}
}
.height(100%)
}
}深度定制聊天UI。替换输入区域为你自己的输入组件替换头像文本颜色等。
import { Chat, ChatRole, ChatMessage } from changwei/chatui
import { ChatController } from changwei/chatui
import router from ohos.router;Entry
Component
struct CustomInput {State userInput: string State needBackButton: boolean falsechatController new ChatController()build() {Row() {Column() {Chat({title: demo chatbot,needTitleBar: true,welcomeMessage: 我是你的测试bot,botMessageBackgroundColor: Color.Brown,botMessageTextColor: Color.White,userMessageBackgroundColor: Color.Green,userMessageTextColor: Color.White,botAvatar:$r(app.media.chat),messageFontSize: 20,userInput: this.userInput,controller: this.chatController,needBackButton:this.needBackButton,onSendMessage: (ctl, message) {//发送用户消息ctl.postMessage(message)this.userInput //显示回复等待动画ctl.setTyping(true)//3秒后发送chatbot响应消息setTimeout(() {ctl.postMessage(new ChatMessage({role:ChatRole.Assistant, content:这是一条测试回复}))}, 3000)}}){Row() {Button() {Image($r(app.media.app_icon))}.backgroundColor(#).height(40).width(40).margin(5)TextInput({text: this.userInput}).enterKeyType(EnterKeyType.Send).fontColor(Color.White).backgroundColor(Color.Blue).width(80%).onChange((val) {this.userInput val}).onSubmit((ss) {this.chatController.submitUserInput(this.userInput)})}}}}.height(100%)}aboutToAppear() {const params router.getParams(); // 获取传递过来的参数对象if(params) {this.needBackButton params[needBackButton]}}
}使用Markdown格式显示消息 Chat({useMarkdown:true})markdown消息效果请看上面的demo gif
约束与限制
在下述版本验证通过 DevEco Studio: 4.0.0.600, SDK: API9
为了能让大家更好的学习鸿蒙HarmonyOS NEXT开发技术这边特意整理了《鸿蒙开发学习手册》共计890页希望对大家有所帮助https://qr21.cn/FV7h05
《鸿蒙开发学习手册》
如何快速入门https://qr21.cn/FV7h05
基本概念构建第一个ArkTS应用…… 开发基础知识https://qr21.cn/FV7h05
应用基础知识配置文件应用数据管理应用安全管理应用隐私保护三方应用调用管控机制资源分类与访问学习ArkTS语言…… 基于ArkTS 开发https://qr21.cn/FV7h05
Ability开发UI开发公共事件与通知窗口管理媒体安全网络与链接电话服务数据管理后台任务(Background Task)管理设备管理设备使用信息统计DFX国际化开发折叠屏系列…… 鸿蒙开发面试真题含参考答案https://qr18.cn/F781PH 鸿蒙开发面试大盘集篇共计319页https://qr18.cn/F781PH
1.项目开发必备面试题 2.性能优化方向 3.架构方向 4.鸿蒙开发系统底层方向 5.鸿蒙音视频开发方向 6.鸿蒙车载开发方向 7.鸿蒙南向开发方向