@matechat/ng 20.1.0-alpha.1 → 20.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img alt="MateChat Logo" src="https://matechat.gitcode.com/logo.svg" width="180" style="max-width:100%;">
4
4
  </a>
5
5
  </p>
6
- <h1 align="center">MateChat/Angular</h1>
6
+ <h1 align="center">MateChat / Angular</h1>
7
7
  <p align="center">前端智能化场景解决方案UI库,轻松构建你的AI应用。已服务于华为内部多个应用智能化改造,并助力CodeArts、InsCode AI IDE等智能化助手搭建。</p>
8
8
 
9
9
  ![example](https://matechat.gitcode.com/example1.png)
@@ -25,7 +25,7 @@
25
25
  如果你还没有新建项目,可以使用 Angular CLI 首先初始化一个`angular`项目:
26
26
 
27
27
  ```bash
28
- $ npm install -g @angular/cli
28
+ $ npm install -g @angular/cli@latest
29
29
 
30
30
  $ ng new matechat-demo
31
31
 
@@ -34,7 +34,7 @@ $ npm i @matechat/ng
34
34
 
35
35
  ### 2. 引入
36
36
 
37
- 在`app.component.ts`文件中引入模块
37
+ 在`app.ts`文件中引入模块
38
38
 
39
39
  ```ts
40
40
  import { Component } from "@angular/core";
@@ -53,7 +53,7 @@ export class AppComponent {}
53
53
 
54
54
  ### 3. 使用
55
55
 
56
- 在`app.component.html`文件中使用 MateChat 组件,如:
56
+ 在`app.html`文件中使用 MateChat 组件,如:
57
57
 
58
58
  ```html
59
59
  <mc-bubble [content]="'Hello, MateChat'" [avatarConfig]="{ name: 'matechat' }"></mc-bubble>
@@ -61,27 +61,68 @@ export class AppComponent {}
61
61
 
62
62
  以下为一个简单的对话界面搭建示例:
63
63
 
64
+ 在app.html使用如下代码:
65
+
64
66
  ```html
65
- <template>
67
+ <div class="mc-layout">
66
68
  <div class="chat-container">
69
+ <div class="chat-header" :title="'MateChat'" :logoImg="'https://matechat.gitcode.com/logo.svg'">
70
+ <img src="https://matechat.gitcode.com/logo.svg" />
71
+ <span>MateChat</span>
72
+ </div>
73
+ @if (newPage) {
74
+ <div class="welcom-page">
75
+ <div class="content-wrapper">
76
+ <div class="mc-introduction">
77
+ <div class="mc-introduction-logo-container">
78
+ <img src="https://matechat.gitcode.com/logo2x.svg" alt="MateChat" />
79
+ <div class="mc-introduction-title">MateChat</div>
80
+ </div>
81
+ <!--v-if-->
82
+ <div class="mc-introduction-description">
83
+ <div>MateChat 可以辅助研发人员编码、查询知识和相关作业信息、编写文档等。</div>
84
+ <div>
85
+ 作为AI模型,MateChat 提供的答案可能不总是确定或准确的,但您的反馈可以帮助 MateChat
86
+ 做的更好。
87
+ </div>
88
+ </div>
89
+ </div>
90
+ <div class="guess-question">
91
+ <div class="guess-title">
92
+ <div>猜你想问</div>
93
+ </div>
94
+ <div class="guess-content">
95
+ <ng-container *ngFor="let item of questionList">
96
+ <span (click)="onSubmit(item)">{{ item }}</span>
97
+ </ng-container>
98
+ </div>
99
+ </div>
100
+ </div>
101
+ </div>
102
+ } @else {
67
103
  <div class="chat-list">
68
104
  <ng-container *ngFor="let msg of messages">
69
105
  @if (msg.from === 'user') {
70
- <mc-bubble class="user-bubble" [align]="'right'" [content]="msg.content"></mc-bubble>
106
+ <mc-bubble class="user-bubble" [align]="'right'" [content]="msg.content" [avatarConfig]="avatarConfig"></mc-bubble>
71
107
  } @else if (msg.from === 'model') {
72
- <mc-bubble class="model-bubble" [align]="'left'">
73
- <mc-markdown-card [content]="msg.content" [enableMermaid]="true"></mc-markdown-card>
108
+ <mc-bubble class="model-bubble" [align]="'left'" [loading]="msg.loading" [avatarConfig]="modelAvatar">
109
+ <mc-markdown-card [theme]="theme" [content]="msg.content" [enableMermaid]="true"></mc-markdown-card>
74
110
  </mc-bubble>
75
111
  }
76
112
  </ng-container>
77
113
  </div>
114
+ }
78
115
  <div class="chat-footer">
79
- <mc-input (submit)="onSubmit($event)"></mc-input>
116
+ <mc-input (submit)="onSubmit($event)"> </mc-input>
117
+ <div class="statement-box">
118
+ <span>内容由AI生成,无法确保准确性和完整性,仅供参考</span>
119
+ </div>
80
120
  </div>
81
121
  </div>
82
- </template>
122
+ </div>
83
123
  ```
84
124
 
125
+ 在app.ts中使用如下代码:
85
126
 
86
127
  ```ts
87
128
  import { Component } from '@angular/core';
@@ -91,13 +132,27 @@ import { BubbleModule, InputModule, MarkdownCardModule } from '@matechat/ng';
91
132
  selector: 'app-root',
92
133
  imports: [CommonModule, BubbleModule, InputModule, MarkdownCardModule],
93
134
  templateUrl: './app.html',
94
- styleUrl: './app.css',
135
+ styleUrl: './app.scss',
95
136
  })
