Commit 44f322bb by YunaiV

【代码优化】AI:聊天对话 index.vue 代码梳理 30%

parent 1064bbe5
...@@ -30,7 +30,7 @@ export const ChatMessageApi = { ...@@ -30,7 +30,7 @@ export const ChatMessageApi = {
// 发送 Stream 消息 // 发送 Stream 消息
// 为什么不用 axios 呢?因为它不支持 SSE 调用 // 为什么不用 axios 呢?因为它不支持 SSE 调用
sendStream: async ( sendChatMessageStream: async (
conversationId: number, conversationId: number,
content: string, content: string,
ctrl, ctrl,
...@@ -60,11 +60,11 @@ export const ChatMessageApi = { ...@@ -60,11 +60,11 @@ export const ChatMessageApi = {
}, },
// 删除消息 // 删除消息
delete: async (id: string) => { deleteChatMessage: async (id: string) => {
return await request.delete({ url: `/ai/chat/message/delete?id=${id}` }) return await request.delete({ url: `/ai/chat/message/delete?id=${id}` })
}, },
// 删除消息 - 对话所有消息 // 删除指定对话的消息
deleteByConversationId: async (conversationId: number) => { deleteByConversationId: async (conversationId: number) => {
return await request.delete({ return await request.delete({
url: `/ai/chat/message/delete-by-conversation-id?conversationId=${conversationId}` url: `/ai/chat/message/delete-by-conversation-id?conversationId=${conversationId}`
......
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ChatConversationApi, ChatConversationVO } from '@/api/ai/chat/conversation' import { ChatConversationApi, ChatConversationVO } from '@/api/ai/chat/conversation'
import { ref } from 'vue' import { ref } from 'vue'
import Role from '../../role/index.vue' import Role from '../role/index.vue'
import { Bottom, Top } from '@element-plus/icons-vue' import { Bottom, Top } from '@element-plus/icons-vue'
import roleAvatarDefaultImg from '@/assets/ai/gpt.svg' import roleAvatarDefaultImg from '@/assets/ai/gpt.svg'
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<el-button class="btn-cus" link @click="noCopy(item.content)"> <el-button class="btn-cus" link @click="noCopy(item.content)">
<img class="btn-image" src="@/assets/ai/copy.svg" /> <img class="btn-image" src="@/assets/ai/copy.svg" />
</el-button> </el-button>
<el-button class="btn-cus" link @click="onDelete(item.id)"> <el-button v-if="item.id > 0" class="btn-cus" link @click="onDelete(item.id)">
<img class="btn-image" src="@/assets/ai/delete.svg" style="height: 17px" /> <img class="btn-image" src="@/assets/ai/delete.svg" style="height: 17px" />
</el-button> </el-button>
</div> </div>
...@@ -70,7 +70,7 @@ import { useClipboard } from '@vueuse/core' ...@@ -70,7 +70,7 @@ import { useClipboard } from '@vueuse/core'
import { PropType } from 'vue' import { PropType } from 'vue'
import { ArrowDownBold, Edit, RefreshRight } from '@element-plus/icons-vue' import { ArrowDownBold, Edit, RefreshRight } from '@element-plus/icons-vue'
import { ChatConversationVO } from '@/api/ai/chat/conversation' import { ChatConversationVO } from '@/api/ai/chat/conversation'
import {useUserStore} from '@/store/modules/user'; import { useUserStore } from '@/store/modules/user'
import userAvatarDefaultImg from '@/assets/imgs/avatar.gif' import userAvatarDefaultImg from '@/assets/imgs/avatar.gif'
import roleAvatarDefaultImg from '@/assets/ai/gpt.svg' import roleAvatarDefaultImg from '@/assets/ai/gpt.svg'
...@@ -138,7 +138,7 @@ const noCopy = async (content) => { ...@@ -138,7 +138,7 @@ const noCopy = async (content) => {
*/ */
const onDelete = async (id) => { const onDelete = async (id) => {
// 删除 message // 删除 message
await ChatMessageApi.delete(id) await ChatMessageApi.deleteChatMessage(id)
ElMessage({ ElMessage({
message: '删除成功!', message: '删除成功!',
type: 'success' type: 'success'
......
<!-- message 新增对话 --> <!-- 无聊天对话时,在 message 区域,可以新增对话 -->
<template> <template>
<div class="new-chat"> <div class="new-chat">
<div class="box-center"> <div class="box-center">
...@@ -11,14 +11,13 @@ ...@@ -11,14 +11,13 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// 定义钩子 const emits = defineEmits(['onNewConversation'])
const emits = defineEmits(['onNewChat'])
/** /**
* 新建 chat * 新建 conversation 聊天对话
*/ */
const handlerNewChat = async () => { const handlerNewChat = () => {
await emits('onNewChat') emits('onNewConversation')
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
......
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue' import { ref } from 'vue'
import Header from './../components/Header.vue' import Header from '../Header.vue'
import RoleList from './RoleList.vue' import RoleList from './RoleList.vue'
import ChatRoleForm from '@/views/ai/model/chatRole/ChatRoleForm.vue' import ChatRoleForm from '@/views/ai/model/chatRole/ChatRoleForm.vue'
import RoleCategoryList from './RoleCategoryList.vue' import RoleCategoryList from './RoleCategoryList.vue'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment