news 2026/2/25 15:56:49

前端智能化场景解决方案UI库matechat,如何在项目中使用matechat

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
前端智能化场景解决方案UI库matechat,如何在项目中使用matechat

MateChat / Angular

前端智能化场景解决方案UI库,轻松构建你的AI应用。已服务于华为内部多个应用智能化改造,并助力CodeArts、InsCode AI IDE等智能化助手搭建。

特性

  • 面向智能化场景组件库
  • 开箱即用
  • 多场景匹配
  • 多主题适配

快速集成:

1. 引入

在app.ts文件中引入模块

import{Component,signal}from'@angular/core';import{RouterOutlet}from'@angular/router';import{CommonModule}from"@angular/common";import{BubbleModule}from"@matechat/ng";@Component({selector:'app-root',standalone:true,imports:[RouterOutlet,CommonModule,BubbleModule],templateUrl:'./app.html',styleUrl:'./app.css'})exportclassApp{protectedreadonly title=signal('matechat-demo');}


2. 使用

在app.html文件中使用 MateChat 组件,如:

<mc-bubble[content]="'Hello, MateChat'"[avatarConfig]="{ name: 'matechat' }"></mc-bubble>


3. 以下为一个简单的对话界面搭建示例:

在app.html使用如下代码:

<divclass="mc-layout"><divclass="chat-container"><divclass="chat-header":title="'MateChat'"><img src="https://matechat.gitcode.com/logo.svg"/><span>MateChat</span></div>@if(newPage){<divclass="welcom-page"><divclass="content-wrapper"><divclass="mc-introduction"><divclass="mc-introduction-logo-container"><img src="https://matechat.gitcode.com/logo2x.svg"alt="MateChat"/><divclass="mc-introduction-title">MateChat</div></div><divclass="mc-introduction-description"><div>MateChat 可以辅助研发人员编码、查询知识和相关作业信息、编写文档等。</div><div>作为AI模型,MateChat 提供的答案可能不总是确定或准确的,但您的反馈可以帮助 MateChat 做的更好。</div></div></div><divclass="guess-question"><divclass="guess-title"><div>猜你想问</div></div><divclass="guess-content"><ng-container*ngFor="let item of questionList"><span(click)="onSubmit(item)">{{item}}</span></ng-container></div></div></div></div>}@else{<divclass="chat-list"><ng-container*ngFor="let msg of messages">@if(msg.from==='user'){<mc-bubbleclass="user-bubble"[align]="'right'"[content]="msg.content"[avatarConfig]="avatarConfig"></mc-bubble>}@elseif(msg.from==='model'){<mc-bubbleclass="model-bubble"[align]="'left'"[loading]="msg.loading"[avatarConfig]="modelAvatar"><mc-markdown-card[theme]="theme"[content]="msg.content"[enableMermaid]="true"></mc-markdown-card></mc-bubble>}</ng-container></div>}<divclass="chat-footer"><mc-input(submit)="onSubmit($event)"></mc-input><divclass="statement-box"><span>内容由AI生成,无法确保准确性和完整性,仅供参考</span></div></div></div></div>

在app.ts中使用如下代码:

