Skip to content

Commit 1064bbe

Browse files
committed
【代码优化】AI:聊天对话 index.vue 代码梳理 20%
1 parent f3777f6 commit 1064bbe

File tree

6 files changed

+198
-210
lines changed

6 files changed

+198
-210
lines changed

src/api/ai/chat/conversation/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import request from '@/config/axios'
22

33
// AI 聊天对话 VO
44
export interface ChatConversationVO {
5-
id: string // ID 编号
5+
id: number // ID 编号
66
userId: number // 用户编号
77
title: string // 对话标题
88
pinned: boolean // 是否置顶
@@ -23,7 +23,7 @@ export interface ChatConversationVO {
2323
// AI 聊天对话 API
2424
export const ChatConversationApi = {
2525
// 获得【我的】聊天对话
26-
getChatConversationMy: async (id: string) => {
26+
getChatConversationMy: async (id: number) => {
2727
return await request.get({ url: `/ai/chat/conversation/get-my?id=${id}` })
2828
},
2929

src/api/ai/chat/message/index.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,17 @@ export interface ChatMessageVO {
1919
userAvatar: string // 创建时间
2020
}
2121

22-
export interface ChatMessageSendVO {
23-
conversationId: string // 对话编号
24-
content: number // 聊天内容
25-
}
26-
2722
// AI chat 聊天
2823
export const ChatMessageApi = {
2924
// 消息列表
30-
messageList: async (conversationId: string | null) => {
25+
getChatMessageListByConversationId: async (conversationId: number | null) => {
3126
return await request.get({
3227
url: `/ai/chat/message/list-by-conversation-id?conversationId=${conversationId}`
3328
})
3429
},
3530

36-
// 发送 send stream 消息
37-
// TODO axios 可以么? https://apifox.com/apiskills/how-to-create-axios-stream/
31+
// 发送 Stream 消息
32+
// 为什么不用 axios 呢?因为它不支持 SSE 调用
3833
sendStream: async (
3934
conversationId: number,
4035
content: string,
@@ -70,7 +65,7 @@ export const ChatMessageApi = {
7065
},
7166

7267
// 删除消息 - 对话所有消息
73-
deleteByConversationId: async (conversationId: string) => {
68+
deleteByConversationId: async (conversationId: number) => {
7469
return await request.delete({
7570
url: `/ai/chat/message/delete-by-conversation-id?conversationId=${conversationId}`
7671
})

src/views/ai/chat/index/MessageNewChat.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<!-- message 新增对话 -->
22
<template>
3-
<div class="new-chat" >
3+
<div class="new-chat">
44
<div class="box-center">
55
<div class="tip">点击下方按钮,开始你的对话吧</div>
6-
<div class="btns"><el-button type="primary" round @click="handlerNewChat">新建对话</el-button></div>
6+
<div class="btns">
7+
<el-button type="primary" round @click="handlerNewChat">新建对话</el-button>
8+
</div>
79
</div>
810
</div>
911
</template>
1012

1113
<script setup lang="ts">
12-
1314
// 定义钩子
1415
const emits = defineEmits(['onNewChat'])
1516
@@ -19,7 +20,6 @@ const emits = defineEmits(['onNewChat'])
1920
const handlerNewChat = async () => {
2021
await emits('onNewChat')
2122
}
22-
2323
</script>
2424
<style scoped lang="scss">
2525
.new-chat {

src/views/ai/chat/index/Conversation.vue renamed to src/views/ai/chat/index/components/conversation/ConversationList.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<script setup lang="ts">
9999
import { ChatConversationApi, ChatConversationVO } from '@/api/ai/chat/conversation'
100100
import { ref } from 'vue'
101-
import Role from './role/index.vue'
101+
import Role from '../../role/index.vue'
102102
import { Bottom, Top } from '@element-plus/icons-vue'
103103
import roleAvatarDefaultImg from '@/assets/ai/gpt.svg'
104104
@@ -398,8 +398,7 @@ onMounted(async () => {
398398
display: flex;
399399
flex-direction: column;
400400
justify-content: space-between;
401-
padding: 0 10px;
402-
padding-top: 10px;
401+
padding: 10px 10px 0;
403402
overflow: hidden;
404403
405404
.btn-new-conversation {

src/views/ai/chat/index/components/ChatConversationUpdateForm.vue renamed to src/views/ai/chat/index/components/conversation/ConversationUpdateForm.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
v-loading="formLoading"
99
>
1010
<el-form-item label="角色设定" prop="systemMessage">
11-
<el-input type="textarea" v-model="formData.systemMessage" rows="4" placeholder="请输入角色设定" />
11+
<el-input
12+
type="textarea"
13+
v-model="formData.systemMessage"
14+
rows="4"
15+
placeholder="请输入角色设定"
16+
/>
1217
</el-form-item>
1318
<el-form-item label="模型" prop="modelId">
1419
<el-select v-model="formData.modelId" placeholder="请选择模型">
@@ -57,10 +62,9 @@ import { CommonStatusEnum } from '@/utils/constants'
5762
import { ChatModelApi, ChatModelVO } from '@/api/ai/model/chatModel'
5863
import { ChatConversationApi, ChatConversationVO } from '@/api/ai/chat/conversation'
5964
60-
/** AI 聊天角色 表单 */
65+
/** AI 聊天对话的更新表单 */
6166
defineOptions({ name: 'ChatConversationUpdateForm' })
6267
63-
const { t } = useI18n() // 国际化
6468
const message = useMessage() // 消息弹窗
6569
6670
const dialogVisible = ref(false) // 弹窗的是否展示

0 commit comments

Comments
 (0)