|
1 | 1 | import React, { useMemo, useState } from 'react';
|
2 |
| -import { Button, Tabs } from 'antd'; |
| 2 | +import { Tabs } from 'antd'; |
3 | 3 | import { Chat } from 'dt-react-component';
|
4 | 4 | import { Conversation, Message, MessageStatus, Prompt } from 'dt-react-component/chat/entity';
|
5 | 5 | import { produce } from 'immer';
|
@@ -44,7 +44,7 @@ export default function () {
|
44 | 44 | return conversations[activeKey];
|
45 | 45 | }, [activeKey, conversations]);
|
46 | 46 |
|
47 |
| - const handleSubmit = (val: string) => { |
| 47 | + const handleSubmit = (val = '') => { |
48 | 48 | if (!data) {
|
49 | 49 | const promptId = new Date().valueOf().toString();
|
50 | 50 | const messageId = (new Date().valueOf() + 1).toString();
|
@@ -122,38 +122,38 @@ export default function () {
|
122 | 122 | );
|
123 | 123 | }
|
124 | 124 |
|
125 |
| -function AI({ data, onSubmit }: { data?: Conversation; onSubmit?: (str: string) => void }) { |
| 125 | +function AI({ data, onSubmit }: { data?: Conversation; onSubmit?: (str?: string) => void }) { |
126 | 126 | const chat = Chat.useChat();
|
127 |
| - const [value, setValue] = useState(''); |
| 127 | + const [value, setValue] = useState<string | undefined>(''); |
128 | 128 |
|
129 | 129 | return (
|
130 |
| - <div style={{ width: '100%', height: 400 }}> |
| 130 | + <div style={{ width: '100%', height: 400, marginBottom: 46 }}> |
131 | 131 | <Chat chat={chat}>
|
132 | 132 | <Chat.Content
|
133 | 133 | data={data?.prompts || []}
|
134 | 134 | placeholder={
|
135 | 135 | <h1>
|
136 |
| - 有什么可以帮忙的? |
| 136 | + <Chat.Welcome |
| 137 | + title="dt-react-component" |
| 138 | + description="React UI component library based on antd package" |
| 139 | + /> |
137 | 140 | <br />
|
138 |
| - <Button onClick={() => onSubmit?.('请告诉我一首诗')}>返回一首诗</Button> |
| 141 | + <Chat.Tag onClick={() => onSubmit?.('请告诉我一首诗')}> |
| 142 | + 返回一首诗 |
| 143 | + </Chat.Tag> |
139 | 144 | </h1>
|
140 | 145 | }
|
141 | 146 | />
|
142 |
| - <div style={{ display: 'flex', gap: 4 }}> |
143 |
| - <Chat.Input |
144 |
| - value={value} |
145 |
| - onChange={setValue} |
146 |
| - onPressEnter={() => onSubmit?.(value)} |
147 |
| - placeholder="请输入想咨询的内容…" |
148 |
| - /> |
149 |
| - <Chat.Button |
150 |
| - type="primary" |
151 |
| - onClick={() => onSubmit?.(value)} |
152 |
| - disabled={chat.loading() || !value} |
153 |
| - > |
154 |
| - <Chat.Icon.SendIcon style={{ fontSize: 16 }} /> |
155 |
| - </Chat.Button> |
156 |
| - </div> |
| 147 | + <Chat.Input |
| 148 | + value={value} |
| 149 | + onChange={setValue} |
| 150 | + onPressEnter={() => onSubmit?.(value)} |
| 151 | + onPressShiftEnter={() => setValue((v) => v + '\n')} |
| 152 | + button={{ |
| 153 | + disabled: chat.loading() || !value?.trim(), |
| 154 | + }} |
| 155 | + placeholder="请输入想咨询的内容…" |
| 156 | + /> |
157 | 157 | </Chat>
|
158 | 158 | </div>
|
159 | 159 | );
|
|
0 commit comments