import{Component,signal}from'@angular/core';import{CommonModule}from'@angular/common';import{BubbleModule,InputModule,MarkdownCardModule}from'@matechat/ng';@Component({selector:'app-root',standalone:true,imports:[CommonModule,BubbleModule,InputModule,MarkdownCardModule],templateUrl:'./app.html',styleUrl:'./app.css',})exportclassApp{protectedreadonly title=signal('matechat-demo');inputValue='';messages:any=[];newPage=true;questionList=['帮我写一篇文章','你可以帮我做些什么?','帮我写一个快速排序','使用 js 格式化时间',];avatarConfig={imgSrc:'https://matechat.gitcode.com/png/demo/userAvatar.svg',};modelAvatar={imgSrc:'https://matechat.gitcode.com/logo.svg',};onSubmit=(evt:any)=>{this.newPage=false;this.inputValue='';// 用户发送消息this.messages.push({from:'user',content:evt,});setTimeout(()=>{// 模型返回消息this.messages.push({from:'model',content:evt,});},200);};}


在将模板应用中的app.css修改成app.less,使用如下代码:

::ng-deep body{margin:0;color:var(--devui-text,#252b3a);}.mc-layout{height:100vh;width:100%;padding:12px;box-sizing:border-box;background:linear-gradient(to bottom,#d0c9ff0%,#e6d6f08%,#f1dbea12%,#c8dcfb40%,#abc6f660%,#87aefe90%);}::ng-deep body[ui-theme='galaxy-theme'].mc-layout{background:var(--devui-global-bg,#f6f6f8);.chat-container{background:transparent;border:none;}}.chat-container{display:flex;flex-direction:column;box-sizing:border-box;gap:8px;}.welcom-page{display:flex;flex-direction:column;flex:1;max-width:1200px;margin:0auto;overflow:auto;width:100%;max-width:1200px;padding:012px;box-sizing:border-box;gap:24px;}.guess-title{display:flex;justify-content:space-between;align-items:center;color:var(--devui-text,#252b3a);margin-bottom:16px;}.guess-content{display:flex;align-items:center;flex-wrap:wrap;gap:12px;}.mc-introduction-logo-container{display:flex;align-items:center;gap:8px;}.mc-introduction-description{text-align:center;font-size:14px;color:var(--devui-text,#252b3a);}.mc-introduction-title{font-weight:700;font-size:32px;letter-spacing:1px;color:var(--devui-text,#252b3a);}.guess-question{width:100%;margin-top:24px;padding:24px;border-radius:24px;box-sizing:border-box;background-color:var(--devui-base-bg,#ffffff);}.guess-question-title{font-size:24px;font-weight:700;color:var(--devui-text,#252b3a);margin-bottom:16px;}.guess-question span{font-size:var(--devui-font-size,12px);color:var(--devui-aide-text,#71757f);padding:10px16px;border-radius:var(--devui-border-radius-full,100px);background-color:var(--devui-dividing-line,#f2f2f3);cursor:pointer;}.content-wrapper{margin:auto0;}.chat-container{width:100%;height:100%;padding:12px;border-radius:20px;margin:0auto;border:1px solid #e5e5e5;background:linear-gradient(180deg,#fffffff2,#f8fafff299%);}.chat-header{display:flex;align-items:center;gap:4px;margin-bottom:8px;img{width:32px;height:32px;}span{font-size:20px;color:var(--devui-text,#252b3a);}}.mc-introduction{display:flex;flex-direction:column;align-items:center;gap:12px;}.chat-list{flex:1;width:100%;max-width:1200px;margin:0auto12px;overflow:auto;.user-bubble,.model-bubble{display:block;margin-top:8px;}}.chat-footer{width:100%;max-width:1200px;margin:0auto;padding:012px12px;box-sizing:border-box;}.statement-box{font-size:12px;margin-top:8px;color:var(--devui-aide-text,#71757f);text-align:center;}



以下是配置 Angular CLI 使用 Less 的方法:

Angular CLI 默认使用 CSS 作为样式表预处理器,但可以通过以下步骤配置为使用 Less:

安装 Less 和 Less Loader:

npm install less less-loader--save-dev

修改 angular.json 配置文件,在 projects -> your-project-name -> architect -> build -> options 中添加或修改样式配置:

{"projects":{"your-project":{"architect":{"build":{"options":{"styles":["src/styles.less"],"stylePreprocessorOptions":{"includePaths":["src/styles"]}}}}}}}

将组件中的 .css 文件重命名为 .less,并在组件装饰器中更新样式 URLs:

@Component({styleUrls:['./app.component.less']})

重启开发服务器以使配置生效:

ng serve

注意事项:

  • 确保所有组件的样式文件扩展名从 .css 改为 .less
  • 如果已有全局样式文件,也需将其扩展名改为 .less
  • 当使用第三方库时,确保其样式文件也支持 Less 预处理
  • 版本兼容性很重要,建议使用与 Angular CLI 兼容的 Less 和 less-loader 版本

Application bundle generation failed.[1.522seconds]-2025-12-11T05:46:09.453Z ✘[ERROR]TS2339:Property'theme'does not exist on type'App'.[plugin angular-compiler]src/app/app.html:42:37:42...<mc-markdown-card[theme]="theme"[content]="msg.content"[en...~~~~~Error occursinthe templateofcomponent App.src/app/app.ts:8:15:8│ templateUrl:'./app.html',~~~~~~~~~~~~[ERROR]Could not resolve"src/styles.less"angular:styles/global:styles:1:8:1│ @import'src/styles.less';~~~~~~~~~~~~~~~~~

主题化

在main.ts中初始化主题,更多用法可参考 devui-theme

import{bootstrapApplication}from'@angular/platform-browser';import{appConfig}from'./app/app.config';import{App}from'./app/app';import{ThemeServiceInit,infinityTheme,galaxyTheme}from'devui-theme';ThemeServiceInit({'galaxy-theme':galaxyTheme,// 暗黑主题'infinity-theme':infinityTheme,},'infinity-theme');bootstrapApplication(App,appConfig).catch((err)=>console.error(err));





MateChat是一个基于Angular的前端智能化UI组件库,专为AI应用场景设计。它提供开箱即用的组件(如对话气泡、输入框等),支持多主题适配,已成功应用于华为内部多个智能化项目。通过简单的模块引入和组件调用,开发者可快速构建AI对话界面。示例代码展示了如何实现包含欢迎页、消息列表和输入区的完整聊天界面,支持用户与AI模型的交互。该库显著降低了AI应用的前端开发门槛。

MateChat:https://gitcode.com/DevCloudFE/MateChat
MateChat官网:https://matechat.gitcode.com
DevUI官网:https://devui.design/home

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/2/22 3:42:54

n8n实战营Day3课时3:库存物流联动·全流程测试与异常调试

我将承接上节课订单同步内容&#xff0c;聚焦库存扣减与物流联动的核心实现&#xff0c;重点拆解并发控制与物流API调用技巧&#xff0c;搭配全流程测试方案&#xff0c;结构图采用CSDN适配的mermaid语法确保清晰呈现。 n8n实战营Day3课时3&#xff1a;库存物流联动全流程测试与…

作者头像 李华
网站建设 2026/2/19 19:50:09

基于java的SpringBoot/SSM+Vue+uniapp的车联网通信平台的详细设计和实现(源码+lw+部署文档+讲解等)

文章目录前言详细视频演示具体实现截图技术栈后端框架SpringBoot前端框架Vue持久层框架MyBaitsPlus系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言 &#x1f31e;博主介绍&#xff1a;✌全网粉丝15W,CSDN特邀作者、211毕业、高级全…

作者头像 李华
网站建设 2026/2/21 3:36:29

SAAS-错误处理方法总结

在SAAS的数据源视图中&#xff08;注意这儿的强调词&#xff09;通过外键关联的字段&#xff0c;必须要么为空&#xff0c;要么在主键表中有对应值。不能为0&#xff0c;否则报0值找不到对应键。

作者头像 李华
网站建设 2026/2/23 19:21:14

FTP使用指南:原理、用途及实战操作全解析

文章目录前言网工高频的FTP操作一、版本补丁更新二、配置文件获取三、诊断日志获取介绍FTP一、什么是 FTP&#xff1f;二、FTP vs SFTPFTP软件3CDaemon&#xff08;FTP服务器端&#xff09;Python代码&#xff08;FTP服务器端&#xff09;CMD&#xff08;FTP客户端&#xff09;…

作者头像 李华
网站建设 2026/2/21 7:35:18

Wan2.2-T2V-A14B生成视频是否可通过广电审核标准?

Wan2.2-T2V-A14B生成视频是否可通过广电审核标准&#xff1f; 在AI视频生成技术突飞猛进的今天&#xff0c;一个现实而关键的问题摆在了内容创作者和平台面前&#xff1a;我们用大模型“一键生成”的视频&#xff0c;真的能上电视吗&#xff1f; 别笑&#xff0c;这可不是开玩笑…

作者头像 李华