* feat: 添加聊天记录删除按钮及功能 #548

This commit is contained in:
shaohuzhang1 2024-06-13 15:17:36 +08:00 committed by GitHub
parent 3f38f14caa
commit 4c1fcba546
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 120 additions and 9 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 4.1.13 on 2024-06-13 11:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('application', '0007_alter_application_prologue'),
]
operations = [
migrations.AddField(
model_name='chat',
name='is_deleted',
field=models.BooleanField(default=False, verbose_name=''),
),
]

View File

@ -75,6 +75,7 @@ class Chat(AppModelMixin):
application = models.ForeignKey(Application, on_delete=models.CASCADE)
abstract = models.CharField(max_length=1024, verbose_name="摘要")
client_id = models.UUIDField(verbose_name="客户端id", default=None, null=True)
is_deleted = models.BooleanField(verbose_name="", default=False)
class Meta:
db_table = "application_chat"

View File

@ -50,6 +50,13 @@ class ChatSerializers(serializers.Serializer):
chat_id = serializers.UUIDField(required=True, error_messages=ErrMessage.uuid("对话id"))
application_id = serializers.UUIDField(required=True, error_messages=ErrMessage.uuid("应用id"))
def logic_delete(self, with_valid=True):
if with_valid:
self.is_valid(raise_exception=True)
QuerySet(Chat).filter(id=self.data.get('chat_id'), application_id=self.data.get('application_id')).update(
is_deleted=True)
return True
def delete(self, with_valid=True):
if with_valid:
self.is_valid(raise_exception=True)
@ -64,7 +71,8 @@ class ChatSerializers(serializers.Serializer):
if with_valid:
self.is_valid(raise_exception=True)
queryset = QuerySet(Chat).filter(client_id=self.data.get('client_id'),
application_id=self.data.get('application_id'))
application_id=self.data.get('application_id'),
is_deleted=False)
queryset = queryset.order_by('-create_time')
return page_search(current_page, page_size, queryset, lambda row: ChatSerializerModel(row).data)

View File

@ -32,6 +32,8 @@ urlpatterns = [
path("application/chat/open", views.ChatView.OpenTemp.as_view()),
path("application/<str:application_id>/chat/client/<int:current_page>/<int:page_size>",
views.ChatView.ClientChatHistoryPage.as_view()),
path("application/<str:application_id>/chat/client/<chat_id>",
views.ChatView.ClientChatHistoryPage.Operate.as_view()),
path('application/<str:application_id>/chat/export', views.ChatView.Export.as_view(), name='export'),
path('application/<str:application_id>/chat', views.ChatView.as_view(), name='chats'),
path('application/<str:application_id>/chat/<int:current_page>/<int:page_size>', views.ChatView.Page.as_view()),

View File

@ -160,6 +160,25 @@ class ChatView(APIView):
current_page=current_page,
page_size=page_size))
class Operate(APIView):
authentication_classes = [TokenAuth]
@action(methods=['DELETE'], detail=False)
@swagger_auto_schema(operation_summary="客户端删除对话",
operation_id="客户端删除对话",
tags=["应用/对话日志"])
@has_permissions(ViewPermission(
[RoleConstants.APPLICATION_ACCESS_TOKEN],
[lambda r, keywords: Permission(group=Group.APPLICATION, operate=Operate.USE,
dynamic_tag=keywords.get('application_id'))],
compare=CompareConstants.AND),
compare=CompareConstants.AND)
def delete(self, request: Request, application_id: str, chat_id: str):
return result.success(
ChatSerializers.Operate(
data={'application_id': application_id, 'user_id': request.user.id,
'chat_id': chat_id}).logic_delete())
class Page(APIView):
authentication_classes = [TokenAuth]

View File

@ -186,6 +186,18 @@ const getChatLogClient: (
)
}
/**
*
* @param application_id, chat_id,
*/
const delChatClientLog: (
application_id: string,
chat_id: string,
loading?: Ref<boolean>
) => Promise<Result<boolean>> = (application_id, chat_id, loading) => {
return del(`${prefix}/${application_id}/chat/client/${chat_id}`, undefined, {}, loading)
}
export default {
getChatLog,
delChatLog,
@ -195,5 +207,6 @@ export default {
getRecordDetail,
delMarkRecord,
exportChatLog,
getChatLogClient
getChatLogClient,
delChatClientLog
}

View File

@ -96,7 +96,6 @@
plain
size="small"
@click="openParagraph(item)"
:disabled="!item.paragraph_list || item.paragraph_list?.length === 0"
>引用分段{{ item.paragraph_list?.length || 0 }}</el-button
>
<el-tag type="info" effect="plain" class="mr-8 mt-8">

View File

@ -48,6 +48,18 @@ const useLogStore = defineStore({
reject(error)
})
})
},
async asyncDelChatClientLog(id: string, chatId: string, loading?: Ref<boolean>) {
return new Promise((resolve, reject) => {
logApi
.delChatClientLog(id, chatId, loading)
.then((data) => {
resolve(data)
})
.catch((error) => {
reject(error)
})
})
}
}
})

View File

@ -45,9 +45,16 @@
@click="clickListHandle"
>
<template #default="{ row }">
<auto-tooltip :content="row.abstract">
{{ row.abstract }}
</auto-tooltip>
<div class="flex-between">
<auto-tooltip :content="row.abstract">
{{ row.abstract }}
</auto-tooltip>
<div @click.stop>
<el-button text @click.stop="deleteLog(row)">
<el-icon><Delete /></el-icon>
</el-button>
</div>
</div>
</template>
<template #empty>
<div class="text-center">
@ -94,6 +101,18 @@ const paginationConfig = reactive({
const currentRecordList = ref<any>([])
const currentChatId = ref('new') // Id 'new'
function deleteLog(row: any) {
log.asyncDelChatClientLog(applicationDetail.value.id, row.id, left_loading).then(() => {
if (currentChatId.value === row.id) {
currentChatId.value = 'new'
paginationConfig.current_page = 1
paginationConfig.total = 0
currentRecordList.value = []
}
getChatLog(applicationDetail.value.id)
})
}
function handleScroll(event: any) {
if (
currentChatId.value !== 'new' &&

View File

@ -25,9 +25,16 @@
@click="clickListHandle"
>
<template #default="{ row }">
<auto-tooltip :content="row.abstract">
{{ row.abstract }}
</auto-tooltip>
<div class="flex-between">
<auto-tooltip :content="row.abstract">
{{ row.abstract }}
</auto-tooltip>
<div @click.stop>
<el-button text @click.stop="deleteLog(row)">
<el-icon><Delete /></el-icon>
</el-button>
</div>
</div>
</template>
<template #empty>
<div class="text-center">
@ -144,6 +151,19 @@ const currentRecordList = ref<any>([])
const currentChatId = ref('new') // Id 'new'
const currentChatName = ref('新建对话')
function deleteLog(row: any) {
log.asyncDelChatClientLog(applicationDetail.value.id, row.id, left_loading).then(() => {
if (currentChatId.value === row.id) {
currentChatId.value = 'new'
currentChatName.value = '新建对话'
paginationConfig.value.current_page = 1
paginationConfig.value.total = 0
currentRecordList.value = []
}
getChatLog(applicationDetail.value.id)
})
}
function handleScroll(event: any) {
if (
currentChatId.value !== 'new' &&