|
19 | 19 | <el-container :loading="loading"> |
20 | 20 | <el-main class="chat-record-list"> |
21 | 21 | <el-scrollbar> |
22 | | - <div v-for="message in computedMessages"> |
23 | | - {{ message.role }}: {{ message.content }} |
24 | | - <div v-if="message.isWelcome"> |
25 | | - <el-select v-model="currentChat.datasource" :disabled="currentChat.id!==undefined"> |
26 | | - <el-option v-for="item in dsList" |
27 | | - :value="item.id" |
28 | | - :key="item.id" |
29 | | - :label="item.name"/> |
30 | | - </el-select> |
31 | | - </div> |
32 | | - </div> |
| 22 | + <template v-for="(message, _index) in computedMessages" :key="_index"> |
| 23 | + <ChatRow :current-chat="currentChat" v-model:datasource="currentChat.datasource" :msg="message"/> |
| 24 | + </template> |
33 | 25 | </el-scrollbar> |
34 | 26 | </el-main> |
35 | | - <el-footer> |
36 | | - <div class="chat-input"> |
37 | | - <div class="input-wrapper"> |
38 | | - <el-input |
39 | | - v-model="inputMessage" |
40 | | - type="textarea" |
41 | | - :rows="1" |
42 | | - :autosize="{ minRows: 1, maxRows: 8 }" |
43 | | - placeholder="Press Enter to send, Ctrl + Enter for new line" |
44 | | - @keydown.enter.exact.prevent="sendMessage" |
45 | | - @keydown.ctrl.enter.exact.prevent="handleCtrlEnter" |
46 | | - /> |
47 | | - <div class="input-actions"> |
48 | | - <el-button circle type="primary" class="send-btn" @click="sendMessage"> |
49 | | - <el-icon> |
50 | | - <Position/> |
51 | | - </el-icon> |
52 | | - </el-button> |
53 | | - </div> |
54 | | - </div> |
| 27 | + <el-footer class="chat-footer"> |
| 28 | + <div style="height: 24px;"> |
| 29 | + <template v-if="currentChat.datasource"> |
| 30 | + 使用数据源:{{ currentChat.datasource_name }} |
| 31 | + </template> |
| 32 | + </div> |
| 33 | + <div class="input-wrapper"> |
| 34 | + <el-input |
| 35 | + class="input-area" |
| 36 | + v-model="inputMessage" |
| 37 | + type="textarea" |
| 38 | + :rows="1" |
| 39 | + :autosize="{ minRows: 1, maxRows: 8 }" |
| 40 | + placeholder="Press Enter to send, Ctrl + Enter for new line" |
| 41 | + @keydown.enter.exact.prevent="sendMessage" |
| 42 | + @keydown.ctrl.enter.exact.prevent="handleCtrlEnter" |
| 43 | + /> |
| 44 | + <el-button link type="primary" class="input-icon" @click="sendMessage"> |
| 45 | + <el-icon size="20"> |
| 46 | + <Position/> |
| 47 | + </el-icon> |
| 48 | + </el-button> |
55 | 49 | </div> |
56 | 50 | </el-footer> |
57 | 51 | </el-container> |
|
62 | 56 | <script setup lang="ts"> |
63 | 57 | import {ref, computed, nextTick, watch, onMounted} from 'vue' |
64 | 58 | import {Plus, Position} from '@element-plus/icons-vue' |
65 | | -import {Chat, chatApi, ChatInfo, ChatRecord, questionApi} from '@/api/chat' |
66 | | -import {datasourceApi} from "@/api/datasource.ts" |
| 59 | +import {Chat, chatApi, ChatInfo, type ChatMessage, ChatRecord, questionApi} from '@/api/chat' |
67 | 60 | import ChatList from './ChatList.vue' |
68 | | -
|
69 | | -interface ChatMessage { |
70 | | - role: 'user' | 'assistant' |
71 | | - create_time?: Date | string |
72 | | - content?: string | number |
73 | | - isTyping?: boolean |
74 | | - isWelcome?: boolean |
75 | | -} |
| 61 | +import ChatRow from './ChatRow.vue' |
76 | 62 |
|
77 | 63 | const inputMessage = ref('') |
78 | 64 |
|
79 | 65 | const loading = ref<boolean>(false); |
80 | 66 | const chatList = ref<Array<ChatInfo>>([]) |
81 | | -const dsList = ref<any>([]) |
82 | 67 |
|
83 | 68 | const currentChatId = ref<number | undefined>() |
84 | 69 | const currentChat = ref<ChatInfo>(new ChatInfo()) |
@@ -131,7 +116,6 @@ const createNewChat = () => { |
131 | 116 | currentChat.value = new ChatInfo() |
132 | 117 | currentChatId.value = undefined |
133 | 118 | inputMessage.value = '' |
134 | | - listDs() |
135 | 119 | } |
136 | 120 |
|
137 | 121 | function getChatList() { |
@@ -183,15 +167,9 @@ function onChatRenamed(chat: Chat) { |
183 | 167 | } |
184 | 168 | } |
185 | 169 |
|
186 | | -function listDs() { |
187 | | - datasourceApi.list().then((res) => { |
188 | | - dsList.value = res |
189 | | - }) |
190 | | -} |
191 | 170 |
|
192 | 171 | onMounted(() => { |
193 | 172 | getChatList() |
194 | | - listDs() |
195 | 173 | }) |
196 | 174 |
|
197 | 175 |
|
@@ -347,7 +325,39 @@ const handleCtrlEnter = (e: KeyboardEvent) => { |
347 | 325 | } |
348 | 326 |
|
349 | 327 | .chat-record-list { |
350 | | - padding: 20px 0 0 0; |
| 328 | + padding: 0 0 20px 0; |
| 329 | + } |
| 330 | +
|
| 331 | + .chat-footer { |
| 332 | + --ed-footer-height: 120px; |
| 333 | +
|
| 334 | + display: flex; |
| 335 | + flex-direction: column; |
| 336 | +
|
| 337 | + .input-wrapper { |
| 338 | + flex: 1; |
| 339 | +
|
| 340 | + position: relative; |
| 341 | +
|
| 342 | + .input-area { |
| 343 | + height: 100%; |
| 344 | + padding-bottom: 8px; |
| 345 | +
|
| 346 | + :deep(.ed-textarea__inner) { |
| 347 | + height: 100% !important; |
| 348 | + } |
| 349 | + } |
| 350 | +
|
| 351 | + .input-icon { |
| 352 | + min-width: unset; |
| 353 | + position: absolute; |
| 354 | + bottom: 14px; |
| 355 | + right: 8px; |
| 356 | + } |
| 357 | +
|
| 358 | + } |
| 359 | +
|
| 360 | +
|
351 | 361 | } |
352 | 362 |
|
353 | 363 |
|
|
0 commit comments