feat: 增加会话改名和删除的接口

This commit is contained in:
zoujing
2026-03-06 10:51:54 +08:00
parent ef50aae9d0
commit ed04eea481
3 changed files with 111 additions and 37 deletions

View File

@@ -1,4 +1,4 @@
import { getRequest, postRequest, ResponseModel } from '@utils/request'
import { getRequest, postRequest, patchRequest, deleteRequest, ResponseModel } from '@utils/request'
// 创建会话 的请求参数和响应数据结构
export interface CreateSessionRequest {
@@ -83,3 +83,40 @@ export const getSessionMessages = async (params: SessionMessagesRequest) => {
})
return res.data as SessionMessagesResponse
}
/// PATCH /api/sessions/{session_id} 的请求参数和响应数据结构
export interface UpdateSessionRequest {
session_id: string
title: string
}
export interface UpdateSessionResponse {
success: boolean
}
// 更新会话信息 的函数实现
export const updateSession = async (params: UpdateSessionRequest) => {
const res: ResponseModel = await patchRequest(`/nianxx/api/sessions/${params.session_id}`, {
title: params.title,
})
return res.data as UpdateSessionResponse
}
/// DELETE /api/sessions/{session_id} 的请求参数和响应数据结构
export interface DeleteSessionRequest {
session_id: string
}
export interface DeleteSessionResponse {
success: boolean
}
// 删除会话 的函数实现
export const deleteSession = async (params: DeleteSessionRequest) => {
const res: ResponseModel = await deleteRequest(`/nianxx/api/sessions/${params.session_id}`)
return res.data as DeleteSessionResponse
}

View File

@@ -163,6 +163,32 @@ export const getRequest = <ResponseModel>(url: string, params?: any, options?: a
}) as Promise<ResponseModel>
}
// 封装基于 request 的 PATCH 请求
export const patchRequest = <ResponseModel>(url: string, data?: any, options?: any): Promise<ResponseModel> => {
return instance.request({
url,
method: 'patch',
headers: {
'Content-Type': 'application/json',
},
data,
...(options || {}),
}) as Promise<ResponseModel>
}
// 封装基于 request 的 DELETE 请求
export const deleteRequest = <ResponseModel>(url: string, data?: any, options?: any): Promise<ResponseModel> => {
return instance.request({
url,
method: 'delete',
headers: {
'Content-Type': 'application/json',
},
data,
...(options || {}),
}) as Promise<ResponseModel>
}
export default instance
/// 响应模型

View File

@@ -36,6 +36,7 @@
</li>
</ul>
</div>
</aside>
<!-- 重命名对话框 -->
<el-dialog v-model="renameDialogFormVisible" title="重命名对话" width="500">
@@ -47,35 +48,28 @@
<template #footer>
<div class="dialog-footer">
<el-button @click="renameDialogFormVisible = false">取消</el-button>
<el-button type="primary" @click="submitNameChange">
确定
</el-button>
<el-button type="primary" @click="submitNameChange">确定</el-button>
</div>
</template>
</el-dialog>
<!-- 删除确认对话框 -->
<el-dialog v-model="deleteDialogVisible" title="温馨提示" width="500" center>
<span>
您确定删除该会话吗删除后将无法恢复<br />
</span>
<el-dialog v-model="deleteDialogVisible" title="温馨提示" width="500">
<span>您确定删除该会话吗删除后将无法恢复</span>
<template #footer>
<div class="dialog-footer">
<el-button @click="deleteDialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitDelete">
确定
</el-button>
<el-button type="primary" @click="submitDelete">确定</el-button>
</div>
</template>
</el-dialog>
</aside>
</template>
<script setup lang="ts">
import { ref, onMounted, defineEmits } from 'vue'
import { RiAddLine, RiArrowRightSLine, RiArrowDownSLine } from '@remixicon/vue'
import { getSessionList } from '../../api/SessionsApi';
import { getSessionList, deleteSession, updateSession } from '../../api/SessionsApi';
const deleteDialogVisible = ref(false)
const renameDialogFormVisible = ref(false)
@@ -99,6 +93,10 @@ const emit = defineEmits(['new-chat', 'select-chat'])
/// 添加新对话
const addNewChat = () => {
console.log('add new chat')
updateNewChat()
}
const updateNewChat = () => {
// 触发新对话事件
emit('new-chat')
// 清空选择的历史消息ID
@@ -126,15 +124,28 @@ const deleteHistoryMessage = (conversationId: string) => {
}
/// 提交重命名
const submitNameChange = () => {
const submitNameChange = async () => {
console.log('submit name change', newMessageName.value)
renameDialogFormVisible.value = false
const res = await updateSession({
session_id: selectedConversationId.value,
title: newMessageName.value
})
if (res && res.success) {
updateNewChat()
}
}
/// 提交删除
const submitDelete = () => {
const submitDelete = async () => {
console.log('submit delete')
deleteDialogVisible.value = false
const res = await deleteSession({
session_id: selectedConversationId.value
})
if (res && res.success) {
updateNewChat()
}
}
/// 页面加载时获取历史会话列表