96
137
  export class App {
97
138
  inputValue = '';
98
139
  messages: any = [];
140
+ newPage = true;
141
+ questionList = [
142
+ '帮我写一篇文章',
143
+ '你可以帮我做些什么?',
144
+ '帮我写一个快速排序',
145
+ '使用 js 格式化时间',
146
+ ];
147
+ avatarConfig = {
148
+ imgSrc: 'https://matechat.gitcode.com/png/demo/userAvatar.svg',
149
+ };
150
+ modelAvatar = {
151
+ imgSrc: 'https://matechat.gitcode.com/logo.svg',
152
+ };
99
153
 
100
154
  onSubmit = (evt: any) => {
155
+ this.newPage = false;
101
156
  this.inputValue = '';
102
157
  // 用户发送消息
103
158
  this.messages.push({
@@ -113,42 +168,208 @@ export class App {
113
168
  }, 200);
114
169
  };
115
170
  }
116
-
117
171
  ```
118
172
 
173
+ 在将模板应用中的app.css修改成`app.scss`,使用如下代码:
174
+
175
+
119
176
  ```scss
177
+ ::ng-deep body {
178
+ margin: 0;
179
+ color: var(--devui-text, #252b3a);
180
+ }
181
+
182
+ .mc-layout {
183
+ height: 100vh;
184
+ width: 100%;
185
+ padding: 12px;
186
+ box-sizing: border-box;
187
+ background: linear-gradient(
188
+ to bottom,
189
+ #d0c9ff 0%,
190
+ #e6d6f0 8%,
191
+ #f1dbea 12%,
192
+ #c8dcfb 40%,
193
+ #abc6f6 60%,
194
+ #87aefe 90%
195
+ );
196
+ }
197
+
198
+ ::ng-deep body[ui-theme='galaxy-theme'] .mc-layout {
199
+ background: var(--devui-global-bg, #f6f6f8);
200
+
201
+ .chat-container {
202
+ background: transparent;
203
+ border: none;
204
+ }
205
+ }
206
+
120
207
  .chat-container {
208
+ display: flex;
209
+ flex-direction: column;
210
+ box-sizing: border-box;
211
+ gap: 8px;
212
+ }
213
+
214
+ .welcom-page {
215
+ display: flex;
216
+ flex-direction: column;
217
+ flex: 1;
218
+ max-width: 1200px;
219
+ margin: 0 auto;
220
+ overflow: auto;
221
+ width: 100%;
121
222
  max-width: 1200px;
223
+ padding: 0 12px;
224
+ box-sizing: border-box;
225
+ gap: 24px;
226
+ }
227
+
228
+ .guess-title {
229
+ display: flex;
230
+ justify-content: space-between;
231
+ align-items: center;
232
+ color: var(--devui-text, #252b3a);
233
+ margin-bottom: 16px;
234
+ }
235
+
236
+ .guess-content {
237
+ display: flex;
238
+ align-items: center;
239
+ flex-wrap: wrap;
240
+ gap: 12px;
241
+ }
242
+
243
+ .mc-introduction-logo-container {
244
+ display: flex;
245
+ align-items: center;
246
+ gap: 8px;
247
+ }
248
+
249
+ .mc-introduction-description {
250
+ text-align: center;
251
+ font-size: 14px;
252
+ color: var(--devui-text, #252b3a);
253
+ }
254
+
255
+ .mc-introduction-title {
256
+ font-weight: 700;
257
+ font-size: 32px;
258
+ letter-spacing: 1px;
259
+ color: var(--devui-text, #252b3a);
260
+ }
261
+
262
+ .guess-question {
122
263
  width: 100%;
264
+ margin-top: 24px;
265
+ padding: 24px;
266
+ border-radius: 24px;
267
+ box-sizing: border-box;
268
+ background-color: var(--devui-base-bg, #ffffff);
269
+ }
270
+
271
+ .guess-question-title {
272
+ font-size: 24px;
273
+ font-weight: 700;
274
+ color: var(--devui-text, #252b3a);
275
+ margin-bottom: 16px;
276
+ }
277
+
278
+ .guess-question span {
279
+ font-size: var(--devui-font-size, 12px);
280
+ color: var(--devui-aide-text, #71757f);
281
+ padding: 10px 16px;
282
+ border-radius: var(--devui-border-radius-full, 100px);
283
+ background-color: var(--devui-dividing-line, #f2f2f3);
284
+ cursor: pointer;
285
+ }
286
+
287
+ .content-wrapper {
288
+ margin: auto 0;
289
+ }
290
+
291
+ .chat-container {
292
+ width: 100%;
293
+ height: 100%;
123
294
  padding: 12px;
124
- border-radius: 8px;
295
+ border-radius: 20px;
125
296
  margin: 0 auto;
126
297
  border: 1px solid #e5e5e5;
298
+ background: linear-gradient(180deg, #fffffff2, #f8fafff2 99%);
127
299
  }
300
+
301
+ .chat-header {
302
+ display: flex;
303
+ align-items: center;
304
+ gap: 4px;
305
+ margin-bottom: 8px;
306
+
307
+ img {
308
+ width: 32px;
309
+ height: 32px;
310
+ }
311
+
312
+ span {
313
+ font-size: 20px;
314
+ color: var(--devui-text, #252b3a);
315
+ }
316
+ }
317
+
318
+ .mc-introduction {
319
+ display: flex;
320
+ flex-direction: column;
321
+ align-items: center;
322
+ gap: 12px;
323
+ }
324
+
128
325
  .chat-list {
129
- margin-bottom: 12px;
130
- height: 500px;
326
+ flex: 1;
327
+ width: 100%;
328
+ max-width: 1200px;
329
+ margin: 0 auto 12px;
131
330
  overflow: auto;
331
+
332
+ .user-bubble,
333
+ .model-bubble {
334
+ display: block;
335
+ margin-top: 8px;
336
+ }
337
+ }
338
+
339
+ .chat-footer {
340
+ width: 100%;
341
+ max-width: 1200px;
342
+ margin: 0 auto;
343
+ padding: 0 12px 12px;
344
+ box-sizing: border-box;
132
345
  }
133
- .user-bubble,
134
- .model-bubble {
135
- display: block;
346
+
347
+ .statement-box {
348
+ font-size: 12px;
136
349
  margin-top: 8px;
350
+ color: var(--devui-aide-text, #71757f);
351
+ text-align: center;
137
352
  }
138
353
  ```
139
354
  ### 4. 主题化
140
355
 
141
- 在`main.ts`中初始化主题
356
+ 在`main.ts`中初始化主题,更多用法可参考 [devui-theme](https://matechat.gitcode.com/use-guide/theme.html)
142
357
 
143
358
  ```ts
144
- import { bootstrapApplication } from "@angular/platform-browser";
145
- import { appConfig } from "./app/app.config";
146
- import { AppComponent } from "./app/app.component";
147
- import { ThemeServiceInit, infinityTheme } from "devui-theme";
148
-
149
- // 使用无限主题
150
- ThemeServiceInit({ infinityTheme }, "infinityTheme");
151
- bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));
359
+ import { bootstrapApplication } from '@angular/platform-browser';
360
+ import { appConfig } from './app/app.config';
361
+ import { App } from './app/app';
362
+ import { ThemeServiceInit, infinityTheme, galaxyTheme } from 'devui-theme';
363
+
364
+ ThemeServiceInit(
365
+ {
366
+ 'galaxy-theme': galaxyTheme, // 暗黑主题
367
+ 'infinity-theme': infinityTheme,
368
+ },
369
+ 'infinity-theme'
370
+ );
371
+ bootstrapApplication(App, appConfig).catch((err) => console.error(err));
372
+
152
373
  ```
153
374
  ## 🧩 对接模型服务
154
375